/* ============ Child Monitoring System - styles ============ */
:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #243247;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; flex-shrink: 0; background: #0b1220;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 14px;
  position: sticky; top: 0; height: 100vh;
}
.brand { font-size: 18px; font-weight: 700; margin-bottom: 24px; }
.sidebar nav { display: flex; flex-direction: column; gap: 6px; }
.sidebar nav a {
  color: var(--text); text-decoration: none; padding: 10px 12px;
  border-radius: 8px; transition: background .15s;
}
.sidebar nav a:hover { background: var(--panel-2); }
.sidebar nav a.active { background: var(--accent); color: #082032; font-weight: 600; }
.sidebar-user { margin-top: auto; color: var(--muted); font-size: 12px; line-height: 1.5; }

.content { flex: 1; padding: 20px 24px; }
.page-header { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-header h1 { margin: 0; font-size: 22px; }
.muted { color: var(--muted); font-size: 12px; }

.live-badge {
  background: var(--panel); border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 14px; display: inline-flex; align-items: center; gap: 8px; font-size: 12px;
}
.dot {
  width: 9px; height: 9px; border-radius: 50%; background: var(--green);
  animation: pulse 1.5s infinite; display: inline-block;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* ---------- panels / cards ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; font-size: 15px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px;
}
.stat-label { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.stat-value { font-size: 24px; font-weight: 700; }

.dash-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
@media (max-width: 1000px) { .dash-grid { grid-template-columns: 1fr; } }

#map { height: 420px; border-radius: 8px; z-index: 0; }
.map-legend { display: flex; gap: 16px; margin-top: 8px; font-size: 12px; color: var(--muted); }
/* ---------- device list ---------- */
.device-list { display: flex; flex-direction: column; gap: 10px; max-height: 470px; overflow-y: auto; }
.device-card {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; cursor: pointer; transition: border-color .15s;
}
.device-card:hover { border-color: var(--accent); }
.device-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.device-card .dc-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.device-card .dc-name { font-weight: 600; }
.device-card .dc-meta { color: var(--muted); font-size: 12px; margin-top: 4px; line-height: 1.5; }
.device-card .dc-sensors { display: flex; gap: 14px; margin-top: 6px; font-size: 13px; }

.badge { padding: 2px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge-on  { background: rgba(34,197,94,.15); color: var(--green); border: 1px solid var(--green); }
.badge-off { background: rgba(239,68,68,.12); color: var(--red); border: 1px solid var(--red); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.table tr:hover td { background: rgba(56,189,248,.05); }

/* ---------- forms ---------- */
.filter-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.field { display: block; margin-bottom: 14px; }
.field span, .field-inline span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.field-inline { display: flex; flex-direction: column; }
.field-inline.grow { flex: 1; min-width: 220px; }
input, select {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 9px 12px; font-size: 14px; outline: none; font-family: inherit;
}
input:focus, select:focus { border-color: var(--accent); }
.input-sm { padding: 4px 8px; font-size: 12px; width: 160px; }
.select { min-width: 180px; }

.btn {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 9px 16px; border-radius: 8px; cursor: pointer; font-size: 14px; font-family: inherit;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); color: #082032; border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.1); color: #082032; }
.btn-block { width: 100%; }
.btn-sm { padding: 4px 8px; font-size: 12px; border-radius: 6px; }
.btn-danger:hover { border-color: var(--red); color: var(--red); }
.actions { display: flex; gap: 6px; }
.inline-form { display: inline-flex; gap: 4px; margin: 0; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }
.alert-error { background: rgba(239,68,68,.12); border: 1px solid var(--red); color: #fca5a5; }
.alert-ok { background: rgba(34,197,94,.12); border: 1px solid var(--green); color: #86efac; }

code.apikey { background: #0b1220; padding: 3px 7px; border-radius: 5px; font-size: 12px; color: var(--amber); word-break: break-all; }
code.endpoint { background: #0b1220; padding: 3px 7px; border-radius: 5px; font-size: 11px; color: var(--muted); }

.lg-online { color: var(--green); } .lg-offline { color: var(--red); } .lg-sel { color: var(--accent); }

/* ---------- auth pages ---------- */
.auth-body {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  padding: 24px 16px;
  background:
    radial-gradient(900px 480px at 8% -8%, rgba(56,189,248,.16), transparent 60%),
    radial-gradient(760px 420px at 108% 108%, rgba(34,197,94,.12), transparent 60%),
    var(--bg);
}
.auth-shell {
  display: grid; grid-template-columns: 1.05fr .95fr;
  width: 880px; max-width: 96vw; border-radius: 20px; overflow: hidden;
  border: 1px solid var(--border); background: var(--panel);
  box-shadow: 0 30px 90px rgba(0,0,0,.5);
}
/* left brand panel */
.auth-hero {
  position: relative; padding: 44px 38px; color: #f0f9ff; overflow: hidden;
  background: linear-gradient(160deg, #0ea5e9 0%, #0c6fae 45%, #0b3a5c 100%);
  display: flex; flex-direction: column; gap: 26px;
}
.auth-hero::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(circle at 82% 10%, rgba(255,255,255,.16) 0 10px, transparent 11px),
    radial-gradient(circle at 64% 32%, rgba(255,255,255,.11) 0 6px, transparent 7px),
    radial-gradient(circle at 20% 80%, rgba(255,255,255,.09) 0 9px, transparent 10px),
    radial-gradient(circle at 90% 70%, rgba(255,255,255,.07) 0 14px, transparent 15px);
}
.auth-brand { display: flex; align-items: center; gap: 12px; font-size: 17px; font-weight: 700; }
.auth-brand .logo {
  width: 44px; height: 44px; border-radius: 12px; background: rgba(255,255,255,.18);
  display: flex; align-items: center; justify-content: center; font-size: 22px;
  border: 1px solid rgba(255,255,255,.28);
}
.auth-hero h1 { font-size: 26px; line-height: 1.25; margin: 0; }
.auth-hero .lead { margin: 10px 0 0; color: rgba(240,249,255,.82); font-size: 14px; line-height: 1.6; }
.auth-feats { display: flex; flex-direction: column; gap: 12px; margin-top: auto; position: relative; }
.auth-feat { display: flex; align-items: center; gap: 10px; font-size: 13px; color: rgba(240,249,255,.94); }
.auth-feat .fi {
  width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0;
  background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.22);
  display: flex; align-items: center; justify-content: center; font-size: 14px;
}
/* right form card */
.auth-card { padding: 42px 36px; display: flex; flex-direction: column; justify-content: center; }
.auth-card h2 { margin: 0 0 4px; font-size: 20px; }
.auth-sub { color: var(--muted); margin: 0 0 22px; font-size: 13px; }
.auth-card .field { margin-bottom: 14px; }
.input-wrap { position: relative; display: block; }
.input-wrap .icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  font-size: 14px; opacity: .65; pointer-events: none; line-height: 1;
}
.input-wrap input { width: 100%; padding-left: 38px; }
.input-wrap.has-toggle input { padding-right: 44px; }
.pw-toggle {
  position: absolute; right: 5px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: 15px; opacity: .65;
  padding: 6px; line-height: 1;
}
.pw-toggle:hover { opacity: 1; }
.auth-card .btn-block { margin-top: 6px; padding: 12px; font-size: 15px; }
.auth-switch, .auth-hint { margin-top: 18px; font-size: 13px; color: var(--muted); text-align: center; }
.auth-hint code { background: var(--panel-2); padding: 2px 6px; border-radius: 5px; }
.auth-card a { color: var(--accent); text-decoration: none; font-weight: 600; }
.auth-card a:hover { text-decoration: underline; }
@media (max-width: 860px) {
  .auth-shell { grid-template-columns: 1fr; width: 420px; }
  .auth-hero { padding: 26px 24px; gap: 14px; }
  .auth-hero h1 { font-size: 20px; }
  .auth-feats { display: none; }
  .auth-card { padding: 28px 24px; }
}

