/* Farm cockpit: Bridge tokens inverted for a dark control-room surface (05-OPERATOR-WEB-UI 3.1). */
:root {
  --bg: #0b0d1a;
  --surface: #10132b;
  --surface-2: #171a36;
  --line: #2a2e52;
  --text: #e8e9f5;
  --muted: #9a9fbf;
  --accent: #7072d6;
  --ok: #15803d;
  --warn: #b45309;
  --fail: #b91c1c;
  --radius: 6px;
  --mono: ui-monospace, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h2 { font-size: 14px; margin: 12px 0 6px; }
h3 { font-size: 13px; margin: 10px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.mono, code, pre, textarea { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
a { color: var(--accent); }

/* Controls */
button, input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--radius);
}
button { padding: 4px 10px; cursor: pointer; white-space: nowrap; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { background: var(--fail); border-color: var(--fail); color: #fff; }
button.ghost { background: transparent; padding: 2px 6px; }
input, select { padding: 3px 6px; }
input[type=checkbox] { accent-color: var(--accent); }
input:invalid:not(:placeholder-shown), input.invalid { border-color: var(--fail); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: inline-flex; gap: 6px; align-items: center; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); }

/* In-flight spinner: buttons are disabled while their request runs (3.8). */
.busy { position: relative; color: transparent !important; }
.busy::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 12px; height: 12px;
  border: 2px solid var(--muted); border-top-color: var(--text); border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Badges: status colours are fills with white text, never coloured text (3.1). */
.badge {
  display: inline-block; padding: 1px 7px; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge.green, .badge.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.badge.amber, .badge.warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.badge.red, .badge.fail { background: var(--fail); border-color: var(--fail); color: #fff; }
.banner { padding: 6px 10px; border-radius: var(--radius); margin: 6px 0; }
.banner.amber { background: var(--warn); color: #fff; }
.banner.red { background: var(--fail); color: #fff; white-space: pre-wrap; }

/* Layout */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; gap: 10px; align-items: center;
  padding: 6px 12px; background: var(--surface-2); border-bottom: 1px solid var(--line);
}
.brand { letter-spacing: .08em; color: var(--accent); }
#btn-sync { margin-left: auto; }
#operator-handle { width: 130px; }
.gauge { display: flex; align-items: center; gap: 6px; }
.gauge-track { width: 90px; height: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.gauge-fill { height: 100%; width: 0; background: var(--ok); }
.gauge.amber .gauge-fill { background: var(--warn); }
.gauge.red .gauge-fill { background: var(--fail); }

.tabs { display: flex; gap: 2px; padding: 0 12px; background: var(--surface); border-bottom: 1px solid var(--line); }
.tabs button, .subtabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; padding: 7px 12px; color: var(--muted); }
.tabs button[aria-selected=true], .subtabs button[aria-selected=true] { color: var(--text); border-bottom-color: var(--accent); }
main { padding: 8px 12px 40px; }
.panel { min-width: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.end { justify-content: flex-end; }
.cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 1fr); gap: 12px; align-items: start; }
#tab-audit .cols { grid-template-columns: minmax(0, 3fr) minmax(260px, 1fr); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; margin: 8px 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.cards .card dl { display: grid; grid-template-columns: auto auto; gap: 2px 10px; margin: 4px 0 0; }
.cards dt { color: var(--muted); }
.cards dd { margin: 0; text-align: right; font-family: var(--mono); }

/* QC studio: list on the left, detail on the right */
.split { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 12px; }
.split[hidden] { display: none; }
.list-pane { position: sticky; top: 84px; align-self: start; max-height: calc(100vh - 96px); display: flex; flex-direction: column; }
.list-pane .row input { flex: 1; min-width: 0; }
.list { list-style: none; margin: 0; padding: 0; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.list li { display: flex; gap: 6px; align-items: center; min-height: 28px; padding: 2px 8px; border-bottom: 1px solid var(--line); cursor: pointer; }
.list li[aria-selected=true] { background: var(--surface-2); box-shadow: inset 3px 0 var(--accent); }
.list li .grow { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor { display: grid; grid-template-columns: 30% 70%; gap: 8px; }
.editor textarea { width: 100%; min-height: 52vh; padding: 8px; resize: vertical; line-height: 1.5; tab-size: 2; }
.facts { margin: 0; padding: 6px 6px 6px 24px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; max-height: 56vh; }
.facts li { margin-bottom: 6px; }
.issues { margin: 2px 0; color: var(--muted); }
pre { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; max-height: 40vh; overflow: auto; white-space: pre-wrap; }
.player video { width: 100%; max-height: 52vh; background: #000; border-radius: var(--radius); }

/* High-density tables: 28 px rows, sticky headers (1.3). */
.grid { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); margin: 4px 0 10px; }
.grid th, .grid td { height: 28px; padding: 3px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.grid th { position: sticky; top: 40px; z-index: 1; background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: 12px; }
.grid td.wrap { white-space: normal; min-width: 200px; }
.grid td.num { text-align: right; font-family: var(--mono); }
.grid tbody tr:hover { background: var(--surface-2); }
.grid tr.row-red td:first-child { box-shadow: inset 3px 0 var(--fail); }
.grid tr.row-amber td:first-child { box-shadow: inset 3px 0 var(--warn); }
.grid tr.selected { outline: 1px solid var(--accent); }
.kv td:first-child { color: var(--muted); }
#ops-panel dl { display: grid; grid-template-columns: max-content 1fr; gap: 2px 10px; margin: 0; }
#ops-panel dd { margin: 0; overflow-wrap: anywhere; }
#tab-fleet, #tab-publishing { overflow-x: auto; }

.alerts { display: grid; gap: 4px; margin-bottom: 6px; }
.alert { display: flex; gap: 10px; align-items: center; padding: 5px 10px; border-radius: var(--radius); color: #fff; }
.alert.red { background: var(--fail); }
.alert.amber { background: var(--warn); }
.alert button { background: rgba(0, 0, 0, .25); color: #fff; border-color: rgba(255, 255, 255, .4); }

.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chips button[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Dialogs, popovers and the decoupling drawer */
dialog {
  background: var(--surface); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 16px; min-width: 360px; max-width: min(720px, 94vw);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .6);
}
dialog::backdrop { background: rgba(5, 6, 15, .7); }
dialog form > label { display: flex; margin: 6px 0; }
dialog form > label > input:not([type=checkbox]) { flex: 1; }
dialog.drawer { margin: 0 0 0 auto; height: 100vh; max-height: 100vh; border-radius: 0; width: 440px; }
dialog footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }

.toasts { position: fixed; right: 12px; bottom: 12px; display: grid; gap: 6px; z-index: 20; max-width: 520px; }
.toast { background: var(--surface-2); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: var(--radius); padding: 8px 12px; box-shadow: 0 6px 20px rgba(0, 0, 0, .5); white-space: pre-wrap; }
.toast.ok { border-left-color: var(--ok); }
.toast.fail { border-left-color: var(--fail); }
.toast-code { font-family: var(--mono); }

@media (max-width: 1100px) {
  .split, .cols, #tab-audit .cols { grid-template-columns: 1fr; }
  .list-pane { position: static; max-height: 40vh; }
}
