:root {
  --teal: #0d9488;
  --teal-deep: #0b6e7c;
  --bg: #0f172a;
  --card: #1e293b;
  --card-2: #243248;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --line: #334155;
  --warn: #f59e0b;
  --crit: #ef4444;
  --ok: #22c55e;
}

* { box-sizing: border-box; }
html, body { margin: 0; overflow-x: hidden; max-width: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

.hidden { display: none !important; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
  background: linear-gradient(180deg, var(--teal), var(--teal-deep));
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.conn { display: flex; align-items: center; gap: 6px; font-size: 13px; opacity: .9; }
.conn .dot { width: 9px; height: 9px; border-radius: 50%; background: #cbd5e1; }
.conn.online .dot { background: var(--ok); }
.conn.offline .dot { background: var(--crit); }
.status-icons { display: flex; align-items: center; gap: 16px; }
.pump-ind.on .dot { background: var(--ok); }
.pump-ind.off .dot { background: var(--crit); }

main { max-width: 560px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }

.card { background: var(--card); border-radius: 16px; padding: 16px; box-shadow: 0 1px 0 rgba(255,255,255,.03) inset; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.head-actions { display: flex; gap: 6px; flex: none; }
h2 { font-size: 16px; margin: 0; display: inline; }
h3 { grid-column: 1 / -1; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 8px 0 0; }

/* The ⓘ button next to settings section headers — taps open a descriptive popup. */
.info-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; margin-left: 6px; padding: 0; vertical-align: text-bottom;
  border: 1px solid var(--muted); border-radius: 50%; background: transparent;
  color: var(--muted); font: italic 700 11px/1 Georgia, serif; text-transform: none;
  cursor: pointer;
}
.info-btn:hover, .info-btn:focus-visible { color: var(--text); border-color: var(--text); }

/* Alert banner */
.banner { border-radius: 16px; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.banner.warn { background: #422006; border: 1px solid var(--warn); }
.banner.crit { background: #450a0a; border: 1px solid var(--crit); }
.banner .b-title { font-weight: 700; }
.banner .b-msg { font-size: 14px; color: #fde68a; }
.banner.crit .b-msg { color: #fecaca; }
.banner .b-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Live gauge */
.live { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.gauge-wrap { position: relative; width: 220px; height: 220px; }
.gauge { width: 220px; height: 220px; transform: rotate(-90deg); }
.gauge-track { fill: none; stroke: var(--line); stroke-width: 16; }
.gauge-arc {
  fill: none; stroke: var(--teal); stroke-width: 16; stroke-linecap: round;
  transition: stroke-dashoffset .4s ease, stroke .3s ease;
}
.gauge-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.watts { font-size: 46px; font-weight: 800; line-height: 1; }
.watts-unit { color: var(--muted); font-size: 13px; margin-top: 4px; }

.live-meta { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.pill { padding: 6px 16px; border-radius: 999px; font-weight: 700; font-size: 14px; }
.pill.idle { background: var(--card-2); color: var(--muted); }
.pill.running { background: rgba(13,148,136,.2); color: #5eead4; }
.pill.alert { background: rgba(239,68,68,.2); color: #fca5a5; }

.readouts { display: flex; gap: 22px; flex-wrap: wrap; justify-content: center; }
.readouts > div { text-align: center; }
.readouts span { font-size: 18px; font-weight: 700; }
.readouts label { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; }

/* Range tabs */
.range-tabs { display: flex; gap: 4px; background: var(--card-2); border-radius: 10px; padding: 3px; }
.range-tabs button { border: 0; background: transparent; color: var(--muted); padding: 5px 12px; border-radius: 8px; font-size: 13px; cursor: pointer; }
.range-tabs button.active { background: var(--teal); color: #fff; }

.chart { width: 100%; display: block; }
.chart-legend { display: flex; gap: 16px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.chart-legend .sw { display: inline-block; width: 14px; height: 10px; vertical-align: middle; margin-right: 5px; border-radius: 2px; }
.chart-legend .sw.line { background: var(--teal); height: 3px; }
.chart-legend .sw.shade { background: rgba(13,148,136,.25); }

/* Settings */
summary { cursor: pointer; list-style: none; }
summary::-webkit-details-marker { display: none; }
summary::after { content: "▾"; float: right; color: var(--muted); }
details[open] summary::after { content: "▴"; }

.actions { display: flex; gap: 8px; margin: 14px 0 6px; }
.actions .btn { flex: 1; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; margin-top: 8px; }
.grid label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; min-width: 0; }
.grid label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.grid input[type="number"], .grid input[type="text"], .grid input[type="time"] {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-size: 15px;
  width: 100%; min-width: 0; /* allow inputs to shrink inside the grid (no horizontal overflow) */
}
/* Narrow phones (e.g. Galaxy Z Flip): one column so the form never overflows the viewport. */
@media (max-width: 460px) {
  .grid { grid-template-columns: 1fr; }
}
.form-actions { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; margin-top: 6px; }

.btn { border: 1px solid var(--line); background: var(--card-2); color: var(--text); padding: 9px 14px; border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.success { background: var(--ok); border-color: var(--ok); color: #052e16; }
.btn.danger { background: var(--crit); border-color: var(--crit); color: #fff; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; }

.pump-toggle { width: 100%; padding: 11px 14px; font-size: 15px; margin-top: 16px; margin-bottom: 2px; }
.notif-head { margin-top: 20px; }

/* Alert history */
.alert-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.alert-row { display: flex; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.alert-row:last-child { border-bottom: 0; }
.alert-row.closed { opacity: .55; }
.alert-row .dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 5px; flex: none; background: var(--muted); }
.alert-row .dot.sev-warning { background: var(--warn); }
.alert-row .dot.sev-critical { background: var(--crit); }
.alert-body { flex: 1; min-width: 0; }
.alert-top { display: flex; justify-content: space-between; gap: 8px; }
.alert-when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.alert-msg { font-size: 13px; color: var(--text); margin: 2px 0; }
.alert-status { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }

.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
/* Away switch */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.away-row { margin: 16px 0 6px; }
.switch-label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.switch-label small { font-weight: 400; color: var(--muted); font-size: 12px; line-height: 1.4; }
.switch-row input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 50px; height: 28px; border-radius: 999px; background: var(--card-2);
  border: 1px solid var(--line); position: relative; cursor: pointer; transition: background .15s;
}
.switch-row input[type="checkbox"]::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 22px; height: 22px;
  border-radius: 50%; background: #cbd5e1; transition: transform .15s;
}
.switch-row input[type="checkbox"]:checked { background: var(--teal); border-color: var(--teal); }
.switch-row input[type="checkbox"]:checked::after { transform: translateX(22px); background: #fff; }
.control-buttons { display: flex; gap: 8px; margin-top: 14px; }
.control-buttons .btn { flex: 1; }

/* Custom confirm modal */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  background: rgba(2, 6, 23, .65); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
.modal-box {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 20px; width: 100%; max-width: 360px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, .55);
  animation: modal-in .14s ease-out;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-title { margin: 0 0 8px; font-size: 18px; }
.modal-body { margin: 0 0 18px; color: var(--muted); font-size: 14px; line-height: 1.45; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 18px; }
.foot a { color: #5eead4; }
