:root {
  --bg: #f5f7f8; --panel: #ffffff; --text: #17222b; --muted: #5d6b76; --line: #e1e7eb;
  --brand: #0f766e; --brand-ink: #ffffff; --brand-soft: #e3f4f1;
  --danger: #b42318; --danger-soft: #fdecea; --warn: #9a5b00; --warn-soft: #fff3dc; --ok: #11743f; --ok-soft: #e2f5ea;
  --c1: #0f766e; --c2: #d9534f; --c3: #e0a030; --c4: #3b6ea8; --c5: #7a5ea8;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 32, .06), 0 2px 8px rgba(16, 24, 32, .04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1418; --panel: #162026; --text: #e7edf0; --muted: #98a7b1; --line: #26343c;
    --brand: #2bb3a5; --brand-ink: #06201d; --brand-soft: #12312e;
    --danger: #ff8a80; --danger-soft: #3a1b19; --warn: #f2b84b; --warn-soft: #3a2c10; --ok: #5fd08e; --ok-soft: #12301f;
    --c1: #2bb3a5; --c2: #ff7a70; --c3: #f2b84b; --c4: #6fa4e0; --c5: #a98ee0;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h3 { font-size: .95rem; margin: 16px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hide { display: none !important; }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 16px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { font-weight: 700; font-size: 1.05rem; padding: 4px 10px 14px; display: flex; gap: 8px; align-items: center; }
.brand svg { width: 22px; height: 22px; fill: var(--brand); }
.side a.nav { display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 8px; color: var(--text); }
.side a.nav:hover { background: var(--bg); text-decoration: none; }
.side a.nav.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.side .who { margin-top: auto; padding: 10px; border-top: 1px solid var(--line); font-size: .85rem; }
.main { padding: 24px 28px 60px; max-width: 1280px; width: 100%; }
.head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.side .menu { display: flex; flex-direction: column; gap: 4px; flex: 1; min-height: 0; }
.menu-btn { display: none; }
/* componentes */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); }
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.kpi .v { font-size: 1.55rem; font-weight: 700; line-height: 1.15; }
.kpi .l { color: var(--muted); font-size: .82rem; }
.kpi.alert .v { color: var(--danger); }
.kpi small { color: var(--muted); }
.chart { position: relative; height: 250px; }
.btn, button { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 7px 13px; border-radius: 8px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.btn:hover, button:hover { border-color: var(--brand); text-decoration: none; }
.btn.primary, button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.btn.wa { background: #1fa855; border-color: #1fa855; color: #fff; font-weight: 600; }
.btn.danger, button.danger { color: var(--danger); }
.btn.sm, button.sm { padding: 3px 9px; font-size: .85rem; }
button:disabled { opacity: .55; cursor: not-allowed; }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
input[type=checkbox] { width: auto; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 3px; }
.fld { margin-bottom: 10px; }
.row { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.check { display: flex; gap: 8px; align-items: flex-start; color: var(--text); font-size: .92rem; margin: 6px 0; }
.check input { margin-top: 3px; }
.bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.bar input, .bar select { width: auto; min-width: 150px; }
.bar input[type=search] { min-width: 260px; flex: 1; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--bg); }
.tbl { overflow-x: auto; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.bad { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.tabs a { padding: 7px 13px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text); }
.tabs a.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; text-decoration: none; }
.note { background: var(--brand-soft); border-radius: 8px; padding: 10px 12px; font-size: .9rem; margin-bottom: 14px; }
.note.warn { background: var(--warn-soft); }
.note.bad { background: var(--danger-soft); color: var(--danger); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 7px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; }
.list li:last-child { border: 0; }
.wa-item { display: grid; grid-template-columns: 220px 1fr auto; gap: 12px; align-items: start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.wa-item.sent { opacity: .6; }
.wa-item textarea { min-height: 70px; resize: vertical; }
@media (max-width: 820px) { .wa-item { grid-template-columns: 1fr; } }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.chip { font-size: .78rem; padding: 2px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); cursor: pointer; color: var(--muted); }

/* diálogo */
dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); padding: 20px; width: min(640px, 94vw); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
dialog::backdrop { background: rgba(8, 14, 18, .55); }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 99; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
#toast div { background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); max-width: 90vw; }
#toast div.err { background: var(--danger); color: #fff; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: min(400px, 100%); padding: 28px; }
.login h1 { display: flex; gap: 10px; align-items: center; }
.login h1 svg { width: 28px; height: 28px; fill: var(--brand); }
.login .btn, .login button { width: 100%; justify-content: center; margin-top: 8px; padding: 10px; }
.sep { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .85rem; margin: 14px 0 6px; }
.sep::before, .sep::after { content: ''; flex: 1; height: 1px; background: var(--line); }

/* agenda: mesmas colunas em todos os dias */
table.tab-agenda { table-layout: fixed; width: 100%; }
.tab-agenda .c-hora { width: 70px; } .tab-agenda .c-nome { width: 34%; } .tab-agenda .c-tipo { width: 28%; } .tab-agenda .c-extra { width: 90px; }
.tab-agenda td { overflow: hidden; text-overflow: ellipsis; }
.tab-agenda td:nth-child(4) { white-space: nowrap; overflow: visible; }

/* logo completa da CARDIOEXPERT (menu e login) */
.brand img { width: 100%; max-width: 180px; height: auto; display: block; }
.login h1.logo-login { justify-content: center; margin-bottom: 4px; }
.login h1.logo-login img { width: 100%; max-width: 260px; height: auto; display: block; }
@media (prefers-color-scheme: dark) { .brand img, .login h1.logo-login img { background: #fff; border-radius: 10px; padding: 6px 10px; box-sizing: border-box; } }

/* campo de senha com botão de mostrar/ocultar */
.senha-wrap { position: relative; display: block; }
.senha-wrap input { padding-right: 46px; }
.senha-wrap .olho { position: absolute; right: 4px; top: 50%; margin: 0; transform: translateY(-50%); width: 38px; height: 34px; min-height: 0; padding: 0; justify-content: center; border: 0; background: transparent; color: var(--muted); border-radius: 8px; }
.senha-wrap .olho:hover { color: var(--brand); background: var(--brand-soft); border: 0; }

/* celular (no fim do arquivo para vencer as regras base acima) */
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  /* barra superior fixa: logo à esquerda, botão de opções à direita */
  .side { position: sticky; top: 0; z-index: 40; height: auto; flex-direction: row; align-items: center; justify-content: space-between; padding: 6px 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 2px 0; }
  .brand img { max-width: 120px; }
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 0; border-radius: 10px; }
  .menu-ico, .menu-ico::before, .menu-ico::after { display: block; width: 20px; height: 2px; background: var(--text); border-radius: 2px; content: ''; position: relative; }
  .menu-ico::before { position: absolute; top: -6px; left: 0; } .menu-ico::after { position: absolute; top: 6px; left: 0; }
  .side.aberto .menu-btn { border-color: var(--brand); background: var(--brand-soft); }
  .side .menu { display: none; position: absolute; top: calc(100% + 6px); right: 10px; width: min(300px, calc(100vw - 20px)); max-height: calc(100vh - 90px); overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 14px 40px rgba(0, 0, 0, .28); padding: 8px; }
  .side.aberto .menu { display: flex; }
  .side a.nav { padding: 13px 12px; font-size: 1.02rem; }
  .side .who { margin: 6px 0 0; padding: 12px; }
  .main { padding: 14px 12px 60px; }
  h1 { font-size: 1.3rem; }
  .head { gap: 8px; }
  .g2, .g3 { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi .v { font-size: 1.25rem; }
  .row { grid-template-columns: minmax(0, 1fr); }
  .bar input, .bar select, .bar input[type=search] { min-width: 0; flex: 1 1 100%; width: 100%; }
  .bar .btn, .bar button { flex: 1 1 auto; justify-content: center; }
  .tabs a { padding: 8px 11px; }
  .card { padding: 12px; }
  button, .btn, input, select, textarea { min-height: 40px; } /* alvos de toque maiores */
  input[type=checkbox], input[type=radio] { min-height: 0; }
  table.tab-agenda { min-width: 600px; }
  th, td { padding: 8px 8px; }
  dialog { width: 96vw; max-height: 92vh; padding: 14px; }
  dialog .actions { flex-wrap: wrap; }
  dialog .actions button { flex: 1 1 auto; justify-content: center; }
  #toast { bottom: 14px; }
  .chart { height: 220px; }
}


/* impressão / PDF das listas e do painel: sem menu, botões e filtros */
@media print {
  .side, .menu-btn, .no-print, dialog, #toast { display: none !important; }
  .shell { display: block; } .main { padding: 0; max-width: none; }
  body { background: #fff; }
  .card, .kpi { box-shadow: none; break-inside: avoid; }
}

/* painel geral: seções com opção de entrar no relatório */
.relsec { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.relsec.sem-card { background: none; border: 0; box-shadow: none; padding: 26px 0 0; }
.relsec > h2 { padding-right: 90px; }
.relsec .rel { position: absolute; top: 6px; right: 8px; display: inline-flex; align-items: center; gap: 4px; font-size: .78rem; margin: 0; padding: 1px 8px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: var(--muted); }
.relsec.sem-card .rel { top: 0; }
.relsec.fora { opacity: .55; }
.relsec .kpis { margin-bottom: 0; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font-size: .9rem; }
.pill:hover { text-decoration: none; border-color: var(--brand); }
.pill.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
@media print { .relsec.fora { display: none !important; } .relsec { box-shadow: none; } }
@media print { [data-rolar] { max-height: none !important; overflow: visible !important; } }

/* aniversariantes: cada linha se acomoda na largura disponível (quebra em vez de rolar para o lado) */
table.aniv, table.aniv tbody { display: block; width: 100%; }
table.aniv tr { display: flex; flex-wrap: wrap; align-items: center; column-gap: 18px; row-gap: 4px; padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.aniv td { display: block; border: 0; padding: 2px 0; }
table.aniv td:first-child { flex: 1 1 260px; min-width: 0 !important; }
table.aniv td.nowrap:last-child { white-space: normal; display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }
[data-rolar] { overflow-x: hidden; }

/* nomes de pacientes nas listas: coluna larga o bastante para o nome completo caber em até duas linhas */
td.col-nome { min-width: 230px; }
td > a[href^="#/pacientes/"]:not([title]) { display: inline-block; min-width: 230px; line-height: 1.35; }
table.aniv td:first-child { flex: 1 1 300px; min-width: min(250px, 100%) !important; }
.wa-item { grid-template-columns: 270px 1fr auto; }
@media (max-width: 820px) { .wa-item { grid-template-columns: 1fr; } td.col-nome, td > a[href^="#/pacientes/"]:not([title]) { min-width: 200px; } table.aniv td > a[href^="#/pacientes/"] { min-width: 0; } }
.tab-agenda .c-nome { width: 40%; }

/* Retornos: colunas Situação e Mensagem mais largas, sem quebrar textos e botões */
th.col-sit, td.col-sit { min-width: 150px; white-space: nowrap; }
th.col-msg, td.col-msg { min-width: 190px; white-space: nowrap; }

.pv-rever { background: none; border: 0; padding: 0 4px; min-height: 0; font-size: .75rem; color: var(--muted); text-decoration: underline; }

.side .who .versao { margin-top: 6px; font-size: .75rem; color: var(--muted); }
