/* =====================================================================
   Planning Tool — design system
   Swiss Modernism 2.0 x Data-Dense Dashboard. 3 layers: primitive tokens
   -> semantic tokens -> component classes. Components consume semantic
   tokens only, never primitives directly, so re-theming never needs a
   component rewrite.
   ===================================================================== */

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('/static/fonts/inter-var.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url('/static/fonts/jbmono.woff2') format('woff2');
}

/* ---------- 1. Primitive tokens ---------- */
:root {
  --p-teal-400: #2DD4BF; --p-teal-500: #14B8A6; --p-teal-600: #0D9488; --p-teal-700: #0F766E; --p-teal-800: #115E54;
  --p-slate-50: #F8FAFC; --p-slate-100: #F1F5F9; --p-slate-200: #E4E7EB; --p-slate-300: #CBD5E1;
  --p-slate-400: #94A3B8; --p-slate-500: #64748B; --p-slate-600: #475569; --p-slate-700: #334155;
  --p-slate-800: #1B2639; --p-slate-850: #131C2E; --p-slate-900: #0F172A; --p-slate-950: #0B1120;
  --p-green-500: #059669; --p-green-400: #34D399;
  --p-amber-500: #D97706; --p-amber-400: #FBBF24;
  --p-red-500: #DC2626; --p-red-400: #F87171;
  --p-white: #FFFFFF;

  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 24px; --space-6: 32px; --space-7: 48px;
  --radius-sm: 6px; --radius-md: 10px; --radius-lg: 14px; --radius-full: 999px;

  --text-xs: .75rem; --text-sm: .8125rem; --text-base: .875rem; --text-md: 1rem;
  --text-lg: 1.25rem; --text-xl: 1.5rem; --text-2xl: 2rem;
  --leading-tight: 1.25; --leading-normal: 1.5;
  --weight-regular: 400; --weight-medium: 500; --weight-semibold: 600;

  --dur-fast: 120ms; --dur: 200ms; --dur-slow: 280ms;
  --ease-out: cubic-bezier(.16, 1, .3, 1); --ease-in: cubic-bezier(.7, 0, 1, 1);

  --row-h: 36px; --card-pad: 12px; --gap: 8px; --appbar-h: 56px; --sidebar-w: 240px;
  --sidebar-w-collapsed: 64px;
  --touch-target: 44px;
}

/* ---------- 2. Semantic tokens — light (default) ---------- */
:root, :root[data-theme="light"] {
  color-scheme: light;
  --bg: var(--p-slate-50);
  --surface: var(--p-white);
  --surface-raised: var(--p-white);
  --surface-sunken: var(--p-slate-100);
  --fg: var(--p-slate-900);
  --fg-muted: var(--p-slate-500);
  --fg-subtle: var(--p-slate-400);
  --border: var(--p-slate-200);
  --border-strong: var(--p-slate-300);
  /* p-teal-600 reads well as an accent but white-on-600 measures 3.74:1 -- below the
     4.5:1 text-contrast minimum for a button label at this font-size/weight. 700/800
     keep the same hue while giving on-primary white text 5.47:1 / 7.63:1. */
  --primary: var(--p-teal-700);
  --primary-hover: var(--p-teal-800);
  --on-primary: var(--p-white);
  --primary-wash: #E6F7F5;
  --success: var(--p-green-500);
  --success-wash: #ECFDF5;
  --warning: var(--p-amber-500);
  --warning-wash: #FFFBEB;
  --danger: var(--p-red-500);
  --danger-wash: #FEF2F2;
  --focus-ring: var(--p-teal-700);
  --shadow-1: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 1px rgba(15, 23, 42, .04);
  --shadow-2: 0 4px 12px rgba(15, 23, 42, .08), 0 2px 4px rgba(15, 23, 42, .04);
  --shadow-3: 0 16px 40px rgba(15, 23, 42, .16), 0 4px 10px rgba(15, 23, 42, .08);
  --scrim: rgba(15, 23, 42, .5);
}

/* ---------- 2b. Semantic tokens — dark ----------
   Desaturated, lighter tonal variants — never a raw inversion of light values.
   Shadows barely read on dark, so elevation leans on surface-lightness instead. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { color-scheme: dark; }
  :root:not([data-theme="light"]) {
    --bg: var(--p-slate-950);
    --surface: var(--p-slate-850);
    --surface-raised: var(--p-slate-800);
    --surface-sunken: #0E1728;
    --fg: #E8EDF5;
    --fg-muted: var(--p-slate-400);
    --fg-subtle: #5B6B84;
    --border: #243044;
    --border-strong: #324160;
    --primary: var(--p-teal-400);
    --primary-hover: #5EEAD4;
    --on-primary: #04201C;
    --primary-wash: #0E2E2A;
    --success: var(--p-green-400);
    --success-wash: #0C2A20;
    --warning: var(--p-amber-400);
    --warning-wash: #2E2308;
    --danger: var(--p-red-400);
    --danger-wash: #34120F;
    --focus-ring: var(--p-teal-400);
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-2: 0 4px 16px rgba(0, 0, 0, .5);
    --shadow-3: 0 20px 48px rgba(0, 0, 0, .6);
    --scrim: rgba(0, 0, 0, .65);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: var(--p-slate-950); --surface: var(--p-slate-850); --surface-raised: var(--p-slate-800);
  --surface-sunken: #0E1728; --fg: #E8EDF5; --fg-muted: var(--p-slate-400); --fg-subtle: #5B6B84;
  --border: #243044; --border-strong: #324160; --primary: var(--p-teal-400);
  --primary-hover: #5EEAD4; --on-primary: #04201C; --primary-wash: #0E2E2A;
  --success: var(--p-green-400); --success-wash: #0C2A20; --warning: var(--p-amber-400);
  --warning-wash: #2E2308; --danger: var(--p-red-400); --danger-wash: #34120F;
  --focus-ring: var(--p-teal-400); --shadow-1: 0 1px 2px rgba(0,0,0,.4);
  --shadow-2: 0 4px 16px rgba(0,0,0,.5); --shadow-3: 0 20px 48px rgba(0,0,0,.6);
  --scrim: rgba(0, 0, 0, .65);
}

/* ---------- 3. Reset & base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: var(--text-md); line-height: var(--leading-normal);
  margin: 0; background: var(--bg); color: var(--fg);
  transition: background var(--dur) var(--ease-out), color var(--dur) var(--ease-out);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'tnum' 1, 'cv11' 1;
}
h1, h2, h3 { font-weight: var(--weight-semibold); line-height: var(--leading-tight); margin: 0; letter-spacing: -.011em; }
h1 { font-size: var(--text-xl); } h2 { font-size: var(--text-lg); margin-top: var(--space-6); margin-bottom: var(--space-2); }
h3 { font-size: var(--text-md); }
a { color: var(--primary); }
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.hint { color: var(--fg-muted); font-size: var(--text-sm); line-height: var(--leading-normal); }
.grey { color: var(--fg-muted); }
.red, .text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.inline { display: inline; }
::selection { background: var(--primary-wash); color: var(--fg); }

:focus-visible {
  outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: var(--radius-sm);
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

main { max-width: 68em; margin: 0 auto; padding: var(--space-5); }
@media (max-width: 640px) { main { padding: var(--space-3); } }

/* ---------- 4. Shell: app bar / sidebar ---------- */
/* .app-shell is a flex container at every width (only flex-direction changes at the
   desktop breakpoint below) -- flex items default to min-width:auto, not 0, so without
   this, wide content (e.g. the Gantt SVG) forces the whole shell wider than the
   viewport even in mobile's column layout. Must apply unconditionally, not just >=1024px. */
.app-shell { display: flex; flex-direction: column; min-height: 100dvh; }
.app-main { min-width: 0; }
nav.appnav {
  display: flex; align-items: center; gap: var(--space-1);
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 var(--space-4); height: var(--appbar-h); flex-wrap: nowrap;
  position: sticky; top: 0; z-index: 40; overflow-x: auto;
}
nav.appnav a.brand {
  font-weight: var(--weight-semibold); color: var(--fg); text-decoration: none;
  margin-right: var(--space-4); white-space: nowrap; letter-spacing: -.02em;
  display: flex; align-items: center; gap: var(--space-2);
}
nav.appnav a.navlink {
  color: var(--fg-muted); text-decoration: none; font-size: var(--text-sm);
  font-weight: var(--weight-medium); padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm); display: flex; align-items: center; gap: var(--space-1);
  transition: color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
  white-space: nowrap;
}
nav.appnav a.navlink:hover { color: var(--fg); background: var(--surface-sunken); }
nav.appnav a.navlink[aria-current="page"] { color: var(--primary); background: var(--primary-wash); }
nav.appnav .spacer { flex: 1; }
nav.appnav .who { color: var(--fg-muted); font-size: var(--text-sm); white-space: nowrap;
  display: inline-flex; align-items: center; gap: var(--space-1); }
#sidebar-toggle { display: none; }

@media (min-width: 1024px) {
  .app-shell { flex-direction: row; }
  nav.appnav {
    flex-direction: column; align-items: stretch; height: 100dvh; width: var(--sidebar-w);
    /* nav is itself a flex item of .app-shell (row direction here) -- flex items default
       to min-width:auto (their content's min-content size as a size floor), which silently
       stops `width` from ever shrinking below that, no matter how it's set (same gotcha
       already noted on .app-shell above, just one level down). min-width:0 opts out so the
       collapsed rule below can actually take effect. */
    min-width: 0;
    position: sticky; top: 0; border-right: 1px solid var(--border); border-bottom: none;
    padding: var(--space-4) var(--space-3); overflow-x: visible; overflow-y: auto;
    transition: width var(--dur) var(--ease-out);
  }
  nav.appnav a.brand { margin: 0 0 var(--space-5) var(--space-1); }
  nav.appnav .navgroup { display: flex; flex-direction: column; gap: 2px; }
  nav.appnav .spacer { display: none; }
  nav.appnav .navfoot { margin-top: auto; display: flex; flex-direction: column; gap: var(--space-2); }
  .app-main { flex: 1; min-width: 0; }
  #sidebar-toggle { display: inline-flex; }

  /* collapsed: icons-only rail. Labels are wrapped in .nav-label spans (added around
     each navlink's/the who/brand's text) so they can be hidden while the icon stays. */
  nav.appnav.is-collapsed { width: var(--sidebar-w-collapsed); padding-left: var(--space-2); padding-right: var(--space-2); }
  nav.appnav.is-collapsed .nav-label { display: none; }
  nav.appnav.is-collapsed a.brand { justify-content: center; margin-left: 0; }
  nav.appnav.is-collapsed a.navlink { justify-content: center; padding-left: 0; padding-right: 0; }
  nav.appnav.is-collapsed .who { justify-content: center; }
  nav.appnav.is-collapsed #sidebar-toggle svg { transform: rotate(180deg); }
}

/* ---------- 5. Loading bar / toasts ---------- */
#loadbar {
  position: fixed; top: 0; left: 0; height: 2px; width: 0; background: var(--primary);
  z-index: 100; transition: width var(--dur-slow) var(--ease-out), opacity var(--dur) var(--ease-out);
  box-shadow: 0 0 8px var(--primary);
}
#loadbar.active { width: 70%; }
#loadbar.done { width: 100%; opacity: 0; }

#toasts {
  position: fixed; bottom: var(--space-4); left: 50%; transform: translateX(-50%);
  z-index: 90; display: flex; flex-direction: column; gap: var(--space-2); align-items: center;
  pointer-events: none; width: min(92vw, 26em);
}
.toast {
  pointer-events: auto; background: var(--p-slate-900); color: #fff;
  border-radius: var(--radius-md); padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-3); display: flex; align-items: center; gap: var(--space-3);
  font-size: var(--text-sm); animation: toast-in var(--dur-slow) var(--ease-out);
}
.toast button { background: transparent; border: none; color: var(--p-teal-400); font-weight: var(--weight-semibold);
  cursor: pointer; padding: 0; min-height: auto; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- 6. Banners ---------- */
.banner {
  display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap;
  padding: var(--space-3) var(--space-4); font-size: var(--text-sm);
  border-bottom: 1px solid var(--border);
}
.banner.running { background: var(--primary-wash); color: var(--fg); }
.banner.error { background: var(--danger-wash); color: var(--danger); }
.banner .timer-readout {
  font-family: 'JetBrains Mono', monospace; font-weight: var(--weight-medium);
  background: var(--surface); border-radius: var(--radius-sm); padding: 2px var(--space-2);
  font-size: var(--text-sm); border: 1px solid var(--border);
}
.banner .spacer { flex: 1; }

/* ---------- 7. Buttons ---------- */
button, .btn {
  cursor: pointer; border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--fg); border-radius: var(--radius-sm); padding: 0 var(--space-3);
  min-height: var(--touch-target); font: inherit; font-size: var(--text-sm);
  font-weight: var(--weight-medium); display: inline-flex; align-items: center;
  justify-content: center; gap: var(--space-1); text-decoration: none;
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out), opacity var(--dur-fast) var(--ease-out);
  touch-action: manipulation;
}
button:hover, .btn:hover { background: var(--surface-sunken); }
button:active, .btn:active { transform: scale(.98); }
button:disabled, .btn:disabled, button[aria-busy="true"] { opacity: .5; cursor: default; pointer-events: none; }
button.sm, .btn.sm { min-height: 32px; padding: 0 var(--space-2); font-size: var(--text-xs); }
/* Density (the .sm/.navlink compact sizing above) is a mouse/desktop optimization --
   it must never cost a touch user a reachable target. On a coarse pointer (touch),
   every interactive control gets a real 44px hit area regardless of its visual size;
   padding absorbs the extra space so the visible label/icon doesn't change size. */
@media (pointer: coarse) {
  button, .btn, button.sm, .btn.sm, a.navlink, .collapse-btn, input, select {
    min-height: var(--touch-target);
  }
  button.sm, .btn.sm { padding: 0 var(--space-3); }
}

.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
button.warn, .btn-warning { border-color: var(--warning); background: var(--warning-wash); color: var(--warning); }
button.danger, .btn-danger { border-color: var(--danger); background: var(--danger-wash); color: var(--danger); }
button.danger:hover, .btn-danger:hover { background: var(--danger); color: #fff; }
button.ghost, .btn-ghost { background: transparent; border-color: transparent; color: var(--fg-muted); }
button.ghost:hover, .btn-ghost:hover { background: var(--surface-sunken); color: var(--fg); }
nav.appnav button.ghost { color: var(--fg-muted); }

button[aria-busy="true"] .spinner, .btn[aria-busy="true"] .spinner { display: inline-block; }
button[aria-busy="true"] .btn-label, .btn[aria-busy="true"] .btn-label { visibility: hidden; position: absolute; }
.spinner {
  display: none;
  width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 8. Forms ---------- */
input, textarea, select {
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 0 var(--space-3); font: inherit; font-size: var(--text-sm);
  min-height: var(--touch-target); background: var(--surface); color: var(--fg);
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
textarea { padding: var(--space-2) var(--space-3); min-height: 5em; }
input:focus, textarea:focus, select:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-wash); outline: none;
}
label { font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--fg); display: flex; flex-direction: column; gap: var(--space-1); }
label > .hint { font-weight: var(--weight-regular); }
.stack { display: flex; flex-direction: column; gap: var(--space-2); margin: var(--space-2) 0; }
.rowform { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; margin: var(--space-2) 0; }
/* .rowform nested inline inside an already-spaced parent (a card, a row) doesn't
   want its own default vertical margin -- this was previously an inline
   style="margin:0" repeated at every such call site. */
.rowform.tight { margin: 0; }

/* ---------- 9. Cards & sections ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: var(--card-pad); margin: var(--space-2) 0; box-shadow: var(--shadow-1);
  transition: border-color var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out);
}
.card.over { border-color: var(--danger); }
.card.pinned { background: var(--warning-wash); border-color: var(--warning); }
.card .row { display: flex; justify-content: space-between; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.section-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--space-4); margin: var(--space-3) 0; }
.section-card > h3 { margin-bottom: var(--space-3); }

/* ---------- 10. Badges & progress ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: var(--text-xs);
  font-weight: var(--weight-medium); padding: 2px var(--space-2); border-radius: var(--radius-full);
  background: var(--surface-sunken); color: var(--fg-muted); line-height: 1.6;
}
.badge svg { width: 12px; height: 12px; }
.badge.primary { background: var(--primary-wash); color: var(--primary); }
.badge.warning { background: var(--warning-wash); color: var(--warning); }
.badge.danger { background: var(--danger-wash); color: var(--danger); }
.badge.success { background: var(--success-wash); color: var(--success); }

.bar { height: 6px; background: var(--surface-sunken); border-radius: var(--radius-full); margin: var(--space-2) 0; overflow: hidden; }
.fill { height: 100%; background: var(--success); border-radius: var(--radius-full); transition: width var(--dur-slow) var(--ease-out); }
.fill.red { background: var(--danger); }
.mins { color: var(--fg-muted); font-size: var(--text-xs); font-family: 'JetBrains Mono', monospace; }
.done-tag { color: var(--success); font-size: var(--text-sm); font-weight: var(--weight-medium); }

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .stat-label { font-size: var(--text-xs); color: var(--fg-muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .stat-value { font-size: var(--text-xl); font-weight: var(--weight-semibold); font-family: 'JetBrains Mono', monospace; }
.stat .stat-sub { font-size: var(--text-xs); color: var(--fg-muted); }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(7em, 1fr)); gap: var(--space-4);
  padding: var(--space-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  margin-bottom: var(--space-4); }

/* ---------- 11. Segmented control ---------- */
.segmented { display: inline-flex; background: var(--surface-sunken); border-radius: var(--radius-sm); padding: 2px; gap: 2px; }
.segmented button { border: none; background: transparent; min-height: 28px; padding: 0 var(--space-2); border-radius: 4px; font-size: var(--text-xs); }
.segmented button[aria-pressed="true"] { background: var(--surface); box-shadow: var(--shadow-1); color: var(--fg); }

/* ---------- 12. Tree ---------- */
ul.tree, ul.children { list-style: none; padding-left: 0; margin: 0; }
ul.children { padding-left: var(--space-5); border-left: 1px solid var(--border); margin-left: var(--space-2); }
/* Minimum for cross-parent drag-and-drop: since v3.7.1 (add-child moved to a
   header popup, no more "+ New ..." li), a childless node's ul.children is
   genuinely empty in the DOM, so it needs SOME height to stay a droppable
   target -- but --touch-target (44px) read as a visible gap after every
   childless activity, standing out next to activities that DO have children
   (whose ul.children is naturally sized to its real rows, no gap). A small
   value is enough for Sortable to register a drop and reads as part of the
   nesting guide (border-left below), not as empty space. */
ul.children { min-height: var(--space-2); }
li.node { margin: 2px 0; }
/* SortableJS's default placeholder class for the dragged item's landing spot --
   undecorated by default (invisible feedback) without this. */
.sortable-ghost { opacity: .4; background: var(--primary-wash); border-radius: var(--radius-sm); }
li.node > .row {
  display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3); min-height: var(--row-h);
  transition: border-color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
li.node > .row:hover { border-color: var(--border-strong); }
li.node.kind-group > .row { background: var(--surface-sunken); }
li.node.kind-group > .row .title { font-weight: var(--weight-semibold); }
li.node.is-done > .row .title { text-decoration: line-through; color: var(--fg-muted); }
/* Paused (not done -- on hold, so no strikethrough): dim the whole row rather
   than just the title, since a paused row's action buttons are still all
   present and clickable (reactivate lives in More actions), unlike a done
   row's mostly-inert state. */
li.node.is-paused > .row { opacity: .6; }
li.node .title { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; flex: 1; min-width: 8em; font-size: var(--text-sm); }
.prio { font-size: var(--text-xs); background: var(--surface-sunken); border-radius: 4px; padding: 0 var(--space-1);
  color: var(--fg-muted); font-family: 'JetBrains Mono', monospace; }
.drag { cursor: grab; color: var(--fg-subtle); opacity: 0; transition: opacity var(--dur-fast) var(--ease-out); width: var(--touch-target); display: flex; align-items: center; justify-content: center; }
li.node > .row:hover .drag, li.node > .row:focus-within .drag { opacity: 1; }
.deadline { color: var(--warning); }
.rollup { font-size: var(--text-xs); color: var(--fg-muted); display: flex; gap: var(--space-3); font-family: 'JetBrains Mono', monospace; align-items: center; flex-wrap: wrap; }
.rollup .rollup-item { display: inline-flex; align-items: center; gap: 3px; }
.collapse-btn { background: transparent; border: none; min-height: var(--touch-target); width: var(--touch-target);
  padding: 0; color: var(--fg-muted); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.collapse-btn:disabled { visibility: hidden; }
.collapse-btn svg { transition: transform var(--dur) var(--ease-out); }
li.node.is-collapsed > .row .collapse-btn svg { transform: rotate(-90deg); }
li.node.is-collapsed > ul.children, li.node.is-collapsed > details.done-section { display: none; }

.done-section { margin-top: var(--space-1); font-size: var(--text-xs); color: var(--fg-muted); }
.done-section > summary { cursor: pointer; padding: var(--space-1) var(--space-2); }
.done-section > summary:hover { color: var(--fg); }
.done-section > ul.children { margin-top: var(--space-1); font-size: var(--text-sm); color: var(--fg); }

/* display:contents strips the <details> element's own box so its children (summary +
   edit-panel) render as direct flex items of li.node > .row -- the "open" attribute
   still toggles which of those children paint (that's native <details> behavior, not
   CSS display, so it's unaffected by removing the box). summary becomes an icon-only
   button matching the Move up/down buttons in .actions; edit-panel gets flex:1 0 100%
   so it wraps onto its own full-width line under the row, same as the old text-line
   toggle, just reached via an icon button instead. */
details.edit { display: contents; }
details.edit > summary {
  cursor: pointer; list-style: none; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; min-height: 32px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--fg-muted);
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
details.edit > summary::-webkit-details-marker { display: none; }
details.edit > summary:hover { background: var(--surface-sunken); }
details.edit[open] > summary { color: var(--fg); background: var(--surface-sunken); }
.edit-panel { flex: 1 0 100%; background: var(--surface-sunken); border-radius: var(--radius-md); padding: var(--space-3); margin-top: var(--space-1); }

/* Segmented tabs inside the edit panel, built from radios + labels so tab-switching
   itself keeps working with JavaScript off — pure CSS, no click handler required.
   Radio+label stay paired (so :checked + label can highlight the active tab); which
   .tab-panel is visible is decided by :has() on the shared .edit-panel ancestor,
   since the panels live after .edit-tabs rather than directly beside each radio. */
.edit-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: var(--space-3); flex-wrap: wrap; }
.tab-radio { position: absolute; opacity: 0; pointer-events: none; }
.edit-tabs label { cursor: pointer; font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--fg-muted);
  padding: var(--space-2) var(--space-3); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab-radio:checked + label { color: var(--primary); border-bottom-color: var(--primary); }
.tab-radio:focus-visible + label { outline: 2px solid var(--focus-ring); outline-offset: -2px; }
.tab-panel { display: none; }
.edit-panel:has(.tab-radio-details:checked) .tab-panel.panel-details,
.edit-panel:has(.tab-radio-schedule:checked) .tab-panel.panel-schedule,
.edit-panel:has(.tab-radio-deps:checked) .tab-panel.panel-deps,
.edit-panel:has(.tab-radio-share:checked) .tab-panel.panel-share { display: block; }
/* :has() fallback: on a browser too old to support it, every panel stays visible
   (the :has() rules above simply never match) rather than every panel staying
   hidden — so the no-JS baseline degrades to "see everything", never "see nothing". */
@supports not selector(:has(a)) {
  .tab-panel { display: block; }
}

/* "Which week(s)" + "Day of week" only matter when Repeat is set to "Monthly by
   weekday" -- same :has()/fallback pattern as the tabs above. */
.monthweek-fields { display: none; }
.panel-schedule:has(option[value="monthweek"]:checked) .monthweek-fields { display: flex; }
@supports not selector(:has(a)) {
  .monthweek-fields { display: flex; }
}

.notes { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3); font-size: var(--text-sm); }
.addform { list-style: none; margin: var(--space-1) 0; }

/* ---------- 13. Tables ---------- */
table { border-collapse: collapse; background: var(--surface); width: 100%; font-size: var(--text-sm); }
th, td { border-bottom: 1px solid var(--border); padding: var(--space-2) var(--space-3); text-align: left; }
th { color: var(--fg-muted); font-weight: var(--weight-medium); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .04em;
  position: sticky; top: 0; background: var(--surface); }
td.num, th.num { font-family: 'JetBrains Mono', monospace; text-align: right; }
tr.state-done td { color: var(--success); }
tr.state-carried td { color: var(--warning); }
tr.state-dropped td { color: var(--fg-muted); }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-md); }
.table-wrap table { border: none; }

/* ---------- 14. Empty states ---------- */
.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: var(--space-3); padding: var(--space-7) var(--space-4); color: var(--fg-muted); }
.empty-state svg { width: 40px; height: 40px; color: var(--fg-subtle); }
.empty-state h3 { color: var(--fg); }
.empty-state p { margin: 0; max-width: 28em; font-size: var(--text-sm); }

/* ---------- 16. Calendar ---------- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: var(--space-1); margin: var(--space-2) 0; }
.cal-dow { font-size: var(--text-xs); font-weight: var(--weight-semibold); color: var(--fg-muted); text-align: center; padding: var(--space-1) 0; text-transform: uppercase; letter-spacing: .04em; }
.cal-day { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--space-1);
  min-height: 6em; display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.cal-day.is-today { border-color: var(--primary); border-width: 2px; background: var(--primary-wash); }
.cal-date { font-size: var(--text-xs); font-weight: var(--weight-semibold); color: var(--fg-muted); font-family: 'JetBrains Mono', monospace; }
.cal-day.is-today .cal-date { color: var(--primary); }
.cal-chip { display: flex; align-items: center; gap: 3px; font-size: var(--text-xs); background: var(--surface-sunken);
  border-radius: 4px; padding: 1px var(--space-1); color: var(--fg); text-decoration: none; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.cal-chip svg { width: 10px; height: 10px; flex-shrink: 0; }
.cal-chip:hover { background: var(--border); }
/* v3.3.0: one visual identity per chip type (previously all five types shared
   identical styling, told apart only by a 10px glyph) */
.cal-chip--pin { background: var(--primary-wash); color: var(--primary); }
.cal-chip--deadline { background: var(--danger-wash); color: var(--danger); }
.cal-chip--recur { background: var(--warning-wash); color: var(--warning); }
.cal-chip--reminder { background: var(--warning-wash); color: var(--warning); }
/* v3.4.0: 'task' (planned/projected, not yet done) intentionally has no override --
   it's the most common chip type, so it stays the neutral base .cal-chip look rather
   than competing visually with the more special-cased pin/deadline/recur/reminder/done. */
.cal-chip--done { background: var(--success-wash); color: var(--success); }
.cal-legend { display: flex; gap: var(--space-3); flex-wrap: wrap; font-size: var(--text-xs); color: var(--fg-muted); margin-top: var(--space-2); }
.cal-legend span { display: inline-flex; align-items: center; gap: 4px; }
@media (max-width: 640px) { .cal-grid { grid-template-columns: repeat(7, minmax(2.4em, 1fr)); font-size: var(--text-xs); } .cal-day { min-height: 4em; } }

/* ---------- 17. Gantt (server-rendered CSS grid, v3.4.0 -- replaces frappe-gantt) ----------
   One grid: title cells and day cells auto-flow in source order (see gantt.html's own
   comment for why that needs no position math); only each row's projected bar is placed
   explicitly, overlaid on top of that row's day-cells by DOM order (grid auto-placement
   skips explicitly-positioned items, so the bar sitting between two rows' auto-flowed
   cells in the markup doesn't disturb their layout). */
.gantt-wrap { max-width: 100%; max-height: 82vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.gantt-grid { display: grid; font-size: var(--text-sm); }
.gantt-title { position: sticky; left: 0; z-index: 2; background: var(--surface);
  padding: 4px var(--space-2); border-bottom: 1px solid var(--border); border-right: 2px solid var(--border);
  box-shadow: 2px 0 4px -2px rgba(0,0,0,.15); width: 100%; box-sizing: border-box;
  overflow: hidden; display: flex; flex-direction: column; align-items: flex-start; gap: 1px; }
.gantt-corner { position: sticky; top: 0; z-index: 3; }
.gantt-title.wbs-group { font-weight: var(--weight-semibold); }
.gantt-title.wbs-activity { color: var(--fg-muted); }
.gantt-name { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gantt-dep { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
  font-size: var(--text-xs); color: var(--fg-subtle); white-space: nowrap; }
.gantt-col-head { position: sticky; top: 0; z-index: 1; background: var(--surface);
  border-bottom: 1px solid var(--border); text-align: center; font-size: var(--text-xs);
  color: var(--fg-muted); padding: 4px 0; }
.gantt-col-head.is-weekend { background: var(--surface-sunken); }
.gantt-col-head.is-today { background: var(--primary-wash); color: var(--primary); font-weight: var(--weight-semibold); }
.gantt-month { display: block; font-size: 9px; text-transform: uppercase; letter-spacing: .04em; }
.gantt-cell { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); min-height: 2em; }
.gantt-cell.is-weekend { background: var(--surface-sunken); }
.gantt-cell.is-today { background: var(--primary-wash); }
.gantt-bar { align-self: center; height: 1.1em; margin: 0 1px; border-radius: var(--radius-sm);
  background: var(--primary); }
.gantt-bar.wbs-group { background: var(--fg-muted); }
.gantt-bar.wbs-activity { background: var(--fg-subtle); }

/* ---------- 17.5 Logic panel (Today, v3.3.0) ---------- */
.logic-panel summary { cursor: pointer; font-weight: var(--weight-semibold); display: flex;
  align-items: center; gap: var(--space-2); }
.logic-panel[open] summary { margin-bottom: var(--space-2); }
.logic-groups { width: 100%; border-collapse: collapse; font-size: var(--text-sm); margin: var(--space-2) 0; }
.logic-groups th, .logic-groups td { text-align: left; padding: 2px var(--space-2) 2px 0; }
.logic-groups th { color: var(--fg-muted); font-weight: var(--weight-semibold); }
.logic-reasons { list-style: none; padding: 0; margin: var(--space-2) 0 0; font-size: var(--text-sm);
  color: var(--fg-muted); display: flex; flex-direction: column; gap: 2px; }

/* ---------- 18. Layout helpers ---------- */
.today-layout { display: flex; gap: var(--space-5); align-items: flex-start; }
.today-main { flex: 1; min-width: 0; }
.today-side { width: 20em; flex-shrink: 0; display: flex; flex-direction: column; gap: var(--space-4); }
.today-side .card { padding: var(--space-2) var(--space-3); }
@media (max-width: 900px) { .today-layout { flex-direction: column; } .today-side { width: auto; } }

.plan-list { display: flex; flex-direction: column; gap: var(--space-2); }

/* On mobile the app bar sits above <main> in normal flow (real height, not a sidebar),
   so a flat 100dvh here would overflow the page by --appbar-h. On desktop the nav is a
   sidebar (no vertical height contribution) so the full subtraction isn't needed there,
   but a small gap under a login card is a far smaller defect than page-level scroll. */
.center-page { min-height: calc(100dvh - var(--appbar-h)); display: flex; align-items: center; justify-content: center; padding: var(--space-4); }
@media (min-width: 1024px) { .center-page { min-height: 100dvh; } }
.auth-card { width: 100%; max-width: 24em; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: var(--space-6); box-shadow: var(--shadow-2); }

footer.ver { text-align: center; color: var(--fg-subtle); font-size: var(--text-xs); padding: var(--space-5) 0; }

/* ---------- 19. Icon sizing ---------- */
.icon { width: 16px; height: 16px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round; }

/* ---------- 20. Overflow menu ---------- */
.menu { position: relative; display: inline-block; }
.menu summary { list-style: none; cursor: pointer; }
.menu summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 50; min-width: 10em;
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-2); padding: var(--space-1); display: flex; flex-direction: column; gap: 1px;
  animation: menu-in var(--dur-fast) var(--ease-out);
}
.menu-panel form, .menu-panel .menu-item { display: block; width: 100%; }
.menu-panel button { width: 100%; justify-content: flex-start; border: none; background: transparent; min-height: 36px; }
.menu-panel button:hover { background: var(--surface-sunken); }
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
/* Inbox promote popup: a real form with its own primary submit button, not a
   list of plain menu-item rows -- (.menu-panel .promote-form) is deliberately
   two classes so it outranks the plain-row rules above (.menu-panel button /
   .menu-panel form, one class + one element each) without touching them,
   since every other .menu-panel on the site still wants that flat list look. */
.menu-panel .promote-form {
  display: flex; flex-direction: column; gap: var(--space-2); margin: var(--space-2) 0;
  padding: var(--space-2);
}
.menu-panel .promote-form .btn-primary {
  width: auto; justify-content: center;
  background: var(--primary); border-color: var(--primary); color: var(--on-primary);
}
.menu-panel .promote-form .btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.icon-sm { width: 14px; height: 14px; }
.icon-lg { width: 20px; height: 20px; }
