/* DoorControl Virtual Simulator Stylesheet */
:root {
  --bg-color: #0b0f19;
  --bg-card: #131b2e;
  --bg-card-hover: #1a243c;
  --bg-subtle: #1e293b;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-active: rgba(59, 130, 246, 0.4);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --color-primary: #3b82f6;
  --color-primary-hover: #2563eb;
  --color-success: #10b981;
  --color-success-hover: #059669;
  --color-danger: #ef4444;
  --color-warning: #f59e0b;
  --color-cabinet: #f59e0b;
  
  --font-main: 'Prompt', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  --transition-normal: 0.25s ease;
  --gate-speed: 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  background-color: var(--bg-color);
  color: var(--text-primary);
  font-family: var(--font-main);
  min-height: 100vh;
  line-height: 1.5;
  background-image: 
    radial-gradient(ellipse at 50% -20%, rgba(59, 130, 246, 0.15), transparent 70%),
    radial-gradient(circle at 10% 80%, rgba(16, 185, 129, 0.05), transparent 40%);
  background-attachment: fixed;
}

.app-container {
  max-width: 1360px;
  margin: 0 auto;
  padding: 20px 24px 40px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ==========================================================================
   HEADER
   ========================================================================== */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  backdrop-filter: blur(12px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  flex-wrap: wrap;
  gap: 16px;
}

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

.brand-icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.35);
}

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

.brand-subtitle {
  font-size: 0.85rem;
  color: var(--color-primary);
  font-weight: 400;
}

.header-badges {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  display: inline-block;
  transition: background 0.3s ease;
}

.status-badge.connected .status-dot {
  background: var(--color-success);
  box-shadow: 0 0 8px var(--color-success);
}

.status-badge.connected strong {
  color: var(--color-success);
}

.status-badge.disconnected .status-dot {
  background: var(--color-danger);
  box-shadow: 0 0 8px var(--color-danger);
}

.status-badge.disconnected strong {
  color: var(--color-danger);
}

.status-dot.pulsing {
  animation: pulse-dot 1.5s infinite ease-in-out;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 0.4; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.2); }
}

.device-id-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.25);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-family: var(--font-mono);
  color: #93c5fd;
  max-width: 240px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================================================
   CARDS & COMMON
   ========================================================================== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}

.section-header {
  padding: 18px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 12px;
}

.section-title-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
}

.badge-tag {
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 500;
}

.quick-sound-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toggle-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Toggle switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-color);
  transition: var(--transition-normal);
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: var(--transition-normal);
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--color-primary);
}

input:checked + .slider:before {
  transform: translateX(18px);
}

/* ==========================================================================
   SIMULATION STAGE AREA
   ========================================================================== */
.stage-container {
  position: relative;
  background: linear-gradient(180deg, #101726 0%, #0d121f 50%, #090d16 100%);
  padding: 30px 24px 24px;
  min-height: 440px;
  overflow: hidden;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.skyline-glow {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 120px;
  background: radial-gradient(circle at 50% -40px, rgba(59, 130, 246, 0.2), transparent 70%);
  pointer-events: none;
}

/* Canopy Roof */
.canopy-roof {
  position: absolute;
  top: 0;
  left: 10%;
  right: 10%;
  height: 38px;
  background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
  border-bottom: 3px solid var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0 0 16px 16px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5);
  z-index: 10;
}

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

.canopy-sign {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: #f1f5f9;
  text-shadow: 0 0 10px rgba(59, 130, 246, 0.8);
}

/* Guardhouse Booth (Center) */
.guardhouse-booth {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  width: 140px;
  height: 220px;
  background: linear-gradient(180deg, #1e293b 0%, #111827 100%);
  border: 2px solid #334155;
  border-radius: 12px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.6);
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 10px;
}

.booth-roof {
  position: absolute;
  top: -12px;
  left: -10px;
  right: -10px;
  height: 16px;
  background: #334155;
  border-radius: 6px;
  border-bottom: 2px solid #475569;
}

.booth-window {
  width: 100%;
  height: 85px;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.25) 0%, rgba(14, 116, 144, 0.4) 100%);
  border: 2px solid #38bdf8;
  border-radius: 8px;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 12px rgba(56, 189, 248, 0.3);
}

.guard-silhouette {
  font-size: 2.2rem;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6));
}

.window-reflection {
  position: absolute;
  top: 0;
  left: 0;
  width: 150%;
  height: 100%;
  background: linear-gradient(45deg, transparent 40%, rgba(255, 255, 255, 0.25) 50%, transparent 60%);
  pointer-events: none;
}

.booth-nameplate {
  margin-top: 10px;
  font-size: 0.6rem;
  font-weight: 700;
  color: #38bdf8;
  letter-spacing: 0.05em;
  background: #0f172a;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(56, 189, 248, 0.3);
  text-align: center;
  width: 100%;
}

.booth-door {
  width: 50px;
  height: 75px;
  margin-top: auto;
  background: #1e293b;
  border: 1px solid #475569;
  border-bottom: none;
  border-radius: 4px 4px 0 0;
}

/* Lanes Layout */
.lanes-wrapper {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 160px; /* Space for the center guardhouse */
  position: relative;
  z-index: 6;
  margin-top: 100px;
}

.lane {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.lane-badge {
  font-size: 0.85rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
}

.lane-badge.in {
  background: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.lane-badge.out {
  background: rgba(16, 185, 129, 0.2);
  color: #a7f3d0;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.gate-status-pill {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: all 0.3s ease;
}

.gate-status-pill.closed {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

.gate-status-pill.opening,
.gate-status-pill.closing {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.5);
  animation: pulse-badge 0.8s infinite alternate;
}

.gate-status-pill.open {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.5);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.25);
}

@keyframes pulse-badge {
  from { opacity: 0.7; }
  to { opacity: 1; }
}

/* Road Surface */
.road-surface {
  height: 90px;
  background: #171d2c;
  border-radius: 8px;
  position: relative;
  overflow: hidden;
  border: 1px dashed rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: space-around;
}

.road-lines {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 2px;
  background: repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.15) 0px, rgba(255, 255, 255, 0.15) 20px, transparent 20px, transparent 40px);
}

.road-arrow {
  font-size: 0.78rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.35);
  letter-spacing: 0.05em;
  z-index: 1;
}

.loop-detector {
  border: 2px solid rgba(245, 158, 11, 0.35);
  background: rgba(245, 158, 11, 0.05);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 600;
  color: rgba(245, 158, 11, 0.6);
  z-index: 1;
}

/* Barrier Assembly & Mechanics */
.barrier-assembly {
  height: 120px;
  position: relative;
  display: flex;
  align-items: flex-end;
}

.barrier-assembly.in {
  justify-content: flex-start;
}

.barrier-assembly.out {
  justify-content: flex-end;
}

/* Traffic Light Post */
.traffic-light-post {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0 12px;
  z-index: 8;
}

.traffic-light {
  width: 24px;
  height: 52px;
  background: #0f172a;
  border: 2px solid #334155;
  border-radius: 12px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6);
}

.light {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #27272a;
  transition: all 0.3s ease;
}

.light-red.active {
  background: #ef4444;
  box-shadow: 0 0 12px #ef4444, 0 0 20px rgba(239, 68, 68, 0.6);
}

.light-green.active {
  background: #10b981;
  box-shadow: 0 0 12px #10b981, 0 0 20px rgba(16, 185, 129, 0.6);
}

.post-pole {
  width: 4px;
  height: 48px;
  background: #475569;
}

/* Barrier Cabinet (Industrial Housing) */
.barrier-cabinet {
  width: 52px;
  height: 105px;
  background: linear-gradient(180deg, #f59e0b 0%, #d97706 70%, #b45309 100%);
  border-radius: 8px 8px 3px 3px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.7), inset 0 2px 4px rgba(255, 255, 255, 0.3);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 6px;
  z-index: 7;
}

.cabinet-top-led {
  width: 20px;
  height: 6px;
  background: #ef4444;
  border-radius: 3px;
  box-shadow: 0 0 8px #ef4444;
  transition: background 0.3s ease, box-shadow 0.3s ease;
}

.cabinet-top-led.green {
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
}

.cabinet-brand {
  font-size: 0.52rem;
  font-weight: 800;
  color: #451a03;
  margin-top: 4px;
  letter-spacing: -0.02em;
}

/* Pivot Joint */
.cabinet-pivot {
  width: 28px;
  height: 28px;
  background: #1e293b;
  border: 3px solid #64748b;
  border-radius: 50%;
  position: absolute;
  top: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
  z-index: 10;
}

.cabinet-pivot.in {
  right: -14px;
}

.cabinet-pivot.out {
  left: -14px;
}

/* Barrier Arm (The Moving Gate) */
.barrier-arm {
  position: absolute;
  height: 14px;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
  transition: transform var(--gate-speed);
  will-change: transform;
}

/* INBOUND ARM: Origin is at pivot on left, arm extends RIGHT across lane */
.barrier-arm.in {
  width: 280px;
  left: 12px;
  top: 4px;
  transform-origin: 0px 50%;
  transform: rotate(0deg); /* 0deg is CLOSED (horizontal) */
}

/* When INBOUND is OPEN: rotates UP by -90deg */
.barrier-arm.in.open {
  transform: rotate(-90deg);
}

/* OUTBOUND ARM: Origin is at pivot on right, arm extends LEFT across lane */
.barrier-arm.out {
  width: 280px;
  right: 12px;
  top: 4px;
  transform-origin: 100% 50%;
  transform: rotate(0deg); /* 0deg is CLOSED (horizontal) */
}

/* When OUTBOUND is OPEN: rotates UP by 90deg */
.barrier-arm.out.open {
  transform: rotate(90deg);
}

.arm-stripes {
  width: 100%;
  height: 100%;
  border-radius: 4px;
  background: repeating-linear-gradient(
    -45deg,
    #ef4444 0px,
    #ef4444 16px,
    #ffffff 16px,
    #ffffff 32px
  );
  border: 1px solid rgba(0, 0, 0, 0.2);
}

.arm-tip-light {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ef4444;
  box-shadow: 0 0 8px #ef4444;
  top: 3px;
}

.barrier-arm.in .arm-tip-light {
  right: 6px;
}

.barrier-arm.out .arm-tip-light {
  left: 6px;
}

.barrier-arm.open .arm-tip-light {
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
}

/* Action Buttons below lanes */
.lane-footer-action {
  display: flex;
  justify-content: center;
  margin-top: 4px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  font-family: var(--font-main);
  transition: all var(--transition-normal);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
  width: 100%;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #60a5fa, #3b82f6);
  box-shadow: 0 6px 18px rgba(59, 130, 246, 0.35);
}

.btn-success {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  width: 100%;
}

.btn-success:hover {
  background: linear-gradient(135deg, #34d399, #10b981);
  box-shadow: 0 6px 18px rgba(16, 185, 129, 0.35);
}

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.btn-outline:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.btn-sm {
  padding: 5px 12px;
  font-size: 0.8rem;
  border-radius: 6px;
}

/* Stage Footer Controls */
.stage-footer {
  padding: 14px 24px;
  background: var(--bg-card);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

.footer-control-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.form-select {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 6px 12px;
  border-radius: 8px;
  font-family: var(--font-main);
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}

.form-select:focus {
  border-color: var(--color-primary);
}

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

/* ==========================================================================
   TELEMETRY & ACTIVITY SECTION
   ========================================================================== */
.telemetry-section {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
}

@media (max-width: 960px) {
  .telemetry-section {
    grid-template-columns: 1fr;
  }
  .lanes-wrapper {
    gap: 80px;
  }
}

@media (max-width: 768px) {
  .lanes-wrapper {
    grid-template-columns: 1fr;
    gap: 24px;
  }
  .guardhouse-booth {
    display: none;
  }
}

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

.card-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
}

.status-grid {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.info-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.info-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.info-label {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.info-value {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-primary);
}

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

.info-value.highlight {
  color: #60a5fa;
  font-weight: 600;
}

/* Log Container */
.log-count {
  background: var(--bg-subtle);
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: 12px;
}

.log-container {
  height: 240px;
  overflow-y: auto;
  padding: 12px 16px;
  background: #0d1322;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.log-container::-webkit-scrollbar {
  width: 6px;
}

.log-container::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 3px;
}

.log-empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 0.88rem;
}

.empty-icon {
  font-size: 2rem;
  opacity: 0.6;
}

.log-entry {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
  border-left: 3px solid #475569;
  line-height: 1.4;
  animation: fade-in 0.2s ease-out;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.log-entry.trigger-in {
  border-left-color: #3b82f6;
  background: rgba(59, 130, 246, 0.05);
}

.log-entry.trigger-out {
  border-left-color: #10b981;
  background: rgba(16, 185, 129, 0.05);
}

.log-entry.telegram {
  border-left-color: #0ea5e9;
  background: rgba(14, 165, 233, 0.05);
}

.log-entry.error {
  border-left-color: #ef4444;
  background: rgba(239, 68, 68, 0.08);
}

.log-time {
  color: var(--text-muted);
  font-size: 0.75rem;
  white-space: nowrap;
}

.log-type {
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.7rem;
  text-transform: uppercase;
}

.log-type.in { background: #1e3a8a; color: #93c5fd; }
.log-type.out { background: #064e3b; color: #6ee7b7; }
.log-type.ws { background: #312e81; color: #c7d2fe; }
.log-type.tg { background: #075985; color: #7dd3fc; }
.log-type.err { background: #7f1d1d; color: #fca5a5; }

.log-msg {
  color: var(--text-primary);
  flex: 1;
  word-break: break-all;
}

/* Footer */
.app-footer {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.footer-separator {
  opacity: 0.4;
}
