/* ============================================================================
   PLUMB — base: reset, typography, native form controls
   ========================================================================= */
@layer base {

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scrollbar-color: var(--border-loud) transparent;
}

body {
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--t-base);
  font-weight: var(--w-norm);
  line-height: var(--lh-body);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv05" 1, "ss02" 1;
  min-height: 100vh;
  /* clip, not hidden: clip does not create a scroll container, so sticky
     headers keep working and an off-canvas panel cannot inflate scrollWidth */
  overflow-x: clip;
}
@supports not (overflow-x: clip) { body { overflow-x: hidden; } }

img, svg, video, canvas { display: block; max-width: 100%; }
svg { flex-shrink: 0; }

/* ---- headings: display face, negative tracking, never bold -------------- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: var(--w-semi);
  line-height: var(--lh-tight);
  letter-spacing: var(--track-display);
  text-wrap: balance;
  font-variation-settings: "wdth" 100;
}
h1 { font-size: var(--t-3xl); }
h2 { font-size: var(--t-2xl); }
h3 { font-size: var(--t-xl); }
h4 { font-size: var(--t-lg); letter-spacing: var(--track-tight); }
h5, h6 { font-size: var(--t-base); letter-spacing: var(--track-tight); }

p { text-wrap: pretty; }
p, li { max-width: 72ch; }

b, strong { font-weight: var(--w-semi); }

a { color: var(--brand); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--brand-hover); }

code, kbd, samp, pre, .mono {
  font-family: var(--font-mono);
  font-size: 0.9em;
  font-variant-ligatures: none;
}
/* realm ids, envelope ids and account paths are long unbroken strings —
   they must be allowed to break rather than widen their column */
.mono, code { overflow-wrap: anywhere; }
.tablewrap, .code, .iif { max-width: 100%; }

hr { border: 0; border-top: 1px solid var(--border); }

/* every number that lines up in a column ---------------------------------- */
.num, td.num, th.num, .money, input[type="number"], time, .tnum {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}
.money {
  letter-spacing: var(--track-num);
  white-space: nowrap;
  color: var(--money-out);
}
.money--held  { color: var(--money-held); }
.money--late  { color: var(--money-late); }
.money--saved { color: var(--money-saved); }
/* accounting convention: negatives in parentheses, not just red */
.money--neg::before { content: "("; }
.money--neg::after  { content: ")"; }
.money--neg { color: var(--money-late); }

.figure {
  font-family: var(--font-display);
  font-variation-settings: "wdth" 112;
  font-weight: var(--w-med);
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--track-num);
  line-height: var(--lh-num);
}

/* ---- form controls: one vocabulary, everywhere -------------------------- */
input, textarea, select, button {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}

input[type="text"], input[type="search"], input[type="email"], input[type="number"],
input[type="date"], input[type="tel"], input[type="password"], textarea, select {
  width: 100%;
  padding: 7px 10px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  font-size: var(--t-sm);
  color: var(--ink);
  transition: border-color var(--d-fast) var(--ease-out),
              box-shadow var(--d-fast) var(--ease-out),
              background-color var(--d-fast) var(--ease-out);
}
textarea { min-height: 76px; resize: vertical; line-height: var(--lh-snug); }

input:hover:not(:disabled), textarea:hover:not(:disabled), select:hover:not(:disabled) {
  border-color: var(--border-loud);
}
input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--brand) 16%, transparent);
}
input:disabled, textarea:disabled, select:disabled {
  background: var(--sunken);
  color: var(--muted);
  cursor: not-allowed;
  border-color: var(--border);
}
input[aria-invalid="true"], textarea[aria-invalid="true"], select[aria-invalid="true"] {
  border-color: var(--neg);
  background: var(--neg-soft);
}
input[aria-invalid="true"]:focus-visible {
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--neg) 18%, transparent);
}
::placeholder { color: var(--muted); opacity: 1; }  /* muted is ≥4.5:1, not faint */

select {
  appearance: none;
  padding-right: 28px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 15px) calc(50% + 1px), calc(100% - 10px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

input[type="checkbox"], input[type="radio"] {
  appearance: none;
  width: 15px; height: 15px;
  flex: 0 0 15px;
  border: 1px solid var(--border-loud);
  background: var(--surface);
  border-radius: var(--r-xs);
  cursor: pointer;
  display: grid;
  place-content: center;
  transition: background-color var(--d-press) var(--ease-out),
              border-color var(--d-press) var(--ease-out);
}
input[type="radio"] { border-radius: var(--r-full); }
input[type="checkbox"]::after {
  content: "";
  width: 9px; height: 9px;
  transform: scale(0);
  transition: transform var(--d-press) var(--ease-out);
  background: var(--on-brand);
  clip-path: polygon(14% 46%, 0 62%, 38% 100%, 100% 22%, 84% 6%, 36% 66%);
}
input[type="radio"]::after {
  content: "";
  width: 6px; height: 6px; border-radius: var(--r-full);
  background: var(--on-brand);
  transform: scale(0);
  transition: transform var(--d-press) var(--ease-out);
}
input[type="checkbox"]:checked, input[type="radio"]:checked,
input[type="checkbox"]:indeterminate {
  background: var(--brand); border-color: var(--brand);
}
input[type="checkbox"]:checked::after, input[type="radio"]:checked::after { transform: scale(1); }
input[type="checkbox"]:indeterminate::after {
  transform: scale(1);
  clip-path: polygon(8% 40%, 92% 40%, 92% 60%, 8% 60%);
}
input[type="checkbox"]:focus-visible, input[type="radio"]:focus-visible {
  outline: none; box-shadow: var(--focus);
}
input[type="checkbox"]:disabled, input[type="radio"]:disabled {
  background: var(--sunken-2); border-color: var(--border); cursor: not-allowed;
}

input[type="range"] {
  appearance: none; width: 100%; background: transparent; cursor: pointer; padding: 0;
  border: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px; border-radius: var(--r-full); background: var(--sunken-2);
}
input[type="range"]::-moz-range-track {
  height: 4px; border-radius: var(--r-full); background: var(--sunken-2);
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none; width: 15px; height: 15px; margin-top: -5.5px;
  border-radius: var(--r-full); background: var(--brand);
  border: 2px solid var(--surface);
  transition: transform var(--d-press) var(--ease-out);
}
input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px; border-radius: var(--r-full);
  background: var(--brand); border: 2px solid var(--surface);
}
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.14); }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: var(--focus); }

label { font-size: var(--t-xs); color: var(--ink-2); font-weight: var(--w-med); }

fieldset { border: 0; padding: 0; }
legend { padding: 0; }

/* ---- focus: one ring, everywhere ---------------------------------------- */
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: var(--r-xs); }
:focus:not(:focus-visible) { outline: none; }

::selection { background: var(--brand-soft-2); color: var(--brand-ink); }

/* ---- scrollbars: quiet, not reinvented ---------------------------------- */
::-webkit-scrollbar { width: 11px; height: 11px; }
::-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: var(--border-loud); background-clip: content-box; }
::-webkit-scrollbar-corner { background: transparent; }

/* ---- a11y helpers -------------------------------------------------------- */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.skip-link {
  position: absolute; left: var(--s-4); top: -60px; z-index: var(--z-tooltip);
  background: var(--brand); color: var(--on-brand);
  padding: var(--s-3) var(--s-6); border-radius: var(--r-sm);
  font-size: var(--t-sm); font-weight: var(--w-med); text-decoration: none;
  transition: top var(--d-base) var(--ease-out);
}
.skip-link:focus { top: var(--s-4); color: var(--on-brand); }

[hidden] { display: none !important; }

/* ---- reduced motion: crossfade or instant, never nothing ---------------- */
@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;
  }
  .allow-fade { transition: opacity 140ms linear !important; }
}

/* ---- cross-document transitions: pure progressive enhancement ----------- */
@supports (view-transition-name: none) {
  @view-transition { navigation: auto; }
  ::view-transition-old(root) { animation: vt-out 90ms linear both; }
  ::view-transition-new(root) { animation: vt-in 140ms var(--ease-out) both; }
  @keyframes vt-out { to { opacity: 0; } }
  @keyframes vt-in { from { opacity: 0; } }
  @media (prefers-reduced-motion: reduce) {
    ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
  }
}

@media print {
  .app-nav, .app-topbar, .no-print { display: none !important; }
  body { background: #fff; }
}

}
