/* ═══════════════════════════════════════════════════════════
   SENSOR DASHBOARD — style.css
═══════════════════════════════════════════════════════════ */

:root {
  --font-body: 'Inter', system-ui, sans-serif;
  --bg:           #0b1220;
  --panel:        #111827;
  --panel-2:      #1a2540;
  --panel-hover:  #1e2d4a;
  --border:       rgba(255,255,255,0.08);
  --border-active:rgba(79,140,255,0.5);
  --divider:      rgba(255,255,255,0.05);
  --text:         #e8eefc;
  --muted:        #7a90b8;
  --faint:        #3d5278;
  --accent:       #4f8cff;
  --accent-hover: #3a7af0;
  --accent-glow:  rgba(79,140,255,0.15);
  --success:      #2fbf71;
  --danger:       #ff6b6b;
  --warning:      #fbbf24;
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-xl: 18px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.45);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.55);
  --ease: 160ms cubic-bezier(0.16,1,0.3,1);
  --sidebar-w: 260px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: none; text-size-adjust: none; -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--font-body);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100dvh;
}
img, svg { display: block; }
input, button { font: inherit; }
button { cursor: pointer; border: none; background: none; }
.hidden { display: none !important; }
.muted  { color: var(--muted); }
.faint  { color: var(--faint); }
.small  { font-size: 12px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 500;
  transition: background var(--ease), box-shadow var(--ease), color var(--ease);
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover  { background: var(--accent-hover); box-shadow: 0 0 0 3px var(--accent-glow); }
.btn-primary:active { background: #2e65e0; }
.btn-secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--panel-hover); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); border-color: rgba(255,255,255,0.16); }
.btn-full { width: 100%; justify-content: center; padding: 11px 16px; }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-msg {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: var(--r-md);
  background: rgba(255,107,107,0.12);
  border: 1px solid rgba(255,107,107,0.3);
  color: var(--danger);
  font-size: 13px;
}

/* LOGIN */
.login-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse 600px 400px at 60% 20%, rgba(79,140,255,0.06) 0%, transparent 70%),
    var(--bg);
}
.login-box {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 32px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 17px; font-weight: 600; color: var(--accent);
  margin-bottom: 24px;
}
.login-box h1 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.login-box p  { color: var(--muted); font-size: 13px; margin-bottom: 24px; }

.field { margin-bottom: 14px; }
.field label {
  display: block; font-size: 12px; font-weight: 500;
  color: var(--muted); margin-bottom: 6px;
  text-transform: uppercase; letter-spacing: 0.05em;
}
input[type="text"],
input[type="password"],
input[type="datetime-local"] {
  width: 100%; padding: 10px 13px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text); font-size: 14px;
  transition: border-color var(--ease), box-shadow var(--ease);
  outline: none; color-scheme: dark;
}
input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* APP LAYOUT */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100dvh;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0;
  height: 100dvh; overflow-y: auto;
}
.sidebar-header {
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--divider);
}
.sidebar-logo {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 700; color: var(--accent);
}
.sidebar-brand { color: var(--text); }
.sidebar-section-label {
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--faint); padding: 16px 16px 8px;
}
.sensor-list { padding: 0 8px 16px; flex: 1; }

.sensor-item {
  width: 100%; text-align: left;
  background: transparent; color: var(--text);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  padding: 10px 12px; margin-bottom: 4px;
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease);
  display: flex; flex-direction: column; gap: 2px;
}
.sensor-item:hover  { background: var(--panel-2); }
.sensor-item.active { background: var(--panel-2); border-color: var(--border-active); }
.sensor-item .s-name  { font-size: 13px; font-weight: 600; }
.sensor-item .s-kid   { font-size: 11px; color: var(--muted); }
.sensor-item .s-status {
  font-size: 11px; display: flex; align-items: center;
  gap: 4px; margin-top: 2px;
}
.dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--faint); flex-shrink: 0;
}
.dot.active { background: var(--success); box-shadow: 0 0 4px var(--success); }

@keyframes shimmer {
  0%   { background-position: -300px 0; }
  100% { background-position:  300px 0; }
}
.skeleton-sensor {
  height: 62px; border-radius: var(--r-md); margin-bottom: 4px;
  background: linear-gradient(90deg, var(--panel-2) 25%, rgba(255,255,255,0.04) 50%, var(--panel-2) 75%);
  background-size: 600px 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

.content {
  padding: 24px;
  display: flex; flex-direction: column; gap: 20px;
  min-width: 0;
}

.topbar {
  display: flex; align-items: flex-start;
  justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.topbar-left h1 { font-size: 20px; font-weight: 700; line-height: 1.2; }
.topbar-right { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-label {
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint);
}
.input-sm {
  padding: 7px 10px; font-size: 12px;
  border-radius: var(--r-md); border: 1px solid var(--border);
  background: rgba(255,255,255,0.04); color: var(--text);
  outline: none; color-scheme: dark;
  transition: border-color var(--ease), box-shadow var(--ease);
}
.input-sm:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px 18px;
}
.metric-key {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); margin-bottom: 6px;
}
.metric-value { font-size: 32px; font-weight: 700; line-height: 1; color: var(--text); }
.metric-unit  { font-size: 14px; font-weight: 400; color: var(--muted); margin-left: 3px; }
.metric-label { font-size: 11px; color: var(--faint); margin-top: 4px; }

.chart-card {
  flex: 1; min-height: 320px;
  display: flex; flex-direction: column;
  padding: 18px 20px;
}
.card-header {
  display: flex; align-items: center;
  justify-content: space-between; margin-bottom: 16px;
}
.card-title  { font-size: 14px; font-weight: 600; color: var(--text); }
.chart-empty { font-size: 13px; color: var(--muted); text-align: center; padding: 40px 0; }
#chartWrap   { flex: 1; position: relative; min-height: 260px; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .sensor-list { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; }
  .sensor-item { width: auto; flex-direction: row; align-items: center; gap: 8px; padding: 8px 12px; }
  .s-kid, .s-status { display: none; }
  .topbar { flex-direction: column; }
  .topbar-right { width: 100%; }
}