:root {
  --bg: #0d0c0a; --surface: #18160f; --ink: #f5efe2; --ink-soft: #b3a994; --ink-faint: #6e6557;
  --accent: #d4a050; --accent-soft: #2d2515;
  --yes: #6fbb7e; --no: #c4683f; --voice: #c7b4ff;
  --hair: rgba(245,239,226,0.08);
  --shadow-card: 0 20px 60px rgba(0,0,0,0.6), 0 2px 8px rgba(0,0,0,0.3);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; background: var(--bg); }
body { font-family: ui-rounded, "SF Pro Rounded", -apple-system, system-ui, sans-serif; color: var(--ink); font-size: 18px; line-height: 1.45; -webkit-font-smoothing: antialiased; display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
button { font: inherit; color: inherit; border: 0; background: transparent; cursor: pointer; padding: 0; }

.bar { display: flex; align-items: center; gap: 14px; padding: 16px 20px; padding-top: calc(16px + env(safe-area-inset-top)); font-size: 13px; color: var(--ink-faint); flex-shrink: 0; }
.bar .menu { width: 38px; height: 38px; border-radius: 12px; background: var(--surface); display: flex; align-items: center; justify-content: center; color: var(--ink-soft); transition: background .15s; }
.bar .menu:active { background: var(--accent-soft); }
.bar .menu svg { width: 18px; height: 18px; }
.bar .stat { flex: 1; display: flex; gap: 16px; align-items: center; }
.bar .stat .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--yes); animation: pulse 2s infinite; }
.bar .stat strong { color: var(--ink); font-weight: 600; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

.stage { flex: 1; position: relative; display: flex; align-items: center; justify-content: center; padding: 0 22px; overflow: hidden; }
.card { width: 100%; max-width: 560px; background: var(--surface); border-radius: 28px; padding: 32px 28px 28px; box-shadow: var(--shadow-card); display: flex; flex-direction: column; gap: 20px; border: 1px solid var(--hair); transition: transform 280ms cubic-bezier(.2,.8,.2,1), opacity 200ms; }
.card.swiping-right { transform: translateX(110%) rotate(8deg); opacity: 0; }
.card.swiping-left  { transform: translateX(-110%) rotate(-8deg); opacity: 0; }
.card.entering { transform: translateY(20px); opacity: 0; }

.card-head { display: flex; align-items: center; gap: 14px; }
.card-avatar { width: 56px; height: 56px; border-radius: 18px; background: linear-gradient(135deg, var(--accent), var(--accent-soft)); display: flex; align-items: center; justify-content: center; font-size: 26px; font-weight: 700; color: var(--bg); flex-shrink: 0; }
.card-meta { flex: 1; min-width: 0; }
.card-meta .who { font-size: 13px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 1.2px; font-weight: 600; }
.card-meta .name { font-size: 22px; font-weight: 700; color: var(--ink); margin-top: 2px; }

.card-question { font-size: 26px; line-height: 1.35; font-weight: 600; color: var(--ink); padding: 8px 0; letter-spacing: -0.3px; }

.card-context { display: flex; flex-direction: column; gap: 10px; padding: 14px 16px; border-radius: 16px; background: rgba(245,239,226,0.03); border: 1px solid var(--hair); }
.card-context .row { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; color: var(--ink-soft); }
.card-context .row .label { color: var(--ink-faint); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; min-width: 70px; padding-top: 2px; flex-shrink: 0; }
.card-context .row .val { flex: 1; word-break: break-word; }
.card-context .row.has-pill .val { display: flex; flex-wrap: wrap; gap: 6px; }
.card-context .pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; }

.actions { flex-shrink: 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; gap: 12px; justify-content: center; align-items: stretch; }
.act { flex: 1; min-width: 0; padding: 12px 8px; border-radius: 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 14px; font-weight: 700; line-height: 1.1; transition: transform .1s, opacity .15s; min-height: 76px; }
.act:active { transform: scale(.96); }
.act svg { width: 28px; height: 28px; stroke-width: 2.5; }
.act .lbl { overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.act.yes  { background: var(--yes);  color: #0a1d12; }
.act.no   { background: var(--no);   color: #1a0d08; }
.act.mic  { background: var(--voice); color: #1a1430; flex: 1.25; }
.act.mic.recording { background: var(--no); color: white; animation: pulse 1.2s infinite; }
@media (min-width: 480px) {
  .act { flex-direction: row; gap: 8px; font-size: 17px; min-height: 64px; padding: 0 14px; }
}


.empty { text-align: center; padding: 60px 30px; display: flex; flex-direction: column; gap: 20px; align-items: center; }
.empty .emoji { font-size: 64px; }
.empty h1 { font-size: 28px; margin: 0; font-weight: 700; }
.empty p { color: var(--ink-soft); margin: 0; font-size: 16px; max-width: 340px; }
.empty .ghost-stat { font-size: 13px; color: var(--ink-faint); margin-top: 14px; }

.drawer { position: fixed; top: 0; left: 0; bottom: 0; width: min(380px, 86%); background: var(--surface); transform: translateX(-100%); transition: transform 260ms cubic-bezier(.2,.8,.2,1); z-index: 100; box-shadow: 8px 0 32px rgba(0,0,0,0.5); display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); }
.drawer.open { transform: translateX(0); }
.drawer h2 { margin: 24px 22px 16px; font-size: 22px; font-weight: 700; }
.drawer-list { flex: 1; overflow-y: auto; padding: 0 12px 24px; }
.drawer-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; font-size: 15px; transition: background .12s; }
.drawer-row:active { background: rgba(245,239,226,0.04); }
.drawer-row .pip { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-faint); flex-shrink: 0; }
.drawer-row .pip.working { background: var(--yes); }
.drawer-row .pip.warn { background: var(--no); }
.drawer-row .lbl { flex: 1; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-row .ctx { font-size: 12px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.55); opacity: 0; pointer-events: none; transition: opacity 200ms; z-index: 90; }
.scrim.show { opacity: 1; pointer-events: auto; }

.voice-sheet { position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-radius: 28px 28px 0 0; padding: 28px 24px calc(28px + env(safe-area-inset-bottom)); transform: translateY(100%); transition: transform 280ms cubic-bezier(.2,.8,.2,1); z-index: 110; box-shadow: 0 -16px 48px rgba(0,0,0,0.6); display: flex; flex-direction: column; gap: 18px; align-items: center; }
.voice-sheet.open { transform: translateY(0); }
.voice-sheet h3 { margin: 0; font-size: 20px; font-weight: 700; }
.voice-sheet textarea { width: 100%; min-height: 100px; max-height: 220px; background: rgba(245,239,226,0.04); border: 1px solid var(--hair); border-radius: 16px; padding: 14px 16px; color: var(--ink); font: inherit; font-size: 17px; resize: none; outline: none; }
.voice-sheet .row { display: flex; gap: 12px; width: 100%; }
.voice-sheet .row .act { height: 56px; font-size: 16px; }

.toast { position: fixed; bottom: 120px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 12px 22px; border-radius: 999px; font-size: 14px; font-weight: 700; z-index: 200; box-shadow: var(--shadow-card); pointer-events: none; opacity: 0; transition: opacity 200ms; }
.toast.show { opacity: 1; }

/* v2 additions: text input row + play-aloud button on card */
.bottom { display: flex; flex-direction: column; gap: 8px; padding-bottom: env(safe-area-inset-bottom); flex-shrink: 0; }
.bottom .actions { padding: 14px 16px 6px; }
.quick-type { display: flex; align-items: flex-end; gap: 8px; padding: 6px 16px 14px; }
.quick-type textarea { flex: 1; min-height: 44px; max-height: 120px; padding: 11px 14px; border: 1px solid var(--hair); border-radius: 18px; background: rgba(245,239,226,0.04); color: var(--ink); font: inherit; font-size: 16px; line-height: 1.3; resize: none; outline: none; transition: border-color .15s; }
.quick-type textarea:focus { border-color: var(--accent); }
.send-arrow { width: 44px; height: 44px; border-radius: 50%; background: var(--yes); color: #0a1d12; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: background .15s, transform .1s, opacity .15s; }
.send-arrow:disabled { background: rgba(245,239,226,0.06); color: var(--ink-faint); cursor: default; }
.send-arrow:not(:disabled):active { transform: scale(.92); }
.send-arrow svg { width: 20px; height: 20px; stroke-width: 2.5; }

.play-btn { width: 38px; height: 38px; border-radius: 50%; background: rgba(245,239,226,0.06); color: var(--accent); display: flex; align-items: center; justify-content: center; flex-shrink: 0; align-self: flex-start; margin-top: 4px; transition: background .15s, transform .1s; }
.play-btn:active { transform: scale(.9); background: var(--accent-soft); }
.play-btn svg { width: 16px; height: 16px; }

/* v3: drawer rows tappable + per-agent compose sheet */
.drawer-hint { margin: -8px 22px 14px; color: var(--ink-faint); font-size: 13px; }
button.drawer-row { width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer; }

.compose-sheet { position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-radius: 28px 28px 0 0; padding: 22px 22px calc(22px + env(safe-area-inset-bottom)); transform: translateY(110%); transition: transform 280ms cubic-bezier(.2,.8,.2,1); z-index: 120; box-shadow: 0 -16px 48px rgba(0,0,0,0.6); display: flex; flex-direction: column; gap: 14px; }
.compose-sheet.open { transform: translateY(0); }
.compose-head { display: flex; align-items: center; gap: 14px; }
.compose-head .card-avatar.small { width: 44px; height: 44px; border-radius: 14px; font-size: 20px; }
.compose-meta { flex: 1; min-width: 0; }
.compose-meta .name { font-size: 18px; font-weight: 700; color: var(--ink); }
.compose-meta .sub { font-size: 13px; color: var(--ink-soft); display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.compose-meta .sub .pip { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-faint); }
.compose-meta .sub .pip.working { background: var(--yes); }
.compose-meta .sub .pip.warn { background: var(--no); }
.x-btn { width: 38px; height: 38px; border-radius: 50%; background: rgba(245,239,226,0.06); color: var(--ink-soft); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.x-btn:active { transform: scale(.9); }
.x-btn svg { width: 18px; height: 18px; stroke-width: 2.5; }
.compose-sheet textarea { width: 100%; min-height: 100px; max-height: 240px; padding: 14px 16px; border: 1px solid var(--hair); border-radius: 18px; background: rgba(245,239,226,0.04); color: var(--ink); font: inherit; font-size: 16px; line-height: 1.4; resize: none; outline: none; transition: border-color .15s; }
.compose-sheet textarea:focus { border-color: var(--accent); }
.compose-sheet .row { display: flex; gap: 12px; }
.compose-sheet .row .act { height: 56px; font-size: 15px; }

/* v4: per-agent history strip + file attach UX */
.hist { background: rgba(245,239,226,0.03); border: 1px solid var(--hair); border-radius: 14px; padding: 10px 14px; display: flex; flex-direction: column; gap: 6px; max-height: 180px; overflow-y: auto; }
.hist-h { font-size: 11px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 1.2px; font-weight: 700; margin-bottom: 4px; }
.hist-row { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink-soft); }
.hist-time { font-size: 11px; color: var(--ink-faint); font-variant-numeric: tabular-nums; min-width: 32px; flex-shrink: 0; }
.hist-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-faint); flex-shrink: 0; }
.hist-row.hist-commit .hist-dot { background: var(--accent); }
.hist-row.hist-fail   .hist-dot { background: var(--no); }
.hist-row.hist-tool   .hist-dot { background: var(--voice); }
.hist-row.hist-msg    .hist-dot { background: var(--yes); }
.hist-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-empty { color: var(--ink-faint); font-size: 13px; text-align: center; padding: 12px; }

.act.attach { background: rgba(245,239,226,0.08); color: var(--ink-soft); cursor: pointer; }
.attach-row { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 0; }
.attach-chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; }
.attach-chip em { color: var(--ink-faint); font-style: normal; font-weight: 500; }
