/* AI Task Board — design tokens, themes and responsive layout (spec 0002 §7.1). */

:root {
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Consolas, monospace;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fbfbfc;
  --column: #eef0f4;
  --text: #1b1f27;
  --text-2: #333a47;
  --muted: #5b6475;
  --border: #e3e6ec;
  --border-strong: #d5d9e2;
  --accent: #3b5bdb;
  --accent-strong: #2f4ac0;
  --accent-text: #ffffff;
  --accent-soft: #eef1fb;
  --accent-soft-text: #2f3f8f;
  --warn-soft: #fff4db;
  --warn-text: #7a4f00;
  --warn-border: #f1dfae;
  --ok-soft: #eaf5ea;
  --ok-text: #2a6b2d;
  --ok-border: #cfe6cf;
  --danger-soft: #fff6f3;
  --danger-text: #a3321a;
  --danger-border: #f0c4b8;
  --chip: #f1f3f6;
  --overlay: rgba(20, 24, 33, .32);
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-lg: -16px 0 40px rgba(20, 24, 33, .12);

  --h-claude: #fdf0e7; --h-claude-t: #8f4511;
  --h-codex: #e8f4f2;  --h-codex-t: #1c5a51;
  --h-deepseek: #f3eefc; --h-deepseek-t: #55368f;

  --r-sm: 6px; --r: 10px; --r-lg: 14px;
  --gap: 16px;
  --tap: 44px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #121419;
  --surface: #1a1d24;
  --surface-2: #15171d;
  --column: #171a20;
  --text: #e7e9ee;
  --text-2: #c9ced8;
  --muted: #9aa1ae;
  --border: #2c313c;
  --border-strong: #3a404c;
  --accent: #8ea2ff;
  --accent-strong: #b3c0ff;
  --accent-text: #10142a;
  --accent-soft: #232a45;
  --accent-soft-text: #c3cdff;
  --warn-soft: #2e2512;
  --warn-text: #f2c66b;
  --warn-border: #5a4718;
  --ok-soft: #17251a;
  --ok-text: #8fd59a;
  --ok-border: #284a2e;
  --danger-soft: #2a1916;
  --danger-text: #ff9c86;
  --danger-border: #4a2a24;
  --chip: #22262f;
  --overlay: rgba(0, 0, 0, .55);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: -16px 0 40px rgba(0, 0, 0, .45);
  --h-claude: #2b2420; --h-claude-t: #f0b48a;
  --h-codex: #18282a;  --h-codex-t: #86d3c4;
  --h-deepseek: #251f33; --h-deepseek-t: #c7b0f2;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121419; --surface: #1a1d24; --surface-2: #15171d; --column: #171a20;
    --text: #e7e9ee; --text-2: #c9ced8; --muted: #9aa1ae; --border: #2c313c; --border-strong: #3a404c;
    --accent: #8ea2ff; --accent-strong: #b3c0ff; --accent-text: #10142a; --accent-soft: #232a45; --accent-soft-text: #c3cdff;
    --warn-soft: #2e2512; --warn-text: #f2c66b; --warn-border: #5a4718;
    --ok-soft: #17251a; --ok-text: #8fd59a; --ok-border: #284a2e;
    --danger-soft: #2a1916; --danger-text: #ff9c86; --danger-border: #4a2a24;
    --chip: #22262f; --overlay: rgba(0, 0, 0, .55);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); --shadow-lg: -16px 0 40px rgba(0, 0, 0, .45);
    --h-claude: #2b2420; --h-claude-t: #f0b48a; --h-codex: #18282a; --h-codex-t: #86d3c4;
    --h-deepseek: #251f33; --h-deepseek-t: #c7b0f2;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
a:hover { color: var(--accent-strong); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mono { font-family: var(--mono); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* Controls */
.btn {
  min-height: 40px; padding: 0 14px; border: 1px solid var(--border-strong); border-radius: var(--r);
  background: var(--surface); color: var(--text-2); cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  font-size: 14px; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.danger { background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger-text); font-weight: 600; }
.btn.icon { width: 40px; padding: 0; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.field { display: grid; gap: 6px; font-size: 12px; color: var(--muted); }
.input, .field input, .field select, .field textarea, .reply textarea {
  width: 100%; min-height: 40px; padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: var(--r);
  background: var(--surface-2); color: var(--text); font-size: 14px;
}
textarea { resize: vertical; min-height: 72px; }
.row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); min-height: 32px; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: var(--r-sm); background: var(--chip); color: var(--text-2); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.project { background: var(--accent-soft); color: var(--accent-soft-text); }
.chip.h-claude-code { background: var(--h-claude); color: var(--h-claude-t); }
.chip.h-codex { background: var(--h-codex); color: var(--h-codex-t); }
.chip.h-deepseek { background: var(--h-deepseek); color: var(--h-deepseek-t); }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; padding: 3px 10px; border-radius: 999px; background: var(--chip); color: var(--text-2); }
.pill.run { background: var(--accent-soft); color: var(--accent-soft-text); }
.pill.wait { background: var(--warn-soft); color: var(--warn-text); }
.pill.ok { background: var(--ok-soft); color: var(--ok-text); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.dot.pulse { animation: pulse 1.6s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* App shell */
.topbar {
  position: sticky; top: 0; z-index: 5; height: 64px; padding: 0 24px; display: flex; align-items: center; gap: 12px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; white-space: nowrap; margin: 0; }
.search { flex: 1; min-width: 180px; max-width: 420px; position: relative; }
.search input { padding-left: 34px; }
.search svg { position: absolute; left: 11px; top: 12px; color: var(--muted); }
.project-filter { min-height: 40px; border: 1px solid var(--border-strong); border-radius: var(--r); background: var(--surface); padding: 0 10px; color: var(--text-2); }
.spacer { flex: 1; }
.runner-status { font-size: 12px; white-space: nowrap; }

/* Status tabs (phone) */
.status-tabs { display: none; gap: 6px; padding: 10px 16px; overflow-x: auto; scrollbar-width: none; }
.status-tabs button {
  flex: none; min-height: 36px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.status-tabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }

/* Board */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(240px, 1fr); gap: var(--gap); padding: 20px 24px; align-items: start; }
.column { background: var(--column); border-radius: var(--r-lg); padding: 12px; display: flex; flex-direction: column; gap: 10px; min-height: 160px; }
.column.drop { outline: 2px dashed var(--accent); outline-offset: -2px; }
.column h2 { margin: 2px 4px 2px; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); display: flex; justify-content: space-between; }
.column .empty { font-size: 13px; color: var(--muted); padding: 8px 4px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px;
  box-shadow: var(--shadow); cursor: pointer; text-align: left; width: 100%; color: inherit; transition: box-shadow .15s ease;
  -webkit-touch-callout: none; user-select: none;
}
.card:hover { box-shadow: 0 6px 16px rgba(20, 24, 33, .1); }
.card.running { border: 2px solid var(--accent); padding: 11px 13px; }
.card.dragging { opacity: .4; }
.card .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.card .title { font-weight: 600; font-size: 14px; line-height: 1.35; overflow-wrap: anywhere; }
.card .meta { display: flex; flex-wrap: wrap; gap: 6px; }
.card .question { font-size: 13px; background: var(--warn-soft); color: var(--text); border-radius: 8px; padding: 8px 10px; line-height: 1.4; }
.card .summary { font-size: 13px; color: var(--muted); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.drop-marker { height: 3px; background: var(--accent); border-radius: 2px; }
.board-state { padding: 48px 24px; text-align: center; color: var(--muted); }
.fab { display: none; }

/* Task panel */
.overlay { position: fixed; inset: 0; background: var(--overlay); z-index: 8; }
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 100vw); z-index: 9; background: var(--surface);
  border-left: 1px solid var(--border); box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
  animation: slide-in .18s ease-out;
}
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.panel-head { padding: 16px 20px 0; display: flex; flex-direction: column; gap: 10px; }
.panel-head .bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.panel-head h1 { margin: 0; font-size: 20px; line-height: 1.3; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-top: 2px; }
.tabs button { min-height: 44px; padding: 0 12px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--muted); cursor: pointer; font-size: 14px; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.panel-body { flex: 1; overflow-y: auto; padding: 16px 20px; background: var(--surface-2); }
.panel-body.form-body { background: var(--surface); display: grid; gap: 12px; align-content: start; }
.panel-body h3 { margin: 12px 0 0; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* Conversation */
.feed { display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 86%; padding: 10px 14px; font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-radius: 14px 14px 4px 14px; white-space: pre-wrap; }
.msg.agent { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-radius: 14px 14px 14px 4px; }
.md p { margin: 0 0 6px; } .md p:last-child { margin: 0; }
.md ul, .md ol { margin: 4px 0 6px; padding-left: 20px; }
.md pre { background: var(--chip); border-radius: 8px; padding: 8px 10px; overflow-x: auto; font: 12px/1.45 var(--mono); }
.md code { font: 12.5px var(--mono); background: var(--chip); padding: 1px 4px; border-radius: 4px; }
.md pre code { background: none; padding: 0; }
.who { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.tool { align-self: flex-start; max-width: 92%; border: 1px solid var(--border); background: var(--surface); border-radius: var(--r); font-size: 13px; }
.tool summary { min-height: 36px; padding: 6px 10px; cursor: pointer; display: flex; align-items: center; gap: 8px; list-style: none; }
.tool summary::-webkit-details-marker { display: none; }
.tool .name { font-family: var(--mono); font-weight: 500; }
.tool .arg { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 46ch; }
.tool .st-ok { color: var(--ok-text); font-weight: 600; } .tool .st-err { color: var(--danger-text); font-weight: 600; }
.tool pre { margin: 0; border-top: 1px solid var(--border); padding: 8px 10px; max-height: 260px; overflow: auto; font: 12px/1.45 var(--mono); white-space: pre-wrap; }
.file { align-self: flex-start; font-size: 12px; color: var(--muted); font-family: var(--mono); }
.result { border-radius: 12px; padding: 12px 14px; font-size: 14px; line-height: 1.5; border: 1px solid var(--ok-border); background: var(--ok-soft); }
.result.wait { border-color: var(--warn-border); background: var(--warn-soft); }
.result.fail { border-color: var(--danger-border); background: var(--danger-soft); }
.result .label { font-size: 11px; font-weight: 700; letter-spacing: .04em; margin-bottom: 4px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; text-align: center; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border-strong); }
.linklike { border: 0; background: none; color: var(--accent); cursor: pointer; font-size: 12px; text-decoration: underline; padding: 0; }
.typing { font-size: 12px; color: var(--accent); display: flex; align-items: center; gap: 6px; }
.err-line { font-size: 13px; color: var(--danger-text); }
.handoff { white-space: pre-wrap; font: 12px/1.45 var(--mono); background: var(--chip); border-radius: var(--r); padding: 10px; max-height: 360px; overflow: auto; }

.reply { border-top: 1px solid var(--border); padding: 12px 20px 16px; display: grid; gap: 10px; background: var(--surface); }
.reply .opts { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.reply select { min-height: 36px; border: 1px solid var(--border-strong); border-radius: 9px; background: var(--surface); padding: 0 8px; }
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.history li { border: 1px solid var(--border); border-radius: var(--r); padding: 8px 12px; background: var(--surface); overflow-wrap: anywhere; }
.when { font-size: 12px; color: var(--muted); }
.secret { background: var(--chip); border-radius: var(--r); padding: 8px 10px; white-space: pre-wrap; word-break: break-all; font: 12px var(--mono); }
.empty-state { color: var(--muted); font-size: 13px; text-align: center; padding: 24px 8px; }

/* Sheet */
.sheet {
  position: fixed; z-index: 11; left: 50%; bottom: 0; transform: translateX(-50%); width: min(480px, 100vw);
  background: var(--surface); border-radius: 22px 22px 0 0; padding: 10px 16px 20px; display: grid; gap: 6px; box-shadow: 0 -12px 40px rgba(0, 0, 0, .25);
  animation: sheet-in .18s ease-out;
}
@keyframes sheet-in { from { transform: translate(-50%, 24px); opacity: 0; } to { transform: translateX(-50%); opacity: 1; } }
.sheet .grip { width: 40px; height: 5px; border-radius: 3px; background: var(--border-strong); justify-self: center; margin-bottom: 6px; }
.sheet h2 { margin: 0 0 6px; font-size: 18px; }
.sheet .opt { min-height: 52px; border: 0; border-radius: 12px; background: transparent; text-align: left; padding: 0 12px; display: flex; align-items: center; gap: 12px; font-size: 16px; cursor: pointer; color: var(--text); }
.sheet .opt[aria-current="true"] { background: var(--chip); }
.sheet .opt .now { margin-left: auto; font-size: 13px; color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--r); max-width: calc(100vw - 32px); }

/* Login */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 28px; display: grid; gap: 16px; box-shadow: var(--shadow); }
.login-card h1 { margin: 0; font-size: 20px; }
.form { display: grid; gap: 12px; }
.error { color: var(--danger-text); font-size: 13px; margin: 0; }

/* Tablet */
@media (max-width: 1199px) {
  .board { grid-auto-columns: calc((100vw - 48px - var(--gap)) / 2); overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding: 0 24px; }
  .column { scroll-snap-align: start; }
  .panel { width: max(60vw, 460px); }
  .runner-status { display: none; }
}

/* Phone */
@media (max-width: 767px) {
  .topbar { height: 60px; padding: 0 12px 0 16px; }
  .search, .project-filter, .topbar .new-task, .topbar .theme { display: none; }
  .topbar.searching .search { display: block; position: absolute; left: 12px; right: 68px; top: 10px; max-width: none; }
  .btn.icon { width: var(--tap); min-height: var(--tap); }
  .status-tabs { display: flex; }
  .board { display: block; padding: 0 16px 96px; overflow: visible; }
  .column { background: none; padding: 0; min-height: 0; }
  .column:not(.current) { display: none; }
  .column h2 { display: none; }
  .card { padding: 14px 16px; border-radius: 16px; }
  .card .title { font-size: 16px; }
  .fab { display: grid; place-items: center; position: fixed; right: 16px; bottom: 20px; width: 56px; height: 56px; border: 0; border-radius: 18px; background: var(--accent); color: var(--accent-text); box-shadow: 0 10px 24px rgba(0, 0, 0, .3); z-index: 6; cursor: pointer; }
  .panel { width: 100vw; border: 0; animation: none; }
  .panel-head h1 { font-size: 17px; }
  .row { grid-template-columns: 1fr; }
  .msg { max-width: 90%; }
  .reply { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
}
@media (min-width: 768px) { .search-toggle { display: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.contents { display: contents; }
.brand-mark { color: var(--accent); }
