/* Tasks: Phase 1A prototype styles. Light/dark via CSS variables; status never relies on colour alone. */
:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f0f2f5; --text: #1b2330; --muted: #566174;
  --border: #d9dee6; --accent: #1f4e8c; --accent-text: #ffffff; --accent-soft: #e4edf9;
  --danger: #b3261e; --danger-soft: #fdeceb; --warn: #8a5300; --warn-soft: #fff3df;
  --ok: #1d6b3a; --ok-soft: #e6f4ea; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 2px 8px rgba(16,24,40,.05);
  --radius: 10px; --sidebar-w: 212px; --panel-w: 360px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #12161d; --surface: #1a2029; --surface-2: #232b37; --text: #e8ecf2; --muted: #a2adbd;
  --border: #323c4b; --accent: #7fb0f0; --accent-text: #0d1726; --accent-soft: #1f3250;
  --danger: #ff8a80; --danger-soft: #3a1f1d; --warn: #f3c26b; --warn-soft: #3a2d14;
  --ok: #7ddc9b; --ok-soft: #173424; --shadow: none; color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161d; --surface: #1a2029; --surface-2: #232b37; --text: #e8ecf2; --muted: #a2adbd;
    --border: #323c4b; --accent: #7fb0f0; --accent-text: #0d1726; --accent-soft: #1f3250;
    --danger: #ff8a80; --danger-soft: #3a1f1d; --warn: #f3c26b; --warn-soft: #3a2d14;
    --ok: #7ddc9b; --ok-soft: #173424; --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; } .skip:focus { left: 8px; top: 8px; background: var(--surface); padding: 8px; z-index: 99; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--muted); } .small { font-size: 13px; }
[hidden] { display: none !important; }

/* ---- layout ---- */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); height: 100vh; height: 100dvh; }
.app.panel-open { grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--panel-w); }
/* With the panel open, the list is narrower: the row actions drop under the title instead of squeezing it. */
.app.panel-open .row { flex-wrap: wrap; }
.app.panel-open .row-actions { order: 3; width: 100%; max-width: none; justify-content: flex-start; padding-left: 38px; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 14px 10px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.center { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.main { flex: 1; overflow-y: auto; padding: 20px 24px 80px; outline: none; }
.main-inner { max-width: 860px; margin: 0 auto; }
.panel { background: var(--surface); border-left: 1px solid var(--border); overflow-y: auto; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 24px; border-bottom: 1px solid var(--border); background: var(--surface); }
.search { flex: 1; max-width: 460px; }
.search input { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }

.brand { font-weight: 700; font-size: 17px; padding: 6px 10px 12px; display: flex; align-items: center; gap: 8px; }
.nav-btn, .ws-btn { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 9px 10px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; }
.nav-btn:hover, .ws-btn:hover { background: var(--surface-2); }
.nav-btn[aria-current="page"], .ws-btn[aria-pressed="true"] { background: var(--accent-soft); font-weight: 600; }
.nav-btn .count { margin-left: auto; background: var(--surface-2); border-radius: 99px; padding: 0 8px; font-size: 12px; }
.side-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 10px 4px; }
.ws-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding-top: 12px; }
.side-foot .btn { white-space: nowrap; }

.btn { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 7px 12px; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary kbd { background: transparent; color: inherit; border-color: currentColor; opacity: .85; margin-left: 4px; }
.linkish { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font-size: inherit; }
.check-line { display: flex; flex-direction: row; align-items: flex-start; gap: 8px; color: var(--text); font-size: 14px; }
.check-line input { width: auto; margin-top: 3px; flex: none; }
.danger-btn:not([disabled]) { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.sm { padding: 3px 9px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; cursor: pointer; padding: 6px 9px; border-radius: 8px; font-size: 16px; }
.icon-btn:hover { background: var(--surface-2); }

.pill { display: inline-flex; align-items: center; gap: 4px; border-radius: 99px; padding: 1px 9px; font-size: 12px; border: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.pill.proto { border-style: dashed; color: var(--muted); }
.save { font-size: 13px; min-width: 96px; text-align: right; color: var(--muted); }
.save.saving { color: var(--muted); } .save.saved { color: var(--ok); } .save.failed { color: var(--danger); font-weight: 600; }

/* ---- page heads, chips, cards ---- */
.page-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; }
.section { margin-top: 26px; }
.section > h2 { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.section > h2 .hint { font-weight: 400; color: var(--muted); font-size: 13px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 4px; }
.count-chip { border: 1px solid var(--border); background: var(--surface); border-radius: 99px; padding: 5px 14px; cursor: pointer; }
.count-chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.count-chip b { font-variant-numeric: tabular-nums; }
.count-chip.bad:not([aria-pressed="true"]) b { color: var(--danger); }
.ws-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; border-left: 4px solid var(--c); padding-left: 6px; }
.ws-chips { display: none; }
.banner { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; margin: 10px 0; background: var(--surface); }
.banner.warn { background: var(--warn-soft); border-color: var(--warn); color: var(--text); }
.banner.err { background: var(--danger-soft); border-color: var(--danger); }
.banner.ok { background: var(--ok-soft); border-color: var(--ok); }
.empty { text-align: center; padding: 36px 18px; color: var(--muted); }
.empty b { color: var(--text); display: block; margin-bottom: 4px; font-size: 16px; }

/* ---- task rows ---- */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.row.done .row-title { text-decoration: line-through; color: var(--muted); }
.row.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.row.kbd { outline: 2px dashed var(--accent); outline-offset: 2px; }
.row.sub { margin-left: 34px; padding: 8px 12px; background: var(--surface-2); }
.row-main { flex: 1; min-width: 0; cursor: pointer; }
.row-title { font-weight: 600; word-break: break-word; }
.row-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 3px; color: var(--muted); font-size: 13px; }
.row-reason { font-size: 13px; margin-top: 3px; color: var(--text); }
.row-reason.overdue { color: var(--danger); font-weight: 600; } .row-reason.due_today { color: var(--warn); font-weight: 600; }
.row-meta + .row-reason, .row-reason + .row-meta { margin-top: 3px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; align-items: flex-start; }
.move-select { padding: 4px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); max-width: 230px; }
.check { width: 26px; height: 26px; flex: none; border-radius: 7px; border: 2px solid var(--muted); background: var(--surface); cursor: pointer; display: grid; place-items: center; font-size: 14px; font-weight: 700; padding: 0; margin-top: 1px; }
.check:hover:not([disabled]) { border-color: var(--accent); background: var(--accent-soft); }
.check.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.check[disabled] { width: auto; min-width: 38px; padding: 0 6px; font-size: 12px; cursor: help; border-style: dashed; }
.badge { display: inline-flex; align-items: center; gap: 4px; border-radius: 6px; padding: 0 7px; font-size: 12px; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); margin-left: 6px; vertical-align: 1px; }
.badge.overdue { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.badge.waiting { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.badge.st-progress { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.badge.done { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.ddl { font-weight: 600; } .ddl.overdue { color: var(--danger); } .ddl.due_today { color: var(--warn); }
.warn-text { color: var(--warn); font-size: 13px; }

.rec { padding: 16px 18px; border-left: 6px solid var(--accent); }
.rec .label { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 4px; }
.rec .row-title { font-size: 19px; }
.rec .big-actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }

.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--border); min-width: 120px; }
.bar span { display: block; height: 100%; background: var(--ok); }
.proj-card { padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.proj-card.compact { padding: 10px 14px; gap: 6px; }
.bg-section { margin-top: 22px; } .bg-section > h2 { font-size: 14px; color: var(--muted); }
.add-form { display: flex; gap: 8px; margin-bottom: 10px; }
.add-form input { flex: 1; min-width: 0; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.proj-card .title { font-weight: 700; font-size: 16px; text-decoration: none; color: var(--text); cursor: pointer; background: none; border: 0; padding: 0; text-align: left; }
.proj-card .title:hover { text-decoration: underline; }
.proj-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 13px; align-items: center; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters select { padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); }

/* ---- details panel ---- */
.panel-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.panel-body { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.title-input { width: 100%; font-size: 18px; font-weight: 700; border: 1px solid transparent; border-radius: 8px; padding: 6px 8px; background: transparent; }
.title-input:hover, .title-input:focus { border-color: var(--border); background: var(--bg); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.field.full { grid-column: 1 / -1; }
.field input, .field select, .field textarea { color: var(--text); padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); width: 100%; }
.field textarea { min-height: 90px; resize: vertical; }
.note-slot:empty { display: none; }
.field-note { font-size: 12px; }
.field-note.saving { color: var(--muted); }
.field-note.failed { color: var(--danger); font-weight: 600; background: var(--danger-soft); border: 1px solid var(--danger); border-radius: 6px; padding: 3px 8px; display: block; }
.panel:focus { outline: none; }
details.more { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; }
details.more summary { cursor: pointer; font-weight: 600; }
details.more .grid2 { margin-top: 12px; }

/* ---- dialogs, menus, toasts ---- */
dialog { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); padding: 0; width: min(520px, calc(100vw - 24px)); box-shadow: 0 10px 40px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(10,14,20,.5); }
dialog form { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
dialog h2 { font-size: 18px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.form-error { background: var(--danger-soft); border: 1px solid var(--danger); border-radius: 8px; padding: 8px 12px; font-size: 14px; }
.menu { position: fixed; z-index: 60; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.25); padding: 6px; min-width: 200px; }
.menu button { display: block; width: 100%; text-align: left; padding: 9px 12px; border: 0; background: transparent; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--surface-2); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 80; width: min(520px, calc(100vw - 24px)); }
.toast { background: #1b2330; color: #fff; border-radius: 10px; padding: 10px 14px; display: flex; gap: 12px; align-items: center; box-shadow: 0 6px 24px rgba(0,0,0,.3); }
.toast.error { background: #8c1d18; }
.toast .btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.5); margin-left: auto; }
kbd { background: var(--surface-2); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; padding: 0 6px; font-size: 12px; }
table.keys { border-collapse: collapse; width: 100%; } table.keys td { padding: 5px 4px; border-bottom: 1px solid var(--border); }

.tabbar, .fab { display: none; }

/* ---- details panel below ~1200px: overlay the list instead of squeezing it ---- */
@media (min-width: 900px) and (max-width: 1199px) {
  :root { --sidebar-w: 188px; }
  .app.panel-open { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .panel { position: fixed; top: 61px; right: 0; bottom: 0; width: min(390px, calc(100vw - 80px)); z-index: 40; box-shadow: -8px 0 28px rgba(0,0,0,.22); } /* below the top bar, so Search, Save status and More stay visible */
  .side-foot kbd { display: none; }
}

/* ---- iPhone / narrow layout ---- */
@media (max-width: 899px) {
  .app, .app.panel-open { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { padding: 8px 12px; gap: 8px; }
  .topbar .proto { display: none; }
  .search { max-width: none; }
  .search input { font-size: 16px; }
  .main { padding: 12px 12px 130px; }
  .ws-chips { display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
  .ws-chips button { flex: none; border: 1px solid var(--border); background: var(--surface); border-radius: 99px; padding: 6px 12px; white-space: nowrap; cursor: pointer; }
  .ws-chips button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
  .row { flex-wrap: wrap; }
  .row-actions { max-width: none; width: 100%; justify-content: flex-start; padding-left: 38px; }
  .row.sub { margin-left: 14px; }
  .panel { position: fixed; inset: 0; z-index: 40; border-left: 0; }
  .grid2 { grid-template-columns: 1fr; }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); z-index: 30; }
  .tabbar button { flex: 1; border: 0; background: transparent; padding: 10px 4px 12px; font-size: 13px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; }
  .tabbar button[aria-current="page"] { color: var(--accent); font-weight: 700; }
  .tabbar .ico { font-size: 18px; }
  .fab { display: grid; place-items: center; position: fixed; right: 16px; bottom: calc(70px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-text); font-size: 30px; line-height: 1; box-shadow: 0 6px 18px rgba(0,0,0,.3); z-index: 31; cursor: pointer; }
  .toasts { bottom: 140px; }
  .check { width: 32px; height: 32px; }
  /* phone: 16px inputs (iOS Safari zooms the page on focus below 16px) and finger-sized targets */
  input, select, textarea, .title-input { font-size: 16px; }
  .btn { min-height: 40px; } .btn.sm { min-height: 40px; padding: 6px 12px; font-size: 14px; }
  .icon-btn { min-width: 44px; min-height: 44px; }
  .count-chip, .ws-chips button { min-height: 40px; }
  .menu button { padding: 12px 14px; }
  .field input, .field select, .field textarea { padding: 10px 11px; }
  .add-form input { padding: 11px 12px; }
  .row-actions { gap: 8px; }
  .toast .btn { min-height: 36px; }
}
@media (prefers-reduced-motion: no-preference) { .bar span { transition: width .3s; } }

/* ---- Sign-in screen ---- */
.login { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; background: var(--bg); padding: 16px; overflow-y: auto; }
.login[hidden] { display: none; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 24px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.08); }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card .field input { font-size: 16px; padding: 10px 12px; }
.login-card .btn { min-height: 44px; font-size: 16px; justify-content: center; }
.login-note { margin: 0; color: var(--muted); font-size: 14px; }
.login-note:empty, .login-err:empty { display: none; }
.login-err { margin: 0; color: var(--danger); background: var(--danger-soft); border: 1px solid var(--danger); border-radius: 8px; padding: 8px 10px; font-size: 14px; font-weight: 600; }
body.locked { overflow: hidden; }

/* ---- Settings ---- */
.set-card { padding: 14px 16px; margin-bottom: 14px; }
.set-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.set-head h2 { margin: 0; font-size: 17px; }
.set-list { list-style: none; margin: 0; padding: 0; }
.set-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.set-row:first-child { border-top: 0; }
.set-ico { font-size: 20px; width: 26px; text-align: center; }
.set-main { flex: 1 1 180px; min-width: 0; display: flex; flex-direction: column; }
.set-main b { overflow-wrap: anywhere; }
.set-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.set-actions .icon-btn[disabled] { opacity: .35; cursor: default; }
.set-arch { margin-top: 10px; border-top: 1px dashed var(--border); padding-top: 8px; }
.set-arch summary { cursor: pointer; font-weight: 600; color: var(--muted); padding: 6px 0; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.sw-col { width: 28px; height: 28px; border-radius: 50%; background: var(--c); border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border); cursor: pointer; }
.sw-ico { font-size: 18px; min-width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; }
.sw-ico:hover, .sw-col:hover { outline: 2px solid var(--accent); }
.plain-list { margin: 6px 0 10px; padding-left: 18px; }
.plain-list li { margin: 2px 0; }
@media (max-width: 899px) { .set-actions .btn.sm, .set-actions .icon-btn { min-height: 40px; } .set-actions { justify-content: flex-start; width: 100%; } }

/* ---- Inbox chips / Done ---- */
.inbox-chip { display: inline-flex; align-items: center; gap: 6px; }
.inbox-chip.attn:not([aria-pressed="true"]) { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.inbox-chip.attn:not([aria-pressed="true"]) b { background: var(--accent); color: var(--accent-text); border-radius: 99px; padding: 0 7px; }
.done-day h2 { font-size: 14px; color: var(--muted); text-transform: none; letter-spacing: 0; }
.done-proj { margin: 8px 0; }

.restore-result { margin: 10px 0; font-size: 14px; }
.restore-result:empty { display: none; }
.restore-result.good { background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 8px; padding: 8px 10px; }
.restore-result.bad { background: var(--danger-soft); border: 1px solid var(--danger); border-radius: 8px; padding: 8px 10px; color: var(--text); }
.linklike { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font: inherit; }
