/* Components: the one definition of each piece of the UI. Loaded last (after site.css). Same class names the pages already use, so no page
   needs to change; the template's own rules for these classes are overridden by listing every property here.
   Phase 2 of the UI overhaul; the showcase of every state is the development-only page /Dev/Ui. */

/* ---------- buttons ---------- */
.btn {
  --btn-bg: var(--bg-card);
  --btn-fg: var(--t-base);
  --btn-border: var(--border);
  --btn-hover-bg: var(--bg-hover);
  --btn-hover-border: var(--t-light);
  --btn-spinner: var(--t-base);

  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  position: relative;
  min-height: 38px; padding: 0 var(--space-4);
  border: 1px solid var(--btn-border); border-radius: var(--radius-pill);
  background: var(--btn-bg); color: var(--btn-fg);
  font-family: var(--font-ui); font-size: var(--text-sm); font-weight: 600; line-height: 1.2; letter-spacing: .005em;
  text-decoration: none; white-space: nowrap; cursor: pointer;
  box-shadow: none;
  transition: background-color .15s ease, border-color .15s ease, box-shadow .15s ease, color .15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--btn-hover-bg); border-color: var(--btn-hover-border); box-shadow: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; border-color: var(--primary); box-shadow: var(--focus-ring); }
.btn svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn:disabled:hover, .btn[aria-disabled="true"]:hover { background: var(--btn-bg); border-color: var(--btn-border); }

/* sizes */
.btn--sm { min-height: 30px; padding: 0 var(--space-3); font-size: 12.5px; gap: 6px; }
.btn--sm svg { width: 14px; height: 14px; }
.btn--lg { min-height: 46px; padding: 0 22px; font-size: var(--text-md); }

/* neutral: the default look, ghost and secondary are the same thing */
.btn--ghost, .btn--secondary { --btn-bg: var(--bg-card); --btn-border: var(--border); --btn-fg: var(--t-base); }

/* solid */
.btn--primary, .btn--success, .btn--danger, .btn--warning, .btn--info { --btn-fg: var(--on-fill); --btn-spinner: var(--on-fill); border-color: transparent; }
.btn--primary { --btn-bg: var(--primary); --btn-border: var(--primary); --btn-hover-bg: var(--primary-dark); --btn-hover-border: var(--primary-dark); }
.btn--success { --btn-bg: var(--success); --btn-border: var(--success); --btn-hover-bg: var(--success); --btn-hover-border: var(--success); }
.btn--danger { --btn-bg: var(--danger); --btn-border: var(--danger); --btn-hover-bg: var(--danger); --btn-hover-border: var(--danger); }
.btn--warning { --btn-bg: var(--warning); --btn-border: var(--warning); --btn-hover-bg: var(--warning); --btn-hover-border: var(--warning); }
.btn--info { --btn-bg: var(--info); --btn-border: var(--info); --btn-hover-bg: var(--info); --btn-hover-border: var(--info); }
.btn--success:hover, .btn--danger:hover, .btn--warning:hover, .btn--info:hover { filter: brightness(.93); }
:root[data-theme=dark] .btn--success:hover, :root[data-theme=dark] .btn--danger:hover, :root[data-theme=dark] .btn--warning:hover, :root[data-theme=dark] .btn--info:hover { filter: brightness(1.1); }
:root[data-theme=dark] .btn--primary:hover { --btn-hover-bg: var(--primary-light); --btn-hover-border: var(--primary-light); }

/* outline */
.btn--outline-primary, .btn--outline-success, .btn--outline-danger, .btn--warning-outline { --btn-bg: transparent; }
.btn--outline-primary { --btn-border: var(--primary); --btn-fg: var(--primary); --btn-hover-bg: var(--primary-soft); --btn-hover-border: var(--primary); --btn-spinner: var(--primary); }
.btn--outline-success { --btn-border: var(--success); --btn-fg: var(--success); --btn-hover-bg: var(--success-soft); --btn-hover-border: var(--success); --btn-spinner: var(--success); }
.btn--outline-danger { --btn-border: var(--danger); --btn-fg: var(--danger); --btn-hover-bg: var(--danger-soft); --btn-hover-border: var(--danger); --btn-spinner: var(--danger); }
.btn--warning-outline { --btn-border: var(--warning); --btn-fg: var(--warning); --btn-hover-bg: var(--warning-soft); --btn-hover-border: var(--warning); --btn-spinner: var(--warning); }

/* soft (tinted background, no border) */
.btn--soft-primary { --btn-bg: var(--primary-soft); --btn-fg: var(--primary); --btn-border: transparent; --btn-hover-bg: var(--primary-soft); --btn-hover-border: var(--primary); }
.btn--soft-success { --btn-bg: var(--success-soft); --btn-fg: var(--success); --btn-border: transparent; --btn-hover-bg: var(--success-soft); --btn-hover-border: var(--success); }
.btn--soft-danger { --btn-bg: var(--danger-soft); --btn-fg: var(--danger); --btn-border: transparent; --btn-hover-bg: var(--danger-soft); --btn-hover-border: var(--danger); }
.btn--soft-warning { --btn-bg: var(--warning-soft); --btn-fg: var(--warning); --btn-border: transparent; --btn-hover-bg: var(--warning-soft); --btn-hover-border: var(--warning); }
.btn--soft-info { --btn-bg: var(--info-soft); --btn-fg: var(--info); --btn-border: transparent; --btn-hover-bg: var(--info-soft); --btn-hover-border: var(--info); }

/* link-looking button */
.btn--link { --btn-bg: transparent; --btn-border: transparent; --btn-fg: var(--primary); --btn-hover-bg: transparent; --btn-hover-border: transparent; padding-left: 0; padding-right: 0; min-height: 0; }
.btn--link:hover { text-decoration: underline; }

/* icon only: always give it an aria-label */
.btn--icon { width: 38px; padding: 0; }
.btn--icon.btn--sm { width: 30px; }

/* loading: the label is hidden, a spinner shows, clicks are ignored. Set the class (and aria-busy="true") while the request runs. */
.btn.is-loading { color: transparent; pointer-events: none; }
.btn.is-loading > * { visibility: hidden; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--btn-spinner); border-right-color: transparent;
  animation: btn-spin .7s linear infinite;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }

/* a button next to a select in a form lines up with the buttons of the other forms in the same row (an older rule pinned it to the top) */
.inline-form > .btn, .row-actions .btn { align-self: center; }

/* touch screens: bigger targets */
@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .btn--sm { min-height: 40px; }
  .btn--icon { width: 44px; }
}

/* ---------- tags (status chips) ---------- */
.tag {
  --tag-bg: var(--bg-muted);
  --tag-fg: var(--t-muted);
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 22px; padding: 2px 10px;
  border-radius: var(--radius-pill);
  background: var(--tag-bg); color: var(--tag-fg);
  font-family: var(--font-ui); font-size: 12px; font-weight: 600; line-height: 1.2; letter-spacing: .01em;
  white-space: nowrap;
}
.tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.tag--plain::before { display: none; }
/* strong tags: a solid colour with the fill text colour (white on light, dark on the bright dark-mode colours) */
.tag--sm { min-height: 18px; padding: 1px 8px; font-size: 11px; }
.tag.t-active, .tag--success { --tag-bg: var(--success); --tag-fg: var(--on-fill); }
.tag.t-old, .tag--warning { --tag-bg: var(--warning); --tag-fg: var(--on-fill); }
.tag.t-unavail, .tag--danger { --tag-bg: var(--danger); --tag-fg: var(--on-fill); }
.tag.t-info, .tag--info { --tag-bg: var(--info); --tag-fg: var(--on-fill); }
.tag.t-new, .tag--purple { --tag-bg: var(--purple); --tag-fg: var(--on-fill); }
.tag.t-used, .tag--orange { --tag-bg: var(--orange); --tag-fg: var(--on-fill); }
.tag.t-muted, .tag--neutral { --tag-bg: var(--bg-muted); --tag-fg: var(--t-muted); }
.tag--primary { --tag-bg: var(--primary); --tag-fg: var(--on-fill); }

/* ---------- form fields ---------- */
.field { gap: 6px; }
.field-label { font-size: var(--text-sm); font-weight: 600; color: var(--t-base); letter-spacing: 0; }
.field-label .req { color: var(--danger); }
.field-help { font-size: 12.5px; line-height: 1.45; color: var(--t-muted); }
.field-error { font-size: 12.5px; font-weight: 500; color: var(--danger); gap: 4px; }

.input, .select, .textarea {
  min-height: 40px; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background-color: var(--bg-card); color: var(--t-base);
  font-family: var(--font-ui); font-size: var(--text-md); line-height: 1.35;
  transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}
.input::placeholder, .textarea::placeholder { color: var(--t-light); opacity: 1; }
.input:hover:not(:disabled):not(:focus), .select:hover:not(:disabled):not(:focus), .textarea:hover:not(:disabled):not(:focus) { border-color: var(--t-light); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus-ring); }
.input:disabled, .select:disabled, .textarea:disabled { background-color: var(--bg-muted); color: var(--t-muted); cursor: not-allowed; opacity: .8; }
.input[readonly], .textarea[readonly] { background-color: var(--bg-muted); }
.input.is-invalid, .select.is-invalid, .textarea.is-invalid, .input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] {
  border-color: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 18%, transparent);
}
.input-group .addon { font-family: var(--font-ui); }

/* file inputs: the browser button is restyled (no script needed) */
input[type="file"].input { padding: 6px 8px; min-height: 40px; color: var(--t-muted); cursor: pointer; }
input[type="file"]::file-selector-button {
  margin-right: var(--space-3); padding: 6px 14px;
  border: 1px solid var(--primary); border-radius: var(--radius-pill);
  background: var(--primary-soft); color: var(--primary);
  font-family: var(--font-ui); font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: background-color .15s ease;
}
input[type="file"]::file-selector-button:hover { background: var(--bg-hover); }

/* drop zone: forms.js wraps a file input that has data-dropzone; the transparent input covers the zone, so a click or a dropped file works natively */
.dropzone {
  position: relative; display: flex; align-items: center; gap: var(--space-3);
  min-height: 72px; padding: var(--space-3) var(--space-4);
  border: 1.5px dashed var(--border); border-radius: var(--radius-md);
  background: var(--bg-muted); color: var(--t-muted);
  transition: border-color .15s ease, background-color .15s ease, box-shadow .15s ease;
}
.dropzone:hover, .dropzone.is-dragover { border-color: var(--primary); background: var(--primary-soft); }
.dropzone:focus-within { border-color: var(--primary); box-shadow: var(--focus-ring); }
.dropzone.has-file { border-style: solid; background: var(--primary-soft); color: var(--t-base); }
.dropzone.is-invalid { border-color: var(--danger); }
.dropzone { flex-wrap: wrap; }
.dropzone > .field-error { flex: 1 0 100%; }
.dropzone-input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.dropzone-icon { flex: none; width: 28px; height: 28px; color: var(--primary); }
.dropzone-icon svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.dropzone-text { min-width: 0; display: grid; gap: 2px; font-size: var(--text-sm); }
.dropzone-text strong { color: var(--t-base); font-weight: 600; overflow-wrap: anywhere; }
.dropzone-hint { font-size: 12px; color: var(--t-muted); }

/* ---------- checkbox, radio, switch ---------- */
.check { font-size: var(--text-sm); gap: var(--space-2); position: relative; }
.check .box { width: 18px; height: 18px; border: 1.5px solid var(--t-light); border-radius: 5px; background: var(--bg-card); }
.check:hover input:not(:disabled) + .box { border-color: var(--primary); }
.check input:checked + .box { background: var(--primary); border-color: var(--primary); }
.check input:checked + .box::after { border-color: var(--on-fill); }
.check.radio input:checked + .box::after { background: var(--on-fill); }
/* the real input is hidden, so the keyboard focus ring goes on the box */
.check input:focus-visible + .box { box-shadow: var(--focus-ring); border-color: var(--primary); }

.switch { display: inline-flex; align-items: center; gap: var(--space-3); cursor: pointer; font-size: var(--text-sm); position: relative; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { flex: none; width: 40px; height: 22px; border-radius: var(--radius-pill); background: var(--t-light); position: relative; transition: background-color .15s ease; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--bg-card); box-shadow: var(--shadow-sm); transition: transform .15s ease; }
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(18px); background: var(--on-fill); }
.switch input:focus-visible + .track { box-shadow: var(--focus-ring); }
.switch input:disabled + .track { opacity: .5; cursor: not-allowed; }

/* ---------- cards and KPI tiles: calmer ---------- */
/* flat surfaces, one border, a light shadow; no tinted corner glow, no hover lift, no entrance animation (the live dashboard swaps tiles in place,
   and an animation replayed on every refresh is noise) */
.card, .kpi-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); animation: none;
}
.kpi-card { padding: var(--space-5); gap: var(--space-3); transition: none; }
.kpi-card::before { display: none; }
.kpi-card:hover { transform: none; box-shadow: var(--shadow-sm); }
.kpi-label { font-size: var(--text-sm); font-weight: 600; color: var(--t-muted); }
.kpi-value { font-family: var(--font-display) !important; font-size: var(--text-3xl); font-weight: 700; letter-spacing: -.02em; line-height: 1.05; color: var(--t-base); }
.kpi-grid--compact .kpi-value { font-size: var(--text-2xl); }
.kpi-icon { width: 30px; height: 30px; border-radius: var(--radius-sm); }
.kpi-compare { border-top: 1px solid var(--border-soft); color: var(--t-muted); }

.card-head { border-bottom: 1px solid var(--border-soft); margin-bottom: var(--space-5); padding-bottom: var(--space-4); }
.card-title { font-size: var(--text-lg); font-weight: 600; letter-spacing: -.01em; }
.eyebrow { font-size: 11.5px; font-weight: 600; letter-spacing: .08em; color: var(--t-muted); }
.hero-text .eyebrow { display: none; } /* the breadcrumb in the top bar already names the section */

/* ---------- page header ---------- */
.hero { margin-bottom: var(--space-6); animation: none; }
.hero-title { font-size: clamp(26px, 2.8vw, 32px); margin-bottom: var(--space-2); }
.hero-sub { font-size: var(--text-md); color: var(--t-muted); }
.d-topbar { height: 56px; }

/* ---------- segmented control (the time-range tabs) ---------- */
.range-tabs { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--border); border-radius: var(--radius-pill); background: var(--bg-muted); }
.range-tabs a { padding: 6px 14px; border-radius: var(--radius-pill); font-size: var(--text-sm); font-weight: 600; color: var(--t-muted); transition: background-color .15s ease, color .15s ease; }
.range-tabs a:hover { background: var(--bg-hover); color: var(--t-base); }
.range-tabs a.is-active, .range-tabs a[aria-current="page"] { background: var(--primary); color: var(--on-fill); }
.range-tabs a:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* ---------- tables ---------- */
/* one definition (the template's and the older overrides' rules for the table parts are overridden here): a plain header with a rule under it,
   no zebra, a soft hover row, right-aligned tabular numbers, the first column pinned while a wide table scrolls sideways */
.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table thead th {
  padding: 10px var(--space-4); border-bottom: 1px solid var(--border); border-radius: 0;
  background: transparent; color: var(--t-muted);
  font-family: var(--font-ui); font-size: 11.5px; font-weight: 600; letter-spacing: .06em; line-height: 1.3; text-align: left; text-transform: uppercase;
  white-space: nowrap; vertical-align: bottom;
}
.table tbody td { padding: 12px var(--space-4); border-bottom: 1px solid var(--border-soft); font-size: var(--text-md); line-height: 1.45; background: transparent; }
.table tbody tr:nth-child(even) td { background: transparent; }
.table tbody tr:hover td { background: var(--bg-hover); }
.table tbody tr.is-selected td { background: var(--primary-soft); }
.table tbody tr:last-child td { border-bottom: 0; }
.table th:last-child, .table td:last-child { padding-right: var(--space-4); }
.table td.num, .table th.num { text-align: left; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table td.is-zero { color: var(--t-muted); }
.table--compact tbody td { padding: 7px var(--space-3); }
.table--compact thead th { padding: 8px var(--space-3); }

/* wide tables scroll sideways inside .table-scroll; the first column (the text that names the row) stays in view */
.table-scroll { padding-bottom: 4px; }
.table-scroll:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: var(--radius-sm); }
.table-scroll > .table thead th:first-child, .table-scroll > .table tbody td:first-child { position: sticky; left: 0; z-index: 1; background: var(--bg-card); }
.table-scroll > .table thead th:first-child { z-index: 3; }
.table-scroll > .table tbody tr:hover td:first-child { background: var(--bg-hover); }
.table-scroll > .table tbody tr.is-selected td:first-child { background: var(--primary-soft); }
.table-scroll > .table tbody td:first-child { min-width: 150px; max-width: 280px; }
.table-scroll > .table tbody td:first-child:not([colspan]) { box-shadow: 1px 0 0 var(--border-soft); }
.table-scroll > .table tbody td[colspan] { position: static; box-shadow: none; max-width: none; }

/* a long table (100 rows): the header stays at the top of the scrolling area. Put .table-scroll--tall on the container and .table--sticky on the table. */
.table-scroll--tall { max-height: 70vh; overflow: auto; }
.table--sticky thead th { position: sticky; top: 0; z-index: 4; background: var(--bg-card); }
.table--sticky thead th:first-child { z-index: 5; }

/* sortable headers (tables.js turns the text of a th into a button when the table has data-sortable) */
.th-sort { display: inline-flex; align-items: center; gap: 6px; padding: 0; border: 0; background: none; color: inherit; font: inherit; letter-spacing: inherit; text-transform: inherit; cursor: pointer; }
.th-sort:hover { color: var(--t-base); }
.th-sort:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; border-radius: 4px; }
.th-sort::after { content: "\2195"; font-size: 12px; opacity: .5; }
th[aria-sort="ascending"] .th-sort::after { content: "\25B2"; opacity: 1; font-size: 9px; }
th[aria-sort="descending"] .th-sort::after { content: "\25BC"; opacity: 1; font-size: 9px; }
th[aria-sort] .th-sort { color: var(--t-base); }

/* pager: a disabled arrow is only a picture */
.pager-btn.is-disabled { opacity: .4; cursor: default; }

/* ---------- the /Dev/Ui showcase page ---------- */
.demo-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); padding: var(--space-2) 0 var(--space-4); }
.demo-label { margin: var(--space-3) 0 0; font-size: var(--text-sm); font-weight: 600; color: var(--t-muted); }
.demo-note { text-align: left !important; padding: 0 !important; }

/* forced colours (Windows high contrast) drops shadows, so the focus ring is drawn as an outline in the system highlight colour */
@media (forced-colors: active) {
  .btn:focus-visible, .range-tabs a:focus-visible, .check input:focus-visible + .box, .switch input:focus-visible + .track,
  .dropzone:focus-within, .input:focus, .select:focus, .textarea:focus { outline: 2px solid Highlight; outline-offset: 2px; }
}
