/* ==========================================================================
   MARQUEE — Components
   Every interactive component ships default / hover / focus / active /
   disabled / loading / error. Hover is gated behind a fine pointer.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Icons
   -------------------------------------------------------------------------- */
.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-xs { width: 14px; height: 14px; stroke-width: 1.7; }
.icon-sm { width: 16px; height: 16px; stroke-width: 1.6; }
.icon-lg { width: 22px; height: 22px; stroke-width: 1.45; }
.icon-xl { width: 28px; height: 28px; stroke-width: 1.35; }
.icon-2xl { width: 40px; height: 40px; stroke-width: 1.2; }
.icon-fill { fill: currentColor; stroke: none; }

/* --------------------------------------------------------------------------
   Brand lockup
   -------------------------------------------------------------------------- */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: inherit;
}
.brand-mark { width: 27px; height: 27px; border-radius: 6.5px; flex-shrink: 0; }
.brand-mark-lg { width: 34px; height: 34px; border-radius: 8px; }
.brand-word {
  font-family: var(--font-display);
  font-stretch: 112%;
  font-weight: var(--fw-bold);
  font-size: 1.06rem;
  letter-spacing: -0.021em;
  line-height: 1;
}
.brand-word-lg { font-size: 1.32rem; }

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  --btn-h: 36px;
  --btn-px: var(--s-4);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: var(--btn-h);
  padding: 0 var(--btn-px);
  border-radius: var(--r-md);
  border: 1px solid transparent;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semi);
  letter-spacing: -0.004em;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  position: relative;
  transition: background-color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out),
              transform var(--dur-press) var(--ease-out);
}
.btn:active { transform: scale(0.97); }
.btn .icon { width: 16px; height: 16px; }

.btn-xs { --btn-h: 26px; --btn-px: var(--s-2); font-size: var(--fs-2xs); border-radius: var(--r-sm); }
.btn-sm { --btn-h: 31px; --btn-px: var(--s-3); font-size: var(--fs-xs); }
.btn-lg { --btn-h: 44px; --btn-px: var(--s-6); font-size: var(--fs-md); border-radius: var(--r-lg); }
.btn-xl { --btn-h: 52px; --btn-px: var(--s-7); font-size: var(--fs-md); border-radius: var(--r-lg); }

.btn-icon { --btn-px: 0; width: var(--btn-h); }
.btn-block { width: 100%; }

/* Primary — white text on saturated ember (5.3:1) */
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:disabled { background: var(--surface-3); color: var(--muted); }

/* Default — the workhorse */
.btn-default {
  background: var(--bg);
  color: var(--ink);
  border-color: var(--line-strong);
  box-shadow: var(--shadow-xs);
}

/* Soft — tinted brand, for secondary actions inside brand context */
.btn-soft { background: var(--primary-soft); color: var(--primary-press); border-color: var(--primary-line); }

/* Ghost — toolbars, table row actions */
.btn-ghost { background: transparent; color: var(--ink-2); }

/* Danger */
.btn-danger { background: var(--danger); color: var(--on-primary); }
.btn-danger-ghost { background: transparent; color: var(--danger); }

/* Chrome-context buttons (dark sidebar / topbar) */
.btn-chrome { background: var(--chrome-2); color: var(--chrome-ink); border-color: var(--chrome-line); }

@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
  .btn-default:hover:not(:disabled) { background: var(--surface); border-color: var(--muted); }
  .btn-soft:hover:not(:disabled) { background: var(--primary-soft-2); }
  .btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
  .btn-danger:hover:not(:disabled) { background: oklch(0.435 0.190 18); }
  .btn-danger-ghost:hover:not(:disabled) { background: var(--danger-soft); }
  .btn-chrome:hover:not(:disabled) { background: var(--chrome-3); }
}

.btn:disabled,
.btn[aria-disabled='true'] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Loading — label hides, spinner takes its place, width does not jump */
.btn[data-loading='true'] { pointer-events: none; color: transparent; }
.btn[data-loading='true']::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 15px; height: 15px;
  border: 2px solid currentColor;
  border-radius: 50%;
  border-top-color: transparent;
  color: var(--on-primary);
  animation: spin 620ms linear infinite;
}
.btn-default[data-loading='true']::after,
.btn-ghost[data-loading='true']::after,
.btn-soft[data-loading='true']::after { color: var(--ink-2); }

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

/* Coarse pointers get real touch targets */
@media (pointer: coarse) {
  .btn { --btn-h: 44px; }
  .btn-xs { --btn-h: 36px; }
  .btn-sm { --btn-h: 40px; }
}

/* --------------------------------------------------------------------------
   Keyboard hint
   -------------------------------------------------------------------------- */
.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: var(--r-xs);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  background: var(--bg);
  font-family: var(--font-ui);
  font-size: var(--fs-3xs);
  font-weight: var(--fw-semi);
  color: var(--muted);
  line-height: 1;
}
.chrome .kbd { background: var(--chrome-2); border-color: var(--chrome-line); color: var(--chrome-muted); }

/* --------------------------------------------------------------------------
   Form controls
   -------------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; }

.field-label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semi);
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: var(--s-2);
}
.field-label .req { color: var(--danger); font-weight: var(--fw-regular); }

.field-hint { font-size: var(--fs-2xs); color: var(--muted); }

.field-error {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: var(--fs-2xs);
  font-weight: var(--fw-medium);
  color: var(--danger);
}
.field-error .icon { width: 13px; height: 13px; }

.input,
.textarea,
.select {
  width: 100%;
  min-height: 36px;
  padding: 7px var(--s-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--bg);
  color: var(--ink);
  font-size: var(--fs-sm);
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out),
              background-color var(--dur-fast) var(--ease-out);
}
.textarea { min-height: 92px; resize: vertical; line-height: var(--lh-normal); padding-top: var(--s-2); }

.input::placeholder,
.textarea::placeholder { color: var(--muted); }  /* 4.9:1 — not the usual unreadable grey */

.input:hover:not(:disabled),
.textarea:hover:not(:disabled),
.select:hover:not(:disabled) { border-color: var(--muted); }

.input:focus-visible,
.textarea:focus-visible,
.select:focus-visible {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft-2);
  z-index: auto;
}

.input:disabled, .textarea:disabled, .select:disabled {
  background: var(--surface-2);
  color: var(--muted);
  cursor: not-allowed;
}

.input[aria-invalid='true'],
.textarea[aria-invalid='true'] { border-color: var(--danger); }
.input[aria-invalid='true']:focus-visible { box-shadow: 0 0 0 3px var(--danger-soft); }

.select {
  appearance: none;
  padding-right: var(--s-8);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23807672' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6.4 9.4 5.6 5.6 5.6-5.6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--s-3) center;
  background-size: 15px;
  cursor: pointer;
}

/* Input with a leading icon */
.input-wrap { position: relative; display: flex; align-items: center; width: 100%; }
.input-wrap > .icon {
  position: absolute;
  left: var(--s-3);
  color: var(--muted);
  pointer-events: none;
  width: 16px; height: 16px;
}
.input-wrap > .input { padding-left: 34px; }
.input-wrap > .input-suffix {
  position: absolute;
  right: var(--s-3);
  font-size: var(--fs-2xs);
  color: var(--muted);
  pointer-events: none;
}

/* Currency / unit prefix */
.input-affix {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--bg);
  overflow: hidden;
}
.input-affix:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft-2); }
.input-affix .affix {
  display: flex;
  align-items: center;
  padding: 0 var(--s-3);
  background: var(--surface-2);
  border-right: 1px solid var(--line);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  color: var(--ink-2);
}
.input-affix .affix-end { border-right: 0; border-left: 1px solid var(--line); }
.input-affix .input { border: 0; border-radius: 0; }
.input-affix .input:focus-visible { box-shadow: none; }

/* Checkbox & radio */
.check {
  display: inline-flex;
  align-items: flex-start;
  gap: var(--s-3);
  cursor: pointer;
  font-size: var(--fs-sm);
  min-height: 22px;
}
.check input { position: absolute; opacity: 0; width: 0; height: 0; }
.check-box {
  width: 17px; height: 17px;
  margin-top: 2px;
  flex-shrink: 0;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-xs);
  background: var(--bg);
  display: grid;
  place-items: center;
  transition: background-color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out);
}
.check-radio { border-radius: 50%; }
.check-box::after {
  content: '';
  width: 9px; height: 9px;
  transform: scale(0.6);
  opacity: 0;
  background: var(--on-primary);
  clip-path: polygon(14% 47%, 0 61%, 39% 100%, 100% 22%, 86% 8%, 38% 71%);
  transition: opacity var(--dur-press) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.check-radio::after { clip-path: none; border-radius: 50%; width: 7px; height: 7px; }
.check input:checked + .check-box { background: var(--primary); border-color: var(--primary); }
.check input:checked + .check-box::after { opacity: 1; transform: scale(1); }
.check input:focus-visible + .check-box { box-shadow: var(--focus-ring); }
.check input:disabled + .check-box { background: var(--surface-2); border-color: var(--line); }
.check input:disabled ~ .check-text { color: var(--muted); }
@media (hover: hover) and (pointer: fine) {
  .check:hover .check-box { border-color: var(--muted); }
  .check:hover input:checked + .check-box { border-color: var(--primary); }
}

/* Switch */
.switch { display: inline-flex; align-items: center; gap: var(--s-3); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 34px; height: 20px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  padding: 2px;
  flex-shrink: 0;
  transition: background-color var(--dur) var(--ease-out), border-color var(--dur) var(--ease-out);
}
.switch-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: var(--shadow-xs);
  transition: transform var(--dur) var(--ease-out);
}
.switch input:checked + .switch-track { background: var(--primary); border-color: var(--primary); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(14px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--focus-ring); }
.switch input:disabled + .switch-track { opacity: 0.5; }

/* Segmented control */
.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.segmented button {
  padding: 5px var(--s-4);
  border-radius: var(--r-sm);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semi);
  color: var(--ink-2);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out),
              transform var(--dur-press) var(--ease-out);
}
.segmented button:active { transform: scale(0.97); }
.segmented button[aria-selected='true'] {
  background: var(--bg);
  color: var(--ink);
  box-shadow: var(--shadow-xs);
}
@media (hover: hover) and (pointer: fine) {
  .segmented button:not([aria-selected='true']):hover { color: var(--ink); }
}

/* Filter chip */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 10px;
  border-radius: var(--r-full);
  border: 1px solid var(--line-strong);
  background: var(--bg);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-medium);
  color: var(--ink-2);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              transform var(--dur-press) var(--ease-out);
}
.chip:active { transform: scale(0.96); }
.chip[aria-pressed='true'] {
  background: var(--primary-soft);
  border-color: var(--primary-line);
  color: var(--primary-press);
}
@media (hover: hover) and (pointer: fine) {
  .chip:hover { border-color: var(--muted); color: var(--ink); }
  .chip[aria-pressed='true']:hover { background: var(--primary-soft-2); }
}

/* --------------------------------------------------------------------------
   Badges & status pills
   White text on saturated fills; dark text only on pale ones.
   Status always pairs colour with a word — colour is never the only signal.
   -------------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 21px;
  padding: 0 8px;
  border-radius: var(--r-full);
  font-size: var(--fs-3xs);
  font-weight: var(--fw-semi);
  letter-spacing: 0.005em;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge .icon { width: 12px; height: 12px; stroke-width: 2; }
.badge-lg { height: 25px; padding: 0 10px; font-size: var(--fs-2xs); }

.badge-neutral { background: var(--neutral-soft); color: var(--ink-2); border-color: var(--neutral-line); }
.badge-brand   { background: var(--primary-soft); color: var(--primary-press); border-color: var(--primary-line); }
.badge-success { background: var(--success-soft); color: oklch(0.40 0.115 155); border-color: var(--success-line); }
.badge-warning { background: var(--warning-soft); color: oklch(0.46 0.115 70); border-color: var(--warning-line); }
.badge-danger  { background: var(--danger-soft); color: oklch(0.42 0.180 18); border-color: var(--danger-line); }
.badge-info    { background: var(--info-soft); color: oklch(0.41 0.105 245); border-color: var(--info-line); }
.badge-signal  { background: var(--signal); color: var(--on-signal); border-color: oklch(0.80 0.16 116); }
.badge-solid   { background: var(--primary); color: var(--on-primary); }
.badge-dark    { background: var(--chrome); color: var(--chrome-ink); }

/* Status dot for compact rows — always accompanied by a text label */
.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--muted);
}
.dot-success { background: var(--success); }
.dot-warning { background: var(--warning); }
.dot-danger  { background: var(--danger); }
.dot-info    { background: var(--info); }
.dot-brand   { background: var(--primary); }

/* --------------------------------------------------------------------------
   Panels & cards
   Cards are used where they are the right affordance, never nested.
   -------------------------------------------------------------------------- */
.panel {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  overflow: hidden;
}
.panel-flush { border-radius: 0; border-left: 0; border-right: 0; }
.panel-quiet { background: var(--surface); border-color: transparent; }
.panel-raised { box-shadow: var(--shadow-sm); }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--line);
  min-height: 52px;
}
.panel-head-title { display: flex; align-items: center; gap: var(--s-3); min-width: 0; }
.panel-head h2, .panel-head h3 {
  font-size: var(--fs-base);
  font-weight: var(--fw-semi);
  letter-spacing: var(--ls-title);
}
.panel-body { padding: var(--s-5); }
.panel-body-flush { padding: 0; }
.panel-foot {
  padding: var(--s-3) var(--s-5);
  border-top: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
}

/* Interactive card */
.card-link {
  display: block;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out),
              background-color var(--dur-fast) var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  .card-link:hover { border-color: var(--line-strong); box-shadow: var(--shadow-sm); }
}
.card-link:active { background: var(--surface); }
.card-link[aria-current='true'],
.card-link[data-selected='true'] {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

/* --------------------------------------------------------------------------
   Metric block — deliberately not the "big number + gradient" hero template.
   Label reads first, number is the answer, delta is evidence.
   -------------------------------------------------------------------------- */
.stat { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.stat-label {
  font-size: var(--fs-2xs);
  font-weight: var(--fw-medium);
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 5px;
}
.stat-value { font-size: var(--fs-2xl); }
.stat-value.metric { font-size: var(--fs-2xl); }

/* The supporting line wraps rather than truncating: these numbers are the
   evidence for the headline figure, so clipping them defeats the point. */
.stat-foot {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 3px 7px;
  font-size: var(--fs-2xs);
  line-height: 1.4;
  color: var(--muted);
}
.stat-foot .delta { white-space: nowrap; }

.delta { display: inline-flex; align-items: center; gap: 3px; font-weight: var(--fw-semi); }
.delta .icon { width: 13px; height: 13px; stroke-width: 2; }
.delta-up   { color: var(--success); }
.delta-down { color: var(--danger); }
.delta-flat { color: var(--muted); }

/* --------------------------------------------------------------------------
   Tables — dense by permission; readable by requirement
   -------------------------------------------------------------------------- */
.table { width: 100%; font-size: var(--fs-sm); }

.table thead th {
  position: sticky;
  top: 0;
  z-index: var(--z-raised);
  background: var(--surface);
  text-align: left;
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semi);
  color: var(--ink-2);
  letter-spacing: var(--ls-label);
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
}
.table thead th.sortable { cursor: pointer; user-select: none; }
.table thead th.sortable .icon {
  width: 13px; height: 13px;
  opacity: 0.4;
  vertical-align: -2px;
  margin-left: 3px;
  transition: opacity var(--dur-fast) var(--ease-out);
}
.table thead th[aria-sort]:not([aria-sort='none']) { color: var(--ink); }
.table thead th[aria-sort]:not([aria-sort='none']) .icon { opacity: 1; color: var(--primary); }
@media (hover: hover) and (pointer: fine) {
  .table thead th.sortable:hover { color: var(--ink); }
  .table thead th.sortable:hover .icon { opacity: 0.8; }
}

.table tbody td {
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  color: var(--ink);
}
.table tbody tr { transition: background-color var(--dur-fast) var(--ease-out); }
.table tbody tr:last-child td { border-bottom: 0; }
@media (hover: hover) and (pointer: fine) {
  .table tbody tr:hover { background: var(--surface); }
}
.table tbody tr[data-selected='true'] { background: var(--primary-soft); }
.table tbody tr.row-link { cursor: pointer; }

.table .num-cell { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions-cell { width: 1%; white-space: nowrap; text-align: right; }
.table .actions-cell .btn { opacity: 0; transition: opacity var(--dur-fast) var(--ease-out); }
.table tr:hover .actions-cell .btn,
.table tr:focus-within .actions-cell .btn { opacity: 1; }
@media (hover: none) { .table .actions-cell .btn { opacity: 1; } }

.table-compact tbody td { padding: 7px var(--s-4); }

/* Below 640px, tables become stacked records rather than a horizontal scroll trap */
@media (max-width: 640px) {
  .table-stack thead { display: none; }
  .table-stack tbody tr {
    display: block;
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: var(--s-3);
    margin-bottom: var(--s-3);
  }
  .table-stack tbody td {
    display: flex;
    justify-content: space-between;
    gap: var(--s-4);
    border: 0;
    padding: 5px 0;
    text-align: left;
  }
  .table-stack tbody td::before {
    content: attr(data-label);
    font-size: var(--fs-2xs);
    font-weight: var(--fw-semi);
    color: var(--muted);
    flex-shrink: 0;
  }
  .table-stack .num-cell { text-align: left; }
  .table-stack .actions-cell { width: auto; justify-content: flex-end; }
}

/* --------------------------------------------------------------------------
   List rows — the alternative to a card grid when items are homogeneous
   -------------------------------------------------------------------------- */
.rows { display: flex; flex-direction: column; }
.row-item {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  padding: var(--s-3) var(--s-5);
  border-bottom: 1px solid var(--line);
  min-height: 56px;
  width: 100%;
  text-align: left;
  transition: background-color var(--dur-fast) var(--ease-out);
}
.row-item:last-child { border-bottom: 0; }
@media (hover: hover) and (pointer: fine) {
  a.row-item:hover, button.row-item:hover { background: var(--surface); }
}

/* --------------------------------------------------------------------------
   Tabs
   -------------------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: var(--s-5);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  padding: var(--s-3) 0 11px;
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--muted);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: color var(--dur-fast) var(--ease-out);
}
.tab::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: var(--primary);
  border-radius: 2px 2px 0 0;
  transform: scaleX(0);
  transform-origin: center;
  transition: transform var(--dur) var(--ease-out);
}
.tab[aria-selected='true'] { color: var(--ink); font-weight: var(--fw-semi); }
.tab[aria-selected='true']::after { transform: scaleX(1); }
@media (hover: hover) and (pointer: fine) { .tab:hover { color: var(--ink); } }
.tab-count {
  font-size: var(--fs-3xs);
  font-weight: var(--fw-semi);
  background: var(--surface-3);
  color: var(--ink-2);
  border-radius: var(--r-full);
  padding: 1px 6px;
  font-variant-numeric: tabular-nums;
}
.tab[aria-selected='true'] .tab-count { background: var(--primary-soft); color: var(--primary-press); }

/* --------------------------------------------------------------------------
   Dropdown menu — popovers scale from their trigger, never from centre
   -------------------------------------------------------------------------- */
.menu {
  position: fixed;
  z-index: var(--z-dropdown);
  min-width: 190px;
  max-height: min(420px, 70vh);
  overflow-y: auto;
  padding: 5px;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  transform-origin: var(--menu-origin, top left);
  transition: opacity var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.menu[hidden] { display: none; }
.menu[data-state='closed'] { opacity: 0; transform: scale(0.97); pointer-events: none; }
.menu[data-state='open'] { opacity: 1; transform: scale(1); }

.menu-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  padding: 7px var(--s-3);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  color: var(--ink);
  text-align: left;
  transition: background-color var(--dur-press) var(--ease-out);
}
.menu-item .icon { width: 16px; height: 16px; color: var(--muted); }
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); }
.menu-item[aria-checked='true'] { color: var(--primary-press); font-weight: var(--fw-semi); }
.menu-item[aria-checked='true'] .icon { color: var(--primary); }
.menu-item-danger { color: var(--danger); }
.menu-item-danger .icon { color: var(--danger); }
.menu-item-danger:hover { background: var(--danger-soft); }
.menu-sep { height: 1px; background: var(--line); margin: 5px 0; }
.menu-label {
  padding: 7px var(--s-3) 4px;
  font-size: var(--fs-3xs);
  font-weight: var(--fw-semi);
  color: var(--muted);
  letter-spacing: var(--ls-label);
}
.menu-item .shortcut { margin-left: auto; font-size: var(--fs-3xs); color: var(--muted); }

/* --------------------------------------------------------------------------
   Drawer — slides from the right, exits faster than it enters
   -------------------------------------------------------------------------- */
.scrim {
  position: fixed;
  inset: 0;
  background: oklch(0.185 0.012 45 / 0.42);
  opacity: 0;
  transition: opacity var(--dur-panel) var(--ease-out);
}
.scrim[data-state='open'] { opacity: 1; }
.scrim-drawer { z-index: var(--z-drawer-backdrop); }
.scrim-modal  { z-index: var(--z-modal-backdrop); }
.scrim[hidden] { display: none; }

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  z-index: var(--z-drawer);
  width: min(560px, 100vw);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-left: 1px solid var(--line-strong);
  box-shadow: var(--shadow-xl);
  transform: translateX(100%);
  transition: transform var(--dur-panel) var(--ease-drawer);
}
.drawer[data-state='open'] { transform: translateX(0); }
.drawer[data-state='closed'] { transition-duration: var(--dur-fast); }
.drawer[hidden] { display: none; }
.drawer-wide { width: min(760px, 100vw); }

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-4);
  padding: var(--s-5);
  border-bottom: 1px solid var(--line);
}
.drawer-body { flex: 1; overflow-y: auto; padding: var(--s-5); }
.drawer-foot {
  padding: var(--s-4) var(--s-5);
  border-top: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s-3);
}

/* --------------------------------------------------------------------------
   Modal — stays centred; it is not anchored to a trigger.
   Used sparingly: confirmations and genuinely blocking decisions only.
   -------------------------------------------------------------------------- */
.modal {
  position: fixed;
  z-index: var(--z-modal);
  top: 50%; left: 50%;
  width: min(520px, calc(100vw - 2rem));
  max-height: calc(100vh - 4rem);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-radius: var(--r-2xl);
  box-shadow: var(--shadow-xl);
  transform: translate(-50%, -50%) scale(0.97);
  transform-origin: center;
  opacity: 0;
  transition: opacity var(--dur) var(--ease-out), transform var(--dur) var(--ease-out);
}
.modal[data-state='open'] { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.modal[data-state='closed'] { transition-duration: var(--dur-fast); }
.modal[hidden] { display: none; }
.modal-lg { width: min(760px, calc(100vw - 2rem)); }
.modal-head { padding: var(--s-6) var(--s-6) 0; }
.modal-body { padding: var(--s-4) var(--s-6); overflow-y: auto; }
.modal-foot {
  padding: var(--s-4) var(--s-6) var(--s-6);
  display: flex;
  justify-content: flex-end;
  gap: var(--s-3);
}

/* --------------------------------------------------------------------------
   Toasts — transitions not keyframes, so rapid stacking retargets smoothly
   -------------------------------------------------------------------------- */
.toaster {
  position: fixed;
  bottom: var(--s-5);
  right: var(--s-5);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column-reverse;
  gap: var(--s-2);
  width: min(370px, calc(100vw - 2rem));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--chrome);
  color: var(--chrome-ink);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(10px) scale(0.98);
  transition: opacity var(--dur) var(--ease-out), transform var(--dur) var(--ease-out);
}
.toast[data-state='open'] { opacity: 1; transform: translateY(0) scale(1); }
.toast .icon { width: 17px; height: 17px; margin-top: 1px; flex-shrink: 0; }
.toast-success .icon { color: oklch(0.76 0.15 155); }
.toast-danger  .icon { color: oklch(0.72 0.16 22); }
.toast-info    .icon { color: var(--signal); }
.toast-close { color: var(--chrome-muted); margin-left: auto; flex-shrink: 0; }
.toast-close:hover { color: var(--chrome-ink); }

/* --------------------------------------------------------------------------
   Tooltip
   -------------------------------------------------------------------------- */
.tooltip {
  position: fixed;
  z-index: var(--z-tooltip);
  max-width: 260px;
  padding: 5px 9px;
  background: var(--chrome);
  color: var(--chrome-ink);
  border-radius: var(--r-sm);
  font-size: var(--fs-2xs);
  line-height: 1.4;
  box-shadow: var(--shadow-md);
  pointer-events: none;
  transform-origin: var(--tip-origin, bottom center);
  opacity: 0;
  transform: scale(0.97);
  transition: opacity 125ms var(--ease-out), transform 125ms var(--ease-out);
}
.tooltip[data-state='open'] { opacity: 1; transform: scale(1); }
/* Once one tooltip is open, neighbours appear instantly — feels faster without
   defeating the purpose of the initial delay. */
.tooltip[data-instant='true'] { transition-duration: 0ms; }
.tooltip[hidden] { display: none; }

/* --------------------------------------------------------------------------
   Progress, meters, rings
   -------------------------------------------------------------------------- */
.progress {
  height: 6px;
  background: var(--surface-3);
  border-radius: var(--r-full);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: var(--r-full);
  transition: width var(--dur-slow) var(--ease-out);
}
.progress-lg { height: 9px; }
.progress-bar-success { background: var(--success); }
.progress-bar-warning { background: var(--warning); }
.progress-bar-danger  { background: var(--danger); }

/* Stacked meter for inventory utilisation */
.meter { display: flex; height: 9px; border-radius: var(--r-full); overflow: hidden; background: var(--surface-3); }
.meter span { display: block; height: 100%; }

.ring { transform: rotate(-90deg); }
.ring-track { stroke: var(--surface-3); fill: none; }
.ring-fill {
  fill: none;
  stroke: var(--primary);
  stroke-linecap: round;
  transition: stroke-dashoffset var(--dur-slow) var(--ease-out);
}

/* --------------------------------------------------------------------------
   Avatars
   -------------------------------------------------------------------------- */
.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface-3);
  color: var(--ink-2);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semi);
  flex-shrink: 0;
  letter-spacing: 0.01em;
  overflow: hidden;
  user-select: none;
}
.avatar-sm { width: 24px; height: 24px; font-size: var(--fs-3xs); }
.avatar-lg { width: 40px; height: 40px; font-size: var(--fs-sm); }
.avatar-xl { width: 56px; height: 56px; font-size: var(--fs-md); }
.avatar-brand { background: var(--primary-soft); color: var(--primary-press); }
.avatar-dark  { background: var(--chrome-2); color: var(--chrome-ink); }
.avatar-square { border-radius: var(--r-md); }

.avatar-stack { display: flex; }
.avatar-stack .avatar { margin-left: -7px; border: 2px solid var(--bg); }
.avatar-stack .avatar:first-child { margin-left: 0; }

/* --------------------------------------------------------------------------
   Callouts — full borders and background tints. No side stripes.
   -------------------------------------------------------------------------- */
.callout {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-4);
  border-radius: var(--r-lg);
  border: 1px solid var(--neutral-line);
  background: var(--neutral-soft);
  font-size: var(--fs-sm);
  line-height: var(--lh-normal);
}
.callout .icon { width: 17px; height: 17px; flex-shrink: 0; margin-top: 1px; }
.callout-title { font-weight: var(--fw-semi); display: block; margin-bottom: 2px; }
.callout-brand   { background: var(--primary-soft); border-color: var(--primary-line); color: oklch(0.34 0.10 41); }
.callout-brand .icon { color: var(--primary); }
.callout-success { background: var(--success-soft); border-color: var(--success-line); color: oklch(0.36 0.10 155); }
.callout-success .icon { color: var(--success); }
.callout-warning { background: var(--warning-soft); border-color: var(--warning-line); color: oklch(0.40 0.10 70); }
.callout-warning .icon { color: var(--warning); }
.callout-danger  { background: var(--danger-soft); border-color: var(--danger-line); color: oklch(0.38 0.15 18); }
.callout-danger .icon { color: var(--danger); }
.callout-info    { background: var(--info-soft); border-color: var(--info-line); color: oklch(0.36 0.09 245); }
.callout-info .icon { color: var(--info); }

/* --------------------------------------------------------------------------
   Empty states — teach the interface, never just "nothing here"
   -------------------------------------------------------------------------- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--s-10) var(--s-6);
  gap: var(--s-3);
}
.empty-art {
  width: 52px; height: 52px;
  border-radius: var(--r-xl);
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  margin-bottom: var(--s-1);
}
.empty h3 { font-size: var(--fs-md); font-weight: var(--fw-semi); }
.empty p { font-size: var(--fs-sm); color: var(--muted); max-width: 46ch; }

/* --------------------------------------------------------------------------
   Skeletons — used instead of spinners inside content
   -------------------------------------------------------------------------- */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  border-radius: var(--r-sm);
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; background: var(--surface-2); }
}
.skeleton-text { height: 11px; margin-bottom: 7px; }
.skeleton-title { height: 17px; width: 40%; margin-bottom: var(--s-3); }

/* --------------------------------------------------------------------------
   Kanban
   -------------------------------------------------------------------------- */
.board {
  display: flex;
  gap: var(--s-3);
  align-items: flex-start;
  overflow-x: auto;
  padding-bottom: var(--s-3);
  overscroll-behavior-x: contain;
}
.board-col {
  flex: 0 0 268px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  display: flex;
  flex-direction: column;
  max-height: 100%;
}
.board-col-head {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-3) var(--s-2);
}
.board-col-title { font-size: var(--fs-2xs); font-weight: var(--fw-semi); color: var(--ink); }
.board-col-body {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 0 7px 7px;
  min-height: 62px;
  overflow-y: auto;
  transition: background-color var(--dur-fast) var(--ease-out);
}
.board-col-body[data-dragover='true'] { background: var(--primary-soft); border-radius: var(--r-md); }

.board-card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 10px;
  cursor: grab;
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              opacity var(--dur-fast) var(--ease-out);
}
.board-card:active { cursor: grabbing; }
.board-card[data-dragging='true'] { opacity: 0.4; }
@media (hover: hover) and (pointer: fine) {
  .board-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow-sm); }
}

/* --------------------------------------------------------------------------
   Stepper (wizards)
   -------------------------------------------------------------------------- */
.stepper { display: flex; align-items: center; gap: var(--s-2); }
.step { display: flex; align-items: center; gap: var(--s-2); }
.step-dot {
  width: 24px; height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface-3);
  color: var(--muted);
  font-size: var(--fs-3xs);
  font-weight: var(--fw-bold);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  transition: background-color var(--dur) var(--ease-out), color var(--dur) var(--ease-out);
}
.step[data-state='current'] .step-dot { background: var(--primary); color: var(--on-primary); }
.step[data-state='done'] .step-dot { background: var(--success); color: var(--on-primary); }
.step-label { font-size: var(--fs-xs); font-weight: var(--fw-medium); color: var(--muted); white-space: nowrap; }
.step[data-state='current'] .step-label { color: var(--ink); font-weight: var(--fw-semi); }
.step[data-state='done'] .step-label { color: var(--ink-2); }
.step-line { width: 26px; height: 1.5px; background: var(--line-strong); flex-shrink: 0; }
.step-line[data-done='true'] { background: var(--success); }

/* --------------------------------------------------------------------------
   Breadcrumb
   -------------------------------------------------------------------------- */
.crumbs { display: flex; align-items: center; gap: 5px; font-size: var(--fs-xs); color: var(--muted); }
.crumbs a { transition: color var(--dur-fast) var(--ease-out); }
.crumbs a:hover { color: var(--ink); }
.crumbs .icon { width: 13px; height: 13px; opacity: 0.6; }
.crumbs [aria-current='page'] { color: var(--ink); font-weight: var(--fw-medium); }

/* --------------------------------------------------------------------------
   Score ring + gauge label used by the readiness score
   -------------------------------------------------------------------------- */
.score { display: inline-flex; align-items: center; gap: var(--s-3); }
.score-ring { position: relative; display: grid; place-items: center; }
.score-ring .score-num {
  position: absolute;
  font-family: var(--font-display);
  font-stretch: 112%;
  font-weight: var(--fw-bold);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

/* --------------------------------------------------------------------------
   AI surfaces — a consistent visual signature so generated content is always
   distinguishable from data the user entered
   -------------------------------------------------------------------------- */
.ai-surface {
  border: 1px solid var(--primary-line);
  background: var(--primary-soft);
  border-radius: var(--r-lg);
  padding: var(--s-4);
}
.ai-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--fs-3xs);
  font-weight: var(--fw-semi);
  color: var(--primary-press);
  letter-spacing: var(--ls-label);
}
.ai-tag .icon { width: 13px; height: 13px; }

.ai-out { font-size: var(--fs-sm); line-height: var(--lh-loose); color: var(--ink); }
.ai-out p + p { margin-top: 0.85em; }
.ai-out h4 { font-size: var(--fs-sm); font-weight: var(--fw-semi); margin: 1.2em 0 0.35em; }
.ai-out h4:first-child { margin-top: 0; }
.ai-out ul { margin: 0.5em 0; display: flex; flex-direction: column; gap: 5px; }
.ai-out li { padding-left: 17px; position: relative; }
.ai-out li::before {
  content: '';
  position: absolute;
  left: 4px; top: 0.62em;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--primary);
}
.ai-out strong { font-weight: var(--fw-semi); }

/* Streaming caret */
.ai-caret {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--primary);
  vertical-align: -2px;
  margin-left: 1px;
  animation: caret 1s steps(2) infinite;
}
@keyframes caret { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .ai-caret { animation: none; } }

/* Thinking state */
.ai-thinking { display: flex; align-items: center; gap: 7px; font-size: var(--fs-xs); color: var(--muted); }
.ai-thinking-dots { display: inline-flex; gap: 3px; }
.ai-thinking-dots i {
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--primary);
  animation: pulse-dot 1.1s ease-in-out infinite;
}
.ai-thinking-dots i:nth-child(2) { animation-delay: 140ms; }
.ai-thinking-dots i:nth-child(3) { animation-delay: 280ms; }
@keyframes pulse-dot { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .ai-thinking-dots i { animation: none; opacity: 0.7; } }

/* Highlighter — the only place --signal appears in the app */
.mark {
  background: var(--signal);
  color: var(--on-signal);
  padding: 0 3px;
  border-radius: 2px;
  font-weight: var(--fw-medium);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

/* --------------------------------------------------------------------------
   Divider with a label
   -------------------------------------------------------------------------- */
.rule {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semi);
  color: var(--muted);
  letter-spacing: var(--ls-label);
}
.rule::before, .rule::after { content: ''; flex: 1; height: 1px; background: var(--line); }

/* --------------------------------------------------------------------------
   Command palette — keyboard-initiated, so it does not animate
   -------------------------------------------------------------------------- */
.palette {
  position: fixed;
  z-index: var(--z-modal);
  top: 14vh; left: 50%;
  transform: translateX(-50%);
  width: min(600px, calc(100vw - 2rem));
  max-height: 62vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
}
.palette[hidden] { display: none; }
.palette-input {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: var(--s-4) var(--s-5);
  font-size: var(--fs-md);
  background: transparent;
}
.palette-input:focus-visible { box-shadow: none; }
.palette-list { overflow-y: auto; padding: var(--s-2); }
.palette-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  padding: 9px var(--s-3);
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  text-align: left;
  color: var(--ink);
}
.palette-item .icon { width: 16px; height: 16px; color: var(--muted); }
.palette-item[data-active='true'] { background: var(--primary-soft); }
.palette-item[data-active='true'] .icon { color: var(--primary); }
.palette-item .stage { margin-left: auto; font-size: var(--fs-3xs); color: var(--muted); }
