:root {
  --paper: #f6f7f9; --surface: #ffffff; --surface-2: #eef1f4;
  --ink: #1a2230; --ink-soft: #55606f; --ink-faint: #8a94a2;
  --line: #dfe4ea; --line-soft: #eceff3;
  --accent: #0d7a72; --accent-soft: #d8efec; --accent-ink: #ffffff;
  --good: #1f9d57; --warn: #b8860b; --crit: #c0392b; --gold: #b8860b;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0f141b; --surface: #161d27; --surface-2: #1f2836;
    --ink: #e6ebf1; --ink-soft: #a3adba; --ink-faint: #6b7686;
    --line: #26313f; --line-soft: #1c2531;
    --accent: #2bb3a6; --accent-soft: #123b39; --accent-ink: #06120f;
    --good: #35c46f; --warn: #e0a92b; --crit: #e5695c; --gold: #e0a92b;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; font-size: 14px; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; color: var(--ink); }
a { color: var(--accent); }

/* login */
.login { max-width: 340px; margin: 12vh auto; background: var(--surface);
  border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.login h1 { font-size: 18px; margin: 0 0 4px; }
.login p { color: var(--ink-faint); margin: 0 0 18px; font-size: 13px; }
.login input { width: 100%; padding: 10px 12px; margin-bottom: 10px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); }
.btn { background: var(--accent); color: var(--accent-ink); border: 0;
  padding: 10px 16px; border-radius: 9px; font-weight: 600; }
.btn.ghost { background: transparent; color: var(--ink-soft); border: 1px solid var(--line); }
.btn.sm { padding: 6px 12px; font-size: 12.5px; }
.err { color: var(--crit); font-size: 12.5px; min-height: 16px; }

/* layout */
.shell { display: grid; grid-template-columns: 260px 1fr; height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; overflow: hidden; }
.side-h { padding: 14px 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; }
.side-h b { font-size: 14px; }
.wslist { overflow-y: auto; flex: 1; }
.wsitem { padding: 11px 16px; border-bottom: 1px solid var(--line-soft); cursor: pointer; }
.wsitem:hover { background: var(--surface-2); }
.wsitem.sel { background: var(--accent-soft); }
.wsitem .n { font-weight: 600; }
.wsitem .m { font-size: 12px; color: var(--ink-faint); }
.side-f { padding: 12px 16px; border-top: 1px solid var(--line); }
.side-f .who { font-size: 12px; color: var(--ink-faint); margin-bottom: 8px; }

.main { overflow-y: auto; }
.topbar { padding: 12px 22px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px; background: var(--surface); position: sticky; top: 0; z-index: 2; }
.topbar h2 { font-size: 16px; margin: 0; }
.tabs { display: flex; gap: 6px; }
.tab { padding: 6px 14px; border-radius: 8px; border: 1px solid transparent;
  background: transparent; color: var(--ink-soft); font-weight: 600; font-size: 13px; }
.tab.sel { background: var(--accent-soft); color: var(--accent); }
.pad { padding: 22px; }
.muted { color: var(--ink-faint); }
.empty { color: var(--ink-faint); text-align: center; margin-top: 18vh; }

/* prompt editor */
.grid { display: grid; grid-template-columns: 1fr 300px; gap: 20px; align-items: start; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.field textarea { width: 100%; min-height: 76px; padding: 10px 12px; resize: vertical;
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface); line-height: 1.5; }
.field textarea.big { min-height: 180px; }
.charcount { margin-top: 4px; font-size: 11px; color: var(--ink-soft); text-align: right;
  font-variant-numeric: tabular-nums; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.card h3 { margin: 0 0 10px; font-size: 13px; }
.vrow { display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.vrow:last-child { border-bottom: 0; }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.pill.gold { background: var(--accent-soft); color: var(--accent); }

/* chat */
.chatwrap { display: grid; grid-template-columns: 240px 1fr; gap: 18px; align-items: start; }
.chatlist .card { padding: 0; overflow: hidden; }
.citem { padding: 10px 14px; border-bottom: 1px solid var(--line-soft); cursor: pointer; font-size: 13px; }
.citem:hover { background: var(--surface-2); }
.citem.sel { background: var(--accent-soft); }
.thread { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.msg { max-width: 78%; padding: 10px 13px; border-radius: 12px; line-height: 1.5; white-space: pre-wrap; }
.msg .meta { font-size: 11px; color: var(--ink-faint); margin-bottom: 4px; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.user .meta { color: rgba(255,255,255,.7); }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg .foot { display: flex; gap: 10px; align-items: center; margin-top: 7px; font-size: 11px; color: var(--ink-faint); font-family: var(--mono); }
.rate { border: 1px solid var(--line); background: transparent; border-radius: 6px; padding: 1px 7px; font-size: 12px; color: var(--ink-soft); }
.rate.on-up { border-color: var(--good); color: var(--good); }
.rate.on-down { border-color: var(--crit); color: var(--crit); }
.chatsum { font-size: 12px; color: var(--ink-faint); font-family: var(--mono);
  padding: 2px 2px 12px; border-bottom: 1px solid var(--line-soft); margin-bottom: 14px;
  display: flex; gap: 8px; flex-wrap: wrap; }
.chatsum b { color: var(--ink-soft); font-weight: 600; }
.composer { display: flex; gap: 10px; position: sticky; bottom: 0; padding-top: 8px; background: var(--paper); }
.composer textarea { flex: 1; min-height: 46px; max-height: 160px; padding: 11px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); resize: vertical; }
select, .inp { padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.bar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.spacer { flex: 1; }

.btn:disabled { opacity: .55; cursor: default; }
.btn.danger { background: var(--crit); color: #fff; }
.btn.ghost.danger-text { color: var(--crit); }

/* typing indicator */
.msg.pending { color: var(--ink-faint); }
.typing { display: inline-flex; gap: 5px; align-items: center; height: 16px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-faint);
  animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .typing i { animation: none; opacity: .5; } }

/* compare */
.ckrow { display: flex; flex-wrap: wrap; gap: 14px; }
.ckbox { display: flex; gap: 6px; align-items: center; font-size: 13px; cursor: pointer; }
.cmpgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 14px; }
.cmpcol { display: flex; flex-direction: column; }
.cmphead { font-family: var(--mono); font-size: 12px; color: var(--accent); font-weight: 600; margin-bottom: 8px; }
.cmpbody { white-space: pre-wrap; line-height: 1.5; font-size: 13px; flex: 1; }
.cmpmetr { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line-soft);
  font-family: var(--mono); font-size: 11px; color: var(--ink-faint); }
.cmperr { color: var(--crit); font-size: 13px; }

/* lead assessment */
.leadbox { margin-top: 8px; border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 11px; background: var(--surface-2); width: 100%; font-size: 12.5px; }
.leadhead { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.temp { font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 999px; text-transform: uppercase; letter-spacing: .03em; }
.temp-cold { background: rgba(90,120,160,.18); color: #5f7fb0; }
.temp-warm { background: var(--warn-soft); color: var(--warn); }
.temp-hot { background: var(--crit-soft); color: var(--crit); }
.handoff { margin: 6px 0; padding: 7px 10px; border-radius: 7px; font-weight: 700;
  background: var(--crit-soft); color: var(--crit); font-size: 13px; }
.leadcard { margin-top: 6px; display: flex; flex-direction: column; gap: 2px; }
.lrow { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; }
.lrow span { color: var(--ink-faint); }
.lrow b { color: var(--ink-soft); text-align: right; }
.nextstep { margin-top: 7px; color: var(--ink-soft); font-style: italic; }
.msg.assistant:has(.leadbox) { max-width: 88%; }

/* prompt inspector */
.promptbox { margin-top: 8px; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 9px; padding: 10px 12px; max-height: 340px; overflow: auto; width: 100%; }
.pbhint { font-size: 11px; color: var(--ink-faint); margin-bottom: 6px; }
.pmrow b { display: block; font-size: 10px; letter-spacing: .05em; color: var(--accent);
  margin: 8px 0 3px; }
.pmrow div { font-size: 12.5px; line-height: 1.5; white-space: pre-wrap;
  font-family: var(--mono); color: var(--ink-soft); }
.msg.assistant:has(.promptbox:not([hidden])) { max-width: 92%; }

/* modal confirm */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex;
  align-items: center; justify-content: center; z-index: 50; }
.modal { background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 22px; max-width: 400px; width: 90%; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal h3 { margin: 0 0 8px; font-size: 15px; }
.modal p { margin: 0 0 18px; line-height: 1.5; color: var(--ink-soft); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 11px 16px; border-radius: 10px;
  font-size: 13px; z-index: 60; box-shadow: 0 8px 24px rgba(0,0,0,.3); max-width: 80%; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .grid, .chatwrap { grid-template-columns: 1fr; }
}
