:root {
  --brand: #1d5bfa;
  --brand-ink: #0c3ec9;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --ink: #141a24;
  --muted: #667085;
  --line: #e6e9f0;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 6px 20px rgba(16, 24, 40, .06);
  --radius: 16px;
  --ok: #12b76a;
  --warn: #f79009;
  --wait: #7a5af8;
  --danger: #e5484d;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1c2430;
    --ink: #e6edf3;
    --muted: #9aa4b2;
    --line: #263040;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* must win over .login/.app/.drawer display rules */
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}

.muted { color: var(--muted); }
.bolt { color: var(--brand); }

/* Buttons */
.btn { border: 0; border-radius: 12px; padding: 10px 16px; font-size: 15px; font-weight: 600; cursor: pointer; background: var(--surface-2); color: var(--ink); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:active { background: var(--brand-ink); }
.icon-btn { border: 0; background: transparent; font-size: 20px; cursor: pointer; padding: 6px; border-radius: 10px; position: relative; color: var(--ink); }
.icon-btn:hover { background: var(--surface-2); }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card { background: var(--surface); border-radius: 24px; box-shadow: var(--shadow); padding: 40px 32px; text-align: center; max-width: 360px; width: 100%; }
.login-card .brand { font-size: 30px; font-weight: 800; margin-bottom: 4px; }
.login-card .btn { margin-top: 18px; display: inline-block; text-decoration: none; }
.fineprint { font-size: 12px; color: var(--muted); margin-top: 14px; }

/* App shell */
.app { max-width: 720px; margin: 0 auto; padding: calc(var(--safe-top) + 8px) 16px calc(var(--safe-bottom) + 40px); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 2px 12px; }
.title { font-size: 22px; font-weight: 800; }
.dateline { font-size: 13px; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 6px; }
.local-toggle { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); background: var(--surface-2); padding: 6px 9px; border-radius: 999px; cursor: pointer; user-select: none; }
.local-toggle input { accent-color: var(--brand); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: #fff; font-weight: 700; font-size: 14px; display: grid; place-items: center; border: 0; cursor: pointer; }
.badge-count { position: absolute; top: -2px; right: -2px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; border-radius: 999px; padding: 1px 5px; }

/* Capture */
.capture { display: flex; gap: 8px; align-items: center; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px; position: sticky; top: calc(var(--safe-top) + 4px); z-index: 20; }
.capture-input { flex: 1; border: 0; background: transparent; font-size: 16px; padding: 10px 8px; color: var(--ink); outline: none; }
.mic.recording { color: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.18); } }
.voice-hint { font-size: 12px; color: var(--muted); padding: 8px 6px 0; }

/* Sections */
.main { margin-top: 16px; }
.section { margin-bottom: 22px; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 4px 10px; display: flex; align-items: center; gap: 8px; }
.section-title.toggle { cursor: pointer; }
.count { background: var(--surface-2); color: var(--muted); font-size: 11px; padding: 1px 8px; border-radius: 999px; }
.chev { margin-left: auto; transition: transform .15s; }
.collapsible:not(.collapsed) .chev { transform: rotate(90deg); }
.collapsible.collapsed .list { display: none; }

/* Cards */
.list { display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 14px 10px; border: 1px solid transparent; transition: opacity .2s; }
.card.done { opacity: .55; }
.card.working { border-color: color-mix(in srgb, var(--brand) 40%, transparent); }
.card-title { font-size: 16px; font-weight: 600; outline: none; }
.card-title[contenteditable]:focus { border-bottom: 1px dashed var(--line); }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { font-size: 12px; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.chip.person { background: color-mix(in srgb, var(--wait) 15%, transparent); color: var(--wait); font-weight: 600; }
.chip.working { background: color-mix(in srgb, var(--brand) 15%, transparent); color: var(--brand); font-weight: 600; }
.chip.assigned { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); font-weight: 600; }
.chip.hive { background: color-mix(in srgb, var(--brand) 12%, transparent); color: var(--brand); cursor: pointer; }
.chip.link { cursor: pointer; text-decoration: underline; }
.note { font-size: 13px; color: var(--muted); margin-top: 6px; }

/* Action buttons */
.actions { display: flex; gap: 4px; margin-top: 10px; flex-wrap: wrap; }
.act { flex: 1 1 auto; min-width: 44px; border: 0; background: var(--surface-2); border-radius: 10px; padding: 8px 6px; font-size: 17px; cursor: pointer; display: grid; place-items: center; gap: 2px; }
.act:hover { background: color-mix(in srgb, var(--brand) 10%, var(--surface-2)); }
.act small { font-size: 10px; color: var(--muted); font-weight: 600; }
.act.done:hover { background: color-mix(in srgb, var(--ok) 18%, transparent); }
.act.claude:hover { background: color-mix(in srgb, var(--brand) 18%, transparent); }
.act.waiting:hover { background: color-mix(in srgb, var(--wait) 18%, transparent); }

/* Inline mini-form (assign / waiting) */
.miniform { display: flex; gap: 6px; margin-top: 10px; }
.miniform input { flex: 1; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 14px; background: var(--surface-2); color: var(--ink); }
.miniform .btn { padding: 8px 12px; }

/* Dashboard */
#sec-dashboard { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
#sec-dashboard .section-title { margin: 0 0 8px; }
.dash-group { margin-top: 10px; }
.dash-group:first-of-type { margin-top: 4px; }
.dash-group h3 { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 4px; }
.dash-item { padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.dash-item:last-child { border-bottom: none; }
.dash-item b { font-weight: 600; }
.dash-item small { display: block; color: var(--muted); font-size: 12px; margin-top: 1px; }
.dash-empty { color: var(--muted); font-size: 13px; padding: 4px 0; }
#dashboardRefreshBtn[disabled] { opacity: .5; cursor: default; }
.dash-stale { color: var(--warn); }

/* Empty */
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty-emoji { font-size: 40px; }

/* Activity drawer */
.drawer { position: fixed; top: 0; right: 0; height: 100dvh; width: min(440px, 92vw); background: var(--surface); box-shadow: var(--shadow); z-index: 60; display: flex; flex-direction: column; transform: translateX(0); }
.drawer[hidden] { display: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid var(--line); }
.activity-list { overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.job { border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.job-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.job-title { font-weight: 600; font-size: 14px; }
.job-status { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; text-transform: uppercase; }
.st-queued { background: var(--surface-2); color: var(--muted); }
.st-running { background: color-mix(in srgb, var(--brand) 16%, transparent); color: var(--brand); }
.st-needs-attention { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.st-done { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.st-failed { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.job-log { margin-top: 8px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; color: var(--muted); white-space: pre-wrap; max-height: 180px; overflow: auto; background: var(--surface-2); border-radius: 8px; padding: 8px; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 55; }
.scrim[hidden] { display: none; }

/* Account menu */
.menu { position: fixed; top: 58px; right: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); z-index: 70; display: flex; flex-direction: column; min-width: 210px; overflow: hidden; }
.menu button { text-align: left; background: transparent; border: 0; padding: 12px 14px; font-size: 14px; cursor: pointer; color: var(--ink); }
.menu button:hover { background: var(--surface-2); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 75; display: grid; place-items: center; padding: 20px; }
.modal-card { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); width: min(640px, 96vw); max-height: 85vh; display: flex; flex-direction: column; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 8px 20px 20px; overflow: auto; }
.modal-body h1 { font-size: 20px; margin: 14px 0 6px; }
.modal-body h2 { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 18px 0 6px; }
.modal-body ul { padding-left: 20px; margin: 6px 0; }
.modal-body li { margin: 3px 0; }
.modal-body p { margin: 6px 0; }
.modal-body blockquote { border-left: 3px solid var(--line); margin: 12px 0; padding: 4px 12px; color: var(--muted); font-size: 13px; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 20px); transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 80; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
