:root {
  --bg: #eef2f8; --surface: #f7f9fc; --surface-2: #ffffff; --bar: #d9e2f0; --line: #c3cddc; --line-soft: #dde4ee;
  --text: #17202e; --muted: #5a6678; --accent: #2f5fb3; --accent-soft: #dbe6f7; --accent-text: #ffffff;
  --danger: #b3261e; --ok: #1f7a4d; --warn: #9a6400; --select: #dfe8f6; --shadow: 0 8px 30px rgba(20, 32, 54, .18);
  --radius: 8px; --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161d; --surface: #1a2029; --surface-2: #212833; --bar: #1c232e; --line: #37414f; --line-soft: #2a323e;
    --text: #e4e9f1; --muted: #97a3b4; --accent: #7ea6ee; --accent-soft: #24344f; --accent-text: #0e1420;
    --danger: #f08a82; --ok: #6fcf9a; --warn: #e0b060; --select: #26334a; --shadow: 0 8px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12161d; --surface: #1a2029; --surface-2: #212833; --bar: #1c232e; --line: #37414f; --line-soft: #2a323e;
  --text: #e4e9f1; --muted: #97a3b4; --accent: #7ea6ee; --accent-soft: #24344f; --accent-text: #0e1420;
  --danger: #f08a82; --ok: #6fcf9a; --warn: #e0b060; --select: #26334a; --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: .2rem 0 .4rem; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
h3 { font-size: 1rem; margin: 0; }
p { margin: .4rem 0; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .strong { font-weight: 600; }
.pad { padding: 1rem; } .center { text-align: center; } .grow { flex: 1 1 auto; } .nowrap { white-space: nowrap; }
.boot { padding: 3rem; text-align: center; color: var(--muted); }
[hidden] { display: none !important; }

/* controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 2.4rem; padding: .35rem .8rem;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); color: var(--text); font: inherit;
  cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { border-color: var(--line); }
.btn.wide { width: 100%; margin-top: .6rem; }
.btn.tab.active { background: var(--accent-soft); border-color: var(--accent); }
.btn.tool { min-width: 2.4rem; padding: .3rem .5rem; }
.btn.small-btn { min-height: 1.9rem; padding: .1rem .5rem; font-size: .85rem; }
.btn.mic.recording { background: var(--danger); border-color: var(--danger); color: #fff; }
.icon { display: inline-flex; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .45rem .6rem; min-height: 2.4rem; max-width: 100%; }
input[type=checkbox] { min-height: 0; width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
textarea { width: 100%; resize: vertical; line-height: 1.45; }
.field { display: flex; flex-direction: column; gap: .2rem; margin: .45rem 0; min-width: 0; }
.field > input, .field > select, .field > textarea, .field > span > input { width: 100%; }
.field-label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.field.inline-field { flex-direction: row; align-items: center; gap: .5rem; }
.hint { font-size: .8rem; color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: .35rem; margin-right: .8rem; }
.checks { display: flex; flex-wrap: wrap; gap: .2rem; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
label.inline { display: inline-flex; align-items: center; gap: .35rem; color: var(--muted); font-size: .85rem; }

/* layout */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .5rem; padding: .45rem .7rem;
  padding-top: calc(.45rem + env(safe-area-inset-top)); background: var(--bar); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 1.05rem; color: var(--text); margin-left: .3rem; }
.home-btn { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.top-search { width: min(22rem, 30vw); }
.who { color: var(--muted); font-size: .85rem; }
@media (min-width: 861px) { .logout .icon { display: none; } }
.page { padding: .8rem; padding-bottom: calc(5rem + env(safe-area-inset-bottom)); max-width: 120rem; margin: 0 auto; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin: .5rem 0; }
.toolbar.end { justify-content: flex-end; }
.toolbar .filter { width: min(24rem, 100%); }
.tabs { display: flex; flex-wrap: wrap; gap: .4rem; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; margin: .7rem 0; padding: .8rem; }
.panel.flush { padding: 0; overflow: hidden; min-height: 4rem; }
.panel-head, .page-head, .card-head, .entry-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .6rem; flex-wrap: wrap; }
.head-actions, .row-actions, .entry-actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.crumbs { margin: .1rem 0 .4rem; } .crumbs a { display: inline-flex; align-items: center; }
.sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 .2rem; }
.sticky-actions { position: sticky; bottom: 0; background: var(--surface); padding: .5rem 0 calc(.2rem + env(safe-area-inset-bottom)); }

/* tables */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; }
.grid th { text-align: left; font-weight: 600; padding: .6rem .7rem; background: var(--bar); border-bottom: 1px solid var(--line); white-space: nowrap; font-size: .85rem; }
.grid th.sortable { cursor: pointer; user-select: none; }
.grid td { padding: .55rem .7rem; border-bottom: 1px solid var(--line-soft); vertical-align: middle; font-size: .9rem; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tbody tr { cursor: pointer; }
.grid tbody tr:hover { background: var(--accent-soft); }
.grid tr.selected { background: var(--select); }
.grid.compact td { padding: .35rem .5rem; } .grid.compact tbody tr { cursor: default; } .grid.compact tbody tr:hover { background: none; }
.grid td.num { font-variant-numeric: tabular-nums; color: var(--muted); }
.home-table td:last-child { text-align: right; } .home-table .row-actions { justify-content: flex-end; flex-wrap: nowrap; }
.home-table th, .home-table td { padding-left: .5rem; padding-right: .5rem; }
.home-table .btn { min-height: 2.1rem; padding: .2rem .6rem; font-size: .88rem; }
.subject-cell { min-width: 16rem; }
.snippet { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: .08rem .45rem; border-radius: 99px; border: 1px solid var(--line);
  color: var(--muted); margin-left: .35rem; vertical-align: middle; white-space: nowrap; }
.badge.s-active { color: var(--ok); border-color: var(--ok); } .badge.s-completed { color: var(--accent); border-color: var(--accent); }
.badge.s-paused, .badge.s-planned { color: var(--warn); border-color: var(--warn); }
.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: .6rem; margin: .5rem 0 0; }
.meta-grid dt { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.meta-grid dd { margin: 0; }

/* cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(19rem, 1fr)); gap: .6rem; padding: .6rem; }
.cards.one { grid-template-columns: 1fr; padding: 0; }
.card { display: block; background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: 10px; padding: .7rem; color: var(--text); min-width: 0; }
a.card:hover { border-color: var(--accent); text-decoration: none; }
.card.selected { border-color: var(--accent); background: var(--select); }
.card-title { font-weight: 600; font-size: 1.02rem; }
.card .row-actions { margin-top: .5rem; }
.card-thumb { display: block; max-height: 9rem; max-width: 100%; border-radius: 6px; margin: .4rem 0; }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; margin: .35rem 0; }
.chip { font-size: .8rem; background: var(--accent-soft); border-radius: 6px; padding: .1rem .45rem; }
mark { background: #ffe58a; color: #222; border-radius: 3px; padding: 0 .1rem; }

/* entry */
.entry.focus { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.entry h2 { font-size: 1.1rem; margin: 0; }
.prose { overflow-wrap: anywhere; margin-top: .5rem; }
.prose img { max-width: 100%; height: auto; border-radius: 6px; }
.prose table { border-collapse: collapse; margin: .5rem 0; display: block; overflow-x: auto; max-width: 100%; }
.prose th, .prose td { border: 1px solid var(--line); padding: .25rem .55rem; text-align: left; }
.prose th { background: var(--bar); }
.prose pre, .code { background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: 6px; padding: .6rem; overflow-x: auto; font-size: .85rem; }
.prose code { font-size: .9em; }
.prose blockquote { margin: .5rem 0; padding-left: .8rem; border-left: 3px solid var(--line); color: var(--muted); }
.prose ul.contains-task-list { list-style: none; padding-left: .4rem; }
.prose h1, .prose h2, .prose h3 { font-size: 1.05rem; margin: .8rem 0 .3rem; display: block; }
.prose.live { white-space: pre-wrap; }
.files { margin-top: .6rem; border-top: 1px solid var(--line-soft); padding-top: .6rem; }
.thumbs { display: flex; flex-wrap: wrap; gap: .5rem; }
.thumbs img { height: 8rem; max-width: 100%; border-radius: 6px; border: 1px solid var(--line-soft); display: block; object-fit: cover; }
.file-links { list-style: none; padding: 0; margin: .4rem 0 0; }
.audio { display: flex; flex-direction: column; gap: .2rem; margin: .4rem 0; } .audio audio { width: min(28rem, 100%); }
.rev { border: 1px solid var(--line-soft); border-radius: 8px; padding: .5rem .7rem; margin: .5rem 0; }
.rev summary { cursor: pointer; font-weight: 600; } .rev textarea, .rev .two { margin: .4rem 0; }

/* editor */
.editor .subject { width: 100%; font-size: 1.1rem; font-weight: 600; margin: .4rem 0; }
.attr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: 0 .8rem; }
.editor .body { min-height: 40vh; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92rem; }
.preview { min-height: 40vh; border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem; background: var(--surface-2); }
.tools { position: sticky; top: 3.4rem; z-index: 5; background: var(--surface); padding: .3rem 0; }
.editor-status { min-height: 1.2rem; }
.notice { background: var(--accent-soft); border-radius: 8px; padding: .5rem .7rem; margin-bottom: .5rem; font-size: .9rem; }
.file-row { display: flex; align-items: center; gap: .6rem; padding: .3rem 0; border-bottom: 1px solid var(--line-soft); }
.file-row img { width: 3rem; height: 3rem; object-fit: cover; border-radius: 6px; }
.file-name { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.attr-row { display: grid; grid-template-columns: minmax(8rem, 1.2fr) 10rem minmax(8rem, 2fr) 5rem auto auto; gap: .4rem; align-items: center;
  padding: .4rem 0; border-bottom: 1px solid var(--line-soft); }
.attr-row .flags { display: flex; flex-wrap: wrap; }
.attr-row input, .attr-row select { width: 100%; min-width: 0; }
.attr-row .flags input { width: 1.1rem; }
.fab { position: fixed; right: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom)); width: 3.6rem; height: 3.6rem; border-radius: 50%;
  background: var(--accent); color: var(--accent-text); display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow); z-index: 15; }
.fab svg { width: 28px; height: 28px; }

/* sign in */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-card { width: min(24rem, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 1.4rem; }

/* dialogs, toasts, drawer */
.dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--surface); color: var(--text);
  width: min(44rem, calc(100vw - 1.5rem)); max-height: calc(100vh - 2rem); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(10, 16, 28, .5); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: .6rem .6rem .6rem 1rem; border-bottom: 1px solid var(--line-soft); }
.dialog-head h2 { margin: 0; }
.dialog-body { padding: 1rem; overflow-y: auto; max-height: calc(100vh - 11rem); }
.dialog-body input:not([type=checkbox]) { width: 100%; }
.dialog-foot { display: flex; justify-content: flex-end; gap: .5rem; padding: .6rem 1rem; border-top: 1px solid var(--line-soft); }
#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(1rem + env(safe-area-inset-bottom)); z-index: 100;
  display: flex; flex-direction: column; gap: .4rem; width: min(30rem, calc(100vw - 2rem)); pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: .6rem .9rem; border-radius: 8px; box-shadow: var(--shadow); }
.toast.error { background: var(--danger); color: #fff; }
:root[data-theme="dark"] .toast.error { color: #1a0d0c; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(30rem, 100vw); z-index: 40; background: var(--surface);
  border-left: 1px solid var(--line); box-shadow: var(--shadow); display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
.drawer-head { display: flex; align-items: center; gap: .5rem; padding: .5rem .5rem .5rem .9rem; border-bottom: 1px solid var(--line-soft); }
.drawer-scope { padding: .5rem .9rem; } .drawer-scope select { width: 100%; }
.chat-log { flex: 1 1 auto; overflow-y: auto; padding: .4rem .9rem; display: flex; flex-direction: column; gap: .6rem; }
.msg { max-width: 100%; padding: .5rem .7rem; border-radius: 10px; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent-soft); max-width: 88%; white-space: pre-wrap; }
.msg.assistant { background: var(--surface-2); border: 1px solid var(--line-soft); }
.msg.assistant .prose { margin-top: 0; }
.msg.error { color: var(--danger); border-color: var(--danger); }
.chat-empty { display: flex; flex-direction: column; gap: .5rem; }
.hint-btn { white-space: normal; text-align: left; justify-content: flex-start; }
.chat-input { display: flex; gap: .5rem; padding: .6rem .9rem; border-top: 1px solid var(--line-soft); align-items: flex-end; }

.narrow-only { display: none; }
@media (max-width: 860px) {
  .wide-only { display: none; } .narrow-only { display: grid; } a.fab.narrow-only { display: flex; }
  .top-search, .who, .logout span:last-child { display: none; }
  .page { padding: .6rem; }
  .two { grid-template-columns: 1fr; gap: 0; }
  .head-actions .btn span:last-child:not(:first-child) { display: none; }
  .head-actions .btn.primary span:last-child { display: inline; }
  .entry-actions .btn span:last-child:not(:first-child) { display: none; }
  .attr-row { grid-template-columns: 1fr 1fr; }
  .cards { grid-template-columns: 1fr; }
  .layout-toggle { display: none; }
  .tools { top: 3.2rem; }
  input, select, textarea { font-size: 16px; }   /* stops iOS zooming into fields */
}
@media print {
  .topbar, .toolbar, .entry-actions, .crumbs, .fab, .drawer, #toasts { display: none !important; }
  body { background: #fff; } .panel { border-color: #999; break-inside: avoid; }
}
@media (prefers-reduced-motion: no-preference) { .btn, .card { transition: border-color .12s; } }
