/* Klinio — interface
   Para qualquer consultório: medicina, odontologia, psicologia, nutrição…
   Verde-petróleo como cor de ação (calmo e confiável, sem o "azul de hospital"),
   neutros levemente esverdeados no lugar do cinza frio, status com cores próprias.
   Geist para interface, Geist Mono para números (CPF, horários, valores em tabela). */

:root {
  --bg: #F4F6F5;
  --surface: #FFFFFF;
  --surface-2: #F8FAF9;
  --hover: #EEF2F0;
  --line: #E1E7E4;
  --line-strong: #C9D3CE;
  --ink: #13201C;
  --ink-2: #44524D;
  --ink-3: #66746F;
  --ink-4: #97A39E;
  --accent: #0B6E62;
  --accent-hover: #08584F;
  --accent-soft: #E5F3EF;
  --accent-line: #BFE0D7;
  --chart: #00897B;
  --ok: #1E7A45;
  --ok-soft: #EAF6EE;
  --danger: #B4362B;
  --danger-soft: #FDF0EE;
  --warn: #8A5A00;
  --warn-soft: #FDF4E3;
  --focus: #0B6E62;
  --ring: rgba(11, 110, 98, .18);

  --font: 'Geist', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --r: 10px;
  --r-sm: 8px;
  --side-w: 240px;
  --shadow-sm: 0 1px 2px rgba(19, 32, 28, .04);
  --shadow-pop: 0 12px 32px -12px rgba(19, 32, 28, .22), 0 2px 6px rgba(19, 32, 28, .06);
  --ease: cubic-bezier(.2, .7, .2, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3, p { margin: 0; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
[tabindex="-1"]:focus { outline: none; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.i { width: 18px; height: 18px; flex: none; }
.i-sm { width: 16px; height: 16px; }
.mono { font-family: var(--mono); font-size: .92em; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.skip { position: fixed; z-index: 200; left: 12px; top: -60px; padding: 10px 14px; border-radius: var(--r-sm); background: var(--ink); color: #fff; font-weight: 500; text-decoration: none; }
.skip:focus { top: 12px; }

.boot { min-height: 100vh; display: grid; place-items: center; }
.boot-mark { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px; border-radius: var(--r-sm);
  border: 1px solid var(--line-strong); background: var(--surface); box-shadow: var(--shadow-sm);
  font-weight: 500; font-size: 14px; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .55; cursor: progress; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn-ghost:hover { background: var(--hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #962B22; border-color: #962B22; }
.btn-danger-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-lg { height: 42px; padding: 0 18px; font-size: 15px; }
.btn-block { width: 100%; }

.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--r-sm); border: 0; background: transparent; color: var(--ink-3); cursor: pointer; text-decoration: none; }
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn-accent { background: var(--accent); color: #fff; }
.icon-btn-accent:hover { background: var(--accent-hover); color: #fff; }

/* ---------- estrutura ---------- */
.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 16px 12px 12px; background: var(--surface); border-right: 1px solid var(--line); }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 2px 8px; }
.brand { display: inline-flex; align-items: center; gap: 9px; text-decoration: none; color: var(--ink); }
.brand span { font-weight: 600; font-size: 17px; letter-spacing: -.02em; }
.mark { width: 26px; height: 26px; color: var(--accent); flex: none; }

.room { margin: 18px 0 14px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface-2); }
.room-label { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 500; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-3); }
.room-label::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }
.room-name { display: block; margin-top: 2px; font-weight: 500; line-height: 1.35; }
.room select {
  width: 100%; margin-top: 2px; padding: 2px 22px 2px 0; border: 0; background: transparent; font-weight: 500; cursor: pointer; appearance: none; -webkit-appearance: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E") no-repeat right center / 16px;
}
.room-empty { display: inline-flex; align-items: center; gap: 6px; margin-top: 4px; color: var(--accent); font-weight: 500; text-decoration: none; }
.room-admin { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--ink-2); }

.side-gap { height: 18px; }
.nav { display: grid; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 10px; border-radius: var(--r-sm); color: var(--ink-2); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--hover); color: var(--ink); }
.nav a.is-active { background: var(--accent-soft); color: var(--accent); }
.nav-sep { height: 1px; margin: 8px 4px; background: var(--line); }

.side-foot { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 12px 4px 0; border-top: 1px solid var(--line); }
.avatar { display: inline-grid; place-items: center; width: 32px; height: 32px; flex: none; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 12px; }
.avatar-lg { width: 48px; height: 48px; font-size: 16px; }
.who { min-width: 0; flex: 1; display: grid; line-height: 1.3; }
.who strong { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who span { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { min-width: 0; }
.mobile-bar { display: none; }
.content { width: 100%; max-width: 1120px; margin: 0 auto; padding: 32px 40px 80px; }
.scrim { display: none; }

/* ---------- cabeçalho ---------- */
.page-head { margin-bottom: 24px; }
.back { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 12px; color: var(--ink-3); text-decoration: none; font-size: 13px; font-weight: 500; }
.back:hover { color: var(--ink); }
.page-head-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.eyebrow { font-size: 13px; color: var(--ink-3); margin-bottom: 4px; }
.page-head h1 { font-size: 26px; font-weight: 600; line-height: 1.2; letter-spacing: -.025em; }
.page-sub { margin-top: 6px; color: var(--ink-3); max-width: 64ch; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.section { margin-top: 32px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-head h2 { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.section-head a { font-size: 13px; font-weight: 500; color: var(--accent); text-decoration: none; }
.section-head a:hover { text-decoration: underline; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-sm); }
.panel-pad { padding: 24px; }

/* ---------- métricas ---------- */
.stats { display: grid; grid-template-columns: repeat(var(--n, 4), minmax(0, 1fr)); gap: 12px; margin: 0; }
.stat { padding: 16px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-sm); min-width: 0; }
.stat dt { font-size: 13px; color: var(--ink-3); }
.stat dd { margin: 6px 0 0; font-size: 24px; font-weight: 600; letter-spacing: -.02em; line-height: 1.15; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat small { display: block; margin-top: 4px; font-size: 12px; color: var(--ink-3); }
.delta-up { color: var(--ok); }
.delta-down { color: var(--danger); }

/* ---------- linhas ---------- */
.rows { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-sm); overflow: hidden; }
.rows > li + li { border-top: 1px solid var(--line); }
.row { display: grid; grid-template-columns: var(--cols, 1fr auto); gap: 16px; align-items: center; padding: 12px 16px; text-decoration: none; color: inherit; min-height: 60px; }
a.row:hover { background: var(--surface-2); }
a.row:hover .row-go { color: var(--ink-2); }
.row-go { color: var(--ink-4); }
.row-main { min-width: 0; display: flex; align-items: center; gap: 12px; }
.row-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 13px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-text { min-width: 0; display: grid; }
.row-meta { font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-money { font-size: 14px; font-weight: 500; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cols-head { display: grid; grid-template-columns: var(--cols); gap: 16px; padding: 0 16px 8px; font-size: 12px; font-weight: 500; color: var(--ink-3); }
.cols-head .r { text-align: right; }

/* lista de procedimentos dentro de uma linha */
.procs { display: grid; gap: 2px; min-width: 0; font-size: 13px; }
.procs li { display: flex; justify-content: space-between; gap: 12px; min-width: 0; }
.procs ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.procs .p-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); }
.procs .p-val { white-space: nowrap; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.procs .p-more { color: var(--ink-3); }

.badge { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-off { background: var(--hover); color: var(--ink-3); }
.badge-live { background: var(--accent-soft); color: var(--accent); }
.badge-live::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------- clínicas (cartões) ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.card { position: relative; display: flex; flex-direction: column; gap: 12px; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-sm); transition: border-color .15s; }
.card:hover { border-color: var(--line-strong); }
.card.is-live { border-color: var(--accent-line); box-shadow: 0 0 0 1px var(--accent-line); }
.card h3 { font-size: 16px; font-weight: 600; letter-spacing: -.01em; }
.card h3 a { text-decoration: none; }
.card h3 a::after { content: ''; position: absolute; inset: 0; border-radius: inherit; }
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card-lines { display: grid; gap: 6px; font-size: 13px; color: var(--ink-2); }
.card-lines div { display: flex; gap: 8px; align-items: flex-start; }
.card-lines .i { margin-top: 1px; color: var(--ink-4); }
.card-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; gap: 10px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 13px; color: var(--ink-3); }
.card-foot .btn { position: relative; z-index: 1; }

/* ---------- ficha ---------- */
.dossier { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 20px; align-items: start; }
.facts { padding: 20px; }
.facts-id { display: flex; align-items: center; gap: 12px; padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.facts dl { margin: 0; display: grid; gap: 12px; }
.facts dt { font-size: 12px; color: var(--ink-3); }
.facts dd { margin: 2px 0 0; overflow-wrap: anywhere; }
.facts dd.pre { white-space: pre-line; }
.facts-actions { display: flex; gap: 8px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }

/* histórico */
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.tl-card { padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-sm); }
.tl-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.tl-when { font-weight: 600; }
.tl-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 2px; font-size: 13px; color: var(--ink-3); }
.tl-meta span { display: inline-flex; align-items: center; gap: 5px; }
.items { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.items li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 12px; }
.items li + li { border-top: 1px solid var(--line); }
.items .it-name { min-width: 0; }
.items .it-code { margin-left: 6px; font-size: 12px; color: var(--ink-3); }
.items .it-val { white-space: nowrap; font-variant-numeric: tabular-nums; }
.items .it-total { background: var(--surface-2); font-weight: 600; }
.tl-obs { margin-top: 12px; color: var(--ink-2); white-space: pre-line; font-size: 13px; }
.tl-obs strong { display: block; font-size: 12px; font-weight: 500; color: var(--ink-3); margin-bottom: 2px; }

/* tabela simples */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-sm); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { padding: 10px 16px; text-align: left; font-size: 12px; font-weight: 500; color: var(--ink-3); background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .r { text-align: right; }
.table .num, .table td.r { font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tr.is-off td { color: var(--ink-3); }
.table tbody tr:hover td { background: var(--surface-2); }
.table a { text-decoration: none; font-weight: 500; }
.table a:hover { text-decoration: underline; }
.share { display: flex; align-items: center; gap: 10px; min-width: 140px; }
.share-bar { flex: 1; height: 6px; border-radius: 3px; background: var(--hover); overflow: hidden; }
.share-bar span { display: block; height: 100%; border-radius: 3px; background: var(--chart); }
.share small { width: 40px; text-align: right; color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* ---------- formulários ---------- */
.form { display: grid; gap: 24px; }
.fieldset { border: 0; margin: 0; padding: 0; display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; }
.fieldset + .fieldset { padding-top: 24px; border-top: 1px solid var(--line); }
.fieldset-legend h2 { font-size: 14px; font-weight: 600; }
.fieldset-legend p { margin-top: 4px; font-size: 13px; color: var(--ink-3); }
.grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 16px; }
.field { grid-column: span 6; display: grid; gap: 6px; align-content: start; }
.span-1 { grid-column: span 1; } .span-2 { grid-column: span 2; } .span-3 { grid-column: span 3; } .span-4 { grid-column: span 4; } .span-5 { grid-column: span 5; }
.field label, .label { font-size: 13px; font-weight: 500; }
.opt { font-weight: 400; color: var(--ink-4); font-size: 12px; margin-left: 4px; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 38px; padding: 8px 11px; border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface); box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s;
}
.field textarea { resize: vertical; min-height: 84px; line-height: 1.5; }
.field select { appearance: none; -webkit-appearance: none; padding-right: 34px; background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E") no-repeat right 10px center / 16px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.field input[readonly] { background: var(--surface-2); color: var(--ink-2); }
.field input::placeholder, .field textarea::placeholder { color: var(--ink-4); }
.prefix { position: relative; }
.prefix span { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.prefix input { padding-left: 34px; font-variant-numeric: tabular-nums; }
.field .help { font-size: 12px; color: var(--ink-3); }
.field .error { display: none; font-size: 12px; color: var(--danger); font-weight: 500; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.field.has-error .error { display: block; }
.form-foot { display: flex; justify-content: flex-end; align-items: center; gap: 10px; padding-top: 20px; border-top: 1px solid var(--line); }
.form-foot .grow { margin-right: auto; }
.form-alert { display: none; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--r-sm); background: var(--danger-soft); color: var(--danger); font-weight: 500; font-size: 13px; }
.form-alert.show { display: flex; }

/* valor automático */
.auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; margin: 0; }
.auto > div { padding: 12px 14px; background: var(--surface-2); }
.auto > div + div { border-left: 1px solid var(--line); }
.auto dt { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-3); }
.auto dd { margin: 4px 0 0; font-weight: 500; }
.auto small { display: block; font-size: 12px; color: var(--ink-3); font-weight: 400; margin-top: 2px; }

/* busca de paciente */
.combo { position: relative; }
.with-icon { position: relative; }
.with-icon > .i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--ink-4); pointer-events: none; }
.with-icon input { padding-left: 36px !important; }
.combo-list { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); max-height: 300px; overflow: auto; margin: 0; padding: 4px; list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-pop); }
.combo-opt { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.combo-opt[aria-selected="true"] { background: var(--accent-soft); }
.combo-opt mark { background: transparent; color: var(--accent); font-weight: 600; }
.combo-opt .mono { color: var(--ink-3); font-size: 12px; }
.combo-new { color: var(--accent); font-weight: 500; justify-content: flex-start; }
.combo-empty { padding: 10px; color: var(--ink-3); font-size: 13px; }
.patient-pick { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--accent-line); border-radius: var(--r-sm); background: var(--accent-soft); }
.patient-pick.is-new { border-color: #F2DDA9; background: var(--warn-soft); }
.patient-pick .avatar { background: var(--surface); }
.patient-pick .grow { flex: 1; min-width: 0; display: grid; line-height: 1.35; }
.patient-pick .grow span { font-size: 12px; color: var(--ink-2); }

/* seleção de procedimentos */
.picks { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--r-sm); max-height: 340px; overflow: auto; background: var(--surface); }
.picks li + li { border-top: 1px solid var(--line); }
.pick { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 12px; cursor: pointer; }
.pick:hover { background: var(--surface-2); }
.field .pick input { width: 16px; height: 16px; min-height: 0; margin: 0; padding: 0; border: 0; box-shadow: none; accent-color: var(--accent); }
.pick:has(input:checked) { background: var(--accent-soft); }
.pick-name { font-weight: 500; }
.pick-meta { display: block; font-size: 12px; color: var(--ink-3); }
.pick-val { font-variant-numeric: tabular-nums; font-weight: 500; }
.picks-empty { padding: 14px; font-size: 13px; color: var(--ink-3); }
.picks-tools { margin-bottom: 8px; }
.picks-tools input { width: 100%; height: 36px; padding: 0 11px 0 36px; border: 1px solid var(--line-strong); border-radius: var(--r-sm); }
.notice { display: flex; gap: 12px; align-items: flex-start; padding: 14px; border: 1px dashed var(--line-strong); border-radius: var(--r-sm); background: var(--surface-2); }
.notice .i { color: var(--ink-3); margin-top: 1px; }
.notice p { color: var(--ink-2); font-size: 13px; }
.notice strong { display: block; color: var(--ink); font-size: 14px; margin-bottom: 2px; }
.notice .btn { margin-top: 10px; }

.summary { margin-top: 12px; }
.total-bar { display: flex; align-items: baseline; gap: 8px; }
.total-bar span { font-size: 13px; color: var(--ink-3); }
.total-bar strong { font-size: 20px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }

/* ---------- busca e filtros ---------- */
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.search { position: relative; flex: 1; min-width: 220px; max-width: 400px; }
.search .i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--ink-4); }
.search input { width: 100%; height: 38px; padding: 0 12px 0 36px; border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--surface); box-shadow: var(--shadow-sm); }
.search input:focus, .filter input:focus, .filter select:focus, .picks-tools input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.count { font-size: 13px; color: var(--ink-3); }

.filters { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1.15fr) repeat(2, minmax(0, 1fr)) repeat(2, minmax(0, 1.2fr)); gap: 12px; padding: 14px 16px; margin-bottom: 14px; }
.filter-fields { display: contents; }
.filter { display: grid; gap: 5px; align-content: start; min-width: 0; }
.filter label { font-size: 12px; font-weight: 500; color: var(--ink-3); }
.filter input, .filter select { width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--surface); font-size: 13px; min-width: 0; }
.filter select { appearance: none; -webkit-appearance: none; padding-right: 30px; text-overflow: ellipsis; background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E") no-repeat right 8px center / 16px; }
.filter .with-icon input { padding-left: 32px !important; }
.filter .with-icon > .i { left: 10px; }
.filter-foot { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding-top: 12px; border-top: 1px solid var(--line); }
.filter-status { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.filter-toggle { display: none; }
.filter-n { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 11px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { height: 28px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); font-size: 12px; font-weight: 500; cursor: pointer; color: var(--ink-2); }
.chip:hover { border-color: var(--ink-4); color: var(--ink); }
.chip.is-on { background: var(--ink); border-color: var(--ink); color: #fff; }

.seg { display: inline-flex; padding: 2px; border-radius: var(--r-sm); background: var(--hover); }
.seg button { height: 28px; padding: 0 12px; border: 0; border-radius: 6px; background: transparent; font-size: 13px; font-weight: 500; color: var(--ink-3); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

.more { display: flex; justify-content: center; margin-top: 12px; }

/* ---------- gráfico financeiro ---------- */
.atd-filters { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1.2fr); }
.atd-filters .filter-foot { justify-content: space-between; }
.fin-filters { grid-template-columns: repeat(2, minmax(0, 180px)) minmax(0, 320px); justify-content: start; }
.fin-filters .filter-foot { padding-top: 12px; }
.chart-card { padding: 18px 18px 12px; }
.chart-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.chart-head h2 { font-size: 15px; font-weight: 600; }
.chart-head p { font-size: 13px; color: var(--ink-3); margin-top: 2px; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart:focus-visible { outline-offset: 4px; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .base-line { stroke: var(--line-strong); stroke-width: 1; }
.chart .tick { fill: var(--ink-3); font-size: 11px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--chart); transition: opacity .15s; }
.chart .bar.dim { opacity: .45; }
.chart .area { fill: var(--chart); opacity: .08; }
.chart .line { fill: none; stroke: var(--chart); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--chart); stroke: var(--surface); stroke-width: 2; }
.chart .cross { stroke: var(--ink-4); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-tip { position: absolute; z-index: 5; pointer-events: none; min-width: 170px; padding: 10px 12px; border-radius: var(--r-sm); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-pop); font-size: 12px; transform: translate(-50%, calc(-100% - 10px)); }
.chart-tip strong { display: block; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart-tip .t-label { color: var(--ink-3); margin-bottom: 4px; }
.chart-tip .t-row { display: flex; justify-content: space-between; gap: 12px; color: var(--ink-2); margin-top: 2px; font-variant-numeric: tabular-nums; }
.chart-empty { display: grid; place-items: center; height: 240px; color: var(--ink-3); font-size: 13px; }
.chart-note { margin-top: 8px; font-size: 12px; color: var(--ink-3); }
details.data-table { margin-top: 8px; }
details.data-table summary { cursor: pointer; font-size: 13px; color: var(--ink-3); padding: 6px 0; }
details.data-table summary:hover { color: var(--ink); }
.two-col { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; align-items: start; }

/* ---------- vazio ---------- */
.empty { text-align: center; padding: 44px 24px; background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--r); }
.empty-icon { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; background: var(--hover); color: var(--ink-3); margin-bottom: 12px; }
.empty h2 { font-size: 16px; font-weight: 600; }
.empty p { margin: 4px auto 0; max-width: 46ch; color: var(--ink-3); }
.empty-action { margin-top: 16px; }
.empty-sm { padding: 28px 20px; }

/* ---------- avisos ---------- */
.toasts { position: fixed; z-index: 100; right: 20px; bottom: 20px; display: grid; gap: 8px; }
.toast { display: flex; align-items: center; gap: 10px; max-width: 380px; padding: 10px 14px; border-radius: var(--r-sm); background: var(--ink); color: #fff; font-size: 13px; font-weight: 500; box-shadow: var(--shadow-pop); animation: toast-in .2s var(--ease); }
.toast .i { color: #86EFAC; }
.toast-error .i { color: #FCA5A5; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

.dialog { border: 0; padding: 0; border-radius: 12px; width: min(420px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-pop); }
.dialog::backdrop { background: rgba(19, 32, 28, .4); }
.dialog form { padding: 22px; }
.dialog h2 { font-size: 17px; font-weight: 600; }
.dialog p { margin-top: 8px; color: var(--ink-2); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }

/* ---------- acesso ---------- */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; background: var(--bg); }
.gate-box { width: 100%; max-width: 380px; }
.gate-box .brand { margin-bottom: 28px; }
.gate-card { padding: 28px; }
.gate-card h1 { font-size: 20px; font-weight: 600; letter-spacing: -.02em; }
.gate-card > p { margin-top: 4px; color: var(--ink-3); }
.gate-card .form { gap: 16px; margin-top: 22px; }
.gate-card .grid { gap: 14px; }
.gate-foot { margin-top: 18px; text-align: center; font-size: 12px; color: var(--ink-3); }
.pw { position: relative; }
.pw button { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); height: 30px; padding: 0 10px; border: 0; background: transparent; color: var(--ink-3); font-size: 12px; font-weight: 500; cursor: pointer; border-radius: 6px; }
.pw button:hover { color: var(--ink); background: var(--hover); }
.pw input { padding-right: 72px !important; }

/* ---------- responsivo ---------- */
.only-mobile, .show-sm { display: none !important; }

@media (max-width: 1100px) {
  .filters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .filter-wide { grid-column: span 2; }
  .two-col { grid-template-columns: 1fr; }
}

@media (max-width: 960px) {
  .dossier { grid-template-columns: 1fr; }
  .fieldset { grid-template-columns: 1fr; gap: 12px; }
  .stats { --n: 2 !important; }
}

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 50; left: 0; top: 0; bottom: 0; width: min(290px, 86vw); height: auto; transform: translateX(-100%); visibility: hidden; transition: transform .25s var(--ease), visibility 0s linear .25s; }
  .menu-open .side { transform: none; visibility: visible; transition: transform .25s var(--ease); box-shadow: var(--shadow-pop); }
  .scrim { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(19, 32, 28, .35); opacity: 0; pointer-events: none; transition: opacity .25s; }
  .menu-open .scrim { opacity: 1; pointer-events: auto; }
  .only-mobile { display: inline-grid !important; }
  .show-sm { display: block !important; }
  .mobile-bar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; height: 56px; padding: 0 10px; background: rgba(255, 255, 255, .94); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
  .content { padding: 20px 16px 64px; }
  .page-head h1 { font-size: 22px; }
  .stat { padding: 12px 14px; }
  .stat dd { font-size: 20px; }
  .row { --cols: minmax(0, 1fr) auto !important; padding: 12px 14px; gap: 12px; }
  .hide-sm, .cols-head { display: none !important; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field, .span-3, .span-4, .span-5 { grid-column: span 2; }
  .span-1, .span-2 { grid-column: span 1; }
  .auto { grid-template-columns: 1fr; }
  .auto > div + div { border-left: 0; border-top: 1px solid var(--line); }
  .form-foot { position: sticky; bottom: 0; z-index: 5; margin: 0 -24px -24px; padding: 12px 16px; background: rgba(255, 255, 255, .96); backdrop-filter: blur(8px); border-radius: 0 0 var(--r) var(--r); flex-wrap: wrap; }
  .form-foot .btn { flex: 1; }
  .form-foot .grow { flex-basis: 100%; }
  .panel-pad { padding: 16px; }
  .form-foot { margin: 0 -16px -16px; }
  .toasts { left: 12px; right: 12px; bottom: 12px; }
  .toast { max-width: none; }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 12px; }
  .filter-wide { grid-column: 1 / -1; }
  .filter-toggle { display: inline-flex; grid-column: 1 / -1; justify-self: start; }
  .filter-fields { display: none; }
  .filters.is-open .filter-fields { display: grid; grid-column: 1 / -1; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .filter-fields > .filter:last-child, .fin-cli { grid-column: 1 / -1; }
  .fin-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters:not(.is-open) .filter-foot { border-top: 0; padding-top: 0; }
  .filter-status { margin-left: 0; width: 100%; justify-content: space-between; }
  .table th, .table td { padding: 10px 12px; }
  .hide-table-sm { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- pagamento, data do atendimento e ações ---------- */
.row-money { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.row-money .badge { font-weight: 500; }
.pay-pago { background: var(--ok-soft); color: var(--ok); }
.pay-pendente { background: var(--warn-soft); color: var(--warn); }
.pay-nao_informado { background: var(--hover); color: var(--ink-3); }
.tl-actions { display: flex; align-items: center; gap: 2px; }
.tl-actions .badge { margin-right: 6px; }
.tl-pay { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 12px; padding: 10px 12px; border-radius: var(--r-sm); background: var(--warn-soft); color: var(--warn); font-size: 13px; }
.tl-pay strong { font-variant-numeric: tabular-nums; }
.seg-lg { display: flex; width: 100%; max-width: 320px; }
.seg-lg label { position: relative; flex: 1; cursor: pointer; }
.seg-lg input { position: absolute; opacity: 0; pointer-events: none; }
.seg-lg span { display: grid; place-items: center; height: 34px; border-radius: 6px; font-size: 14px; font-weight: 500; color: var(--ink-3); }
.seg-lg input:checked + span { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.seg-lg input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }
.when-now { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface-2); max-width: 420px; }
.when-now strong { display: block; font-weight: 500; font-variant-numeric: tabular-nums; }
.when-now small { font-size: 12px; color: var(--ink-3); }
.field input[type="datetime-local"] { max-width: 260px; }
.link { padding: 0; border: 0; background: none; color: var(--accent); font: inherit; font-size: 12px; font-weight: 500; cursor: pointer; }
.link:hover { text-decoration: underline; }
.atd-filters { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1.2fr) minmax(0, 1fr) !important; }
@media (max-width: 820px) {
  .atd-filters { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .tl-pay .btn { width: 100%; }
}

/* ---------- celular: barra inferior, toque e telas compactas ---------- */
.tabbar, .mobile-user, .facts-toggle, .only-mobile-chip { display: none; }
.facts-alert { margin: -4px 0 12px; padding: 8px 10px; border-radius: var(--r-sm); background: var(--warn-soft); color: var(--warn); font-size: 13px; }
.facts-quick { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.logout-box { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.logout-box p { font-size: 13px; }

@media (max-width: 820px) {
  :root { --tab-h: 64px; }
  /* 16px evita o zoom automático do iPhone ao tocar num campo */
  input, select, textarea,
  .field input, .field select, .field textarea, .filter input, .filter select, .search input, .picks-tools input, .room select { font-size: 16px !important; }
  .btn { min-height: 44px; }
  .btn-sm { min-height: 40px; height: auto; padding: 0 12px; }
  .icon-btn { width: 44px; height: 44px; }
  .chip { height: 36px; padding: 0 14px; font-size: 13px; flex: none; }
  .filter input, .filter select, .search input, .picks-tools input { height: 44px; }
  .field input, .field select { min-height: 44px; }
  .pick { padding: 12px; min-height: 56px; }
  .field .pick input { width: 20px; height: 20px; }

  .mobile-bar { justify-content: space-between; padding: env(safe-area-inset-top) 16px 0; height: calc(52px + env(safe-area-inset-top)); }
  .mobile-user { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--hover); color: var(--ink-2); font-size: 12px; font-weight: 600; }

  .tabbar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; z-index: 45; left: 0; right: 0; bottom: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); background: rgba(255, 255, 255, .96); backdrop-filter: blur(10px); border-top: 1px solid var(--line); }
  .tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 50px; color: var(--ink-3); text-decoration: none; font-size: 11px; font-weight: 500; border-radius: var(--r-sm); }
  .tab .i { width: 22px; height: 22px; }
  .tab.is-active { color: var(--accent); }
  .tab-plus-icon { display: grid; place-items: center; width: 46px; height: 32px; border-radius: 10px; background: var(--accent); color: #fff; }
  .tab-plus-icon .i { width: 20px; height: 20px; }
  .tab-plus { color: var(--ink-2); }
  .content { padding-bottom: calc(var(--tab-h) + 32px + env(safe-area-inset-bottom)); }
  .toasts { bottom: calc(var(--tab-h) + 12px + env(safe-area-inset-bottom)); }
  body.is-focus .content { padding-bottom: 32px; }
  body.is-focus .toasts { bottom: calc(132px + env(safe-area-inset-bottom)); }
  .form-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }

  .page-head-row { align-items: flex-start; }
  .actions { width: 100%; }
  .actions .btn { flex: 1; }
  .fieldset-legend p { display: none; }

  /* ficha do paciente: dados recolhidos, histórico logo abaixo */
  .facts { padding: 16px; }
  .facts-id { padding-bottom: 12px; margin-bottom: 12px; }
  .facts:not(.is-open) dl, .facts:not(.is-open) .facts-actions { display: none; }
  .facts dl > .is-empty { display: none; }
  .facts-toggle { display: inline-flex; width: 100%; }
  .facts.is-open .facts-toggle { margin-bottom: 12px; }
  .facts-quick .btn { flex: 1; }
  .tl-head { flex-wrap: wrap; }

  /* financeiro: uma faixa de períodos com rolagem lateral; datas só em "Personalizado" */
  .chips-scroll { flex-wrap: nowrap; overflow-x: auto; margin: 0 -12px; padding: 2px 12px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .chips-scroll::-webkit-scrollbar { display: none; }
  .only-mobile-chip { display: inline-flex; align-items: center; }
  .fin-filters .filter:not(.fin-cli) { display: none; }
  .fin-filters.show-dates .filter:not(.fin-cli) { display: grid; }
  .fin-filters .filter-foot { order: -1; border-top: 0; padding-top: 0; }
}

/* ---------- celular: todos os campos de formulário com a mesma largura ---------- */
@media (max-width: 820px) {
  .grid > .field, .grid > .span-1, .grid > .span-2, .grid > .span-3, .grid > .span-4, .grid > .span-5 { grid-column: 1 / -1; }
  .field input, .field select, .field textarea, .prefix, .pw { width: 100%; max-width: none; }
  .field input[type="date"], .field input[type="datetime-local"], .field input[type="number"] {
    -webkit-appearance: none; appearance: none; display: block; min-height: 44px; max-width: none; text-align: left;
  }
  .when-now { max-width: none; }
  .seg-lg { max-width: none; }
}
