/* わんこWeb アプリ。モバイルファースト。PC（900px〜）で 左: 一覧／中央: チャット／右: プレビュー。 */
:root {
  --bg: #f6f7f5; --panel: #ffffff; --ink: #1d2320; --muted: #5f6b66; --line: #dde3df;
  --green: #0B6B52; --green-ink: #ffffff; --green-soft: #e3f1ec; --me: #0B6B52; --me-ink: #ffffff; --bot: #ffffff;
  --green-text: #0B6B52; --danger: #b4232c; --warn: #8a5a00; --warn-bg: #fff6e0; --radius: 14px; --tap: 44px;
  --sab: env(safe-area-inset-bottom, 0px); --sat: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121614; --panel: #1b201d; --ink: #e8ece9; --muted: #9aa69f; --line: #2b332e; --green-soft: #15302a; --bot: #222926; --warn-bg: #2b2410; --warn: #e3b955; --green-text: #8fd9bf; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif; -webkit-text-size-adjust: 100%; overflow-x: hidden; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--green); }
.app { height: 100dvh; display: flex; flex-direction: column; }
.hidden { display: none !important; }
.sr { position: absolute; left: -9999px; }

/* ---- 共通の部品 ---- */
.btn { min-height: var(--tap); padding: 10px 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.primary { background: var(--green); color: var(--green-ink); border-color: var(--green); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
/* 押した瞬間の反応（押下状態）と、処理中の表示 */
.btn:active:not(:disabled), .chip:active:not(:disabled), .sidebar .item:active { transform: scale(.97); filter: brightness(.95); }
.btn.busy { opacity: .7; cursor: progress; }
.btn.busy::after { content: ""; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
/* 読み込み中の骨組み（スケルトン） */
.skeleton { display: flex; flex-direction: column; gap: 12px; }
.sk { height: 44px; width: min(60%, 420px); border-radius: 16px; background: linear-gradient(90deg, var(--line) 25%, var(--panel) 50%, var(--line) 75%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
.sk.right { align-self: flex-end; width: min(40%, 300px); }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .sk, .btn.busy::after { animation: none; } }
.btn.icon { width: var(--tap); padding: 0; border: 0; background: transparent; font-size: 22px; }
.input { width: 100%; min-height: var(--tap); padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); }
.note { color: var(--muted); font-size: 14px; }
.error { color: var(--danger); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--green-soft); color: var(--green); font-size: 13px; }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.stack > * + * { margin-top: 12px; }

/* ---- ログイン ---- */
.auth { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px 16px calc(24px + var(--sab)); }
.auth .card { width: 100%; max-width: 420px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; }
.brand img { width: 32px; height: 32px; }

/* ---- アプリの骨組み ---- */
.topbar { display: flex; align-items: center; gap: 8px; padding: calc(8px + var(--sat)) 12px 8px; background: var(--panel); border-bottom: 1px solid var(--line); min-height: calc(56px + var(--sat)); }
.topbar .title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title small, .topbar .title .site-link { display: block; font-weight: 400; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title .site-link { text-decoration: underline; text-underline-offset: 2px; min-height: 24px; line-height: 24px; }
.topbar .site-check { flex: none; text-decoration: none; padding: 10px 14px; }
.topbar .site-check .full { display: none; }
.topbar .site-check .short { display: inline; }
.layout { flex: 1; min-height: 0; display: flex; position: relative; }
.sidebar { position: absolute; inset: 0; z-index: 20; background: var(--panel); transform: translateX(-100%); transition: transform .2s; display: flex; flex-direction: column; width: min(85vw, 320px); border-right: 1px solid var(--line); }
.sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
/* サイドバーの左右の余白は 16px でそろえる（新しい相談・一覧・下部のボタン） */
.sidebar .head { padding: 12px 16px; display: flex; gap: 8px; align-items: center; border-bottom: 1px solid var(--line); }
.sidebar .new { padding: 12px 16px 4px; }
.sidebar .list { flex: 1; overflow: auto; padding: 8px 16px; }
.sidebar .item { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 10px 12px; border-radius: 10px; min-height: var(--tap); overflow-wrap: anywhere; }
.sidebar .item.active { background: var(--green-soft); }
.sidebar .item small { display: block; color: var(--muted); font-size: 12px; }
.sidebar .foot { padding: 12px 16px calc(12px + var(--sab)); border-top: 1px solid var(--line); display: grid; gap: 8px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.messages { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 16px 12px; display: flex; flex-direction: column; gap: 12px; overscroll-behavior: contain; }
.msg { max-width: min(88%, 640px); padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--me); color: var(--me-ink); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--bot); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.card { align-self: flex-start; width: min(100%, 640px); max-width: none; white-space: normal; padding: 14px; }
.msg.card h3 { margin: 0 0 8px; font-size: 16px; }
.msg.card ul { margin: 0 0 12px; padding-left: 18px; }
.msg.card .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.msg.card .status { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.msg .meta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.typing { align-self: flex-start; color: var(--muted); font-size: 14px; padding: 4px 8px; }
.msg.live::after { content: "▍"; color: var(--muted); animation: blink 1s steps(2) infinite; }
@keyframes blink { to { opacity: 0; } }
.msg a { color: inherit; text-decoration: underline; text-underline-offset: 2px; overflow-wrap: anywhere; }
.msg.assistant a { color: var(--green-text); }
.composer { border-top: 1px solid var(--line); background: var(--panel); padding: 8px 12px calc(8px + var(--sab)); }
.chip { flex: 0 0 auto; min-height: 36px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); font-size: 14px; }
/* 返信の候補: 折り返す（横スクロールしない）・44px のタップ領域・タップでそのまま送信 */
.suggest { display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 8px; }
.chip.suggestion { min-height: var(--tap); padding: 8px 16px; background: var(--green-soft); border-color: transparent; color: var(--green-text); font-weight: 600; max-width: 100%; overflow-wrap: anywhere; text-align: left; }
.chip.suggestion:disabled { opacity: .5; cursor: default; }
.composer form { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; max-height: 160px; min-height: var(--tap); padding: 10px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg); }
.composer textarea:disabled { opacity: .6; }
.composer .send { width: var(--tap); height: var(--tap); border-radius: 50%; padding: 0; }
.preview { position: absolute; inset: 0; z-index: 30; background: var(--panel); display: none; flex-direction: column; }
.preview.open { display: flex; }
.preview .head { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.preview .head .url { flex: 1; min-width: 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview iframe { flex: 1; width: 100%; border: 0; background: #fff; }
.preview .frame-wrap { flex: 1; display: flex; justify-content: center; background: var(--bg); overflow: auto; }
.preview .frame-wrap.phone iframe { width: 390px; flex: none; margin: 12px auto; border: 1px solid var(--line); border-radius: 18px; height: calc(100% - 24px); }

/* ---- 一覧画面（メンバー・履歴） ---- */
.page { flex: 1; overflow: auto; padding: 16px 16px calc(16px + var(--sab)); }
.page .inner { max-width: 720px; margin: 0 auto; }
.row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.row .grow { flex: 1; min-width: 160px; overflow-wrap: anywhere; }
.row select { min-height: var(--tap); border-radius: 10px; border: 1px solid var(--line); background: var(--panel); padding: 0 10px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.ops-main { max-width: 960px; margin: 0 auto; padding: 24px 16px; }

/* ---- PC ---- */
@media (min-width: 900px) {
  .sidebar { position: static; transform: none; width: 280px; flex: none; box-shadow: none !important; }
  .sidebar.open { box-shadow: none; }
  .topbar .menu, .sidebar .head .icon { display: none; }
  .preview { position: static; flex: 0 0 42%; border-left: 1px solid var(--line); }
  .preview.open { display: flex; }
  .messages { padding: 24px; }
  .composer { padding: 12px 24px calc(12px + var(--sab)); }
  .topbar .site-check .full { display: inline; }
  .topbar .site-check .short { display: none; }
}
@media (prefers-reduced-motion: reduce) { .msg.live::after { animation: none; } }
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }
