/* ─────────────────────────────────────────
   BLE Door Monitor – Dashboard Styles
   Dark theme, mobile-first, CSS variables
   ───────────────────────────────────────── */

:root {
  --bg:           #0d0f14;
  --bg-card:      #141720;
  --bg-card-2:    #1a1e2a;
  --bg-hover:     #1f2435;
  --border:       rgba(255,255,255,0.07);
  --border-hover: rgba(255,255,255,0.14);

  --text:         #e8eaf0;
  --text-muted:   #8892a4;
  --text-dim:     #555f72;

  --accent:       #4f8ef7;
  --accent-glow:  rgba(79,142,247,0.25);

  --open-color:   #f87171;
  --open-glow:    rgba(248,113,113,0.2);
  --close-color:  #34d399;
  --close-glow:   rgba(52,211,153,0.2);
  --warn-color:   #fbbf24;
  --warn-glow:    rgba(251,191,36,0.2);

  --radius:       12px;
  --radius-sm:    8px;
  --shadow:       0 4px 24px rgba(0,0,0,0.4);
  --shadow-sm:    0 2px 8px  rgba(0,0,0,0.25);

  --font:         'Inter', system-ui, sans-serif;
  --mono:         'JetBrains Mono', 'Fira Code', monospace;

  --topbar-h:     60px;
  --transition:   0.2s ease;
}

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

html { font-size: 15px; }

body {
  background:  var(--bg);
  color:       var(--text);
  font-family: var(--font);
  min-height:  100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Top Bar ── */
.topbar {
  position:   fixed;
  top: 0; left: 0; right: 0;
  height:     var(--topbar-h);
  background: rgba(13,15,20,0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index:    100;
}
.topbar-inner {
  max-width:   1200px;
  margin:      0 auto;
  padding:     0 20px;
  height:      100%;
  display:     flex;
  align-items: center;
  justify-content: space-between;
}
.topbar-brand {
  display:     flex;
  align-items: center;
  gap:         10px;
  font-weight: 600;
  font-size:   1rem;
  color:       var(--text);
}
.brand-icon { width: 22px; height: 22px; color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 12px; }

/* ── Connection Badge ── */
.connection-badge {
  display:     flex;
  align-items: center;
  gap:         7px;
  padding:     5px 12px;
  border-radius: 20px;
  background:  var(--bg-card);
  border:      1px solid var(--border);
  font-size:   0.8rem;
  font-weight: 500;
  color:       var(--text-muted);
  transition:  var(--transition);
}
.connection-badge.connected {
  border-color: var(--close-color);
  color:        var(--close-color);
}
.connection-badge.disconnected {
  border-color: var(--open-color);
  color:        var(--open-color);
}
.pulse-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}
.connection-badge.connected .pulse-dot {
  background: var(--close-color);
  box-shadow: 0 0 6px var(--close-color);
  animation: pulse 2s infinite;
}
.connection-badge.disconnected .pulse-dot {
  background: var(--open-color);
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ── Icon Button ── */
.icon-btn {
  background: transparent;
  border:     1px solid var(--border);
  color:      var(--text-muted);
  width:      36px; height: 36px;
  border-radius: var(--radius-sm);
  cursor:     pointer;
  display:    flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.icon-btn:hover { background: var(--bg-card); color: var(--text); border-color: var(--border-hover); }
.icon-btn svg { width: 18px; height: 18px; }

/* ── Main Layout ── */
.layout {
  max-width: 1200px;
  margin:    0 auto;
  padding:   calc(var(--topbar-h) + 28px) 20px 48px;
  display:   flex;
  flex-direction: column;
  gap:       20px;
}

/* ── Hero Card ── */
.hero-card {
  background:    var(--bg-card);
  border:        1px solid var(--border);
  border-radius: var(--radius);
  padding:       32px;
  display:       flex;
  align-items:   center;
  gap:           40px;
  box-shadow:    var(--shadow);
  transition:    border-color 0.4s ease, box-shadow 0.4s ease;
  overflow:      hidden;
  position:      relative;
}
.hero-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 20% 50%, var(--accent-glow) 0%, transparent 60%);
  pointer-events: none;
  transition: background 0.4s ease;
}
.hero-card.state-open::before    { background: radial-gradient(ellipse at 20% 50%, var(--open-glow)  0%, transparent 60%); }
.hero-card.state-closed::before  { background: radial-gradient(ellipse at 20% 50%, var(--close-glow) 0%, transparent 60%); }
.hero-card.state-open   { border-color: rgba(248,113,113,0.3); }
.hero-card.state-closed { border-color: rgba(52,211,153,0.3);  }

/* Door visual */
.door-visual {
  flex-shrink: 0;
  position:    relative;
  width:       80px;
}
.door-frame {
  width:         72px;
  height:        100px;
  border:        3px solid var(--border-hover);
  border-radius: 4px 4px 0 0;
  position:      relative;
  background:    var(--bg-card-2);
}
.door-panel {
  position:   absolute;
  top:        3px; left: 3px; bottom: 0;
  width:      calc(100% - 6px);
  background: var(--bg-card);
  border-radius: 2px;
  transform-origin: left center;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  border:     1px solid var(--border);
}
.door-panel.open {
  transform: perspective(200px) rotateY(-70deg);
}
.door-handle {
  position:     absolute;
  right:        8px; top: 50%;
  transform:    translateY(-50%);
  width:        5px; height: 16px;
  background:   var(--text-dim);
  border-radius: 3px;
}
.door-shadow {
  width:      72px; height: 6px;
  background: rgba(0,0,0,0.4);
  border-radius: 50%;
  margin-top: 2px;
}

/* Hero info */
.hero-info { flex: 1; }
.hero-label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-dim); margin-bottom: 4px; }
.hero-state {
  font-size:   2.8rem;
  font-weight: 700;
  line-height: 1;
  color:       var(--text-muted);
  margin-bottom: 8px;
  transition:  color 0.3s ease;
}
.hero-state.state-open   { color: var(--open-color);  }
.hero-state.state-closed { color: var(--close-color); }
.hero-time  { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 16px; }

.hero-badges { display: flex; gap: 10px; flex-wrap: wrap; }
.badge {
  display:     flex;
  align-items: center;
  gap:         6px;
  padding:     5px 10px;
  border-radius: 20px;
  background:  var(--bg-card-2);
  border:      1px solid var(--border);
  font-size:   0.78rem;
  font-family: var(--mono);
  color:       var(--text-muted);
}
.badge svg { width: 13px; height: 13px; flex-shrink: 0; }
.badge-battery.low { border-color: var(--warn-color); color: var(--warn-color); }
.badge-signal  { color: var(--accent); border-color: rgba(79,142,247,0.3); }

/* ── Stats Row ── */
.stats-row {
  display:               grid;
  grid-template-columns: repeat(4, 1fr);
  gap:                   14px;
}
@media (max-width: 768px) { .stats-row { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 420px) { .stats-row { grid-template-columns: 1fr 1fr; } }

.stat-card {
  background:    var(--bg-card);
  border:        1px solid var(--border);
  border-radius: var(--radius);
  padding:       18px;
  display:       flex;
  align-items:   center;
  gap:           14px;
}
.stat-icon {
  width: 42px; height: 42px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon svg { width: 20px; height: 20px; }
.stat-icon-open    { background: rgba(248,113,113,0.12); color: var(--open-color); }
.stat-icon-close   { background: rgba(52,211,153,0.12);  color: var(--close-color); }
.stat-icon-battery { background: rgba(251,191,36,0.12);  color: var(--warn-color); }
.stat-icon-uptime  { background: rgba(79,142,247,0.12);  color: var(--accent); }
.stat-value { font-size: 1.4rem; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }

/* ── Alert Zone ── */
.alert-zone { display: flex; flex-direction: column; gap: 10px; }
.alert-item {
  display:       flex;
  align-items:   center;
  gap:           12px;
  padding:       12px 16px;
  border-radius: var(--radius-sm);
  border:        1px solid;
  font-size:     0.875rem;
  animation:     slideIn 0.3s ease;
}
.alert-item.offline  { background: rgba(248,113,113,0.08); border-color: rgba(248,113,113,0.3); color: var(--open-color); }
.alert-item.battery  { background: rgba(251,191,36,0.08);  border-color: rgba(251,191,36,0.3);  color: var(--warn-color); }
@keyframes slideIn { from { opacity:0; transform: translateY(-6px); } to { opacity:1; transform:none; } }

/* ── Timeline Section ── */
.timeline-section {
  background:    var(--bg-card);
  border:        1px solid var(--border);
  border-radius: var(--radius);
  overflow:      hidden;
}
.section-header {
  padding:       18px 20px;
  border-bottom: 1px solid var(--border);
  display:       flex;
  align-items:   center;
  justify-content: space-between;
  flex-wrap:     wrap;
  gap:           10px;
}
.section-title { font-size: 0.95rem; font-weight: 600; }
.section-actions { display: flex; gap: 8px; align-items: center; }

.filter-select {
  background:    var(--bg-card-2);
  border:        1px solid var(--border);
  color:         var(--text);
  padding:       6px 10px;
  border-radius: var(--radius-sm);
  font-size:     0.82rem;
  cursor:        pointer;
}
.filter-select:focus { outline: none; border-color: var(--accent); }

.btn {
  display:     inline-flex;
  align-items: center;
  gap:         6px;
  padding:     7px 14px;
  border-radius: var(--radius-sm);
  font-size:   0.82rem;
  font-weight: 500;
  cursor:      pointer;
  border:      1px solid transparent;
  transition:  var(--transition);
}
.btn svg { width: 14px; height: 14px; }
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover  { filter: brightness(1.1); }
.btn-secondary { background: var(--bg-card-2); border-color: var(--border); color: var(--text-muted); }
.btn-secondary:hover { background: var(--bg-hover); color: var(--text); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-card-2); color: var(--text); }
.w-full  { width: 100%; justify-content: center; }
.mt-2    { margin-top: 8px; }

/* Timeline */
.timeline { padding: 8px 0; min-height: 200px; }
.timeline-loading { padding: 40px; text-align: center; color: var(--text-dim); font-size: 0.85rem; }
.timeline-empty   { padding: 40px; text-align: center; color: var(--text-dim); }

.timeline-item {
  display:     flex;
  align-items: flex-start;
  gap:         16px;
  padding:     12px 20px;
  border-bottom: 1px solid var(--border);
  transition:  background var(--transition);
}
.timeline-item:last-child { border-bottom: none; }
.timeline-item:hover { background: var(--bg-hover); }

.tl-dot-col { display: flex; flex-direction: column; align-items: center; padding-top: 4px; }
.tl-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.tl-dot.open    { background: var(--open-color);  box-shadow: 0 0 6px var(--open-color); }
.tl-dot.closed  { background: var(--close-color); box-shadow: 0 0 6px var(--close-color); }
.tl-dot.battery { background: var(--warn-color); }
.tl-dot.offline { background: var(--text-dim); }
.tl-dot.online  { background: var(--close-color); }
.tl-dot.raw     { background: var(--accent); }
.tl-line { width: 1px; flex: 1; background: var(--border); margin-top: 4px; min-height: 24px; }

.tl-body { flex: 1; min-width: 0; }
.tl-title {
  font-size:   0.875rem;
  font-weight: 500;
  color:       var(--text);
  margin-bottom: 3px;
}
.tl-meta { display: flex; gap: 12px; flex-wrap: wrap; }
.tl-time  { font-size: 0.78rem; color: var(--text-dim); font-family: var(--mono); }
.tl-badge {
  font-size:     0.72rem;
  padding:       2px 8px;
  border-radius: 10px;
  font-family:   var(--mono);
}
.tl-badge.rssi    { background: rgba(79,142,247,0.1);  color: var(--accent); }
.tl-badge.battery { background: rgba(251,191,36,0.1);  color: var(--warn-color); }

.timeline-footer {
  padding:     14px 20px;
  border-top:  1px solid var(--border);
  display:     flex;
  align-items: center;
  justify-content: space-between;
}
.timeline-count { font-size: 0.78rem; color: var(--text-dim); }

/* ── Settings Drawer ── */
.drawer-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease;
}
.drawer-overlay.open { opacity: 1; pointer-events: all; }

.settings-drawer {
  position:   fixed;
  top: 0; right: 0; bottom: 0;
  width:      340px;
  max-width:  100%;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  z-index:    201;
  transform:  translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display:    flex;
  flex-direction: column;
}
.settings-drawer.open { transform: translateX(0); }

.drawer-header {
  display:     flex;
  align-items: center;
  justify-content: space-between;
  padding:     18px 20px;
  border-bottom: 1px solid var(--border);
}
.drawer-header h3 { font-size: 0.95rem; font-weight: 600; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px; }
.drawer-section { margin-bottom: 24px; }
.drawer-section h4 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); margin-bottom: 12px; }
.hint { font-size: 0.75rem; color: var(--text-dim); margin-top: 8px; }

.field-label { font-size: 0.8rem; color: var(--text-muted); display: block; margin-bottom: 6px; }
.text-input {
  width:      100%;
  background: var(--bg);
  border:     1px solid var(--border);
  color:      var(--text);
  padding:    8px 10px;
  border-radius: var(--radius-sm);
  font-size:  0.82rem;
  font-family: var(--mono);
}
.text-input:focus { outline: none; border-color: var(--accent); }

.debug-output {
  margin-top:    10px;
  padding:       10px;
  background:    var(--bg);
  border-radius: var(--radius-sm);
  font-family:   var(--mono);
  font-size:     0.72rem;
  color:         var(--text-muted);
  white-space:   pre-wrap;
  word-break:    break-all;
  max-height:    300px;
  overflow-y:    auto;
  display:       none;
}
.debug-output.visible { display: block; }

.info-row {
  display:       flex;
  justify-content: space-between;
  padding:       8px 0;
  border-bottom: 1px solid var(--border);
  font-size:     0.82rem;
}
.info-row span:last-child { color: var(--text-muted); font-family: var(--mono); font-size: 0.78rem; }

/* Scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 3px; }

/* Mobile responsive */
@media (max-width: 640px) {
  .hero-card { flex-direction: column; gap: 24px; padding: 24px; }
  .hero-state { font-size: 2.2rem; }
  .door-visual { align-self: center; }
  .layout { padding-left: 12px; padding-right: 12px; }
}
