:root {
  --bg: #f6f6f4;
  --panel: #ffffff;
  --side: #efefec;
  --text: #1c1c1e;
  --muted: #6e6e73;
  --faint: #a1a1a6;
  --line: #e3e3df;
  --accent: #2f6df6;
  --brand: #3F4450;
  --accent-soft: #e6eefe;
  --danger: #d6372f;
  --warn: #c77700;
  --ok: #2d9a55;
  --radius: 10px;
  --shadow: 0 8px 30px rgba(0, 0, 0, .14);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b1d;
    --panel: #252528;
    --side: #212123;
    --text: #f2f2f4;
    --muted: #9a9aa0;
    --faint: #66666c;
    --line: #333337;
    --accent: #6c9bff;
    --brand: #E3E6EC;
    --accent-soft: #26324d;
    --danger: #ff6b63;
    --warn: #f0a638;
    --ok: #5fcf8a;
    --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
html, body, #app { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.noscript { padding: 2rem; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* Layout */
.shell { display: grid; grid-template-columns: 250px minmax(0, 1fr); height: 100%; }
.side {
  background: var(--side); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; padding: 14px 10px 10px;
}
.brand { display: flex; align-items: center; gap: 9px; padding: 2px 8px 12px; font-weight: 700; letter-spacing: .08em; }
.brand svg { width: 18px; height: 20px; flex: none; color: var(--brand); fill: currentColor; }
.side-scroll { overflow-y: auto; flex: 1; min-height: 0; padding-bottom: 8px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 7px 10px; border-radius: 8px; color: var(--text);
}
.nav-item:hover { background: rgba(127, 127, 127, .12); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .count { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.nav-item .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .ring { width: 16px; height: 16px; flex: none; }
.nav-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 7px; color: var(--muted); }
.icon-btn:hover { background: rgba(127, 127, 127, .15); color: var(--text); }
.side-foot { border-top: 1px solid var(--line); padding-top: 8px; display: flex; gap: 4px; align-items: center; }
.sync-pill { margin-left: auto; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; padding-right: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.dot.syncing { background: var(--accent); animation: pulse 1s infinite; }
.dot.offline { background: var(--faint); }
.dot.error { background: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 12px 24px 0; min-height: 52px; }
.topbar .menu-btn { display: none; }
.content { overflow-y: auto; flex: 1; padding: 6px 24px 120px; }
.page { max-width: 760px; margin: 0 auto; }
.page-title { display: flex; align-items: center; gap: 12px; margin: 10px 0 4px; }
.page-title h1 { font-size: 28px; line-height: 1.15; margin: 0; letter-spacing: -.01em; overflow-wrap: anywhere; }
.page-title .big { width: 28px; height: 28px; flex: none; }
.page-title input.title-edit { font-size: 28px; font-weight: 700; border: 0; background: transparent; width: 100%; padding: 0; letter-spacing: -.01em; }
.page-sub { color: var(--muted); margin: 0 0 12px; }
.notes-edit { width: 100%; border: 0; background: transparent; resize: none; color: var(--muted); padding: 0; margin: 2px 0 10px; }
.section-head { display: flex; align-items: center; gap: 8px; margin: 22px 0 4px; padding-bottom: 5px; border-bottom: 1px solid var(--line); font-weight: 700; }
.section-head .count { color: var(--muted); font-weight: 400; font-size: 13px; }
.section-head .spacer { flex: 1; }
.section-head.evening { color: var(--accent); }
.section-head .title-edit { font-weight: 700; border: 0; background: transparent; padding: 0; flex: 1; min-width: 0; }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty svg { color: var(--faint); margin-bottom: 8px; }

/* To-do rows */
.row {
  display: flex; align-items: flex-start; gap: 10px; padding: 7px 8px; margin: 1px -8px;
  border-radius: 9px; position: relative; cursor: default;
}
.row:hover { background: rgba(127, 127, 127, .08); }
.row.selected { background: var(--accent-soft); }
.row.dragging { opacity: .4; }
.row.drop-before::before, .row.drop-after::after {
  content: ''; position: absolute; left: 8px; right: 8px; height: 2px; background: var(--accent); border-radius: 2px;
}
.row.drop-before::before { top: -2px; }
.row.drop-after::after { bottom: -2px; }
.check {
  flex: none; width: 20px; height: 20px; margin-top: 1px; border-radius: 6px; border: 2px solid var(--faint);
  display: inline-flex; align-items: center; justify-content: center; color: #fff; background: transparent;
}
.check:hover { border-color: var(--accent); }
.check.done { background: var(--accent); border-color: var(--accent); }
.check svg { width: 12px; height: 12px; stroke-width: 3; }
.row .body { flex: 1; min-width: 0; }
.row .title { overflow-wrap: anywhere; }
.row.done .title { color: var(--muted); text-decoration: line-through; }
.chips { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 2px; font-size: 12.5px; color: var(--muted); align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 4px; }
.chip svg { width: 12px; height: 12px; }
.chip.overdue { color: var(--danger); }
.chip.soon { color: var(--warn); }
.chip.tag { background: rgba(127, 127, 127, .15); padding: 0 7px; border-radius: 99px; }
.row .actions { display: none; gap: 2px; }
.row:hover .actions, .row.selected .actions { display: flex; }
.progress { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.progress circle { fill: none; stroke-width: 3; }
.progress .track { stroke: var(--line); }
.progress .bar { stroke: var(--accent); stroke-linecap: round; transform: rotate(-90deg); transform-origin: 50% 50%; }

/* Quick add */
.quick { display: flex; gap: 8px; align-items: center; margin: 10px 0 4px; padding: 8px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.quick:focus-within { border-color: var(--accent); }
.quick input { flex: 1; border: 0; background: transparent; outline: 0; min-width: 0; }
.quick .hint { font-size: 12px; color: var(--faint); white-space: nowrap; }
.preview { font-size: 12.5px; color: var(--accent); margin: 0 0 8px 4px; min-height: 0; }
.fab {
  position: absolute; right: 24px; bottom: 24px; width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent); color: #fff; display: none; align-items: center; justify-content: center; box-shadow: var(--shadow);
}

/* Editor panel */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 20; }
.editor {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100vw); z-index: 21; background: var(--panel);
  border-left: 1px solid var(--line); box-shadow: var(--shadow); display: flex; flex-direction: column;
}
.editor header { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.editor header .spacer { flex: 1; }
.editor .scroll { overflow-y: auto; padding: 14px 16px 40px; flex: 1; }
.editor .title-line { display: flex; gap: 10px; align-items: flex-start; }
.editor .title-input { font-size: 20px; font-weight: 600; width: 100%; border: 0; background: transparent; outline: 0; padding: 0; resize: none; overflow: hidden; }
.editor .notes { width: 100%; min-height: 80px; border: 1px solid transparent; border-radius: 8px; background: transparent; padding: 8px; margin: 8px -8px 4px; resize: vertical; outline: 0; }
.editor .notes:focus { border-color: var(--line); background: var(--bg); }
.field { display: grid; grid-template-columns: 110px 1fr; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.field > label, .field > .lab { color: var(--muted); font-size: 13px; }
.field .ctl { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-width: 0; }
.field input[type=date], .field input[type=datetime-local], .field select, .field input[type=number], .field input[type=text] {
  background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px; min-width: 0; max-width: 100%;
}
.field input[type=number] { width: 70px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { padding: 4px 10px; font-size: 13px; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #fff; }
.pill { background: var(--bg); border: 1px solid var(--line); border-radius: 99px; padding: 3px 10px; font-size: 13px; }
.pill.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.pill.removable::after { content: ' \00d7'; color: var(--muted); }
.btn { padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); }
.btn:hover { border-color: var(--faint); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 3px 9px; font-size: 13px; }
.checklist { margin: 12px 0 4px; }
.checklist .item { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.checklist .item input[type=text] { flex: 1; border: 0; background: transparent; outline: 0; min-width: 0; padding: 3px 0; }
.checklist .item.done input[type=text] { text-decoration: line-through; color: var(--muted); }
.checklist .add input { width: 100%; border: 0; border-bottom: 1px dashed var(--line); background: transparent; outline: 0; padding: 5px 0; }

/* Palette and menus */
.palette-wrap { position: fixed; inset: 0; z-index: 40; display: flex; justify-content: center; align-items: flex-start; padding-top: 12vh; background: rgba(0, 0, 0, .35); }
.palette { width: min(600px, calc(100vw - 24px)); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.palette input { width: 100%; border: 0; border-bottom: 1px solid var(--line); background: transparent; outline: 0; padding: 14px 16px; font-size: 16px; }
.palette ul { list-style: none; margin: 0; padding: 6px; max-height: 50vh; overflow-y: auto; }
.palette li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.palette li.on { background: var(--accent-soft); color: var(--accent); }
.palette li .kind { margin-left: auto; color: var(--muted); font-size: 12px; }
.palette li kbd { margin-left: auto; }
.palette .none { padding: 14px 16px; color: var(--muted); }
.menu { position: fixed; z-index: 45; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 5px; min-width: 190px; max-height: 60vh; overflow-y: auto; }
.menu button { display: flex; width: 100%; gap: 10px; align-items: center; text-align: left; padding: 7px 10px; border-radius: 7px; }
.menu button:hover, .menu button.on { background: var(--accent-soft); color: var(--accent); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.menu .menu-head { padding: 4px 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

kbd {
  display: inline-block; min-width: 20px; text-align: center; padding: 1px 6px; font: 12px ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; color: var(--muted);
}
.help { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .4); display: flex; justify-content: center; align-items: center; padding: 16px; }
.help .card { background: var(--panel); border-radius: 14px; max-width: 760px; width: 100%; max-height: 86vh; overflow-y: auto; padding: 20px 24px; box-shadow: var(--shadow); }
.help h2 { margin: 0 0 4px; }
.help .cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 0 28px; }
.help h3 { margin: 18px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.help dl { margin: 0; }
.help .line { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; }
.help .line .keys { display: flex; gap: 4px; flex: none; }

/* Dialogs and settings */
.dialog { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 18px 20px; width: min(440px, calc(100vw - 24px)); }
.dialog h2 { margin: 0 0 8px; }
.dialog .row-end { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.modal-wrap { position: fixed; inset: 0; z-index: 48; background: rgba(0, 0, 0, .4); display: flex; justify-content: center; align-items: center; padding: 12px; }
.dialog input[type=text] { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.settings-block { border-top: 1px solid var(--line); padding: 12px 0; }
.settings-block:first-of-type { border-top: 0; }
.settings-block h3 { margin: 0 0 4px; font-size: 14px; }
.settings-block p { margin: 0 0 8px; color: var(--muted); font-size: 13px; }

/* Toasts */
#toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; background: #2a2a2d; color: #fff; padding: 9px 14px; border-radius: 10px; box-shadow: var(--shadow); display: flex; gap: 12px; align-items: center; max-width: min(520px, 92vw); }
.toast button { color: #8db4ff; font-weight: 600; }

/* Login */
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login .card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); width: min(460px, 100%); padding: 30px 28px; }
.login .logo { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .1em; margin-bottom: 14px; }
.login .logo svg { width: 26px; height: 29px; color: var(--brand); fill: currentColor; }
.login h1 { font-size: 22px; margin: 0 0 6px; }
.login ol { padding-left: 20px; color: var(--muted); }
.login .code-input { width: 100%; font-size: 28px; letter-spacing: .3em; text-align: center; text-transform: uppercase; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); margin: 8px 0; font-family: ui-monospace, Menlo, monospace; }
.login .error { color: var(--danger); min-height: 1.4em; margin: 4px 0; }
.login .fine { color: var(--muted); font-size: 12.5px; margin-top: 14px; }
.login .btn.primary { width: 100%; padding: 11px; font-weight: 600; }

/* Small screens */
@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 30; top: 0; bottom: 0; left: 0; width: 280px; transform: translateX(-100%); transition: transform .18s; }
  .side.open { transform: none; box-shadow: var(--shadow); }
  .topbar { padding: 10px 14px 0; }
  .topbar .menu-btn { display: inline-flex; }
  .content { padding: 4px 16px 110px; }
  .fab { display: flex; }
  .quick .hint { display: none; }
  .row .actions { display: none !important; }
  .field { grid-template-columns: 1fr; gap: 4px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media print { .side, .topbar, .fab, .quick { display: none; } .shell { display: block; } }

/* Import dialog */
.dialog.wide { width: min(620px, calc(100vw - 24px)); max-height: 90vh; overflow-y: auto; }
.import-body.busy { opacity: .6; pointer-events: none; }
.import-apps { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.import-app { border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; font-size: 13px; background: var(--bg); }
.import-app.active { background: var(--brand); color: var(--panel); border-color: var(--brand); }
.import-how p { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.import-link { color: var(--brand); font-weight: 600; text-decoration: underline; }
.import-choose { display: inline-flex; margin: 4px 0 10px; cursor: pointer; }
.import-file { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.import-choose:focus-within { outline: 2px solid var(--brand); outline-offset: 2px; }
.import-paste label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.import-paste textarea { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: inherit; font-size: 13px; resize: vertical; }
.import-error { color: #d03b3b; font-size: 13px; min-height: 1em; margin: 8px 0 0; }
.import-stats { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.import-stat { display: flex; flex-direction: column; min-width: 80px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.import-stat strong { font-size: 20px; }
.import-stat span { font-size: 12px; color: var(--muted); }
.import-sample { list-style: none; margin: 0 0 10px; padding: 0; border: 1px solid var(--line); border-radius: 10px; }
.import-sample li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 12px; font-size: 13px; border-top: 1px solid var(--line); }
.import-sample li:first-child { border-top: 0; }
.import-where, .import-more { color: var(--muted); font-size: 12px; }
.import-warn { font-size: 13px; margin: 0 0 10px; }
.import-warn ul { margin: 6px 0 0; padding-left: 18px; color: var(--muted); }
.import-options { display: grid; gap: 8px; margin: 10px 0 0; }
.import-options label:first-child { font-size: 13px; color: var(--muted); }
.import-options select { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font: inherit; font-size: 13px; }
.import-check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; }
