/* ══════════════════════════════════════════════════════════════════════════
   Reset and element defaults.
   Everything here applies to bare HTML; nothing here knows about a component.
   ══════════════════════════════════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; }

* { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  /* The PWA is a fixed shell with scrolling panes, not a scrolling document. */
  height: 100%;
}

body {
  height: 100%;
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Stop iOS rubber-banding the whole app when a pane hits its end. */
  overscroll-behavior-y: none;
}

/* The single mount point. It has to carry the full height itself: the app shell
   is a fixed frame with scrolling panes inside it, and a min-height:100% child
   resolves against nothing if this is auto. */
#app { height: 100%; display: flex; flex-direction: column; }
#app > .app { flex: 1; min-height: 0; }
#app > .offline-bar { flex: none; }

/* Keep the browser's own tap highlight out of the way; :active states below
   provide the feedback instead, and they respect the theme. */
* { -webkit-tap-highlight-color: transparent; }

img, svg, video, canvas { display: block; max-width: 100%; }
img, video { height: auto; }

input, button, textarea, select {
  font: inherit;
  color: inherit;
}

button { background: none; border: none; padding: 0; cursor: pointer; }

a {
  color: var(--accent-text);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

h1, h2, h3, h4, h5, h6 {
  font-weight: var(--fw-semi);
  line-height: var(--lh-tight);
  letter-spacing: -0.011em;
  text-wrap: balance;
}

h1 { font-size: var(--fs-lg); }
h2 { font-size: var(--fs-md); }
h3 { font-size: var(--fs-base); }

p { text-wrap: pretty; }

ul, ol { list-style: none; padding: 0; }

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--s-5) 0;
}

code, kbd, pre, samp { font-family: var(--font-mono); font-size: 0.92em; }

kbd {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: var(--r-sm);
  padding: 0.1em 0.4em;
  font-size: 0.85em;
}

/* ── focus ────────────────────────────────────────────────────────────────
   Visible for keyboard users, invisible for pointer users. Never removed:
   this app has forms, and a keyboard user who cannot see focus cannot use it. */
:focus { outline: none; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* ── selection ─────────────────────────────────────────────────────────── */
::selection {
  background: var(--accent-soft);
  color: var(--accent-text);
}

/* ── scrollbars ────────────────────────────────────────────────────────────
   Thin and theme-aware where supported; the platform default elsewhere. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--r-full);
  border: 3px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background-color: var(--text-subtle); background-clip: content-box; }

/* ── utilities ─────────────────────────────────────────────────────────── */

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Money and any figure that is read in a column. Without tabular numerals a
   column of amounts jitters and stops being scannable. */
.num, .money, td.num, .stat-value {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.muted   { color: var(--text-muted); }
.subtle  { color: var(--text-subtle); }
.small   { font-size: var(--fs-sm); }
.tiny    { font-size: var(--fs-xs); }
.strong  { font-weight: var(--fw-semi); }
.center  { text-align: center; }
.right   { text-align: right; }
.nowrap  { white-space: nowrap; }
.pos     { color: var(--ok); }
.neg     { color: var(--danger); }

.row  { display: flex; align-items: center; gap: var(--s-2); }
.col  { display: flex; flex-direction: column; gap: var(--s-2); }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.spacer { flex: 1 1 auto; }

.hidden, [hidden] { display: none !important; }

/* ── motion preference ─────────────────────────────────────────────────────
   Honour the system setting rather than assuming everyone enjoys movement.
   Kept to one rule at the end so it wins without needing !important anywhere. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── print ─────────────────────────────────────────────────────────────────
   Reports do get printed. Drop the chrome, keep the content on white. */
@media print {
  :root { color-scheme: light; }
  body { background: #fff; color: #000; }
  .app-sidebar, .app-tabbar, .app-topbar, .fab, .no-print { display: none !important; }
  .app-main { padding: 0 !important; overflow: visible !important; }
  .card { break-inside: avoid; box-shadow: none; border: 1px solid #ccc; }
}
