:root {
  --bg: #f4f7f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --primary: #0e7490;
  --primary-hover: #0b5d74;
  --primary-soft: #e6f6f8;
  --accent: #0ea5a4;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --success: #059669;
  --success-bg: #ecfdf5;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --info: #0284c7;
  --info-bg: #f0f9ff;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.07);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

main.container {
  flex: 1;
  width: 100%;
}

.app-footer {
  margin-top: auto;
  padding: 12px 24px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

a {
  color: var(--primary);
  text-decoration: none;
}

/* Top Navigation Bar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: var(--shadow-sm);
}

.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 24px;
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
}

.brand-logo-img {
  width: 38px;
  height: 38px;
  object-fit: contain;
  display: block;
}

.login-logo-img {
  width: 210px;
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto 10px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: -0.5px;
}

.brand-sub {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  display: block;
  line-height: 1.1;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-link {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.92rem;
  transition: background 0.15s, color 0.15s;
}

.nav-link:hover, .nav-link.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
}

.role-badge {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 999px;
}

.role-medico {
  background: var(--primary-soft);
  color: var(--primary);
}

.role-secretaria {
  background: var(--info-bg);
  color: var(--info);
}

/* Main Container */
.container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 20px 22px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.card-title {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 600;
  color: var(--text);
}

.card-subtitle {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover {
  background: var(--surface-alt);
}

.btn-soft {
  background: var(--primary-soft);
  color: var(--primary);
}
.btn-soft:hover {
  background: #d4eff3;
}

.btn-whatsapp {
  background: #16a34a;
  color: #fff;
}
.btn-whatsapp:hover {
  background: #15803d;
}

.btn-danger-soft {
  background: var(--danger-bg);
  color: var(--danger);
}
.btn-danger-soft:hover {
  background: #fee2e2;
}

.btn-sm {
  padding: 6px 11px;
  font-size: 0.82rem;
}

.btn-lg {
  padding: 12px 22px;
  font-size: 0.98rem;
}

/* Forms */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 5px;
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14, 116, 144, 0.12);
}

textarea.form-control {
  resize: vertical;
  min-height: 86px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.grid-dashboard {
  display: grid;
  grid-template-columns: 1.45fr 1fr;
  gap: 20px;
  align-items: start;
}

/* Search Box */
.search-wrapper {
  position: relative;
}

.search-input {
  width: 100%;
  padding: 12px 16px 12px 42px;
  font-size: 0.98rem;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(14, 116, 144, 0.12);
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 30;
  max-height: 340px;
  overflow-y: auto;
  display: none;
}

.search-results.open {
  display: block;
}

.search-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  transition: background 0.12s;
}

.search-item:last-child {
  border-bottom: none;
}

.search-item:hover {
  background: var(--primary-soft);
}

/* Turnos list */
.turno-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  background: var(--surface);
  transition: border-color 0.15s;
}

.turno-row:hover {
  border-color: var(--border-strong);
}

.turno-time {
  font-weight: 700;
  font-size: 0.98rem;
  color: var(--primary);
  min-width: 56px;
}

.turno-info {
  flex: 1;
  min-width: 0;
}

.turno-name {
  font-weight: 600;
  color: var(--text);
  display: block;
}

.turno-meta {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.turno-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Status Pills */
.status-pill {
  border: none;
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.status-pendiente {
  background: var(--warning-bg);
  color: var(--warning);
}
.status-en_sala {
  background: var(--info-bg);
  color: var(--info);
}
.status-atendido {
  background: var(--success-bg);
  color: var(--success);
}

/* Alert Banner (Alertas Médicas) */
.alert-medical {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-left: 5px solid #ea580c;
  border-radius: var(--radius-md);
  padding: 14px 18px;
  margin-bottom: 20px;
  color: #9a3412;
}

.alert-medical.has-alert {
  background: #fef2f2;
  border-color: #fecaca;
  border-left-color: #dc2626;
  color: #991b1b;
}

.alert-medical-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}

.alert-medical-title {
  font-weight: 700;
  font-size: 0.88rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Patient Header */
.patient-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
}

.patient-avatar {
  width: 54px;
  height: 54px;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: 700;
  flex-shrink: 0;
}

.patient-meta-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-top: 6px;
  font-size: 0.88rem;
  color: var(--text-muted);
}

/* Timeline / Consultas */
.timeline {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.consulta-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
}

.consulta-summary {
  list-style: none;
  padding: 15px 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  transition: background 0.15s;
}

.consulta-summary::-webkit-details-marker {
  display: none;
}

.consulta-summary:hover {
  background: var(--surface-alt);
}

.consulta-body {
  padding: 0 18px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
}

.consulta-section {
  margin-top: 14px;
}

.consulta-section-label {
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
  margin-bottom: 4px;
}

.consulta-text {
  white-space: pre-wrap;
  font-size: 0.92rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

/* Specialty Module Container */
.specialty-box {
  background: #f8fbfc;
  border: 1px solid #cfe6eb;
  border-radius: var(--radius-md);
  padding: 18px;
  margin: 18px 0;
}

.specialty-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.specialty-badge {
  background: var(--primary);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
}

/* Odontograma Avanzado (5 caras + tratamientos + adulto/niño) */
.odonto-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.odonto-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.odonto-tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.12s ease;
}

.odonto-tool-btn:hover {
  border-color: var(--primary);
}

.odonto-tool-btn.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
  box-shadow: 0 0 0 2px rgba(14, 116, 144, 0.14);
}

.odonto-mode-switch {
  display: inline-flex;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.odonto-mode-btn {
  border: none;
  background: transparent;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
}

.odonto-mode-btn.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.odonto-inherited-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 12px;
  margin-bottom: 10px;
  background: var(--info-bg);
  border: 1px solid #bae6fd;
  border-radius: var(--radius-sm);
  color: #0369a1;
  font-size: 0.8rem;
  font-weight: 500;
}

.odontograma-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid var(--border-strong);
  display: inline-block;
}

.odontograma-section-label {
  text-align: center;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 6px 0 2px;
}

.odontograma-arch {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 8px;
  overflow-x: auto;
  padding: 4px 2px;
}

.odontograma-quadrant {
  display: flex;
  gap: 4px;
}

.odontograma-divider {
  width: 2px;
  background: var(--border-strong);
  align-self: stretch;
  margin: 0 2px;
}

.tooth-unit {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 2px;
  user-select: none;
}

.tooth-num {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  line-height: 1;
}

.tooth-svg {
  width: 34px;
  height: 34px;
  overflow: visible;
}

.tooth-unit.interactive .tooth-face {
  cursor: pointer;
}

.tooth-unit.interactive .tooth-face:hover {
  filter: brightness(0.92);
}

.tooth-face {
  fill: #ffffff;
  stroke: #94a3b8;
  stroke-width: 1.2;
  transition: fill 0.12s ease;
}

.tooth-face[data-face-state="caries"] {
  fill: #ef4444;
  stroke: #b91c1c;
}

.tooth-face[data-face-state="arreglo"] {
  fill: #3b82f6;
  stroke: #1d4ed8;
}

/* Estados de pieza completa */
.tooth-unit[data-piece-state="ausente"] .tooth-face {
  fill: #e2e8f0;
  stroke: #94a3b8;
}

.tooth-overlay-ausente,
.tooth-overlay-corona,
.tooth-overlay-conducto,
.tooth-overlay-implante {
  display: none;
  pointer-events: none;
}

.tooth-unit[data-piece-state="ausente"] .tooth-overlay-ausente {
  display: block;
}

.tooth-unit[data-piece-state="corona"] .tooth-overlay-corona {
  display: block;
}

.tooth-unit[data-piece-state="conducto"] .tooth-overlay-conducto {
  display: block;
}

.tooth-unit[data-piece-state="implante"] .tooth-overlay-implante {
  display: block;
}

/* Oftalmología table */
.optics-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}

.optics-table th, .optics-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 0.86rem;
}

.optics-table th {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

/* Otorrino rows */
.orl-row {
  display: grid;
  grid-template-columns: 185px 1fr;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.orl-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

/* Attachments */
.attachments-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 0.84rem;
  color: var(--text);
}

.attachment-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 22px 24px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-close {
  border: none;
  background: transparent;
  font-size: 1.4rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}

/* Login Page */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(150deg, #e6f6f8 0%, #f4f7f9 55%, #eef2f6 100%);
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 34px 30px;
}

.login-brand {
  text-align: center;
  margin-bottom: 24px;
}

.login-brand .brand-logo-img {
  width: 38px;
  height: 38px;
  object-fit: contain;
  display: block;
}

.login-logo-img {
  width: 210px;
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto 10px;
}

.brand-mark {
  width: 50px;
  height: 50px;
  font-size: 1.25rem;
  margin: 0 auto 12px;
}

.login-brand h1 {
  margin: 0;
  font-size: 1.35rem;
  color: var(--text);
}

.login-brand p {
  margin: 4px 0 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}

/* Flash & Toast */
.flash-banner {
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.9rem;
  font-weight: 500;
}

.flash-success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid #a7f3d0;
}

.flash-error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #fecaca;
}

.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  background: var(--text);
  color: #fff;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  z-index: 200;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* Tabs in Config */
.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.tab-btn {
  padding: 10px 16px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2.5px solid transparent;
  margin-bottom: -1px;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th, .data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 0.9rem;
}

.data-table th {
  font-size: 0.8rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.empty-state {
  text-align: center;
  padding: 28px 16px;
  color: var(--text-muted);
  font-size: 0.92rem;
}

@media (max-width: 900px) {
  .grid-dashboard, .grid-2, .grid-3 {
    grid-template-columns: 1fr;
  }
  .orl-row {
    grid-template-columns: 1fr;
  }
}
