:root {
  --bg-dark: #090d16;
  --bg-card: #131b2e;
  --bg-card-hover: #1a253e;
  --border-color: rgba(255, 255, 255, 0.08);
  --primary-accent: #38bdf8;
  --primary-glow: rgba(56, 189, 248, 0.25);
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  --purple-color: #a855f7;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --font-sans: 'Outfit', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-sans);
  height: 100vh;
  overflow: hidden;
}

.app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background-color: #0d1322;
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  gap: 2rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  font-size: 1.8rem;
}

.brand-text h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-text .sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
}

.nav-item.active {
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.3);
  color: var(--primary-accent);
}

.sidebar-status-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.system-status-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 0.85rem 1rem;
  border-radius: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 84px;
}

.status-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--text-muted);
}

.status-indicator.online {
  background-color: var(--success-color);
  box-shadow: 0 0 10px var(--success-color);
}

.status-indicator.offline {
  background-color: var(--danger-color);
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.45);
}

.status-indicator.stale {
  background-color: var(--warning-color);
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.45);
}

.status-indicator.disabled {
  background-color: var(--text-muted);
  box-shadow: none;
}

.status-info {
  display: flex;
  flex-direction: column;
}

.status-title {
  font-size: 0.85rem;
  font-weight: 600;
}

.status-detail {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 2rem;
  gap: 1.5rem;
}

.top-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1rem;
}

.page-title h2 {
  font-size: 1.5rem;
  font-weight: 700;
}

.page-title p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.live-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: var(--success-color);
  padding: 0.4rem 0.8rem;
  border-radius: 2rem;
  font-size: 0.75rem;
  font-weight: 600;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  background-color: var(--success-color);
  border-radius: 50%;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.btn {
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.btn-secondary {
  background: var(--bg-card);
  border-color: var(--border-color);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
}

.history-toggle-btn.active {
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.3);
  color: var(--primary-accent);
}

.btn-primary {
  background: var(--primary-accent);
  color: #090d16;
}

.btn-primary:hover {
  box-shadow: 0 0 15px var(--primary-glow);
  transform: translateY(-1px);
}

.btn-success {
  background: var(--success-color);
  color: #042f1f;
}

.btn-success:hover {
  box-shadow: 0 0 15px rgba(16, 185, 129, 0.35);
  transform: translateY(-1px);
}

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

.btn-danger:hover {
  box-shadow: 0 0 15px rgba(239, 68, 68, 0.35);
  transform: translateY(-1px);
}

.btn-sm {
  padding: 0.3rem 0.65rem;
  font-size: 0.75rem;
}

.table-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

/* Tabs */
.tab-content {
  display: none;
  flex-direction: column;
  gap: 1.5rem;
}

.tab-content.active {
  display: flex;
}

/* Metrics Grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.25rem;
}

.camera-count-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 1.25rem;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 1rem;
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.metric-icon {
  width: 48px;
  height: 48px;
  border-radius: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  background: rgba(255, 255, 255, 0.05);
}

.metric-data {
  display: flex;
  flex-direction: column;
}

.metric-value {
  font-size: 1.4rem;
  font-weight: 700;
}

.metric-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Hero Event Card */
.hero-event-card {
  background: linear-gradient(135deg, #162238 0%, #0d1627 100%);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 1rem;
  padding: 1.5rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}

.hero-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.75rem;
}

.hero-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

.hero-body {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.5rem;
}

.hero-item {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.hero-item .label {
  font-size: 0.75rem;
  color: var(--text-muted);

}

.hero-item .value {
  font-size: 1.25rem;
  font-weight: 700;
}

.plate-display {
  background: #facc15;
  color: #000;
  padding: 0.25rem 0.75rem;
  border-radius: 0.4rem;
  font-family: var(--font-mono);
  font-weight: 700;
  display: inline-block;
  text-align: center;
  box-shadow: 0 2px 8px rgba(250, 204, 21, 0.3);
}

.lpr-hero-images {
  display: flex;
  gap: 1rem;
  padding: 0 1.25rem 1.25rem;
  flex-wrap: wrap;
}

.lpr-hero-shot {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 160px;
}

.lpr-hero-shot img {
  max-height: 180px;
  max-width: 320px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: #0b1220;
  object-fit: contain;
}

.lpr-thumb {
  height: 40px;
  max-width: 72px;
  border-radius: 4px;
  object-fit: cover;
  border: 1px solid var(--border-color);
  vertical-align: middle;
}

.lpr-thumb-scene {
  max-width: 88px;
}

.lpr-download {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.lpr-download a {
  color: var(--primary-accent);
  font-size: 0.8rem;
}

/* Cards & Tables */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 1rem;
  padding: 1.5rem;
}

.card-header {
  margin-bottom: 1rem;
}

.card-header.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.table-responsive {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th, .data-table td {
  padding: 0.85rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.data-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
}

.data-table tbody tr:hover {
  background: var(--bg-card-hover);
}

.data-table th.col-inspect,
.data-table td.col-inspect {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--bg-card);
  min-width: 9rem;
  white-space: nowrap;
}

.data-table thead th.col-inspect {
  z-index: 3;
}

.data-table tbody tr:hover td.col-inspect {
  background: var(--bg-card-hover);
}

.data-table tbody tr.txn-row {
  cursor: pointer;
}

.font-mono {
  font-family: var(--font-mono);
}

.text-glowing {
  color: var(--primary-accent);
  text-shadow: 0 0 8px var(--primary-glow);
}

.badge {
  padding: 0.25rem 0.6rem;
  border-radius: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  display: inline-block;
}

.badge-success { background: rgba(16, 185, 129, 0.15); color: var(--success-color); border: 1px solid rgba(16, 185, 129, 0.3); }
.badge-warning { background: rgba(245, 158, 11, 0.15); color: var(--warning-color); border: 1px solid rgba(245, 158, 11, 0.3); }
.badge-danger { background: rgba(239, 68, 68, 0.15); color: var(--danger-color); border: 1px solid rgba(239, 68, 68, 0.3); }
.badge-muted { background: rgba(148, 163, 184, 0.15); color: #94a3b8; border: 1px solid rgba(148, 163, 184, 0.3); }
.badge-info { background: rgba(56, 189, 248, 0.15); color: #38bdf8; border: 1px solid rgba(56, 189, 248, 0.3); }

/* Config Form */
.config-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
}

.full-width {
  grid-column: span 2;
}

.config-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.config-preview {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 8px;
  padding: 0.75rem;
  font-size: 0.75rem;
  line-height: 1.4;
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  color: #e2e8f0;
}

.config-hint {
  margin: 0;
  font-size: 0.8rem;
  color: #94a3b8;
}

.form-group label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.form-control {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 0.65rem 0.85rem;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.9rem;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary-accent);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-row-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
}

.save-msg {
  font-size: 0.85rem;
  color: var(--success-color);
  white-space: pre-wrap;
  max-width: 28rem;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 1rem;
  width: 600px;
  max-width: 90vw;
  padding: 1.5rem;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}

.hex-dump-box {
  background: #060911;
  padding: 1rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border-color);
  word-break: break-all;
  color: var(--primary-accent);
  font-size: 0.85rem;
  max-height: 300px;
  overflow-y: auto;
}

.user-modal-card {
  width: 460px;
}

.txn-inspect-card {
  width: 960px;
}

.txn-inspect-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

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

.txn-inspect-grid .hex-dump-box {
  max-height: 420px;
  white-space: pre-wrap;
}

.led-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) 1.1fr;
  gap: 1.5rem;
}

.led-preview-card {
  min-height: 100%;
}

.led-board {
  background:
    radial-gradient(circle at 20% 0%, rgba(56, 189, 248, 0.08), transparent 45%),
    linear-gradient(180deg, #070b14 0%, #04070d 100%);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 1rem;
  padding: 2rem 1.25rem;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.65);
}

.led-line {
  font-family: var(--font-mono);
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  line-height: 1.1;
  min-height: 1.1em;
}

.led-line.yellow { color: #facc15; text-shadow: 0 0 18px rgba(250, 204, 21, 0.55); }
.led-line.green { color: #4ade80; text-shadow: 0 0 18px rgba(74, 222, 128, 0.55); }
.led-line.red { color: #f87171; text-shadow: 0 0 18px rgba(248, 113, 113, 0.55); }
.led-line.white { color: #f8fafc; text-shadow: 0 0 18px rgba(248, 250, 252, 0.4); }
.led-line.blue { color: #38bdf8; text-shadow: 0 0 18px rgba(56, 189, 248, 0.55); }

.led-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

@media (max-width: 1100px) {
  .led-layout,
  .form-row-3 {
    grid-template-columns: 1fr;
  }
}

.barrier-stage {
  position: relative;
  height: 200px;
  margin-top: 0.5rem;
  background:
    linear-gradient(180deg, rgba(15, 23, 42, 0.35) 0%, rgba(2, 6, 23, 0.9) 100%);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 1rem;
  overflow: hidden;
}

.barrier-housing {
  position: absolute;
  left: 28px;
  bottom: 42px;
  width: 36px;
  height: 92px;
  background: linear-gradient(180deg, #cbd5e1 0%, #64748b 100%);
  border-radius: 6px 6px 2px 2px;
  z-index: 2;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.35);
}

.barrier-arm {
  position: absolute;
  left: 58px;
  bottom: 118px;
  width: 210px;
  height: 16px;
  background: repeating-linear-gradient(
    90deg,
    #ef4444 0 22px,
    #f8fafc 22px 44px
  );
  border-radius: 3px;
  transform-origin: left center;
  transform: rotate(0deg);
  transition: transform 0.45s ease;
  z-index: 3;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.35);
}

.barrier-arm.open {
  transform: rotate(-80deg);
}

.barrier-arm.closed {
  transform: rotate(0deg);
}

.barrier-road {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 42px;
  background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
  border-top: 3px dashed rgba(250, 204, 21, 0.45);
}

.barrier-state-label {
  margin-top: 1rem;
  text-align: center;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.barrier-state-label.open { color: var(--success-color); }
.barrier-state-label.closed { color: var(--danger-color); }
.barrier-state-label.unknown { color: var(--text-muted); }

.header-buttons {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.header-user {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-body {
  height: auto;
  min-height: 100vh;
  overflow: auto;
}

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.guide-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 1rem 0 0;
}

.guide-toc a {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary-accent);
  text-decoration: none;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
}

.guide-toc a:hover {
  border-color: var(--primary-accent);
}

.guide-section {
  margin: 0;
}

.guide-section summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 1rem;
  padding: 1rem 1.25rem;
  list-style: none;
}

.guide-section summary::-webkit-details-marker {
  display: none;
}

.guide-section > *:not(summary) {
  padding: 0 1.25rem 1.1rem;
}

.guide-section h4 {
  margin: 0.85rem 0 0.35rem;
  font-size: 0.88rem;
  color: var(--text-main);
}

.guide-section p,
.guide-section li {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.guide-section ol,
.guide-section ul {
  margin: 0.35rem 0 0.7rem 1.2rem;
}

.guide-live {
  color: #fde68a;
  font-weight: 600;
}

.guide-pre {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.75rem;
  line-height: 1.45;
  overflow-x: auto;
  white-space: pre-wrap;
  color: #e2e8f0;
  margin: 0.6rem 0 0.9rem;
}

.guide-callout {
  margin: 0.75rem 0 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid rgba(250, 204, 21, 0.35);
  background: rgba(250, 204, 21, 0.08);
  border-radius: 10px;
}

.guide-callout strong {
  color: #fde68a;
}

.guide-callout ul {
  margin: 0.45rem 0 0 1.1rem;
}

.guide-callout li {
  color: var(--text-main);
  font-size: 0.86rem;
  line-height: 1.5;
}

.guide-figure {
  margin: 0.75rem 0 1rem;
}

.guide-figure img,
.guide-figure svg {
  display: block;
  width: 100%;
  max-width: 980px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: #0b1220;
}

.guide-figure figcaption {
  margin-top: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

@media print {
  body {
    background: #fff;
    color: #111;
    height: auto;
    overflow: visible;
  }

  .sidebar,
  .top-header,
  .header-actions,
  .live-pill {
    display: none !important;
  }

  .app-layout,
  .main-content {
    display: block;
    height: auto;
    overflow: visible;
    padding: 0;
    width: 100%;
  }

  .tab-content {
    display: none !important;
  }

  #tab-guide {
    display: block !important;
  }

  .guide-section {
    break-inside: avoid;
    border: 1px solid #ddd;
  }

  .guide-live {
    color: #92400e;
  }

  .guide-figure {
    break-inside: avoid;
  }
}
