:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --accent: #14b8a6;
  --danger: #dc2626;
  --border: #e2e8f0;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 14px rgba(15, 23, 42, .05);
  --tabbar-h: 60px;
}

* { box-sizing: border-box; }

/* garante que o atributo hidden esconde sempre (anula display:flex do autor) */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-size: 16px;
}

body { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--brand);
  color: #fff;
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { margin: 0; font-size: 1.25rem; font-weight: 700; letter-spacing: -.02em; }
.heart { width: 26px; height: 26px; fill: #fff; }

.btn-install {
  background: rgba(255,255,255,.18);
  color: #fff;
  border: 1px solid rgba(255,255,255,.4);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: .85rem;
  cursor: pointer;
}

main.view { max-width: 560px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

/* Resumo */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.summary-item { display: flex; flex-direction: column; gap: 2px; }
.summary-item .label { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.summary-item .value { font-size: 1.6rem; font-weight: 800; color: var(--brand-dark); }
.summary-item .sub { font-size: .68rem; color: var(--muted); }

/* Botões */
.btn-primary, .btn-secondary {
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform .05s ease, filter .15s ease;
}
.btn-primary { background: var(--brand); color: #fff; width: 100%; }
.btn-primary:active { transform: scale(.98); }
.btn-secondary { background: #e2e8f0; color: var(--ink); width: 100%; }
.btn-secondary:active { transform: scale(.98); }

/* Gráficos */
.chart-head { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.chart-head h2 { margin: 0; font-size: 1rem; font-weight: 700; }
.legend { display: flex; align-items: center; gap: 6px; font-size: .72rem; color: var(--muted); flex-wrap: wrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot-sys { background: #dc2626; }
.dot-dia { background: #2563eb; }
.dot-pulse { background: #16a34a; }

.chart-card svg { width: 100%; height: 180px; display: block; }

.empty { color: var(--muted); font-size: .9rem; text-align: center; padding: 12px 0; }

/* Tabela últimos registos */
table.recent { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.recent th { text-align: left; color: var(--muted); font-weight: 600; font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; padding: 6px 4px; border-bottom: 1px solid var(--border); }
table.recent td { padding: 9px 4px; border-bottom: 1px solid var(--border); }
table.recent tr:last-child td { border-bottom: none; }
.pa { font-weight: 700; }

/* Badges de classificação */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
}
.badge.otima { background: #16a34a; }
.badge.normal { background: #65a30d; }
.badge.normal-alta { background: #ca8a04; }
.badge.h1 { background: #ea580c; }
.badge.h2 { background: #dc2626; }
.badge.h3 { background: #991b1b; }

/* Formulário */
#view-form form, #view-export form { display: flex; flex-direction: column; gap: 14px; }
#view-form h2, #view-export h2, #view-history h2 { margin: 0; font-size: 1.15rem; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field span { font-size: .85rem; font-weight: 600; color: var(--ink); }
.field em { font-style: normal; color: var(--muted); font-weight: 400; font-size: .75rem; }
.field input {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 1rem;
  background: #f8fafc;
  color: var(--ink);
}
.field input:focus { outline: 2px solid var(--accent); border-color: transparent; background: #fff; }

.classify { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: #f8fafc; border-radius: 10px; font-size: .85rem; }

.form-actions { display: flex; gap: 10px; margin-top: 4px; }

.hint { color: var(--muted); font-size: .85rem; margin: 0; }

/* Histórico */
.history-head { display: flex; flex-direction: column; gap: 10px; }
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item { display: flex; flex-direction: column; gap: 8px; }
.history-item .top { display: flex; justify-content: space-between; align-items: center; }
.history-item .date { color: var(--muted); font-size: .85rem; }
.history-item .pa { font-size: 1.15rem; }
.history-item .meta { display: flex; gap: 10px; align-items: center; }
.history-item .pulse { color: var(--muted); font-size: .9rem; }
.history-item .notes { color: var(--muted); font-size: .85rem; font-style: italic; }
.history-item .del {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
}
.history-item .del:active { background: #fee2e2; color: var(--danger); }

/* Barra de abas */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 20;
  box-shadow: 0 -2px 10px rgba(15, 23, 42, .06);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: .68rem;
  font-weight: 600;
  cursor: pointer;
}
.tab svg { width: 24px; height: 24px; fill: currentColor; }
.tab.active { color: var(--brand); }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  font-size: .9rem;
  box-shadow: var(--shadow);
  z-index: 100;
  max-width: 90%;
  text-align: center;
}

@media (min-width: 600px) {
  .summary-item .value { font-size: 2rem; }
}
