/* Denala — warm, calm, accessible (WCAG 2.2 AA). SPDX-License-Identifier: AGPL-3.0-or-later */
@layer reset, base, components, utilities, print;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  body, h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; }
  ul[class], ol[class] { list-style: none; padding: 0; }
  img, svg { display: block; max-width: 100%; }
  input, button, select, textarea { font: inherit; color: inherit; }
}

@layer base {
  :root {
    color-scheme: light dark;
    --bg: light-dark(#f7f3ee, #1f1d1b);
    --surface: light-dark(#fffdfa, #2a2724);
    --ink: light-dark(#2b2622, #f1ece6);
    --muted: light-dark(#665d55, #bcb3a9);       /* 5.6:1 on --bg */
    --line: light-dark(#e3dbd1, #45403a);
    --accent: light-dark(#3f6b5c, #8cc1ad);      /* sage green, 5.9:1 / 8:1 */
    --accent-ink: light-dark(#ffffff, #10231c);
    --accent-soft: light-dark(#e4efe9, #24352e);
    --warn: light-dark(#8a4b14, #f0b37a);
    --warn-soft: light-dark(#fbeee0, #3a2b1d);
    --danger: light-dark(#a3302a, #f19c94);
    --radius: 14px;
    --space: clamp(1rem, 0.8rem + 1vw, 1.5rem);
    --font: "Atkinson Hyperlegible", "Segoe UI", system-ui, -apple-system, sans-serif;
    --serif: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  }
  html { -webkit-text-size-adjust: 100%; }
  body {
    background: var(--bg); color: var(--ink);
    font: 1.0625rem/1.6 var(--font);
    min-height: 100dvh;
  }
  h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.25; text-wrap: balance; }
  h1 { font-size: clamp(1.75rem, 1.4rem + 1.6vw, 2.4rem); margin-block: 0.5rem 1rem; }
  h2 { font-size: 1.3rem; }
  h3 { font-size: 1.1rem; margin-block: 1rem 0.5rem; }
  p { text-wrap: pretty; }
  a { color: var(--accent); text-underline-offset: 0.2em; }
  :focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
  h1:focus { outline: none; }
  @media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }
}

@layer components {
  .wrap { max-width: 52rem; margin-inline: auto; padding: var(--space); padding-bottom: 4rem; }
  .skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: 0.5rem 1rem; z-index: 10; }
  .skip:focus { left: 0.5rem; }

  .topbar { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; min-height: 2.75rem; }
  .topbar .sync { margin-inline-start: auto; font-size: 0.875rem; color: var(--muted); }
  .brand { font-family: var(--serif); font-size: 1.25rem; font-weight: 600; }
  .back { text-decoration: none; font-weight: 600; padding-block: 0.5rem; }
  .sync-synced::before { content: "● "; color: var(--accent); }
  .sync-offline::before, .sync-conflict::before { content: "● "; color: var(--warn); }

  .lead { font-size: 1.15rem; color: var(--muted); margin-bottom: 1.5rem; max-width: 40rem; }
  .muted { color: var(--muted); }
  .small { font-size: 0.9rem; }

  .card {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    padding: var(--space); margin-bottom: 1rem;
  }
  .grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr)); }
  .tile { display: flex; flex-direction: column; gap: 0.5rem; text-decoration: none; color: inherit; margin: 0;
    transition: border-color .15s, transform .15s; }
  .tile:hover { border-color: var(--accent); transform: translateY(-2px); }
  .tile h2 { color: var(--accent); }
  progress { width: 100%; height: 0.5rem; appearance: none; border: 0; border-radius: 99px; background: var(--line); overflow: hidden; margin-top: auto; }
  progress::-webkit-progress-bar { background: var(--line); }
  progress::-webkit-progress-value { background: var(--accent); border-radius: 99px; }
  progress::-moz-progress-bar { background: var(--accent); }

  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
    min-height: 2.75rem; padding: 0.5rem 1.1rem; border-radius: 999px; border: 1.5px solid var(--accent);
    background: transparent; color: var(--accent); font-weight: 600; text-decoration: none; cursor: pointer;
  }
  .btn.primary { background: var(--accent); color: var(--accent-ink); }
  .btn.ghost { border-color: var(--line); color: var(--ink); }
  .btn.ghost:hover { border-color: var(--accent); }
  .btn.danger { color: var(--danger); border-color: currentColor; }
  .btn.primary.danger { background: var(--danger); color: #fff; }
  .btn.small { min-height: 2.25rem; padding: 0.25rem 0.8rem; font-size: 0.9rem; }
  .btn.big { min-height: 3.25rem; font-size: 1.1rem; }
  .btn:disabled { opacity: 0.55; cursor: progress; }
  .btn.add { margin-top: 0.75rem; }
  .icon { min-width: 2.25rem; min-height: 2.25rem; border-radius: 50%; border: 1px solid var(--line); background: none; cursor: pointer; }
  .icon:disabled { opacity: 0.35; }
  .link { background: none; border: 0; color: var(--accent); text-decoration: underline; cursor: pointer; padding: 0.5rem; min-height: 2.75rem; }
  .link[aria-current] { font-weight: 700; text-decoration: none; color: var(--ink); }

  .stack { display: grid; gap: 0.75rem; max-width: 22rem; margin-block: 1.5rem; }
  .stack-links { margin-top: 1rem; }
  .actions-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-block: 0.75rem 1.5rem; }
  .bullets { padding-inline-start: 1.25rem; display: grid; gap: 0.35rem; }
  h2.sub { margin-top: 2rem; }

  .form { display: grid; gap: 1rem; max-width: 36rem; }
  .form form { display: grid; gap: 1rem; }
  .field { display: grid; gap: 0.35rem; }
  .field label, legend { font-weight: 600; }
  input:not([type=checkbox]):not([type=radio]), select, textarea {
    width: 100%; min-height: 2.75rem; padding: 0.55rem 0.8rem;
    border: 1.5px solid var(--line); border-radius: 10px; background: var(--bg);
  }
  input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--accent); }
  input[type=checkbox], input[type=radio] { width: 1.3rem; height: 1.3rem; accent-color: var(--accent); flex: none; margin-top: 0.2rem; }
  fieldset { border: 0; padding: 0; display: grid; gap: 0.75rem; }
  .check { display: flex; gap: 0.6rem; align-items: flex-start; cursor: pointer; }
  .form-error { color: var(--danger); font-weight: 600; }
  .form-error:empty { display: none; }
  .warn { color: var(--warn); font-size: 0.9rem; }
  .callout { background: var(--accent-soft); border-radius: 10px; padding: 0.75rem 1rem; }
  .callout.warn { background: var(--warn-soft); color: inherit; }

  .profiles { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.25rem; }
  .chip { min-height: 2.5rem; padding: 0.3rem 1rem; border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface); cursor: pointer; }
  .chip[aria-current] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
  .chip.add { border-style: dashed; }

  .group-head { display: flex; align-items: baseline; gap: 0.5rem; }
  .count { color: var(--accent); font-weight: 700; }
  .hints { margin-top: 0.5rem; font-size: 0.95rem; }
  .hints summary { cursor: pointer; color: var(--accent); font-weight: 600; min-height: 2rem; }
  .hints ul { padding-inline-start: 1.25rem; color: var(--muted); }
  .items { display: grid; gap: 0.5rem; margin-top: 0.75rem; counter-reset: item; }
  .item { display: flex; gap: 0.75rem; align-items: flex-start; justify-content: space-between;
    border: 1px solid var(--line); border-radius: 10px; padding: 0.75rem 1rem; background: var(--bg); }
  .items.ordered .item-body strong::before { counter-increment: item; content: counter(item) ". "; color: var(--accent); }
  .item-body { min-width: 0; overflow-wrap: anywhere; }
  .item-body dl { display: grid; gap: 0.15rem; margin-top: 0.25rem; font-size: 0.95rem; }
  .item-body dl div { display: flex; gap: 0.4rem; flex-wrap: wrap; }
  .item-body dt { color: var(--muted); }
  .item-body dt::after { content: ":"; }
  .item-body dd { white-space: pre-line; }
  .item-actions { display: flex; gap: 0.35rem; flex: none; }
  .item-form { display: grid; gap: 0.85rem; margin-top: 0.75rem; padding: 1rem; border: 1.5px solid var(--accent); border-radius: 12px; }
  .actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
  .spacer { flex: 1; }

  .checklist { display: grid; gap: 0.6rem; margin-top: 0.75rem; }
  .checklist input:checked + span { text-decoration: line-through; text-decoration-color: var(--muted); }
  .add-step .row { display: flex; gap: 0.5rem; margin-top: 0.4rem; }

  .cards { display: grid; gap: 0.75rem; }
  .row { display: flex; gap: 0.5rem; align-items: center; }
  .row.between { justify-content: space-between; }
  .plain { display: grid; gap: 0.5rem; list-style: none; padding: 0; }
  .badge { font-size: 0.85rem; background: var(--accent-soft); padding: 0.15rem 0.6rem; border-radius: 99px; }

  .code { font: 600 clamp(1.1rem, 0.9rem + 1.2vw, 1.6rem)/1.4 ui-monospace, "SF Mono", Menlo, monospace;
    letter-spacing: 0.06em; padding: 1rem; background: var(--bg); border: 2px dashed var(--accent); border-radius: 10px;
    text-align: center; margin-block: 1rem; overflow-wrap: anywhere; }
  .code.small { font-size: 1rem; text-align: start; }

  .dialog { border: 0; border-radius: var(--radius); padding: var(--space); max-width: min(28rem, 92vw); background: var(--surface); color: var(--ink); }
  .dialog::backdrop { background: rgb(0 0 0 / .4); }
  .dialog form { display: grid; gap: 1rem; }
  .dialog .actions { justify-content: flex-end; }

  #toast { position: fixed; inset-inline: 1rem; bottom: 1rem; margin-inline: auto; max-width: 28rem;
    background: var(--ink); color: var(--bg); padding: 0.85rem 1.1rem; border-radius: 12px;
    opacity: 0; translate: 0 1rem; transition: opacity .2s, translate .2s; pointer-events: none; z-index: 20; }
  #toast.show { opacity: 1; translate: 0 0; }


  /* Todos — the heart of the app */
  .todo-panel { border: 2px solid var(--accent); }
  .todo-panel h2 { font-size: 1.45rem; }
  .kind-counts { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-block: 0.75rem; }
  .kind-counts a { text-decoration: none; display: inline-flex; gap: 0.35rem; align-items: baseline; padding: 0.35rem 0.85rem; border-radius: 999px; min-height: 2.5rem; align-items: center; }
  .kind { font-size: 0.85rem; padding: 0.1rem 0.6rem; border-radius: 99px; font-weight: 600; }
  .kind-collect { background: light-dark(#e4efe9, #24352e); color: light-dark(#2d5245, #b7dccd); }
  .kind-decide { background: light-dark(#f6ead8, #3a2f1f); color: light-dark(#7a4a12, #f0c68e); }
  .kind-discuss { background: light-dark(#e9e6f4, #2d2a3c); color: light-dark(#4a3f86, #c9c0f2); }
  .kind-counts .kind { font-size: 1rem; }
  .filters { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 1rem; }
  .filters .chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
  .filters .n { opacity: 0.75; }
  .filters .who { width: auto; min-width: 11rem; }
  .todo-list { display: grid; gap: 0.5rem; margin-top: 0.75rem; }
  .todo { display: flex; gap: 0.75rem; align-items: flex-start; padding: 0.7rem 0.9rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
  .todo.auto { border-style: dashed; }
  .todo.is-done .todo-text { text-decoration: line-through; color: var(--muted); }
  .todo-body { flex: 1; min-width: 0; display: grid; gap: 0.3rem; overflow-wrap: anywhere; }
  .tags { display: flex; flex-wrap: wrap; gap: 0.35rem; }
  .tag { font-size: 0.85rem; padding: 0.1rem 0.55rem; border-radius: 99px; border: 1px solid var(--line); text-decoration: none; color: inherit; }
  .todo-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; justify-content: flex-end; }
  .small-select { width: auto !important; min-height: 2.25rem !important; padding: 0.2rem 0.5rem !important; font-size: 0.9rem; max-width: 12rem; }
  .grid3 { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr)); }
  details.card > summary { cursor: pointer; list-style: none; }
  details.card > summary h2 { display: inline; }
  .group.is-na { opacity: 0.7; }
  .group-actions { margin-top: 0.75rem; }
  .tile h3 { color: var(--accent); margin: 0; }
  nl-binder .who { font-size: 1.4rem; font-family: var(--serif); }
  @media (max-width: 34rem) { .todo { flex-wrap: wrap; } .todo-actions { width: 100%; justify-content: flex-start; } }

  .lang-switch { margin-top: 2rem; display: flex; gap: 0.5rem; }

  /* Binder (screen) */
  nl-binder { display: block; }
  nl-binder .sheet { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space); margin-bottom: 1rem; }
  nl-binder table { width: 100%; border-collapse: collapse; font-size: 0.95rem; margin-bottom: 0.75rem; }
  nl-binder th, nl-binder td { text-align: start; vertical-align: top; padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--line); white-space: pre-line; }
  nl-binder th { font-size: 0.85rem; color: var(--muted); }
  nl-binder .cover h1 { font-size: 2.2rem; }
  nl-binder .note { margin-top: 1.5rem; font-style: italic; }
  .blank-item { border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem 0.75rem; margin-bottom: 0.5rem; }
  .blank-line { border-bottom: 1px solid var(--line); min-height: 2.2rem; display: flex; align-items: flex-end; font-size: 0.8rem; color: var(--muted); }
  .print-check { padding-inline-start: 0; list-style: none; display: grid; gap: 0.3rem; }
}

@layer utilities {
  .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  [hidden] { display: none !important; }
}

@layer print {
  @media print {
    :root { color-scheme: light; }
    body { background: #fff; color: #000; font-size: 11pt; }
    .wrap { max-width: none; padding: 0; }
    .topbar, .no-print, .skip, #toast, h1#page-title, .lead, form button, .stack-links { display: none !important; }
    nl-binder .sheet { border: 0; padding: 0; break-after: page; }
    nl-binder .pgroup { break-inside: avoid; }
    nl-binder .cover { display: grid; align-content: center; min-height: 90vh; }
    a { color: inherit; text-decoration: none; }
    .recovery-sheet { border: 0; }
    .recovery-sheet .code { border-color: #000; }
  }
}

@layer components {
  .group-place { margin-top: 0.75rem; max-width: 26rem; }
  .group-place label { font-size: 0.9rem; }
  .place-chip { display: inline-block; padding: 0.05rem 0.6rem; border-radius: 99px; background: var(--accent-soft); text-decoration: none; font-weight: 600; }
  .place h2 { font-size: 1.2rem; }
  .place h3 { font-size: 1rem; margin-block: 0.75rem 0.25rem; }
  .usage { padding-inline-start: 1.1rem; display: grid; gap: 0.2rem; }
  .place:target { outline: 3px solid var(--accent); }
}

@layer components {
  .local-only { margin-bottom: 1rem; display: grid; gap: 0.6rem; }
}

/* ---------- App layout with side menu ---------- */
@layer components {
  .layout { display: grid; grid-template-columns: 17rem minmax(0, 1fr); grid-template-rows: auto 1fr; min-height: 100dvh; }
  .appbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 0.75rem; padding: 0.6rem var(--space);
    border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; }
  .appbar .sync { margin-inline-start: auto; font-size: 0.875rem; color: var(--muted); }
  .brand { text-decoration: none; color: var(--accent); }
  .menu-btn { display: none; align-items: center; gap: 0.5rem; min-height: 2.75rem; padding: 0.3rem 0.9rem;
    border: 1.5px solid var(--line); border-radius: 999px; background: none; cursor: pointer; font-weight: 600; }
  .burger, .burger::before, .burger::after { display: block; width: 1.1rem; height: 2px; background: currentColor; border-radius: 2px; position: relative; }
  .burger::before, .burger::after { content: ""; position: absolute; left: 0; }
  .burger::before { top: -6px; } .burger::after { top: 6px; }

  .sidenav { border-right: 1px solid var(--line); background: var(--surface); padding: 1rem 0.75rem 2rem;
    position: sticky; top: 3.6rem; height: calc(100dvh - 3.6rem); overflow-y: auto; }
  .sidenav ul { list-style: none; padding: 0; margin: 0 0 0.75rem; display: grid; gap: 2px; }
  .sidenav a, .sidenav button { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; width: 100%;
    min-height: 2.6rem; padding: 0.45rem 0.75rem; border-radius: 10px; color: var(--ink); text-decoration: none;
    background: none; border: 0; font: inherit; text-align: start; cursor: pointer; }
  .sidenav a:hover, .sidenav button:hover { background: var(--bg); }
  .sidenav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
  .nav-badge { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
  .sidenav a[aria-current="page"] .nav-badge { color: var(--accent); }
  .nav-caption { font-size: 0.78rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); padding: 0.6rem 0.75rem 0.25rem; }
  .nav-dossier { padding: 0 0.25rem 0.75rem; display: grid; gap: 0.25rem; }
  .nav-dossier .nav-caption { padding: 0 0.5rem; }
  .nav-foot { border-top: 1px solid var(--line); padding-top: 0.75rem !important; margin-top: 1rem !important; }

  .content { padding: var(--space) clamp(1rem, 3vw, 2.5rem) 4rem; max-width: 56rem; width: 100%; }
  .content > .back { display: inline-block; margin-bottom: 0.5rem; }

  @media (max-width: 56rem) {
    .layout { grid-template-columns: 1fr; }
    .menu-btn { display: inline-flex; }
    .sidenav { position: fixed; inset: 3.6rem 0 0 0; height: auto; width: min(20rem, 88vw); z-index: 10;
      transform: translateX(-105%); transition: transform .2s ease; box-shadow: 0 0 0 100vmax transparent; }
    .nav-open .sidenav { transform: none; box-shadow: 0 0 0 100vmax rgb(0 0 0 / .35); }
  }

  /* Dashboard progress list */
  .progress-list { list-style: none; padding: 0; margin: 0.5rem 0 0; display: grid; gap: 2px; }
  .progress-list a { display: grid; grid-template-columns: minmax(0, 1fr) 8rem 3rem; align-items: center; gap: 1rem;
    min-height: 2.75rem; padding: 0.4rem 0.6rem; border-radius: 10px; color: inherit; text-decoration: none; }
  .progress-list a:hover { background: var(--bg); }
  .progress-list progress { margin: 0; }
  .pl-count { text-align: end; color: var(--muted); font-variant-numeric: tabular-nums; }
  @media (max-width: 30rem) { .progress-list a { grid-template-columns: minmax(0, 1fr) 4.5rem 2.5rem; gap: 0.5rem; } }

  /* Section accordion */
  details.group { padding: 0; }
  details.group > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between;
    gap: 1rem; padding: 1rem var(--space); min-height: 3.25rem; }
  details.group > summary::-webkit-details-marker { display: none; }
  details.group > summary::after { content: ""; width: 0.6rem; height: 0.6rem; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
    transform: rotate(45deg); transition: transform .15s; flex: none; margin-top: -0.3rem; }
  details.group[open] > summary::after { transform: rotate(-135deg); margin-top: 0.3rem; }
  details.group[open] > summary { border-bottom: 1px solid var(--line); }
  details.group > :not(summary) { margin-inline: var(--space); }
  details.group > :last-child { margin-bottom: var(--space); }
  details.group > p.muted { margin-top: 0.75rem; }
  .group-title { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; min-width: 0; }
  .group-title h2 { font-size: 1.15rem; margin: 0; }
  .group-status { margin-inline-start: auto; font-size: 0.875rem; color: var(--muted); white-space: nowrap; }
  details.group.is-filled .group-status { color: var(--accent); font-weight: 600; }
  .place-chip.small { font-size: 0.8rem; font-weight: 600; padding: 0 0.5rem; }
}

@layer print {
  @media print {
    .appbar, .sidenav { display: none !important; }
    .layout { display: block; }
    .content { padding: 0; max-width: none; }
  }
}
