/* tasteskill / app.css — Institutional Swiss Ledger & Execution Desk
   Tokens and shell rules from .taste-skill/direction.json and references/app-screens.md */

:root {
  --ground: #eef1f6;          /* architectural slate-grey ledger ground */
  --surface: #ffffff;         /* crisp white execution panels */
  --raised: #e6eaf0;          /* recessed inner wells, segmented track, sizing box */
  --active: #dde3ec;          /* active rail or selected row */
  --border: #dfe3eb;          /* panel and rail 1px structural edge */
  --rule: #edf0f5;            /* row rules inside tables and lists */
  --control: #7d889b;         /* inputs and outlined buttons (>= 3:1 non-text contrast on white and ground) */
  --text: #0b0f17;            /* deep obsidian primary ink */
  --muted: #4b5565;           /* secondary text and labels (>= 4.5:1 on white and #eef1f6) */
  --faint: #55606f;           /* meta and timestamps (>= 4.5:1 on white, ground, raised and active) */
  --accent: #0f172a;          /* achromatic chrome selection */
  --primary: #0f172a;         /* institutional near-black primary action */
  --primary-ink: #ffffff;
  --positive: #136f3e;
  --negative: #b91c22;
  --warning: #8a3c0c;
  --chart-1: #1d5fbf;         /* primary chart series hue */
  --chart-2: #7c8798;
  --chart-3: #0f172a;
  --chart-muted: #7d889b;       /* >= 3:1 on white for dimmed series marks */
  --chart-mark: var(--text);
  --chart-span: 0.06;
  --grid: #e6eaf0;
  --axis-ink: #4b5565;
  --ink: var(--text);

  --pill-positive-bg: #dcfce7; --pill-positive-ink: #06371b;
  --pill-negative-bg: #ffe4e6; --pill-negative-ink: #881317;
  --pill-warning-bg: #fef3c7;  --pill-warning-ink: #78350f;
  --pill-neutral-bg: #e8ecf2;  --pill-neutral-ink: #334155;

  --font: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
  --fs-title: 24px;
  --fs-section: 16px;
  --fs-kpi: 28px;
  --fs-body: 14px;
  --fs-small: 13px;

  --sidebar-width: 72px;      /* Labeled icon rail width per institutional ledger */
  --pad: 22px 26px;
  --gap: 14px;                /* Balanced 14px Swiss ledger grid gap */
  --card-pad: 20px;
  --radius-card: 8px;
  --radius-control: 6px;
  --control-height: 36px;
  --row-height: 46px;
  --nav-row: 38px;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --t-press: 120ms;
  --t-hover: 150ms;
  --t-ui: 200ms;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--text);
  font: var(--fs-body)/20px var(--font);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, p, figure, ul, ol, dl, dd { margin: 0; }
ul[class], ol[class] { padding: 0; list-style: none; }
img, svg, video, canvas { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--chart-1); outline-offset: 2px; border-radius: 4px; }
/* two-tone ring on dark surfaces so focus keeps 3:1 against the near-black fill */
.cmd-ribbon :focus-visible,
.btn.primary:focus-visible,
.ws-tab-btn[aria-selected="true"]:focus-visible,
.skip-link:focus-visible { outline-color: #ffffff; box-shadow: 0 0 0 4px var(--chart-1); }
/* WCAG 2.5.8: every pointer target at least 24x24 CSS px */
button, [role="button"], [role="tab"], summary, select, input:not([type="hidden"]) { min-height: 24px; }
input[type="checkbox"], input[type="radio"] { min-width: 24px; min-height: 24px; }
.table-wrap { overscroll-behavior-x: contain; }
.table-wrap:focus-visible { outline: 2px solid var(--chart-1); outline-offset: -2px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; }
.panel, .title-row, .stamp { overflow-wrap: break-word; }
.skip-link {
  position: absolute;
  top: -48px;
  left: 12px;
  z-index: 10000;
  padding: 8px 14px;
  background: var(--primary);
  color: var(--primary-ink);
  border-radius: var(--radius-control);
  font-size: var(--fs-small);
  font-weight: 700;
  transition: top var(--t-ui) ease;
}
.skip-link:focus,
.skip-link:focus-visible {
  top: 12px;
  outline: 2px solid var(--chart-1);
  outline-offset: 2px;
}
.num, table, .kpi-value, .mono-id { font-variant-numeric: tabular-nums; }

/* ---------- shell: 72px labeled icon rail + canvas ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100svh;
}
.rail {
  position: sticky;
  top: 0;
  height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  gap: 6px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.rail-brand {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  background: var(--primary);
  color: var(--surface);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: -0.02em;
  margin-bottom: 10px;
}
.rail-sep {
  width: 22px;
  height: 1px; /* taste-skill-ignore: rail group divider */
  background: var(--border);
  margin: 6px 0;
}
.rail-btn {
  position: relative;
  width: 58px;
  min-height: 46px;
  padding: 5px 4px;
  border-radius: 6px;
  border: 0;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  transition: background-color var(--t-hover) ease, color var(--t-hover) ease;
}
.rail-btn svg {
  width: 17px;
  height: 17px;
  flex: none;
  stroke-width: 1.75;
}
.rail-btn .rail-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.rail-btn:hover {
  background: var(--raised);
  color: var(--text);
}
.rail-btn[aria-current="page"] {
  color: var(--text);
  background: var(--active);
  font-weight: 600;
}
.rail-btn[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 9px;
  bottom: 9px;
  width: 2px;
  background: var(--primary);
  border-radius: 1px;
}
.rail-bottom {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.canvas {
  min-width: 0;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
  padding: var(--pad);
}

/* ---------- title block and header controls ---------- */
.title-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  padding: 0 2px;
}
.title-row h1 {
  font-size: var(--fs-title);
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.title-row .sub {
  margin-top: 4px;
  color: var(--muted);
  font-size: var(--fs-body);
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  flex-shrink: 0;
  white-space: nowrap;
}
.stamp {
  color: var(--muted);
  font-size: var(--fs-small);
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border); /* taste-skill-ignore */
  border-radius: var(--radius-control);
}
@media (max-width: 1180px) {
  .header-actions {
    flex-wrap: wrap;
    white-space: normal;
  }
}

/* ---------- grid & panels ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--gap);
}
.span-12 { grid-column: span 12; }
.span-6 { grid-column: span 6; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: var(--card-pad);
  min-width: 0;
}
.panel > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.panel h2 {
  font-size: var(--fs-section);
  line-height: 1.3;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.panel .meta {
  color: var(--muted);
  font-size: var(--fs-small);
  margin-top: 2px;
}

/* ---------- KPI divided strip ---------- */
.kpis {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
}
.kpi {
  padding: 16px var(--card-pad);
  min-width: 0;
}
.kpi + .kpi {
  border-left: 1px solid var(--border);
}
.kpi-label {
  color: var(--muted);
  font-size: var(--fs-small);
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.kpi-value {
  margin-top: 8px;
  font-size: var(--fs-kpi);
  line-height: 1.15;
  font-weight: 500;
  letter-spacing: -0.02em;
}
.kpi-value.money {
  font-weight: 700;
}
.kpi-value.zero {
  color: var(--text);
  font-weight: 500;
}
.delta {
  margin-top: 6px;
  font-size: var(--fs-small);
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.delta .up { color: var(--positive); font-weight: 500; }
.delta .down { color: var(--negative); font-weight: 500; }

/* KPI tabs inside the main chart card */
.chart-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-bottom: 1px solid var(--border);
  margin: calc(-1 * var(--card-pad)) calc(-1 * var(--card-pad)) 16px;
  padding: 0 var(--card-pad);
}
.chart-tab {
  position: relative;
  padding: 14px 16px 12px 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background-color var(--t-hover) ease;
}
.chart-tab + .chart-tab {
  padding-left: 18px;
  border-left: 1px solid var(--rule);
}
.chart-tab .kpi-label {
  color: var(--muted);
}
.chart-tab .kpi-value {
  font-size: 24px;
  color: var(--text);
  font-weight: 500;
}
.chart-tab .kpi-value.money {
  font-weight: 700;
}
.chart-tab[aria-selected="true"] .kpi-label {
  color: var(--text);
  font-weight: 700;
}
.chart-tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: var(--chart-1);
}

.chart-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-bottom: 10px;
}
.chart-head h3 {
  font-size: var(--fs-body);
  line-height: 20px;
  font-weight: 700;
}
.chart {
  position: relative;
  min-width: 0;
}

/* Comparison sub-table at the foot of the main chart card */
.cmp-table {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}
.cmp-table table {
  table-layout: fixed;
  width: 100%;
}
.cmp-table table th {
  height: 30px;
}
.cmp-table table td {
  padding: 7px 10px;
}

/* ---------- tables ---------- */
.table-wrap {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
}
.watchlist-table {
  table-layout: fixed;
  width: 100%;
}
th {
  height: 36px;
  padding: 0 10px;
  text-align: left;
  font-weight: 500;
  font-size: var(--fs-small);
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th:first-child, td:first-child {
  padding-left: 4px;
}
th:last-child, td:last-child {
  padding-right: 4px;
}
td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--rule);
  vertical-align: middle;
}
tbody tr {
  transition: background-color var(--t-hover) ease;
}
tbody tr:hover td {
  background: #f7f9fc;
}
tbody tr:last-child td {
  border-bottom: 0;
}
tbody tr[aria-selected="true"] td {
  background: var(--active);
}
th.n, td.n {
  text-align: right;
}
td .primary-cell {
  display: block;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
td .money-cell {
  display: block;
  font-weight: 700;
  color: var(--text);
}
td .sub {
  display: block;
  margin-top: 2px;
  font-size: var(--fs-small);
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn-order {
  height: 30px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 500;
}

/* ---------- status pills ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  border-radius: 4px;
  font-size: var(--fs-small);
  font-weight: 500;
  background: var(--pill-neutral-bg);
  color: var(--pill-neutral-ink);
  white-space: nowrap;
  flex: none;
}
.pill.pos { background: var(--pill-positive-bg); color: var(--pill-positive-ink); }
.pill.neg { background: var(--pill-negative-bg); color: var(--pill-negative-ink); }
.pill.warn { background: var(--pill-warning-bg); color: var(--pill-warning-ink); }

/* ---------- fixed-pitch rows in paired cards ---------- */
.rows {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  padding: 8px 0;
  min-width: 0;
}
.row + .row {
  border-top: 1px solid var(--rule);
}
.row-main {
  min-width: 0;
  flex: 1;
}
.row-title {
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-sub {
  margin-top: 2px;
  font-size: var(--fs-small);
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-right {
  text-align: right;
  flex: none;
  font-variant-numeric: tabular-nums;
}
.row-val {
  font-weight: 700;
  color: var(--text);
}
.row-val.money {
  font-weight: 700;
}

/* ---------- controls & forms ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--control-height);
  padding: 0 12px;
  border-radius: var(--radius-control);
  border: 1px solid var(--control);
  background: var(--surface);
  font-size: var(--fs-body);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--t-hover) ease, transform var(--t-press) var(--ease-out);
}
.btn:hover:not(:disabled) { background: var(--raised); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled {
  opacity: 0.62;
  cursor: not-allowed;
  transform: none;
}
.btn.primary:disabled {
  background: #475569; /* 7.6:1 against the white label, so the busy/disabled text stays legible */
  color: #ffffff;
  opacity: 1;
}
.btn[aria-busy="true"] { cursor: progress; }
.btn.primary {
  background: var(--primary);
  color: var(--primary-ink);
  border-color: transparent;
}
.btn.primary:hover:not(:disabled) {
  background: #1e293b;
}
.btn.secondary-pill {
  background: var(--raised);
  border-color: transparent;
  color: var(--text);
}
.btn.secondary-pill:hover {
  background: var(--active);
}
.input {
  display: block;
  width: 100%;
  height: var(--control-height);
  padding: 0 12px;
  border: 1px solid var(--control);
  border-radius: var(--radius-control);
  background: var(--surface);
  font-size: var(--fs-body);
  color: var(--text);
}
.input:focus,
.input:focus-visible {
  border-color: var(--chart-1);
  outline: 2px solid var(--chart-1);
  outline-offset: 1px;
}
.input[readonly] {
  background: var(--raised);
  color: var(--muted);
}
.input::placeholder {
  color: var(--faint);
}
.segmented {
  display: inline-flex;
  width: max-content;
  max-width: 100%;
  padding: 2px;
  border-radius: var(--radius-control);
  background: var(--raised);
  height: var(--control-height);
  align-items: center;
}
.segmented button {
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: var(--fs-small);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.empty {
  display: grid;
  place-items: center;
  min-height: 76px;
  padding: 16px;
  border: 1px dashed var(--control);
  border-radius: var(--radius-control);
  color: var(--muted);
  text-align: center;
  grid-column: 1 / -1;
  width: 100%;
}

/* ---------- Institutional Order Ticket Modal ([data-ui="order-modal"]) ---------- */
.order-modal-backdrop[data-ui] {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11, 15, 23, 0.56);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}
.order-modal-dialog[data-ui] {
  width: 100%;
  max-width: 660px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: 0 20px 44px rgba(11, 15, 23, 0.22);
  overflow: hidden;
}
.order-modal-head[data-ui] {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px 14px;
  background: var(--ground);
  border-bottom: 1px solid var(--border);
}
.order-modal-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.order-modal-title-row h2 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.order-modal-quote-strip[data-ui] {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.order-quote-cell[data-ui] {
  padding: 10px 16px;
  min-width: 0;
}
.order-quote-cell[data-ui] + .order-quote-cell[data-ui] {
  border-left: 1px solid var(--rule);
}
.order-quote-label {
  font-size: 12px;
  color: var(--muted);
  display: block;
}
.order-quote-val {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-top: 2px;
  display: block;
}
.order-modal-body[data-ui] {
  padding: 18px 22px 20px;
  display: grid;
  gap: 14px;
}
.order-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.order-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.order-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.order-field-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.order-field-hint {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.order-sizing-well[data-ui] {
  background: var(--ground);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 12px 14px;
  display: grid;
  gap: 10px;
}
.order-sizing-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.order-sizing-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
.lot-presets {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.lot-preset-btn[data-ui] {
  min-height: 24px;
  min-width: 24px;
  height: 26px;
  padding: 0 8px;
  border-radius: 4px;
  border: 1px solid var(--control);
  background: var(--surface);
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
}
.lot-preset-btn[data-ui]:hover {
  background: var(--active);
}
.lot-preset-btn[data-ui].active {
  background: var(--primary);
  color: var(--primary-ink);
  border-color: var(--primary);
}
.lot-stepper[data-ui] {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 34px;
  align-items: center;
}
.lot-step-btn[data-ui] {
  height: var(--control-height);
  border: 1px solid var(--control);
  background: var(--raised);
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.lot-step-btn[data-ui]:first-child {
  border-radius: var(--radius-control) 0 0 var(--radius-control);
  border-right: 0;
}
.lot-step-btn[data-ui]:last-child {
  border-radius: 0 var(--radius-control) var(--radius-control) 0;
  border-left: 0;
}
.lot-step-btn[data-ui]:hover {
  background: var(--active);
}
.lot-stepper[data-ui] .input {
  border-radius: 0;
  text-align: center;
  font-weight: 700;
  padding: 0 6px;
}
.order-telemetry-matrix[data-ui] {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  background: var(--ground);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  overflow: hidden;
}
.order-telemetry-cell[data-ui] {
  padding: 10px 14px;
  min-width: 0;
}
.order-telemetry-cell[data-ui]:nth-child(2n) {
  border-left: 1px solid var(--border);
}
.order-telemetry-cell[data-ui]:nth-child(n + 3) {
  border-top: 1px solid var(--border);
}
.order-telemetry-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.order-telemetry-val {
  margin-top: 3px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}
.order-telemetry-sub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.order-error-banner[data-ui] {
  display: none;
  padding: 10px 12px;
  border-radius: var(--radius-control);
  background: var(--pill-negative-bg);
  color: var(--pill-negative-ink);
  border: 1px solid rgba(185, 28, 34, 0.3);
  font-size: 13px;
  font-weight: 500;
}
.order-modal-foot[data-ui] {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 6px;
  flex-wrap: wrap;
}

/* ---------- login screen ---------- */
.auth-shell {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 28px;
}
.auth-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.auth-form {
  display: grid;
  gap: 16px;
  margin-top: 24px;
}
.field {
  display: grid;
  gap: 8px;
}
.field label {
  font-size: var(--fs-body);
  font-weight: 500;
  color: var(--text);
}
.field .input {
  height: 40px;
  width: 100%;
}
.auth-error {
  padding: 10px 12px;
  border-radius: var(--radius-control);
  border: 1px solid var(--negative);
  border-left-width: 4px; /* shape cue, not colour alone */
  background: var(--pill-negative-bg);
  color: var(--pill-negative-ink);
  font-weight: 500;
  font-size: var(--fs-small);
  display: none;
}
.input[aria-invalid="true"] { border-color: var(--negative); border-width: 2px; }
.auth-error:focus-visible { outline: 2px solid var(--chart-1); outline-offset: 2px; }
.auth-error:empty { display: none; }
.show-pw { display: inline-flex; align-items: center; gap: 8px; min-height: 24px; font-size: var(--fs-small); font-weight: 400; color: var(--muted); cursor: pointer; }
.show-pw input { width: 18px; height: 18px; margin: 0; }
.auth-error.visible {
  display: block;
}
.auth-foot {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
  font-size: var(--fs-small);
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

/* ---------- Institutional Command Ribbon, Gate-1 Strip & Multi-Tab Workspace ---------- */
.cmd-ribbon {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 14px;
  margin-bottom: 14px;
  background: #0b0f17;
  color: #f8fafc;
  border-radius: var(--radius-card);
  border: 1px solid #1e293b;
  font-size: 12px;
}
.cmd-ribbon-left,
.cmd-ribbon-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.cmd-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 9px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  color: #e2e8f0;
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.cmd-pill strong {
  color: #ffffff;
  font-weight: 700;
}
.cmd-pill.emerald {
  background: rgba(16, 185, 129, 0.16);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.32);
}
.cmd-pill.blue {
  background: rgba(59, 130, 246, 0.18);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.32);
}
.cmd-pill.amber {
  background: rgba(245, 158, 11, 0.18);
  color: #fcd34d;
  border: 1px solid rgba(245, 158, 11, 0.32);
}
.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.28);
  flex: none;
}

.grad-strip {
  display: grid;
  grid-template-columns: minmax(260px, 1.4fr) repeat(4, minmax(0, 1fr));
  gap: 14px;
  align-items: center;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  border: 1px solid var(--border);
  border-left: 4px solid var(--chart-1);
  border-radius: var(--radius-card);
  padding: 12px 18px;
}
.grad-main-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
.grad-bar-track {
  width: 100%;
  height: 7px;
  background: var(--raised);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 6px;
}
.grad-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #1d5fbf 0%, #136f3e 100%);
  border-radius: 999px;
}
.grad-stat {
  border-left: 1px solid var(--rule);
  padding-left: 14px;
  min-width: 0;
}
.grad-stat-label {
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 500;
}
.grad-stat-val {
  margin-top: 2px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}
.grad-stat-sub {
  margin-top: 1px;
  font-size: 11.5px;
  color: var(--muted);
}

.workspace-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 6px 8px;
}
.ws-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.ws-tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 0 13px;
  border-radius: 6px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--t-hover) ease, color var(--t-hover) ease;
}
.ws-tab-btn:hover {
  background: var(--raised);
  color: var(--text);
}
.ws-tab-btn[aria-selected="true"] {
  background: var(--primary);
  color: var(--primary-ink);
}
.ws-tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 18px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: rgba(15, 23, 42, 0.08);
  color: inherit;
}
.ws-tab-btn[aria-selected="true"] .ws-tab-count {
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
}

.prob-meter {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}
.prob-bar-track {
  width: 68px;
  height: 5px;
  background: var(--raised);
  border-radius: 999px;
  overflow: hidden;
  flex: none;
}
.prob-bar-fill {
  height: 100%;
  background: var(--positive);
  border-radius: 999px;
}
.lifecycle-steps {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 3px;
}
.lc-step {
  font-size: 12px;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--raised);
  color: var(--muted);
  font-weight: 600;
}
.lc-step.done {
  background: var(--pill-positive-bg);
  color: var(--pill-positive-ink);
}
.lc-step.active {
  background: #dbeafe;
  color: #1e40af;
}
.lc-step.stopped {
  background: var(--pill-negative-bg);
  color: var(--pill-negative-ink);
}

/* ---------- responsive tablet & phone rules ---------- */
.mobile-watchlist {
  display: none;
}
@media (max-width: 960px) {
  .span-6 { grid-column: span 12; }
}
@media (max-width: 860px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    padding-bottom: 64px;
  }
  .rail {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    height: 58px;
    width: 100%;
    flex-direction: row;
    justify-content: space-around;
    padding: 4px 8px;
    border-right: 0;
    border-top: 1px solid var(--border);
    background: var(--surface);
    z-index: 30;
  }
  .rail-brand, .rail-sep, .rail-bottom {
    display: none;
  }
  .rail-btn {
    width: auto;
    min-width: 64px;
    height: 46px;
    padding: 4px 8px;
  }
  .rail-btn .rail-label {
    display: block;
  }
  .rail-btn[aria-current="page"]::before {
    display: none;
  }
  .canvas {
    padding: 16px;
  }
  .title-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .kpis {
    grid-auto-flow: row;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .kpi + .kpi { border-left: 0; }
  .kpi:nth-child(n + 3) { border-top: 1px solid var(--border); }
  .kpi:nth-child(2n) { border-left: 1px solid var(--border); }
  .chart-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin: -16px -16px 12px;
    padding: 0;
  }
  .chart-tab {
    padding: 12px 14px;
    border-bottom: 1px solid var(--rule);
  }
  .chart-tab:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }
  .chart-tab[aria-selected="true"] {
    background: var(--active);
  }
  .chart-tab[aria-selected="true"]::after {
    content: none;
  }
}
@media (max-width: 640px) {
  :root {
    --fs-kpi: 20px;
    --card-pad: 16px;
  }
  .desktop-watchlist {
    display: none;
  }
  .mobile-watchlist {
    display: flex;
    flex-direction: column;
  }
  .watchlist-table {
    table-layout: auto;
    min-width: 620px;
  }
  .kpi {
    padding: 12px 14px;
  }
  .chart-tab .kpi-value {
    font-size: 20px;
  }
  .row-title, .row-sub {
    white-space: normal;
  }
  .header-actions {
    width: 100%;
  }
  .stamp {
    width: 100%;
    margin-bottom: 2px;
  }
  .order-grid-3, .order-grid-4, .order-telemetry-matrix[data-ui], .order-modal-quote-strip[data-ui] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation: none !important; scroll-behavior: auto !important; }
}

/* Deep-link targets: keep anchored panels clear of the viewport edge and show focus when targeted */
[id$="-section"] { scroll-margin-top: 16px; }
[id$="-section"]:focus-visible { outline: 2px solid var(--chart-1); outline-offset: 2px; }
a.rail-btn { text-decoration: none; }

/* ---------- WCAG 2.2 additions: reflow, scroll padding, forced colours ---------- */
@media (max-width: 860px) {
  html { scroll-padding-bottom: 72px; } /* the fixed bottom rail must not hide a focused control (2.4.11) */
}
@media (max-width: 400px) { /* reflow at 320 CSS px without two-dimensional page scroll */
  .canvas { padding: 12px; }
  .rail { padding: 4px; gap: 0; }
  .rail-btn { min-width: 0; flex: 1 1 0; padding: 4px 2px; }
  .rail-btn .rail-label { font-size: 11px; white-space: normal; text-align: center; }
  .kpis { grid-template-columns: minmax(0, 1fr); }
  .kpi:nth-child(2n) { border-left: 0; }
  .kpi + .kpi { border-top: 1px solid var(--border); }
  .auth-card { padding: 20px 16px; }
  .auth-foot { flex-wrap: wrap; }
  .header-actions .btn { flex: 1 1 auto; }
  .ws-tabs { width: 100%; }
}
@media (forced-colors: active) {
  :focus-visible, .input:focus-visible { outline: 2px solid Highlight; outline-offset: 2px; box-shadow: none; }
  .btn, .input, .panel, .stamp, .auth-card, .lot-preset-btn[data-ui], .ws-tab-btn, .chart-tab { border: 1px solid CanvasText; }
  .btn.primary, .btn.primary:disabled { background: ButtonFace; color: ButtonText; border: 1px solid ButtonText; }
  .btn:disabled { color: GrayText; border-color: GrayText; opacity: 1; }
  .ws-tab-btn[aria-selected="true"], .chart-tab[aria-selected="true"], .rail-btn[aria-current="page"], tbody tr[aria-selected="true"] td { background: Highlight; color: HighlightText; forced-color-adjust: none; }
  .rail-btn[aria-current="page"]::before { background: Highlight; }
  .auth-error { border: 2px solid CanvasText; background: Canvas; color: CanvasText; }
  .rail-brand { background: CanvasText; color: Canvas; forced-color-adjust: none; }
  .cmd-ribbon, .cmd-pill { background: Canvas; color: CanvasText; border: 1px solid CanvasText; }
  .prob-bar-track, .prob-bar-fill { background: CanvasText; forced-color-adjust: none; }
  .prob-bar-track { background: Canvas; border: 1px solid CanvasText; }
  .lc-step, .ws-tab-count { border: 1px solid CanvasText; }
  .live-dot { background: CanvasText; box-shadow: none; }
  svg text { fill: CanvasText; }
}
