:root {
  --bg: #f3f7fb;
  --card: #ffffff;
  --text: #0f2233;
  --muted: #5b6f82;
  --line: #e2e9f1;
  --brand: #0284c7;
  --brand-2: #0ea5e9;
  --brand-ink: #ffffff;
  --brand-soft: #e0f2fe;
  --ok: #16a34a; --ok-soft: #dcfce7;
  --warn: #d97706; --warn-soft: #fef3c7;
  --bad: #dc2626; --bad-soft: #fee2e2;
  --info-soft: #e0f2fe;
  --shadow: 0 1px 2px rgba(15, 34, 51, .06), 0 4px 16px rgba(15, 34, 51, .05);
  --radius: 16px;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1520; --card: #12202e; --text: #e6eef6; --muted: #8fa3b6; --line: #1f3244;
    --brand: #38bdf8; --brand-2: #0ea5e9; --brand-ink: #062033; --brand-soft: #0c2a3d;
    --ok: #4ade80; --ok-soft: #0f2e1d; --warn: #fbbf24; --warn-soft: #332608; --bad: #f87171; --bad-soft: #3a1414; --info-soft: #0c2a3d;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
svg[aria-hidden] { width: 1.25em; height: 1.25em; flex-shrink: 0; vertical-align: -0.2em; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.45;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
a { color: var(--brand); text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .6rem; }
small, .muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.shell { min-height: 100vh; display: flex; }
.sidebar { display: none; }
.content { flex: 1; min-width: 0; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); }
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid transparent;
}
.topbar.scrolled { border-bottom-color: var(--line); }
.topbar .title { font-weight: 700; font-size: 1.1rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pool-switch { display: flex; align-items: center; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: .9rem; color: var(--text); cursor: pointer; max-width: 55vw; }
.pool-switch span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
main { padding: 4px 16px 16px; max-width: 860px; margin: 0 auto; }

.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: flex;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); height: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .72rem; font-weight: 600;
}
.bottomnav a svg { width: 24px; height: 24px; }
.bottomnav a.active { color: var(--brand); }

@media (min-width: 900px) {
  .sidebar {
    display: flex; flex-direction: column; width: 240px; flex-shrink: 0; position: sticky; top: 0; height: 100vh;
    background: var(--card); border-right: 1px solid var(--line); padding: 20px 12px; gap: 2px;
  }
  .sidebar .brand { padding: 4px 10px 18px; }
  .sidebar a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--text); font-weight: 500; }
  .sidebar a svg { width: 20px; height: 20px; color: var(--muted); }
  .sidebar a.active { background: var(--brand-soft); color: var(--brand); }
  .sidebar a.active svg { color: var(--brand); }
  .sidebar .sep { height: 1px; background: var(--line); margin: 10px 6px; }
  .bottomnav { display: none; }
  .content { padding-bottom: 32px; }
  main { padding: 8px 28px 28px; }
  .topbar { padding: 18px 28px 12px; }
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.1rem; }
.brand .logo { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, #0ea5e9, #0369a1); display: grid; place-items: center; color: white; }
.brand .logo svg { width: 20px; height: 20px; }

/* ---------- componentes ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; border: 1px solid var(--line); }
.card.flat { box-shadow: none; }
.card h3 { display: flex; align-items: center; gap: 8px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.card-head h2, .card-head h3 { margin: 0; }
.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin: 22px 2px 10px; }
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 520px) { .grid-3 { grid-template-columns: 1fr 1fr; } }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 10px 16px; border-radius: 12px; font: inherit; font-weight: 600; font-size: .95rem; cursor: pointer;
  min-height: 44px; transition: transform .05s, background .15s;
}
.btn:active { transform: scale(.98); }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.ok { background: var(--ok); color: white; border-color: var(--ok); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: 6px 12px; min-height: 36px; font-size: .85rem; border-radius: 10px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 700; background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.gray { background: var(--line); color: var(--muted); }

.alert { border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; font-size: .93rem; display: flex; gap: 10px; }
.alert svg { width: 20px; height: 20px; flex-shrink: 0; margin-top: 1px; }
.alert b { display: block; margin-bottom: 2px; }
.alert.info { background: var(--info-soft); }
.alert.warn { background: var(--warn-soft); }
.alert.bad { background: var(--bad-soft); }
.alert.ok { background: var(--ok-soft); }

/* forms */
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: .88rem; font-weight: 600; margin-bottom: 6px; }
label.field > small { display: block; margin-top: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--card);
  border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 12px; min-height: 46px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); }
input[type=checkbox] { width: 22px; height: 22px; min-height: 0; accent-color: var(--brand); }
.input-unit { position: relative; }
.input-unit input { padding-right: 52px; }
.input-unit em { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--muted); font-size: .85rem; pointer-events: none; }

.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.choice {
  border: 1.5px solid var(--line); border-radius: 12px; padding: 12px; cursor: pointer; background: var(--card);
  display: flex; flex-direction: column; gap: 4px; font-size: .9rem; text-align: left; font: inherit; color: var(--text);
}
.choice b { font-size: .95rem; }
.choice small { font-size: .78rem; }
.choice.selected { border-color: var(--brand); background: var(--brand-soft); }
.choice .swatch { width: 100%; height: 28px; border-radius: 8px; margin-bottom: 4px; }

.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.toggle:last-child { border-bottom: 0; }
.switch { position: relative; width: 48px; height: 28px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch i { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .2s; }
.switch i::after { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: white; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + i { background: var(--brand); }
.switch input:checked + i::after { transform: translateX(20px); }

/* ---------- dashboard ---------- */
.hero {
  background: linear-gradient(135deg, #0369a1 0%, #0ea5e9 100%); color: white; border-radius: 20px; padding: 18px;
  margin-bottom: 14px; position: relative; overflow: hidden;
}
.hero::after { content: ""; position: absolute; right: -40px; bottom: -60px; width: 200px; height: 200px; border-radius: 50%; background: rgba(255,255,255,.08); }
.hero h1 { font-size: 1.3rem; margin-bottom: 2px; }
.hero .sub { opacity: .9; font-size: .9rem; }
.hero .stats { display: flex; gap: 18px; margin-top: 14px; flex-wrap: wrap; position: relative; z-index: 1; }
.hero .stat b { display: block; font-size: 1.25rem; }
.hero .stat span { font-size: .78rem; opacity: .85; }
.hero .weather { position: absolute; top: 16px; right: 16px; text-align: right; z-index: 1; }
.hero .weather .t { font-size: 1.6rem; font-weight: 800; }
.hero .weather .d { font-size: .78rem; opacity: .9; }

.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.quick a { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 6px; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: .75rem; font-weight: 600; color: var(--text); text-align: center; box-shadow: var(--shadow); }
.quick a svg { width: 26px; height: 26px; color: var(--brand); }
.quick a.green svg { color: #16a34a; }

.task { border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 10px; background: var(--card); }
.task.late { border-left: 4px solid var(--warn); }
.task.very-late { border-left: 4px solid var(--bad); }
.task-head { display: flex; align-items: flex-start; gap: 12px; }
.task-icon { width: 40px; height: 40px; border-radius: 12px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; flex-shrink: 0; }
.task-icon svg { width: 22px; height: 22px; }
.task-title { font-weight: 700; }
.task .meta { font-size: .82rem; color: var(--muted); }
.task .info { font-size: .9rem; margin: 10px 0 0; color: var(--muted); }
.task .actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.task .actions .btn { flex: 1; min-width: 0; }
.dose { background: var(--brand-soft); border-radius: 12px; padding: 12px; margin-top: 10px; }
.dose .amt { font-size: 1.35rem; font-weight: 800; color: var(--brand); }
.dose .hh { font-size: .85rem; color: var(--muted); }
.dose .pname { font-weight: 600; font-size: .92rem; }
.dose.missing { background: var(--warn-soft); }
.dose.missing .amt { color: var(--warn); }
.dose .note { font-size: .83rem; margin-top: 6px; }
.recovery { background: var(--warn-soft); border-radius: 12px; padding: 12px; margin-top: 10px; font-size: .9rem; }
.recovery b { display: block; margin-bottom: 4px; }
details.more { margin-top: 8px; }
details.more summary { cursor: pointer; font-size: .88rem; color: var(--brand); font-weight: 600; list-style: none; }
details.more summary::-webkit-details-marker { display: none; }
details.more ol, details.more ul { margin: 8px 0 0; padding-left: 20px; font-size: .9rem; }
details.more li { margin-bottom: 4px; }

.params { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.param { border-radius: 12px; padding: 10px; background: var(--bg); text-align: center; }
.param .v { font-size: 1.3rem; font-weight: 800; }
.param .n { font-size: .75rem; color: var(--muted); }
.param.ok .v { color: var(--ok); } .param.baixo .v, .param.alto .v { color: var(--warn); }

.valve { display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: #0f172a; color: #e2e8f0; }
.valve.recircular { background: #7c3aed; color: white; }
.valve.drenar { background: #b45309; color: white; }
.valve.retrolavar { background: #0369a1; color: white; }
.valve.fechado { background: #475569; color: white; }

.days { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.day { flex: 0 0 auto; text-align: center; background: var(--bg); border-radius: 12px; padding: 8px 10px; min-width: 64px; font-size: .8rem; }
.day .e { font-size: 1.3rem; }
.day b { display: block; }

/* ---------- plano ---------- */
.plan-step { position: relative; padding-left: 44px; margin-bottom: 18px; }
.plan-step .num { position: absolute; left: 0; top: 0; width: 32px; height: 32px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 800; }
.plan-step.highlight .num { background: var(--bad); color: white; }
.plan-step::before { content: ""; position: absolute; left: 15px; top: 36px; bottom: -14px; width: 2px; background: var(--line); }
.plan-step:last-child::before { display: none; }
.plan-step h3 { margin-bottom: 4px; }
.plan-step .wait { font-size: .85rem; background: var(--bg); padding: 8px 10px; border-radius: 10px; margin-top: 8px; display: flex; gap: 8px; }
.checklist { list-style: none; padding: 0; margin: 8px 0 0; }
.checklist li { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; font-size: .92rem; }
.checklist input { margin-top: 1px; flex-shrink: 0; }
.checklist li.done span { text-decoration: line-through; color: var(--muted); }

.swim { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 12px; font-weight: 700; margin-bottom: 12px; }
.swim.yes { background: var(--ok-soft); color: var(--ok); }
.swim.no { background: var(--bad-soft); color: var(--bad); }
.swim.maybe { background: var(--bg); color: var(--muted); }

/* listas */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.list .main { flex: 1; min-width: 0; }
.list .main b { display: block; }
.list .main small { display: block; }
.link-card { display: flex; align-items: center; gap: 14px; color: var(--text); }
.link-card .ic { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0; font-size: 1.4rem; background: var(--brand-soft); }
.link-card .chev { color: var(--muted); }

.tabs { display: flex; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 14px; overflow-x: auto; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 8px 12px; border-radius: 9px; font: inherit; font-weight: 600; font-size: .88rem; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button.active { background: var(--brand); color: var(--brand-ink); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(2, 12, 24, .5); z-index: 100; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.modal { background: var(--card); width: 100%; max-width: 520px; border-radius: 20px 20px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); max-height: 90vh; overflow-y: auto; animation: up .2s; }
@media (min-width: 600px) { .modal-bg { align-items: center; } .modal { border-radius: 20px; } }
.modal h2 { margin-bottom: 12px; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }

.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #0f172a; color: white; padding: 12px 18px; border-radius: 12px; z-index: 200; font-size: .92rem; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: 90vw; animation: up .2s; }
.toast.err { background: var(--bad); }

/* login */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #075985 0%, #0ea5e9 60%, #7dd3fc 100%); }
.auth-card { width: 100%; max-width: 400px; background: var(--card); border-radius: 24px; padding: 28px 24px; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.auth-card .brand { justify-content: center; font-size: 1.35rem; margin-bottom: 6px; }
.auth-card .brand .logo { width: 44px; height: 44px; }
.auth-card .tagline { text-align: center; color: var(--muted); margin-bottom: 22px; font-size: .92rem; }
.code-input { text-align: center; font-size: 1.6rem; letter-spacing: .4em; font-weight: 700; }

/* wizard */
.steps-bar { display: flex; gap: 6px; margin-bottom: 18px; }
.steps-bar i { flex: 1; height: 5px; border-radius: 99px; background: var(--line); }
.steps-bar i.on { background: var(--brand); }
.vol-box { background: var(--brand-soft); border-radius: 14px; padding: 14px; text-align: center; margin: 6px 0 14px; }
.vol-box b { font-size: 1.6rem; color: var(--brand); display: block; }

.chart { width: 100%; height: 160px; }
.chart text { fill: var(--muted); font-size: 10px; }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }
.empty .e { font-size: 2.4rem; margin-bottom: 8px; }
.kbd { font-family: ui-monospace, Menlo, monospace; background: var(--bg); border: 1px solid var(--line); padding: 2px 6px; border-radius: 6px; font-size: .9em; word-break: break-all; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.codes span { font-family: ui-monospace, Menlo, monospace; background: var(--bg); padding: 8px; border-radius: 8px; text-align: center; font-weight: 700; letter-spacing: .08em; }
.guide h3 { margin-top: 14px; }
.guide ul { padding-left: 20px; }
.guide li { margin-bottom: 6px; }
table.ideal { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.ideal td, table.ideal th { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.spin { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: rot .8s linear infinite; margin: 40px auto; }
@keyframes rot { to { transform: rotate(360deg); } }
.banner { background: var(--warn-soft); padding: 10px 14px; border-radius: 12px; font-size: .9rem; margin-bottom: 12px; display: flex; align-items: center; gap: 10px; }
.banner .btn { margin-left: auto; }
