:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #fcfcfb;
  --surface-2: #efede8;
  --border: #e2dfd8;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #75736d;
  --grid: #e8e6e0;
  --series: #2a78d6;
  --series-soft: rgba(42, 120, 214, 0.10);
  --good: #0f7a3d;
  --bad: #c0352b;
  --band-warn: rgba(237, 161, 0, 0.10);
  --band-bad: rgba(227, 73, 72, 0.10);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2f2f2c;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #96958d;
    --grid: #2a2a27;
    --series: #3987e5;
    --series-soft: rgba(57, 135, 229, 0.16);
    --good: #4cc27c;
    --bad: #f07a70;
    --band-warn: rgba(201, 133, 0, 0.14);
    --band-bad: rgba(230, 103, 103, 0.14);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2f2f2c;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #96958d; --grid: #2a2a27;
  --series: #3987e5; --series-soft: rgba(57, 135, 229, 0.16);
  --good: #4cc27c; --bad: #f07a70;
  --band-warn: rgba(201, 133, 0, 0.14); --band-bad: rgba(230, 103, 103, 0.14);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Botões */
.btn {
  appearance: none; border: 1px solid transparent; border-radius: 10px;
  padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; color: var(--text);
}
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; font-weight: 500; }
.btn.primary { background: var(--text); color: var(--bg); }
.btn.primary:hover { opacity: 0.9; }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--bad); }
.btn:focus-visible, input:focus-visible, .chips button:focus-visible, .segmented button:focus-visible {
  outline: 2px solid var(--series); outline-offset: 2px;
}

/* Marca */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 7px; background: var(--text); position: relative; flex: none;
}
.brand-mark::after {
  content: ""; position: absolute; left: 5px; right: 5px; top: 6px; height: 3px; border-radius: 2px; background: var(--bg);
}

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 28px 22px; display: grid; gap: 14px;
}
.login-card p { margin: 0; }

label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-2); }
input {
  font: inherit; font-size: 16px; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%;
}
input::placeholder { color: var(--muted); }
.form-error { color: var(--bad); font-size: 14px; margin: 0; min-height: 1em; }

/* Layout */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-actions { display: flex; gap: 6px; }
.wrap { max-width: 960px; margin: 0 auto; padding: 20px 16px 64px; display: grid; gap: 16px; }

.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.hero p { margin: 0; }
.hero h1 { font-size: 44px; line-height: 1.1; font-weight: 700; }
.hero h1 .unit { font-size: 20px; font-weight: 500; color: var(--text-2); margin-left: 4px; }
.hero-sub { color: var(--text-2); font-size: 15px; }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; display: grid; gap: 2px; text-align: left; font: inherit; color: inherit; cursor: pointer;
}
.tile:hover { border-color: var(--muted); }
.tile.active { border-color: var(--series); box-shadow: inset 0 0 0 1px var(--series); }
.tile .label { font-size: 13px; color: var(--text-2); }
.tile .value { font-size: 22px; font-weight: 700; }
.tile .value .unit { font-size: 13px; font-weight: 500; color: var(--text-2); margin-left: 2px; }
.tile .extra { font-size: 12px; color: var(--muted); }
.delta { font-size: 12px; font-weight: 600; color: var(--text-2); }
.delta.good { color: var(--good); }
.delta.bad { color: var(--bad); }
.badge {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2); margin-left: 4px; vertical-align: 2px;
}
.badge.warn { background: var(--band-warn); color: var(--text); }
.badge.bad { background: var(--band-bad); color: var(--text); }

/* Painéis */
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px;
  display: grid; gap: 12px; min-width: 0;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.segmented { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.segmented button {
  appearance: none; border: 0; background: transparent; font: inherit; font-size: 13px; font-weight: 600;
  color: var(--text-2); padding: 6px 10px; border-radius: 8px; cursor: pointer; min-height: 32px;
}
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,0.12); }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips button {
  appearance: none; flex: none; border: 1px solid var(--border); background: transparent; color: var(--text-2);
  font: inherit; font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 999px; cursor: pointer; min-height: 34px;
}
.chips button.active { background: var(--text); border-color: var(--text); color: var(--bg); }

/* Gráfico */
.chart { position: relative; height: 260px; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--series-soft); }
.chart .dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.chart .crosshair { stroke: var(--text-2); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .focus-dot { fill: var(--surface); stroke: var(--series); stroke-width: 2.5; }
.chart .band-warn { fill: var(--band-warn); }
.chart .band-bad { fill: var(--band-bad); }
.chart .band-label { fill: var(--muted); font-size: 10px; }
.chart .empty { fill: var(--muted); font-size: 14px; }
.tooltip {
  position: absolute; top: 0; pointer-events: none; background: var(--text); color: var(--bg);
  border-radius: 10px; padding: 8px 10px; font-size: 13px; line-height: 1.35; white-space: nowrap;
  box-shadow: 0 6px 20px rgba(0,0,0,0.18); z-index: 2;
}
.tooltip strong { font-size: 15px; }
.chart-note { margin: 0; }

/* Tabela */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 640px; }
th, td { padding: 9px 8px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; }
td.note-cell { color: var(--muted); font-size: 12px; white-space: normal; padding-top: 0; }
tr.has-note td { border-bottom: 0; }
td .row-btn { min-height: 32px; padding: 4px 10px; }

/* Diálogos */
dialog {
  border: 1px solid var(--border); border-radius: 18px; padding: 0; background: var(--surface); color: var(--text);
  width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
}
dialog::backdrop { background: rgba(0,0,0,0.45); }
dialog form { padding: 18px; display: grid; gap: 14px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid .full { grid-column: 1 / -1; }
.dialog-actions { display: flex; justify-content: space-between; gap: 10px; }
.dialog-actions .primary { margin-left: auto; min-width: 120px; }

@media (max-width: 640px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .hero h1 { font-size: 38px; }
  .hero .btn { width: 100%; }
  .chart { height: 220px; }
  .topbar .brand { font-size: 16px; }
}
@media (max-width: 380px) {
  .topbar-actions .btn { padding: 6px 9px; }
}
