/* ============================================================
   Clínica Bem Me Quer — Sistema de Gestão
   Base: CSS custom properties + flexbox/grid
   Sem prefixos vendor obsoletos
   ============================================================ */

@font-face {
  font-family: 'Inter';
  src: url('../fonts/inter.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* ── Reset mínimo ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
img { border: none; max-width: 100%; image-orientation: from-image; }

/* ── Tokens ──────────────────────────────────────────────────
   Linen — claro & editorial. Cor é informação, não decoração.
   ──────────────────────────────────────────────────────────── */
:root {
  /* marca (usada com contenção) */
  --color-primary:      #2f5d8a;
  --color-primary-dark: #234a70;
  --color-primary-light:#eaf1f8;
  --color-accent:       #b9648f;
  --color-accent-soft:  #faf0f5;

  /* texto — quase-preto quente, não #000 */
  --color-text:         #1a1d21;
  --color-text-soft:    #3f4650;
  --color-text-muted:   #8a909a;
  --color-text-faint:   #b4b9c2;

  /* superfícies — off-white quente */
  --color-bg:           #f7f6f3;
  --color-surface:      #ffffff;
  --color-surface-sunk: #fbfaf8;

  /* bordas nítidas, finas */
  --color-border:       #e7e4de;
  --color-border-strong:#d8d4cc;

  /* semântica (significado, não enfeite) */
  --color-danger:       #c0392b;
  --color-danger-soft:  #fbeae8;
  --color-warning:      #b7791f;
  --color-warning-soft: #fbf3e3;
  --color-success:      #2f7d52;
  --color-success-soft: #e9f3ec;

  --radius-sm:   6px;
  --radius-md:   9px;
  --radius-lg:   12px;
  --radius-xl:   16px;

  /* sombras quase invisíveis — profundidade por borda, não por blur */
  --shadow-xs:   0 1px 1px rgba(26,29,33,.03);
  --shadow-sm:   0 1px 2px rgba(26,29,33,.04), 0 1px 1px rgba(26,29,33,.03);
  --shadow-md:   0 2px 6px rgba(26,29,33,.05), 0 1px 2px rgba(26,29,33,.04);
  --shadow-lg:   0 8px 24px rgba(26,29,33,.07), 0 2px 6px rgba(26,29,33,.04);

  --font-base:   'Inter', system-ui, sans-serif;
  --font-size:   14px;
  --line-height: 1.5;

  /* numerais tabulares para tudo o que é dado/financeiro */
  --tnum: "tnum" 1, "lnum" 1;

  --topbar-height: 56px;
  --navbar-height: 46px;

  --ease-out: cubic-bezier(.16,1,.3,1);
}

/* ── Animações globais ── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ── Base ── */
html { height: 100%; font-size: var(--font-size); }

body {
  font-family: var(--font-base);
  line-height: var(--line-height);
  color: var(--color-text);
  background: var(--color-bg);
  height: 100%;
}

/* ── Layout principal ── */
#app {
  display: grid;
  grid-template-rows: var(--topbar-height) var(--navbar-height) 1fr;
  grid-template-columns: 1fr;
  grid-template-areas:
    "topbar"
    "navbar"
    "main";
  min-height: 100vh;
}

/* ── Topbar (barra superior: logo + utilizador) ── */
#topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  padding: 0 22px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 200;
}

#topbar .logo {
  display: flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  cursor: pointer;
  flex-shrink: 0;
}

#topbar .logo img { height: 34px; width: auto; }

#topbar .logo-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.2;
  letter-spacing: -.01em;
}

#topbar .topbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  flex-shrink: 0;
}

#topbar .user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-soft);
  margin-right: 8px;
  padding-right: 12px;
  border-right: 1px solid var(--color-border);
}

.topbar-icon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  text-decoration: none;
  transition: background .15s, color .15s;
  cursor: pointer;
}
.topbar-icon:hover { background: var(--color-bg); color: var(--color-text); }
.topbar-icon .badge {
  position: absolute;
  top: 4px; right: 2px;
  min-width: 16px; height: 16px;
  font-size: 9px;
}

#topbar .btn-icon {
  color: var(--color-text-muted);
  border: none;
  background: transparent;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  transition: background .15s, color .15s;
}
#topbar .btn-icon:hover { background: var(--color-danger-soft); color: var(--color-danger); }

/* ── Navbar (barra de módulos) ── */
#main-nav {
  grid-area: navbar;
  display: flex;
  align-items: stretch;
  padding: 0 16px;
  background: var(--color-surface);
  border-bottom: 2px solid var(--color-border);
  position: sticky;
  top: var(--topbar-height);
  z-index: 100;
  overflow-x: auto;
  gap: 0;
}

.nav-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 15px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-soft);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}

.nav-item:hover { color: var(--color-text); }
.nav-item.active { color: var(--color-primary); border-bottom-color: var(--color-primary); font-weight: 600; }
.nav-item-ext { color: var(--color-text-muted); opacity: .7; }
.nav-item-wip { color: var(--color-text-faint); }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--color-primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
}

.badge-danger { background: var(--color-danger); }
.badge-warning { background: var(--color-warning); }

/* ── Área principal ── */
#main {
  grid-area: main;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* conteúdo trocado via htmx entra suavemente */
#main-content { animation: fadeInUp .4s var(--ease-out); }

/* ── Indicador de carregamento htmx ── */
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { opacity: 1; }
#main-content.htmx-request { opacity: .5; transition: opacity .15s; }

/* barra de progresso topo durante pedidos */
#htmx-progress {
  position: fixed; top: 0; left: 0; height: 2px; width: 0;
  background: var(--color-primary);
  z-index: 9999;
  transition: width .3s var(--ease-out), opacity .3s;
  opacity: 0;
}

/* ── Cards / superfícies ── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: box-shadow .25s var(--ease-out), transform .25s var(--ease-out);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
  font-weight: 600;
  font-size: 14px;
  color: var(--color-primary);
}

.card-body { padding: 20px; }

/* ── Tabelas ── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  padding: 11px 14px;
  background: var(--color-surface-sunk);
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
  line-height: 1.4;
  font-feature-settings: var(--tnum);
}

tr:last-child td { border-bottom: none; }
tbody tr { transition: background .12s; }
tbody tr:hover td { background: var(--color-surface-sunk); }

/* linha destacada — paciente não pago */
tr.unpaid td { background: var(--color-warning-soft); color: var(--color-warning); }
tr.unpaid:hover td { background: #f6ecd6; }

/* ── Formulários ── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
}

label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
}

input, select, textarea {
  font-family: var(--font-base);
  font-size: 13px;
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  background: var(--color-surface);
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(51,102,153,.15);
}

textarea { resize: vertical; min-height: 80px; }

/* ── Botões ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-family: var(--font-base);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, box-shadow .15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
  box-shadow: 0 2px 8px rgba(51,102,153,.25);
}

.btn-primary:hover {
  background: var(--color-primary-dark);
  border-color: var(--color-primary-dark);
  box-shadow: 0 4px 14px rgba(51,102,153,.35);
  transform: translateY(-1px);
}

.btn-outline {
  background: transparent;
  color: var(--color-primary);
  border-color: var(--color-primary);
}

.btn-outline:hover {
  background: var(--color-primary-light);
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
  border-color: var(--color-danger);
}

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { padding: 6px; border-radius: var(--radius-sm); }

/* ── Título de página ── */
.page-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.page-title h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-primary);
}

/* ── Alerts / notificações ── */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  border: 1px solid transparent;
}

.alert-info    { background: var(--color-primary-light); color: var(--color-primary-dark); border-color: #c3d9ef; }
.alert-success { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.alert-warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.alert-danger  { background: #fef2f2; color: #991b1b; border-color: #fecaca; }

/* ── Login ── */
#login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--color-primary-light) 0%, var(--color-accent-soft) 100%);
}

.login-box {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 40px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.login-box img { height: 64px; margin-bottom: 20px; }
.login-box h1 { font-size: 18px; color: var(--color-primary); margin-bottom: 24px; }

/* ── Chips de estado ── */
.chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
}

.chip-active   { background: var(--color-success-soft); color: var(--color-success); }
.chip-inactive { background: var(--color-bg); color: var(--color-text-muted); }
.chip-pending  { background: var(--color-warning-soft); color: var(--color-warning); }

.tab-btn {
  background: none; border: none; padding: 10px 16px; font-size: 13px;
  cursor: pointer; color: var(--color-text-muted); border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab-btn:hover { color: var(--color-primary); }
.tab-active { color: var(--color-primary) !important; border-bottom-color: var(--color-primary) !important; font-weight: 600; }

/* ── SVG ícones inline ── */
.icon {
  width: 16px;
  height: 16px;
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

/* ── Responsivo — tablet ── */
@media (max-width: 700px) {
  #main { padding: 16px; }
  #topbar, #main-nav { padding-left: 14px; padding-right: 14px; }
}

/* ════════════════════════════════════════════════════════════
   DASHBOARD — Linen / editorial
   Cor = informação. Hierarquia por tipografia e espaço.
   ════════════════════════════════════════════════════════════ */
.dash { max-width: 1280px; margin: 0 auto; width: 100%; }

/* Cabeçalho editorial — sem caixa, sem gradiente */
.dash-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  padding-bottom: 18px; margin-bottom: 22px;
  border-bottom: 1px solid var(--color-border);
}
.dash-head h1 {
  font-size: 26px; font-weight: 700; letter-spacing: -.02em;
  color: var(--color-text); line-height: 1.1;
}
.dash-head .dash-date {
  font-size: 13px; color: var(--color-text-muted);
  text-transform: capitalize; margin-top: 4px;
}
.dash-head .dash-aside { font-size: 13px; color: var(--color-text-soft); text-align: right; }
.dash-head .dash-aside b { color: var(--color-text); font-weight: 700; }

/* Faixa de métricas — uma régua dividida, não 4 caixas soltas */
.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 22px;
}
@media (max-width: 820px) { .metrics { grid-template-columns: repeat(2, 1fr); } }

.metric {
  padding: 20px 22px;
  border-right: 1px solid var(--color-border);
  position: relative;
}
.metric:last-child { border-right: none; }
@media (max-width: 820px) {
  .metric:nth-child(2n) { border-right: none; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--color-border); }
}
.metric-label {
  font-size: 11px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase;
  color: var(--color-text-muted); margin-bottom: 12px;
  display: flex; align-items: center; gap: 6px;
}
.metric-label svg { width: 13px; height: 13px; opacity: .7; }
.metric-value {
  font-size: 30px; font-weight: 700; line-height: 1; letter-spacing: -.02em;
  color: var(--color-text); font-feature-settings: var(--tnum);
}
.metric-value .unit { font-size: 16px; font-weight: 600; color: var(--color-text-muted); margin-left: 3px; }
.metric-foot { margin-top: 10px; font-size: 12px; color: var(--color-text-muted); }
.metric-delta { font-weight: 600; font-feature-settings: var(--tnum); }
.metric-delta.up   { color: var(--color-success); }
.metric-delta.down { color: var(--color-danger); }
.metric-value.is-warn   { color: var(--color-warning); }
.metric-value.is-danger { color: var(--color-danger); }

/* Layout de conteúdo: principal + lateral */
.dash-grid {
  display: grid;
  grid-template-columns: minmax(0,1.7fr) minmax(280px,1fr);
  gap: 22px;
  align-items: start;
}
@media (max-width: 1000px) { .dash-grid { grid-template-columns: 1fr; } }
.dash-col { display: flex; flex-direction: column; gap: 22px; }

/* Cabeçalho de secção dentro de card */
.sec-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--color-border);
}
.sec-head h2 {
  font-size: 13px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
  color: var(--color-text-soft);
}
.sec-link {
  font-size: 12px; font-weight: 600; color: var(--color-primary);
  text-decoration: none; cursor: pointer;
}
.sec-link:hover { text-decoration: underline; }

/* Gráfico de barras — fino, editorial, baseline clara */
.chart { padding: 18px 20px 12px; }
.chart-bars {
  display: flex; align-items: flex-end; gap: 6px;
  height: 130px;
  border-bottom: 1px solid var(--color-border-strong);
}
.bar {
  flex: 1; min-width: 3px;
  background: var(--color-primary-light);
  border-radius: 3px 3px 0 0;
  position: relative;
  transition: background .15s;
  transform-origin: bottom;
  animation: growBar .55s var(--ease-out) backwards;
}
@keyframes growBar { from { transform: scaleY(0); } to { transform: scaleY(1); } }
.bar > i {
  position: absolute; inset: 0; top: auto; height: 100%;
  background: var(--color-primary); border-radius: 3px 3px 0 0;
  opacity: .85;
}
.bar.is-max > i { background: var(--color-accent); opacity: 1; }
.bar:hover > i { opacity: 1; }
.bar .tip {
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  background: var(--color-text); color: #fff; font-size: 11px; font-weight: 600;
  padding: 3px 8px; border-radius: 6px; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity .15s; margin-bottom: 8px;
  z-index: 3; font-feature-settings: var(--tnum);
}
.bar:hover .tip { opacity: 1; }
.chart-axis { display: flex; gap: 6px; padding-top: 8px; }
.chart-axis span { flex: 1; text-align: center; font-size: 10px; color: var(--color-text-faint); font-feature-settings: var(--tnum); }

/* Agenda do dia */
.agenda-row {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 20px;
  border-bottom: 1px solid var(--color-border);
  text-decoration: none; color: inherit;
  transition: background .12s;
}
.agenda-row:hover { background: var(--color-surface-sunk); }
.agenda-row:last-child { border-bottom: none; }
.agenda-time {
  flex-shrink: 0; width: 46px;
  font-weight: 700; font-size: 14px; color: var(--color-text);
  font-feature-settings: var(--tnum);
}
.agenda-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  background: var(--color-text-faint);
  box-shadow: 0 0 0 3px var(--color-bg);
}
.agenda-dot.done    { background: var(--color-success); }
.agenda-dot.pending { background: var(--color-warning); }
.agenda-body { flex: 1; min-width: 0; }
.agenda-name { font-weight: 600; font-size: 14px; color: var(--color-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agenda-meta { font-size: 12px; color: var(--color-text-muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Lista lateral compacta */
.mini-row {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 20px; border-bottom: 1px solid var(--color-border);
  font-size: 13px; text-decoration: none; color: inherit;
  transition: background .12s;
}
.mini-row:hover { background: var(--color-surface-sunk); }
.mini-row:last-child { border-bottom: none; }
.mini-date {
  flex-shrink: 0; width: 38px; text-align: center;
  border: 1px solid var(--color-border); border-radius: 7px;
  padding: 3px 0; line-height: 1.1;
}
.mini-date .d { font-size: 14px; font-weight: 700; color: var(--color-text); font-feature-settings: var(--tnum); }
.mini-date .m { font-size: 9px; font-weight: 600; text-transform: uppercase; color: var(--color-text-muted); letter-spacing: .04em; }
.mini-body { flex: 1; min-width: 0; }
.mini-name { font-weight: 600; color: var(--color-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-meta { font-size: 11px; color: var(--color-text-muted); }
.mini-val { font-weight: 700; font-size: 14px; white-space: nowrap; font-feature-settings: var(--tnum); color: var(--color-danger); }
.mini-rank {
  flex-shrink: 0; width: 20px; text-align: center;
  font-size: 12px; font-weight: 700; color: var(--color-text-faint);
  font-feature-settings: var(--tnum);
}

.empty-state {
  padding: 36px 20px; text-align: center; color: var(--color-text-muted); font-size: 13px;
}
.empty-state svg { opacity: .35; margin-bottom: 10px; }

/* ── Utilitários ── */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--color-text-muted); }
.text-danger { color: var(--color-danger); }
.text-success{ color: var(--color-success); }
.fw-bold     { font-weight: 700; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.w-full { width: 100%; }
.hidden { display: none; }
