:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --bg-elevated: #14181f;
  --bg-tile: #1a2030;
  --bg-tile-hover: #222a3c;
  --border: #2a3348;
  --text: #e8ecf4;
  --text-dim: #8b95a8;
  --accent: #5b8cff;
  --accent-soft: rgba(91, 140, 255, 0.15);
  --success: #3dd68c;
  --danger: #ff6b7a;
  --warn: #f5c542;
  --radius: 20px;
  --touch: 64px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; }

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

button, .btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  font-size: 1.15rem;
  min-height: var(--touch);
  min-width: var(--touch);
  padding: 0.85rem 1.6rem;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  transition: transform 0.08s ease, background 0.15s ease, opacity 0.15s;
}
button:active, .btn:active { transform: scale(0.98); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.secondary, .btn.secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
}
button.danger, .btn.danger { background: var(--danger); }
button.success, .btn.success { background: var(--success); color: #062416; }

input[type="text"], input[type="password"] {
  width: 100%;
  min-height: var(--touch);
  padding: 0.85rem 1.1rem;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 1.15rem;
}

/* ---------- QR / pairing login (Tesla) ---------- */
.login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  gap: 1.5rem;
  background:
    radial-gradient(ellipse at 50% 0%, #1a2744 0%, transparent 55%),
    var(--bg);
}

.login-screen h1 {
  font-size: clamp(1.6rem, 3vw, 2.4rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.login-sub {
  color: var(--text-dim);
  font-size: 1.15rem;
  text-align: center;
  max-width: 36rem;
}

.qr-wrap {
  background: #fff;
  padding: 1.25rem;
  border-radius: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.45);
}

.qr-wrap svg { display: block; width: min(42vw, 320px); height: auto; }

.short-code {
  font-size: clamp(2.5rem, 6vw, 4rem);
  font-weight: 800;
  letter-spacing: 0.35em;
  padding-left: 0.35em;
  font-variant-numeric: tabular-nums;
}

.timer {
  color: var(--text-dim);
  font-size: 1rem;
}

.timer.warn { color: var(--warn); }
.timer.expired { color: var(--danger); }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.95rem;
}
.status-pill.ok { color: var(--success); border-color: rgba(61,214,140,0.35); }
.status-pill.err { color: var(--danger); border-color: rgba(255,107,122,0.35); }

.phone-hint {
  margin-top: 0.5rem;
  color: var(--text-dim);
  font-size: 0.95rem;
}
.phone-hint code {
  background: var(--bg-elevated);
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  color: var(--text);
}

/* ---------- Phone pages ---------- */
.phone {
  max-width: 480px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.phone h1 { font-size: 1.6rem; margin-bottom: 0.35rem; }
.phone .lead { color: var(--text-dim); margin-bottom: 1.5rem; }

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card dt {
  color: var(--text-dim);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 0.75rem;
}
.card dt:first-child { margin-top: 0; }
.card dd { font-size: 1.1rem; margin-top: 0.2rem; word-break: break-word; }

.actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1.25rem;
}
.actions button, .actions .btn { flex: 1; }

.msg {
  padding: 0.85rem 1rem;
  border-radius: 12px;
  margin-bottom: 1rem;
  background: var(--accent-soft);
  color: var(--text);
}
.msg.error { background: rgba(255,107,122,0.15); color: var(--danger); }
.msg.ok { background: rgba(61,214,140,0.12); color: var(--success); }

/* ---------- Dashboard (Tesla landscape) ---------- */
.dash {
  min-height: 100vh;
  padding: 1.5rem 2rem 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.greeting {
  font-size: clamp(1.8rem, 3.5vw, 2.8rem);
  font-weight: 700;
  letter-spacing: -0.03em;
}
.greeting .dim { color: var(--text-dim); font-weight: 500; }

.clock-block {
  text-align: right;
}
.clock-time {
  font-size: clamp(2rem, 4vw, 3.2rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.clock-date {
  color: var(--text-dim);
  font-size: 1.1rem;
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 1.25rem;
  flex: 1;
}

.tile {
  background: var(--bg-tile);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 220px;
}

.tile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.35rem;
  cursor: pointer;
  user-select: none;
  background: transparent;
  color: inherit;
  width: 100%;
  min-height: var(--touch);
  border-radius: 0;
  text-align: left;
}
.tile-head:hover { background: var(--bg-tile-hover); }
.tile-head h2 {
  font-size: 1.35rem;
  font-weight: 650;
}
.tile-head .chev {
  color: var(--text-dim);
  font-size: 1.4rem;
  transition: transform 0.2s ease;
}
.tile.collapsed .chev { transform: rotate(-90deg); }
.tile.collapsed .tile-body { display: none; }

.tile-body {
  padding: 0 1.35rem 1.35rem;
  color: var(--text-dim);
  flex: 1;
}

.tile-placeholder {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.5rem 0;
}
.tile-placeholder .row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 52px;
  padding: 0.5rem 0.85rem;
  border-radius: 12px;
  background: rgba(255,255,255,0.03);
  border: 1px dashed var(--border);
}
.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
}
.badge.warn { background: rgba(245,197,66,0.15); color: var(--warn); }

.nav-links {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.nav-links a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-size: 1rem;
  min-height: 48px;
  padding: 0.6rem 1.1rem;
}

.device-list { list-style: none; }
.device-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}
.device-list li:last-child { border-bottom: none; }
.device-meta { color: var(--text-dim); font-size: 0.9rem; }

@media (min-width: 1600px) {
  .dash { padding: 2rem 3rem 3rem; }
  .tile-grid { grid-template-columns: repeat(3, 1fr); }
}
