/* =========================================================
   OdontoSys - Estilos principais (mobile-first, responsivo)
   ========================================================= */

:root {
  --azul: #2563eb;
  --azul-escuro: #1d4ed8;
  --azul-claro: #eff6ff;
  --verde: #16a34a;
  --vermelho: #dc2626;
  --amarelo: #f59e0b;
  --cinza-900: #111827;
  --cinza-700: #374151;
  --cinza-500: #6b7280;
  --cinza-300: #d1d5db;
  --cinza-100: #f3f4f6;
  --branco: #ffffff;
  --radius: 10px;
  --sombra: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --sidebar-w: 250px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--cinza-100);
  color: var(--cinza-900);
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--azul); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 12px; color: var(--cinza-900); }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }

/* ---------- Layout com sidebar ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--cinza-900);
  color: #e5e7eb;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  transition: transform 0.25s ease;
  z-index: 100;
}
.sidebar-brand {
  padding: 20px 18px;
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--branco);
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  gap: 8px;
}
.sidebar-brand .tooth-icon { font-size: 1.4rem; }
.sidebar nav { padding: 10px 0; }
.sidebar a.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  color: #cbd5e1;
  font-size: 0.92rem;
  border-left: 3px solid transparent;
}
.sidebar a.nav-link:hover { background: rgba(255,255,255,0.06); text-decoration: none; color: #fff; }
.sidebar a.nav-link.active {
  background: rgba(37,99,235,0.18);
  border-left-color: var(--azul);
  color: #fff;
  font-weight: 600;
}
.sidebar .nav-section-title {
  padding: 16px 20px 6px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
}

.content-area {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--branco);
  border-bottom: 1px solid var(--cinza-300);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--cinza-700);
}
.topbar .user-info { display: flex; align-items: center; gap: 12px; font-size: 0.9rem; }
.topbar .user-badge {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--azul); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.85rem;
}

.page-content { padding: 22px 24px; flex: 1; }

/* ---------- Cards ---------- */
.card {
  background: var(--branco);
  border-radius: var(--radius);
  box-shadow: var(--sombra);
  padding: 20px;
  margin-bottom: 20px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

.kpi-card {
  background: var(--branco);
  border-radius: var(--radius);
  box-shadow: var(--sombra);
  padding: 18px 20px;
  border-left: 4px solid var(--azul);
}
.kpi-card .kpi-value { font-size: 1.7rem; font-weight: 700; color: var(--cinza-900); }
.kpi-card .kpi-label { font-size: 0.82rem; color: var(--cinza-500); margin-top: 4px; }
.kpi-card.verde { border-left-color: var(--verde); }
.kpi-card.amarelo { border-left-color: var(--amarelo); }
.kpi-card.vermelho { border-left-color: var(--vermelho); }
.kpi-card.azul { border-left-color: var(--azul); }

/* ---------- Formulários ---------- */
.form-group { margin-bottom: 16px; }
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 200px; }
label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 0.85rem; color: var(--cinza-700); }
input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--cinza-300);
  border-radius: 8px;
  font-size: 0.92rem;
  font-family: inherit;
  background: var(--branco);
  color: var(--cinza-900);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--azul);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: 0.78rem; color: var(--cinza-500); margin-top: 4px; }
fieldset { border: 1px solid var(--cinza-300); border-radius: 8px; padding: 14px 16px; margin-bottom: 16px; }
legend { font-weight: 700; padding: 0 6px; font-size: 0.9rem; }
.checkbox-inline { display: flex; align-items: center; gap: 8px; }
.checkbox-inline input { width: auto; }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, opacity 0.15s ease;
}
.btn:hover { text-decoration: none; opacity: 0.92; }
.btn-primario { background: var(--azul); color: #fff; }
.btn-primario:hover { background: var(--azul-escuro); }
.btn-sucesso { background: var(--verde); color: #fff; }
.btn-perigo { background: var(--vermelho); color: #fff; }
.btn-secundario { background: var(--cinza-100); color: var(--cinza-700); border: 1px solid var(--cinza-300); }
.btn-sm { padding: 6px 12px; font-size: 0.78rem; }
.btn-icon { padding: 8px; }

/* ---------- Tabelas ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--cinza-100); white-space: nowrap; }
th { color: var(--cinza-500); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr:hover { background: var(--azul-claro); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #fff;
}

/* ---------- Alertas ---------- */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 0.9rem; }
.alert-sucesso { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-erro { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* ---------- Login ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1d4ed8, #1e293b);
  padding: 20px;
}
.login-box {
  background: var(--branco);
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
.login-box .brand { text-align: center; margin-bottom: 26px; }
.login-box .brand .icon { font-size: 2.6rem; }
.login-box .brand h1 { font-size: 1.35rem; margin: 6px 0 2px; }
.login-box .brand p { color: var(--cinza-500); font-size: 0.85rem; margin: 0; }
.login-box .btn { width: 100%; justify-content: center; padding: 12px; font-size: 0.95rem; }

/* ---------- Agenda ---------- */
.agenda-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }
.agenda-grid { display: grid; grid-template-columns: 70px repeat(var(--num-dentistas, 1), 1fr); gap: 1px; background: var(--cinza-300); border: 1px solid var(--cinza-300); border-radius: 8px; overflow: hidden; }
.agenda-grid .celula { background: var(--branco); padding: 6px; min-height: 46px; font-size: 0.78rem; position: relative; }
.agenda-grid .cabecalho { background: var(--cinza-900); color: #fff; font-weight: 700; text-align: center; padding: 10px 6px; font-size: 0.8rem; }
.agenda-grid .hora-label { background: var(--cinza-100); text-align: right; padding-right: 8px; font-size: 0.72rem; color: var(--cinza-500); }
.evento-agenda { border-radius: 6px; padding: 4px 6px; font-size: 0.72rem; color: #fff; margin-bottom: 2px; cursor: pointer; line-height: 1.3; }

.legenda-status { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.78rem; margin-top: 10px; }
.legenda-status span { display: flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ---------- Odontograma ---------- */
.odontograma-arcada { display: flex; justify-content: center; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; }
.dente-btn {
  width: 34px; height: 34px;
  border: 2px solid var(--cinza-300);
  border-radius: 6px;
  background: var(--branco);
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.dente-btn.higido { border-color: var(--cinza-300); }
.dente-btn.cariado { border-color: var(--vermelho); background: #fee2e2; }
.dente-btn.restaurado { border-color: var(--azul); background: #dbeafe; }
.dente-btn.ausente { border-color: var(--cinza-500); background: var(--cinza-100); opacity: 0.5; }
.dente-btn.canal_tratado { border-color: var(--amarelo); background: #fef3c7; }
.dente-btn.extracao_indicada { border-color: var(--vermelho); background: #fecaca; }

/* ---------- Modal genérico ---------- */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.aberto { display: flex; }
.modal-box {
  background: var(--branco);
  border-radius: 14px;
  max-width: 980px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.modal-box-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--cinza-100);
  position: sticky; top: 0; background: var(--branco); z-index: 2;
}
.modal-box-header h3 { margin: 0; }
.modal-box-fechar {
  background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--cinza-500); line-height: 1;
  padding: 4px 8px;
}
.modal-box-body { padding: 18px 20px; }
.modal-box-footer {
  padding: 14px 20px; border-top: 1px solid var(--cinza-100);
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
  position: sticky; bottom: 0; background: var(--branco);
}

/* ---------- Seletor de dente + face (formato cruz: V / M-O-D / L) ---------- */
.seletor-arcada-titulo { text-align: center; font-size: 0.78rem; color: var(--cinza-500); text-transform: uppercase; letter-spacing: 0.04em; margin: 14px 0 8px; }

/* Uma arcada = uma única linha; se não couber na tela, rola horizontalmente
   em vez de quebrar para uma segunda linha (flex-shrink:0 nos filhos evita
   que o navegador espreme os dentes para caber). */
.seletor-arcada-scroll { overflow-x: auto; padding-bottom: 6px; }
.seletor-arcada { display: flex; flex-wrap: nowrap; gap: 4px; width: max-content; margin: 0 auto; }

.seletor-dente-unidade { display: flex; flex-direction: column; align-items: center; gap: 1px; flex-shrink: 0; width: 42px; }
.seletor-dente-numero { font-size: 0.68rem; font-weight: 700; color: var(--cinza-700); margin-top: 2px; }

.seletor-tooth-icon { width: 30px; height: 24px; display: block; }
.seletor-tooth-icon.invertido { transform: scaleY(-1); }
.seletor-tooth-icon svg { width: 100%; height: 100%; display: block; }

.seletor-cruz {
  display: grid;
  grid-template-columns: repeat(3, 13px);
  grid-template-rows: repeat(3, 13px);
  gap: 1.5px;
  margin: 2px 0;
}
.seletor-face {
  width: 13px; height: 13px;
  border: 1px solid var(--cinza-300);
  border-radius: 2.5px;
  background: var(--branco);
  cursor: pointer;
  padding: 0;
}
.seletor-face:hover { border-color: var(--azul); }
.seletor-face.marcada { background: #f59e0b; border-color: #d97706; }
.seletor-face.vazio { visibility: hidden; }
.seletor-face-v { grid-column: 2; grid-row: 1; }
.seletor-face-m { grid-column: 1; grid-row: 2; }
.seletor-face-o { grid-column: 2; grid-row: 2; }
.seletor-face-d { grid-column: 3; grid-row: 2; }
.seletor-face-l { grid-column: 2; grid-row: 3; }

.seletor-legenda { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.78rem; color: var(--cinza-500); margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--cinza-100); }
.seletor-legenda span { display: flex; align-items: center; gap: 5px; }
.seletor-legenda .amostra { width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--cinza-300); display: inline-block; }
.seletor-legenda .amostra.marcada { background: #f59e0b; border-color: #d97706; }

.seletor-resumo-selecao { background: var(--azul-claro); border-radius: 8px; padding: 10px 14px; font-size: 0.85rem; margin-bottom: 6px; min-height: 20px; }


/* ---------- Tabs ---------- */
.tabs { display: flex; border-bottom: 2px solid var(--cinza-300); margin-bottom: 18px; overflow-x: auto; }
.tab-link { padding: 10px 18px; font-size: 0.88rem; font-weight: 600; color: var(--cinza-500); border-bottom: 2px solid transparent; margin-bottom: -2px; white-space: nowrap; cursor: pointer; }
.tab-link.active { color: var(--azul); border-bottom-color: var(--azul); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ---------- Utilitários ---------- */
.text-muted { color: var(--cinza-500); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.w-full { width: 100%; }

/* ---------- Responsivo ---------- */
@media (max-width: 960px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.aberta { transform: translateX(0); }
  .content-area { margin-left: 0; }
  .topbar .menu-toggle { display: block; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .page-content { padding: 16px; }
  .form-row { flex-direction: column; }
  table { font-size: 0.8rem; }
  .sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 90;
  }
  .sidebar-overlay.ativa { display: block; }
}

@media print {
  .sidebar, .topbar, .btn, .no-print { display: none !important; }
  .content-area { margin-left: 0 !important; }
  body { background: #fff; }
}
