:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --line: #e3e6eb;
  --accent: #1f5fbf;
  --accent-hover: #184c99;
  --row-hover: #f1f5fc;
  --new-row: #fff6d6;
  --error: #b42318;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --panel: #1c2027;
    --text: #e6e8eb;
    --muted: #9aa3ae;
    --line: #2c323b;
    --accent: #5b9bf0;
    --accent-hover: #7cb0f5;
    --row-hover: #232a35;
    --new-row: #3a3420;
    --error: #f97066;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
}

.topbar {
  display: flex; align-items: center; gap: 28px;
  padding: 0 20px; height: 48px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .2px; }
.brand span { font-weight: 400; color: var(--muted); }
.topbar nav a {
  color: var(--muted); text-decoration: none; padding: 14px 2px;
  border-bottom: 2px solid transparent;
}
.topbar nav a.active { color: var(--text); border-bottom-color: var(--accent); }

main { padding: 16px 20px 40px; }

/* Quick Add */
.quick-add {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 14px; margin-bottom: 16px;
}
.qa-label { display: block; font-weight: 600; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
kbd {
  font: 11px "Segoe UI", sans-serif; border: 1px solid var(--line); border-radius: 3px;
  padding: 0 4px; background: var(--bg);
}
textarea, input, select, button { font: inherit; color: inherit; }
#qa-text {
  width: 100%; resize: none; overflow: hidden; min-height: 40px; max-height: 50vh;
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg);
}
#qa-text:focus, .qa-row input:focus, .qa-row select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.qa-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.qa-row select, .qa-row input {
  height: 32px; padding: 0 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel);
}
.qa-row select { min-width: 200px; }
.qa-row input[name=customer] { min-width: 200px; }
button.primary {
  height: 32px; padding: 0 18px; border: 0; border-radius: 6px;
  background: var(--accent); color: #fff; font-weight: 600; cursor: pointer;
}
button.primary:hover { background: var(--accent-hover); }
button.primary:disabled { opacity: .6; cursor: default; }
.hint { color: var(--muted); font-size: 12px; margin-left: auto; }
.error { color: var(--error); margin-top: 6px; }

/* Toolbar: search and filters */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.toolbar input, .toolbar select {
  height: 32px; padding: 0 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel);
}
.toolbar input:focus, .toolbar select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.toolbar .search { flex: 1 1 260px; min-width: 200px; }
.toolbar select { max-width: 220px; }
.toolbar .range { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.toolbar .range[hidden] { display: none; }
.toolbar .count { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.snippet { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
mark { background: #ffe58a; color: #1d2330; border-radius: 2px; padding: 0 1px; }
button.sort {
  background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer;
}
button.sort span { color: var(--accent); }

/* Grid */
.grid-wrap {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow-x: auto;
}
.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td {
  text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.grid th { white-space: nowrap; }
.grid td { min-width: 90px; max-width: 200px; overflow-wrap: break-word; }
.grid td.c-date { white-space: nowrap; }
.grid th {
  position: sticky; top: 0; background: var(--panel);
  font-size: 12px; font-weight: 600; color: var(--muted);
}
.grid tbody tr:hover { background: var(--row-hover); }
.grid tr.new { background: var(--new-row); transition: background 2s; }
.c-date small { display: block; color: var(--muted); font-size: 12px; }
.grid td.c-summary, .grid th.c-summary { min-width: 260px; max-width: none; width: 100%; overflow-wrap: normal; }
.more-row td { text-align: center; }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 6px; }
.empty { color: var(--muted); padding: 24px; text-align: center; margin: 0; }

.grid tbody tr[data-id] { cursor: pointer; }
.grid tbody tr.selected { background: var(--row-hover); box-shadow: inset 3px 0 0 var(--accent); }

/* Detail side panel */
#panel-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.15); z-index: 9; }
#panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100vw); z-index: 10;
  background: var(--panel); border-left: 1px solid var(--line);
  box-shadow: -8px 0 24px rgba(0,0,0,.12);
}
#detail-form { display: flex; flex-direction: column; height: 100%; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
}
.panel-head h2 { font-size: 15px; margin: 0; }
.icon-btn { background: none; border: 0; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); padding: 2px 6px; }
.panel-body {
  flex: 1; overflow-y: auto; padding: 14px 16px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; align-content: start;
}
.panel-body label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; font-weight: 600; color: var(--muted); }
.panel-body .full { grid-column: 1 / -1; min-width: 0; }
.panel-body input, .panel-body select, .panel-body textarea {
  font-size: 14px; font-weight: 400; color: var(--text);
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel);
}
.panel-body textarea { resize: vertical; font-family: inherit; }
.panel-body input:focus, .panel-body select:focus, .panel-body textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.panel-body label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; color: var(--text); font-size: 13px; }
.original {
  white-space: pre-wrap; font: 13px/1.5 "Segoe UI", sans-serif; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px; margin: 0;
}
.meta { color: var(--muted); font-size: 12px; margin: 0; }
.src-email { color: var(--accent); font-size: 12px; }
.email-box { border: 1px solid var(--line); border-radius: 6px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.email-head { font-size: 13px; display: flex; flex-direction: column; gap: 2px; overflow-wrap: anywhere; }
.email-head span, .atts > span { display: inline-block; width: 56px; color: var(--muted); font-size: 12px; }
.email-box .original { max-height: 45vh; overflow-y: auto; }
.quoted summary { cursor: pointer; color: var(--accent); font-size: 13px; margin-bottom: 6px; }
.quoted .original { color: var(--muted); }
.atts { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; }
.atts a, .eml-link { color: var(--accent); text-decoration: none; }
.eml-link { font-size: 12px; }
.thread { display: flex; flex-direction: column; gap: 2px; }
.thread-title { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.thread-item {
  display: grid; grid-template-columns: 92px 1fr; gap: 8px; padding: 6px 8px; border-radius: 6px;
  color: var(--text); text-decoration: none; font-size: 13px; border-left: 3px solid var(--line);
}
.thread-item[href]:hover { background: var(--row-hover); }
.thread-item.current { border-left-color: var(--accent); background: var(--row-hover); }
.t-date { color: var(--muted); white-space: nowrap; }
.t-text { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.panel-foot { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.panel-foot .danger { margin-left: auto; }
.panel-error { padding: 0 16px 12px; margin: 0; }
.panel-msg { padding: 20px; color: var(--muted); }
button.secondary, button.danger {
  height: 32px; padding: 0 14px; border-radius: 6px; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line);
}
button.danger { color: var(--error); }
button.danger:hover { border-color: var(--error); }

/* Settings page */
.settings { display: grid; grid-template-columns: 170px 1fr; gap: 20px; max-width: 1200px; }
.subnav { position: sticky; top: 16px; align-self: start; display: flex; flex-direction: column; gap: 2px; }
.subnav a { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 6px; }
.subnav a:hover { background: var(--panel); color: var(--text); }
.settings-main { min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px 18px; scroll-margin-top: 16px; }
.card h2 { font-size: 16px; margin: 0 0 6px; }
.card h3 { font-size: 13px; margin: 18px 0 4px; }
.help { color: var(--muted); margin: 0 0 12px; max-width: 760px; }
.help.small { font-size: 12px; margin-top: 16px; }
code { font: 12px Consolas, monospace; background: var(--bg); padding: 1px 4px; border-radius: 3px; overflow-wrap: anywhere; }
.flash { padding: 9px 14px; border-radius: 6px; border: 1px solid; }
.flash.ok { background: #e9f7ef; border-color: #a6dcbc; color: #145c32; }
.flash.bad { background: #fdecea; border-color: #f3b4ad; color: #8a1c12; }
@media (prefers-color-scheme: dark) {
  .flash.ok { background: #14301f; border-color: #2c6b45; color: #a6e3bd; }
  .flash.bad { background: #3a1714; border-color: #7a2a22; color: #f6b3ab; }
}
.stable { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.stable.narrow { width: auto; min-width: 480px; }
.stable th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.stable td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.stable tr.inactive td { opacity: .6; }
.stable td.num { text-align: right; color: var(--muted); width: 1%; white-space: nowrap; }
.stable td.actions { white-space: nowrap; text-align: right; width: 1%; }
form.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.settings input:not([type=checkbox]):not([type=file]), .settings select {
  height: 30px; padding: 0 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel);
}
.settings input:focus, .settings select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.settings select { max-width: 180px; }
.stable input[name=name] { width: 260px; max-width: 60vw; }
.add-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 12px; }
.add-row input { min-width: 220px; }
.add-row input.wide { flex: 1 1 300px; }
.finder { width: 260px; margin-bottom: 6px; }
button.small, a.button.small {
  height: 28px; padding: 0 10px; font-size: 13px; border-radius: 6px; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
}
button.small.danger { color: var(--error); }
button.small.warn { color: #9a6700; border-color: #e3c16f; }
a.button { display: inline-flex; align-items: center; text-decoration: none; }
a.button.primary { height: 32px; padding: 0 16px; border-radius: 6px; background: var(--accent); color: #fff; font-weight: 600; }
a.button.primary:hover { background: var(--accent-hover); }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); margin-left: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 2px; margin: 0;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 1px 4px 1px 9px; font-size: 13px;
}
.chip button { background: none; border: 0; cursor: pointer; color: var(--muted); font-size: 15px; line-height: 1; padding: 0 4px; }
.chip button:hover { color: var(--error); }
.backups { margin-top: 12px; }
.status-line { display: flex; align-items: center; gap: 8px; font-weight: 600; margin: 4px 0 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.ok { background: #1f9d55; }
.dot.bad { background: #d92d20; }
.dot.off { background: #a0a7b1; }
.email-actions { display: flex; gap: 8px; margin-bottom: 10px; }
details.connect, details.log { margin-top: 10px; }
.mbox-form { display: grid; grid-template-columns: repeat(2, minmax(220px, 320px)); gap: 8px 12px; align-items: end; margin: 4px 0 8px; }
.mbox-form label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; font-weight: 600; color: var(--muted); }
.mbox-form button { justify-self: start; }
details.howto summary { cursor: pointer; color: var(--accent); font-size: 13px; }
details.howto ol { margin: 8px 0 0; padding-left: 20px; max-width: 760px; }
details.howto li { margin-bottom: 4px; }
@media (max-width: 700px) { .mbox-form { grid-template-columns: 1fr; } }
details.connect summary, details.log summary { cursor: pointer; color: var(--accent); margin-bottom: 8px; }
.stable td.nowrap, .nowrap { white-space: nowrap; }
.muted { color: var(--muted); }
.stable tr.lvl-error td { color: var(--error); }
.stable tr.lvl-warning td:last-child { color: #9a6700; }
.unmapped { border: 1px solid #e3c16f; background: rgba(255, 229, 138, .12); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; }
.unmapped h3 { margin-top: 0; }

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #1d2330; color: #fff; padding: 8px 16px; border-radius: 6px;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
#toast.show { opacity: 1; }

/* Phone */
@media (max-width: 700px) {
  main { padding: 12px 12px 32px; }
  .topbar { padding: 0 12px; gap: 16px; }
  .qa-row select, .qa-row input { flex: 1 1 100%; min-width: 0; }
  .qa-row button.primary { flex: 1 1 100%; }
  .hint { display: none; }
  .panel-body { grid-template-columns: 1fr; }
  .toolbar select { flex: 1 1 45%; max-width: none; }
  .toolbar .count { margin-left: 0; }
  .settings { grid-template-columns: 1fr; }
  .subnav { position: static; flex-direction: row; flex-wrap: wrap; }
  .card { overflow-x: auto; }
  .add-row input { min-width: 0; flex: 1 1 100%; }
}
.badge { display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 9px; font-size: 11px; font-weight: 600; background: var(--accent); color: #fff; vertical-align: middle; }

/* Claude's summaries and open items */
.c-summary .ai-sum { display: block; color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.hint { color: var(--muted); font-weight: normal; font-size: 12px; }
.items-box { border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; }
.item-row { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-top: 1px solid var(--line); }
.item-row:first-of-type { border-top: 0; }
.item-row .item-text { flex: 1; }
.item-row.done .item-text, .stable.items tr.done td:nth-child(3) { text-decoration: line-through; color: var(--muted); }
.wait { display: inline-block; padding: 1px 8px; border-radius: 9px; font-size: 11px; font-weight: 600; white-space: nowrap; border: 1px solid var(--line); }
.wait-eric { background: #fff4d6; color: #7a5200; border-color: #e9cf85; }
.wait-customer { background: #e6f0ff; color: #184c99; border-color: #b5cdf3; }
.wait-principal { background: #efe8ff; color: #5131a0; border-color: #cdbdf2; }
.items-page { max-width: 1100px; }
.item-filters { display: flex; align-items: center; gap: 14px; margin: 6px 0 4px; }
.item-group { margin-top: 20px; }
.items-page .add-row { display: flex; flex-wrap: wrap; gap: 8px; }
.items-page .add-row .wide { flex: 1; min-width: 260px; }
@media (prefers-color-scheme: dark) {
  .wait-eric { background: #3a2f12; color: #f0cf7a; border-color: #6b5520; }
  .wait-customer { background: #14284a; color: #9cc2ff; border-color: #2c4f86; }
  .wait-principal { background: #2a1f4a; color: #c6b3ff; border-color: #4f3d8a; }
}

/* Snooze, keyboard focus, undo */
.items-list { display: flex; flex-direction: column; }
.items-list .item-row { padding: 7px 8px; border-radius: 6px; }
.item-row { flex-wrap: wrap; }
.item-row:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--row-hover); }
.item-row.state-done .item-text { text-decoration: line-through; color: var(--muted); }
.item-row.state-snoozed { opacity: .75; }
.item-row.leaving { opacity: 0; transition: opacity .18s; }
.item-row.flash-row { background: var(--row-hover); }
.item-note { display: block; font-size: 12px; color: var(--muted); }
.item-note.back, h3.item-group.back { color: #b25e00; }
.item-btns { display: inline-flex; gap: 6px; align-items: center; }
select.snooze-pick { height: 28px; padding: 0 6px; font-size: 12px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--text); }
input.snooze-date { height: 28px; font-size: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg a { padding: 5px 12px; text-decoration: none; color: var(--text); font-size: 13px; }
.seg a.on { background: var(--accent); color: #fff; }
kbd { font: 11px ui-monospace, Consolas, monospace; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: var(--panel); }
.toast-undo { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #222; color: #fff; padding: 9px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.25); z-index: 50; font-size: 13px; }
.toast-undo button.link { color: #9cc2ff; padding: 0 0 0 10px; }
@media (prefers-color-scheme: dark) { .item-note.back, h3.item-group.back { color: #f0a85a; } }
.grid td.c-time, .grid th.c-time { min-width: 0; width: 1%; white-space: nowrap; text-align: right; color: var(--muted); }
.saved-note { margin-left: 8px; font-size: 12px; color: #2e9e6b; } .saved-note.bad { color: var(--error); }
.split-box { border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; font-size: 13px; } .split-box a { color: var(--accent); } .split-box button { margin-top: 6px; }
.person-input { width: 90px; } .grid td.c-by, .grid th.c-by { min-width: 0; width: 1%; white-space: nowrap; color: var(--muted); } .wait.wait-other { background: #e8f5ee; color: #1f6b45; border-color: #a9d8bf; } @media (prefers-color-scheme: dark) { .wait.wait-other { background: #133524; color: #8fd9b2; border-color: #2a6b48; } }

/* ===== Sign-in (server mode) ===== */
.login { max-width: 420px; margin: 48px auto; padding: 22px 24px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; }
.login h2 { margin-top: 0; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 13px; }
.login-form input { padding: 9px 11px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--text); font: inherit; }
.login button.primary { height: 36px; padding: 0 16px; }
.whoami { display: flex; align-items: center; gap: 10px; margin-left: auto; color: var(--muted); font-size: 13px; }
.whoami form { margin: 0; }
.whoami button { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit;
  text-decoration: underline; padding: 0; }
