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

:root {
  --bg:         #020617;
  --surface:    #0f172a;
  --surface2:   #1e293b;
  --border:     #334155;
  --accent:     #f59e0b;
  --accent-dim: rgba(245,158,11,0.12);
  --danger:     #ef4444;
  --danger-dim: rgba(239,68,68,0.10);
  --ok:         #22c55e;
  --ok-dim:     rgba(34,197,94,0.10);
  --text:       #f1f5f9;
  --text-muted: #94a3b8;
  --radius:     14px;
  --t:          0.18s ease;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  min-height: 100dvh;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

#app { max-width: 520px; margin: 0 auto; padding: 20px 16px; }

/* ── animations ──────────────────────────────────────────────────────── */
@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.7); }
  50%       { box-shadow: 0 0 0 6px rgba(239,68,68,0); }
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes alarm-pulse {
  0%, 100% {
    box-shadow:
      0 0 0 0   rgba(239,68,68,0),
      0 0 0 1px rgba(239,68,68,0.2);
  }
  50% {
    box-shadow:
      0 0 22px 2px rgba(239,68,68,0.18),
      0 0 0 1px    rgba(239,68,68,0.5);
  }
}

/* ── auth ────────────────────────────────────────────────────────────── */
.auth-card {
  display: flex; flex-direction: column; gap: 20px;
  padding: 36px 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 48px;
  animation: fade-in 0.3s ease;
}

.auth-brand {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.auth-brand img {
  width: 80px; height: 80px; border-radius: 20px;
}
.auth-brand h1 {
  font-size: 1.75rem; font-weight: 700; letter-spacing: -0.5px;
}

.tab-row {
  display: flex; gap: 4px;
  background: var(--bg);
  border-radius: 10px; padding: 4px;
}
.tab {
  flex: 1; padding: 9px 12px;
  border: none; border-radius: 8px;
  background: transparent; color: var(--text-muted);
  font-size: 0.92rem; font-weight: 500;
  cursor: pointer; transition: all var(--t);
}
.tab.active { background: var(--surface2); color: var(--text); }

form { display: flex; flex-direction: column; gap: 12px; }

input[type="email"],
input[type="password"],
input[type="text"] {
  padding: 13px 15px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem; outline: none;
  transition: border-color var(--t);
}
input:focus { border-color: var(--accent); }

/* ── buttons ─────────────────────────────────────────────────────────── */
.btn-primary {
  padding: 14px; border-radius: 10px; border: none;
  background: var(--accent);
  color: #1a0a00;
  font-size: 1rem; font-weight: 700; cursor: pointer;
  transition: opacity var(--t), transform var(--t);
}
.btn-primary:hover  { opacity: 0.9; }
.btn-primary:active { transform: scale(0.98); opacity: 0.82; }

.btn-secondary {
  padding: 10px 18px; border-radius: 10px;
  border: 1px solid var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 0.93rem; font-weight: 500; cursor: pointer;
  transition: background var(--t);
}
.btn-secondary:hover { background: rgba(245,158,11,0.2); }

.btn-ghost {
  padding: 9px 14px; border-radius: 10px; border: none;
  background: transparent; color: var(--text-muted);
  font-size: 0.9rem; cursor: pointer;
  transition: color var(--t), background var(--t);
}
.btn-ghost:hover { background: var(--surface2); color: var(--text); }

.btn-copy {
  padding: 6px 14px; border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent-dim); color: var(--accent);
  font-size: 0.82rem; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background var(--t);
}
.btn-copy:hover { background: rgba(245,158,11,0.2); }

.btn-delete {
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  border-radius: 7px; border: none;
  background: transparent; color: var(--text-muted);
  font-size: 0.85rem; cursor: pointer; margin-left: auto;
  transition: color var(--t), background var(--t);
}
.btn-delete:hover { color: var(--danger); background: var(--danger-dim); }

/* ── dashboard ───────────────────────────────────────────────────────── */
.dashboard { display: flex; flex-direction: column; gap: 20px; }

header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 4px 0 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
header h1 {
  font-size: 1.2rem; font-weight: 700; letter-spacing: -0.3px;
  display: flex; align-items: center; gap: 9px;
}
.header-logo { width: 30px; height: 30px; border-radius: 8px; }
.header-actions { display: flex; gap: 6px; align-items: center; }

#homes-list { display: flex; flex-direction: column; gap: 10px; }

/* ── home cards ──────────────────────────────────────────────────────── */
.home-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  position: relative; overflow: hidden;
  transition: border-color var(--t);
}

/* ok cards get the entrance animation */
.home-card:not(.down) { animation: fade-in 0.25s ease; }

/* down cards skip the entrance and go straight to alarm */
.home-card.down {
  border-color: transparent;
  background: color-mix(in srgb, var(--surface) 92%, #450a0a 8%);
  animation: alarm-pulse 2.2s ease-in-out infinite;
}

.home-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--ok);
}
.home-card.down::before { background: var(--danger); }

.home-header {
  display: flex; align-items: center; gap: 10px; margin-bottom: 10px;
}

.status-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.status-dot.ok {
  background: var(--ok);
  box-shadow: 0 0 7px rgba(34,197,94,0.55);
}
.status-dot.down {
  background: var(--danger);
  animation: pulse-dot 1.6s ease-in-out infinite;
}

.home-name { font-size: 1.05rem; font-weight: 600; flex: 1; }

.home-meta {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 0.84rem; color: var(--text-muted);
}

.conn-time {
  display: flex; align-items: center; gap: 6px;
  font-variant-numeric: tabular-nums;
}
.conn-time::before { content: '↻'; opacity: 0.55; font-size: 0.78rem; }

.outage-info {
  color: var(--danger); font-weight: 500;
  display: flex; align-items: center; gap: 5px;
}
.outage-info::before { content: '⚡'; font-size: 0.75rem; }

.outage-history { color: var(--text-muted); }

/* ── add home ────────────────────────────────────────────────────────── */
.add-home-form { display: flex; flex-direction: column; gap: 20px; }

.token-result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  display: flex; flex-direction: column; gap: 16px;
  animation: fade-in 0.25s ease;
}
.token-result-card h2 { font-size: 1.1rem; font-weight: 700; }
.token-result-card h3 { font-size: 0.92rem; font-weight: 600; color: var(--text-muted); }
.token-result-card p  { font-size: 0.88rem; color: var(--text-muted); }

.token-block {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px; overflow: hidden;
}
.token-block code {
  font-family: ui-monospace, 'Cascadia Code', 'Fira Code', monospace;
  font-size: 0.77rem; word-break: break-all; flex: 1; color: var(--accent);
}

.setup-steps {
  padding-left: 20px;
  display: flex; flex-direction: column; gap: 14px; font-size: 0.88rem;
}
.setup-steps li { line-height: 1.5; }
.setup-steps pre {
  margin-top: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px; padding: 12px;
  font-size: 0.77rem; overflow-x: auto;
  white-space: pre-wrap; word-break: break-all;
  color: var(--text-muted);
}

/* ── utils ───────────────────────────────────────────────────────────── */
.error { color: var(--danger); font-size: 0.88rem; min-height: 1.2em; }
.loading, .empty {
  color: var(--text-muted); padding: 40px 0;
  text-align: center; font-size: 0.95rem;
}
.empty { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty-icon { font-size: 2.5rem; opacity: 0.4; }
.hidden { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
