/* CaperPlus Q2 — tokens e componentes. Temas: claro (padrão), escuro e azul (cor do aparelho).
   O atributo data-theme fica no <html>; "auto" é resolvido em caper.js conforme o sistema. */

:root, [data-theme="claro"] {
  --bg: #F3F6FA;
  --surface: #FFFFFF;
  --surface-2: #E4EAF1;
  --line: #DDE5EE;
  --line-strong: #D3DCE6;
  --ink: #0F1B2A;
  --muted: #4F6275;
  --accent: #2F6FC4;
  --accent-ink: #1F4F94;
  --accent-soft: #E6EFFA;
  --on-accent: #FFFFFF;
  --band: #E6EFFA;
  --band-edge: #A9C4EA;
  --chart: #2F6FC4;
  --warn: #B4410C;
  --warn-ink: #8A2E06;
  --warn-soft: #FDEEE6;
  --on-warn: #FFFFFF;
  --future: rgba(243, 246, 250, 0.82);
  --visor-frame: #2F6FC4;
  --skeleton: #E1E8EF;
  --scrim: rgba(15, 27, 42, 0.5);
  --toast: #0F1B2A;
  --toast-link: #9EC2F7;
  --co2: #2E9E8F;
  --co2-soft: #E2F3F0;
  --co2-ink: #0E5F55;
  --band-co2: #D7EFEB;
  --band-co2-edge: #8FCFC4;
  --light: #E9A23B;
  --light-soft: #FDF3E1;
  --light-ink: #7A4A00;
  color-scheme: light;
}

[data-theme="escuro"] {
  --bg: #0B1016;
  --surface: #141B23;
  --surface-2: #1C2530;
  --line: #24303C;
  --line-strong: #2E3B49;
  --ink: #E8EEF5;
  --muted: #9AAABB;
  --accent: #7FB0F0;
  --accent-ink: #A9C8F5;
  --accent-soft: #1A2A40;
  --on-accent: #0B1016;
  --band: #1A2A40;
  --band-edge: #3F5F8C;
  --chart: #7FB0F0;
  --warn: #F2925A;
  --warn-ink: #FFC9A6;
  --warn-soft: #3B2116;
  --on-warn: #1A0D06;
  --future: rgba(11, 16, 22, 0.78);
  --visor-frame: #24548F;
  --skeleton: #1C2530;
  --scrim: rgba(0, 0, 0, 0.6);
  --toast: #E8EEF5;
  --toast-link: #1F4F94;
  --co2: #4FC1B0;
  --co2-soft: #12302C;
  --co2-ink: #8FE0D3;
  --band-co2: #13302C;
  --band-co2-edge: #2E7D72;
  --light: #F0B55A;
  --light-soft: #3A2A10;
  --light-ink: #F5CD8A;
  color-scheme: dark;
}

/* Azul do aparelho, um pouco menos saturado: branco 6,7:1 e secundário 5,4:1 sobre o fundo. */
[data-theme="azul"] {
  --bg: #2B5C9C;
  --surface: #1C4E95;
  --surface-2: #234F8C;
  --line: #3A72C2;
  --line-strong: #3A72C2;
  --ink: #FFFFFF;
  --muted: #DCE7F7;
  --accent: #FFFFFF;
  --accent-ink: #FFFFFF;
  --accent-soft: #3A72C2;
  --on-accent: #1C4E95;
  --band: #2A63B4;
  --band-edge: #BCD4F5;
  --chart: #FFFFFF;
  --warn: #FFB27A;
  --warn-ink: #8A2E06;
  --warn-soft: #FDEEE6;
  --on-warn: #1A0D06;
  --future: rgba(28, 78, 149, 0.8);
  --visor-frame: #3A72C2;
  --skeleton: #3567AD;
  --scrim: rgba(8, 26, 54, 0.6);
  --toast: #0D1117;
  --toast-link: #9EC2F7;
  --co2: #8FE0D3;
  --co2-soft: #1F6B78;
  --co2-ink: #FFFFFF;
  --band-co2: #2D6C9A;
  --band-co2-edge: #9FE3D8;
  --light: #FFD08A;
  --light-soft: #6E5626;
  --light-ink: #FFFFFF;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: Manrope, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Layout */
.app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; max-width: 560px; margin: 0 auto; }
.page { flex: 1; padding: 8px 20px 24px; display: flex; flex-direction: column; gap: 12px; }
.head { padding: calc(20px + env(safe-area-inset-top)) 20px 8px; display: flex; flex-direction: column; gap: 4px; }
.head h1 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.head-row { display: flex; align-items: center; gap: 4px; padding: calc(16px + env(safe-area-inset-top)) 12px 4px; }
.head-row h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.sub { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); display: inline-block; flex: none; }
.dot.off { background: transparent; border: 2px solid var(--muted); }
.section-title { margin: 6px 4px 0; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.hint { margin: 0 4px; font-size: 12px; color: var(--muted); line-height: 1.5; }

/* Navegação inferior */
.nav {
  position: sticky; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px 8px calc(10px + env(safe-area-inset-bottom));
}
[data-theme="azul"] .nav { border-top: 0; }
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 56px; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 600;
}
.nav a.active { color: var(--accent); font-weight: 800; }
.nav .pill { width: 48px; height: 30px; border-radius: 15px; display: flex; align-items: center; justify-content: center; }
.nav a.active .pill { background: var(--accent-soft); }

/* Superfícies */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }
.card.pad { padding: 14px 16px; }
.card.alert { border: 2px solid var(--warn); }
.list { padding: 0 14px; display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 10px; min-height: 56px; border-bottom: 1px solid var(--line);
  text-decoration: none; color: var(--ink); background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; width: 100%; padding: 0;
}
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.row strong { font-size: 14px; }
.row small { font-size: 13px; color: var(--muted); }

/* Botões e controles */
.btn {
  height: 48px; border-radius: 14px; border: 1px solid var(--line-strong); background: var(--surface);
  font-size: 15px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; text-decoration: none; color: var(--ink);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 800; }
.btn.outline { border-color: var(--accent); color: var(--accent); }
.btn.danger { color: var(--warn-ink); border-color: var(--warn); }
[data-theme="escuro"] .btn.danger, [data-theme="azul"] .btn.danger { color: var(--warn); }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--surface); display: flex; align-items: center; justify-content: center; color: var(--ink); flex: none; }
.icon-btn.ghost { border: 0; background: transparent; }
.icon-btn:disabled { opacity: 0.35; }

.seg { display: grid; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 12px; }
.seg button { height: 40px; border: 0; border-radius: 9px; background: transparent; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button[aria-selected="true"], .seg button[aria-checked="true"] { background: var(--surface); color: var(--ink); font-weight: 700; }
[data-theme="azul"] .seg button[aria-selected="true"], [data-theme="azul"] .seg button[aria-checked="true"] { background: #FFFFFF; color: #1C4E95; }

.chips { display: grid; gap: 6px; }
.chips button { height: 44px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--surface); font-size: 14px; font-weight: 700; }
.chips button[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select {
  height: 48px; border: 1px solid var(--line-strong); border-radius: 12px; padding: 0 14px; font-size: 16px;
  color: var(--ink); background: var(--surface); font-weight: 600;
}
.field input[aria-invalid="true"] { border: 2px solid var(--warn); }
.switch { width: 44px; height: 24px; accent-color: var(--accent); }

/* Avisos */
.banner {
  display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-radius: 14px;
  background: var(--warn-soft); color: var(--warn-ink); font-size: 13px; line-height: 1.4; text-decoration: none;
}
.banner .grow { flex: 1; }
.banner.neutral { background: #2B3A42; color: #FFFFFF; }
.pill-status { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-ink); white-space: nowrap; }
.pill-status.warn { background: var(--warn-soft); color: var(--warn-ink); font-weight: 800; }
.error-text { font-size: 13px; font-weight: 700; color: var(--warn-ink); }
[data-theme="escuro"] .error-text, [data-theme="azul"] .error-text { color: var(--warn); }

/* Visor (inspirado na tela do aparelho) */
.visor-frame { background: var(--visor-frame); border-radius: 26px; padding: 10px; }
[data-theme="azul"] .visor-frame { background: transparent; padding: 0; }
.visor { background: #0D1117; border-radius: 18px; padding: 12px 16px 6px; display: flex; flex-direction: column; }
[data-theme="azul"] .visor { border: 2px solid #3A72C2; border-radius: 22px; box-shadow: 0 10px 24px rgba(8, 26, 54, 0.35); }
[data-theme="escuro"] .visor { background: #05080B; }
.visor-top { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: #8C9BAB; padding-bottom: 4px; font-weight: 600; letter-spacing: 0.04em; }
.visor-row { display: grid; grid-template-columns: 72px 1fr; align-items: center; min-height: 64px; border-bottom: 1px solid #222A33; text-decoration: none; }
.visor-row:last-child { border-bottom: 0; }
.visor-label { display: flex; flex-direction: column; gap: 4px; }
.visor-label b { font-size: 13px; color: #C9D3DD; }
.visor-label span { font-size: 12px; font-weight: 600; color: #8C9BAB; display: flex; align-items: center; gap: 4px; }
.visor-value { display: flex; align-items: baseline; justify-content: flex-end; gap: 8px; }
.visor-trend { display: flex; align-items: center; gap: 3px; font-size: 12px; font-weight: 600; color: #8C9BAB; }
.visor-num { font-family: "Share Tech Mono", ui-monospace, monospace; font-size: 44px; line-height: 1; color: #F4F7FA; }
.visor-unit { font-size: 14px; color: #8C9BAB; }
.visor-row.warn .visor-num, .visor-row.warn .visor-trend, .visor-row.warn .visor-label span { color: #FFB27A; font-weight: 700; }
.visor.stale .visor-num { color: #6B7A88; }

.minis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.mini { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px; display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: var(--ink); min-width: 0; }
.mini.warn { border: 2px solid var(--warn); }
.mini b { font-size: 12px; display: flex; align-items: center; gap: 4px; }
.mini span { font-size: 12px; color: var(--muted); }

/* Gráfico */
.chart { position: relative; touch-action: pan-y; user-select: none; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .scrub { position: absolute; inset: 0; cursor: crosshair; }
.tip { position: absolute; top: 0; height: 24px; padding: 0 10px; border-radius: 7px; background: var(--toast); color: var(--bg); font-size: 12px; font-weight: 700; display: flex; align-items: center; white-space: nowrap; transform: translateX(-50%); pointer-events: none; }
[data-theme="azul"] .tip { color: #FFFFFF; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat span { font-size: 12px; color: var(--muted); }
.stat b { font-size: 18px; font-weight: 800; }
.stat b.warn { color: var(--warn-ink); }
[data-theme="escuro"] .stat b.warn, [data-theme="azul"] .stat b.warn { color: var(--warn); }

.period-nav { display: flex; align-items: center; gap: 4px; }
.period-nav .label { flex: 1; text-align: center; display: flex; flex-direction: column; gap: 2px; }
.period-nav .label strong { font-size: 15px; }
.period-nav .label span { font-size: 12px; color: var(--muted); }

.bullet { position: relative; height: 14px; background: var(--surface-2); border-radius: 3px; }
.bullet .band { position: absolute; top: 0; bottom: 0; background: var(--band); border-left: 1px dashed var(--band-edge); border-right: 1px dashed var(--band-edge); }
.bullet .bar { position: absolute; top: 4px; height: 6px; border-radius: 3px; background: var(--chart); min-width: 3px; }
.bullet .bar.warn { background: var(--warn); }
.bullet .avg { position: absolute; top: 0; width: 3px; height: 14px; background: var(--ink); margin-left: -1px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); padding: 0 2px; }
.legend span { display: flex; align-items: center; gap: 6px; }

/* Estados */
.skel { background: var(--skeleton); border-radius: 8px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }
@media (prefers-reduced-motion: reduce) { .skel { animation: none; } }
.empty { padding: 24px 8px 0; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px; }
.empty h2 { margin: 0; font-size: 22px; font-weight: 800; }
.empty p { margin: 0; font-size: 15px; line-height: 1.5; color: var(--muted); }

/* Folha inferior e avisos rápidos */
.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; background: var(--surface); color: var(--ink); border-radius: 24px 24px 0 0; padding: 12px 20px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
.sheet .grabber { width: 40px; height: 4px; border-radius: 2px; background: var(--line-strong); align-self: center; }
.sheet h2 { margin: 0; font-size: 20px; font-weight: 800; }
.option { min-height: 56px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--surface); text-align: left; padding: 8px 14px; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.option[aria-checked="true"] { border: 2px solid var(--accent); background: var(--accent-soft); }
.option span { font-size: 12px; color: var(--muted); }
.toast { position: fixed; left: 20px; right: 20px; bottom: calc(90px + env(safe-area-inset-bottom)); max-width: 520px; margin: 0 auto; z-index: 30; background: var(--toast); color: var(--bg); border-radius: 12px; padding: 12px 16px; font-size: 14px; display: flex; gap: 12px; align-items: center; }
[data-theme="azul"] .toast { color: #FFFFFF; }
.toast button { border: 0; background: none; color: var(--toast-link); font-weight: 800; min-height: 40px; }

.stepper { display: flex; align-items: center; justify-content: space-between; border: 1px solid var(--line-strong); border-radius: 12px; padding: 2px; }
.stepper button { width: 44px; height: 44px; border: 0; background: transparent; font-size: 22px; font-weight: 700; color: var(--accent); }
.stepper output { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }

.login { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 32px 24px; gap: 24px; max-width: 480px; margin: 0 auto; }
.logo { width: 64px; height: 64px; border-radius: 18px; background: var(--accent); color: var(--on-accent); display: flex; align-items: center; justify-content: center; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Plantado (P1): rotina de luz/CO₂, CO₂ estimado, queda de pH, trocas e anotações */
.routine-bar { position: relative; height: 18px; }
.routine-bar .track { position: absolute; left: 0; right: 0; top: 2px; height: 14px; border-radius: 4px; background: var(--surface-2); }
.routine-bar .co2, .routine-bar .luz { position: absolute; height: 6px; border-radius: 3px; }
.routine-bar .co2 { top: 2px; background: var(--co2); }
.routine-bar .luz { top: 10px; background: var(--light); }
.routine-bar .now { position: absolute; top: -2px; width: 3px; height: 22px; border-radius: 2px; background: var(--ink); margin-left: -1px; }
.pill-co2, .pill-luz, .pill-off { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.pill-co2 { background: var(--co2-soft); color: var(--co2-ink); }
.pill-luz { background: var(--light-soft); color: var(--light-ink); }
.pill-off { background: var(--surface-2); color: var(--muted); }
.visor-num.co2 { color: #7FD8C9; }
.duo { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: var(--ink); min-width: 0; }
.tile span { font-size: 12px; color: var(--muted); }
.tile b { font-size: 20px; font-weight: 800; }
.tile.co2 { background: var(--co2-soft); border-color: transparent; }
.tile.co2 span { color: var(--co2-ink); }
.tile.warn { border: 2px solid var(--warn); }
.btn.dashed { border: 2px dashed var(--line-strong); background: transparent; color: var(--accent); }
.note-num { width: 22px; height: 22px; flex: none; border-radius: 11px; background: var(--ink); color: var(--bg); font-size: 11px; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.callout { border-radius: 16px; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; font-size: 13px; line-height: 1.5; }
.callout strong { font-size: 14px; }
.callout.amber { background: var(--light-soft); color: var(--light-ink); }
.callout.teal { background: var(--co2-soft); color: var(--co2-ink); }
.callout.warn { background: var(--warn-soft); color: var(--warn-ink); }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-row button { min-height: 44px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); font-size: 14px; font-weight: 600; }
.chip-row button[aria-checked="true"] { border: 2px solid var(--accent); background: var(--accent-soft); color: var(--accent-ink); font-weight: 800; }
.field textarea { border: 1px solid var(--line-strong); border-radius: 12px; padding: 12px 14px; font: inherit; font-size: 16px; color: var(--ink); background: var(--surface); resize: none; }
.time-grid { display: grid; grid-template-columns: 1fr 104px 104px; gap: 8px; align-items: end; }
.time-grid input { height: 40px; border: 1px solid var(--line-strong); border-radius: 10px; padding: 0 6px; font-size: 15px; font-weight: 700; color: var(--ink); background: var(--surface); width: 100%; }
.time-grid label { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--muted); }
.stepper.small button { width: 36px; height: 38px; font-size: 20px; }
.stepper.small output { font-size: 16px; white-space: nowrap; }
.progress { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; border-radius: 4px; background: var(--accent); }
.progress.warn > div { background: var(--warn); }
.mini.co2 { background: var(--co2-soft); border-color: transparent; }
.mini.co2 span { color: var(--co2-ink); }
.nav .badge { position: absolute; top: -2px; right: 6px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--warn); color: var(--on-warn); font-size: 10px; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.nav .pill { position: relative; }
