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

:root {
  /* ── Netatmo blue palette (lighter) ── */
  --bg:          #1a3a6b;
  --bg-card:     #1e4585;
  --bg-hover:    #255099;
  --border:      #2d5faa;
  --text:        #f0f5ff;
  --text-muted:  #a8c4f0;
  --primary:     #4d8af0;
  --primary-dk:  #2d6ae0;
  --primary-lt:  #7aaff5;
  --success:     #34d399;
  --warning:     #fbbf24;
  --danger:      #f87171;
  --sidebar-w:   220px;
  --radius:      10px;
  --shadow:      0 4px 24px rgba(0,0,0,.35);
}

html, body { height: 100%; font-family: 'Inter', system-ui, sans-serif;
             background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6; }

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

/* ── Layout ─────────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0; width: var(--sidebar-w); height: 100%;
  background: linear-gradient(180deg, #163269 0%, #0f2350 100%);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 100;
}
.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.content { padding: 1.5rem 2rem; flex: 1; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar-brand {
  display: flex; align-items: center; gap: .75rem;
  padding: 1.25rem 1rem; border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,.08);
}
.brand-icon { font-size: 1.6rem; }
.brand-name { font-size: .85rem; color: var(--text-muted); line-height: 1.3; }
.brand-name strong { color: var(--text); font-size: 1rem; }

.sidebar-nav { list-style: none; padding: .75rem 0; flex: 1; }
.sidebar-nav li a {
  display: flex; align-items: center; gap: .6rem;
  padding: .65rem 1.2rem; color: var(--text-muted);
  border-left: 3px solid transparent; transition: all .15s;
}
.sidebar-nav li.active a,
.sidebar-nav li a:hover {
  color: #fff; background: rgba(255,255,255,.12);
  border-left-color: var(--primary-lt); text-decoration: none;
}
.nav-icon { font-size: 1rem; }
.sidebar-footer { padding: 1rem; border-top: 1px solid var(--border); }

/* ── Topbar ──────────────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 2rem; border-bottom: 1px solid var(--border);
  background: linear-gradient(90deg, #1e4585 0%, #163269 100%);
  position: sticky; top: 0; z-index: 50;
}
.page-title { font-size: 1.25rem; font-weight: 600; }
.topbar-actions { display: flex; gap: .5rem; align-items: center; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .5rem 1rem; border-radius: 6px; font-size: .875rem;
  border: none; cursor: pointer; transition: background .15s;
}
.btn-sm { padding: .35rem .75rem; font-size: .8rem; }
.btn-primary { background: var(--primary-dk); color: #fff; }
.btn-primary:hover { background: #1a52c0; text-decoration: none; color: #fff; }
.btn-outline { background: rgba(255,255,255,.1); color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { background: rgba(255,255,255,.18); text-decoration: none; }
.btn-danger { background: rgba(239,68,68,.2); color: #fca5a5; border: 1px solid #7f1d1d; }
.btn-danger:hover { background: rgba(239,68,68,.35); text-decoration: none; color: #fca5a5; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem;
}
.form-card { padding: 1.5rem; }

/* ── Flash messages ──────────────────────────────────────────────────────── */
.flash-container { padding: .75rem 2rem 0; }
.flash { padding: .75rem 1rem; border-radius: 6px; margin-bottom: .5rem; font-size: .875rem; }
.flash-success  { background: #065f46; color: #a7f3d0; border: 1px solid #059669; }
.flash-danger   { background: #7f1d1d; color: #fca5a5; border: 1px solid #dc2626; }
.flash-info     { background: #1e3f80; color: #bfdbfe; border: 1px solid var(--border); }
.flash-warning  { background: #78350f; color: #fde68a; border: 1px solid #d97706; }

/* ── Active alert banner ─────────────────────────────────────────────────── */
.alert-banner {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  margin-bottom: 1.25rem; padding: .75rem 1rem;
  background: rgba(251,191,36,.12); border: 1px solid #d97706; border-radius: 8px;
  color: #fbbf24; font-size: .875rem;
}
.alert-banner-icon { font-size: 1.1rem; }
.ml-auto { margin-left: auto; }

/* ── Section headings ────────────────────────────────────────────────────── */
.section-heading {
  display: flex; align-items: center; justify-content: space-between;
  margin: 1.5rem 0 .75rem;
}
.section-heading h2 { font-size: 1rem; font-weight: 600; display: flex; align-items: center; gap: .5rem; }
.badge-count {
  background: var(--border); color: var(--text-muted);
  border-radius: 20px; padding: .1rem .5rem; font-size: .75rem;
}

/* ── Device grid ─────────────────────────────────────────────────────────── */
.device-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem;
}
.device-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem;
  display: flex; flex-direction: column; gap: .75rem;
  color: var(--text); transition: border-color .2s, transform .15s, box-shadow .2s; cursor: pointer;
}
.device-card:hover {
  border-color: var(--primary-lt); transform: translateY(-3px);
  box-shadow: 0 8px 32px rgba(77,138,240,.3); text-decoration: none;
}
.device-card-header { display: flex; justify-content: space-between; align-items: flex-start; }
.device-name { font-weight: 600; font-size: 1rem; }
.device-sub  { color: var(--text-muted); font-size: .8rem; margin-top: .1rem; }
.health-badge {
  padding: .2rem .6rem; border-radius: 20px; font-size: .75rem;
  font-weight: 600; color: #fff; white-space: nowrap;
}
.metric-row { display: flex; gap: .5rem; }
.metric-cell {
  flex: 1; background: rgba(255,255,255,.07); border: 1px solid var(--border);
  border-radius: 8px; padding: .6rem .5rem; text-align: center;
}
.metric-label { font-size: .7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.metric-value { font-size: 1.1rem; font-weight: 700; margin-top: .15rem; }
.metric-unit  { font-size: .65rem; color: var(--text-muted); font-weight: 400; margin-left: 1px; }
.val-warning  { color: var(--warning); }
.val-critical { color: var(--danger); }
.device-footer { display: flex; justify-content: space-between; align-items: center; }
.last-seen    { font-size: .75rem; color: var(--text-muted); }
.view-detail  { font-size: .8rem; color: var(--primary-lt); }
.device-no-data { color: var(--text-muted); font-size: .875rem; text-align: center; padding: .5rem; }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 4rem 2rem; text-align: center; gap: 1rem;
}
.empty-icon { font-size: 3rem; }
.empty-state h2 { font-size: 1.4rem; }
.empty-state p  { color: var(--text-muted); max-width: 380px; }
.empty-inline   { color: var(--text-muted); text-align: center; padding: 1.5rem; }

/* ── Current panel ───────────────────────────────────────────────────────── */
.current-panel {
  display: flex; gap: 1rem; flex-wrap: wrap;
  background: linear-gradient(135deg, #1e4585 0%, #163269 100%);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.5rem; margin-bottom: 1.5rem; box-shadow: var(--shadow);
}
.current-health {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 1.5rem; border: 3px solid; border-radius: var(--radius);
  min-width: 130px; text-align: center; background: rgba(255,255,255,.08);
}
.health-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); }
.health-value { font-size: 1.4rem; font-weight: 700; margin-top: .25rem; }
.health-idx   { font-size: .75rem; color: var(--text-muted); margin-top: .25rem; }
.current-metrics { display: flex; gap: .75rem; flex-wrap: wrap; flex: 1; align-items: center; }
.current-cell {
  background: rgba(255,255,255,.08); border: 1px solid var(--border);
  border-radius: 8px; padding: 1rem; text-align: center; min-width: 90px; flex: 1;
}
.current-icon  { font-size: 1.4rem; }
.current-label { font-size: .7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin: .25rem 0; }
.current-value { font-size: 1.4rem; font-weight: 700; }
.current-meta {
  display: flex; flex-direction: column; justify-content: center;
  gap: .35rem; font-size: .8rem; color: var(--text-muted);
  border-left: 1px solid var(--border); padding-left: 1rem; min-width: 160px;
}
.current-meta strong { color: var(--text); }

/* ── Chart grid ──────────────────────────────────────────────────────────── */
.chart-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
  gap: 1rem; margin-bottom: 1.5rem;
}
.chart-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; height: 220px;
}
.chart-card canvas { width: 100% !important; height: 100% !important; }

/* ── Selects & inputs ────────────────────────────────────────────────────── */
.select-sm, .input-sm {
  background: rgba(255,255,255,.1); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: .35rem .65rem; font-size: .85rem;
}
.select-sm:focus, .input-sm:focus { outline: none; border-color: var(--primary-lt); }
.select-sm option { background: #1e4585; color: #f0f5ff; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; }
.form-group { display: flex; flex-direction: column; gap: .3rem; }
.form-group label { font-size: .75rem; color: var(--text-muted); }
.form-group-end { flex-direction: row; align-items: flex-end; gap: .5rem; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table thead th {
  text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--border);
  color: var(--text-muted); font-size: .75rem; text-transform: uppercase;
  letter-spacing: .06em; background: rgba(0,0,0,.15);
}
.table tbody td { padding: .6rem .75rem; border-bottom: 1px solid var(--border); }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--bg-hover); }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge { display: inline-block; padding: .2rem .55rem; border-radius: 20px; font-size: .72rem; font-weight: 600; }
.badge-warning  { background: rgba(251,191,36,.2); color: #fbbf24; border: 1px solid #d97706; }
.badge-critical { background: rgba(248,113,113,.2); color: #f87171; border: 1px solid #dc2626; }

/* ── Toggle switch ───────────────────────────────────────────────────────── */
.toggle { position: relative; display: inline-block; width: 36px; height: 20px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; cursor: pointer;
  background: rgba(255,255,255,.2); border-radius: 20px; transition: .2s;
}
.slider::before {
  content: ''; position: absolute; width: 14px; height: 14px;
  left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: .2s;
}
.toggle input:checked + .slider { background: var(--primary-dk); }
.toggle input:checked + .slider::before { transform: translateX(16px); }

/* ── Alert log ───────────────────────────────────────────────────────────── */
.filter-bar { display: flex; gap: 1rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.filter-bar .input-sm { min-width: 240px; }
.toggle-label { display: flex; align-items: center; gap: .4rem; font-size: .875rem; cursor: pointer; }
.filter-count { margin-left: auto; color: var(--text-muted); font-size: .8rem; }
.row-active { background: rgba(248,113,113,.08) !important; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.status-dot.active   { background: var(--danger); box-shadow: 0 0 6px var(--danger); }
.status-dot.resolved { background: var(--success); }
