:root {
  --bg: #f6f5f1;
  --panel: #ffffff;
  --panel-2: #f0eee8;
  --line: #e2dfd6;
  --text: #22201c;
  --muted: #6f6a60;
  --accent: #c8643b;
  --accent-ink: #ffffff;
  --primary: #2f5d8a;
  --primary-ink: #ffffff;
  --danger: #b23a3a;
  --user-bubble: #e6eef6;
  --claude-bubble: #ffffff;
  --system-bubble: #f3efe4;
  --code-bg: #f3f1ec;
  --chip-open: #dfe9f3;      --chip-open-ink: #234b70;
  --chip-ready: #f6e7c8;     --chip-ready-ink: #7a5310;
  --chip-approved: #dcefdc;  --chip-approved-ink: #24622b;
  --chip-running: #f4dccf;   --chip-running-ink: #8a3d17;
  --chip-done: #d8eee9;      --chip-done-ink: #1d5f53;
  --chip-failed: #f3d6d6;    --chip-failed-ink: #8a2222;
  --chip-rejected: #e7e5e0;  --chip-rejected-ink: #57534b;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  --radius: 10px;
  --font: "Noto Sans JP", "Hiragino Sans", "Yu Gothic UI", system-ui, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Noto Sans Mono CJK JP", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1917; --panel: #232220; --panel-2: #2b2a27; --line: #3a3834; --text: #ece9e2; --muted: #a39e93;
    --accent: #e07d52; --primary: #6b9bd0; --primary-ink: #0f1a26; --danger: #e07070;
    --user-bubble: #24313f; --claude-bubble: #262522; --system-bubble: #2e2b24; --code-bg: #1f1e1c;
    --chip-open: #24364a; --chip-open-ink: #b5d0ec; --chip-ready: #47391a; --chip-ready-ink: #f0d18f;
    --chip-approved: #1f3a22; --chip-approved-ink: #a9dcae; --chip-running: #4a2c1c; --chip-running-ink: #f3b896;
    --chip-done: #1b3b35; --chip-done-ink: #9fd8cb; --chip-failed: #4a2222; --chip-failed-ink: #f0a9a9;
    --chip-rejected: #34322e; --chip-rejected-ink: #c4bfb5;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.7 var(--font); }
[hidden] { display: none !important; }
body:not(.is-admin) [data-admin] { display: none !important; }  /* 管理者だけのボタン（見た目だけ。権限はサーバーで確認） */
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 11.5px; margin: 4px 2px 0; }
.center { text-align: center; }
.error { color: var(--danger); min-height: 1.2em; margin: 6px 0; font-size: 13px; }
.spacer { flex: 1; }

/* ボタン */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel);
  cursor: pointer; text-decoration: none; color: var(--text); font-size: 14px; white-space: nowrap; line-height: 1.4;
}
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }

/* ログイン */
.login-view { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.login-card label { display: block; margin: 12px 0; font-size: 13px; color: var(--muted); }
.login-card input { display: block; width: 100%; margin-top: 4px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 17px; }
.brand-mark { width: 20px; height: 20px; border-radius: 6px; background: var(--accent); display: inline-block; }
.target { font-weight: 500; font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 1px 9px; margin-left: 4px; }

/* 全体 */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); display: inline-block; }
.dot.ok { background: #3c9a52; } .dot.ng { background: var(--danger); } .dot.warn { background: #d29a2a; }
.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-list { position: absolute; right: 0; top: calc(100% + 4px); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; min-width: 190px; z-index: 20; }
.menu-list button { display: block; width: 100%; text-align: left; padding: 7px 10px; border: 0; background: none; border-radius: 6px; cursor: pointer; }
.menu-list button:hover { background: var(--panel-2); }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 320px 1fr; }

/* 左ペイン */
.pane-list { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.list-head { padding: 12px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); }
.list-head select, .list-head .filters select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.request-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.request-list li button { width: 100%; text-align: left; border: 0; background: none; padding: 10px 10px; border-radius: 8px; cursor: pointer; display: grid; gap: 3px; }
.request-list li button:hover { background: var(--panel-2); }
.request-list li button[aria-current="true"] { background: var(--user-bubble); }
.req-top { display: flex; align-items: center; gap: 6px; }
.req-id { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.req-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.req-bottom { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.typing { color: var(--accent); font-size: 12px; }

.chip { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 99px; font-weight: 600; white-space: nowrap; }
.chip.open { background: var(--chip-open); color: var(--chip-open-ink); }
.chip.prompt_ready { background: var(--chip-ready); color: var(--chip-ready-ink); }
.chip.approved { background: var(--chip-approved); color: var(--chip-approved-ink); }
.chip.running { background: var(--chip-running); color: var(--chip-running-ink); }
.chip.done { background: var(--chip-done); color: var(--chip-done-ink); }
.chip.failed { background: var(--chip-failed); color: var(--chip-failed-ink); }
.chip.rejected { background: var(--chip-rejected); color: var(--chip-rejected-ink); }

/* 右ペイン */
.pane-chat { min-height: 0; display: flex; flex-direction: column; position: relative; }
.chat-empty { margin: auto; max-width: 560px; padding: 24px; }
.chat-empty h2 { font-size: 20px; }
.steps { padding-left: 1.2em; display: grid; gap: 10px; }
.steps b { display: block; }
.chat { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.chat-title { flex: 1; min-width: 0; }
.chat-title h2 { margin: 0; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-sub { display: flex; gap: 8px; align-items: center; }
.chat-actions { display: flex; gap: 6px; }
.back { display: none; font-size: 22px; padding: 2px 10px; }

/* 最終プロンプト */
.fp-card { max-height: 55vh; overflow-y: auto; flex-shrink: 0; margin: 10px 16px 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); }
.fp-card > summary { position: sticky; top: 0; background: var(--panel); z-index: 1; cursor: pointer; padding: 9px 14px; display: flex; gap: 10px; align-items: center; }
.fp-title { font-weight: 700; }
.fp-body { padding: 0 14px 12px; }
.fp-text, .fp-edit { width: 100%; max-height: 32vh; overflow: auto; margin: 0; padding: 12px; background: var(--code-bg); border: 1px solid var(--line); border-radius: 8px; font: 13px/1.6 var(--mono); white-space: pre-wrap; word-break: break-word; }
.fp-edit { min-height: 280px; resize: vertical; }
.fp-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; align-items: center; }
.executions { margin-top: 12px; display: grid; gap: 10px; }
.exec { border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.exec-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.exec pre { max-height: 320px; overflow: auto; background: var(--code-bg); padding: 10px; border-radius: 6px; font: 12px/1.55 var(--mono); white-space: pre-wrap; word-break: break-word; margin: 8px 0 0; }
.diff .add { color: #2f8a46; } .diff .del { color: var(--danger); } .diff .hunk { color: var(--primary); }

/* メッセージ */
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: min(780px, 92%); display: grid; gap: 3px; }
.msg .who { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.msg .bubble { padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; }
.msg.user .who { justify-content: flex-end; }
.msg.user .bubble { background: var(--user-bubble); border-color: transparent; }
.msg.assistant .bubble { background: var(--claude-bubble); box-shadow: var(--shadow); }
.msg.system { align-self: center; max-width: 92%; }
.msg.system .bubble { background: var(--system-bubble); border-style: dashed; font-size: 13px; text-align: center; }
.bubble p { margin: 0 0 .6em; } .bubble p:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { font-size: 15px; margin: .8em 0 .3em; }
.bubble ul, .bubble ol { margin: .3em 0 .6em; padding-left: 1.4em; }
.bubble code { font: 13px var(--mono); background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
.bubble pre { background: var(--code-bg); padding: 10px 12px; border-radius: 8px; overflow-x: auto; margin: .5em 0; }
.bubble pre code { background: none; padding: 0; font-size: 12.5px; }
.bubble blockquote { margin: .4em 0; padding-left: 10px; border-left: 3px solid var(--line); color: var(--muted); }
.bubble .redacted, .redacted { background: var(--chip-failed); color: var(--chip-failed-ink); border-radius: 4px; padding: 0 4px; font-size: 12px; }
.fp-inline { border: 1px solid var(--accent); border-radius: 8px; margin: .6em 0; }
.fp-inline .fp-inline-head { background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 7px 7px 0 0; }
.fp-inline pre { margin: 0; border-radius: 0 0 7px 7px; white-space: pre-wrap; }
.tools { font-size: 12px; color: var(--muted); display: grid; gap: 1px; margin-top: 6px; }
.tools summary { cursor: pointer; }
.atts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.att { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); font-size: 13px; text-decoration: none; color: var(--text); max-width: 100%; }
.att img { max-width: 220px; max-height: 160px; border-radius: 6px; display: block; }
.att.img { padding: 4px; flex-direction: column; align-items: flex-start; }
.live .bubble { border-style: dashed; }
.live-phase { font-size: 12px; color: var(--accent); }
.dots::after { content: "…"; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .2; } }

/* 入力欄 */
.composer { border-top: 1px solid var(--line); background: var(--panel); padding: 10px 16px 8px; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; max-height: 200px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); line-height: 1.6; }
.attach { font-size: 18px; padding: 6px 9px; cursor: pointer; }
.pending-files { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.pending-files:empty { display: none; }
.pending { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; background: var(--panel-2); border-radius: 99px; padding: 2px 4px 2px 10px; }
.pending button { border: 0; background: none; cursor: pointer; padding: 0 6px; color: var(--muted); }
.drop-overlay { position: absolute; inset: 8px; border: 2px dashed var(--accent); border-radius: 14px; background: color-mix(in srgb, var(--bg) 85%, transparent); display: grid; place-items: center; font-weight: 700; color: var(--accent); z-index: 10; pointer-events: none; }

/* ダイアログ */
.dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--panel); color: var(--text); width: min(640px, calc(100% - 32px)); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(0,0,0,.35); }
.dialog form { padding: 20px; }
.dialog h3 { margin: 0 0 12px; }
.dialog label { display: block; margin: 10px 0; font-size: 13px; color: var(--muted); }
.dialog input, .dialog textarea, .dialog select { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.dialog textarea { min-height: 160px; resize: vertical; }
.dialog-actions { display: flex; flex-direction: row-reverse; justify-content: flex-start; gap: 8px; margin-top: 14px; }
.dialog table { width: 100%; border-collapse: collapse; font-size: 13px; }
.dialog th, .dialog td { text-align: left; padding: 6px; border-bottom: 1px solid var(--line); }
.dialog .secret { font: 15px var(--mono); background: var(--code-bg); padding: 8px 12px; border-radius: 8px; user-select: all; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 4px 12px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.list-box { max-height: 220px; overflow: auto; background: var(--code-bg); border-radius: 8px; padding: 8px 12px; font: 12.5px/1.6 var(--mono); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 50; max-width: calc(100% - 32px); font-size: 14px; }

/* スマホ */
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .layout.show-chat .pane-list { display: none; }
  .layout:not(.show-chat) .pane-chat { display: none; }
  .back { display: inline-flex; }
  .topbar { padding: 8px 12px; }
  .target { display: none; }
  .chat-head { padding: 8px 10px; flex-wrap: wrap; }
  .chat-actions { width: 100%; justify-content: flex-end; }
  .messages { padding: 12px; }
  .composer { padding: 8px 10px; }
  .fp-card { margin: 8px 10px 0; }
  .msg { max-width: 100%; }
}

/* Firebase ログイン・承認 */
.hint { background: var(--panel-2); border-radius: 8px; padding: 8px 10px; margin: 8px 0 4px; }
.notice { background: var(--chip-ready); color: var(--chip-ready-ink); border-radius: 8px; padding: 10px 12px; margin: 6px 0; }
.badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 99px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; margin-left: 4px; }
.src { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.src.fb { background: var(--chip-open); color: var(--chip-open-ink); }
.dialog .users-wrap { max-height: 46vh; overflow: auto; }
.dialog:has(.users-wrap) { width: min(900px, calc(100% - 32px)); }
.dialog td { vertical-align: top; }
.dialog td:last-child { white-space: nowrap; }
.dialog td .btn { padding: 3px 8px; font-size: 12.5px; }
.dialog tr.row-pending td { background: color-mix(in srgb, var(--chip-ready) 45%, transparent); }

/* クローズ */
.chip.closed { background: var(--chip-rejected); color: var(--chip-rejected-ink); font-weight: 500; }
.request-list li.is-closed button { opacity: .6; }
.request-list li.is-closed .req-title { text-decoration: line-through; text-decoration-color: var(--muted); }
.composer.is-closed textarea { background: var(--panel-2); }

/* 対象アプリ・依頼の種類 */
.tag { display: inline-block; font-size: 11px; padding: 0 7px; border-radius: 6px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; line-height: 18px; }
.tag.app { border-color: transparent; background: var(--panel-2); color: var(--text); font-weight: 600; }
.tag.cat-bug { color: var(--chip-failed-ink); border-color: var(--chip-failed); }
.tag.cat-addon { color: var(--chip-approved-ink); border-color: var(--chip-approved); }
.tag.cat-core { color: var(--chip-open-ink); border-color: var(--chip-open); }
.req-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.chat-sub { flex-wrap: wrap; }
.dialog .pick { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog .pick-desc { margin: -4px 0 6px; min-height: 1.2em; }
@media (max-width: 820px) { .dialog .pick { grid-template-columns: 1fr; } }

.tag.admin-badge { color: var(--chip-approved-ink); border-color: var(--chip-approved); font-weight: 600; }
