/* =============================================================================
   NutraTech — Components
   Reusable building blocks. Depends on design-tokens.css + base.css.
   Severity is NEVER color-only: .flag / .pill carry an icon + text label.
   ============================================================================= */

/* ---------------------------------------------------------------------------
   CARD / PANEL
   --------------------------------------------------------------------------- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
.card--flush { border-radius: var(--radius-lg); overflow: hidden; }
.card__head {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-soft);
}
.card__head .spacer { flex: 1; }
.card__title { font-size: var(--text-md); font-weight: var(--fw-bold); letter-spacing: var(--tracking-tight); }
.card__title-icon { width: 18px; height: 18px; color: var(--teal-600); flex: none; }
.card__sub { font-size: var(--text-xs); color: var(--text-muted); }
.card__body { padding: var(--space-5); }
.card__body--tight { padding: var(--space-4); }
.card__foot {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border-soft);
  background: var(--bg-inset);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Section divider with eyebrow label (used to chunk the long brief) */
.sectionbar {
  display: flex; align-items: center; gap: var(--space-3);
  margin: var(--space-2) 0 var(--space-1);
}
.sectionbar__num {
  width: 22px; height: 22px; border-radius: var(--radius-pill);
  background: var(--teal-100); color: var(--teal-700);
  font-size: var(--text-2xs); font-weight: var(--fw-bold);
  display: grid; place-items: center; flex: none;
}
.sectionbar h3 { font-size: var(--text-md); font-weight: var(--fw-bold); letter-spacing: var(--tracking-tight); white-space: nowrap; }
.sectionbar .spacer { flex: 1; }
.sectionbar .hint { font-size: var(--text-xs); color: var(--text-muted); }

/* ---------------------------------------------------------------------------
   BUTTONS
   --------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  font-size: var(--text-sm); font-weight: var(--fw-semibold);
  padding: var(--space-2) var(--space-4); height: 38px;
  border-radius: var(--radius-md); border: 1px solid transparent;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast), box-shadow var(--dur-fast);
  white-space: nowrap; line-height: 1;
}
.btn svg { width: 16px; height: 16px; }
.btn--primary { background: var(--teal-800); color: #fff; box-shadow: var(--shadow-xs); }
.btn--primary:hover { background: var(--teal-700); }
.btn--primary:active { background: var(--teal-900); }
.btn--secondary { background: var(--bg-surface); color: var(--text-primary); border-color: var(--border-strong); }
.btn--secondary:hover { background: var(--bg-inset); border-color: var(--ink-400); }
.btn--ghost { background: transparent; color: var(--text-secondary); }
.btn--ghost:hover { background: var(--bg-inset); color: var(--text-primary); }
.btn--danger { background: var(--bg-surface); color: var(--sev-high-700); border-color: var(--sev-high-100); }
.btn--danger:hover { background: var(--sev-high-050); border-color: var(--sev-high-500); }
.btn--sign {
  background: var(--teal-800); color: #fff;
  height: 46px; padding: 0 var(--space-6); font-size: var(--text-md);
  box-shadow: var(--shadow-md);
}
.btn--sign:hover { background: var(--teal-700); }
.btn--sm { height: 30px; padding: var(--space-1) var(--space-3); font-size: var(--text-xs); }
.btn--lg { height: 46px; padding: 0 var(--space-6); font-size: var(--text-md); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }
.btn--block { width: 100%; }

.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; border-left-width: 0; }
.btn-group .btn:first-child { border-radius: var(--radius-md) 0 0 var(--radius-md); border-left-width: 1px; }
.btn-group .btn:last-child { border-radius: 0 var(--radius-md) var(--radius-md) 0; }

/* ---------------------------------------------------------------------------
   PILL / BADGE / STATUS
   --------------------------------------------------------------------------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--text-2xs); font-weight: var(--fw-semibold);
  padding: 2px 9px 2px 7px; border-radius: var(--radius-pill);
  letter-spacing: 0.01em; white-space: nowrap;
  border: 1px solid transparent;
}
.pill svg { width: 12px; height: 12px; flex: none; }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.pill--high { background: var(--sev-high-100); color: var(--sev-high-700); border-color: #f3cbc4; }
.pill--high .dot { background: var(--sev-high-600); }
.pill--mod  { background: var(--sev-mod-100); color: var(--sev-mod-700); border-color: #f0d9a8; }
.pill--mod .dot { background: var(--sev-mod-600); }
.pill--low  { background: var(--sev-low-100); color: var(--sev-low-700); border-color: #c8ddf3; }
.pill--low .dot { background: var(--sev-low-600); }
.pill--ok   { background: var(--sev-ok-100); color: var(--sev-ok-700); border-color: #b9e3cb; }
.pill--ok .dot { background: var(--sev-ok-600); }
.pill--neutral { background: var(--ink-100); color: var(--ink-700); border-color: var(--border); }
.pill--neutral .dot { background: var(--ink-400); }
.pill--teal { background: var(--teal-100); color: var(--teal-700); border-color: var(--teal-200); }
.pill--solid-teal { background: var(--teal-800); color: #fff; }

/* Trend chips */
.trend { display: inline-flex; align-items: center; gap: 4px; font-size: var(--text-xs); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; white-space: nowrap; }
.trend svg { width: 14px; height: 14px; }
.trend--down { color: var(--trend-down); }
.trend--up   { color: var(--trend-up); }
.trend--flat { color: var(--trend-flat); }

/* ---------------------------------------------------------------------------
   SEVERITY FLAG / CALLOUT — the headline component of the brief
   Left severity bar + icon + label + body. Color is reinforced by icon & text.
   --------------------------------------------------------------------------- */
.flag {
  display: grid; grid-template-columns: auto 1fr; gap: var(--space-3);
  padding: var(--space-4); padding-left: var(--space-4);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--bg-surface); position: relative;
  border-left-width: 4px;
}
.flag__icon {
  width: 30px; height: 30px; border-radius: var(--radius-md);
  display: grid; place-items: center; flex: none;
}
.flag__icon svg { width: 18px; height: 18px; }
.flag__main { min-width: 0; }
.flag__top { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; margin-bottom: 3px; }
.flag__title { font-size: var(--text-sm); font-weight: var(--fw-bold); color: var(--text-primary); }
.flag__body { font-size: var(--text-sm); color: var(--text-secondary); line-height: var(--lh-snug); }
.flag__meta { display: flex; gap: var(--space-3); flex-wrap: wrap; margin-top: var(--space-2); font-size: var(--text-xs); color: var(--text-muted); }
.flag__meta b { color: var(--text-secondary); font-weight: var(--fw-semibold); }
.flag__actions { display: flex; gap: var(--space-2); margin-top: var(--space-3); }

.flag--high { border-left-color: var(--sev-high-600); background: var(--sev-high-050); }
.flag--high .flag__icon { background: var(--sev-high-100); color: var(--sev-high-700); }
.flag--mod { border-left-color: var(--sev-mod-600); background: var(--sev-mod-050); }
.flag--mod .flag__icon { background: var(--sev-mod-100); color: var(--sev-mod-700); }
.flag--low { border-left-color: var(--sev-low-600); background: var(--sev-low-050); }
.flag--low .flag__icon { background: var(--sev-low-100); color: var(--sev-low-700); }
.flag--ok { border-left-color: var(--sev-ok-600); background: var(--sev-ok-050); }
.flag--ok .flag__icon { background: var(--sev-ok-100); color: var(--sev-ok-700); }

/* ---------------------------------------------------------------------------
   KPI CARD
   --------------------------------------------------------------------------- */
.kpi {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: var(--space-5);
  display: flex; flex-direction: column; gap: var(--space-2);
  box-shadow: var(--shadow-xs); position: relative; overflow: hidden;
}
.kpi__label { display: flex; align-items: center; gap: var(--space-2); }
.kpi__label .t-label { color: var(--text-muted); }
.kpi__icon { width: 16px; height: 16px; color: var(--teal-600); }
.kpi__value { font-size: var(--text-3xl); font-weight: var(--fw-bold); letter-spacing: -0.03em; line-height: 1; font-variant-numeric: tabular-nums; color: var(--text-primary); }
.kpi__value small { font-size: var(--text-lg); font-weight: var(--fw-semibold); color: var(--text-muted); }
.kpi__foot { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-xs); color: var(--text-muted); }
.kpi__spark { margin-top: var(--space-1); }
.kpi--accent { background: linear-gradient(160deg, var(--teal-800), var(--teal-700)); border-color: var(--teal-700); }
.kpi--accent .kpi__value, .kpi--accent .kpi__label .t-label, .kpi--accent .kpi__foot { color: #fff; }
.kpi--accent .kpi__label .t-label, .kpi--accent .kpi__foot { color: var(--text-on-teal-mut); }
.kpi--accent .kpi__icon { color: var(--teal-300); }

/* ---------------------------------------------------------------------------
   DATA TABLE
   --------------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
.table { font-size: var(--text-sm); }
.table thead th {
  text-align: left; font-size: var(--text-2xs); font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-label); text-transform: uppercase;
  color: var(--text-muted); padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border); white-space: nowrap;
  position: sticky; top: 0; background: var(--bg-surface); z-index: 1;
}
.table tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle; color: var(--text-secondary);
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--teal-050); }
.table td .primary { color: var(--text-primary); font-weight: var(--fw-semibold); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table th.num { text-align: right; }
.table--zebra tbody tr:nth-child(even) { background: var(--ink-050); }
.table--zebra tbody tr:nth-child(even):hover { background: var(--teal-050); }
.table--compact tbody td, .table--compact thead th { padding: var(--space-2) var(--space-3); }
.cell-name { display: flex; align-items: center; gap: var(--space-3); }
.cell-sub { font-size: var(--text-xs); color: var(--text-muted); }

/* progress meter inside cells (edit %, acceptance, etc.) */
.meter { display: flex; align-items: center; gap: var(--space-2); }
.meter__track { flex: 1; min-width: 60px; height: 6px; border-radius: var(--radius-pill); background: var(--ink-150); overflow: hidden; }
.meter__fill { height: 100%; border-radius: var(--radius-pill); background: var(--teal-500); }
.meter__fill--high { background: var(--sev-high-500); }
.meter__fill--mod { background: var(--sev-mod-500); }
.meter__fill--ok { background: var(--sev-ok-500); }
.meter__val { font-variant-numeric: tabular-nums; font-weight: var(--fw-semibold); color: var(--text-primary); min-width: 38px; text-align: right; }

/* ---------------------------------------------------------------------------
   TAB BAR
   --------------------------------------------------------------------------- */
.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--border); }
.tab {
  appearance: none; background: none; border: none;
  padding: var(--space-3) var(--space-4); font-size: var(--text-sm);
  font-weight: var(--fw-semibold); color: var(--text-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  display: inline-flex; align-items: center; gap: var(--space-2);
}
.tab:hover { color: var(--text-primary); }
.tab.is-active { color: var(--teal-700); border-bottom-color: var(--teal-700); }
.tab svg { width: 16px; height: 16px; }
.tab .tab__count {
  font-size: 11px; font-weight: var(--fw-bold); background: var(--ink-100);
  color: var(--text-secondary); padding: 0 6px; border-radius: var(--radius-pill);
}
.tab.is-active .tab__count { background: var(--teal-100); color: var(--teal-700); }

/* Pill-style segmented control (filters) */
.segmented { display: inline-flex; background: var(--bg-inset); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 2px; gap: 2px; }
.segmented button {
  appearance: none; border: none; background: transparent;
  font-size: var(--text-xs); font-weight: var(--fw-semibold); color: var(--text-secondary);
  padding: var(--space-1) var(--space-3); border-radius: var(--radius-sm);
}
.segmented button.is-active { background: var(--bg-surface); color: var(--text-primary); box-shadow: var(--shadow-xs); }

/* ---------------------------------------------------------------------------
   FORM ROW
   --------------------------------------------------------------------------- */
.formrow {
  display: grid; grid-template-columns: 220px 1fr; gap: var(--space-5);
  padding: var(--space-4) 0; border-bottom: 1px solid var(--border-soft);
  align-items: start;
}
.formrow:last-child { border-bottom: none; }
.formrow__label { font-size: var(--text-sm); font-weight: var(--fw-semibold); color: var(--text-primary); }
.formrow__hint { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }
.formrow__control { min-width: 0; }
.input, .select, .textarea {
  width: 100%; background: var(--bg-surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3); font-size: var(--text-sm);
  color: var(--text-primary); transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--focus-ring); box-shadow: var(--ring-focus); outline: none; }
.input::placeholder { color: var(--ink-400); }
.field-max { max-width: 420px; }

/* Toggle switch */
.switch { position: relative; display: inline-flex; align-items: center; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track { width: 40px; height: 23px; border-radius: var(--radius-pill); background: var(--ink-300); transition: background var(--dur); position: relative; }
.switch__track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 19px; height: 19px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-xs); transition: transform var(--dur) var(--ease); }
.switch input:checked + .switch__track { background: var(--teal-600); }
.switch input:checked + .switch__track::after { transform: translateX(17px); }
.switch input:focus-visible + .switch__track { box-shadow: var(--ring-focus); }

/* Checkbox (suggested orders) */
.check { display: inline-flex; align-items: center; gap: var(--space-3); cursor: pointer; }
.check input { position: absolute; opacity: 0; }
.check__box { width: 20px; height: 20px; border-radius: var(--radius-sm); border: 1.5px solid var(--border-strong); background: var(--bg-surface); display: grid; place-items: center; flex: none; transition: all var(--dur-fast); }
.check__box svg { width: 13px; height: 13px; color: #fff; opacity: 0; }
.check input:checked + .check__box { background: var(--teal-600); border-color: var(--teal-600); }
.check input:checked + .check__box svg { opacity: 1; }
.check input:focus-visible + .check__box { box-shadow: var(--ring-focus); }

/* ---------------------------------------------------------------------------
   EDITABLE NOTE BLOCK — the climax of the Pre-Visit Brief
   --------------------------------------------------------------------------- */
.note {
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--bg-surface); box-shadow: var(--shadow-sm); overflow: hidden;
}
.note__bar {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-inset); border-bottom: 1px solid var(--border);
}
.note__bar .spacer { flex: 1; }
.note__doc {
  font-family: var(--font-doc);
  font-size: var(--text-md); line-height: var(--lh-relaxed);
  color: var(--text-primary);
  padding: var(--space-6) var(--space-8);
  background: var(--bg-surface);
  max-width: 70ch;
}
.note__doc:focus { outline: none; }
.note__doc[contenteditable="true"] { box-shadow: inset 0 0 0 2px var(--teal-100); }
.note__doc h4 { font-family: var(--font-ui); font-size: var(--text-2xs); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--text-muted); margin: var(--space-5) 0 var(--space-1); font-weight: var(--fw-semibold); }
.note__doc h4:first-child { margin-top: 0; }
.note__doc p { margin: 0 0 var(--space-3); }
.note__doc .ai-span { background: var(--teal-050); border-bottom: 1px solid var(--teal-200); border-radius: 2px; padding: 0 1px; }
.note__doc .edited { background: var(--sev-mod-050); border-bottom: 1px solid var(--sev-mod-500); }
.note__foot {
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border); background: var(--bg-surface);
}
.note__sigline { display: flex; flex-direction: column; gap: 2px; }
.note__sigline .who { font-size: var(--text-sm); font-weight: var(--fw-semibold); }
.note__sigline .meta { font-size: var(--text-xs); color: var(--text-muted); }
.note.is-signed { border-color: var(--sev-ok-500); box-shadow: 0 0 0 1px var(--sev-ok-500), var(--shadow-sm); }
.note.is-signed .note__bar { background: var(--sev-ok-050); border-bottom-color: var(--sev-ok-100); }

/* ---------------------------------------------------------------------------
   MISC
   --------------------------------------------------------------------------- */
.divider { height: 1px; background: var(--border-soft); border: none; margin: var(--space-4) 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: var(--space-2) var(--space-4); font-size: var(--text-sm); }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; color: var(--text-primary); font-weight: var(--fw-medium); text-align: right; }
.attribution { display: inline-flex; align-items: center; gap: 5px; font-size: var(--text-2xs); color: var(--text-muted); font-weight: var(--fw-medium); }
.attribution svg { width: 13px; height: 13px; color: var(--teal-500); }
.source-cite { display: inline-flex; align-items: center; gap: 4px; font-size: var(--text-2xs); font-weight: var(--fw-semibold); color: var(--teal-700); background: var(--teal-050); border: 1px solid var(--teal-100); border-radius: var(--radius-sm); padding: 1px 6px; }
.source-cite:hover { background: var(--teal-100); text-decoration: none; }
.empty { text-align: center; padding: var(--space-10); color: var(--text-muted); }
.toast {
  position: fixed; bottom: var(--space-6); left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink-900); color: #fff; padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg); font-size: var(--text-sm);
  display: flex; align-items: center; gap: var(--space-2); opacity: 0; pointer-events: none;
  transition: all var(--dur) var(--ease); z-index: 100;
}
.toast.is-on { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast svg { width: 16px; height: 16px; color: var(--teal-300); }
