:root {
  --primary: #0e7490;
  --primary-dark: #0b5567;
  --primary-light: #e0f2f6;
  --accent: #f0f9fb;
  --verde: #15803d;
  --verde-bg: #ecfdf3;
  --vermelho: #be123c;
  --vermelho-bg: #fef1f2;
  --bg: #f1f5f7;
  --borda: #dde5ea;
  --texto: #1e293b;
  --texto-suave: #64748b;
  --sombra: 0 1px 2px rgba(15, 45, 60, 0.06), 0 4px 12px rgba(15, 45, 60, 0.06);
  --raio: 12px;
}

* { box-sizing: border-box; }

body {
  font-family: "Segoe UI", -apple-system, "Helvetica Neue", Arial, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--texto);
  -webkit-font-smoothing: antialiased;
}

/* ===================== HEADER / NAV ===================== */

.app-header {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: white;
  padding: 20px 28px 0;
}

.app-header-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.app-header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.app-header .subtitulo {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.75);
}

.tabs {
  display: flex;
  gap: 4px;
}

.tab-btn {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.75);
  padding: 10px 18px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s, color 0.15s;
}

.tab-btn:hover { background: rgba(255,255,255,0.1); color: white; }

.tab-btn.active {
  background: var(--bg);
  color: var(--primary-dark);
}

.tab-icon { font-size: 1rem; }

main {
  padding: 24px 28px 48px;
  max-width: 1100px;
  margin: 0 auto;
}

.tab-content { display: none; }
.tab-content.active { display: block; animation: fade-in 0.15s ease-out; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(2px); }
  to { opacity: 1; transform: translateY(0); }
}

h2 {
  color: var(--texto);
  font-size: 1.05rem;
  font-weight: 700;
  margin: 28px 0 12px;
}
h2:first-child { margin-top: 0; }

h3 { color: var(--primary-dark); margin-top: 0; font-size: 0.95rem; }

/* ===================== DASHBOARD (resumo rápido) ===================== */

.dashboard {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.dash-card {
  background: white;
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  padding: 14px 16px;
  box-shadow: var(--sombra);
}

.dash-card .dash-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--texto-suave);
  font-weight: 700;
  margin-bottom: 6px;
}

.dash-card .dash-valor {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--texto);
}

.dash-card.positivo .dash-valor { color: var(--verde); }
.dash-card.negativo .dash-valor { color: var(--vermelho); }

/* ===================== CARDS / FORM ===================== */

.card {
  background: white;
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  padding: 22px;
  margin-bottom: 24px;
  box-shadow: var(--sombra);
}

.editing-banner {
  background: var(--primary-light);
  color: var(--primary-dark);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 16px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 14px;
  align-items: flex-end;
}

.row label {
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
  font-weight: 600;
  color: #475569;
  gap: 5px;
  flex: 1 1 160px;
}

.row label.full { flex: 1 1 100%; }

.checkbox-label {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
  font-weight: 500 !important;
}

input, textarea, select {
  font-family: inherit;
  font-size: 0.92rem;
  padding: 9px 11px;
  border: 1px solid var(--borda);
  border-radius: 7px;
  background: white;
  color: var(--texto);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

textarea.campo-invalido, input.campo-invalido {
  border-color: var(--vermelho);
  box-shadow: 0 0 0 3px var(--vermelho-bg);
}

.hint {
  color: var(--vermelho);
  font-weight: 600;
  font-size: 0.75rem;
}

.erro-inline {
  color: var(--vermelho);
  background: var(--vermelho-bg);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.8rem;
  font-weight: 600;
  margin-top: -6px;
  margin-bottom: 12px;
  display: none;
}
.erro-inline.visivel { display: block; }

.actions { justify-content: flex-start; }

.btn-primary, .btn-secondary {
  padding: 10px 22px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background 0.15s, transform 0.05s;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
  background: white;
  color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-secondary:hover { background: var(--primary-light); }

.preview {
  background: var(--accent);
  border: 1px dashed var(--primary);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--primary-dark);
}

/* ===================== TABELAS ===================== */

.table-wrap {
  overflow-x: auto;
  border-radius: var(--raio);
  border: 1px solid var(--borda);
  box-shadow: var(--sombra);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  font-size: 0.87rem;
}

th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--borda);
}

th {
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  font-weight: 700;
  white-space: nowrap;
}

tbody tr:hover { background: #f8fafb; }
tbody tr:last-child td { border-bottom: none; }

td.saldo-positivo { color: var(--verde); font-weight: 700; }
td.saldo-negativo { color: var(--vermelho); font-weight: 700; }

.linha-vazia td {
  text-align: center;
  color: var(--texto-suave);
  font-style: italic;
  padding: 24px 12px;
}

button.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.82rem;
  padding: 4px 6px;
  margin-right: 4px;
  border-radius: 5px;
}
button.link-btn:hover { background: var(--primary-light); }
button.link-btn.excluir { color: var(--vermelho); }
button.link-btn.excluir:hover { background: var(--vermelho-bg); }

.resumo-table td:first-child { font-weight: 600; width: 70%; }
.resumo-table td:last-child { text-align: right; font-weight: 700; }

/* ===================== RELATÓRIO / IMPRESSÃO ===================== */

#relatorio-imprimivel {
  background: white;
  padding: 28px;
  border-radius: var(--raio);
  border: 1px solid var(--borda);
  box-shadow: var(--sombra);
}

.print-header { margin-bottom: 20px; }
.print-header-top {
  display: flex;
  justify-content: space-between;
  border-bottom: 2px solid var(--primary-dark);
  padding-bottom: 12px;
  margin-bottom: 4px;
}
.clinica-info strong { font-size: 1.15rem; color: var(--primary-dark); }
.clinica-info div { color: var(--texto-suave); font-size: 0.85rem; margin-top: 2px; }
.periodo-info { text-align: right; font-size: 0.88rem; }

.assinaturas {
  display: flex;
  justify-content: space-between;
  margin-top: 64px;
  gap: 40px;
}
.assinatura {
  flex: 1;
  text-align: center;
  font-size: 0.85rem;
  color: var(--texto-suave);
}
.linha-assinatura {
  border-top: 1px solid #333;
  margin-bottom: 6px;
  padding-top: 4px;
}

/* ===================== RESPONSIVO ===================== */

@media (max-width: 720px) {
  .app-header { padding: 16px 16px 0; }
  main { padding: 16px 16px 40px; }
  .dashboard { grid-template-columns: repeat(2, 1fr); }
  .tabs { overflow-x: auto; }
  .tab-btn { padding: 8px 12px; font-size: 0.85rem; white-space: nowrap; }
  .row { flex-direction: column; align-items: stretch; }
  .row label { flex: 1 1 auto; }
  .print-header-top { flex-direction: column; gap: 8px; }
  .periodo-info { text-align: left; }
}

/* ===================== PRINT ===================== */
@media print {
  .no-print { display: none !important; }
  body { background: white; }
  main { padding: 0; max-width: 100%; }
  #relatorio-imprimivel { border: none; padding: 0; box-shadow: none; }
  .tab-content { display: none !important; }
  #tab-relatorio { display: block !important; }
  .table-wrap { border: none; box-shadow: none; }
  table { font-size: 11pt; }
  .assinaturas { margin-top: 80px; }
}
