/* MinhaSaude - estilos. Tokens em :root; modo escuro pelo sistema ou pelo botao (data-theme). */
:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e3e6ea;
  --text: #14171a;
  --text-2: #4f5660;
  --muted: #7a828c;
  --brand: #0f7a6c;
  --brand-2: #e6f4f1;
  --brand-ink: #ffffff;
  --series: #2a78d6;
  --series-soft: rgba(42, 120, 214, .14);
  --band: rgba(12, 163, 12, .10);
  --band-line: rgba(12, 163, 12, .45);
  --band-otimo: rgba(12, 163, 12, .16);
  --ok: #0ca30c;
  --ok-ink: #0a6b0a;
  --ok-bg: #e9f7e9;
  --warn: #fab219;
  --warn-ink: #8a5a00;
  --warn-bg: #fff5dc;
  --bad: #d03b3b;
  --bad-ink: #a52525;
  --bad-bg: #fdecec;
  --none: #9aa1aa;
  --none-bg: #f0f1f3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121314; --surface: #1a1a19; --surface-2: #222221; --border: #33332f;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #949389;
    --brand: #35b3a2; --brand-2: #17312d; --brand-ink: #0c1f1c;
    --series: #3987e5; --series-soft: rgba(57, 135, 229, .2);
    --band: rgba(12, 163, 12, .14); --band-line: rgba(12, 163, 12, .55); --band-otimo: rgba(12, 163, 12, .24);
    --ok-ink: #5fd35f; --ok-bg: #16301a; --warn-ink: #fab219; --warn-bg: #352a10;
    --bad-ink: #f08080; --bad-bg: #3a1c1c; --none-bg: #2a2a28;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121314; --surface: #1a1a19; --surface-2: #222221; --border: #33332f;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #949389;
  --brand: #35b3a2; --brand-2: #17312d; --brand-ink: #0c1f1c;
  --series: #3987e5; --series-soft: rgba(57, 135, 229, .2);
  --band: rgba(12, 163, 12, .14); --band-line: rgba(12, 163, 12, .55); --band-otimo: rgba(12, 163, 12, .24);
  --ok-ink: #5fd35f; --ok-bg: #16301a; --warn-ink: #fab219; --warn-bg: #352a10;
  --bad-ink: #f08080; --bad-bg: #3a1c1c; --none-bg: #2a2a28;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; font-weight: 650; }
h3 { font-size: .95rem; font-weight: 650; }
small, .muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- layout */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 18px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 1.1rem; padding: 4px 8px 16px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand .logo { width: 32px; height: 32px; border-radius: 9px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; }
.side .sec { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 10px 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.on { background: var(--brand-2); color: var(--brand); font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex: none; }
.pac-chip { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--border); border-radius: 10px; margin: 2px 0 6px; color: var(--text); }
.pac-chip:hover { text-decoration: none; border-color: var(--brand); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-2); color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: .85rem; flex: none; }
.side .rodape { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); font-size: .85rem; }
.side .rodape form { display: inline; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--brand); cursor: pointer; font: inherit; }

.main { padding: 26px 32px 60px; max-width: 1280px; width: 100%; }
.topo { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.topo .sub { color: var(--text-2); margin-top: -2px; }
.acoes { display: flex; gap: 8px; flex-wrap: wrap; }
.btn.menu-btn { display: none; }

/* ---------- componentes */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.card + .card { margin-top: 16px; }
.grid > .card { margin-top: 0; }
.card-h { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-h h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.mt { margin-top: 16px; }
.mt2 { margin-top: 28px; }

.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { text-decoration: none; border-color: var(--brand); }
.btn.pri { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.pri:hover { filter: brightness(1.07); }
.btn.perigo { color: var(--bad-ink); }
.btn.sm { padding: 5px 10px; font-size: .85rem; }
.btn svg { width: 17px; height: 17px; }

.alerta { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; border: 1px solid; }
.alerta.ok { background: var(--ok-bg); border-color: transparent; color: var(--ok-ink); }
.alerta.erro { background: var(--bad-bg); border-color: transparent; color: var(--bad-ink); }
.alerta.aviso { background: var(--warn-bg); border-color: transparent; color: var(--warn-ink); }

/* status: sempre icone + rotulo (nunca so cor) */
.st { display: inline-flex; align-items: center; gap: 5px; font-size: .78rem; font-weight: 600; padding: 2px 9px 2px 7px; border-radius: 99px; white-space: nowrap; }
.st::before { font-size: .8rem; line-height: 1; }
.st-ok { background: var(--ok-bg); color: var(--ok-ink); }
.st-ok::before { content: "\2713"; }
.st-atencao { background: var(--warn-bg); color: var(--warn-ink); }
.st-atencao::before { content: "!"; font-weight: 800; }
.st-fora { background: var(--bad-bg); color: var(--bad-ink); }
.st-fora::before { content: "\25B2"; font-size: .6rem; }
.st-fora.baixo::before { content: "\25BC"; }
.st-sem_ref { background: var(--none-bg); color: var(--text-2); }
.st-sem_ref::before { content: "\2013"; }

.tend { font-size: .8rem; font-weight: 600; white-space: nowrap; }
.tend.melhora { color: var(--ok-ink); }
.tend.piora { color: var(--bad-ink); }
.tend.estavel { color: var(--muted); }

/* KPI */
.kpi { padding: 16px 18px; }
.kpi .rot { font-size: .8rem; color: var(--text-2); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi .val { font-size: 2rem; font-weight: 750; letter-spacing: -.02em; line-height: 1.15; margin-top: 4px; }
.kpi .det { font-size: .8rem; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.dot.ok { background: var(--ok); } .dot.atencao { background: var(--warn); } .dot.fora { background: var(--bad); } .dot.sem_ref { background: var(--none); }

/* barra empilhada de status (2px de separacao entre segmentos) */
.barra { display: flex; gap: 2px; height: 10px; border-radius: 5px; overflow: hidden; background: var(--surface-2); }
.barra span { display: block; height: 100%; }
.barra .ok { background: var(--ok); } .barra .atencao { background: var(--warn); } .barra .fora { background: var(--bad); } .barra .sem_ref { background: var(--none); }
.legenda { display: flex; gap: 14px; flex-wrap: wrap; font-size: .8rem; color: var(--text-2); margin-top: 8px; }
.legenda span { display: inline-flex; align-items: center; gap: 6px; }

/* listas de marcadores */
.lista { list-style: none; padding: 0; margin: 0; }
.lista li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--border); }
.lista li:first-child { border-top: 0; }
.lista .nome { font-weight: 600; color: var(--text); }
.lista .nome:hover { color: var(--brand); }
.lista .info { font-size: .8rem; color: var(--muted); }
.lista .v { text-align: right; font-weight: 650; }
.lista .v small { font-weight: 400; }

/* categorias */
.cat { display: block; color: var(--text); padding: 14px 16px; }
.cat:hover { text-decoration: none; border-color: var(--brand); }
.cat .t { display: flex; justify-content: space-between; gap: 8px; font-weight: 650; margin-bottom: 10px; }
.cat .t small { font-weight: 500; }

/* sparkline */
.spark { display: block; overflow: visible; }
.sp-band { fill: var(--band); }
.sp-line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.sp-dot { stroke: var(--surface); stroke-width: 2; }
.sp-dot.st-ok { fill: var(--ok); } .sp-dot.st-atencao { fill: var(--warn); } .sp-dot.st-fora { fill: var(--bad); } .sp-dot.st-sem_ref { fill: var(--series); }

/* tabelas */
.tabela-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.t { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.t th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.t td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t td.r, table.t th.r { text-align: right; }
table.t tr.grupo td { background: var(--surface-2); font-weight: 650; font-size: .82rem; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }

/* matriz evolutiva */
.matriz th.data { text-align: center; min-width: 92px; }
.matriz td.cel { text-align: center; font-variant-numeric: tabular-nums; padding: 6px; }
.matriz .c { display: inline-block; min-width: 70px; padding: 4px 8px; border-radius: 7px; font-weight: 600; }
.matriz .c.ok { background: var(--ok-bg); color: var(--ok-ink); }
.matriz .c.atencao { background: var(--warn-bg); color: var(--warn-ink); }
.matriz .c.fora { background: var(--bad-bg); color: var(--bad-ink); }
.matriz .c.sem_ref { background: var(--none-bg); color: var(--text-2); }
.matriz .c .seta { font-size: .65rem; margin-left: 3px; }
.matriz td.nm { position: sticky; left: 0; background: var(--surface); min-width: 190px; z-index: 1; }
.matriz th:first-child { position: sticky; left: 0; background: var(--surface); z-index: 2; }

.filtros { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.pill { padding: 6px 12px; border-radius: 99px; border: 1px solid var(--border); color: var(--text-2); font-size: .85rem; font-weight: 500; background: var(--surface); }
.pill:hover { text-decoration: none; border-color: var(--brand); color: var(--text); }
.pill.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }

/* grafico */
.grafico { position: relative; height: 340px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.stats div { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.stats b { display: block; font-size: 1.2rem; }
.stats span { font-size: .78rem; color: var(--muted); }

/* timeline de exames */
.timeline { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 0 0 18px 16px; }
.timeline li::before { content: ""; position: absolute; left: -25px; top: 5px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 3px solid var(--brand); }
.timeline .data { font-weight: 700; }

/* formularios */
label { display: block; font-size: .85rem; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=date], input[type=email], input[type=file], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
.campo { margin-bottom: 14px; }
.erro-campo { color: var(--bad-ink); font-size: .82rem; margin-top: 3px; }
.conf input[type=text] { padding: 6px 8px; }
.conf td { padding: 6px 8px; }
.conf tr.conferir td { background: var(--warn-bg); }
.conf .orig { font-size: .75rem; color: var(--muted); font-family: ui-monospace, Consolas, monospace; }
.drop { border: 2px dashed var(--border); border-radius: var(--radius); padding: 32px; text-align: center; background: var(--surface-2); }
.drop.over { border-color: var(--brand); background: var(--brand-2); }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, var(--brand-2), var(--bg) 60%); }
.login { width: 100%; max-width: 380px; }
.login .brand { justify-content: center; font-size: 1.4rem; padding-bottom: 6px; }

.tag { display: inline-block; font-size: .72rem; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); }
.vazio { text-align: center; padding: 40px 20px; color: var(--text-2); }
.vazio svg { width: 48px; height: 48px; color: var(--muted); }
.nota { font-size: .8rem; color: var(--muted); margin-top: 18px; }

/* ---------- responsivo */
@media (max-width: 1000px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 50; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  .side.aberto { transform: none; }
  .btn.menu-btn { display: inline-flex; }
  .main { padding: 16px 16px 60px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grafico { height: 260px; }
  .kpi .val { font-size: 1.6rem; }
}

/* ---------- impressao (relatorio) */
@media print {
  :root { color-scheme: light; }
  body { background: #fff; font-size: 11px; }
  .side, .menu-btn, .acoes, .nao-imprimir { display: none !important; }
  .app { display: block; }
  .main { padding: 0; max-width: none; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  table.t td, table.t th { padding: 4px 6px; }
  a { color: inherit; }
}
