/* wicw-design — base.css — v0.1.0
 *
 * Reset, layout primitives and the component set named in
 * portal-rebuild-spec.md §15: card, button, form, table, alert, tabs, nav —
 * plus status chips, which the portal cannot be built without.
 *
 * Every colour and size here comes from tokens.css. There are no literals.
 * Load tokens.css first.
 *
 * MOBILE FIRST, and literally: the single-column rules are the base rules and
 * the wider layouts are added at min-width. 640px is the one breakpoint.
 */

/* ── Reset ──────────────────────────────────────────────────────────────── */

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  font-synthesis-weight: none;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; line-height: var(--lh-tight); text-wrap: balance; font-weight: 600; }
h1 { font-size: var(--fs-xl); letter-spacing: -0.015em; }
h2 { font-size: var(--fs-lg); letter-spacing: -0.01em; }
h3 { font-size: var(--fs-md); }
h4 { font-size: var(--fs-base); }

p  { margin: 0; max-width: var(--measure); }
ul, ol { margin: 0; padding-left: 1.25em; }
img, svg, video { max-width: 100%; height: auto; }

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}
a:hover { color: var(--accent-hov); }

/* One visible focus state for everything, drawn outside the element so it
   never changes layout. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

@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;
  }
}

/* ── Layout primitives ──────────────────────────────────────────────────── */

.wrap {
  max-width: var(--page-max);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* Vertical rhythm is gap on the container, never margins on the children —
   margins collapse and double, gaps do not. */
.stack   { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack-5 { display: flex; flex-direction: column; gap: var(--sp-5); }
.stack-6 { display: flex; flex-direction: column; gap: var(--sp-6); }
.row     { display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: center; }
.row-end { margin-left: auto; }

/* Cards stack under 640px and fill their track above it. */
.grid {
  display: grid;
  gap: var(--sp-4);
  grid-template-columns: 1fr;
}
@media (min-width: 640px) {
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ── Type helpers ───────────────────────────────────────────────────────── */

.label {
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--muted);
}
.caption { font-size: var(--fs-sm); color: var(--muted); }
.lede    { font-size: var(--fs-md); color: var(--muted); line-height: var(--lh-snug); }

/* Money. Tabular figures so columns of dollars line up, and the sans rather
   than the mono — a bill should not look like a terminal. */
.money {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  white-space: nowrap;
}
.money-lg { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -0.02em; }
.money-neg { color: var(--good); }   /* a credit is good news, not an error */

/* Identifiers a person reads out loud or types back: Billing Numbers, invoice
   numbers, transaction ids. */
.ident {
  font-family: var(--font-mono);
  font-size: 0.9em;
  letter-spacing: 0.01em;
}

/* ── Card ───────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}
/* Spent deliberately, on the one card that is the point of the page — not on
   every card, which would flatten the hierarchy back out. */
.card-raised { box-shadow: var(--shadow-1); }

.card-head {
  display: flex;
  align-items: baseline;
  gap: var(--sp-3);
  flex-wrap: wrap;
}
.card-head .row-end { flex-shrink: 0; }

/* A dashboard card whose source is unreachable (spec §6). Still a card, still
   the same edges — it just says so. */
.card-degraded { border-style: dashed; color: var(--muted); }

/* Label/value pairs down a card. Same baseline on every row. */
.pairs { display: grid; gap: var(--sp-3); margin: 0; }
.pairs > div {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-1);
  padding-bottom: var(--sp-3);
  border-bottom: 1px solid var(--line);
}
.pairs > div:last-child { padding-bottom: 0; border-bottom: 0; }
.pairs dt { font-size: var(--fs-sm); color: var(--muted); }
.pairs dd { margin: 0; }
@media (min-width: 640px) {
  .pairs > div { grid-template-columns: 11rem 1fr; align-items: baseline; gap: var(--sp-4); }
}

/* ── Button ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--tap);
  padding: 0 var(--sp-5);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--line); color: var(--ink); }

.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hov); color: var(--accent-ink); }

.btn-quiet { background: transparent; border-color: var(--line-strong); color: var(--ink); }
.btn-quiet:hover { background: var(--surface-2); }

.btn-danger { background: transparent; border-color: var(--alert); color: var(--alert); }
.btn-danger:hover { background: var(--alert); color: var(--alert-ink); }

.btn-sm { min-height: 34px; padding: 0 var(--sp-3); font-size: var(--fs-sm); }

.btn[disabled], .btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

/* Full width under 640px — a payment button is pressed with a thumb. */
.btn-block { width: 100%; }
@media (min-width: 640px) { .btn-block { width: auto; } }

/* ── Form ───────────────────────────────────────────────────────────────── */

.field { display: flex; flex-direction: column; gap: var(--sp-2); }
.field > label { font-size: var(--fs-sm); font-weight: 600; color: var(--ink); }

.input, .select, .textarea {
  width: 100%;
  min-height: var(--tap);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font: inherit;               /* 16px, so iOS Safari does not zoom on focus */
  transition: border-color var(--dur-fast) var(--ease);
}
.textarea { min-height: 7rem; resize: vertical; line-height: var(--lh-body); }
.input::placeholder, .textarea::placeholder { color: var(--muted); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--muted); }
.input[aria-invalid="true"] { border-color: var(--alert); }

.select {
  appearance: none;
  padding-right: var(--sp-6);
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 1.15rem center, right 0.85rem center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.hint { font-size: var(--fs-sm); color: var(--muted); }
.hint-error { color: var(--alert); }

/* Checkbox and radio rows, sized to the 44px target including the label. */
.check {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  min-height: var(--tap);
  padding: var(--sp-2) 0;
  cursor: pointer;
}
.check input { width: 1.25rem; height: 1.25rem; margin: 0.2rem 0 0; accent-color: var(--accent); flex: none; }

/* ── Table ──────────────────────────────────────────────────────────────── */

.table-scroll { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.table caption {
  text-align: left;
  padding-bottom: var(--sp-3);
  font-size: var(--fs-sm);
  color: var(--muted);
}
.table th {
  text-align: left;
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--muted);
  padding: var(--sp-3);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td {
  padding: var(--sp-3);
  border-bottom: 1px solid var(--line);
  vertical-align: baseline;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }

/* Under 640px the table becomes stacked rows: each cell shows its own header
   from data-label, so nothing scrolls sideways and nothing is truncated. */
@media (max-width: 639px) {
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .table tr {
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: var(--sp-2) var(--sp-3);
    margin-bottom: var(--sp-3);
    background: var(--surface);
  }
  .table td {
    display: grid;
    grid-template-columns: 9rem 1fr;
    gap: var(--sp-3);
    align-items: baseline;
    padding: var(--sp-2) 0;
    border-bottom: 1px solid var(--line);
  }
  .table td::before {
    content: attr(data-label);
    font-size: var(--fs-sm);
    font-weight: 600;
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
    color: var(--muted);
  }
  .table td:last-child { border-bottom: 0; }
  .table .num { text-align: left; }
}

/* ── Status chips ───────────────────────────────────────────────────────── */

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}
/* The dot carries the state as well as the colour, so the chip is still
   readable in greyscale and to anyone who does not see the hue. */
.chip::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.chip-good  { background: var(--good-soft);  color: var(--good); }
.chip-alert { background: var(--alert-soft); color: var(--alert); }

/* Pending is deliberately colourless: an invoice awaiting settlement is not a
   warning, and amber here would collide with the accent. The pulse is what
   says "in progress". */
.chip-pending { background: var(--surface-2); color: var(--muted); }
.chip-pending::before { animation: chip-pulse 1.8s var(--ease) infinite; }
@keyframes chip-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ── Alert ──────────────────────────────────────────────────────────────── */

.alert {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border: 1px solid var(--line);
  border-left: 3px solid var(--muted);
  border-radius: var(--r-md);
  background: var(--surface);
  font-size: var(--fs-base);
}
.alert-good  { border-left-color: var(--good);   background: var(--good-soft); }
.alert-error { border-left-color: var(--alert);  background: var(--alert-soft); }
.alert-accent{ border-left-color: var(--accent); background: var(--accent-soft); }
.alert strong { font-weight: 600; }

/* The card-descriptor disclosure required by spec §11, wherever a card or
   bank account is entered and in every receipt. It is a component rather than
   a string in a template so it cannot be styled inconsistently or dropped. */
.disclosure {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--ink);
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
}
.disclosure b { font-family: var(--font-mono); font-size: 0.92em; font-weight: 600; }

/* ── Tabs ───────────────────────────────────────────────────────────────── */

.tabs {
  display: flex;
  gap: var(--sp-1);
  list-style: none;
  margin: 0;
  padding: 0;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a, .tabs button {
  display: flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 var(--sp-4);
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.tabs a:hover, .tabs button:hover { color: var(--ink); }
.tabs [aria-selected="true"], .tabs .is-active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

/* ── Nav ────────────────────────────────────────────────────────────────── */

.nav {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  flex-wrap: wrap;
  padding-block: var(--sp-3);
  border-bottom: 1px solid var(--line);
  background: var(--ground);
}
.nav-links {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav-links::-webkit-scrollbar { display: none; }
.nav-links a {
  display: flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 var(--sp-3);
  border-radius: var(--r-md);
  color: var(--muted);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.nav-links a:hover { background: var(--surface-2); color: var(--ink); }
.nav-links a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }

/* The mark. Swapped by changing --logo-src in tokens.css and nothing else. */
.logo {
  display: block;
  width: 168px;
  aspect-ratio: var(--logo-ratio);
  background-color: var(--logo-plate);
  background-image: var(--logo-src);
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  border-radius: var(--r-sm);
  padding: var(--logo-pad);
  flex: none;
}

/* ── Utilities ──────────────────────────────────────────────────────────── */

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
.divider { height: 1px; background: var(--line); border: 0; margin: 0; }
