/* Component layer. Reads tokens.css and nothing else - no literal colour, no
   raw font-size lives here, and app_selftest asserts that.

   Every class is prefixed .ds- so this file can sit beside bootstrap and each
   app's own stylesheet without either winning by accident. Phases 33-37 copy
   markup from the reference page 32-03 renders from this file. */

/* ============================================================ buttons ==== */

.ds-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--ds-space-2);
  padding: var(--ds-space-3) var(--ds-space-5);
  border: 1px solid transparent;
  border-radius: var(--ds-radius);
  font-family: var(--ds-font);
  font-size: var(--ds-button);
  font-weight: var(--ds-weight-medium);
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--ds-duration-fast) var(--ds-ease),
              border-color var(--ds-duration-fast) var(--ds-ease),
              color var(--ds-duration-fast) var(--ds-ease);
}

.ds-btn:focus-visible {
  outline: none;
  box-shadow: var(--ds-focus-ring);
}

.ds-btn:disabled,
.ds-btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}

.ds-btn-sm { padding: var(--ds-space-2) var(--ds-space-3); font-size: var(--ds-small); }
.ds-btn-lg { padding: var(--ds-space-4) var(--ds-space-6); font-size: var(--ds-body-lg); }
.ds-btn-block { width: 100%; }

.ds-btn-primary {
  background: var(--ds-primary);
  border-color: var(--ds-primary);
  color: var(--ds-text-on-dark);
}
.ds-btn-primary:hover { background: var(--ds-primary-hover); border-color: var(--ds-primary-hover); }
.ds-btn-primary:active { background: var(--ds-primary-active); border-color: var(--ds-primary-active); }

.ds-btn-secondary {
  background: var(--ds-surface);
  border-color: var(--ds-border-strong);
  color: var(--ds-text);
}
.ds-btn-secondary:hover { background: var(--ds-surface-sunken); border-color: var(--ds-text-subtle); }
.ds-btn-secondary:active { background: var(--ds-surface-sunken); border-color: var(--ds-text-muted); }

.ds-btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ds-primary);
}
.ds-btn-ghost:hover { background: var(--ds-surface-sunken); }
.ds-btn-ghost:active { background: var(--ds-border); }

.ds-btn-success {
  background: var(--ds-success);
  border-color: var(--ds-success);
  color: var(--ds-text-on-dark);
}
.ds-btn-success:hover { filter: brightness(0.92); }

/* Danger carries a second, non-colour signal on purpose.
   --ds-primary and --ds-danger sit at almost the same greyscale luminance
   (54 vs 60 of 255), so hue is the ONLY thing separating them for a viewer
   who cannot use it - and this is the button that deletes a patient record.
   The inset ring reads as a different shape, not a different colour, and
   survives greyscale, contrast modes and a monochrome print. */
.ds-btn-danger {
  background: var(--ds-danger);
  border-color: var(--ds-danger);
  color: var(--ds-text-on-dark);
  box-shadow: inset 0 0 0 2px var(--ds-surface),
              inset 0 0 0 3px var(--ds-danger);
}
.ds-btn-danger:hover { filter: brightness(0.92); }
.ds-btn-danger:focus-visible { box-shadow: var(--ds-focus-ring-danger); }

/* ============================================================== forms ==== */

.ds-field { margin-bottom: var(--ds-space-4); }

.ds-label {
  display: block;
  margin-bottom: var(--ds-space-2);
  font-size: var(--ds-small);
  font-weight: var(--ds-weight-medium);
  color: var(--ds-text);
}

.ds-input,
.ds-textarea,
.ds-select {
  display: block;
  width: 100%;
  padding: var(--ds-space-3) var(--ds-space-4);
  border: 1px solid var(--ds-border-strong);
  border-radius: var(--ds-radius);
  background: var(--ds-surface);
  font-family: var(--ds-font);
  font-size: var(--ds-body);
  line-height: var(--ds-body-lh);
  color: var(--ds-text);
  transition: border-color var(--ds-duration-fast) var(--ds-ease),
              box-shadow var(--ds-duration-fast) var(--ds-ease);
}

.ds-input::placeholder,
.ds-textarea::placeholder { color: var(--ds-text-subtle); }

.ds-input:focus,
.ds-textarea:focus,
.ds-select:focus {
  outline: none;
  border-color: var(--ds-primary);
  box-shadow: var(--ds-focus-ring);
}

.ds-input:disabled,
.ds-textarea:disabled,
.ds-select:disabled {
  background: var(--ds-surface-sunken);
  color: var(--ds-text-subtle);
  cursor: not-allowed;
}

.ds-textarea { min-height: 7rem; resize: vertical; }

.ds-check {
  display: flex;
  align-items: flex-start;
  gap: var(--ds-space-3);
  font-size: var(--ds-body);
}
.ds-check input { margin-top: 0.2em; accent-color: var(--ds-primary); }
.ds-check input:focus-visible { outline: none; box-shadow: var(--ds-focus-ring); }

.ds-help {
  margin-top: var(--ds-space-2);
  font-size: var(--ds-caption);
  line-height: var(--ds-caption-lh);
  color: var(--ds-text-muted);
}

/* An error is a sentence, not a red border. The border changes too, but the
   message is what tells a screen reader and a colour-blind reader what is
   wrong - so .ds-error-text is required markup, not an optional extra. */
.ds-field-error .ds-input,
.ds-field-error .ds-textarea,
.ds-field-error .ds-select { border-color: var(--ds-danger); }

.ds-field-error .ds-input:focus,
.ds-field-error .ds-textarea:focus,
.ds-field-error .ds-select:focus { box-shadow: var(--ds-focus-ring-danger); }

.ds-error-text {
  display: flex;
  align-items: center;
  gap: var(--ds-space-2);
  margin-top: var(--ds-space-2);
  font-size: var(--ds-caption);
  line-height: var(--ds-caption-lh);
  color: var(--ds-danger);
}

/* =============================================================== card ==== */

.ds-card {
  background: var(--ds-surface);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-lg);
  box-shadow: var(--ds-shadow);
}

.ds-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ds-space-4);
  padding: var(--ds-space-4) var(--ds-space-5);
  border-bottom: 1px solid var(--ds-border);
}

.ds-card-title {
  margin: 0;
  font-size: var(--ds-h3);
  line-height: var(--ds-h3-lh);
  font-weight: var(--ds-weight-semibold);
  color: var(--ds-text);
}

.ds-card-body { padding: var(--ds-space-5); }

.ds-card-footer {
  padding: var(--ds-space-4) var(--ds-space-5);
  border-top: 1px solid var(--ds-border);
  background: var(--ds-surface-sunken);
  border-radius: 0 0 var(--ds-radius-lg) var(--ds-radius-lg);
}

/* ============================================================== table ==== */

.ds-table-wrap { overflow-x: auto; }

.ds-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--ds-body);
}

.ds-table th {
  padding: var(--ds-space-3) var(--ds-space-4);
  text-align: left;
  background: var(--ds-surface-sunken);
  border-bottom: 1px solid var(--ds-border);
  font-size: var(--ds-caption);
  font-weight: var(--ds-weight-semibold);
  letter-spacing: var(--ds-tracking-wide);
  text-transform: uppercase;
  color: var(--ds-text-muted);
  white-space: nowrap;
}

.ds-table td {
  padding: var(--ds-space-4);
  border-bottom: 1px solid var(--ds-border);
  color: var(--ds-text);
  vertical-align: middle;
}

.ds-table tbody tr:last-child td { border-bottom: none; }
.ds-table tbody tr:hover td { background: var(--ds-surface-sunken); }

/* Mobile hook, defined here and unused until phase 37.
   Declaring it now is what stops three phases inventing three of them.
   Markup contract: each <td> carries data-label="<its column heading>". */
@media (max-width: 767px) {
  /* the table, its body AND its rows all have to leave table layout
     together. setting display:block on tr alone leaves tbody as a
     table-row-group, and the two layout modes overlap each other - which is
     exactly what happened the first time this was applied to a bootstrap
     .table rather than to .ds-table, because the reference page only ever
     proved it against its own markup. */
  .ds-table-cards,
  .ds-table-cards tbody { display: block; width: 100%; }
  .ds-table-cards thead { display: none; }
  /* app.css's `.table > tbody > tr { height: 44px }` is 0,1,2 and loads
     after this file, so a 0,1,1 selector loses on specificity AND on order.
     `table.ds-table-cards > tbody > tr` is 0,1,3 and wins on its own. */
  table.ds-table-cards > tbody > tr {
    display: block;
    /* height on a table row is a MINIMUM in table layout and a hard
       constraint in block layout. app.css pins staff rows to 44px for a
       touch-friendly action column; once the row is a card holding six
       stacked cells, that 44px clipped the content and every card drew on
       top of the next. measured: tr height 44px, content 246px. */
    height: auto;
    margin-bottom: var(--ds-space-4);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius);
    background: var(--ds-surface);
  }
  .ds-table-cards td {
    display: flex;
    box-shadow: none;
    justify-content: space-between;
    gap: var(--ds-space-4);
    border-bottom: 1px solid var(--ds-border);
  }
  .ds-table-cards td::before {
    content: attr(data-label);
    font-size: var(--ds-caption);
    font-weight: var(--ds-weight-semibold);
    text-transform: uppercase;
    letter-spacing: var(--ds-tracking-wide);
    color: var(--ds-text-muted);
  }
  .ds-table-cards tr td:last-child { border-bottom: none; }
}

/* ============================================================== badge ==== */

/* Styling only. Which state gets which colour is Phase 23's contract and is
   asserted in upload_routes_selftest 11-11i - this layer does not re-map it,
   and no two failure domains may share a colour. */
.ds-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--ds-space-1);
  padding: var(--ds-space-1) var(--ds-space-3);
  border-radius: var(--ds-radius-pill);
  font-size: var(--ds-caption);
  font-weight: var(--ds-weight-medium);
  line-height: 1.4;
  white-space: nowrap;
}

.ds-badge-info { background: var(--ds-info-surface); color: var(--ds-info); }
.ds-badge-success { background: var(--ds-success-surface); color: var(--ds-success); }
.ds-badge-warning { background: var(--ds-warning-surface); color: var(--ds-warning); }
.ds-badge-danger { background: var(--ds-danger-surface); color: var(--ds-danger); }
.ds-badge-neutral { background: var(--ds-neutral-surface); color: var(--ds-neutral); }

/* ============================================================== alert ==== */

.ds-alert {
  display: flex;
  align-items: flex-start;
  gap: var(--ds-space-3);
  padding: var(--ds-space-4) var(--ds-space-5);
  border: 1px solid transparent;
  border-radius: var(--ds-radius);
  font-size: var(--ds-body);
  line-height: var(--ds-body-lh);
}

.ds-alert-title {
  display: block;
  margin-bottom: var(--ds-space-1);
  font-weight: var(--ds-weight-semibold);
}

.ds-alert-info { background: var(--ds-info-surface); border-color: var(--ds-info); color: var(--ds-info); }
.ds-alert-success { background: var(--ds-success-surface); border-color: var(--ds-success); color: var(--ds-success); }
.ds-alert-warning { background: var(--ds-warning-surface); border-color: var(--ds-warning); color: var(--ds-warning); }
.ds-alert-danger { background: var(--ds-danger-surface); border-color: var(--ds-danger); color: var(--ds-danger); }

/* =============================================================== tabs ==== */

.ds-tabs {
  display: flex;
  gap: var(--ds-space-2);
  border-bottom: 1px solid var(--ds-border);
}

.ds-tab {
  padding: var(--ds-space-3) var(--ds-space-4);
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  font-family: var(--ds-font);
  font-size: var(--ds-nav);
  font-weight: var(--ds-weight-medium);
  color: var(--ds-text-muted);
  cursor: pointer;
}

.ds-tab:hover { color: var(--ds-text); }
.ds-tab:focus-visible { outline: none; box-shadow: var(--ds-focus-ring); }

/* aria-selected drives the active look, so the accessible state and the
   visible state cannot disagree */
.ds-tab[aria-selected="true"] {
  color: var(--ds-primary);
  border-bottom-color: var(--ds-primary);
}

/* ============================================================== modal ==== */

.ds-modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--ds-scrim);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--ds-space-4);
}

.ds-modal {
  width: 100%;
  max-width: 32rem;
  background: var(--ds-surface);
  border-radius: var(--ds-radius-lg);
  box-shadow: var(--ds-shadow-lg);
}

.ds-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ds-space-4);
  padding: var(--ds-space-5);
  border-bottom: 1px solid var(--ds-border);
}

.ds-modal-title {
  margin: 0;
  font-size: var(--ds-h3);
  line-height: var(--ds-h3-lh);
  font-weight: var(--ds-weight-semibold);
}

.ds-modal-body { padding: var(--ds-space-5); }

.ds-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--ds-space-3);
  padding: var(--ds-space-5);
  border-top: 1px solid var(--ds-border);
}

/* ============================================================= avatar ==== */

.ds-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--ds-radius-pill);
  background: var(--ds-accent-soft);
  color: var(--ds-accent);
  font-size: var(--ds-small);
  font-weight: var(--ds-weight-semibold);
  overflow: hidden;
}

.ds-avatar img { width: 100%; height: 100%; object-fit: cover; }
.ds-avatar-sm { width: 2rem; height: 2rem; font-size: var(--ds-caption); }
.ds-avatar-lg { width: 4rem; height: 4rem; font-size: var(--ds-body-lg); }

/* ========================================================= breadcrumb ==== */

.ds-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--ds-space-2);
  padding: 0;
  margin: 0;
  list-style: none;
  font-size: var(--ds-small);
  color: var(--ds-text-muted);
}

.ds-breadcrumb a { color: var(--ds-text-muted); text-decoration: none; }
.ds-breadcrumb a:hover { color: var(--ds-primary); text-decoration: underline; }
.ds-breadcrumb li + li::before { content: "/"; margin-right: var(--ds-space-2); color: var(--ds-text-subtle); }
.ds-breadcrumb [aria-current="page"] { color: var(--ds-text); font-weight: var(--ds-weight-medium); }

/* =================================================== status indicator ==== */

/* The dot is never the only signal - .ds-status always carries its label as
   text. Colour alone would fail UX-17 and, on a clinical surface, would be
   the kind of thing that reads fine to whoever built it. */
.ds-status {
  display: inline-flex;
  align-items: center;
  gap: var(--ds-space-2);
  font-size: var(--ds-small);
  color: var(--ds-text);
}

.ds-status::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: var(--ds-radius-pill);
  background: currentColor;
  flex: none;
}

.ds-status-success { color: var(--ds-success); }
.ds-status-warning { color: var(--ds-warning); }
.ds-status-danger { color: var(--ds-danger); }
.ds-status-neutral { color: var(--ds-neutral); }

/* ======================================== loading / empty / error ======== */

/* Copy conventions, so five phases write one voice:
     empty  - say what will appear here AND why it has not yet.
              "No dated visits yet. Visits appear here once a note carries a
               visit date." names the cause; "No data" does not.
     error  - say what failed and what to do next.
     loading - a verb, not a noun. "Loading appointments", not "Please wait".
   Each state holds the height of what it replaces, so a card does not
   collapse and the page does not jump as data arrives (phase 31's
   .chart-empty established this). */

.ds-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--ds-space-3);
  min-height: 16rem;
  padding: var(--ds-space-6);
  text-align: center;
}

.ds-state-icon { font-size: var(--ds-h1); line-height: 1; color: var(--ds-text-subtle); }
.ds-state-title { margin: 0; font-size: var(--ds-h3); line-height: var(--ds-h3-lh); font-weight: var(--ds-weight-semibold); color: var(--ds-text); }
.ds-state-body { margin: 0; max-width: 34rem; font-size: var(--ds-body); line-height: var(--ds-body-lh); color: var(--ds-text-muted); }

.ds-state-error .ds-state-icon { color: var(--ds-danger); }
.ds-state-error .ds-state-title { color: var(--ds-danger); }

.ds-spinner {
  width: 1.5rem;
  height: 1.5rem;
  border: 2px solid var(--ds-border-strong);
  border-top-color: var(--ds-primary);
  border-radius: var(--ds-radius-pill);
  animation: ds-spin var(--ds-duration-slow) linear infinite;
}

@keyframes ds-spin { to { transform: rotate(360deg); } }

/* the global prefers-reduced-motion block in tokens.css clamps the duration;
   the spinner still needs to read as busy rather than frozen, so it stops
   spinning and shows as a static ring instead */
@media (prefers-reduced-motion: reduce) {
  .ds-spinner { animation: none; border-top-color: var(--ds-primary); }
}

/* ============================================== screen-reader helper ==== */

.ds-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* =========================================================== exchange ==== */

/* One question and one reply, rendered as turns. Used by the patient chat,
   the staff Q&A, and the public site's assistant preview - defined once so
   the three cannot drift.

   It is an EXCHANGE, not a transcript. Neither app keeps conversation
   state, and the patient app's D-03 requires a reload to return to the
   empty page, so a history here would be a second source of truth. */
.ds-exchange { display: flex; flex-direction: column; gap: var(--ds-space-3); }

.ds-turn {
  max-width: 85%;
  margin: 0;
  padding: var(--ds-space-3) var(--ds-space-4);
  border-radius: var(--ds-radius-lg);
  font-size: var(--ds-body);
  line-height: var(--ds-body-lh);
  overflow-wrap: anywhere;
}

.ds-turn-user {
  align-self: flex-end;
  background: var(--ds-primary);
  color: var(--ds-text-on-dark);
  border-bottom-right-radius: var(--ds-radius-sm);
}

.ds-turn-agent {
  align-self: flex-start;
  background: var(--ds-surface-sunken);
  color: var(--ds-text);
  border-bottom-left-radius: var(--ds-radius-sm);
}

/* ================================================== bootstrap bridge ==== */

/* Bootstrap compiles its own blue into .btn-primary's component variables,
   so overriding --bs-primary in tokens.css never reaches the button.

   Bound to --bs-primary, NOT --ds-primary. Each app defines its own: the
   staff app inherits the navy token, and patient.css deliberately sets green
   - "the one visual signal that tells a public surface apart from the
   internal clinic app at a glance". Phase 34 bound this to --ds-primary and
   so painted navy buttons onto that green surface; this restores the
   distinction the patient app documents and the brief asks for.

   Hover darkens the app's own colour rather than naming a second one, so no
   per-app hover token is needed. The staff app's app.css block still wins
   for it and keeps its named hover shades.

   DEBT: app/static/css/app.css holds an equivalent block. Phase 37 removes
   that copy when it reskins the staff surface. */
.btn-primary {
  --bs-btn-bg: var(--bs-primary);
  --bs-btn-border-color: var(--bs-primary);
  --bs-btn-hover-bg: var(--bs-primary);
  --bs-btn-hover-border-color: var(--bs-primary);
  --bs-btn-active-bg: var(--bs-primary);
  --bs-btn-active-border-color: var(--bs-primary);
  --bs-btn-disabled-bg: var(--bs-primary);
  --bs-btn-disabled-border-color: var(--bs-primary);
}

.btn-primary:hover,
.btn-primary:active { filter: brightness(0.92); }

.btn-outline-primary {
  --bs-btn-color: var(--bs-primary);
  --bs-btn-border-color: var(--bs-primary);
  --bs-btn-hover-bg: var(--bs-primary);
  --bs-btn-hover-border-color: var(--bs-primary);
  --bs-btn-active-bg: var(--bs-primary);
  --bs-btn-active-border-color: var(--bs-primary);
}

/* ===================================================== dashboard (43) ==== */

/* Phase 43 - the language of the Fireart "Pet Clinic Dashboard" reference:
   a page head with a greeting, KPI cards with serif numerals, avatar rows,
   tinted pills, a segmented control and a stacked distribution bar. Shared by
   the staff app and the patient app; each app binds its own --ds-primary. */

.ds-badge-primary {
  background: color-mix(in srgb, var(--ds-primary) 12%, var(--ds-surface));
  color: var(--ds-primary-active);
}

.ds-numeral {
  font-family: var(--ds-font-display);
  font-style: italic;
  font-weight: var(--ds-weight-semibold);
  font-variant-numeric: lining-nums;
  letter-spacing: -0.01em;
}

/* ---- page head ---- */
.ds-page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--ds-space-4);
  padding-bottom: var(--ds-space-5);
  margin-bottom: var(--ds-space-5);
  border-bottom: 1px solid var(--ds-border);
}

.ds-page-eyebrow {
  margin: 0 0 var(--ds-space-1);
  font-size: var(--ds-small);
  color: var(--ds-text-muted);
}

.ds-page-title {
  margin: 0;
  font-size: var(--ds-h2);
  line-height: var(--ds-h2-lh);
  font-weight: var(--ds-weight-semibold);
  letter-spacing: var(--ds-tracking-tight);
  color: var(--ds-text);
}

.ds-page-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--ds-space-2);
  margin: var(--ds-space-2) 0 0;
  font-size: var(--ds-caption);
  color: var(--ds-text-muted);
}

.ds-page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--ds-space-3); }

.ds-dot {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: var(--ds-radius-pill);
  background: currentColor;
  flex: none;
}

.ds-dot-success { color: var(--ds-success); }

/* ---- chip: a person or a thing, small and bordered ---- */
.ds-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--ds-space-3);
  padding: var(--ds-space-2) var(--ds-space-4) var(--ds-space-2) var(--ds-space-2);
  background: var(--ds-surface);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-lg);
  box-shadow: var(--ds-shadow-sm);
  min-width: 0;
}

.ds-chip-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.ds-chip-title { font-size: var(--ds-small); font-weight: var(--ds-weight-semibold); color: var(--ds-text); }
.ds-chip-sub { font-size: var(--ds-caption); color: var(--ds-text-muted); }

/* ---- kpi card ---- */
.ds-kpi {
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-3);
  height: 100%;
  padding: var(--ds-space-5);
  background: var(--ds-surface);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-lg);
  box-shadow: var(--ds-shadow-sm);
}

.ds-kpi-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--ds-radius);
  background: color-mix(in srgb, var(--ds-primary) 10%, var(--ds-surface));
  color: var(--ds-primary);
  font-size: var(--ds-body-lg);
}

.ds-kpi-value {
  margin: var(--ds-space-1) 0 0;
  font-size: var(--ds-numeral);
  line-height: 1;
  color: var(--ds-text);
}

.ds-kpi-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--ds-space-2);
}

.ds-kpi-label { font-size: var(--ds-small); color: var(--ds-text-muted); }

/* ---- segmented control ---- */
/* aria-pressed carries the state, so what is announced and what is drawn
   cannot disagree - the same rule .ds-tab follows with aria-selected */
.ds-segmented {
  display: inline-flex;
  gap: var(--ds-space-1);
  padding: var(--ds-space-1);
  background: var(--ds-surface-sunken);
  border-radius: var(--ds-radius);
}

.ds-segmented button,
.ds-segmented a {
  padding: var(--ds-space-1) var(--ds-space-3);
  border: 0;
  border-radius: var(--ds-radius-sm);
  background: transparent;
  font-family: var(--ds-font);
  font-size: var(--ds-small);
  color: var(--ds-text-muted);
  text-decoration: none;
  cursor: pointer;
}

.ds-segmented button:hover,
.ds-segmented a:hover { color: var(--ds-text); }

.ds-segmented button:focus-visible,
.ds-segmented a:focus-visible { outline: none; box-shadow: var(--ds-focus-ring); }

.ds-segmented [aria-pressed="true"],
.ds-segmented [aria-current="page"] {
  background: var(--ds-surface);
  color: var(--ds-text);
  font-weight: var(--ds-weight-medium);
  box-shadow: var(--ds-shadow-sm);
}

/* ---- row: one line of a list - time, avatar, two lines, pill, person ---- */
.ds-rows { display: flex; flex-direction: column; gap: var(--ds-space-1); margin: 0; padding: 0; list-style: none; }

.ds-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--ds-space-3) var(--ds-space-4);
  padding: var(--ds-space-3);
  border-radius: var(--ds-radius);
  color: var(--ds-text);
  text-decoration: none;
}

.ds-row:hover,
.ds-row.is-current { background: var(--ds-surface-sunken); }

a.ds-row:focus-visible { outline: none; box-shadow: var(--ds-focus-ring); }

.ds-row-time {
  flex: none;
  min-width: 3rem;
  font-size: var(--ds-caption);
  font-variant-numeric: tabular-nums;
  color: var(--ds-text-muted);
}

.ds-row-lead { flex: none; }
.ds-row-main { flex: 1 1 8rem; min-width: 0; }

.ds-row-title {
  display: block;
  font-size: var(--ds-small);
  font-weight: var(--ds-weight-semibold);
  color: var(--ds-text);
  overflow-wrap: anywhere;
}

.ds-row-sub {
  display: block;
  font-size: var(--ds-caption);
  color: var(--ds-text-muted);
  overflow-wrap: anywhere;
}

.ds-row-aside {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--ds-space-3);
}

.ds-row-status {
  font-family: var(--ds-font-display);
  font-style: italic;
  font-size: var(--ds-small);
  font-weight: var(--ds-weight-semibold);
}

.ds-row-status-danger { color: var(--ds-danger); }
.ds-row-status-warning { color: var(--ds-warning); }
.ds-row-status-success { color: var(--ds-success); }
.ds-row-status-muted { color: var(--ds-text-muted); }

.ds-person {
  display: inline-flex;
  align-items: center;
  gap: var(--ds-space-2);
  font-size: var(--ds-small);
  font-weight: var(--ds-weight-medium);
  color: var(--ds-text);
}

.ds-avatar-xs { width: 1.75rem; height: 1.75rem; font-size: var(--ds-caption); }

/* avatar tints, so a column of initials is not one flat colour. picked by
   the server from the name, never at random - the same person always gets
   the same tint on every page. */
.ds-avatar-t1 { background: color-mix(in srgb, var(--ds-chart-1) 16%, var(--ds-surface)); color: var(--ds-teal-600); }
.ds-avatar-t2 { background: color-mix(in srgb, var(--ds-chart-2) 20%, var(--ds-surface)); color: var(--ds-warning); }
.ds-avatar-t3 { background: color-mix(in srgb, var(--ds-chart-3) 16%, var(--ds-surface)); color: var(--ds-info); }
.ds-avatar-t4 { background: color-mix(in srgb, var(--ds-chart-4) 18%, var(--ds-surface)); color: var(--ds-neutral); }

/* ---- list card: card title + an "All" link at the right ---- */
.ds-card-link {
  font-size: var(--ds-small);
  font-weight: var(--ds-weight-semibold);
  color: var(--ds-primary);
  text-decoration: none;
}

.ds-card-link:hover { text-decoration: underline; }
.ds-card-link:focus-visible { outline: none; box-shadow: var(--ds-focus-ring); border-radius: var(--ds-radius-sm); }

.ds-card-sub { margin: var(--ds-space-1) 0 0; font-size: var(--ds-caption); color: var(--ds-text-muted); }

/* ---- distribution: one stacked bar and a dot legend ---- */
/* drawn as svg rects whose x/width the server computes - attributes, not an
   inline style, so the no-style= rule on staff pages still holds */
.ds-distbar { display: block; width: 100%; height: 0.625rem; border-radius: var(--ds-radius-pill); overflow: hidden; }
.ds-distbar rect { fill: var(--ds-surface-sunken); }
.ds-distbar .ds-seg-1 { fill: var(--ds-chart-1); }
.ds-distbar .ds-seg-2 { fill: var(--ds-chart-2); }
.ds-distbar .ds-seg-3 { fill: var(--ds-chart-3); }
.ds-distbar .ds-seg-4 { fill: var(--ds-chart-4); }
.ds-distbar .ds-seg-5 { fill: var(--ds-chart-5); }
.ds-distbar .ds-seg-6 { fill: var(--ds-border-strong); }

.ds-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ds-space-2) var(--ds-space-5);
  margin: var(--ds-space-4) 0 0;
  padding: 0;
  list-style: none;
  font-size: var(--ds-small);
  color: var(--ds-text);
}

.ds-legend li { display: inline-flex; align-items: center; gap: var(--ds-space-2); }
.ds-legend .ds-numeral { color: var(--ds-text); }
.ds-legend .ds-seg-1 { color: var(--ds-chart-1); }
.ds-legend .ds-seg-2 { color: var(--ds-chart-2); }
.ds-legend .ds-seg-3 { color: var(--ds-chart-3); }
.ds-legend .ds-seg-4 { color: var(--ds-chart-4); }
.ds-legend .ds-seg-5 { color: var(--ds-chart-5); }
.ds-legend .ds-seg-6 { color: var(--ds-border-strong); }

/* ---- pill nav: tabs whose active member is a filled pill ---- */
.ds-pill-nav { display: flex; flex-wrap: wrap; align-items: center; gap: var(--ds-space-1); }

.ds-pill-nav a,
.ds-pill-nav .nav-link {
  display: inline-flex;
  align-items: center;
  gap: var(--ds-space-2);
  padding: var(--ds-space-2) var(--ds-space-4);
  border-radius: var(--ds-radius);
  font-size: var(--ds-small);
  font-weight: var(--ds-weight-medium);
  color: var(--ds-text-muted);
  text-decoration: none;
  white-space: nowrap;
  transition: background-color var(--ds-duration-fast) var(--ds-ease),
              color var(--ds-duration-fast) var(--ds-ease);
}

.ds-pill-nav a:hover,
.ds-pill-nav .nav-link:hover { background: var(--ds-surface-sunken); color: var(--ds-text); }

.ds-pill-nav a:focus-visible,
.ds-pill-nav .nav-link:focus-visible { outline: none; box-shadow: var(--ds-focus-ring); }

.ds-pill-nav a.active,
.ds-pill-nav .nav-link.active {
  background: var(--ds-primary);
  color: var(--ds-text-on-dark);
  box-shadow: var(--ds-shadow-sm);
}

/* after .active, which is as specific: the current page's link keeps its ring */
.ds-pill-nav a.active:focus-visible,
.ds-pill-nav .nav-link.active:focus-visible { box-shadow: var(--ds-focus-ring); }
