/* ============================================================
   Components — buttons, status, panels, fields, tables

   Every interactive element ships default, hover, focus-visible,
   active and disabled. Hover is gated behind devices that have
   one.
   ============================================================ */

/* ============================================================
   Buttons

   Heights are this product's floors, not a desk tool's density:
   48px for a primary action, 44px for anything else that matters.
   ============================================================ */
.btn {
  min-height: var(--ctl-lg);
  padding: 0 var(--s4);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface-raised);
  color: var(--ink);
  font-size: var(--t-base);
  font-weight: var(--fw-semibold);
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background var(--t-fast) var(--ease-out),
    border-color var(--t-fast) var(--ease-out),
    color var(--t-fast) var(--ease-out),
    transform var(--t-fast) var(--ease-out);
}

a.btn { text-decoration: none; }
.btn:active { transform: scale(0.98); }

/* Primary is graphite. There is no hue on any control in this
   product, so a saturated thing on screen is always a status. */
.btn-primary {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
  color: var(--accent-ink);
  box-shadow: var(--shadow-xs);
}
a.btn-primary { color: var(--accent-ink); }

/* Quiet, but still unmistakably a control. Without the underline
   it reads as a label and nobody presses it. */
.btn-quiet {
  border-color: transparent;
  background: transparent;
  color: var(--ink-soft);
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 3px;
}

.btn-danger {
  border-color: var(--danger-line);
  background: var(--danger-soft);
  color: var(--danger-ink);
}

.btn-sm { min-height: var(--ctl-sm); padding: 0 var(--s3); font-size: var(--t-sm); }
.btn-block { width: 100%; }

.btn[disabled] {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink-muted);
  box-shadow: none;
  cursor: not-allowed;
}
.btn[disabled]:active { transform: none; }

@media (hover: hover) and (pointer: fine) {
  .btn:hover:not([disabled]) { background: var(--surface-hover); border-color: var(--ink-faint); }
  .btn-primary:hover:not([disabled]) { background: var(--accent); border-color: var(--accent); }
  .btn-quiet:hover:not([disabled]) { background: var(--surface); color: var(--ink); }
  .btn-danger:hover:not([disabled]) { background: var(--danger); color: oklch(98% 0.02 28); border-color: var(--danger); }
}

/* ============================================================
   Status

   A dot plus a word. Agents see three, operations sees the full
   set. These are the only saturated things in the interface.
   ============================================================ */
.chip {
  min-height: 26px;
  padding: 3px 9px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  font-size: var(--t-xs);
  font-weight: var(--fw-semibold);
  line-height: 1;
  white-space: nowrap;
}

.chip::before {
  content: "";
  width: 6px;
  height: 6px;
  flex: none;
  border-radius: 50%;
  background: currentColor;
}

.chip-open      { background: var(--neutral-soft);   color: var(--neutral-ink);   border-color: var(--neutral-line); }
.chip-requested { background: var(--attention-soft); color: var(--attention-ink); border-color: var(--attention-line); }
.chip-confirmed { background: var(--positive-soft);  color: var(--positive-ink);  border-color: var(--positive-line); }
.chip-info      { background: var(--info-soft);      color: var(--info-ink);      border-color: var(--info-line); }
.chip-stop      { background: var(--danger-soft);    color: var(--danger-ink);    border-color: var(--danger-line); }
.chip-done      { background: var(--surface);        color: var(--ink-muted);     border-color: var(--line); }

/* A bare state dot, for rows that carry their own words. */
.flagdot {
  width: 7px;
  height: 7px;
  flex: none;
  display: inline-block;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--attention);
  vertical-align: middle;
}

/* ============================================================
   Panel — the one container. Nothing nests inside another panel.
   ============================================================ */
.panel {
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.panel-head {
  padding: 13px var(--s4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  min-height: 52px;
  border-bottom: 1px solid var(--line-soft);
}

.panel-title {
  font-size: var(--t-md);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--track-tight);
}

.panel-note {
  font-size: var(--t-sm);
  font-weight: var(--fw-medium);
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.panel-body { padding: var(--s4); }
.panel-body-flush { padding: 0; }

/* ============================================================
   Avatar
   ============================================================ */
.avatar {
  width: 32px;
  height: 32px;
  flex: none;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--ink);
  font-size: var(--t-xs);
  font-weight: var(--fw-bold);
  letter-spacing: 0.01em;
  line-height: 1;
}

.avatar.xl { width: 64px; height: 64px; font-size: var(--t-lg); }
.avatar.ondark { background: var(--shell-raised); color: var(--shell-ink); }

/* ============================================================
   Fields
   ============================================================ */
textarea,
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="date"],
.field-input {
  width: 100%;
  min-height: var(--ctl-lg);
  padding: 11px var(--s3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface-raised);
  color: var(--ink);
  /* Never below 16px: anything smaller makes iOS zoom the page on
     focus, which throws the layout mid-task. */
  font-size: max(1rem, var(--t-base));
  outline: none;
  transition:
    border-color var(--t-fast) var(--ease-out),
    box-shadow var(--t-fast) var(--ease-out);
}

textarea { resize: vertical; line-height: 1.45; }

textarea:focus,
input[type="text"]:focus,
input[type="email"]:focus,
input[type="tel"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="search"]:focus,
input[type="date"]:focus,
.field-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: var(--t-sm);
  font-weight: var(--fw-semibold);
  color: var(--ink-soft);
}

/* ============================================================
   Segmented control

   The indicator slides: the index is a custom property, so
   movement is one transform and nothing in the row reflows.
   ============================================================ */
.seg {
  position: relative;
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface-sunken);
  max-width: 100%;
}

.seg::before {
  content: "";
  position: absolute;
  z-index: 0;
  inset: 3px auto 3px 3px;
  width: calc((100% - 6px - (var(--seg-n) - 1) * 2px) / var(--seg-n));
  border-radius: var(--r-sm);
  background: var(--surface-raised);
  box-shadow: var(--shadow-xs);
  transform: translateX(calc(var(--seg-i) * (100% + 2px)));
  transition: transform var(--t-mid) var(--ease-out);
}

.seg button {
  position: relative;
  z-index: 1;
  min-height: var(--ctl-md);
  padding: 0 var(--s4);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-muted);
  font-size: var(--t-base);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
  transition: color var(--t-fast) var(--ease-out);
}

.seg button[aria-pressed="true"] { color: var(--ink); }

@media (hover: hover) and (pointer: fine) {
  .seg button:hover { color: var(--ink-soft); }
}

/* ============================================================
   Filter pill — a count you can press
   ============================================================ */
.pill {
  min-height: var(--ctl-md);
  padding: 0 var(--s4);
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  background: var(--surface-raised);
  color: var(--ink-soft);
  font-size: var(--t-base);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
  transition:
    background var(--t-fast) var(--ease-out),
    border-color var(--t-fast) var(--ease-out),
    color var(--t-fast) var(--ease-out);
}

.pill .n {
  font-variant-numeric: tabular-nums;
  color: var(--ink-muted);
  font-weight: var(--fw-bold);
}

.pill[aria-pressed="true"] {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
  color: var(--accent-ink);
}
.pill[aria-pressed="true"] .n { color: var(--accent-ink); }

.pill[data-k="problem"] .n { color: var(--danger-ink); }
.pill[data-k="wait"] .n { color: var(--attention-ink); }
.pill[aria-pressed="true"][data-k="problem"] .n,
.pill[aria-pressed="true"][data-k="wait"] .n { color: var(--accent-ink); }

@media (hover: hover) and (pointer: fine) {
  .pill:hover { background: var(--surface-hover); border-color: var(--ink-faint); }
  .pill[aria-pressed="true"]:hover { background: var(--accent); border-color: var(--accent); }
}

/* ============================================================
   Meter

   Sits inline with the sentence it measures. It never becomes a
   hero number.
   ============================================================ */
.meter {
  display: flex;
  align-items: center;
  gap: var(--s3);
  margin: var(--s3) 0;
}

.meter-track {
  flex: 1;
  height: 8px;
  min-width: 80px;
  border-radius: var(--r-pill);
  background: var(--surface-sunken);
  border: 1px solid var(--line-soft);
  overflow: hidden;
}

.meter-fill {
  display: block;
  height: 100%;
  border-radius: var(--r-pill);
  background: var(--positive);
  transform-origin: left;
  transition: transform var(--t-slow) var(--ease-out);
}

.meter-say {
  flex: none;
  font-size: var(--t-sm);
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   Checklist
   ============================================================ */
.check { display: flex; flex-direction: column; }

.check label {
  min-height: var(--ctl-md);
  padding: 11px 0;
  display: flex;
  align-items: center;
  gap: var(--s3);
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
}

.check label:last-child { border-bottom: 0; }

.check input[type="checkbox"] {
  width: 22px;
  height: 22px;
  flex: none;
  accent-color: var(--accent-strong);
  cursor: pointer;
}

.check .lb { flex: 1; min-width: 0; font-size: var(--t-base); color: var(--ink-soft); }
.check input:checked + .lb { color: var(--ink-muted); text-decoration: line-through; }

.check .note {
  flex: none;
  font-size: var(--t-micro);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--track-over);
  text-transform: uppercase;
  color: var(--ink-muted);
}

/* ============================================================
   Facts — a definition list read as a row of columns
   ============================================================ */
.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: var(--s3) var(--s4);
  padding-top: var(--s4);
  border-top: 1px solid var(--line-soft);
}

.facts dt {
  font-size: var(--t-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--ink-muted);
}

.facts dd {
  margin: 3px 0 0;
  font-size: var(--t-md);
  font-weight: var(--fw-semibold);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   Data table — operations is a desk tool and may be dense
   ============================================================ */
.tablewrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  background: var(--surface-raised);
  box-shadow: var(--shadow-sm);
}

.ops { font-size: var(--t-base); border-collapse: separate; border-spacing: 0; }

.ops thead th {
  padding: 11px var(--s4);
  background: var(--surface-sunken);
  border-bottom: 1px solid var(--line);
  font-size: var(--t-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--ink-muted);
  white-space: nowrap;
}

.ops tbody td {
  padding: 12px var(--s4);
  border-bottom: 1px solid var(--line-soft);
  color: var(--ink-soft);
  vertical-align: middle;
}

.ops tbody tr:last-child td { border-bottom: 0; }
.ops .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ops .p { font-weight: var(--fw-semibold); color: var(--ink); }
.ops .q { font-size: var(--t-sm); color: var(--ink-muted); }

/* ============================================================
   Empty states — teach the surface rather than announce emptiness
   ============================================================ */
.empty {
  padding: var(--s7) var(--s5);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
}

.empty .t { font-size: var(--t-md); font-weight: var(--fw-semibold); color: var(--ink); }
.empty .d { font-size: var(--t-base); color: var(--ink-muted); max-width: 44ch; }

.blank-mid {
  padding: var(--s8) var(--s5);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.blank-mark {
  width: 52px;
  height: 52px;
  margin-bottom: var(--s4);
  display: grid;
  place-items: center;
  border-radius: var(--r-xl);
  background: var(--positive-soft);
  color: var(--positive-ink);
  animation: pop-in var(--t-slow) var(--ease-out);
}

.blank-mark svg { width: 26px; height: 26px; }
.blank-mark.is-quiet { background: var(--surface); color: var(--ink-muted); }

.blank-t { font-size: var(--t-lg); font-weight: var(--fw-semibold); color: var(--ink); }
.blank-d { margin-top: 6px; font-size: var(--t-base); color: var(--ink-muted); max-width: 46ch; }

/* ============================================================
   Toast
   ============================================================ */
.toast {
  position: fixed;
  z-index: var(--z-toast);
  left: var(--s4);
  right: var(--s4);
  bottom: calc(var(--tabbar-h) + var(--s4) + env(safe-area-inset-bottom));
  max-width: 420px;
  margin: 0 auto;
  padding: 13px var(--s4);
  border: 1px solid var(--shell-line);
  border-radius: var(--r-xl);
  background: var(--shell);
  color: var(--shell-ink);
  font-size: var(--t-base);
  font-weight: var(--fw-medium);
  box-shadow: var(--shadow-rail);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition:
    opacity var(--t-mid) var(--ease-out),
    transform var(--t-mid) var(--ease-out);
}

.toast[data-show="true"] { opacity: 1; transform: translateY(0); }

/* ============================================================
   Disclosure — a panel that opens in place, never a modal
   ============================================================ */
.disclose { display: grid; grid-template-rows: 0fr; transition: grid-template-rows var(--t-slow) var(--ease-out); }
.disclose[data-open="true"] { grid-template-rows: 1fr; }
.disclose > div { overflow: hidden; }

/* ============================================================
   Skip link
   ============================================================ */
.skiplink {
  position: absolute;
  left: var(--s3);
  top: -80px;
  z-index: var(--z-toast);
  min-height: var(--ctl-md);
  padding: 11px var(--s4);
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--accent-line);
  border-radius: var(--r-md);
  background: var(--surface-raised);
  color: var(--ink);
  font-size: var(--t-base);
  font-weight: var(--fw-semibold);
  box-shadow: var(--shadow-md);
  transition: top var(--t-fast) var(--ease-out);
}

.skiplink:focus-visible { top: var(--s3); }
