:root {
  --bg-0: #050810;
  --bg-1: #0B1220;
  --bg-2: #111827;
  --surface: rgba(17, 24, 39, 0.7);
  --border: rgba(51, 65, 85, 0.6);
  --primary: #38BDF8;
  --primary-deep: #0EA5E9;
  --cold: #22D3EE;
  --frozen: #818CF8;
  --warm: #FBBF24;
  --hot: #EF4444;
  --good: #34D399;
  --offline: #94A3B8;
  --text: #E2E8F0;
  --text-soft: #94A3B8;
  --text-dim: #64748B;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
  background: radial-gradient(ellipse at 20% -10%, rgba(14, 165, 233, 0.2), transparent 60%),
              linear-gradient(180deg, #050810 0%, #0B1220 50%, #050810 100%);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); }

/* ===== Top bar ===== */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  position: sticky; top: 0;
  background: rgba(11, 18, 32, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  z-index: 50;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 38px; height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--cold));
  box-shadow: 0 6px 20px rgba(14, 165, 233, 0.4);
  position: relative;
}
.brand-mark::after {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255,255,255,0.4), transparent);
}
.brand-eyebrow {
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--text-dim);
  font-weight: 600;
}
.brand-title {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.topbar-right { display: flex; gap: 10px; align-items: center; }

.conn-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  border-radius: 100px;
  background: rgba(52, 211, 153, 0.1);
  color: var(--good);
  font-size: 12px;
  font-weight: 600;
  border: 1px solid rgba(52, 211, 153, 0.3);
}
.conn-pill.bad {
  background: rgba(239, 68, 68, 0.1);
  color: var(--hot);
  border-color: rgba(239, 68, 68, 0.3);
}
.conn-pill i {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: currentColor;
  display: block;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.3); }
}

.icon-btn {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: rgba(56, 189, 248, 0.1);
  color: var(--primary);
  border: 1px solid rgba(56, 189, 248, 0.3);
  font-size: 20px;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s;
}
.icon-btn:hover { background: rgba(56, 189, 248, 0.2); transform: rotate(45deg); }

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 4px;
  padding: 16px 24px 0;
  border-bottom: 1px solid var(--border);
}
.tab {
  padding: 12px 18px;
  background: transparent;
  border: 0;
  color: var(--text-soft);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

main { padding: 24px; max-width: 1100px; margin: 0 auto; }

.tab-pane { display: none; animation: fadeIn 0.3s ease; }
.tab-pane.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ===== Cards ===== */
.card {
  background: linear-gradient(160deg, rgba(17,24,39,0.85), rgba(11,18,32,0.7));
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px;
  margin-bottom: 20px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.card.glass { box-shadow: 0 20px 60px rgba(0,0,0,0.3); }

.card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 14px;
}
.card-header h3 { margin: 0; font-size: 18px; font-weight: 700; }
.card-header .muted { color: var(--text-dim); font-size: 12px; }

/* ===== Sensor card ===== */
#sensors-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.sensor-big {
  position: relative;
  padding: 24px;
  border-radius: 20px;
  background: linear-gradient(160deg, rgba(17,24,39,0.85), rgba(11,18,32,0.7));
  border: 1px solid var(--border);
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.sensor-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 24px;
}
.sensor-head h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.3px; }
.sensor-head .loc { color: var(--text-soft); font-size: 14px; margin-top: 4px; }

.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid currentColor;
}
.status-pill::before {
  content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor;
}
.status-pill.ok { color: var(--good); background: rgba(52,211,153,0.1); }
.status-pill.crit { color: var(--hot); background: rgba(239,68,68,0.1); }
.status-pill.crit::before { animation: pulse 0.9s infinite; }
.status-pill.offline { color: var(--offline); background: rgba(148,163,184,0.1); }
.status-pill.empty { color: transparent; border-color: transparent; background: transparent; }
.status-pill.empty::before { display: none; }

.dial-wrap {
  display: flex; justify-content: center; padding: 12px 0;
}
.dial {
  width: 240px; height: 240px;
  position: relative;
}
.dial-value {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.dial-temp {
  font-size: 64px;
  font-weight: 900;
  letter-spacing: -2px;
  line-height: 1;
}
.dial-unit { color: var(--text-soft); font-size: 14px; font-weight: 600; margin-top: 4px; }

.range-info {
  text-align: center;
  font-size: 13px;
  color: var(--text-soft);
  font-weight: 500;
  margin-bottom: 18px;
}

.metric-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.metric {
  background: rgba(5,8,16,0.6);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
}
.metric .label {
  font-size: 10px; letter-spacing: 1.2px;
  color: var(--text-soft);
  font-weight: 600;
  margin-bottom: 6px;
}
.metric .value { font-size: 22px; font-weight: 700; }
.metric .icon { font-size: 14px; opacity: 0.7; margin-right: 4px; }
.metric .metric-sub {
  font-size: 10px;
  margin-top: 4px;
  font-weight: 600;
  color: var(--text-soft);
}
.metric-bat.metric-warn { background: rgba(251,191,36,0.1); border-color: rgba(251,191,36,0.3); }
.metric-bat.metric-warn .metric-sub { color: var(--warm); }
.metric-bat.metric-crit { background: rgba(239,68,68,0.12); border-color: rgba(239,68,68,0.4); }
.metric-bat.metric-crit .metric-sub { color: var(--hot); }
.bat-info {
  margin-top: 12px;
  padding: 8px 12px;
  background: rgba(5,8,16,0.5);
  border-radius: 8px;
  font-size: 11px;
  color: var(--text-soft);
  text-align: center;
}

.updated-at {
  text-align: center;
  color: var(--text-dim);
  font-size: 11px;
  margin-top: 14px;
}

/* ===== Chart ===== */
.chart-wrap { height: 240px; margin-top: 12px; }

/* ===== Alerts list ===== */
.alerts-list { list-style: none; padding: 0; margin: 0; }
.alerts-list li {
  padding: 14px;
  background: rgba(5,8,16,0.6);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 10px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.alerts-list li.cleared { opacity: 0.5; }
.alerts-list .alert-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.alerts-list .alert-icon.crit { background: rgba(239,68,68,0.15); color: var(--hot); }
.alerts-list .alert-icon.warn { background: rgba(251,191,36,0.15); color: var(--warm); }
.alerts-list .alert-icon.good { background: rgba(52,211,153,0.15); color: var(--good); }
.alerts-list .alert-icon.info { background: rgba(56,189,248,0.15); color: var(--primary); }
.alerts-list .alert-body { flex: 1; min-width: 0; }
.alerts-list .alert-title { font-weight: 700; font-size: 14px; }
.alerts-list .alert-sub { font-size: 13px; color: var(--text-soft); }
.alerts-list .alert-time { font-size: 11px; color: var(--text-dim); margin-top: 4px; }
.alerts-list .empty { justify-content: center; color: var(--text-dim); }

/* ===== Settings forms ===== */
.form-row, .form-grid {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}
.form-row { grid-template-columns: 1fr 2fr; }
.form-grid { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 640px) {
  .form-row, .form-grid { grid-template-columns: 1fr; }
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-soft);
}
input, select {
  padding: 11px 14px;
  background: rgba(5,8,16,0.6);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(56,189,248,0.2);
}
input::placeholder { color: var(--text-dim); }

.check {
  flex-direction: row;
  align-items: center;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.check input { width: auto; }

.presets { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.presets > span { font-size: 12px; color: var(--text-soft); margin-right: 6px; }
.presets button {
  background: rgba(56,189,248,0.08);
  border: 1px solid rgba(56,189,248,0.25);
  color: var(--primary);
  border-radius: 100px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.presets button:hover { background: rgba(56,189,248,0.15); }

.row-actions { display: flex; gap: 10px; flex-wrap: wrap; }
button {
  padding: 11px 18px;
  border-radius: 10px;
  border: 0;
  background: var(--primary);
  color: #050810;
  font-weight: 700;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
}
button:hover { filter: brightness(1.1); }
button:active { transform: translateY(1px); }
button.secondary { background: rgba(56,189,248,0.1); color: var(--primary); border: 1px solid rgba(56,189,248,0.3); }
button.primary { background: linear-gradient(135deg, var(--primary), var(--primary-deep)); color: white; }

/* ===== Status pill nas configs ===== */
.status-pill.cfg {
  background: rgba(148,163,184,0.1); color: var(--text-soft); border-color: rgba(148,163,184,0.2);
}
.status-pill.cfg.on { background: rgba(52,211,153,0.1); color: var(--good); border-color: rgba(52,211,153,0.3); }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: rgba(17,24,39,0.95);
  border: 1px solid var(--border);
  padding: 14px 20px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 100;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  backdrop-filter: blur(10px);
}
.toast.hidden { display: none; }
.toast.ok { border-color: rgba(52,211,153,0.5); }
.toast.err { border-color: rgba(239,68,68,0.5); color: var(--hot); }

/* ===== ALARM OVERLAY ===== */
.alarm-overlay {
  position: fixed; inset: 0;
  z-index: 1000;
  background: linear-gradient(180deg, #7F1D1D 0%, #450A0A 60%, #000 100%);
  display: flex;
  align-items: center; justify-content: center;
  padding: 32px;
}
.alarm-overlay.hidden { display: none; }
.alarm-pulse {
  position: absolute; inset: 0;
  background: radial-gradient(circle, rgba(239,68,68,0.7), transparent 70%);
  animation: alarm-pulse 1.2s ease-in-out infinite;
  pointer-events: none;
}
@keyframes alarm-pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.7; }
}
.alarm-content {
  position: relative;
  text-align: center;
  max-width: 480px;
  width: 100%;
  color: white;
}
.alarm-icon { font-size: 88px; animation: shake 0.5s infinite alternate; }
@keyframes shake { from { transform: rotate(-8deg) scale(1); } to { transform: rotate(8deg) scale(1.1); } }
.alarm-content h1 {
  margin: 8px 0 0;
  font-size: 64px;
  font-weight: 900;
  letter-spacing: 6px;
}
.alarm-content p { font-size: 18px; opacity: 0.9; font-weight: 600; }
.alarm-card {
  background: rgba(0,0,0,0.3);
  border-radius: 20px;
  padding: 24px;
  margin: 24px 0;
}
.alarm-card h2 { margin: 0; font-size: 24px; }
.alarm-sub { font-size: 14px; opacity: 0.7; margin-top: 4px; }
.alarm-value { font-size: 88px; font-weight: 900; line-height: 1; margin: 12px 0; }
.alarm-value small { font-size: 28px; opacity: 0.7; }

.alarm-ack {
  width: 100%;
  padding: 22px;
  background: white;
  color: #7F1D1D;
  font-weight: 900;
  font-size: 18px;
  letter-spacing: 1px;
  border-radius: 14px;
  margin-bottom: 10px;
}
.alarm-snooze {
  width: 100%;
  background: transparent;
  border: 2px solid white;
  color: white;
  padding: 14px;
}

.hidden { display: none !important; }

.howto {
  background: rgba(56, 189, 248, 0.06);
  border: 1px solid rgba(56, 189, 248, 0.2);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--text-soft);
}
.howto summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--primary);
  user-select: none;
}
.howto ol { margin: 10px 0 6px; padding-left: 22px; }
.howto li { margin-bottom: 6px; }
.howto code {
  background: rgba(0,0,0,0.4);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--cold);
  font-family: ui-monospace, monospace;
  font-size: 12px;
}
.ntfy-preview {
  margin-bottom: 12px;
  padding: 8px 12px;
  background: rgba(5,8,16,0.6);
  border-radius: 8px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  color: var(--text-soft);
}
.ntfy-preview.ok { color: var(--good); }
.ntfy-preview.bad { color: var(--hot); }

.test-alarm-card {
  border-color: rgba(239, 68, 68, 0.4) !important;
  background: linear-gradient(160deg, rgba(127, 29, 29, 0.4), rgba(11,18,32,0.7)) !important;
}
.big-alarm-btn {
  width: 100%;
  padding: 18px;
  background: linear-gradient(135deg, #DC2626, #7F1D1D);
  color: white;
  font-weight: 900;
  font-size: 16px;
  letter-spacing: 1px;
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(220, 38, 38, 0.3);
}
.big-alarm-btn:hover {
  filter: brightness(1.15);
  transform: translateY(-2px);
}
