/* ---------------------------------------------------------------------------
   Estilo base do sistema. Sem framework — variáveis CSS + layout simples.
   --------------------------------------------------------------------------- */
:root {
  /* -- Superfícies e linhas -- */
  --bg: #f6f8f8;
  --surface: #ffffff;
  --surface-2: #fbfcfc;
  --border: #e4e8ea;
  --line: #e4e8ea;            /* alias de --border (nome usado no design system) */
  --line-strong: #ccd3d6;

  /* -- Tinta (texto) -- */
  --text: #263238;
  --ink: #263238;            /* alias de --text */
  --ink-2: #51626b;
  --ink-3: #87959c;
  --muted: #64748b;

  /* -- Marca -- */
  --primary: #123b52;        /* azul-marinho (accent) — ações principais, nav */
  --primary-d: #0d2c3e;
  --primary-soft: #e7eef2;
  --accent: #123b52;         /* alias de --primary */
  --accent-2: #267eae;       /* azul médio — confirmado, "previsto" */
  --accent-soft: #e7eef2;

  /* -- Status / semânticas -- */
  --ok: #1f8a78;
  --pago: #31b7a5;           /* verde-água da marca = pago/recebido */
  --brand-check: #31b7a5;
  --warn: #d97706;
  --danger: #dc2626;

  /* -- Status de agendamento (globais; consumidos pela agenda e badges) -- */
  --st-agendado: #51626b;    --st-agendado-bg: #eef1f2;
  --st-confirmado: #267eae;  --st-confirmado-bg: #e7eff4;
  --st-realizado: #1f8a78;   --st-realizado-bg: #e3f4f0;
  --st-faltou: #b5742a;      --st-faltou-bg: #f6ecdd;
  --st-cancelado: #b04a4a;   --st-cancelado-bg: #f6e7e7;

  /* -- Espaçamento (ritmo 4/8/12/16/20/24) e trilha lateral única -- */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px;
  --gutter: 16px;

  /* -- Raios e sombra -- */
  --radius-sm: 7px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(20, 40, 60, .06), 0 4px 16px rgba(20, 40, 60, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* -- Topbar / nav --
   Navegação sempre em menu-hambúrguer (drawer), em todas as larguras — igual ao
   mockup v3. Grid de 3 colunas: ☰ menu (esq.) · nome da clínica (centro) ·
   selo da marca (dir.). Links de navegação e "Sair" vivem dentro do drawer. */
.topbar {
  display: grid; grid-template-columns: 40px 1fr 40px; align-items: center; gap: .5rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 8px 1rem; min-height: 56px; position: sticky; top: 0; z-index: 50;
}
.brand { display: flex; align-items: center; justify-self: end; }
.brand .tb-mark { width: 30px; height: 30px; display: block; }
.brand:hover { text-decoration: none; }
.nav-toggle {
  display: grid; width: 40px; height: 40px; flex: none; padding: 0; justify-self: start;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: var(--radius-sm); place-items: center; cursor: pointer;
}
.nav-toggle:hover { background: var(--bg); }
.clinic-name {
  justify-self: center; min-width: 0; max-width: 100%;
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 1rem; font-weight: 650; color: var(--text);
}
.clinic-name::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--brand-check); flex: none; }
.clinic-name .cn { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

.mainnav {
  position: absolute; top: 100%; left: 0; right: 0; display: none;
  flex-direction: column; gap: .1rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow); padding: .5rem; max-height: calc(100vh - 60px); overflow-y: auto;
}
.topbar.nav-open .mainnav { display: flex; }
.mainnav a { color: var(--text); padding: .8rem .85rem; border-radius: 8px; font-weight: 500; font-size: 1rem; }
.mainnav a:hover { background: var(--bg); text-decoration: none; }
.mainnav a[aria-current="page"] { background: var(--primary-soft); color: var(--primary); }
.mainnav-user { display: flex; align-items: center; gap: .5rem; padding: .8rem .85rem .4rem; border-top: 1px solid var(--border); margin-top: .3rem; }
.user-nome { font-weight: 600; font-size: .9rem; }
.user-papel {
  background: var(--bg); color: var(--muted); padding: .1rem .5rem;
  border-radius: 999px; font-size: .72rem; text-transform: capitalize;
}
.mainnav-sair { display: block; padding: .7rem .85rem; color: var(--danger); font-weight: 600; border-radius: 8px; }
.mainnav-sair:hover { background: var(--bg); text-decoration: none; }

/* Faixa estreita: encolhe um pouco o topo. */
@media (max-width: 720px) {
  .topbar { gap: .4rem; padding: 8px .85rem; }
  .clinic-name { font-size: .95rem; }
}

.content { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1.25rem; }

/* -- Cabeçalho de página -- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head h1 { font-size: 1.4rem; margin: 0; }
.toolbar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

/* -- Botões -- */
.btn {
  display: inline-flex; align-items: center; gap: .4rem; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: .5rem .9rem; border-radius: 8px; font-size: .9rem; font-weight: 600;
  font-family: inherit; line-height: 1; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn--primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-d); }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--ghost { background: transparent; }
.btn--sm { padding: .3rem .6rem; font-size: .8rem; }

/* -- Cards / tabelas -- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1rem; }
/* Espaço abaixo de todo card (não só entre cards adjacentes) — assim dois
   cards nunca "colam", mesmo que haja outro elemento entre eles (ex.: um
   <link>/<script>). Regra geral p/ todo o sistema, inclusive telas futuras. */
.card:last-child { margin-bottom: 0; }
.card-pad { padding: 1.1rem; }

table.grid { width: 100%; border-collapse: collapse; background: var(--surface); }
table.grid th, table.grid td { padding: .65rem .8rem; text-align: left; border-bottom: 1px solid var(--border); }
table.grid th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
table.grid tr:last-child td { border-bottom: 0; }
table.grid tbody tr:hover { background: #fafbfd; }
.text-right { text-align: right !important; }

/* Tabelas largas rolam na horizontal no mobile (em vez de vazar/cortar). */
@media (max-width: 720px) {
  .card:has(> table.grid) { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .card:has(> table.grid) > table.grid { min-width: max-content; }
}
.muted { color: var(--muted); }

/* -- Stat cards -- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.stat .label { font-size: .8rem; color: var(--muted); }
.stat .value { font-size: 1.5rem; font-weight: 700; margin-top: .2rem; }
.value--ok { color: var(--ok); } .value--danger { color: var(--danger); }

/* -- Badges de status / pago -- */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .73rem; font-weight: 600; }
.badge--agendado { background: var(--st-agendado-bg); color: var(--st-agendado); }
.badge--confirmado { background: var(--st-confirmado-bg); color: var(--st-confirmado); }
.badge--realizado { background: var(--st-realizado-bg); color: var(--st-realizado); }
.badge--faltou { background: var(--st-faltou-bg); color: var(--st-faltou); }
.badge--cancelado { background: var(--st-cancelado-bg); color: var(--st-cancelado); }
.badge--pago { background: #e6f6f3; color: #0f7a6c; }
.badge--readonly { background: #f1f5f9; color: #64748b; }

/* -- Forms -- */
.form-row { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .9rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
label { font-size: .82rem; font-weight: 600; color: #334155; }
.input, select.input, textarea.input {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px;
  font-size: .9rem; font-family: inherit; background: #fff; color: var(--text);
}
.input:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea.input { resize: vertical; min-height: 70px; }

/* -- Dialog / drawer -- */
dialog {
  border: none; border-radius: 12px; padding: 0; box-shadow: 0 20px 50px rgba(2,6,23,.25);
  width: min(560px, 94vw); color: var(--text);
}
dialog::backdrop { background: rgba(15,23,42,.4); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.2rem; border-bottom: 1px solid var(--border); }
.dialog-head h3 { margin: 0; font-size: 1.05rem; }
.dialog-body { padding: 1.2rem; }
.dialog-foot { display: flex; justify-content: flex-end; gap: .5rem; padding: 1rem 1.2rem; border-top: 1px solid var(--border); }
.x { cursor: pointer; border: none; background: none; font-size: 1.3rem; color: var(--muted); line-height: 1; }

/* -- Toast -- */
.toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%) translateY(2rem);
  background: #0f172a; color: #fff; padding: .7rem 1.1rem; border-radius: 8px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 100; max-width: 90vw;
}
.toast--show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast--erro { background: var(--danger); }
.toast--ok { background: var(--ok); }

/* -- Auth -- */
.auth-body { display: grid; place-items: center; min-height: 100vh; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 2rem; width: min(380px, 92vw); }
.auth-card h1 { font-size: 1.3rem; margin: 0 0 1.25rem; text-align: center; }
.auth-logo { text-align: center; margin-bottom: 1.4rem; }
.auth-logo img { height: 46px; }
.auth-error { color: var(--danger); font-size: .85rem; margin: .2rem 0 0; }
.auth-card .btn { width: 100%; justify-content: center; margin-top: .4rem; }

/* -- Calendário (agenda) -- */
.cal { display: grid; grid-template-columns: 56px repeat(6, 1fr); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.cal-head { background: #f8fafc; border-bottom: 1px solid var(--border); padding: .5rem; text-align: center; font-size: .8rem; font-weight: 600; }
.cal-head .dow { color: var(--muted); font-weight: 500; text-transform: uppercase; font-size: .68rem; }
.cal-hour { border-right: 1px solid var(--border); border-bottom: 1px solid #f1f5f9; font-size: .72rem; color: var(--muted); text-align: right; padding: 2px 6px; height: 44px; }
.cal-cell { border-right: 1px solid #f1f5f9; border-bottom: 1px solid #f1f5f9; height: 44px; position: relative; cursor: pointer; }
.cal-cell:hover { background: #f8fafc; }
.cal-ev {
  position: absolute; left: 2px; right: 2px; border-radius: 6px; padding: 2px 5px; overflow: hidden;
  font-size: .73rem; color: #fff; cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.15); z-index: 2;
}
.cal-ev .ev-pac { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-ev .ev-proc { opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-ev .ev-pago { position: absolute; top: 2px; right: 3px; font-size: .7rem; }
.cal-ev[data-status="cancelado"] { opacity: .45; text-decoration: line-through; }

.flex { display: flex; gap: .5rem; align-items: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }

/* Bloco "Repetir lançamento" nos diálogos do financeiro. */
.repetir { border: 1px solid var(--linha, #e2e8f0); border-radius: 8px; padding: .6rem .8rem; margin-top: .4rem; }
.repetir-toggle { display: flex; gap: .5rem; align-items: center; font-weight: 500; cursor: pointer; }
.repetir-campos { margin-top: .7rem; }
.repetir-campos .form-grid { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 720px) { .repetir-campos .form-grid { grid-template-columns: 1fr; } }
@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
  .cal { grid-template-columns: 44px repeat(6, 1fr); font-size: .9em; }
}
