/* Painel do administrador do CalmWave 2. Paleta do app (ui/theme/Theme.kt). */
:root {
  color-scheme: light;
  --bg: #eef3f2;
  --surface: #ffffff;
  --surface2: #f4f8f7;
  --line: #d5e2df;
  --ink: #16302c;
  --ink2: #4e6662;
  --accent: #07705f;      /* botões e links (texto branco, contraste > 5:1) */
  --on-accent: #ffffff;
  --accent-soft: #d7f3ec;
  --bar: #0b8f79;         /* série principal (> 3:1 sobre o fundo) */
  --bar2: #2b6f9e;        /* série secundária */
  --ok: #0b8f79;
  --danger: #b4423a;
  --danger-soft: #fbe9e7;
  --grid: #e3ecea;
  --focus: #2b6f9e;
  --shadow: 0 1px 2px rgb(22 48 44 / 6%), 0 4px 16px rgb(22 48 44 / 6%);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0b1513;
    --surface: #13221f;
    --surface2: #182a27;
    --line: #24403b;
    --ink: #e6f2ef;
    --ink2: #a9c2bd;
    --accent: #2fd1b3;
    --on-accent: #04241e;
    --accent-soft: #123b34;
    --bar: #2fd1b3;
    --bar2: #89cff0;
    --ok: #2fd1b3;
    --danger: #e27b71;
    --danger-soft: #3a1d1a;
    --grid: #1f3531;
    --focus: #89cff0;
    --shadow: none;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 8px; }
h1 { font-size: 1.5rem; font-weight: 650; }
h2 { font-size: 1.05rem; font-weight: 600; }
p { margin: 0 0 12px; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--surface2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 4px;
}

[hidden] { display: none !important; }

.muted { color: var(--ink2); }
.small { font-size: 0.875rem; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

.skip {
  position: absolute; left: 16px; top: -48px;
  background: var(--accent); color: var(--on-accent);
  padding: 8px 12px; border-radius: 8px; z-index: 10; text-decoration: none;
}
.skip:focus { top: 12px; }

/* ---------- topo ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px clamp(16px, 4vw, 40px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand img { border-radius: 8px; flex: none; }
.brand-name { margin: 0; font-weight: 700; }
.brand-sub { margin: 0; font-size: 0.875rem; color: var(--ink2); }
.session { display: flex; align-items: center; gap: 12px; min-width: 0; }
.who {
  color: var(--ink2); font-size: 0.875rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw;
}

main {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px clamp(16px, 4vw, 40px) 32px;
}
main:focus { outline: none; }

.foot { padding: 0 clamp(16px, 4vw, 40px) 24px; text-align: center; }

/* ---------- blocos ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
.panel.narrow { max-width: 440px; margin: 8vh auto 0; }
.panel.center { max-width: 440px; margin: 8vh auto 0; text-align: center; }

/* ---------- formulário ---------- */
form { display: grid; gap: 6px; margin: 16px 0; }
label { font-weight: 600; font-size: 0.95rem; margin-top: 8px; }
input {
  font: inherit; color: var(--ink);
  background: var(--surface2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  min-height: 48px;
  width: 100%;
}
input:focus-visible { border-color: var(--focus); }

/* ---------- botões ---------- */
.btn {
  font: inherit; font-weight: 600;
  border-radius: 999px;
  padding: 10px 20px;
  min-height: 44px;
  border: 1px solid transparent;
  cursor: pointer;
}
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface2); }
form .btn { margin-top: 16px; }

.segmented {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
}
.seg {
  font: inherit; font-size: 0.95rem;
  color: var(--ink2);
  background: transparent;
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  min-height: 38px;
  cursor: pointer;
}
.seg[aria-pressed="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 650; }

/* ---------- avisos e estados ---------- */
.alert {
  background: var(--danger-soft);
  color: var(--ink);
  border: 1px solid var(--danger);
  border-left-width: 6px;
  border-radius: 12px;
  padding: 12px 16px;
  margin: 12px 0;
}
.state {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin: 16px 0;
  color: var(--ink2);
}
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--bar);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* ---------- painel ---------- */
.dash-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: 12px 24px;
}
.dash-head p { margin: 0; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
#updated-at { margin: 8px 0 0; min-height: 1.4em; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin: 16px 0 20px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card dl { margin: 0; }
.card dt { color: var(--ink2); font-size: 0.875rem; }
.card dd { margin: 4px 0 0; font-size: 1.75rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.card .hint { display: block; margin-top: 2px; font-size: 0.8rem; color: var(--ink2); font-weight: 400; }
.card.warn dd { color: var(--danger); }

.charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr));
  gap: 16px;
}
.chart-card {
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 16px 12px;
  min-width: 0;
}
.chart-card figcaption { margin-bottom: 8px; }
.chart-card figcaption h2 { margin: 0; }
.chart-card figcaption p { margin: 2px 0 0; font-size: 0.875rem; color: var(--ink2); }
.chart-card svg { display: block; width: 100%; height: auto; }
.chart-empty { color: var(--ink2); padding: 24px 0; text-align: center; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 8px 0 0; padding: 0; list-style: none; font-size: 0.875rem; }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.swatch.s1 { background: var(--bar); }
.swatch.s2 { background: var(--bar2); }
.swatch.ok { background: var(--ok); }
.swatch.err { background: var(--danger); }

/* SVG */
.axis-text { fill: var(--ink2); font-size: 11px; font-family: inherit; }
.grid-line { stroke: var(--grid); stroke-width: 1; }
.base-line { stroke: var(--line); stroke-width: 1; }
.bar { fill: var(--bar); }
.bar:hover { fill-opacity: 0.8; }
.line1 { fill: none; stroke: var(--bar); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.line2 { fill: none; stroke: var(--bar2); stroke-width: 2; stroke-dasharray: 5 4; stroke-linejoin: round; }
.area1 { fill: var(--bar); fill-opacity: 0.12; }
.dot1 { fill: var(--bar); }
.track { fill: var(--grid); }
.seg-ok { fill: var(--ok); }
.seg-err { fill: var(--danger); }
.hit { fill: transparent; }
.hit:hover { fill: var(--ink); fill-opacity: 0.05; }

details { margin-top: 10px; }
summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 0.9rem; padding: 4px 0; }
.table-wrap { overflow-x: auto; max-height: 320px; overflow-y: auto; margin-top: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 0.875rem; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { position: sticky; top: 0; background: var(--surface); color: var(--ink2); font-weight: 600; }

.sync-table { margin-top: 12px; }

@media (max-width: 560px) {
  h1 { font-size: 1.3rem; }
  .brand-sub { display: none; }
  .controls { width: 100%; }
  .segmented { flex: 1; }
  .seg { flex: 1; padding: 8px 6px; }
  .card dd { font-size: 1.45rem; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel { padding: 20px; }
}
