:root {
  --teal: #0f766e; --teal-d: #0b5a53; --green: #16a34a; --grey: #94a3b8;
  --red: #dc2626; --bg: #f1f5f9; --card: #ffffff; --ink: #0f172a; --muted: #64748b;
  --line: #e2e8f0; --amber: #d97706;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.4;
}
.screen { min-height: 100vh; }
.muted { color: var(--muted); }
.sm { font-size: 13px; }
[hidden] { display: none !important; }

/* ---------- login ---------- */
#login { display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  background: var(--card); border-radius: 18px; padding: 28px 22px; width: 100%; max-width: 380px;
  box-shadow: 0 10px 40px rgba(15,23,42,.10);
}
.brand { font-size: 24px; font-weight: 700; color: var(--teal); }
.login-card p { margin: 6px 0 20px; }
.switch { margin-top: 16px; text-align: center; }
.switch a { color: var(--teal); text-decoration: none; font-size: 14px; }

input, select {
  width: 100%; padding: 13px 14px; margin: 7px 0; border: 1px solid var(--line);
  border-radius: 12px; font-size: 16px; background: #fff; color: var(--ink);
}
input:focus, select:focus { outline: none; border-color: var(--teal); }

/* ---------- buttons ---------- */
.btn {
  border: none; border-radius: 12px; padding: 12px 16px; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: transform .05s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.block { width: 100%; margin-top: 10px; }
.btn.primary { background: var(--teal); color: #fff; }
.btn.ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.5); }
.btn.danger { background: var(--red); color: #fff; }
.btn.on { background: var(--green); color: #fff; }
.btn.off { background: #334155; color: #fff; }
.btn.tiny { padding: 8px 12px; font-size: 13px; }

/* ---------- app shell ---------- */
.topbar {
  background: var(--teal); color: #fff; display: flex; align-items: center;
  justify-content: space-between; padding: 14px 16px; position: sticky; top: 0; z-index: 5;
}
.who { font-weight: 600; }
.tabs {
  display: flex; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 52px; z-index: 4;
}
.tab {
  flex: 1; border: none; background: none; padding: 13px 4px; font-size: 14px; font-weight: 600;
  color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer;
}
.tab.active { color: var(--teal); border-bottom-color: var(--teal); }
main { padding: 14px; padding-bottom: 40px; max-width: 640px; margin: 0 auto; }
.tabpane { display: none; }
.tabpane.active { display: block; }
.list { display: flex; flex-direction: column; gap: 12px; }
.empty { text-align: center; color: var(--muted); padding: 40px 12px; }

/* ---------- cards ---------- */
.card {
  background: var(--card); border-radius: 16px; padding: 16px; box-shadow: 0 1px 3px rgba(15,23,42,.06);
}
.card-title { font-weight: 700; margin-bottom: 8px; }
.form-card { margin-bottom: 14px; }

/* DTU connection status */
.dtu-status {
  display: flex; align-items: center; gap: 8px; padding: 11px 14px; margin-bottom: 12px;
  background: var(--card); border-radius: 12px; box-shadow: 0 1px 2px rgba(15,23,42,.05);
}
.dtu-text { font-weight: 700; font-size: 15px; }
.dtu-status.online .dtu-text { color: var(--green); }
.dtu-status.offline .dtu-text { color: var(--red); }
.dtu-seen { margin-left: auto; font-size: 12px; color: var(--muted); }
.offline-banner {
  background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c;
  border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; font-size: 14px; line-height: 1.5;
}

/* motor card */
.motor { }
.motor .row1 { display: flex; align-items: center; justify-content: space-between; }
.motor .mname { font-size: 18px; font-weight: 700; }
.motor .dname { font-size: 12px; color: var(--muted); }
.pill { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.pill.on { background: #dcfce7; color: var(--green); }
.pill.off { background: #f1f5f9; color: var(--muted); }
.badge { font-size: 11px; font-weight: 700; }
.badge.online { color: var(--green); }
.badge.offline { color: var(--grey); }
.runtime { margin: 10px 0; font-variant-numeric: tabular-nums; font-size: 14px; color: var(--muted); }
.runtime b { color: var(--ink); font-size: 16px; }
.ctrls { display: flex; gap: 8px; margin-top: 6px; }
.ctrls .btn { flex: 1; }

/* ---- actual-state lamp (FC01 relay truth) ---- */
.lamp-wrap {
  display: flex; align-items: center; gap: 14px;
  margin: 12px 0; padding: 14px 16px; border-radius: 16px;
  background: #f8fafc; border: 2px solid var(--line);
}
.lamp-wrap .lamp { font-size: 40px; line-height: 1; }
.lamp-wrap.on  { background: #dcfce7; border-color: #86efac; }
.lamp-wrap.on  .lamp { color: var(--green); }
.lamp-wrap.off { background: #f1f5f9; border-color: #e2e8f0; }
.lamp-wrap.off .lamp { color: var(--grey); }
.lamp-wrap.unknown .lamp { color: #cbd5e1; }
.lamp-wrap.stale { opacity: .5; filter: grayscale(1); }
.lamp-state { font-size: 20px; font-weight: 800; letter-spacing: .3px; }
.lamp-wrap.on  .lamp-state { color: #15803d; }
.lamp-wrap.off .lamp-state { color: var(--muted); }
.lamp-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---- command vs actual confirm / mismatch ---- */
.confirm { font-size: 13px; font-weight: 600; padding: 8px 12px; border-radius: 10px; margin: 0 0 8px; }
.confirm.ok   { color: #15803d; background: #f0fdf4; }
.confirm.warn { color: #b45309; background: #fffbeb; border-left: 4px solid var(--amber); }

/* ---- offline apply note ---- */
.apply-note { font-size: 12px; color: var(--amber); margin-top: 8px; font-weight: 600; }

/* ---- DI health row (display only) ---- */
.di-row {
  display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px;
  padding-top: 10px; border-top: 1px dashed var(--line);
}
.di { font-size: 12px; color: var(--muted); flex: 1; min-width: 120px; }
.di b { font-weight: 700; color: var(--grey); }
.di.active b { color: var(--green); }
.di.na b { color: #cbd5e1; }

/* ---- Part C: active-state highlight + syncing + running-timer ---- */
.card.motor.is-on { border: 2px solid var(--green); box-shadow: 0 0 0 3px rgba(22,163,74,.12); }
.card.motor.syncing { border: 2px solid var(--amber); box-shadow: 0 0 0 3px rgba(217,119,6,.12); }
.sync-badge { display:inline-block; font-size:11px; font-weight:700; color:#b45309; background:#fef3c7;
  padding:2px 9px 2px 7px; border-radius:999px; margin-left:6px; vertical-align:middle; }
.sync-badge::before { content:'⟳'; display:inline-block; margin-right:3px; animation: spin 1.1s linear infinite; }
/* command buttons reflect ACTUAL relay state (pressed = this is the current state) */
.btn.on.pressed  { box-shadow: inset 0 0 0 2px rgba(255,255,255,.55), 0 0 0 3px rgba(22,163,74,.4);  filter: brightness(1.06); }
.btn.off.pressed { box-shadow: inset 0 0 0 2px rgba(255,255,255,.25), 0 0 0 3px rgba(51,65,85,.4); }
/* running-timer preset chip (distinct from the tap-to-select .active) */
.tpreset.running { background: var(--teal); color:#fff; border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15,118,110,.28); font-weight:700; }

/* ---- HERO status block: the single biggest, most glanceable element on the card.
   Bigger than the ON/OFF buttons on purpose — a farmer reads it from across the room.
   High-contrast fills for bright sunlight; no animation (fast on cheap Androids). ---- */
.hero { display:flex; align-items:center; gap:14px; padding:15px 16px; border-radius:16px;
  margin:2px 0 12px; border:2px solid transparent; }
.hero-icon { font-size:44px; line-height:1; flex:none; }
.hero-txt { min-width:0; }
.hero-label { font-size:27px; font-weight:900; letter-spacing:.3px; line-height:1.05; }
.hero-sub { font-size:13px; font-weight:600; margin-top:3px; opacity:.92; }
.hero.running  { background:#dcfce7; border-color:#4ade80; }
.hero.running  .hero-icon, .hero.running  .hero-label, .hero.running  .hero-sub { color:#15803d; }
.hero.starting { background:#fef9c3; border-color:#facc15; }
.hero.starting .hero-icon, .hero.starting .hero-label, .hero.starting .hero-sub { color:#a16207; }
.hero.fault    { background:#fee2e2; border-color:#f87171; }
.hero.fault    .hero-icon, .hero.fault    .hero-label, .hero.fault    .hero-sub { color:#b91c1c; }
.hero.stopped  { background:#eef2f7; border-color:#cbd5e1; }
.hero.stopped  .hero-icon, .hero.stopped  .hero-label, .hero.stopped  .hero-sub { color:#475569; }
.hero.offline  { background:#eef2f7; border-color:#cbd5e1; opacity:.85; }
.hero.offline  .hero-icon, .hero.offline  .hero-label, .hero.offline  .hero-sub { color:#64748b; }
.hero.unknown  { background:#f8fafc; border-color:#e2e8f0; }
.hero.unknown  .hero-icon, .hero.unknown  .hero-label, .hero.unknown  .hero-sub { color:#94a3b8; }

/* Big red fault banner — readable, not tiny. Shown only on a true contactor fault. */
.fault-banner { font-size:15px; font-weight:800; line-height:1.35; color:#7f1d1d;
  background:#fef2f2; border:2px solid #fca5a5; border-left:6px solid #dc2626;
  border-radius:12px; padding:12px 14px; margin:0 0 12px; }

/* Secondary detail chips (relay + DI) — small, below the timer controls. */
.details { display:flex; flex-wrap:wrap; gap:7px; margin-top:12px; padding-top:11px;
  border-top:1px solid #e8edf3; }
.chip { font-size:12px; font-weight:700; padding:5px 10px; border-radius:999px;
  background:#f1f5f9; color:#64748b; white-space:nowrap; }
.chip.relay-on { background:#dcfce7; color:#15803d; }
.chip.di-on    { background:#dcfce7; color:#15803d; }

/* ---- STATUS INDICATORS (Part A): labeled, legible tiles — Relay + Input1(phase) + Input2(contactor).
   Secondary to the hero but clearly readable; colored dots; inputs always shown for wiring checks. ---- */
.indicators { display:grid; grid-template-columns:1fr 1fr 1fr; gap:8px; margin-top:14px;
  padding-top:12px; border-top:1px solid #e8edf3; }
.ind { display:flex; flex-direction:column; gap:4px; background:#f8fafc; border:1px solid #eef2f7;
  border-radius:12px; padding:9px 10px; }
.ind-label { font-size:12px; font-weight:700; color:#475569; }
.ind-hint  { font-size:10px; font-weight:600; color:#94a3b8; display:block; margin-top:-1px; }
.ind-val   { font-size:13.5px; font-weight:800; line-height:1.2; }
.ind-val.on { color:#15803d; }
.ind-val.off { color:#64748b; }
.ind-val.na { color:#94a3b8; }

/* ---- Schedules (recurring on/off) ---- */
.sched-btn { width: 100%; margin-top: 10px; background: #f0fdfa; color: var(--teal);
  border: 1.5px solid #99f6e4; font-weight: 700; min-height: 46px; }
.sched-bg { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 75;
  display: flex; align-items: flex-end; justify-content: center; }
.sched-card { background: var(--card); width: 100%; max-width: 480px; max-height: 90vh; overflow: auto;
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(20px + env(safe-area-inset-bottom, 0px)); }
@media (min-width: 520px) { .sched-bg { align-items: center; } .sched-card { border-radius: 18px; } }
.sched-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sched-head span { font-size: 18px; font-weight: 800; }
.sched-x { background: #f1f5f9; border: none; width: 34px; height: 34px; border-radius: 50%; font-size: 16px; cursor: pointer; color: var(--muted); }
.sched-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.sched-empty { padding: 8px 2px; }
.sched-item { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: #f8fafc; border: 1px solid #eef2f7; border-radius: 12px; padding: 11px 12px; }
.sched-item.is-off { opacity: .62; }
.sched-when { font-size: 14px; font-weight: 700; color: var(--ink); }
.sched-paused { font-size: 11px; font-weight: 700; color: var(--amber); background: #fef3c7; border-radius: 999px; padding: 1px 8px; }
.sched-item-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.btn.tiny { padding: 7px 10px; font-size: 12px; min-height: 0; }
.mini-switch { position: relative; display: inline-block; width: 40px; height: 24px; flex: none; }
.mini-switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.mini-switch .ms-track { position: absolute; inset: 0; background: #cbd5e1; border-radius: 999px; transition: background .2s; }
.mini-switch .ms-track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; background: #fff; border-radius: 50%; transition: left .2s; }
.mini-switch input:checked + .ms-track { background: var(--teal); }
.mini-switch input:checked + .ms-track::after { left: 19px; }
.sched-form { background: #f0fdfa; border: 1px solid #ccfbf1; border-radius: 14px; padding: 14px; }
.sched-form-title { font-weight: 800; font-size: 15px; margin-bottom: 12px; color: #0f766e; }
.seg-row { display: flex; gap: 6px; margin-bottom: 12px; }
.seg { flex: 1; padding: 10px 4px; border-radius: 10px; border: 1px solid var(--line); background: #fff;
  color: var(--muted); font-weight: 700; font-size: 12.5px; cursor: pointer; }
.seg.active { background: var(--teal); color: #fff; border-color: var(--teal); }
.sf-field { margin-bottom: 12px; }
.sf-field label { display: block; font-size: 12px; font-weight: 700; color: #334155; margin-bottom: 5px; }
.sf-field input, .sf-field select { width: 100%; min-height: 48px; margin: 0; }
.dur-presets { display: flex; gap: 6px; margin: -4px 0 12px; }
.dpre { flex: 1; padding: 8px 4px; border-radius: 9px; border: 1px solid var(--line); background: #fff; color: var(--ink); font-weight: 600; font-size: 12px; cursor: pointer; }
.day-chips { display: flex; gap: 5px; flex-wrap: wrap; }
.day-chip { flex: 1; min-width: 40px; padding: 9px 2px; border-radius: 9px; border: 1px solid var(--line);
  background: #fff; color: var(--muted); font-weight: 700; font-size: 12px; cursor: pointer; }
.day-chip.on { background: var(--teal); color: #fff; border-color: var(--teal); }
.sched-form-actions { display: flex; gap: 8px; margin-top: 4px; }
.sched-form-actions .btn { flex: 1; min-height: 48px; }

/* ---- Part C: customer 3-phase protection toggle + guarded OFF ---- */
.ph-status { margin-top: 10px; font-size: 14px; font-weight: 700; }
.ph-status.on  { color: #15803d; }
.ph-status.off { color: #b91c1c; }
.ph-status.muted { color: var(--muted); font-weight: 600; }
.rc-status { margin-top: 10px; }
/* persistent reminder banner on the motor card when the customer switched protection off */
.phase-off-banner { font-size: 13px; font-weight: 800; color: #7f1d1d; background: #fef2f2;
  border: 1.5px solid #fca5a5; border-left: 5px solid #dc2626; border-radius: 10px;
  padding: 10px 12px; margin: 0 0 10px; line-height: 1.4; }
/* blocking warning dialog */
.warn-bg { position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 80;
  display: flex; align-items: center; justify-content: center; padding: 20px; }
.warn-card { background: var(--card); border-radius: 16px; padding: 22px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.4); border-top: 6px solid var(--red); }
.warn-title { font-size: 19px; font-weight: 900; color: #b91c1c; margin-bottom: 10px; }
.warn-body { font-size: 14px; line-height: 1.55; color: var(--ink); margin: 0 0 18px; }
.warn-body b { color: #b91c1c; }
.warn-actions { display: flex; flex-direction: column; gap: 10px; }
.warn-actions .btn { margin: 0; min-height: 50px; }
.btn.warn-danger { background: #fff; color: #b91c1c; border: 2px solid #fca5a5; font-weight: 700; }
.log.warn-log { background: #fef2f2; border-left: 4px solid var(--red); }
.log.warn-log .lt { color: #b91c1c; font-weight: 700; }

/* ---- 3-phase safety interlock (prominent bar — now at the bottom of the card, per final layout) ---- */
.phase { font-size:15px; font-weight:800; padding:11px 14px; border-radius:12px; margin:12px 0 0;
  display:flex; align-items:center; gap:6px; }
.phase.ok  { color:#15803d; background:#dcfce7; border:2px solid #86efac; }
.phase.bad { color:#b91c1c; background:#fee2e2; border:2px solid #fca5a5; }
.phase { flex-wrap:wrap; }
.phase-rate { margin-left:auto; font-size:11px; font-weight:600; opacity:.85; }
.phase-trip { font-size:13px; font-weight:600; color:#7f1d1d; background:#fef2f2;
  border-left:4px solid var(--red); padding:10px 12px; border-radius:8px; margin:0 0 10px; line-height:1.45; }
.phase-block-note { font-size:12px; font-weight:600; color:#b91c1c; margin-top:8px; }

/* Contactor run-confirm (diagnostic) — distinct from the 3-phase strip above it. */
.run-confirm { font-size:14px; font-weight:700; padding:9px 12px; border-radius:12px; margin:0 0 10px; }
.run-confirm.running  { color:#15803d; background:#dcfce7; border:1.5px solid #86efac; }
.run-confirm.starting { color:#b45309; background:#fffbeb; border:1.5px solid #fde68a; }
.run-confirm.fault    { color:#b91c1c; background:#fee2e2; border:1.5px solid #fca5a5; }
.run-confirm.stopped  { color:var(--muted); background:#f1f5f9; border:1.5px solid #e2e8f0; font-weight:600; }
.card.motor.rc-fault    { border:2px solid #ef4444; box-shadow:0 0 0 3px rgba(239,68,68,.12); }
.card.motor.rc-starting { border:2px solid var(--amber); box-shadow:0 0 0 3px rgba(217,119,6,.10); }
.btn.on:disabled { background:#cbd5e1; color:#64748b; box-shadow:none; filter:none; }
.toast.warn { background:#b91c1c; color:#fff; font-weight:600; }
.timer-row { display: flex; gap: 8px; margin-top: 10px; }
.timer-row input { margin: 0; flex: 1; }
.timer-row .btn { white-space: nowrap; }

/* logs */
.log { background: var(--card); border-radius: 12px; padding: 10px 14px; display: flex;
  align-items: center; justify-content: space-between; box-shadow: 0 1px 2px rgba(15,23,42,.05); }
.log .l { display: flex; flex-direction: column; }
.log .lt { font-weight: 600; }
.log .ls { font-size: 12px; color: var(--muted); }
.tag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 6px; }
.tag.ON { background: #dcfce7; color: var(--green); }
.tag.OFF { background: #fee2e2; color: var(--red); }

/* alarm rules */
.alarm { background: var(--card); border-radius: 12px; padding: 12px 14px;
  box-shadow: 0 1px 2px rgba(15,23,42,.05); }
.alarm.triggered { border: 1.5px solid var(--amber); background: #fffbeb; }
.alarm .a1 { display: flex; align-items: center; justify-content: space-between; }
.alarm .atitle { font-weight: 700; }
.alarm .asub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.alarm .fire { color: var(--amber); font-weight: 700; font-size: 12px; margin-top: 6px; }

.chk { display: flex; align-items: center; gap: 10px; margin: 10px 2px; font-size: 15px; }
.chk input { width: auto; margin: 0; width: 20px; height: 20px; }

.msg { font-size: 13px; margin-top: 8px; min-height: 18px; }
.msg.err { color: var(--red); }
.msg.ok { color: var(--green); }

/* ---------- analytics ---------- */
.tabs .tab { font-size: 12px; padding: 13px 2px; white-space: nowrap; }
.an-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.an-chip { padding: 8px 16px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font-weight: 600; font-size: 14px; cursor: pointer; }
.an-chip.active { background: var(--teal); color: #fff; border-color: var(--teal); }
.an-presets { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.an-preset { flex: 1; min-width: 68px; padding: 9px 6px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--muted); font-weight: 600; font-size: 13px; cursor: pointer; }
.an-preset.active { background: var(--teal); color: #fff; border-color: var(--teal); }
.an-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.an-card { background: var(--card); border-radius: 16px; padding: 18px 14px; text-align: center;
  box-shadow: 0 1px 3px rgba(15,23,42,.06); }
.an-lbl { color: var(--muted); font-size: 13px; font-weight: 600; }
.an-num { color: var(--teal); font-size: 30px; font-weight: 800; margin-top: 6px; font-variant-numeric: tabular-nums; }
.an-longest { background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; border-radius: 12px;
  padding: 12px 14px; margin-bottom: 14px; font-weight: 700; font-size: 14px; }
.an-daily { display: flex; flex-direction: column; gap: 8px; }
.an-row { display: flex; align-items: center; gap: 10px; font-size: 12px; }
.an-dlabel { width: 52px; color: var(--muted); flex: none; font-weight: 600; }
.an-bar { flex: 1; background: #e2e8f0; border-radius: 5px; height: 20px; overflow: hidden; }
.an-on { background: var(--green); height: 100%; border-radius: 5px; }
.an-hrs { width: 120px; text-align: right; color: var(--muted); flex: none; white-space: nowrap; }
.an-cycles { display: flex; flex-direction: column; }
.an-cyc-row { display: flex; justify-content: space-between; gap: 8px; padding: 9px 2px;
  border-bottom: 1px solid var(--line); font-size: 14px; }
.an-cyc-row:last-child { border-bottom: none; }
.an-cyc-row.head { color: var(--muted); font-size: 12px; font-weight: 700; }
.an-cyc-row span { flex: 1; }
.an-cyc-row .dur { text-align: right; font-weight: 700; color: var(--ink); }
.an-loading { display: flex; justify-content: center; padding: 40px; }
.spinner { width: 34px; height: 34px; border: 4px solid var(--line); border-top-color: var(--teal);
  border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 11px 18px; border-radius: 10px;
  font-size: 14px; z-index: 50; max-width: 90%; text-align: center;
}

/* ===================== mobile polish (Task 4) & analytics (Task 5) ===================== */
/* bottom navigation bar */
.tabs.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; top: auto;
  border-top: 1px solid var(--line); border-bottom: none; z-index: 20;
  padding: 4px 2px calc(4px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -2px 10px rgba(15,23,42,.06);
}
.tabs.bottomnav .tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 2px; font-size: 11px; border-bottom: none;
}
.tabs.bottomnav .tab .ti { font-size: 20px; line-height: 1; }
.tabs.bottomnav .tab.active { color: var(--teal); border-bottom: none; }
main { padding-bottom: 88px; }

/* bigger motor controls */
.motor { padding: 20px 18px; }
.motor .ctrls { gap: 10px; margin-top: 12px; }
.motor .ctrls .btn { min-height: 56px; font-size: 18px; border-radius: 14px; }
.runtime { font-size: 14px; }
.runtime b.rt { display: inline-block; font-size: 24px; color: var(--teal); font-weight: 800; }

/* timer preset buttons */
.timer-presets { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.tpreset { flex: 1; min-width: 52px; padding: 9px 4px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font-weight: 600; font-size: 13px; cursor: pointer; }
.tpreset.active { background: var(--teal); color: #fff; border-color: var(--teal); }
.timer-row .btn { min-height: 46px; }

/* status banner — full width, prominent, icon */
.dtu-status { border-left: 5px solid var(--grey); padding: 14px; gap: 12px; }
.dtu-status.online { border-left-color: var(--green); background: #ecfdf5; }
.dtu-status.offline { border-left-color: var(--red); background: #fef2f2; }
.dtu-icon { font-size: 18px; }
.dtu-status.online .dtu-icon { color: var(--green); }
.dtu-status.offline .dtu-icon { color: var(--red); }
.dtu-textwrap { display: flex; flex-direction: column; }
.dtu-text { font-size: 16px; }
.dtu-seen { margin-left: 0; }
.offline-banner { font-size: 15px; }

/* toast — top of screen, bigger */
.toast { top: 16px; bottom: auto; min-height: 48px; display: flex; align-items: center;
  justify-content: center; font-size: 16px; border-radius: 12px; padding: 14px 20px;
  box-shadow: 0 6px 24px rgba(0,0,0,.28); }

/* command spinner overlay */
.cmd-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.35); z-index: 60;
  display: flex; align-items: center; justify-content: center; }
.spinner.big { width: 52px; height: 52px; border-width: 5px; }

/* forgot-password code box */
.fp-code { background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: 12px; padding: 12px 14px;
  margin: 8px 0; font-size: 18px; color: #065f46; text-align: center; }

/* analytics — colored summary cards */
.an-card { position: relative; padding: 16px 14px; text-align: center; }
.an-card .an-ic { font-size: 20px; }
.an-card .an-num { font-size: 32px; font-weight: 800; margin-top: 2px; }
.an-card .an-unit { color: var(--muted); font-size: 11px; margin-top: 2px; text-transform: uppercase; letter-spacing: .03em; }
.an-card.teal { background: #ecfdf5; } .an-card.teal .an-num { color: var(--teal); }
.an-card.grey { background: #f1f5f9; } .an-card.grey .an-num { color: #475569; }
.an-card.blue { background: #eff6ff; } .an-card.blue .an-num { color: #2563eb; }
.an-card.orange { background: #fff7ed; } .an-card.orange .an-num { color: #d97706; }

/* analytics — vertical bar chart */
.an-chart-wrap { display: flex; gap: 8px; }
.an-yaxis { display: flex; flex-direction: column; justify-content: space-between; height: 180px;
  font-size: 11px; color: var(--muted); padding-bottom: 22px; flex: none; }
.an-chart { display: flex; align-items: flex-end; gap: 8px; overflow-x: auto; flex: 1; padding-bottom: 2px; }
.an-col { display: flex; flex-direction: column; align-items: center; gap: 6px; flex: none; cursor: pointer; }
.an-coltrack { width: 24px; height: 180px; background: #e2e8f0; border-radius: 6px;
  display: flex; align-items: flex-end; overflow: hidden; }
.an-colon { width: 100%; background: var(--green); border-radius: 6px 6px 0 0; min-height: 2px; }
.an-collabel { font-size: 11px; color: var(--muted); white-space: nowrap; }
.an-tooltip { position: fixed; z-index: 70; background: #0f172a; color: #fff; padding: 8px 12px;
  border-radius: 8px; font-size: 13px; width: 140px; text-align: center; box-shadow: 0 6px 20px rgba(0,0,0,.3); }

/* analytics — recent cycles timeline */
.an-timeline { position: relative; padding-left: 22px; }
.an-timeline::before { content: ""; position: absolute; left: 7px; top: 4px; bottom: 4px; width: 2px; background: var(--line); }
.an-tl-item { position: relative; margin-bottom: 12px; }
.an-tl-dot { position: absolute; left: -19px; top: 8px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--card); }
.an-tl-dot.done { background: var(--green); }
.an-tl-dot.running { background: var(--amber); box-shadow: 0 0 0 3px rgba(217,119,6,.2); }
.an-tl-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.an-tl-title { font-weight: 700; }
.an-run { font-size: 11px; color: var(--amber); font-weight: 700; }
.an-tl-time { font-size: 13px; color: var(--muted); margin-top: 2px; }
.an-tl-dur { font-weight: 700; color: var(--teal); margin-top: 2px; }

/* ===================== power-failure recovery + live timer ===================== */
.restore-banner { background: #fffbeb; border: 1px solid #fcd34d; color: #92400e; border-radius: 12px;
  padding: 14px; margin-bottom: 12px; font-weight: 700; font-size: 15px; }
.restored-badge { font-size: 11px; font-weight: 700; color: #b45309; background: #fef3c7;
  border-radius: 999px; padding: 2px 8px; margin-left: 6px; }
.runtime.on { color: var(--muted); }
.runtime.on b.rt { display: inline-block; font-size: 24px; color: var(--teal); font-weight: 800; font-variant-numeric: tabular-nums; }
.runtime.off { color: var(--muted); font-size: 14px; }
.runtime .lastrun { color: var(--muted); font-size: 13px; }
.countdown { margin-top: 8px; background: #f0fdfa; border: 1px solid #99f6e4; color: #0f766e;
  border-radius: 10px; padding: 8px 12px; font-size: 15px; font-weight: 600; }
.countdown b { font-variant-numeric: tabular-nums; }
.countdown.paused { background: #fff7ed; border-color: #fdba74; color: #b45309; font-size: 14px; }
.log.restore { background: #fffbeb; border-left: 4px solid var(--amber); }
.log.restore .lt { color: #92400e; font-weight: 700; }
.power-events { margin-bottom: 12px; }
.power-events:empty { display: none; }
.pevent { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); padding: 6px 0; }
.pevent .pdot { width: 9px; height: 9px; border-radius: 50%; background: var(--amber); flex: none; }
.pevent b { color: var(--ink); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 15px; font-weight: 600; margin-top: 6px; }
.switch { appearance: none; -webkit-appearance: none; width: 52px; height: 30px; border-radius: 999px;
  background: #cbd5e1; position: relative; cursor: pointer; transition: background .2s; flex: none; margin: 0; }
.switch:checked { background: var(--teal); }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px;
  border-radius: 50%; background: #fff; transition: left .2s; }
.switch:checked::after { left: 25px; }

/* ===================== login / password polish (Task 1) ===================== */
#login { padding: 20px 16px; }
.login-card { padding: 30px 22px calc(24px + env(safe-area-inset-bottom, 0px)); border-radius: 20px; }
.brand { font-size: 26px; text-align: center; margin-bottom: 2px; }
#login-sub, #forgot-view p { text-align: center; }
.login-card p { margin: 6px 0 14px; }

/* field labels + larger, higher-contrast inputs (readable in sunlight) */
.fld-label { display: block; font-size: 13px; font-weight: 700; color: #334155; margin: 12px 0 5px; }
.login-card input, #tab-account input { min-height: 52px; font-size: 16px; border-width: 2px; border-color: #cbd5e1; margin: 0 0 4px; }
.login-card input:focus, #tab-account input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(15,118,110,.14); }

/* full-width prominent primary buttons */
.btn-lg { min-height: 54px; font-size: 17px; font-weight: 700; margin-top: 18px; }

/* in-button loading spinner (works on any solid button) */
.btn { position: relative; }
.btn.loading { color: transparent !important; pointer-events: none; }
.btn.loading::after {
  content: ''; position: absolute; left: 50%; top: 50%; width: 20px; height: 20px;
  margin: -10px 0 0 -10px; border: 2.5px solid rgba(255,255,255,.45); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite;
}

/* auth links — clean, centered, well spaced, easy to tap */
.login-links { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-top: 22px; }
.login-links a { color: var(--teal); text-decoration: none; font-size: 15px; font-weight: 600; padding: 6px 8px; }

/* wizard heading */
.fp-head { font-size: 20px; font-weight: 800; color: var(--ink); text-align: center; margin-bottom: 2px; }

/* OTP highlighted box — large spaced digits */
.fp-code { background: #ecfdf5; border: 1.5px solid #6ee7b7; border-radius: 14px; padding: 16px 14px;
  margin: 8px 0 6px; text-align: center; color: #065f46; font-size: inherit; }
.otp-caption { font-size: 12px; font-weight: 700; color: #047857; text-transform: uppercase; letter-spacing: .06em; }
.otp-digits { font-size: 34px; font-weight: 800; color: #065f46; letter-spacing: 6px; padding-left: 6px;
  font-variant-numeric: tabular-nums; margin: 6px 0 4px; }
.otp-valid { font-size: 13px; color: #047857; font-weight: 700; }
.otp-input { text-align: center; letter-spacing: 8px; font-size: 22px; font-weight: 700; padding-left: 8px; }

/* password-reset success */
.fp-success { text-align: center; padding: 20px 8px 8px; }
.fp-check { width: 70px; height: 70px; margin: 0 auto 14px; border-radius: 50%; background: var(--green);
  color: #fff; font-size: 40px; line-height: 70px; font-weight: 800; box-shadow: 0 6px 18px rgba(22,163,74,.35); }
.fp-success-title { font-size: 21px; font-weight: 800; color: var(--green); margin-bottom: 4px; }

/* inline per-field error (red, under the field) */
.fld-err { color: var(--red); font-size: 13px; font-weight: 600; margin: 0 0 4px; }

/* analytics retention note */
.an-retention { margin: -6px 0 14px; text-align: center; }

/* --- billing --- */
.bill-reminder { background: #fef9c3; border: 1px solid #fde68a; color: #854d0e; border-radius: 12px;
  padding: 12px 14px; margin-bottom: 12px; font-size: 14px; }
.bill-reminder a { color: #854d0e; font-weight: 700; text-decoration: none; }
.bill-hero { border-radius: 16px; padding: 22px 18px; text-align: center; margin-bottom: 14px; color: #fff; }
.bill-hero-title { font-size: 26px; font-weight: 800; line-height: 1.2; }
.bill-hero-sub { font-size: 14px; margin-top: 6px; opacity: .95; }
.bill-hero.paid { background: linear-gradient(135deg, #16a34a, #15803d); }
.bill-hero.due { background: linear-gradient(135deg, #f59e0b, #d97706); }
.bill-hero.reported { background: linear-gradient(135deg, #2563eb, #1d4ed8); }
.bill-q { font-weight: 700; margin: 14px 0 10px; text-align: center; }
.bill-q-btns { display: flex; gap: 10px; justify-content: center; }
.bill-q-btns .btn { flex: 1; }
#bill-ref-wrap { margin-top: 14px; }
.bill-hist { display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 8px; border-bottom: 1px solid var(--line); font-size: 14px; }
.bill-hist:last-child { border-bottom: none; }
.bill-hist .ok { color: var(--green); font-weight: 600; font-size: 13px; }
/* keep the 6-tab bottom nav from overflowing on narrow phones */
.bottomnav .tab { min-width: 0; }
.bottomnav .tl { font-size: 10px; }

/* --- billing: 3-method payment section --- */
.pay-card { text-align: center; }
.pay-hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.pay-div { display: flex; align-items: center; gap: 10px; margin: 18px 0 14px; color: var(--muted); font-size: 12px; }
.pay-div::before, .pay-div::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.pay-div span { white-space: nowrap; }
.pay-qr { display: flex; justify-content: center; }
.pay-qr img { width: 210px; max-width: 62%; height: auto; image-rendering: pixelated;
  border: 1px solid var(--line); border-radius: 12px; padding: 8px; background: #fff; }
.pay-manual { background: #f8fafc; border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.pay-upi-row { display: flex; align-items: center; gap: 10px; justify-content: center; }
.pay-upi-row code { font-size: 15px; font-weight: 700; color: var(--ink); word-break: break-all; }
.pay-amt { font-size: 13px; color: var(--muted); margin-top: 6px; }
.btn.sm { padding: 6px 14px; font-size: 13px; width: auto; flex: none; }
.pay-confirm { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.pay-after { font-weight: 700; margin-bottom: 10px; }
#bill-ref-wrap { margin-top: 14px; text-align: left; }

/* ---------- PWA: header refresh, pull-to-refresh, notif status ---------- */
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  background: rgba(255,255,255,.16); color: #fff; border: none;
  width: 38px; height: 38px; border-radius: 10px; font-size: 22px; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0;
}
.icon-btn:active { background: rgba(255,255,255,.32); }
.icon-btn.spin { animation: spin .6s linear; }

/* pull-to-refresh strip (sits above the sticky header; height driven by JS) */
.ptr {
  height: 0; overflow: hidden; display: flex; align-items: center; justify-content: center;
  background: var(--bg); transition: height .14s ease;
}
.ptr-spin {
  width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--teal);
  border-radius: 50%; opacity: .45;
}
.ptr.ready .ptr-spin { opacity: 1; }
.ptr.spinning .ptr-spin { opacity: 1; animation: spin .6s linear infinite; }

.notif-status { margin-top: 8px; }
.notif-status.blocked { color: var(--red); font-weight: 600; }
