/* ============ tokens ============ */
:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #f9f7f2;
  --sidebar: #efebe2;
  --ink: #1c1a15;
  --ink-2: #4a463d;
  --muted: #7a7468;
  --line: #e5dfd2;
  --line-strong: #d3ccbc;
  --accent: #3d3aa8;
  --accent-ink: #ffffff;
  --accent-soft: #e9e8fa;
  --accent-text: #34318f;
  --danger: #b4321f;
  --danger-soft: #fbeae6;
  --ok: #2f7a4b;
  --ok-soft: #e3f2e8;
  --warn: #8f6210;
  --warn-soft: #faefd6;
  --thermo-1: #5b7fc7;
  --thermo-2: #5fa3b5;
  --thermo-3: #c9a43a;
  --thermo-4: #e08a3c;
  --thermo-5: #d9483b;
  --shadow: 0 1px 2px rgb(40 30 10 / 0.05);
  --shadow-lg: 0 16px 48px rgb(40 30 10 / 0.18);
  --radius: 12px;
  --radius-sm: 8px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Fraunces", Georgia, serif;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --sidebar-w: 240px;
  --topbar-h: 64px;
  --gap: 16px;
  /* control sizing — every button/input uses these */
  --ctl-h: 36px;
  --ctl-h-sm: 30px;
  --ctl-px: 14px;
  --ctl-px-sm: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12110d;
    --surface: #1c1b16;
    --surface-2: #211f19;
    --sidebar: #171611;
    --ink: #eeeae0;
    --ink-2: #c9c3b6;
    --muted: #958f82;
    --line: #2c2a23;
    --line-strong: #3b3930;
    --accent: #8f8cf5;
    --accent-ink: #14130f;
    --accent-soft: #25244a;
    --accent-text: #b5b3ff;
    --danger: #f0806c;
    --danger-soft: #3a1d17;
    --ok: #7cc597;
    --ok-soft: #1a2e21;
    --warn: #e3b55a;
    --warn-soft: #33290f;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.35);
    --shadow-lg: 0 16px 48px rgb(0 0 0 / 0.55);
    color-scheme: dark;
  }
}

/* ============ base ============ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; min-height: 100dvh; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
h1, h2, h3, p, ul, dl, dd, pre { margin: 0; }
ul { padding: 0; list-style: none; }
h1, h2 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.01em; line-height: 1.25; }
h3 { font-size: 14px; font-weight: 600; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: var(--accent-soft); }
[hidden] { display: none !important; }

/* Icons scale with text and sit on its optical centre. */
.icon { width: 1.15em; height: 1.15em; flex: none; display: inline-block; vertical-align: -0.2em; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.pad { padding: 16px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 2px; flex-wrap: wrap; }
.error-text { color: var(--danger); font-size: 13px; }
.prose { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink); }

/* ============ shell ============ */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100dvh; }
.sidebar {
  position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 8px;
  background: var(--sidebar); border-right: 1px solid var(--line); padding: 14px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand b { display: block; font-family: var(--serif); font-size: 16px; font-weight: 600; line-height: 1.2; }
.brand span { display: block; font-size: 12px; color: var(--muted); line-height: 1.2; }
.side-nav { flex: 1; display: flex; flex-direction: column; gap: 18px; overflow-y: auto; }
.side-section { display: flex; flex-direction: column; gap: 2px; }
.side-label { font-size: 11px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); padding: 0 10px 6px; }
.side-nav a {
  display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 10px; border-radius: var(--radius-sm);
  color: var(--ink-2); font-weight: 500; transition: background 0.15s, color 0.15s;
}
.side-nav a .icon { color: var(--muted); }
.side-nav a:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); color: var(--ink); text-decoration: none; }
.side-nav a.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.side-nav a.active .icon { color: var(--accent-text); }
.side-user { display: flex; align-items: center; gap: 10px; padding: 10px 6px 4px 8px; border-top: 1px solid var(--line); }
.side-user-text { flex: 1; min-width: 0; line-height: 1.3; }
.side-user-text b, .side-user-text span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user-text b { font-weight: 600; }
.side-user-text span { font-size: 12px; color: var(--muted); }

.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 10; min-height: var(--topbar-h); display: flex; align-items: center; gap: 12px;
  padding: 10px 28px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px); border-bottom: 1px solid var(--line);
}
.top-title { flex: 1; min-width: 0; }
.top-title h1 { font-size: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-title p { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumb { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.crumb:hover { color: var(--ink); text-decoration: none; }
.top-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.btn.menu-btn { display: none; }
.content { padding: 24px 28px 48px; width: 100%; max-width: 1360px; }
.content[aria-busy="true"] { opacity: 0.55; transition: opacity 0.2s 0.15s; }
.scrim { display: none; }

/* ============ layouts ============ */
.split { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--gap); align-items: start; }
.split-form { grid-template-columns: 360px minmax(0, 1fr); }
.sticky { position: sticky; top: calc(var(--topbar-h) + 16px); }
.cols-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--gap); align-items: start; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.span-all { grid-column: 1 / -1; }
.prompts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 20px; }

/* ============ buttons ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--ctl-h); padding: 0 var(--ctl-px); border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500; line-height: 1; white-space: nowrap; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); text-decoration: none; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn .icon { width: 16px; height: 16px; }
.btn:has(.icon):not(.btn-icon) { padding-left: calc(var(--ctl-px) - 3px); } /* optical balance: icon side looks heavier */
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 86%, black); border-color: transparent; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); border-color: transparent; color: var(--ink); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: color-mix(in srgb, var(--danger) 86%, black); }
.btn-sm { height: var(--ctl-h-sm); padding: 0 var(--ctl-px-sm); font-size: 13px; gap: 6px; }
.btn-sm .icon { width: 15px; height: 15px; }
.btn-sm:has(.icon):not(.btn-icon) { padding-left: calc(var(--ctl-px-sm) - 2px); }
.btn-icon { width: var(--ctl-h); padding: 0; }
.btn-icon.btn-sm { width: var(--ctl-h-sm); }
.btn-block { width: 100%; height: 40px; }

/* ============ cards ============ */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); min-height: 52px; flex-wrap: wrap; }
.card-head > .icon { color: var(--muted); width: 16px; height: 16px; }
.card-title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; }
.card-title h2 { font-family: var(--font); font-size: 14px; font-weight: 600; letter-spacing: 0; }
.card-title p { font-size: 13px; color: var(--muted); }
.card-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-body { padding: 16px; }
.card-body.flush { padding: 0; }
.card:not(:has(.card-head)) > .card-body { padding: 18px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat { padding: 12px 16px; display: flex; flex-direction: column; gap: 2px; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-family: var(--serif); font-size: 24px; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-value small { font-family: var(--font); font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 4px; }

.meta { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px 16px; align-items: center; }
.meta dt { font-size: 13px; color: var(--muted); }
.meta dd { min-width: 0; }

.list > li + li { border-top: 1px solid var(--line); }
.list-item { padding: 12px 16px; display: flex; flex-direction: column; gap: 6px; }

/* ============ tags / avatars ============ */
.tag {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; line-height: 1; white-space: nowrap;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2);
}
.tag .icon { width: 12px; height: 12px; }
.tag-accent { background: var(--accent-soft); border-color: transparent; color: var(--accent-text); }
.tag-ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.tag-warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.tag-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none; display: inline-grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-text); font-size: 12px; font-weight: 600;
}
.avatar.staff { background: var(--warn-soft); color: var(--warn); }
.person { display: flex; align-items: center; gap: 10px; min-width: 0; }
.person-text { min-width: 0; line-height: 1.3; }
.person-text b { display: block; font-weight: 600; }
.person-text span { display: block; font-size: 12px; color: var(--muted); }

/* ============ forms ============ */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field > .label { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: 13px; font-weight: 500; }
.hint { font-size: 12px; font-weight: 400; color: var(--muted); }
.input, .textarea {
  width: 100%; border: 1px solid var(--line-strong); background: var(--surface); border-radius: var(--radius-sm);
  padding: 0 12px; font-size: 14px; transition: border-color 0.15s, box-shadow 0.15s;
}
.input { height: var(--ctl-h); }
.textarea { padding: 8px 12px; resize: vertical; line-height: 1.5; min-height: 64px; }
.input:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder, .textarea::placeholder { color: var(--muted); opacity: 0.85; }

.segmented { display: inline-flex; padding: 2px; gap: 2px; background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); height: var(--ctl-h); }
.segmented button { border: 0; background: none; padding: 0 12px; border-radius: 6px; font-size: 13px; font-weight: 500; color: var(--muted); cursor: pointer; }
.segmented button:hover { color: var(--ink); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow), 0 0 0 1px var(--line); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface);
  font-size: 13px; color: var(--ink-2); cursor: pointer; transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.chip:hover { border-color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); font-weight: 500; }

.thermo { display: inline-flex; align-items: center; gap: 8px; }
.thermo-bars { display: inline-flex; gap: 2px; }
.thermo-bars i { width: 5px; height: 12px; border-radius: 2px; background: var(--line-strong); }
.thermo-bars i.on { background: var(--c); }
.thermo-pick { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.thermo-pick button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; height: 52px; padding: 0 2px;
  border: 1px solid var(--line-strong); background: var(--surface); border-radius: var(--radius-sm);
  font-size: 11px; color: var(--muted); cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.thermo-pick button:hover { border-color: var(--muted); }
.thermo-pick .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); opacity: 0.35; transition: opacity 0.15s, transform 0.15s var(--ease); }
.thermo-pick button[aria-pressed="true"] { border-color: var(--c); background: color-mix(in srgb, var(--c) 12%, var(--surface)); color: var(--ink); font-weight: 500; }
.thermo-pick button[aria-pressed="true"] .dot { opacity: 1; transform: scale(1.2); }

.search { position: relative; display: block; width: 220px; }
.search .icon { position: absolute; left: 10px; top: 50%; translate: 0 -50%; color: var(--muted); width: 15px; height: 15px; pointer-events: none; }
.search .input { padding-left: 32px; }

/* ============ journal ============ */
.month + .month { border-top: 1px solid var(--line); }
.month-head { display: flex; align-items: baseline; gap: 10px; padding: 10px 16px; background: var(--surface-2); border-bottom: 1px solid var(--line); position: sticky; top: var(--topbar-h); z-index: 1; }
.month-head span { font-size: 12px; color: var(--muted); }
.entries-card .card-body { overflow: clip; border-radius: 0 0 var(--radius) var(--radius); }
.entry { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 14px; align-items: start; padding: 12px 16px; color: inherit; transition: background 0.12s; }
.entry:hover { background: var(--surface-2); text-decoration: none; }
.datebox { text-align: center; line-height: 1; padding-top: 2px; }
.datebox b { display: block; font-family: var(--serif); font-size: 22px; font-weight: 600; }
.datebox span { display: block; margin-top: 4px; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.entry-main { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.entry-title { display: flex; align-items: center; gap: 8px; font-weight: 600; min-width: 0; }
.entry-excerpt { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-main .tags { margin-top: 2px; }
.entry-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; font-size: 12px; white-space: nowrap; padding-top: 2px; }

/* ============ goals ============ */
.goal { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 12px; align-items: start; padding: 12px 12px 12px 16px; }
.goal-check {
  width: 22px; height: 22px; margin-top: 1px; border-radius: 50%; border: 2px solid var(--line-strong); background: var(--surface);
  display: grid; place-items: center; padding: 0; color: transparent; cursor: pointer; transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.goal-check .icon { width: 12px; height: 12px; }
.goal-check:hover { border-color: var(--ok); color: var(--ok); }
.goal-check.done { background: var(--ok); border-color: var(--ok); color: #fff; }
.goal-main { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.goal-text { font-weight: 500; overflow-wrap: anywhere; }
.goal.closed .goal-text { color: var(--muted); }
.goal.achieved .goal-text { text-decoration: line-through; text-decoration-color: var(--line-strong); }
.goal-review { font-size: 13px; color: var(--ink-2); background: var(--surface-2); border-radius: var(--radius-sm); padding: 8px 10px; white-space: pre-wrap; }

/* ============ entry detail ============ */
.links { display: flex; flex-direction: column; gap: 6px; }
.link { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; }
.comments { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.comment { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 10px; }
.bubble { background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px var(--radius) var(--radius) var(--radius); padding: 8px 12px 10px; }
.bubble-head { display: flex; align-items: center; gap: 8px; font-size: 12px; min-height: 30px; }
.bubble-head b { font-size: 13px; }
.bubble-head .btn { margin-left: auto; }
.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer .textarea { flex: 1; min-height: 40px; }

/* ============ tables ============ */
.table-wrap { overflow-x: auto; }
.dtable { width: 100%; border-collapse: collapse; }
.dtable th { text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 10px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.dtable td { padding: 10px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.dtable tr:last-child td { border-bottom: 0; }
.dtable .num { text-align: right; font-variant-numeric: tabular-nums; }
.dtable .end { text-align: right; }
.dtable tr.clickable { cursor: pointer; transition: background 0.12s; }
.dtable tr.clickable:hover { background: var(--surface-2); }

/* ============ empty ============ */
.empty { text-align: center; padding: 48px 24px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty > .icon { width: 44px; height: 44px; color: var(--line-strong); margin-bottom: 6px; }
.empty h3 { font-family: var(--serif); font-size: 18px; }
.empty p { color: var(--muted); max-width: 380px; margin-bottom: 8px; }

/* ============ dialogs ============ */
.modal { border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); width: min(460px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); }
.modal[open] { animation: pop 0.18s var(--ease); }
.modal::backdrop { background: rgb(20 15 5 / 0.45); }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 0 20px; }
.modal-head h2 { flex: 1; font-size: 18px; }
.modal-body { padding: 12px 20px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 14px 14px; }
.creds { font: 13px/1.7 ui-monospace, "Cascadia Mono", monospace; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
@keyframes pop { from { opacity: 0; transform: scale(0.97) translateY(4px); } }

/* ============ toasts (manual popover → above modals) ============ */
#toasts { position: fixed; inset: auto 0 20px 0; margin: 0 auto; width: max-content; max-width: calc(100vw - 32px); padding: 0; border: 0; background: none; overflow: visible; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
#toasts:not(:popover-open):empty { display: none; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 13px; font-weight: 500; box-shadow: var(--shadow-lg); animation: toast-in 0.22s var(--ease); }
.toast.error { background: var(--danger); color: #fff; }
.toast.leaving { animation: toast-out 0.18s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(4px); } }

/* ============ auth ============ */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; padding: 28px; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; margin-bottom: 24px; }
.auth-brand h1 { font-size: 22px; margin-top: 4px; }
.auth-brand p { color: var(--muted); font-size: 13px; }
.auth-foot { display: flex; justify-content: center; margin-top: 12px; }
.auth form { gap: 14px; }

/* ============ responsive ============ */
@media (max-width: 1180px) {
  .split { grid-template-columns: minmax(0, 1fr) 280px; }
  .split-form { grid-template-columns: 320px minmax(0, 1fr); }
  .prompts { grid-template-columns: 1fr; }
}
@media (max-width: 1020px) {
  .split, .split-form { grid-template-columns: minmax(0, 1fr); }
  .sticky { position: static; }
  .prompts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40; width: min(280px, 85vw); box-shadow: var(--shadow-lg);
    transform: translateX(-102%); transition: transform 0.25s var(--ease); visibility: hidden;
  }
  .shell.nav-open .sidebar { transform: none; visibility: visible; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgb(20 15 5 / 0.4); opacity: 0; pointer-events: none; transition: opacity 0.2s; }
  .shell.nav-open .scrim { opacity: 1; pointer-events: auto; }
  .btn.menu-btn { display: inline-flex; margin-left: -8px; }
  .topbar { padding: 8px 16px; gap: 8px; --topbar-h: 56px; }
  .content { padding: 16px 16px 40px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .card-head .search { width: 100%; order: 3; }
}
@media (max-width: 640px) {
  .btn.btn-collapse:has(.icon) { width: var(--ctl-h); padding: 0; }
  .btn-collapse:has(.icon) .btn-label { display: none; }
  .top-title h1 { font-size: 18px; }
  .top-title p { display: none; }
  .prompts, .form-grid { grid-template-columns: 1fr; }
  .entry { grid-template-columns: 36px minmax(0, 1fr); gap: 12px; }
  .entry-side { grid-column: 2; flex-direction: row; align-items: center; }
  .entry-excerpt { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .stat-value { font-size: 20px; }
  .thermo-pick button { font-size: 10px; }
  /* tables → stacked cards */
  .dtable thead { display: none; }
  .dtable tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
  .dtable tr:last-child { border-bottom: 0; }
  .dtable td { display: flex; flex-direction: column; gap: 2px; padding: 0; border: 0; text-align: left !important; }
  .dtable td::before { content: attr(data-label); font-size: 11px; color: var(--muted); }
  .dtable td.primary, .dtable td[data-label=""] { grid-column: 1 / -1; }
  .dtable td.primary::before, .dtable td[data-label=""]::before { content: none; }
  .dtable td[data-label=""] .row-actions { justify-content: flex-start; margin-left: -10px; }
  .composer { flex-direction: column; align-items: stretch; }
  .modal-foot .btn { flex: 1; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } }
@media print { .sidebar, .topbar, .btn, #toasts { display: none !important; } .shell { display: block; } body { background: #fff; } }
