:root {
  --bg-canvas: #09090b;
  --bg-surface: #18181b;
  --bg-surface-2: #121215;
  --bg-elevated: #202024;
  --border-hairline: #27272a;
  --border-strong: #3f3f46;
  --text-primary: #f4f4f5;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  --accent-blue: #2563eb;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

/* Header & Navigation */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(9, 9, 11, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-hairline);
}

.topbar-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 28px;
  height: 20px;
  border-radius: 3px;
  border: 1.5px solid #e4e4e7;
  background: #fafafa;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.brand-mark-stripe {
  height: 5px;
  background: #1d4ed8;
}

.brand-mark-code {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #09090b;
  font-family: var(--font-mono);
  font-size: 7px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.brand-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.brand-subtitle {
  font-size: 11px;
  color: var(--text-muted);
}

.nav-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: 6px;
  padding: 3px;
  overflow-x: auto;
  max-width: 100%;
}

.nav-tab {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 11px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.nav-tab:hover {
  color: var(--text-primary);
}

.nav-tab.active {
  background: var(--text-primary);
  color: var(--bg-canvas);
}

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

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--border-hairline);
  background: var(--bg-surface);
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}

.dot.ok {
  background: var(--accent-emerald);
}

.dot.warn {
  background: var(--accent-amber);
}

.dot.err {
  background: var(--accent-rose);
}

/* Main Container */
.container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 16px;
}

.view-section {
  display: none;
}

.view-section.active {
  display: block;
}

/* Panels & Cards */
.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: 8px;
}

.panel-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.panel-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.panel-body {
  padding: 14px;
}

/* Asymmetric Monitor Grid */
.monitor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(320px, 1fr);
  gap: 14px;
  align-items: start;
}

@media (max-width: 1024px) {
  .monitor-grid {
    grid-template-columns: 1fr;
  }
}

/* Video Stage */
.stage-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-hairline);
  background: var(--bg-surface-2);
  border-radius: 8px 8px 0 0;
}

.btn-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.btn:hover:not(:disabled) {
  background: #2c2c32;
  border-color: #52525b;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--text-primary);
  color: var(--bg-canvas);
  border-color: var(--text-primary);
}

.btn-primary:hover:not(:disabled) {
  background: #e4e4e7;
  border-color: #e4e4e7;
}

.btn-emerald {
  background: #065f46;
  border-color: var(--accent-emerald);
  color: #ecfdf5;
}

.btn-emerald:hover:not(:disabled) {
  background: #047857;
}

.btn-amber {
  background: #451a03;
  border-color: var(--accent-amber);
  color: #fef3c7;
}

.btn-danger {
  background: #4c0519;
  border-color: #9f1239;
  color: #ffe4e6;
}

.btn-sm {
  padding: 4px 8px;
  font-size: 11px;
}

.btn-active-source {
  background: var(--text-primary);
  color: var(--bg-canvas);
  border-color: var(--text-primary);
}

.stage-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #050507;
  overflow: hidden;
  user-select: none;
}

@media (max-width: 640px) {
  .stage-wrap {
    aspect-ratio: 4 / 3;
  }
}

.stage-media {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
}

.stage-media.visible {
  display: block;
}

.overlay-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
  z-index: 4;
}

.stage-hud {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  z-index: 5;
  gap: 8px;
}

.hud-badge {
  background: rgba(9, 9, 11, 0.82);
  border: 1px solid rgba(63, 63, 70, 0.8);
  padding: 4px 8px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-primary);
}

.stage-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border-hairline);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.meter-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 210px;
}

.meter-track {
  flex: 1;
  height: 7px;
  border-radius: 3px;
  background: #27272a;
  overflow: hidden;
  position: relative;
}

.meter-fill {
  height: 100%;
  width: 0%;
  background: var(--accent-emerald);
  transition: width 0.08s linear, background-color 0.1s ease;
}

.meter-threshold-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--accent-amber);
}

/* Line Controls */
.line-controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-secondary);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent-emerald);
  cursor: pointer;
}

input[type="text"],
input[type="number"],
select {
  background: var(--bg-canvas);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  border-radius: 5px;
  padding: 6px 9px;
  font-size: 13px;
  font-family: var(--font-sans);
  outline: none;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
  border-color: var(--accent-emerald);
}

/* Hero Plate Card */
.hero-card {
  padding: 14px;
  border-bottom: 1px solid var(--border-hairline);
}

.hero-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.plate-visual-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.plate-badge {
  min-width: 196px;
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid #e4e4e7;
  background: #f8fafc;
  color: #09090b;
  display: inline-flex;
  flex-direction: column;
}

.plate-badge.mercosur .plate-header {
  background: #1d4ed8;
  color: #ffffff;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-align: center;
  padding: 3px 8px;
  text-transform: uppercase;
}

.plate-badge.classic {
  background: #09090b;
  color: #fafafa;
  border: 2px solid #f4f4f5;
}

.plate-badge.classic .plate-header {
  background: #09090b;
  color: #d4d4d8;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-align: center;
  padding: 3px 8px 0;
  text-transform: uppercase;
}

.plate-badge.special {
  background: #18181b;
  color: #fef3c7;
  border: 2px solid var(--accent-amber);
}

.plate-badge.special .plate-header {
  background: #78350f;
  color: #fef3c7;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-align: center;
  padding: 3px 8px;
  text-transform: uppercase;
}

.plate-digits {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-align: center;
  padding: 7px 14px 9px;
}

.plate-crop-preview {
  width: 124px;
  height: 58px;
  object-fit: cover;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  background: #050507;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-family: var(--font-mono);
  font-weight: 600;
  border: 1px solid transparent;
}

.tag-onnx {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.35);
  color: #34d399;
}

.tag-corrected {
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.35);
  color: #38bdf8;
}

.tag-ai {
  background: rgba(245, 158, 11, 0.14);
  border-color: rgba(245, 158, 11, 0.4);
  color: #fbbf24;
}

.tag-neutral {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  color: var(--text-secondary);
}

.tag-warn {
  background: rgba(244, 63, 94, 0.12);
  border-color: rgba(244, 63, 94, 0.35);
  color: #fb7185;
}

/* Compact KPI Strip */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-bottom: 1px solid var(--border-hairline);
}

.kpi-cell {
  padding: 10px 12px;
  border-right: 1px solid var(--border-hairline);
}

.kpi-cell:last-child {
  border-right: none;
}

.kpi-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.kpi-val {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 2px;
}

.kpi-sub {
  font-size: 11px;
  color: var(--text-secondary);
}

/* Live Feed List */
.feed-list {
  max-height: 390px;
  overflow-y: auto;
}

.feed-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border-hairline);
  cursor: pointer;
  transition: background-color 0.1s ease;
}

.feed-item:hover {
  background: #1f1f24;
}

.feed-item:last-child {
  border-bottom: none;
}

.feed-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.feed-thumb {
  width: 68px;
  height: 32px;
  object-fit: cover;
  border-radius: 3px;
  border: 1px solid var(--border-strong);
  background: #050507;
  flex-shrink: 0;
}

.feed-plate {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-primary);
}

.feed-meta {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* Two column layout for Masks / Settings */
.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

@media (max-width: 900px) {
  .two-col {
    grid-template-columns: 1fr;
  }
}

/* Data Tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.data-table th {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-hairline);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-hairline);
  vertical-align: middle;
}

.data-table tr:hover td {
  background: #1d1d22;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border-hairline);
}

.switch-row:last-child {
  border-bottom: none;
}

.switch-input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-emerald);
  cursor: pointer;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  width: 100%;
  max-width: 720px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  overflow: hidden;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}

.modal-body {
  padding: 14px;
  overflow-y: auto;
}

.modal-frame-img {
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  border-radius: 5px;
  border: 1px solid var(--border-hairline);
  background: #050507;
}

.toast {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 80;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  padding: 9px 14px;
  border-radius: 6px;
  font-size: 12px;
  display: none;
}

.toast.show {
  display: block;
}

.code-block {
  background: var(--bg-canvas);
  border: 1px solid var(--border-hairline);
  border-radius: 6px;
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: #d4d4d8;
  overflow-x: auto;
  white-space: pre;
}
