/* Ulti-Care 360 — the shared chrome: the twelve primitives every portal already has, given one shape.
 *
 * `design-system.css` holds the vocabulary (six sizes, seven steps, three radii, one family, one palette).
 * This file spends it on the class names the portals already use — `.card`, `.toolbar`, `.section`, `.nav-tab`,
 * `.table-responsive`, `.toast-container` — so a portal adopts it by loading one stylesheet and changing nothing
 * in its markup. Load it LAST, after the portal's own stylesheet and after `design-system.css`.
 *
 * What it deliberately does NOT do: reflow a layout. No grid restructuring, no reordering, no hiding. A shared
 * sheet that moves twenty screens cannot be verified screen by screen, and this is a clinical product where a
 * control in a different place is a defect. It changes spacing, type, borders, radii, control height and the
 * vocabulary for states - the things that make twenty portals read as one product.
 *
 * Measured on the lab portal before this file (live, computed styles): 14 distinct font sizes, 3 font families,
 * 12 colours, 6 corner radii, 5 shadows, 1 decorative gradient and 5 interactive controls under 40px. Those are
 * the numbers `tooling/audit_portal_styles.js` reports, and they are what this sheet exists to bring down.
 *
 * Specificity: plain class selectors, so a portal's `.card` and this `.card` tie and load order decides. Where a
 * portal has deliberately built something more specific, it wins - and the ratchet in
 * `tooling/check_design_tokens.py` is how that local value eventually becomes a token.
 */

/* ── 1. type ───────────────────────────────────────────────────────────────────────────────────────────────── */

html body {
  font-family: var(--uc-font);
  font-size: var(--uc-text-md);
  line-height: 1.5;
  color: var(--uc-ink);
  background: var(--uc-canvas);
  -webkit-font-smoothing: antialiased;
}

/* Six sizes, and a heading is a size and a weight - not a colour. */
h1, .page-title { font-size: var(--uc-text-xl); font-weight: 600; line-height: 1.25; }
h2 { font-size: var(--uc-text-lg); font-weight: 600; line-height: 1.3; }
h3, .card-title { font-size: var(--uc-text-lg); font-weight: 600; line-height: 1.35; }
h4, h5, h6 { font-size: var(--uc-text-md); font-weight: 600; }

/* Supporting copy is one size and one colour everywhere. */
.section-desc, .card-subtitle, .muted, .help-text, small { font-size: var(--uc-text-sm); color: var(--uc-body); }

/* Identifiers are monospaced so a column of them lines up; that is the only place a second family earns its keep. */
code, kbd, samp, .mono, .identifier { font-family: var(--uc-font-mono); font-size: var(--uc-text-sm); }

/* ── 2. the page block ─────────────────────────────────────────────────────────────────────────────────────── */

.section { margin-bottom: var(--uc-space-5); }
.section > h2, .section > h3 { margin: 0 0 var(--uc-space-3); }

/* ── 3. surfaces: a card is a boundary, not a floating object ──────────────────────────────────────────────── */

.card, .form-card, .result-box, .panel {
  background: var(--uc-surface);
  border: 1px solid var(--uc-line);
  border-radius: var(--uc-radius-md);
  padding: var(--uc-space-4);
  box-shadow: none;
}

.card > h2, .card > h3, .form-card > h2, .form-card > h3 { margin-top: 0; }
.card + .card, .form-card + .form-card { margin-top: var(--uc-space-4); }

/* ── 4. grids: one gap, one minimum width ──────────────────────────────────────────────────────────────────── */

/* A grid primitive is opt-in by name: `.grid` is a class portals already use for their own layouts, and a shared
   sheet that redefines it reflows pages it has never been measured on. `.card-grid` and `.stats-grid` mean a grid
   of cards and a grid of stats, which is what this rule does. */
.card-grid, .stats-grid {
  display: grid;
  gap: var(--uc-space-4);
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

/* ── 5. the toolbar above a list ───────────────────────────────────────────────────────────────────────────── */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--uc-space-2);
  padding-bottom: var(--uc-space-3);
  margin-bottom: var(--uc-space-4);
  border-bottom: 1px solid var(--uc-line);
}

/* ── 6. tables ─────────────────────────────────────────────────────────────────────────────────────────────── */

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

table { width: 100%; border-collapse: collapse; font-size: var(--uc-text-sm); }
thead th {
  text-align: left;
  font-size: var(--uc-text-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--uc-body);
  padding: var(--uc-space-2) var(--uc-space-3);
  border-bottom: 1px solid var(--uc-line);
  white-space: nowrap;
}
tbody td { padding: var(--uc-space-3); border-bottom: 1px solid var(--uc-line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
/* Numbers line up down a column without a monospaced face. */
td.num, th.num, .amount { text-align: right; font-variant-numeric: tabular-nums; }

/* ── 7. controls: nothing a finger cannot hit ──────────────────────────────────────────────────────────────── */

button, .btn, [role="button"], input, select, textarea {
  min-height: 40px;
  border-radius: var(--uc-radius-sm);
  font-family: var(--uc-font);
  font-size: var(--uc-text-md);
}
input, select, textarea {
  padding: 0 var(--uc-space-3);
  border: 1px solid var(--uc-line);
  background: var(--uc-surface);
  color: var(--uc-ink);
}
textarea { padding: var(--uc-space-2) var(--uc-space-3); min-height: 88px; }
input::placeholder, textarea::placeholder { color: var(--uc-body); opacity: 1; }

.btn, button.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--uc-space-2);
  padding: 0 var(--uc-space-4);
  border: 1px solid var(--uc-line);
  background: var(--uc-surface);
  color: var(--uc-ink);
  cursor: pointer;
}
/* One primary action per screen. Everything else is the default button. */
.btn-primary, .btn.primary {
  background: var(--uc-teal);
  border-color: var(--uc-teal);
  color: var(--uc-on-brand);
  font-weight: 600;
}
.btn-primary:hover, .btn.primary:hover { background: var(--uc-teal-bright); border-color: var(--uc-teal-bright); }

/* ── 8. navigation: a tab is a target, not a decoration ───────────────────────────────────────────────────── */

.nav-tab, .nav-item, [data-section] {
  display: inline-flex;
  align-items: center;
  gap: var(--uc-space-2);
  min-height: 44px;
  padding: 0 var(--uc-space-3);
  border-radius: var(--uc-radius-sm);
  border-bottom: 2px solid transparent;
  color: var(--uc-body);
  text-decoration: none;
  white-space: nowrap;
}
.nav-tab.active, .nav-item.active, [data-section].active {
  color: var(--uc-teal);
  font-weight: 600;
  border-bottom-color: var(--uc-teal);
}

/* ── 9. the four states, one vocabulary ───────────────────────────────────────────────────────────────────── */

/* Every panel needs to say "nothing yet", "loading", "you may not see this" and "this source is down" - and the
   platform is careful about the difference. One shape for all four, so a reader learns it once. */
.empty, .loading-text, .state {
  display: block;
  padding: var(--uc-space-4);
  font-size: var(--uc-text-sm);
  color: var(--uc-body);
  text-align: center;
}
.state-error, .is-danger { color: var(--uc-danger); }
.state-warning, .is-warn { color: var(--uc-warn); }
.state-ok, .is-ok { color: var(--uc-ok); }

/* A label inside an overlay sits on the overlay, not on the page. Without this, a portal's dark loading overlay
   shows its own message in the page's muted ink - 1.8:1, i.e. a sentence nobody can read while waiting. */
.loading-overlay .loading-text,
.loading-overlay .state {
  color: var(--uc-on-brand);
}
.loading-overlay .spinner {
  border-color: color-mix(in srgb, var(--uc-on-brand) 22%, transparent);
  border-top-color: var(--uc-teal-bright);
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--uc-line);
  border-top-color: var(--uc-teal);
  border-radius: 50%;
  animation: uc-spin 0.8s linear infinite;
}
@keyframes uc-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
}

/* ── 10. chips ────────────────────────────────────────────────────────────────────────────────────────────── */

.chip, .badge, .pill, .tag {
  display: inline-flex;
  align-items: center;
  gap: var(--uc-space-1);
  padding: 2px var(--uc-space-2);
  border: 1px solid var(--uc-line);
  border-radius: var(--uc-radius-sm);
  font-size: var(--uc-text-xs);
  font-weight: 500;
  color: var(--uc-body);
  background: var(--uc-canvas);
}

/* ── 11. the one thing allowed to float ───────────────────────────────────────────────────────────────────── */

/* A toast is above the page, so it keeps one elevation. Nothing else in a card does. */
.toast-container { position: fixed; right: var(--uc-space-4); bottom: var(--uc-space-4); display: grid; gap: var(--uc-space-2); z-index: var(--z-toast); }
.toast {
  min-width: 240px;
  max-width: 360px;
  padding: var(--uc-space-3) var(--uc-space-4);
  background: var(--uc-surface);
  border: 1px solid var(--uc-line);
  border-left: 3px solid var(--uc-teal);
  border-radius: var(--uc-radius-md);
  box-shadow: var(--uc-elev-2);
  font-size: var(--uc-text-sm);
}

/* ── 12. the screen itself on a phone ─────────────────────────────────────────────────────────────────────── */

@media (max-width: 720px) {
  html body { font-size: var(--uc-text-md); }
  h1, .page-title { font-size: var(--uc-text-lg); }
  .card-grid, .stats-grid { grid-template-columns: 1fr; }
  .card, .form-card, .result-box { padding: var(--uc-space-3); }
  .toast-container { left: var(--uc-space-3); right: var(--uc-space-3); bottom: var(--uc-space-3); }
  .toast { max-width: none; }
}
