/* ========================================================================
   Orbit — design system
   ======================================================================== */
:root {
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;

  --accent: #f0a04b;      /* saffron */
  --accent-2: #7c6cf0;    /* violet */
  --accent-3: #4bb39b;    /* teal */
  --accent-ink: #1a1206;

  --prio-high: #f26d6d;
  --prio-med: #f0b24b;
  --prio-low: #6db6f2;

  --radius: 14px;
  --radius-sm: 9px;
  --radius-lg: 22px;
  --shadow-1: 0 1px 2px rgba(0,0,0,.16), 0 2px 8px rgba(0,0,0,.08);
  --shadow-2: 0 8px 30px rgba(0,0,0,.22);
  --shadow-pop: 0 18px 60px rgba(0,0,0,.35);
  --ring: 0 0 0 3px color-mix(in srgb, var(--accent) 38%, transparent);
  --sidebar-w: 264px;
}

/* ---- dark (default) ---- */
:root, :root[data-theme="dark"] {
  --bg: #14110d;
  --bg-grad: radial-gradient(1200px 800px at 15% -10%, #23201a 0%, transparent 55%),
             radial-gradient(1000px 700px at 100% 0%, #1c1a24 0%, transparent 50%);
  --surface: #1e1a15;
  --surface-2: #251f19;
  --surface-3: #2e2820;
  --elevated: #2a241d;
  --line: #37302710;
  --border: #40382d;
  --border-soft: #332c23;
  --text: #f4ede1;
  --text-dim: #b7ac9a;
  --text-faint: #857c6c;
  --shadow-2: 0 12px 40px rgba(0,0,0,.5);
  color-scheme: dark;
}

/* ---- light ---- */
:root[data-theme="light"] {
  --bg: #f6f2ea;
  --bg-grad: radial-gradient(1200px 800px at 12% -12%, #fff7ec 0%, transparent 55%),
             radial-gradient(1000px 700px at 100% 0%, #f0edff 0%, transparent 55%);
  --surface: #fffdf8;
  --surface-2: #f7f2e9;
  --surface-3: #efe8db;
  --elevated: #fffefb;
  --border: #e4dccb;
  --border-soft: #ede6d8;
  --text: #26211a;
  --text-dim: #6d6455;
  --text-faint: #9a9081;
  --accent-ink: #2a1c08;
  --shadow-1: 0 1px 2px rgba(80,60,20,.08), 0 4px 14px rgba(80,60,20,.06);
  --shadow-2: 0 14px 40px rgba(70,55,25,.16);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-size: 14.5px;
  line-height: 1.5;
}
/* fixed gradient painted on a composited layer — smooth on mobile, unlike
   background-attachment: fixed which iOS ignores and desktop repaints per scroll */
body::before { content: ""; position: fixed; inset: 0; z-index: -1; background: var(--bg); background-image: var(--bg-grad); pointer-events: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: color-mix(in srgb, var(--accent) 40%, transparent); }
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 20px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: padding-box; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 8px; }

/* ---- boot ---- */
.boot { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; }
.boot-orb { font-size: 54px; animation: spin 3.4s linear infinite; }
.boot-label { font-family: var(--font-display); font-size: 22px; letter-spacing: .04em; color: var(--text-dim); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ========================================================================
   Layout
   ======================================================================== */
.app { min-height: 100%; }
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar-scrim { display: none; }

/* ---- Sidebar ---- */
.sidebar {
  position: sticky; top: 0; align-self: start; height: 100vh;
  display: flex; flex-direction: column;
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  backdrop-filter: blur(18px);
  border-right: 1px solid var(--border-soft);
  padding: 16px 12px; gap: 6px; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 12px; }
.brand-orb { font-size: 22px; filter: drop-shadow(0 2px 6px rgba(240,160,75,.5)); }
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 20px; letter-spacing: .01em; }
.brand-name small { display: block; font-family: var(--font-ui); font-weight: 450; font-size: 11px; color: var(--text-faint); letter-spacing: .02em; margin-top: -2px; }

.nav-group { margin-top: 6px; }
.nav-label { font-size: 10.5px; font-weight: 600; letter-spacing: .11em; text-transform: uppercase; color: var(--text-faint); padding: 8px 10px 4px; display: flex; justify-content: space-between; align-items: center; }
.nav-label button { color: var(--text-faint); width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; }
.nav-label button:hover { background: var(--surface-3); color: var(--text); }
.nav-item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 8px 10px; border-radius: 10px; color: var(--text-dim);
  font-weight: 500; font-size: 13.5px; text-align: left; position: relative; transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--text); }
.nav-item.active::before { content: ""; position: absolute; left: 0; top: 50%; transform: translateY(-50%); width: 3px; height: 18px; border-radius: 3px; background: var(--accent); }
.nav-item .nav-ico { width: 18px; height: 18px; display: grid; place-items: center; flex: none; }
.nav-item .nav-ico svg { width: 17px; height: 17px; }
.nav-item .nav-emoji { font-size: 15px; width: 18px; text-align: center; flex: none; }
.nav-item .count { margin-left: auto; font-size: 11px; color: var(--text-faint); background: var(--surface-3); padding: 1px 7px; border-radius: 20px; font-variant-numeric: tabular-nums; }
.folder-dot { width: 9px; height: 9px; border-radius: 3px; flex: none; }

.sidebar-foot { margin-top: auto; padding-top: 10px; display: flex; gap: 6px; align-items: center; }

/* ---- Main / topbar ---- */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px; padding: 14px 26px;
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-soft);
}
.topbar h1 { font-family: var(--font-display); font-weight: 600; font-size: 21px; margin: 0; letter-spacing: .005em; }
.topbar .crumb { color: var(--text-faint); font-size: 13px; }
.search-btn {
  margin-left: auto; display: flex; align-items: center; gap: 9px;
  background: var(--surface-2); border: 1px solid var(--border-soft); color: var(--text-faint);
  padding: 7px 12px; border-radius: 10px; font-size: 13px; min-width: 220px;
}
.search-btn:hover { border-color: var(--border); color: var(--text-dim); }
.search-btn kbd { margin-left: auto; font-family: var(--font-ui); font-size: 11px; background: var(--surface-3); padding: 2px 6px; border-radius: 5px; border: 1px solid var(--border-soft); }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: var(--text-dim); border: 1px solid transparent; transition: transform .15s cubic-bezier(.2,.8,.2,1), background .12s, color .12s, border-color .12s; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-soft); }
.icon-btn:active { transform: scale(.88); transition-duration: .06s; }
.icon-btn svg { width: 18px; height: 18px; }

.view { padding: 24px 26px 80px; max-width: 1240px; width: 100%; margin: 0 auto; }
/* entrance animation only on real navigation (.view-enter set by the router);
   reactive re-renders rebuild the DOM on every db change and must not replay it */
.view-enter .view { animation: fade .28s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ========================================================================
   Primitives
   ======================================================================== */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  padding: 9px 15px; border-radius: 10px; font-weight: 550; font-size: 13.5px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  transition: transform .16s cubic-bezier(.2,.8,.2,1), background .14s, border-color .14s, box-shadow .16s, filter .14s;
}
.btn:hover { background: var(--surface-3); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(0,0,0,.16); }
.btn:active { transform: translateY(0) scale(.97); box-shadow: none; transition-duration: .06s; }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 92%, #fff), var(--accent)); color: var(--accent-ink); border-color: color-mix(in srgb, var(--accent) 60%, #000); font-weight: 650; box-shadow: 0 2px 10px color-mix(in srgb, var(--accent) 30%, transparent); }
.btn.primary:hover { filter: brightness(1.05); box-shadow: 0 6px 22px color-mix(in srgb, var(--accent) 45%, transparent); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn.danger { color: var(--prio-high); border-color: color-mix(in srgb, var(--prio-high) 40%, var(--border)); }
.btn.danger:hover { background: color-mix(in srgb, var(--prio-high) 14%, transparent); }

.input, .textarea, select.input {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 12px; color: var(--text); font-size: 13.5px; transition: border-color .12s;
}
.input:focus, .textarea:focus, select.input:focus { border-color: color-mix(in srgb, var(--accent) 60%, var(--border)); box-shadow: var(--ring); outline: none; }
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.textarea { resize: vertical; min-height: 90px; line-height: 1.55; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 550; color: var(--text-dim); }
.row { display: flex; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

.card {
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius);
  box-shadow: var(--shadow-1);
}
.card.pad { padding: 18px; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 20px; background: var(--surface-3); color: var(--text-dim); }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 9px; border-radius: 20px; background: var(--surface-2); border: 1px solid var(--border-soft); color: var(--text-dim); }
.tag { display: inline-flex; align-items: center; font-size: 11.5px; padding: 1px 8px; border-radius: 6px; background: color-mix(in srgb, var(--accent-2) 16%, transparent); color: color-mix(in srgb, var(--accent-2) 92%, var(--text)); font-weight: 550; }
.tag::before { content: "#"; opacity: .6; margin-right: 1px; }

.prio { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 650; padding: 1px 8px; border-radius: 6px; text-transform: capitalize; }
.prio::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.prio.high { color: var(--prio-high); background: color-mix(in srgb, var(--prio-high) 15%, transparent); }
.prio.med { color: var(--prio-med); background: color-mix(in srgb, var(--prio-med) 15%, transparent); }
.prio.low { color: var(--prio-low); background: color-mix(in srgb, var(--prio-low) 15%, transparent); }

.due { font-size: 11.5px; font-weight: 550; color: var(--text-faint); display: inline-flex; align-items: center; gap: 4px; }
.due.today { color: var(--accent); }
.due.over { color: var(--prio-high); }
.due.remind { color: var(--accent-2); }

.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.page-head .ph-title { font-family: var(--font-display); font-size: 30px; font-weight: 600; margin: 0; line-height: 1.1; }
.page-head .ph-sub { color: var(--text-dim); font-size: 13.5px; margin-top: 4px; }
.page-head .ph-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.empty { text-align: center; padding: 44px 20px; color: var(--text-faint); }
.empty .em-ico { font-size: 34px; opacity: .8; }
.empty .em-title { color: var(--text-dim); font-weight: 600; margin-top: 8px; }
.empty .em-sub { font-size: 13px; margin-top: 2px; }

.section-title { font-size: 12px; font-weight: 650; letter-spacing: .07em; text-transform: uppercase; color: var(--text-faint); margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }

/* ---- checkbox ---- */
.check { appearance: none; width: 19px; height: 19px; border-radius: 6px; border: 1.8px solid var(--border); background: var(--surface); flex: none; display: grid; place-items: center; cursor: pointer; transition: .12s; position: relative; }
.check:hover { border-color: var(--accent); }
.check:checked { background: var(--accent); border-color: var(--accent); animation: checkpop .3s cubic-bezier(.3,1.6,.4,1); }
.check:checked::after { content: ""; width: 5px; height: 9px; border: solid var(--accent-ink); border-width: 0 2.2px 2.2px 0; transform: rotate(43deg) translateY(-1px); }
@keyframes checkpop { 0% { transform: scale(.55); } 100% { transform: scale(1); } }

/* ========================================================================
   Dashboard
   ======================================================================== */
.dash-hero { display: flex; align-items: flex-end; gap: 18px; margin-bottom: 22px; }
.dash-hero .greet { font-family: var(--font-display); font-size: 32px; font-weight: 600; line-height: 1.05; }
.dash-hero .subgreet { color: var(--text-dim); margin-top: 4px; font-size: 14px; }
.dash-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 16px; }
.col-8 { grid-column: span 8; }
.col-6 { grid-column: span 6; }
.col-4 { grid-column: span 4; }
.col-12 { grid-column: span 12; }

.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 4px; }
.stat { padding: 14px 16px; }
.stat .s-num { font-family: var(--font-display); font-size: 27px; font-weight: 600; line-height: 1; }
.stat .s-lbl { color: var(--text-dim); font-size: 12px; margin-top: 5px; display: flex; align-items: center; gap: 6px; }
.stat .s-ico { font-size: 15px; }

.quickcap { display: flex; gap: 8px; align-items: center; padding: 10px; }
.quickcap input { border: none; background: transparent; flex: 1; font-size: 14px; padding: 4px 6px; }
.quickcap input:focus { box-shadow: none; }
.quickcap .seg { display: flex; background: var(--surface-2); border-radius: 9px; padding: 3px; }
.seg-btn { padding: 5px 11px; border-radius: 7px; font-size: 12.5px; font-weight: 550; color: var(--text-dim); }
.seg-btn.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }

.list { display: flex; flex-direction: column; }
.task-row { display: flex; align-items: center; gap: 11px; padding: 10px 6px; border-bottom: 1px solid var(--border-soft); }
.task-row:last-child { border-bottom: none; }
.task-row .t-main { min-width: 0; flex: 1; }
.task-row .t-title { font-weight: 500; font-size: 13.5px; }
.task-row.done .t-title { text-decoration: line-through; color: var(--text-faint); }
.task-row .t-meta { display: flex; gap: 8px; align-items: center; margin-top: 3px; flex-wrap: wrap; }
.task-row .t-grip { color: var(--text-faint); cursor: grab; opacity: 0; }
.task-row:hover .t-grip { opacity: 1; }
.task-row.dragging { opacity: .4; }
.mini-folder { font-size: 11px; color: var(--text-faint); display: inline-flex; align-items: center; gap: 4px; }

.goal-card { padding: 14px 16px; display: flex; gap: 14px; align-items: center; }
.ring { --p: 0; width: 46px; height: 46px; border-radius: 50%; flex: none;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--surface-3) 0);
  display: grid; place-items: center; position: relative; }
.ring::before { content: ""; position: absolute; inset: 5px; background: var(--surface); border-radius: 50%; }
.ring span { position: relative; font-size: 11.5px; font-weight: 650; font-variant-numeric: tabular-nums; }
.goal-card .g-title { font-weight: 550; }
.goal-card .g-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.insight-item { display: flex; gap: 11px; padding: 11px 4px; border-bottom: 1px solid var(--border-soft); }
.insight-item:last-child { border-bottom: none; }
.insight-item .i-ico { font-size: 17px; flex: none; margin-top: 1px; }
.insight-item .i-body { font-size: 13px; }
.insight-item .i-body b { font-weight: 600; }
.insight-item .i-act { font-size: 12px; color: var(--accent); margin-top: 3px; display: inline-block; }

/* ========================================================================
   Folder view (tabs)
   ======================================================================== */
.tabs { display: flex; gap: 3px; border-bottom: 1px solid var(--border-soft); margin-bottom: 20px; }
.tab { padding: 9px 14px; font-weight: 550; font-size: 13.5px; color: var(--text-dim); border-bottom: 2px solid transparent; margin-bottom: -1px; display: flex; align-items: center; gap: 7px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-color: var(--accent); }
.tab .count { font-size: 11px; background: var(--surface-3); padding: 0 7px; border-radius: 20px; color: var(--text-faint); }

.notes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.note-card { padding: 15px 16px; cursor: pointer; transition: transform .1s, border-color .12s; display: flex; flex-direction: column; gap: 8px; min-height: 132px; }
.note-card:hover { transform: translateY(-2px); border-color: var(--border); }
.note-card .nc-title { font-family: var(--font-display); font-weight: 600; font-size: 16px; display: flex; align-items: center; gap: 6px; }
.note-card .nc-pin { color: var(--accent); }
.note-card .nc-excerpt { font-size: 12.5px; color: var(--text-dim); line-height: 1.5; flex: 1; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; }
.note-card .nc-foot { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.note-card .nc-date { font-size: 11px; color: var(--text-faint); margin-left: auto; }

/* note editor */
.editor-wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 0; height: calc(100vh - 128px); border: 1px solid var(--border-soft); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.editor-pane { display: flex; flex-direction: column; min-width: 0; }
.editor-pane.preview { border-left: 1px solid var(--border-soft); background: var(--surface-2); }
.editor-toolbar { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--border-soft); flex-wrap: wrap; }
.tb-preview { display: none; } /* shown ≤980px where the preview pane is hidden */
.editor-title { border: none; background: transparent; font-family: var(--font-display); font-size: 22px; font-weight: 600; padding: 14px 20px 6px; width: 100%; }
.editor-title:focus { box-shadow: none; }
.editor-body { border: none; background: transparent; resize: none; flex: 1; padding: 6px 20px 20px; font-family: 'SF Mono', ui-monospace, Menlo, monospace; font-size: 13.5px; line-height: 1.65; }
.editor-body:focus { box-shadow: none; }
.md { padding: 18px 22px; overflow-y: auto; line-height: 1.65; }
.md h1, .md h2, .md h3 { font-family: var(--font-display); line-height: 1.25; margin: 1.1em 0 .5em; }
.md h1 { font-size: 25px; } .md h2 { font-size: 20px; } .md h3 { font-size: 16.5px; }
.md p { margin: .6em 0; } .md ul, .md ol { padding-left: 1.4em; margin: .5em 0; }
.md li { margin: .25em 0; }
.md code { background: var(--surface-3); padding: 1px 6px; border-radius: 5px; font-size: .9em; font-family: ui-monospace, Menlo, monospace; }
.md pre { background: var(--surface-3); padding: 12px 14px; border-radius: 10px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { border-left: 3px solid var(--accent); margin: .6em 0; padding: 2px 14px; color: var(--text-dim); }
.md hr { border: none; border-top: 1px solid var(--border); margin: 1.2em 0; }
.md a.wikilink { background: color-mix(in srgb, var(--accent-2) 15%, transparent); padding: 0 4px; border-radius: 4px; text-decoration: none; }
.md .md-task { list-style: none; margin-left: -1.2em; display: flex; gap: 8px; align-items: baseline; }
.backlinks { margin-top: 22px; padding-top: 16px; border-top: 1px dashed var(--border); }

/* ---- diagrams: tier list ---- */
.tierlist { margin: .8em 0; border: 1px solid var(--border-soft); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; gap: 2px; background: var(--border-soft); }
.tier-row { display: flex; align-items: stretch; min-height: 52px; background: var(--surface-2); }
.tier-label { flex: none; width: 54px; display: grid; place-items: center; font-family: var(--font-display); font-weight: 700; font-size: 20px; color: #1a1206; text-shadow: 0 1px 1px rgba(255,255,255,.25); }
.tier-items { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px 10px; min-width: 0; }
.tier-chip { background: var(--surface); border: 1px solid var(--border-soft); border-radius: 7px; padding: 4px 9px; font-size: 12.5px; font-weight: 500; }
.tier-empty { color: var(--text-faint); }

/* ---- diagrams: flowchart ---- */
.flow-wrap { margin: .8em 0; overflow-x: auto; padding: 4px 2px 8px; -webkit-overflow-scrolling: touch; }
.flow-svg { max-width: 100%; height: auto; color: var(--text-faint); }
.flow-edge { fill: none; stroke: var(--text-faint); stroke-width: 1.6; }
.flow-lblbg { fill: var(--surface); stroke: var(--border-soft); stroke-width: 1; }
.flow-lbl { fill: var(--text-dim); font-size: 10.5px; font-family: var(--font-ui); }
.flow-node rect { fill: var(--surface-2); stroke: var(--border); stroke-width: 1.5; }
.flow-node text { fill: var(--text); font-size: 12.5px; font-weight: 550; font-family: var(--font-ui); }
.flow-node.start rect { fill: color-mix(in srgb, var(--accent-3) 22%, var(--surface)); stroke: var(--accent-3); }
.flow-node.end rect { fill: color-mix(in srgb, var(--accent) 20%, var(--surface)); stroke: var(--accent); }
.flow-node.dec rect { fill: color-mix(in srgb, var(--accent-2) 20%, var(--surface)); stroke: var(--accent-2); }

/* ========================================================================
   Kanban
   ======================================================================== */
.kanban { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; align-items: start; }
.kcol { background: var(--surface-2); border-radius: var(--radius); padding: 6px; min-height: 200px; border: 1px solid var(--border-soft); }
.kcol.dragover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface-2)); }
.kcol-head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 8px; font-weight: 600; font-size: 13px; }
.kcol-head .dot { width: 8px; height: 8px; border-radius: 50%; }
.kcard { background: var(--surface); border: 1px solid var(--border-soft); border-radius: 10px; padding: 11px 12px; margin: 6px; box-shadow: var(--shadow-1); cursor: grab; }
.kcard.dragging { opacity: .4; }
.kcard .kc-title { font-weight: 500; font-size: 13.5px; }
.kcard .kc-meta { display: flex; gap: 6px; align-items: center; margin-top: 8px; flex-wrap: wrap; }

/* ========================================================================
   Calendar
   ======================================================================== */
.cal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.cal-head .cal-title { font-family: var(--font-display); font-size: 22px; font-weight: 600; min-width: 190px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--border-soft); border: 1px solid var(--border-soft); border-radius: var(--radius); overflow: hidden; }
.cal-dow { background: var(--surface-2); padding: 8px; text-align: center; font-size: 11px; font-weight: 600; color: var(--text-faint); text-transform: uppercase; letter-spacing: .05em; }
.cal-cell { background: var(--surface); min-height: 104px; padding: 6px 7px; display: flex; flex-direction: column; gap: 3px; cursor: pointer; transition: background .1s; position: relative; }
.cal-cell:hover { background: var(--surface-2); }
.cal-cell.other { background: var(--bg); color: var(--text-faint); }
.cal-cell.today .cal-num { background: var(--accent); color: var(--accent-ink); }
.cal-num { font-size: 12.5px; font-weight: 600; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 7px; align-self: flex-end; }
.cal-ev { font-size: 11px; padding: 2px 6px; border-radius: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 4px; }
.cal-ev .evdot { width: 6px; height: 6px; border-radius: 50%; flex: none; }
.cal-ev.task { background: color-mix(in srgb, var(--accent) 15%, transparent); }
.cal-ev.goal { background: color-mix(in srgb, var(--accent-3) 18%, transparent); }
.cal-ev.event { background: color-mix(in srgb, var(--accent-2) 16%, transparent); }
.cal-more { font-size: 10.5px; color: var(--text-faint); padding-left: 6px; }

/* ========================================================================
   Meal planner
   ======================================================================== */
.meal-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.meal-board { display: grid; grid-template-columns: 88px repeat(7, 1fr); gap: 8px; }
.meal-corner { }
.meal-daycol { }
.meal-dayhead { text-align: center; padding: 6px; font-size: 12px; font-weight: 600; color: var(--text-dim); }
.meal-dayhead .dnum { font-family: var(--font-display); font-size: 17px; color: var(--text); display: block; }
.meal-dayhead.today .dnum { color: var(--accent); }
.slot-label { display: flex; align-items: center; justify-content: flex-end; padding-right: 8px; font-size: 11.5px; font-weight: 600; color: var(--text-faint); height: 118px; text-transform: uppercase; letter-spacing: .03em; gap: 5px; }
.meal-cell {
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: 12px;
  min-height: 118px; padding: 8px; display: flex; flex-direction: column; gap: 6px; cursor: pointer;
  transition: border-color .12s, transform .1s;
}
.meal-cell:hover { border-color: var(--border); }
.meal-cell.filled { background: linear-gradient(180deg, var(--surface), var(--surface-2)); }
.meal-cell .mc-name { font-size: 12px; font-weight: 600; line-height: 1.2; }
.meal-cell .mc-empty { color: var(--text-faint); font-size: 20px; margin: auto; opacity: .5; }
.plate {
  --sz: 62px; width: var(--sz); height: var(--sz); border-radius: 50%; margin: 2px auto;
  background: radial-gradient(circle at 50% 42%, var(--surface-3), var(--surface-2));
  box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--border) 60%, transparent), var(--shadow-1);
  display: grid; place-items: center; position: relative; overflow: hidden;
}
.plate-emojis { display: flex; flex-wrap: wrap; gap: 0; justify-content: center; align-items: center; max-width: 48px; line-height: 1; }
.plate-emojis span { font-size: 16px; margin: -1px; }
.plate-emojis.n1 span { font-size: 30px; }
.plate-emojis.n2 span { font-size: 22px; }
.plate-emojis.n3 span { font-size: 19px; }
.ingredient-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.ing-chip { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; background: var(--surface-3); padding: 1px 6px 1px 4px; border-radius: 20px; }
.ing-chip .ie { font-size: 13px; }

/* grocery */
.grocery-panel { }
.grocery-cat { margin-bottom: 16px; }
.grocery-cat h4 { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); margin: 0 0 8px; display: flex; align-items: center; gap: 7px; }
.grocery-item { display: flex; align-items: center; gap: 10px; padding: 7px 4px; border-bottom: 1px solid var(--border-soft); }
.grocery-item .gi-emoji { font-size: 17px; }
.grocery-item.checked .gi-name { text-decoration: line-through; color: var(--text-faint); }
.grocery-item .gi-qty { margin-left: auto; font-size: 11.5px; color: var(--text-faint); font-variant-numeric: tabular-nums; }

/* recipe library */
.recipe-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.recipe-card { padding: 14px; cursor: pointer; }
.recipe-card .rc-emojis { font-size: 24px; margin-bottom: 6px; letter-spacing: -2px; }
.recipe-card .rc-name { font-weight: 600; font-family: var(--font-display); font-size: 15px; }
.recipe-card .rc-count { font-size: 12px; color: var(--text-dim); margin-top: 3px; }

/* ========================================================================
   Insights / graph
   ======================================================================== */
.insight-cols { display: grid; grid-template-columns: 1.3fr 1fr; gap: 18px; align-items: start; }
.graph-wrap { position: relative; height: 460px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border-soft); background: radial-gradient(circle at 50% 45%, var(--surface-2), var(--surface)); }
.graph-wrap svg { width: 100%; height: 100%; display: block; cursor: grab; }
.gnode circle { transition: fill .15s; }
.gnode text { font-size: 10px; fill: var(--text-dim); pointer-events: none; }
.glink { stroke: var(--border); stroke-opacity: .8; }
.ai-panel { padding: 18px; }
.ai-out { white-space: normal; line-height: 1.6; font-size: 13.5px; }
.ai-out h1,.ai-out h2,.ai-out h3 { font-family: var(--font-display); margin: .9em 0 .4em; }
.ai-out ul { padding-left: 1.3em; }
.spin-inline { display: inline-block; animation: spin 1s linear infinite; }

/* ========================================================================
   Modal / palette / toast
   ======================================================================== */
.modal-backdrop { position: fixed; inset: 0; background: rgba(8,6,3,.55); backdrop-filter: blur(3px); display: grid; place-items: center; z-index: 100; animation: fade .16s; padding: 20px; }
.modal { background: var(--elevated); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop); width: 100%; max-width: 520px; max-height: 88vh; overflow: auto; animation: pop .2s cubic-bezier(.2,.9,.3,1.3); }
.modal.wide { max-width: 720px; }
@keyframes pop { from { transform: scale(.96) translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 18px 20px 6px; }
.modal-head h3 { font-family: var(--font-display); font-size: 19px; margin: 0; font-weight: 600; }
.modal-body { padding: 14px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 8px 20px 20px; }

.palette-backdrop { position: fixed; inset: 0; background: rgba(8,6,3,.5); backdrop-filter: blur(4px); display: flex; justify-content: center; align-items: flex-start; padding-top: 12vh; z-index: 120; animation: fade .14s; }
.palette { background: var(--elevated); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-pop); width: 100%; max-width: 580px; overflow: hidden; animation: pop .18s; }
.palette-input { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border-soft); }
.palette-input input { border: none; background: transparent; flex: 1; font-size: 16px; }
.palette-input input:focus { box-shadow: none; }
.palette-results { max-height: 52vh; overflow-y: auto; padding: 6px; }
.palette-item { display: flex; align-items: center; gap: 11px; padding: 9px 11px; border-radius: 9px; cursor: pointer; }
.palette-item.sel { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.palette-item .pi-ico { width: 22px; text-align: center; font-size: 15px; color: var(--text-dim); }
.palette-item .pi-title { font-size: 13.5px; font-weight: 500; }
.palette-item .pi-sub { font-size: 11.5px; color: var(--text-faint); }
.palette-item .pi-kind { margin-left: auto; font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .05em; }
.palette-empty { padding: 26px; text-align: center; color: var(--text-faint); font-size: 13px; }

.toast-host { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 200; align-items: center; }
.toast { background: var(--elevated); border: 1px solid var(--border); box-shadow: var(--shadow-pop); border-radius: 11px; padding: 10px 16px; font-size: 13px; display: flex; align-items: center; gap: 9px; animation: pop .2s; }
.toast .t-emoji { font-size: 15px; }

/* color swatches */
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 30px; height: 30px; border-radius: 9px; cursor: pointer; border: 2px solid transparent; }
.swatch.on { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface); }
.emoji-pick { display: flex; gap: 6px; flex-wrap: wrap; }
.emoji-opt { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; font-size: 18px; background: var(--surface-2); border: 1px solid var(--border-soft); }
.emoji-opt.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }

.menu { position: fixed; background: var(--elevated); border: 1px solid var(--border); border-radius: 11px; box-shadow: var(--shadow-pop); padding: 6px; z-index: 90; min-width: 168px; max-height: calc(100dvh - 16px); overflow-y: auto; animation: pop .12s; }
.menu-item { display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: 8px; font-size: 13px; width: 100%; text-align: left; color: var(--text-dim); }
.menu-item:hover { background: var(--surface-2); color: var(--text); }
.menu-item.danger:hover { background: color-mix(in srgb, var(--prio-high) 14%, transparent); color: var(--prio-high); }
.menu-sep { height: 1px; background: var(--border-soft); margin: 5px 4px; }

/* ---- responsive ---- */
.menu-toggle { display: none; }
@media (max-width: 980px) {
  .col-8, .col-6, .col-4 { grid-column: span 12; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .editor-wrap { grid-template-columns: 1fr; height: calc(100dvh - 170px); }
  .editor-pane.preview { display: none; }
  .editor-wrap.mob-preview .editor-pane.preview { display: flex; overflow-y: auto; }
  .editor-wrap.mob-preview .editor-pane:not(.preview) { display: none; }
  .tb-preview { display: inline-flex; }
  .insight-cols { grid-template-columns: 1fr; }
  /* meal board: keep the week grid, scroll it sideways */
  .meal-board { grid-template-columns: 58px repeat(7, minmax(138px, 1fr)); overflow-x: auto; padding-bottom: 10px; -webkit-overflow-scrolling: touch; }
  .slot-label { padding-right: 4px; font-size: 9px; letter-spacing: 0; gap: 3px; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 60; width: min(300px, 84vw); transform: translateX(-100%); transition: transform .26s cubic-bezier(.2,.8,.2,1); box-shadow: var(--shadow-pop); padding-top: calc(16px + env(safe-area-inset-top)); }
  .sidebar.open { transform: none; }
  .menu-toggle { display: grid; }
  .sidebar-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); backdrop-filter: blur(2px); z-index: 55; display: none; animation: fade .2s; }
  .sidebar-scrim.show { display: block; }
  /* kanban: horizontal snap-scroll columns (drag-drop is a desktop gesture) */
  .kanban { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 80%; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 10px; -webkit-overflow-scrolling: touch; }
  .kanban .kcol { scroll-snap-align: start; }
  .search-btn { min-width: 0; }
  .search-btn .lbl { display: none; }
  .view { padding: 18px 14px 90px; }
  /* safe-area top so the sticky bar clears the iPhone status bar / notch when
     installed standalone with the translucent status bar */
  .topbar { padding: calc(10px + env(safe-area-inset-top)) 14px 10px; }
  .topbar h1 { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .page-head { flex-wrap: wrap; }
  .page-head .ph-title { font-size: 25px; }
  /* 16px inputs stop iOS Safari from auto-zooming on focus */
  .input, .textarea, select.input, .editor-title, .editor-body, .quickcap input, .palette-input input { font-size: 16px; }
  .quickcap { flex-wrap: wrap; }
  .quickcap input { flex: 1 1 150px; }
  .toast-host { bottom: calc(18px + env(safe-area-inset-bottom)); width: calc(100% - 24px); }
}

/* ---- small phones ---- */
@media (max-width: 640px) {
  /* modals become bottom sheets */
  .modal-backdrop { place-items: end center; padding: 0; }
  .modal, .modal.wide { max-width: 100%; border-radius: 20px 20px 0 0; max-height: 92dvh; animation: sheet .3s cubic-bezier(.2,.9,.3,1); padding-bottom: env(safe-area-inset-bottom); }
  .modal-foot { position: sticky; bottom: 0; background: var(--elevated); border-top: 1px solid var(--border-soft); padding-top: 12px; }
  .modal-body .row { flex-direction: column; }
  /* calendar: chips condense to color-dots */
  .cal-cell { min-height: 56px; padding: 4px 5px; flex-direction: row; flex-wrap: wrap; gap: 3px; align-content: flex-start; }
  .cal-num { width: 100%; height: 17px; background: none !important; color: inherit !important; display: block; text-align: right; font-size: 11.5px; }
  .cal-cell.today { outline: 2px solid var(--accent); outline-offset: -2px; }
  .cal-cell.today .cal-num { color: var(--accent) !important; }
  .cal-ev { width: 8px; height: 8px; padding: 0; border-radius: 50%; font-size: 0; flex: none; }
  /* solid dot colors — the desktop 15%-alpha chip background is invisible at 8px */
  .cal-ev.task { background: var(--accent); }
  .cal-ev.goal { background: var(--accent-3); }
  .cal-ev.event { background: var(--accent-2); }
  .cal-ev .evdot { display: none; }
  .cal-more { display: none; }
  .cal-head { flex-wrap: wrap; gap: 8px; }
  .cal-head .chip { display: none; }
  .cal-head .cal-title { min-width: 0; font-size: 18px; }
  .dash-hero .greet { font-size: 26px; }
  .notes-grid { grid-template-columns: 1fr; }
  .recipe-grid { grid-template-columns: repeat(2, 1fr); }
}
@keyframes sheet { from { transform: translateY(48px); opacity: 0; } }

/* ---- touch ergonomics ---- */
@media (pointer: coarse) {
  .icon-btn { width: 40px; height: 40px; }
  .nav-item { padding: 11px 12px; }
  .check { width: 22px; height: 22px; }
  .task-row { padding: 12px 6px; }
  .seg-btn { padding: 8px 13px; }
  .btn.sm { padding: 8px 13px; }
  .menu-item { padding: 11px 12px; }
  .tab { padding: 11px 15px; }
}

/* ========================================================================
   Motion & micro-interactions
   ======================================================================== */
/* ripple (spawned by installEffects in ui.js) */
.btn, .icon-btn, .seg-btn, .nav-item, .tab, .chip, .palette-item, .menu-item { position: relative; overflow: hidden; }
.ripple { position: absolute; border-radius: 50%; background: currentColor; opacity: .15; transform: scale(0); animation: ripple .55s ease-out forwards; pointer-events: none; }
@keyframes ripple { to { transform: scale(1); opacity: 0; } }

/* staggered entrance for page sections — navigation only (see .view-enter) */
.view-enter .view > * { animation: rise .4s cubic-bezier(.2,.8,.2,1) backwards; }
.view-enter .view > *:nth-child(2) { animation-delay: .05s; }
.view-enter .view > *:nth-child(3) { animation-delay: .09s; }
.view-enter .view > *:nth-child(4) { animation-delay: .13s; }
.view-enter .view > *:nth-child(n+5) { animation-delay: .16s; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

/* cards lift on hover */
.kcard { transition: transform .16s cubic-bezier(.2,.8,.2,1), box-shadow .16s, border-color .16s; }
.kcard:hover { transform: translateY(-2px); border-color: var(--border); box-shadow: var(--shadow-2); }
.goal-card, .recipe-card { transition: transform .16s cubic-bezier(.2,.8,.2,1), border-color .16s, box-shadow .16s; }
.goal-card:hover, .recipe-card:hover { transform: translateY(-2px); border-color: var(--border); box-shadow: var(--shadow-2); }

/* meal plates give a happy wobble */
.plate { transition: transform .3s cubic-bezier(.3,1.4,.4,1); }
.meal-cell:hover .plate { transform: rotate(-5deg) scale(1.07); }

/* goal rings animate progress changes */
@property --p { syntax: '<number>'; inherits: false; initial-value: 0; }
.ring { transition: --p .7s cubic-bezier(.2,.8,.2,1); }

/* toast emoji pops in */
.toast .t-emoji { display: inline-block; animation: emoji-pop .45s cubic-bezier(.3,1.6,.4,1); }
@keyframes emoji-pop { 0% { transform: scale(0) rotate(-30deg); } 100% { transform: none; } }

/* segmented control: springier selection */
.seg-btn { transition: background .16s, color .16s, transform .12s, box-shadow .16s; }
.seg-btn:active { transform: scale(.94); }

/* tabs underline slide-in */
.tab { transition: color .14s, border-color .18s; }

/* respect reduced-motion everywhere — animation-delay must be zeroed too, or
   `backwards`-fill children sit invisible through their stagger delay */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
