/* Seder — mobile-first, theme-aware. */
:root {
  --bg: #f5f6f8; --card: #ffffff; --ink: #1b2430; --muted: #686f7c;
  --line: #e6e8ee; --accent: #2f5fe0; --accent-ink: #ffffff;
  --accent-weak: rgba(47, 95, 224, .10);
  --alert-bg: #fdecea; --alert-ink: #a1160b;
  --radius: 10px;
}
/* Dark: applied for the system pref (when no explicit choice) … */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0f1318; --card: #171d24; --ink: #e7eaee; --muted: #9aa4b2;
    --line: #262d37; --accent: #5b8dff; --accent-ink: #0b1220;
    --accent-weak: rgba(91, 141, 255, .14);
    --alert-bg: #3a1f1c; --alert-ink: #ffb4a8;
  }
}
/* … and when explicitly chosen (theme toggle / time-of-day). */
:root[data-theme="dark"] {
  --bg: #0f1318; --card: #171d24; --ink: #e7eaee; --muted: #9aa4b2;
  --line: #262d37; --accent: #5b8dff; --accent-ink: #0b1220;
  --accent-weak: rgba(91, 141, 255, .14);
  --alert-bg: #3a1f1c; --alert-ink: #ffb4a8;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow-wrap: break-word;
}
/* Long unbreakable strings (URLs, emails, tokens) must wrap, never spill.
   `anywhere` also lets flex/grid children shrink below their longest word. */
h1, h2, h3, p, li, a, span, td, th, .t-title, .desc, .snippet,
.markdown, .copy, .timeline li { overflow-wrap: anywhere; }
.wrap { max-width: 640px; margin: 0 auto; padding: 16px; }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin: 10px 0;
}
.card > hr { border: 0; border-top: 1px solid var(--line); margin: 16px -16px; }
/* A bare h1/h2/p/form as a card's first or last child still carries its own
   browser-default margin on top of the card's own padding — doubling the
   gap for no reason. */
.card > *:first-child { margin-top: 0; }
.card > *:last-child { margin-bottom: 0; }
.auth { max-width: 380px; margin: min(8vh, 56px) auto 0; }
.auth .remember { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.auth .remember input { width: auto; margin: 0; }
.auth .remember span { color: var(--muted); font-size: .9rem; }
.brand { margin: 0 0 4px; font-size: 1.5rem; letter-spacing: .5px; }
.muted { color: var(--muted); }
.empty-cta a { font-weight: 600; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

label { display: block; margin: 14px 0; font-size: .9rem; color: var(--muted); }
input, textarea, select {
  width: 100%; margin-top: 6px; padding: 12px; font-size: 1rem;
  color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

/* Keyboard focus on everything clickable — previously only inputs got a
   styled ring, so tabbing through buttons/tabs/links/chips fell back to
   whatever bare default the browser happens to draw. */
a:focus-visible, button:focus-visible, .tab:focus-visible,
.icon-btn:focus-visible, .btn:focus-visible, .tag-chip:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

button {
  width: 100%; padding: 12px 16px; font-size: 1rem; font-weight: 600;
  color: var(--accent-ink); background: var(--accent);
  border: 0; border-radius: 10px; cursor: pointer; min-height: 44px;
}
button.ghost { width: auto; background: transparent; color: var(--muted); border: 1px solid var(--line); }
button:active { transform: translateY(1px); }

.alert { background: var(--alert-bg); color: var(--alert-ink); padding: 10px 12px; border-radius: 10px; margin: 12px 0; }
a { color: var(--accent); }

/* Flash — dismissible (app.js appends .flash__close) + auto-fades after 6s */
.flash { background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--accent); padding: 10px 12px; border-radius: 8px; margin: 12px 0;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  transition: opacity .3s, margin .3s, padding .3s; overflow: hidden; }
.flash--out { opacity: 0; margin: 0; padding-top: 0; padding-bottom: 0; border-width: 0; max-height: 0; }
.flash__close { background: none; border: none; color: var(--muted); font-size: 1.1rem; line-height: 1;
  padding: 0 2px; cursor: pointer; width: auto; }
.flash__close:active { transform: none; }

/* PWA install nudge — shown only when the browser actually fires
   beforeinstallprompt (app.js), so it never appears already-installed
   or on a browser that doesn't support the prompt at all. */
.install-banner { display: flex; align-items: center; gap: 10px; background: var(--accent);
  color: var(--accent-ink); padding: 10px 14px; font-size: .9rem; }
/* .install-banner alone has the same specificity as the browser's own
   [hidden] { display: none } rule, and author CSS beats the UA
   stylesheet even at equal specificity — so the plain class rule above
   silently overrode the hidden attribute, and the banner never actually
   hid when app.js set .hidden = true (on dismiss, on install, or simply
   because beforeinstallprompt never fired at all). This makes [hidden]
   win again. */
.install-banner[hidden] { display: none; }
.install-banner span { flex: 1; }
.install-banner button { width: auto; min-height: 0; padding: 6px 12px; }
#install-accept { background: var(--accent-ink); color: var(--accent); font-weight: 600; }
#install-dismiss { background: none; border: 1px solid rgba(255,255,255,.5); color: var(--accent-ink);
  padding: 4px 9px; font-size: 1rem; line-height: 1; }

/* Keyboard-shortcuts help (? key), native <dialog> so backdrop/focus-trap/
   Esc-to-close all come from the browser for free. */
#shortcuts-help { border: 1px solid var(--line); border-radius: var(--radius); padding: 20px;
  background: var(--card); color: var(--ink); max-width: 320px; width: 90vw; }
#shortcuts-help::backdrop { background: rgba(0,0,0,.4); }
.shortcuts-list { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0; align-items: center; }
.shortcuts-list dt { margin: 0; }
.shortcuts-list dd { margin: 0; color: var(--muted); font-size: .9rem; }
kbd { background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 2px 7px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }

/* App header */
.app-header { position: sticky; top: 0; z-index: 20; display: flex; align-items: center;
  justify-content: space-between; gap: 12px; padding: 12px 2px; margin-bottom: 4px;
  background: var(--bg); border-bottom: 1px solid var(--line); }
.app-header .brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 1.15rem;
  letter-spacing: .2px; text-decoration: none; color: var(--ink); margin: 0; }
.brand-mark { border-radius: 6px; display: block; }
.header-actions { display: flex; align-items: center; gap: 6px; }
.header-actions form { width: auto; margin: 0; }
.icon-btn { width: 40px; height: 40px; min-height: 0; padding: 0; display: inline-flex;
  align-items: center; justify-content: center; background: transparent; color: var(--muted);
  border: 1px solid transparent; border-radius: 10px; font-size: 1.05rem; cursor: pointer; }
.icon-btn:hover { background: var(--card); color: var(--ink); border-color: var(--line); }
.icon-btn svg { width: 20px; height: 20px; }

/* Tab bar (top on desktop, bottom on mobile) */
.tabbar { display: flex; gap: 4px; padding: 6px; margin: 8px 0 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.tab { flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px; border-radius: 10px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: .95rem; }
.tab svg { width: 20px; height: 20px; }
.tab.on { background: var(--accent-weak); color: var(--accent); }
.tab:active { transform: translateY(1px); }

/* Quick add */
.quickadd .row { display: flex; gap: 8px; flex-wrap: wrap; }
.quickadd input[type=text] { flex: 1; margin: 0; min-width: 140px; }
.quickadd input[type=date], .quickadd input[type=time] { width: auto; margin: 0; }
.quickadd select.quickadd-priority { width: auto; margin: 0; }
.quickadd button { width: auto; }

@media (max-width: 480px) {
  .quickadd-time, .quickadd-priority { flex: 1 1 auto; }
}

/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0; }
.stat { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; text-decoration: none; color: var(--ink); }
.stat b { font-size: 1.4rem; }
.stat span { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat.danger b { color: var(--alert-ink); }

/* Toolbar / segmented */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 12px 0; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.segmented a { padding: 8px 14px; text-decoration: none; color: var(--muted); }
.segmented a.on { background: var(--accent); color: var(--accent-ink); }
.btn-add, .btn { display: inline-block; padding: 8px 14px; border-radius: 10px; text-decoration: none;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn { background: var(--bg); color: var(--ink); border: 1px solid var(--line); }

/* Notes sort control — a second toolbar row, same spacing as the view segmented control. */
.sort-bar { margin-top: -4px; }
.sort-select { display: flex; align-items: center; gap: 8px; margin: 0; font-size: .85rem; }
.sort-select select { width: auto; margin-top: 0; padding: 6px 10px; font-size: .85rem; }

/* Dashboard sections: reorderable (move up/down) + collapsible, order and
   collapsed state persisted client-side (per-device preference, not data
   worth round-tripping to the server — same reasoning as the theme
   toggle). */
.dash-section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.dash-section-head .sec { margin: 0; }
.dash-section-controls { display: flex; gap: 2px; flex-shrink: 0; }
.dash-move, .dash-collapse { width: auto; min-height: 0; background: none; border: 0; color: var(--muted);
  padding: 2px 6px; cursor: pointer; font-size: .95rem; line-height: 1; }
.dash-move:hover, .dash-collapse:hover { color: var(--ink); }
.dash-move:disabled { opacity: .3; cursor: default; }
.dash-move:disabled:hover { color: var(--muted); }
.dash-collapse { transition: transform .15s; }
.dash-section.collapsed .dash-collapse { transform: rotate(-90deg); }
.dash-section.collapsed .dash-section-body { display: none; }
.dash-section-body { margin-top: 10px; }

/* Task list */
.sec { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 8px; }
ul.tasks { list-style: none; margin: 0; padding: 0; }
.task { padding: 10px 0; border-bottom: 1px solid var(--line);
  transition: opacity .3s, max-height .3s, padding .3s, margin .3s; max-height: 300px; overflow: hidden;
  position: relative; background: var(--card); touch-action: pan-y; }
.task:last-child { border-bottom: 0; }
.task.task-removing { opacity: 0; max-height: 0; padding-top: 0; padding-bottom: 0; border-width: 0; }
/* Swipe-to-complete (touch only — see app.js): .task-content is the part
   that actually translates right as you drag; .task itself stays put
   with its own background, which shows through the gap that opens up to
   its left. .swiping suspends the row's own opacity/height transition
   (so dragging feels immediate) without affecting .task-content's. */
.task-content { display: flex; align-items: flex-start; gap: 10px; background: var(--card); position: relative; }
.task.swiping { background: var(--accent-weak); transition: none; }
.task.swipe-complete { background: var(--accent-weak); }
.undo-toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--ink); color: var(--card); padding: 10px 16px; border-radius: 999px;
  display: flex; align-items: center; gap: 12px; font-size: .9rem; z-index: 30; box-shadow: 0 4px 16px rgba(0,0,0,.25); }
.undo-toast button { width: auto; min-height: 0; background: none; border: 0; color: var(--accent);
  font-weight: 700; padding: 0; }
.task .check { margin: 0; width: auto; }
.tick { width: auto; min-height: 0; background: none; border: 0; font-size: 1.35rem; line-height: 1.5; color: var(--muted); padding: 0 2px; cursor: pointer; }
/* Title takes the full row width; badges wrap onto their own line below it. */
.t-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.t-title { text-decoration: none; color: var(--ink); }
.task.is-done .t-title { color: var(--muted); text-decoration: line-through; }
.t-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* Badges */
.badge { font-size: .72rem; padding: 2px 7px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.overdue { color: var(--alert-ink); border-color: var(--alert-ink); }
.badge.wip { color: var(--accent); border-color: var(--accent); }
.badge.prio.p3 { color: var(--alert-ink); border-color: var(--alert-ink); }
.badge.status { font-size: .8rem; }
.tags { font-size: .75rem; color: var(--accent); }

/* Tag chips (clickable filters) */
.tag-chips { display: inline-flex; flex-wrap: wrap; gap: 5px; }
.tag-chip { font-size: .72rem; padding: 2px 8px; border-radius: 999px;
  background: var(--accent-weak); color: var(--accent); text-decoration: none; white-space: nowrap; }
a.tag-chip:hover { background: var(--accent); color: var(--accent-ink); }
.badge.recur { border: 0; background: transparent; padding: 0; font-size: .85rem; }

/* Filter banner + search */
.tag-cloud { margin: 10px 0; }
.filter-banner { display: flex; align-items: center; gap: 8px; margin: 10px 0; font-size: .9rem; color: var(--muted); }
.filter-banner .clear { font-size: .8rem; }
.search-form { display: flex; gap: 8px; margin: 6px 0 4px; }
.search-form input { margin: 0; }
.search-form button { width: auto; }
.hint { font-size: .8rem; margin: 4px 0 0; }

/* Detail */
.show-head { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.show-head h1 { margin: 0; min-width: 0; font-size: 1.3rem; }
.done-title { text-decoration: line-through; color: var(--muted); }
.overdue-text { color: var(--alert-ink); }
.desc { margin: 12px 0; padding: 12px; background: var(--bg); border-radius: 10px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
.actions form { width: auto; margin: 0; }
.actions button { width: auto; background: var(--bg); color: var(--ink); border: 1px solid var(--line); }
.actions button.primary { background: var(--accent); color: var(--accent-ink); border: 0; }
.top-actions { margin-top: 12px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.postpone { margin-top: 8px; }
.postpone summary { cursor: pointer; list-style: none; }
.postpone summary::-webkit-details-marker { display: none; }
.postpone-menu { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.postpone-menu form { width: auto; margin: 0; display: inline-flex; gap: 4px; }
.chip { width: auto; min-height: 0; padding: 6px 12px; border-radius: 999px; background: var(--bg); color: var(--ink); border: 1px solid var(--line); font-weight: 500; }
.postpone-date input[type=date] { width: auto; margin: 0; padding: 6px 10px; }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: .9rem; }
.timeline li:last-child { border-bottom: 0; }
.timeline .when { color: var(--muted); white-space: nowrap; min-width: 130px; }

/* Forms */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.back { margin-top: 12px; }
.danger-zone { border-color: var(--alert-ink); }
.danger-btn { color: var(--alert-ink); border-color: var(--alert-ink); width: auto; }

/* One-time backup-code reveal */
.new-codes { border-color: var(--accent); }
.code-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.code-list code { display: block; padding: 6px 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; text-align: center; font-size: .95rem; }

/* Notes */
.notes-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin: 12px 0; }
.note-card { position: relative; display: block; min-width: 0; padding: 14px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--ink); }
.note-card.pinned { border-color: var(--accent); }
.note-card .pin { position: absolute; top: 8px; right: 10px; font-size: .85rem; }
.note-card h3 { margin: 0 0 6px; font-size: 1.05rem; padding-right: 18px; }
.note-card .snippet { margin: 0; color: var(--muted); font-size: .9rem;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden; }
.note-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 10px; }
.note-foot time { color: var(--muted); font-size: .78rem; }
textarea.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .95rem; }

/* Jump-to-section list for long notes (3+ headings) — see Markdown::toc().
   scroll-margin-top on the headings themselves keeps the sticky header from
   covering whatever a toc link (or any other #anchor) jumps to. */
.note-toc { margin: 10px 0; padding: 10px 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.note-toc .sec { margin: 0 0 6px; }
.note-toc ul { list-style: none; margin: 0; padding: 0; columns: 2; column-gap: 16px; }
.note-toc li { margin: 3px 0; font-size: .88rem; }
.note-toc .toc-h3 { padding-left: 14px; }
.note-toc a { color: var(--ink); text-decoration: none; }
.note-toc a:hover { color: var(--accent); }
.markdown h1, .markdown h2, .markdown h3 { scroll-margin-top: 70px; }

/* Quick-add box on a note's show page — stamps the entry with the current
   date/time and appends it, instead of a full body edit. See Note::appendEntry(). */
.quick-add { margin: 14px 0; padding: 10px 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.quick-add .sec { margin: 0 0 6px; }
.quick-add textarea { margin-top: 0; resize: vertical; }
.quick-add button { margin-top: 8px; }

/* Rendered markdown */
.markdown { line-height: 1.65; }
.markdown h1, .markdown h2, .markdown h3 { margin: 1em 0 .4em; line-height: 1.25; }
.markdown h1 { font-size: 1.5rem; } .markdown h2 { font-size: 1.25rem; } .markdown h3 { font-size: 1.1rem; }
.markdown p { margin: .6em 0; }
.markdown ul, .markdown ol { margin: .6em 0; padding-left: 1.4em; }
.markdown li { margin: .2em 0; }
.markdown code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em;
  background: var(--bg); padding: 1px 5px; border-radius: 5px; }
.markdown pre { background: var(--bg); padding: 12px; border-radius: 10px; overflow-x: auto; }
.markdown pre code { background: none; padding: 0; }
.markdown blockquote { margin: .6em 0; padding: .2em 1em; border-left: 3px solid var(--line); color: var(--muted); }
.markdown a { color: var(--accent); }
.markdown hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }

@media (max-width: 480px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .quickadd .row { flex-wrap: wrap; }
  .quickadd input[type=text] { flex: 1 1 100%; }
  .notes-grid { grid-template-columns: 1fr; }
  /* Due date + time, and priority + repeat, squeeze far too narrow to show
     a date/time control's placeholder side by side on a phone screen. */
  .grid2 { grid-template-columns: 1fr; }
  .code-list { grid-template-columns: 1fr; }
  .note-toc ul { columns: 1; }
}

/* Note editor */
.editor-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between;
  align-items: center; margin: 6px 0; }
.md-tools, .editor-modes { display: flex; gap: 4px; flex-wrap: wrap; }
.editor-bar button { width: auto; min-height: 0; padding: 6px 10px; font-size: .9rem; font-weight: 600;
  background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; }
.editor-bar .mode.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
#note-preview { min-height: 200px; padding: 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); margin-top: 6px; }
#note-body { min-height: 200px; }

/* Fullscreen editing */
.note-editor.fullscreen { position: fixed; inset: 0; z-index: 50; margin: 0; border-radius: 0;
  overflow: auto; padding: 14px calc(14px + env(safe-area-inset-right)) 14px calc(14px + env(safe-area-inset-left)); }
.note-editor.fullscreen #note-body,
.note-editor.fullscreen #note-preview { min-height: 60vh; }

/* Task lists (rendered - [ ] / - [x]) */
ul.task-list { list-style: none; padding-left: 4px; }
ul.task-list .task-item { display: flex; align-items: flex-start; gap: 8px; }
/* Override the generic `input { width: 100% }` above — without this the
   checkbox's flex-basis resolves to the full row width (same fix already
   used for .auth .remember input), squeezing the label into almost no
   space and forcing it to wrap letter-by-letter. */
ul.task-list input[type=checkbox] { width: auto; margin: .3em 0 0; flex: 0 0 auto; cursor: pointer; }
ul.task-list .task-item.done { color: var(--muted); text-decoration: line-through; }

/* Copyable feed URL field */
.copy { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem;
  background: var(--bg); cursor: pointer; }
.settings code, .card code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg); padding: 1px 5px; border-radius: 5px; font-size: .88em; }

/* Mobile: the tab bar becomes a fixed bottom nav */
@media (max-width: 560px) {
  .tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; margin: 0;
    border-radius: 0; border-left: 0; border-right: 0; border-bottom: 0;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); }
  .tab { flex-direction: column; gap: 3px; padding: 6px 4px; }
  .tab span { font-size: .7rem; }
  body { padding-bottom: 78px; }
}
