/* ============================================================================
   Catastrophe: Bec & Will's survival guide for southside Brisbane and SEQ.
   Tokens come from the shared design system (theme.css, --ds-*). This file
   aliases them to local names (the Cup pattern) + holds app-specific extras.
   ========================================================================== */
:root {
  --accent: var(--ds-accent);
  --accent-strong: var(--ds-lavender-strong);
  --accent-tint: var(--ds-lavender-tint);
  --cat-lime: var(--ds-cat-lime);
  --cat-sage: var(--ds-cat-sage);
  --cat-coral: var(--ds-cat-coral);
  --cat-sky: var(--ds-cat-sky);
  --cat-periwinkle: var(--ds-cat-periwinkle);

  --radius-pill: var(--ds-radius-pill);
  --radius-card: var(--ds-radius-card);
  --radius-sm: var(--ds-radius-sm);
  --font-ui: var(--ds-font-ui);
  --font-display: var(--ds-font-display);

  --bg: var(--ds-bg);
  --surface: var(--ds-surface);
  --surface-2: var(--ds-surface-2);
  --surface-3: var(--ds-surface-3);
  --text: var(--ds-text);
  --text-2: var(--ds-text-2);
  --text-muted: var(--ds-text-muted);
  --border: var(--ds-border);

  --tabbar-h: 64px;
}

html[data-theme="dark"] {
  --accent-text: #C9B4FF;
  --danger-text: #E0798D;
  --glow: rgba(159, 133, 255, 0.30);
  --glow-2: rgba(175, 141, 255, 0.16);
}
html[data-theme="light"] {
  --accent-text: #5A57C9;
  --danger-text: #A84457;
  --glow: rgba(159, 133, 255, 0.50);
  --glow-2: rgba(175, 141, 255, 0.30);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 15px/1.55 var(--font-ui);
  transition: background .25s, color .25s;
}
button { font-family: inherit; cursor: pointer; }
img { display: block; }
.mobile-only { display: none; }

:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 2px; }
#view:focus { outline: none; }

/* fine grain over everything */
body::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 9999;
  opacity: .11; mix-blend-mode: overlay;
  background-image: url("noise.avif"); background-size: 320px; background-repeat: repeat;
}
html[data-theme="dark"] body::after { opacity: .16; }

/* ---- app shell ---- */
#app {
  display: grid;
  grid-template-columns: 232px 1fr;
  gap: 8px; padding: 8px;
  height: 100vh; height: 100dvh;
}
#sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 16px 8px;
  display: flex; flex-direction: column;
  overflow: hidden auto;
}
.brand { font-family: var(--font-display); font-size: 22px; font-weight: 600; padding: 6px 14px 18px 12px; display: flex; align-items: center; gap: 8px; }
.brand-logo { width: 30px; height: 30px; flex: 0 0 auto; }
.nav-primary { list-style: none; margin: 0 0 16px; padding: 0; }
.nav-primary button {
  width: 100%; min-height: 44px; padding: 10px 12px; text-align: left;
  border: none; background: none; border-radius: var(--radius-sm); color: var(--text-2);
  font: 600 14px var(--font-ui); display: flex; align-items: center; gap: 12px;
  transition: background .15s, color .15s;
}
.nav-primary button:hover,
.nav-primary button.active { color: var(--text); background: var(--surface-2); }
.nav-ico { font-size: 18px; width: 22px; text-align: center; flex: 0 0 auto; }
.sidebar-fill { flex: 1; }
.sidebar-note { margin: 8px 4px 2px; padding: 12px 8px 0; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-muted); line-height: 1.6; }
.sidebar-cat { width: 96px; margin: 0 auto 8px; opacity: .95; }

/* ---- content panel + ambient glow ---- */
#content {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card); overflow-y: auto; position: relative;
  background-image:
    radial-gradient(115% 90% at 100% 0%, var(--glow) 0%, transparent 72%),
    radial-gradient(85% 70% at 0% 100%, var(--glow-2) 0%, transparent 68%);
}
#topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
#topbar .brand { padding: 0; font-size: 19px; display: none; }
#topbar .brand-logo { width: 26px; height: 26px; }
.topbar-spacer { flex: 1; }
#print-btn, #theme-toggle {
  width: 38px; height: 38px; border-radius: var(--radius-pill);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  display: grid; place-items: center; font-size: 16px; padding: 0;
}
#print-btn { width: auto; padding: 0 16px; font: 600 13px var(--font-ui); }

/* micro-interactions */
#theme-toggle, #print-btn, .nav-primary button, #tabbar button {
  transition: transform .12s ease, background .15s, color .15s, border-color .15s;
}
#theme-toggle:active, #print-btn:active { transform: scale(.88); }
@media (prefers-reduced-motion: no-preference) {
  #theme-toggle:hover, #print-btn:hover { transform: translateY(-1.5px); }
  .brand-logo { transition: transform .25s ease; }
  .brand:hover .brand-logo { transform: rotate(-10deg) scale(1.1); }
}

/* ---- views ---- */
#view { padding: 20px 24px 48px; max-width: 860px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }
.view-title { font-family: var(--font-display); font-weight: 600; font-size: 32px; line-height: 1.1; margin: 14px 0 6px; }
.view-lead { color: var(--text-2); font-size: 16px; max-width: 62ch; margin: 0 0 22px; }
h3 { font-family: var(--font-display); font-weight: 600; font-size: 22px; margin: 34px 0 10px; }
h4 { font-size: 15px; font-weight: 700; margin: 20px 0 8px; }
p { margin: 0 0 12px; max-width: 68ch; }
ul { margin: 0 0 14px; padding-left: 22px; }
li { margin: 0 0 7px; }
.muted { color: var(--text-muted); }

/* cards */
.card {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-card); padding: 18px 20px; margin: 16px 0;
  box-shadow: var(--ds-shadow-card);
}
.card > h4:first-child { margin-top: 0; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; margin: 16px 0; }
.card-grid .card { margin: 0; }

/* warning card (coral) */
.warn { border-left: 4px solid var(--cat-coral); }
.warn > h4:first-child { color: var(--danger-text); }

/* highlight card (lavender) */
.hilite { border-left: 4px solid var(--accent); }

/* quote / aside */
.callout {
  border-left: 4px solid var(--accent); padding: 4px 0 4px 16px;
  margin: 18px 0; color: var(--text-2); font-style: italic; max-width: 62ch;
}

/* chips */
.chip { display: inline-flex; align-items: center; gap: 6px; border-radius: var(--radius-pill);
  padding: 5px 12px; font-size: 12.5px; font-weight: 600; color: #161213; }
.chip-lime { background: var(--cat-lime); }
.chip-sage { background: var(--cat-sage); }
.chip-sky { background: var(--cat-sky); }
.chip-periwinkle { background: var(--cat-periwinkle); }
.chip-coral { background: var(--cat-coral); color: #fff; }

/* tables */
.table-scroll { overflow-x: auto; margin: 14px 0; border: 1px solid var(--border); border-radius: var(--radius-card); }
table { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--surface-2); }
caption { text-align: left; font-weight: 700; font-size: 13px; padding: 12px 16px 4px; background: var(--surface-2); color: var(--text-2); caption-side: top; }
th, td { padding: 10px 14px; text-align: left; vertical-align: top; border-top: 1px solid var(--border); }
thead th { border-top: none; font-size: 12.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
tfoot td { font-weight: 700; background: var(--surface-3); }

/* people / place rows */
.row-list { border-top: 1px solid var(--border); margin: 14px 0; }
.row-list .row { border-bottom: 1px solid var(--border); padding: 14px 4px; }
.row .who { font-weight: 700; font-size: 16px; }
.row .where { color: var(--accent-text); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; margin: 2px 0 6px; }
.row p { margin: 0; }

/* expandable detail cards (native details/summary) */
details.exp {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-card); margin: 0 0 10px; overflow: hidden;
}
details.exp summary {
  list-style: none; cursor: pointer; min-height: 44px;
  display: flex; align-items: center; gap: 12px; padding: 13px 16px;
  font-weight: 600;
}
details.exp summary::-webkit-details-marker { display: none; }
details.exp summary .sub { display: block; font-weight: 400; font-size: 12.5px; color: var(--text-muted); }
details.exp summary .chip { margin-left: auto; flex: 0 0 auto; }
details.exp summary .chev { flex: 0 0 auto; color: var(--text-muted); transition: transform .2s; margin-left: 6px; }
details.exp[open] summary .chev { transform: rotate(90deg); }
details.exp .exp-body { padding: 2px 16px 16px; color: var(--text-2); font-size: 14px; }
.exp-body .lbl { display: block; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--accent-text); margin: 10px 0 2px; }
.exp-body .lbl.danger { color: var(--danger-text); }

/* level pills on asset cards */
.lvls { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.lvl { font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: var(--radius-pill);
  border: 1px solid var(--border); color: var(--text-muted); }
.lvl.on { color: #161213; background: var(--accent-tint); border-color: var(--accent); }
html[data-theme="dark"] .lvl.on { color: var(--accent-text); background: transparent; }

/* ---- phones ---- */
#tabbar { display: none; }
@media (max-width: 760px) {
  .mobile-only { display: flex; }
  #topbar .brand { display: flex; }
  #sidebar { display: none; }
  #app { grid-template-columns: 1fr; padding: 8px 8px 0; height: calc(100vh - var(--tabbar-h)); height: calc(100dvh - var(--tabbar-h)); }
  #view { padding: 16px 16px 40px; }
  #tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: var(--tabbar-h);
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(10px); border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 20;
  }
  #tabbar button {
    flex: 1; border: none; background: none; color: var(--text-muted);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    font: 600 11px var(--font-ui); border-radius: var(--radius-sm); min-height: 44px;
  }
  #tabbar button .nav-ico { font-size: 20px; width: auto; }
  #tabbar button.active { color: var(--text); background: var(--surface); }
}

/* ---- print: the whole guide, paper friendly ---- */
@media print {
  body { background: #fff; color: #000; font-size: 12px; }
  body::after, #sidebar, #topbar, #tabbar { display: none !important; }
  #app { display: block; height: auto; padding: 0; }
  #content { border: none; border-radius: 0; overflow: visible; background-image: none; background-color: #fff; }
  #view { max-width: none; padding: 0; }
  .view { display: block !important; }
  .view + .view { page-break-before: always; }
  details.exp { page-break-inside: avoid; }
  details.exp > .exp-body { display: block !important; }
  .card, .table-scroll { page-break-inside: avoid; box-shadow: none; }
}
