:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --ink: #17231f;
  --ink-2: #4a5a54;
  --ink-3: #85938d;
  --line: #e6e2d9;
  --brand: #134e40;
  --brand-2: #1f6f5c;
  --brand-soft: #e5efea;
  --gold: #b8913a;
  --gold-soft: #f6efdd;
  --ideal: #2e9e6b;
  --ideal-soft: #e3f4ea;
  --warn: #d99a22;
  --warn-soft: #fbf1dc;
  --out: #d9785c;
  --out-soft: #fbebe5;
  --calm: #5b7c99;
  --calm-soft: #e9eff5;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(23, 35, 31, .04), 0 6px 24px rgba(23, 35, 31, .06);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --serif: 'Fraunces', Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--brand-2); text-decoration: none; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; margin: 0; }
h1 { font-size: 28px; } h2 { font-size: 21px; } h3 { font-size: 17px; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--ink-3); } .small { font-size: 13px; } .tiny { font-size: 12px; }
.hidden { display: none !important; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.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)); }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 720px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { background: var(--brand); color: #e8f1ed; padding: 22px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { padding: 4px 10px 22px; }
.brand .logo { display: flex; align-items: center; gap: 10px; }
.brand .mark { width: 38px; height: 38px; border-radius: 12px; background: linear-gradient(135deg, #2c8a71, #b8913a); display: grid; place-items: center; font-family: var(--serif); font-weight: 700; color: #fff; font-size: 18px; }
.brand .name { font-family: var(--serif); font-size: 17px; line-height: 1.15; color: #fff; }
.brand .tag { font-size: 11.5px; color: #a9c4b9; margin-top: 8px; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 11px; color: #cfe0d9; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav a.active { background: rgba(255,255,255,.13); color: #fff; }
.nav .ico { width: 20px; text-align: center; opacity: .9; }
.sidebar .foot { margin-top: auto; padding: 12px; font-size: 12.5px; color: #a9c4b9; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar .foot b { color: #fff; display: block; font-weight: 600; }
.main { padding: 28px 34px 60px; min-width: 0; }
.topbar { display: none; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .topbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--brand); color: #fff; position: sticky; top: 0; z-index: 40; }
  .topbar button { background: none; border: 0; color: #fff; font-size: 22px; }
  .main { padding: 18px 16px 60px; }
}

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .sub { color: var(--ink-3); margin-top: 4px; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); min-width: 0; }
.card h3 { margin-bottom: 12px; }
.card.flat { box-shadow: none; }
.card .card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; }
.card .card-head h3 { margin: 0; }
.kpi .label { color: var(--ink-3); font-size: 12.5px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.kpi .value { font-family: var(--serif); font-size: 30px; font-weight: 600; margin-top: 4px; }
.kpi .hint { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.kpi.accent { background: linear-gradient(140deg, var(--brand), #1f6f5c); color: #fff; border: 0; }
.kpi.accent .label, .kpi.accent .hint { color: #cfe5dc; }

/* ---------- buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); padding: 9px 15px; border-radius: 11px; cursor: pointer; font-weight: 550; white-space: nowrap; transition: .15s; }
.btn:hover { border-color: #cfc9bc; background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #0f4135; }
.btn.gold { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(0,0,0,.04); }
.btn.danger { color: #b5472b; }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 9px; }
.btn:disabled { opacity: .55; cursor: default; }
label.f { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 550; color: var(--ink-2); }
input, select, textarea { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 9px 11px; outline: none; width: 100%; }
input:focus, select:focus, textarea:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(31,111,92,.12); }
textarea { resize: vertical; min-height: 90px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.form-grid .span2 { grid-column: span 2; }
.form-grid .full { grid-column: 1 / -1; }
.search { max-width: 340px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.check input { width: auto; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 20px 0 22px; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 10px 14px; color: var(--ink-2); font-weight: 550; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--brand); border-color: var(--brand); }
.seg { display: inline-flex; background: #ece8df; border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; font-weight: 550; color: var(--ink-2); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); font-weight: 600; background: var(--surface-2); }
tr.click { cursor: pointer; } tr.click:hover td { background: #fbfaf7; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- chips, badges ---------- */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip.ideal { background: var(--ideal-soft); color: #1d7a50; }
.chip.atencao { background: var(--warn-soft); color: #9a6a0c; }
.chip.fora { background: var(--out-soft); color: #a8513a; }
.chip.calm { background: var(--calm-soft); color: #3f5f7c; }
.chip.gold { background: var(--gold-soft); color: #8a6a1f; }
.chip.neutral { background: #efece5; color: var(--ink-2); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.ideal { background: var(--ideal); } .dot.atencao { background: var(--warn); } .dot.fora { background: var(--out); } .dot.none { background: #c8c3b8; }

/* ---------- patient header ---------- */
.p-head { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.avatar { width: 64px; height: 64px; border-radius: 20px; background: linear-gradient(135deg, var(--brand-2), var(--gold)); color: #fff; display: grid; place-items: center; font-family: var(--serif); font-size: 24px; font-weight: 600; flex-shrink: 0; }
.avatar.sm { width: 38px; height: 38px; border-radius: 12px; font-size: 15px; }
.p-head .meta { color: var(--ink-2); font-size: 14px; display: flex; gap: 14px; flex-wrap: wrap; margin-top: 4px; }
.progress { height: 10px; background: #ece8df; border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--brand-2), var(--ideal)); border-radius: 99px; }

/* ---------- param cards ---------- */
.cat-title { display: flex; align-items: center; gap: 10px; margin: 26px 0 12px; }
.cat-title h3 { margin: 0; }
.params { display: grid; grid-template-columns: repeat(auto-fill, minmax(255px, 1fr)); gap: 14px; }
.pcard { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 15px 12px; cursor: pointer; transition: .15s; position: relative; overflow: hidden; }
.pcard:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.pcard::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--c, #ccc); }
.pcard.ideal { --c: var(--ideal); } .pcard.atencao { --c: var(--warn); } .pcard.fora { --c: var(--out); }
.pcard .name { font-weight: 600; font-size: 14px; }
.pcard .val { font-family: var(--serif); font-size: 26px; font-weight: 600; margin: 4px 0 2px; }
.pcard .val small { font-family: var(--font); font-size: 12.5px; color: var(--ink-3); font-weight: 500; margin-left: 3px; }
.pcard .foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; gap: 6px; }
.pcard canvas { width: 100% !important; height: 38px !important; margin-top: 6px; }

/* gauge bar with ideal band */
.gauge { position: relative; height: 8px; border-radius: 99px; background: linear-gradient(90deg, var(--out-soft), var(--warn-soft) 18%, var(--warn-soft) 82%, var(--out-soft)); margin: 10px 0 4px; }
.gauge .band { position: absolute; top: 0; bottom: 0; background: #bfe6cf; border-radius: 99px; }
.gauge .mark { position: absolute; top: 50%; width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--c, var(--ink)); transform: translate(-50%, -50%); box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.gauge .prev { position: absolute; top: 50%; width: 8px; height: 8px; border-radius: 50%; background: #9aa6a1; transform: translate(-50%, -50%); opacity: .7; }

/* evolution matrix */
.matrix td, .matrix th { padding: 7px 9px; font-size: 13.5px; }
.matrix td.v { text-align: center; font-variant-numeric: tabular-nums; font-weight: 550; border-left: 1px solid var(--line); }
.matrix td.v.ideal { background: #eef8f2; color: #1d7a50; }
.matrix td.v.atencao { background: #fdf6e6; color: #8d630e; }
.matrix td.v.fora { background: #fcf0eb; color: #9b4b35; }
.matrix th.d { text-align: center; border-left: 1px solid var(--line); white-space: nowrap; }
.matrix td.cat { background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.matrix td.small { min-width: 110px; }
.matrix .sticky { position: sticky; left: 0; background: #fff; z-index: 1; min-width: 190px; }
.arrow-up::after { content: ' ↑'; } .arrow-down::after { content: ' ↓'; }

/* highlights */
.win { display: flex; gap: 12px; padding: 12px; border-radius: 12px; background: var(--ideal-soft); margin-bottom: 8px; align-items: flex-start; }
.win.calm { background: var(--calm-soft); }
.win .ic { font-size: 20px; line-height: 1; }
.win .t { display: block; font-weight: 650; }

.score-ring { position: relative; width: 130px; height: 130px; }
.score-ring .center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.score-ring .center b { font-family: var(--serif); font-size: 30px; display: block; }

/* dropzone */
.drop { border: 2px dashed #cfc7b6; border-radius: 16px; padding: 26px; text-align: center; background: var(--surface-2); cursor: pointer; transition: .15s; }
.drop.over { border-color: var(--brand-2); background: var(--brand-soft); }
.drop .big { font-size: 30px; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 28, 24, .45); display: grid; place-items: center; z-index: 100; padding: 16px; animation: fade .15s; }
.modal { background: var(--surface); border-radius: 20px; width: min(760px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 24px 80px rgba(0,0,0,.25); }
.modal.wide { width: min(1000px, 100%); }
.modal .mh { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.modal .mb { padding: 20px 22px; }
.modal .mf { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--surface); }
@keyframes fade { from { opacity: 0; } }

.toast { position: fixed; bottom: 22px; right: 22px; background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 200; box-shadow: var(--shadow); max-width: 420px; animation: fade .2s; }
.toast.err { background: #a8513a; }

/* auth */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth .hero { background: radial-gradient(circle at 20% 20%, #2c8a71 0, transparent 50%), radial-gradient(circle at 80% 90%, rgba(184,145,58,.55) 0, transparent 45%), var(--brand); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; }
.auth .hero h1 { font-size: 40px; line-height: 1.1; max-width: 520px; }
.auth .hero p { color: #cfe5dc; max-width: 460px; font-size: 16px; }
.auth .pillars { display: flex; gap: 10px; flex-wrap: wrap; }
.auth .pillars span { border: 1px solid rgba(255,255,255,.25); padding: 6px 12px; border-radius: 99px; font-size: 13px; }
.auth .panel { display: grid; place-items: center; padding: 30px; }
.auth form { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; }
@media (max-width: 860px) { .auth { grid-template-columns: 1fr; } .auth .hero { padding: 30px; } .auth .hero h1 { font-size: 30px; } }

/* recorder */
.rec { display: flex; align-items: center; gap: 14px; padding: 14px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line); }
.rec .pulse { width: 14px; height: 14px; border-radius: 50%; background: #c9c3b6; }
.rec.on .pulse { background: #d9534f; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(217,83,79,.15); } }
.live { min-height: 120px; max-height: 260px; overflow: auto; white-space: pre-wrap; padding: 12px; background: #fff; border: 1px solid var(--line); border-radius: 12px; font-size: 14px; }
.live .interim { color: var(--ink-3); }

.summary dl { display: grid; grid-template-columns: 180px 1fr; gap: 6px 16px; margin: 0; }
.summary dt { color: var(--ink-3); font-weight: 600; font-size: 13px; }
.summary dd { margin: 0; }
.summary ul { margin: 0; padding-left: 18px; }
@media (max-width: 720px) { .summary dl { grid-template-columns: 1fr; } }

.empty { text-align: center; padding: 34px 16px; color: var(--ink-3); }
.empty .big { font-size: 34px; margin-bottom: 6px; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 200px; }
.pill-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); }
.pill-legend span { display: inline-flex; align-items: center; gap: 6px; }
.callout { padding: 12px 14px; border-radius: 12px; background: var(--gold-soft); color: #6f5518; font-size: 14px; }
.callout.info { background: var(--calm-soft); color: #3f5f7c; }

/* print report */
@media print {
  .sidebar, .topbar, .no-print, .tabs, .btn { display: none !important; }
  .app { display: block; } .main { padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
  body { background: #fff; }
}
