/* MudUp components — pure CSS, no JS.
   Designed to be dropped into any HTML page that imports
   colors_and_type.css. Every component reads from semantic
   tokens, so swapping --brand or theme flips the whole UI. */

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 4px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out),
              color var(--duration-fast) var(--ease-out);
  text-decoration: none;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--brand-600);
  color: var(--text-on-brand);
}
.btn-primary:hover { background: var(--brand-500); }
.btn-primary:active { background: var(--brand-700); }

/* In dark mode the deepest brand stop disappears into the canvas.
   Step up to a lighter, more saturated tier; reverse hover/press
   so hover goes brighter and press goes back toward the base. */
[data-theme="dark"] .btn-primary { background: var(--brand-400); color: #FFFFFF; }
[data-theme="dark"] .btn-primary:hover { background: var(--brand-300); }
[data-theme="dark"] .btn-primary:active { background: var(--brand-500); }

.btn-secondary {
  background: var(--bg-surface);
  border-color: var(--border-strong);
  color: var(--text-1);
}
.btn-secondary:hover { background: var(--bg-row-hover); }
.btn-secondary:active { background: var(--bg-surface-sunk); }

/* Danger should READ as destructive but never out-shout primary.
   Light: solid red, contained. Dark: tinted with a red border —
   visible, scannable, but quieter than the green primary. */
.btn-danger {
  background: var(--status-fail-bg);
  color: var(--status-fail-fg);
  border-color: var(--status-fail-bd);
}
.btn-danger:hover { background: var(--status-fail-bd); }
.btn-danger:active { background: var(--status-fail-bg); filter: brightness(0.92); }

.btn-ghost {
  background: transparent;
  color: var(--text-2);
}
.btn-ghost:hover { background: var(--bg-row-hover); color: var(--text-1); }
.btn-ghost:active { background: var(--bg-surface-sunk); }

.btn-lg { height: 44px; padding: 0 18px; font-size: 14px; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }

/* ── Inputs ──────────────────────────────────────────────────────────── */
.input, .select, .textarea {
  display: block;
  width: 100%;
  height: var(--row-height-input);
  padding: 0 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-input);
  border-radius: 4px;
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  color: var(--text-1);
  outline: none;
  transition: border-color var(--duration-fast) var(--ease-out),
              background-color var(--duration-fast) var(--ease-out);
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--border-strong); }
.input::placeholder { color: var(--text-4); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible {
  border-color: var(--brand-600);
  box-shadow: 0 0 0 2px var(--bg-canvas), 0 0 0 4px var(--brand-600);
}
.input[disabled] { opacity: 0.4; cursor: not-allowed; background: var(--bg-surface-sunk); }
.input.is-error, .select.is-error { border-color: var(--status-fail-fg); }
.input.is-error:focus-visible { box-shadow: 0 0 0 2px var(--bg-canvas), 0 0 0 4px var(--status-fail-fg); }

/* numeric input — mono + right-aligned */
.input.num, input[type="number"].input { font-family: var(--font-mono); text-align: right; padding-right: 12px; font-variant-numeric: tabular-nums; }

.textarea { height: auto; padding: 8px 10px; line-height: var(--lh-normal); resize: vertical; min-height: 72px; }

/* Inline labeled row — 4 columns:
   1. Label + abbr in parens ("Mud Weight (MW)")
   2. Input
   3. Unit ("ppg") — left-aligned, sits right next to the input
   4. Plan / target helper */
.labeled-row {
  display: grid;
  grid-template-columns: 200px 100px 90px 1fr;
  align-items: center;
  gap: 8px 32px;
  padding: 8px 0;
  border-top: 1px solid var(--border-default);
}
.labeled-row:first-of-type { border-top: none; }
.labeled-row > label {
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-3);
}
.labeled-row > label .abbr {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-1);
  margin-left: 4px;
  letter-spacing: 0;
}
.labeled-row > .input {
  height: 32px;
  font-size: 13px;
}
.labeled-row .unit {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-2);
  text-align: left;
}
.labeled-row .hint {
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.labeled-row .hint .mono {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-2);
}

/* ── Status pills ────────────────────────────────────────────────────── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border: 1px solid;
  border-radius: 999px;
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  line-height: 1;
  white-space: nowrap;
}
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-pass    { color: var(--status-pass-fg);    background: var(--status-pass-bg);    border-color: var(--status-pass-bd); }
.pill-warn    { color: var(--status-warn-fg);    background: var(--status-warn-bg);    border-color: var(--status-warn-bd); }
.pill-fail    { color: var(--status-fail-fg);    background: var(--status-fail-bg);    border-color: var(--status-fail-bd); }
.pill-info,
.pill-flag    { color: var(--status-info-fg);    background: var(--status-info-bg);    border-color: var(--status-info-bd); }
.pill-running { color: var(--status-running-fg); background: var(--status-running-bg); border-color: var(--status-running-bd); }
.pill-queued  { color: var(--text-3);            background: var(--bg-surface-sunk);   border-color: var(--border-default); }
.pill-running .dot { animation: mudup-pulse 1.2s ease-in-out infinite; }
@keyframes mudup-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ── Card ────────────────────────────────────────────────────────────── */
.mu-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: 6px;
  /* D4 tweak from design/source-2026-05-13/components.css:
     overflow:hidden keeps child tables / scroll areas clipped to the rounded
     corners; min-width:0 lets the card shrink inside grids without forcing
     overflow on the parent (matters when a card contains a wide table). */
  overflow: hidden;
  min-width: 0;
}
/* In dark mode, default borders are too soft to delineate container
   chrome against the canvas. Lift cards + KPI tiles to border-strong. */
[data-theme="dark"] .mu-card,
[data-theme="dark"] .kpi { border-color: var(--border-strong); }
.mu-card-header {
  padding: 0 16px;
  height: 48px;
  border-bottom: 1px solid var(--border-default);
  display: flex; align-items: center; justify-content: space-between;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-3);
}
.mu-card-body { padding: 16px; }

/* ── KPI card ────────────────────────────────────────────────────────── */
.kpi {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: 6px;
  padding: 12px 14px;
}
.kpi-label {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-3);
}
.kpi-value {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 600;
  line-height: 1.1;
  color: var(--text-1);
  margin-top: 4px;
  font-variant-numeric: tabular-nums lining-nums;
}
.kpi-unit {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-3);
  margin-left: 4px;
}
.kpi-delta {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.kpi-delta.pos { color: var(--num-positive); }
.kpi-delta.neg { color: var(--num-negative); }
.kpi-delta.zero { color: var(--text-3); }

/* ── Data table ──────────────────────────────────────────────────────── */
.mu-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--text-1);
  /* D4 tweak: explicit column widths enforced so dense tables (mud-check,
     inventory, time-dist) don't reflow as engineers type. Cell <th>/<td>
     widths still come from inline style="width:Npx" or the per-table CSS. */
  table-layout: fixed;
}
.mu-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg-surface-sunk);
  color: var(--text-3);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}
.mu-table thead th.num { text-align: right; }
.mu-table tbody td {
  height: var(--row-height-table);
  padding: 0 12px;
  border-bottom: 1px solid var(--border-default);
  vertical-align: middle;
}
.mu-table tbody td.num {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums lining-nums;
}
.mu-table tbody tr:hover { background: var(--bg-row-hover); cursor: pointer; }
.mu-table tbody tr.is-selected { background: var(--bg-row-selected); }
.mu-table tbody tr.is-selected td:first-child {
  box-shadow: inset 2px 0 0 var(--brand-600);
}
.mu-table.zebra tbody tr:nth-child(even):not(:hover):not(.is-selected) {
  background: var(--bg-row-zebra);
}
/* frozen left column */
.mu-table.frozen-left thead th:first-child,
.mu-table.frozen-left tbody td:first-child {
  position: sticky;
  left: 0;
  background: inherit;
  border-right: 1px solid var(--border-default);
}
.mu-table.frozen-left tbody tr:hover td:first-child { background: var(--bg-row-hover); }

/* sortable header indicator */
.mu-table th.sort {
  cursor: pointer;
  user-select: none;
}
.mu-table th.sort:hover { color: var(--text-2); }
.mu-table th.sort .caret {
  display: inline-block; margin-left: 4px; opacity: 0.6;
  font-family: var(--font-mono); font-size: 9px;
}
.mu-table th.sort.is-active { color: var(--text-1); }
.mu-table th.sort.is-active .caret { opacity: 1; color: var(--brand-600); }

/* ── Alert (inline) ──────────────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid;
  border-radius: 4px;
  font-size: 13px;
  line-height: 1.5;
}
.alert-icon { flex-shrink: 0; margin-top: 1px; }
.alert-body strong { font-weight: 600; }
.alert-pass { color: var(--status-pass-fg); background: var(--status-pass-bg); border-color: var(--status-pass-bd); }
.alert-warn { color: var(--status-warn-fg); background: var(--status-warn-bg); border-color: var(--status-warn-bd); }
.alert-fail { color: var(--status-fail-fg); background: var(--status-fail-bg); border-color: var(--status-fail-bd); }
.alert-info { color: var(--status-info-fg); background: var(--status-info-bg); border-color: var(--status-info-bd); }

/* ── Tabbed form ─────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border-default);
}
.tab {
  height: 40px;
  padding: 0 14px;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-3);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tab:hover { color: var(--text-1); }
.tab.is-active { color: var(--brand-600); border-bottom-color: var(--brand-600); font-weight: 600; }

/* ── Nav rail ────────────────────────────────────────────────────────── */
.nav-rail {
  width: 224px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-default);
  padding: 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-rail-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 12px 16px;
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 15px;
  color: var(--text-1);
  letter-spacing: -0.01em;
}
.nav-rail-brand .mark {
  width: 22px; height: 22px;
  background: var(--brand-600);
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-weight: 700; font-size: 12px;
  color: #fff;
}
.nav-rail-section {
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-4);
  padding: 12px 12px 4px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 32px;
  padding: 0 10px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--text-2);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.nav-link:hover { background: var(--bg-row-hover); color: var(--text-1); }
.nav-link.is-active {
  background: var(--brand-tint);
  color: var(--brand-600);
  font-weight: 600;
}
[data-theme="dark"] .nav-link.is-active { background: var(--bg-row-selected); color: var(--brand-300); }
.nav-link .count {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
  background: var(--bg-surface-sunk);
  border: 1px solid var(--border-default);
  border-radius: 2px;
  padding: 1px 6px;
  min-width: 22px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.nav-link.is-active .count {
  background: var(--bg-canvas);
  color: var(--brand-600);
  border-color: var(--brand-300);
}
[data-theme="dark"] .nav-link.is-active .count {
  color: var(--brand-300);
  border-color: var(--brand-400);
}
