/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d0f12;
  --bg2:       #161920;
  --bg3:       #1e2229;
  --border:    #2a2f3a;
  --text:      #e2e8f0;
  --text2:     #8892a4;
  --accent:    #3b82f6;
  --accent2:   #1d4ed8;
  --green:     #22c55e;
  --yellow:    #eab308;
  --red:       #ef4444;
  --orange:    #f97316;
  --radius:    10px;
  --shadow:    0 2px 12px rgba(0,0,0,.4);
  --font:      -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ───────────────────────────────────────────────────────────────── */
.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  flex: 1;
}

.topbar-back {
  color: var(--accent);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
}

.content {
  flex: 1;
  padding: 16px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text2);
  margin-bottom: 12px;
}

.card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.card-row:last-child { border-bottom: none; }
.card-row:hover { color: var(--accent); }
.card-row-label { font-size: 14px; }
.card-row-value { font-size: 14px; color: var(--text2); }
.card-row-arrow { color: var(--text2); margin-left: 8px; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}
.btn:hover { opacity: .85; }
.btn:active { opacity: .7; }
.btn-primary   { background: var(--accent);  color: #fff; }
.btn-danger    { background: var(--red);     color: #fff; }
.btn-secondary { background: var(--bg3);     color: var(--text); border: 1px solid var(--border); }
.btn-green     { background: var(--green);   color: #fff; }
.btn-full      { width: 100%; }
.btn-sm        { padding: 6px 12px; font-size: 13px; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 6px;
}
.form-input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.form-input:focus { border-color: var(--accent); }

/* ── Live Value Grid ──────────────────────────────────────────────────────── */
.value-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.value-cell {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
  transition: border-color .15s;
}
.value-cell:hover { border-color: var(--accent); }
.value-cell.active { border-color: var(--accent); background: #1e2f4a; }

.value-cell-name {
  font-size: 11px;
  color: var(--text2);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.value-cell-val {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--green);
  line-height: 1.2;
}
.value-cell-unit {
  font-size: 11px;
  color: var(--text2);
  margin-top: 2px;
}

/* ── Status Badge ─────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
}
.badge-green  { background: #14532d; color: var(--green); }
.badge-red    { background: #450a0a; color: var(--red); }
.badge-yellow { background: #422006; color: var(--yellow); }
.badge-grey   { background: var(--bg3); color: var(--text2); }

/* ── Chart Container ──────────────────────────────────────────────────────── */
.chart-wrap {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.chart-canvas-wrap {
  position: relative;
  height: 260px;
}

/* ── Time Range Selector ──────────────────────────────────────────────────── */
.timerange {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.timerange-btn {
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text2);
  font-size: 13px;
  cursor: pointer;
}
.timerange-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Device Header ────────────────────────────────────────────────────────── */
.device-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.device-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.device-name { font-size: 16px; font-weight: 600; }
.device-id   { font-size: 12px; color: var(--text2); }

/* ── Tab Bar ──────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  overflow-x: auto;
  gap: 0;
}
.tab {
  padding: 10px 16px;
  font-size: 14px;
  color: var(--text2);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  flex-shrink: 0;
}
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Map ──────────────────────────────────────────────────────────────────── */
#map {
  height: 400px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}

/* ── Login ────────────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  width: 100%;
  max-width: 360px;
}
.login-logo {
  text-align: center;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -.02em;
  margin-bottom: 8px;
}
.login-sub {
  text-align: center;
  color: var(--text2);
  font-size: 14px;
  margin-bottom: 28px;
}

/* ── Floating Action Button ───────────────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 28px;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(59,130,246,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}

/* ── Alert / Toast ────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 14px;
  z-index: 999;
  animation: fadein .2s ease;
}
@keyframes fadein { from { opacity:0; transform: translateX(-50%) translateY(10px); } }

/* ── Session Recording indicator ─────────────────────────────────────────── */
.rec-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--red);
  display: inline-block;
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%,100% { opacity: 1; }
  50%      { opacity: .3; }
}

/* ── Empty State ──────────────────────────────────────────────────────────── */
.empty {
  text-align: center;
  padding: 48px 16px;
  color: var(--text2);
}
.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-text { font-size: 15px; }

/* ── Tab-Navigation ──────────────────────────────────────────────────────── */
.db-tabbar {
  flex-shrink: 0;
  display: flex;
  background: var(--bg); border-top: 1px solid var(--border);
}
.db-tab {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  padding: 6px 0 10px; gap: 3px;
  font-size: 10px; color: var(--text2); cursor: pointer;
  border-top: 2px solid transparent;
}
.db-tab.active { color: var(--green); border-top-color: var(--green); }
.db-tab svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .value-grid { grid-template-columns: repeat(2, 1fr); }
  .value-cell-val { font-size: 18px; }
}
