:root {
  --bg: #f5f8fc;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #e5e7eb;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #0369a1;
  --primary-2: #0284c7;
  --active: #a5f3fc;
  --success: #047857;
  --warning: #d97706;
  --danger: #be123c;
  --shadow: 0 20px 80px rgba(15, 23, 42, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: linear-gradient(180deg, #f8fafc 0%, #f0f9ff 100%);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  right: 24px;
  top: 24px;
  z-index: 50;
  display: grid;
  gap: 10px;
}

.toast-item {
  min-width: 260px;
  max-width: 420px;
  padding: 14px 16px;
  border-radius: 8px;
  color: #f8fafc;
  border: 1px solid #334155;
  background: #0f172a;
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.22);
  font-weight: 600;
}

.toast-item.error {
  color: #fff1f2;
  border-color: #fb7185;
  background: #9f1239;
}

.toast-item.ok {
  color: #ecfdf5;
  border-color: #34d399;
  background: #065f46;
}

.toast-item.info {
  color: #f0f9ff;
  border-color: #38bdf8;
  background: #075985;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(440px, 100%);
  padding: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  color: #fff;
  border-radius: 9999px;
  background: #0f172a;
  font-size: 28px;
  font-weight: 600;
}

.login-panel h1 {
  margin: 20px 0 8px;
  font-size: 2.2rem;
}

.login-panel p,
.panel p,
.topbar p {
  color: var(--muted);
  margin: 0;
}

.login-form,
.stack-form {
  display: grid;
  gap: 16px;
  margin-top: 26px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 600;
}

input,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 12px 14px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(3, 105, 161, 0.1);
}

.login-hint {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--muted);
  margin-top: 18px;
  font-size: 0.82rem;
}

.login-hint span {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 9999px;
  background: var(--surface-soft);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
  color: #ffffff;
  background: #0f172a;
  border-right: 1px solid #1e293b;
  box-shadow: 0 20px 80px rgba(15, 23, 42, 0.12);
}

.sidebar-brand {
  padding: 10px 6px 18px;
  border-bottom: 1px solid #334155;
}

.brand-title {
  font-size: 1.7rem;
  font-weight: 600;
  color: #ffffff;
}

.brand-subtitle {
  margin-top: 4px;
  color: var(--active);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: uppercase;
}

.nav-menu {
  display: grid;
  gap: 8px;
}

.nav-menu button {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  text-align: left;
  color: #cbd5e1;
  background: transparent;
  font-weight: 600;
}

.nav-menu button.active {
  color: #0c4a6e;
  background: var(--active);
}

.nav-menu button:hover {
  color: #ffffff;
  background: #1e293b;
}

.sidebar-status {
  padding: 16px;
  border: 1px solid #334155;
  border-radius: 12px;
  background: #111c31;
}

.status-title {
  color: var(--active);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0;
  font-size: 0.9rem;
}

.status-row span {
  color: #cbd5e1;
}

.status-row b {
  color: #ffffff;
}

.status-row b.ok,
span.ok,
b.ok {
  color: var(--success);
}

.status-row b.warn,
span.warn,
b.warn {
  color: var(--warning);
}

.status-row b.danger,
span.danger,
b.danger {
  color: var(--danger);
}

.logout-btn {
  margin-top: auto;
}

.sidebar .ghost-btn {
  color: #ffffff;
  border-color: #334155;
  background: transparent;
}

.sidebar .ghost-btn:hover {
  color: #0c4a6e;
  background: var(--active);
}

.content {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 20px 24px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  margin-bottom: 24px;
}

.topbar h2 {
  margin: 0 0 4px;
  font-size: 1.5rem;
  font-weight: 600;
}

.grid {
  display: grid;
  gap: 22px;
}

.two-col {
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
}

.monitor-grid {
  grid-template-columns: minmax(0, 1.7fr) minmax(340px, 0.8fr);
  align-items: stretch;
}

.panel {
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 20px;
}

.panel h3 {
  margin: 0 0 6px;
  font-size: 1.125rem;
  font-weight: 600;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 6px;
  border-radius: 9999px;
  background: var(--surface-soft);
  margin-bottom: 18px;
}

.segmented button {
  border: 0;
  border-radius: 9999px;
  background: transparent;
  color: var(--muted);
  min-height: 44px;
  padding: 10px 16px;
  font-weight: 600;
}

.segmented button.active {
  background: #ffffff;
  color: var(--primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.controls-row,
.button-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.controls-row {
  margin-bottom: 18px;
}

.controls-row label:first-child {
  flex: 1;
}

.toggle-line {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
}

.toggle-line input {
  width: auto;
}

.source-panel {
  display: grid;
  gap: 14px;
}

.source-config-panel {
  margin-top: 22px;
}

.source-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.8fr) minmax(320px, 1.2fr);
  gap: 22px;
  align-items: start;
}

.dropzone {
  min-height: 120px;
  display: grid;
  place-items: center;
  padding: 18px;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  background: #f8fafc;
  text-align: center;
}

.dropzone input {
  max-width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
}

.primary-btn,
.ghost-btn,
.danger-btn {
  border: 1px solid transparent;
  border-radius: 9999px;
  min-height: 44px;
  padding: 12px 24px;
  font-size: 0.875rem;
  font-weight: 600;
}

.primary-btn {
  color: #fff;
  background: #0f172a;
  box-shadow: 0 10px 15px -3px rgba(15, 23, 42, 0.15), 0 4px 6px -4px rgba(15, 23, 42, 0.15);
}

.primary-btn:hover {
  background: #1e293b;
}

.ghost-btn {
  color: var(--primary);
  border-color: var(--border);
  background: #fff;
}

.ghost-btn:hover {
  color: #0c4a6e;
  background: #f0f9ff;
  border-color: #cbd5e1;
}

.danger-btn {
  color: #fff;
  background: var(--danger);
}

.result-card {
  min-height: 236px;
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 20px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #f8fafc;
}

.result-card.compact {
  min-height: 130px;
  margin-top: 18px;
}

.result-card.valid {
  border-color: #a7f3d0;
  background: #ecfdf5;
}

.result-card.blocked {
  border-color: #fde68a;
  background: #fef3c7;
}

.result-card.unknown {
  border-color: #fbcfe8;
  background: #ffe4e6;
}

.badge {
  width: fit-content;
  padding: 4px 12px;
  border-radius: 9999px;
  color: var(--primary);
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  font-size: 0.75rem;
  font-weight: 600;
}

.result-card.valid .badge {
  color: var(--success);
  background: #ecfdf5;
  border-color: #a7f3d0;
}

.result-card.blocked .badge {
  color: #92400e;
  background: #fef3c7;
  border-color: #fde68a;
}

.result-card.unknown .badge {
  color: var(--danger);
  background: #ffe4e6;
  border-color: #fbcfe8;
}

.plate-display {
  padding: 16px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--border);
  font-size: 2.1rem;
  font-weight: 600;
  letter-spacing: 0;
  text-align: center;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.detail-row span {
  color: var(--muted);
}

.detail-row b {
  text-align: right;
}

.media-panel {
  margin-top: 0;
}

.live-panel {
  color: #ffffff;
  background: #0f172a;
  border-color: #334155;
  box-shadow: 0 10px 15px -3px rgba(15, 23, 42, 0.15), 0 4px 6px -4px rgba(15, 23, 42, 0.15);
}

.live-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.live-header h3 {
  color: #ffffff;
}

.eyebrow {
  display: block;
  color: var(--active);
  font-size: 0.75rem;
  font-weight: 600;
}

.live-badge {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 9999px;
  border: 1px solid #475569;
  color: #cbd5e1;
  background: #1e293b;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.live-badge i {
  width: 8px;
  height: 8px;
  border-radius: 9999px;
  background: #64748b;
}

.live-badge.active {
  color: #0c4a6e;
  background: var(--active);
  border-color: var(--active);
}

.live-badge.active i,
.live-badge.ready i {
  background: var(--success);
}

.live-badge.ready {
  color: var(--success);
  background: #ecfdf5;
  border-color: #a7f3d0;
}

.live-badge.warming {
  color: #92400e;
  background: #fffbeb;
  border-color: #fde68a;
}

.live-badge.warming i {
  background: var(--warning);
}

.media-stage {
  min-height: 520px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  background: #020617;
  border: 1px solid #1e293b;
}

.media-stage img {
  width: 100%;
  display: block;
  object-fit: contain;
}

.stream-frame {
  position: relative;
  width: 100%;
  min-height: 520px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #020617;
}

.stream-frame img {
  width: 100%;
  height: 100%;
  min-height: 520px;
  display: block;
  object-fit: contain;
}

.video-preview,
.webcam-preview {
  width: 100%;
  height: 100%;
  min-height: 520px;
  display: block;
  object-fit: contain;
}

.field-note {
  display: block;
  margin-top: 8px;
  color: #64748b;
  font-size: 13px;
  line-height: 1.45;
}

.stream-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(165, 243, 252, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(165, 243, 252, 0.08) 1px, transparent 1px);
  background-size: 42px 42px;
  opacity: 0.55;
}

.stream-scan-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 2;
  width: 24%;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(165, 243, 252, 0.28), transparent);
  transform: translateX(-130%);
  animation: streamSweep 2.2s ease-in-out infinite;
}

.stream-overlay-chip {
  position: absolute;
  right: 18px;
  top: 18px;
  z-index: 3;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  border-radius: 9999px;
  color: #0c4a6e;
  background: rgba(240, 249, 255, 0.94);
  border: 1px solid var(--active);
  box-shadow: 0 10px 15px -3px rgba(15, 23, 42, 0.15), 0 4px 6px -4px rgba(15, 23, 42, 0.15);
}

.empty-state {
  color: #cbd5e1;
  font-weight: 600;
}

.scanner-empty {
  width: 100%;
  min-height: 520px;
  display: grid;
  place-items: center;
  gap: 18px;
  padding: 34px;
  color: #475569;
  background:
    linear-gradient(rgba(255, 255, 255, 0.5) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.5) 1px, transparent 1px),
    linear-gradient(135deg, #e0f7fb 0%, #eaf2ff 100%);
  background-size: 36px 36px, 36px 36px, 100% 100%;
}

.scanner-empty p {
  max-width: 440px;
  color: #64748b;
  text-align: center;
  font-weight: 600;
}

.scanner-card {
  width: min(560px, 100%);
  display: grid;
  justify-items: center;
  gap: 18px;
  animation: scannerFloat 4s ease-in-out infinite;
}

.scanner-device {
  position: relative;
  width: min(520px, 100%);
  aspect-ratio: 16 / 7;
  display: grid;
  place-items: center;
  padding: 20px 34px;
  border-radius: 34px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 20px 80px rgba(15, 23, 42, 0.12);
}

.scanner-device::before {
  content: "";
  position: absolute;
  inset: -42px 24px;
  z-index: 0;
  border-radius: 32px;
  background: rgba(255, 255, 255, 0.38);
  box-shadow: 0 40px 80px rgba(15, 23, 42, 0.12);
}

.scanner-screen {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: 28px;
  background: linear-gradient(135deg, #0f172a, #1e293b);
  box-shadow: inset 0 0 0 1px rgba(165, 243, 252, 0.28);
}

.scanner-glow {
  position: absolute;
  inset: 26px 62px;
  z-index: 0;
  border-radius: 28px;
  background: rgba(165, 243, 252, 0.35);
  filter: blur(18px);
  animation: glowPulse 2.8s ease-in-out infinite;
}

.scanner-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 38%;
  background: linear-gradient(90deg, transparent, rgba(165, 243, 252, 0.22), transparent);
  transform: translateX(-120%);
  animation: scannerSweep 2.4s ease-in-out infinite;
}

.scan-chip {
  position: absolute;
  z-index: 2;
  right: -14px;
  top: 50%;
  min-height: 58px;
  display: inline-flex;
  align-items: center;
  gap: 14px;
  padding: 14px 22px;
  border-radius: 9999px;
  color: #334155;
  background: rgba(248, 250, 252, 0.94);
  border: 1px solid var(--active);
  box-shadow: 0 10px 15px -3px rgba(15, 23, 42, 0.15), 0 4px 6px -4px rgba(15, 23, 42, 0.15);
  transform: translateY(-50%);
}

.scan-icon {
  width: 20px;
  height: 20px;
  border: 2px dashed #0284c7;
  border-radius: 6px;
  animation: iconPulse 1.5s ease-in-out infinite;
}

.engine-pill {
  position: relative;
  z-index: 2;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  border-radius: 9999px;
  color: var(--active);
  background: #0f172a;
  border: 1px solid #1e293b;
  box-shadow: 0 10px 15px -3px rgba(15, 23, 42, 0.15), 0 4px 6px -4px rgba(15, 23, 42, 0.15);
}

.engine-pill i {
  width: 10px;
  height: 10px;
  border-radius: 9999px;
  background: #34d399;
  box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.6);
  animation: dotPulse 1.6s ease-in-out infinite;
}

@keyframes scannerFloat {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

@keyframes scannerSweep {
  0% {
    transform: translateX(-120%);
  }
  55% {
    transform: translateX(280%);
  }
  100% {
    transform: translateX(280%);
  }
}

@keyframes streamSweep {
  0% {
    transform: translateX(-130%);
  }
  55% {
    transform: translateX(520%);
  }
  100% {
    transform: translateX(520%);
  }
}

@keyframes glowPulse {
  0%,
  100% {
    opacity: 0.45;
  }
  50% {
    opacity: 0.85;
  }
}

@keyframes iconPulse {
  0%,
  100% {
    opacity: 0.55;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.08);
  }
}

@keyframes dotPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.6);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(52, 211, 153, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(52, 211, 153, 0);
  }
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

.inline-select {
  min-width: 112px;
  padding: 8px 10px;
}

.table-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.small-btn {
  min-height: 34px;
  padding: 8px 14px;
}

.logs-list {
  display: grid;
  gap: 14px;
}

.log-item {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
}

.log-item img {
  width: 140px;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border-radius: 8px;
  background: #e2e8f0;
}

.log-no-image {
  width: 140px;
  aspect-ratio: 16 / 10;
  display: grid;
  place-items: center;
  color: var(--muted);
  border-radius: 8px;
  background: #e2e8f0;
  font-size: 0.82rem;
  font-weight: 800;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .two-col {
    grid-template-columns: 1fr;
  }

  .monitor-grid,
  .source-layout {
    grid-template-columns: 1fr;
  }

  .scanner-empty {
    min-height: 420px;
    padding: 18px;
  }

  .stream-frame,
  .stream-frame img {
    min-height: 420px;
  }

  .stream-overlay-chip {
    left: 14px;
    right: 14px;
    justify-content: center;
  }

  .scanner-device {
    padding: 16px;
    border-radius: 24px;
  }

  .scanner-device::before {
    inset: -28px 18px;
  }

  .scan-chip {
    position: relative;
    right: auto;
    top: auto;
    margin-top: 14px;
    transform: none;
  }

  .topbar {
    border-radius: 8px;
    align-items: flex-start;
    flex-direction: column;
  }

  .log-item {
    grid-template-columns: 1fr;
  }

  .log-item img,
  .log-no-image {
    width: 100%;
  }
}
