/* ============================================================
   Variables
   ============================================================ */
:root {
  --sidebar-width: 240px;
  --topbar-height: 56px;
  --dark-bg:        #0f1b1a;
  --dark-surface:   #16302c;
  --dark-border:    #234943;
  --dark-text:      #cfe8e3;
  --dark-muted:     #7fa89f;
  --dark-sidebar:   #0c1615;
}

/* ============================================================
   Override color primario de Bootstrap → teal clínico Nexus
   ============================================================ */
:root {
  --bs-primary:           #0d9488;
  --bs-primary-rgb:       13, 148, 136;
  --bs-link-color:        #0d9488;
  --bs-link-hover-color:  #0f766e;
}

/* ============================================================
   Base
   ============================================================ */
body {
  font-size: 0.9rem;
}

[data-bs-theme="dark"] body {
  background-color: var(--dark-bg);
  --bs-body-bg:       var(--dark-bg);
  --bs-body-color:    var(--dark-text);
  --bs-border-color:  var(--dark-border);
  --bs-secondary-bg:  var(--dark-surface);
  --bs-tertiary-bg:   var(--dark-surface);
}

[data-bs-theme="light"] {
  --bs-body-bg:      #f1f7f6;
  --bs-secondary-bg: #e6f1ef;
  --bs-tertiary-bg:  #e6f1ef;
}

[data-bs-theme="light"] body {
  background-color: #f1f7f6;
}

[data-bs-theme="light"] .card {
  background-color: #fff;
}

[data-bs-theme="light"] .card-header {
  background-color: #f8fbfa !important;
}

/* ============================================================
   Topbar
   ============================================================ */
#topbar {
  height: var(--topbar-height);
  z-index: 1030;
}

/* ============================================================
   Sidebar
   ============================================================ */
#sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  width: var(--sidebar-width);
  height: calc(100vh - var(--topbar-height));
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 1020;
  padding: 1rem 0.75rem;
  transition: transform 0.25s ease;
  flex-shrink: 0;
  border-right: 1px solid transparent;
}

[data-bs-theme="dark"] #sidebar {
  background-color: var(--dark-sidebar);
  border-right-color: var(--dark-border);
}

[data-bs-theme="light"] #sidebar {
  background-color: #eef6f4;
  border-right-color: #d7e8e4;
}

#sidebar.hidden {
  transform: translateX(calc(-1 * var(--sidebar-width)));
}

.sidebar-section-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 0 0.5rem;
  margin-bottom: 0.25rem;
  margin-top: 0.5rem;
}

[data-bs-theme="dark"] .sidebar-section-label  { color: var(--dark-muted); }
[data-bs-theme="light"] .sidebar-section-label { color: #5c7a75; }

.sidebar-section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 0.25rem 0.5rem;
  margin-bottom: 0.1rem;
  border-radius: 0.3rem;
  cursor: pointer;
  user-select: none;
  transition: color 0.15s, background 0.15s;
}

[data-bs-theme="dark"] .sidebar-section-toggle         { color: var(--dark-muted); }
[data-bs-theme="dark"] .sidebar-section-toggle:hover   { color: var(--dark-text); background: rgba(255,255,255,.05); }
[data-bs-theme="light"] .sidebar-section-toggle        { color: #5c7a75; }
[data-bs-theme="light"] .sidebar-section-toggle:hover  { color: #2f4d48; background: rgba(0,0,0,.05); }

.sidebar-chevron {
  font-size: 0.65rem;
  transition: transform 0.2s ease;
}

.sidebar-section-body {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.25s ease;
}

.sidebar-section-body.open {
  max-height: 600px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.4rem;
  text-decoration: none;
  font-size: 0.875rem;
  transition: background 0.15s, color 0.15s;
}

.sidebar-link i {
  font-size: 1rem;
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
}

[data-bs-theme="dark"] .sidebar-link        { color: #8fb3ac; }
[data-bs-theme="dark"] .sidebar-link:hover  { background-color: rgba(255,255,255,.07); color: var(--dark-text); }
[data-bs-theme="light"] .sidebar-link       { color: #3f5d58; }
[data-bs-theme="light"] .sidebar-link:hover { background-color: rgba(0,0,0,.06); color: #17332e; }

.sidebar-link.active {
  background-color: var(--bs-primary);
  color: #fff !important;
}

/* ============================================================
   Main content
   ============================================================ */
#main-content {
  margin-top: var(--topbar-height);
  margin-left: var(--sidebar-width);
  padding: 1.5rem;
  min-height: calc(100vh - var(--topbar-height));
  flex-grow: 1;
  transition: margin-left 0.25s ease;
}

#main-content.expanded {
  margin-left: 0;
}

/* ============================================================
   Logos
   ============================================================ */
.login-logo {
  width: 240px;
  height: auto;
  display: block;
  margin: 0 auto;
}

.navbar-logo {
  height: 32px;
  width: auto;
}

/* ============================================================
   Auth page
   ============================================================ */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #0d9488 0%, #0f766e 55%, #134e4a 100%);
}

[data-bs-theme="dark"] .auth-page {
  background: linear-gradient(160deg, #0b1f1c 0%, #0f2723 55%, var(--dark-bg) 100%);
}

.auth-box {
  width: 100%;
  max-width: 380px;
  padding: 1rem;
}

/* ============================================================
   Stat cards (dashboard)
   ============================================================ */
.stat-card-link {
  display: block;
  height: 100%;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  border-radius: 0.6rem;
  padding: 1.1rem 1.2rem;
  border-left: 4px solid;
  height: 100%;
  transition: box-shadow .15s, transform .15s;
}

[data-bs-theme="dark"] .stat-card {
  background: var(--dark-surface);
  box-shadow: 0 1px 6px rgba(0,0,0,.35);
}

[data-bs-theme="light"] .stat-card {
  background: #fff;
  box-shadow: 0 1px 6px rgba(15,118,110,.12);
}

.stat-card:hover {
  transform: translateY(-2px);
}

[data-bs-theme="dark"] .stat-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.5); }
[data-bs-theme="light"] .stat-card:hover { box-shadow: 0 4px 16px rgba(15,118,110,.18); }

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.stat-body  { flex-grow: 1; }

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.1;
}

[data-bs-theme="dark"] .stat-value { color: var(--dark-text); }

.stat-label {
  font-size: 0.78rem;
  color: #6c757d;
  margin-top: 0.15rem;
}

/* ============================================================
   Tables
   ============================================================ */
.table th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6c757d;
  font-weight: 600;
}

/* ============================================================
   Cards generales
   ============================================================ */
.card {
  border-radius: 0.6rem;
}

[data-bs-theme="dark"] .card {
  background-color: var(--dark-surface);
  border-color: var(--dark-border);
}

/* ============================================================
   Badges
   ============================================================ */
.badge {
  font-weight: 500;
}

.badge-dot {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  margin-right: 0.35rem;
  flex-shrink: 0;
}

/* ============================================================
   Calendario — vista mensual
   ============================================================ */
.calendario-mes table {
  table-layout: fixed;
  width: 100%;
}

.calendario-mes th {
  text-align: center;
  padding: 0.5rem 0.25rem;
}

.calendario-mes td {
  vertical-align: top;
  height: 108px;
  padding: 0.35rem;
  border: 1px solid var(--bs-border-color);
}

.calendario-mes td.dia-vacio {
  background-color: var(--bs-tertiary-bg);
}

.calendario-mes .celda-dia {
  display: flex;
  flex-direction: column;
  height: 100%;
  text-decoration: none;
  color: inherit;
  border-radius: 0.35rem;
  padding: 0.3rem;
  transition: background 0.15s;
}

.calendario-mes .celda-dia:hover {
  background-color: rgba(var(--bs-primary-rgb), 0.08);
}

.calendario-mes .celda-dia.hoy {
  background-color: rgba(var(--bs-primary-rgb), 0.12);
}

.calendario-mes .numero-dia {
  font-weight: 700;
  font-size: 0.85rem;
  margin-bottom: 0.25rem;
}

.calendario-mes .numero-dia.hoy {
  color: var(--bs-primary);
}

.calendario-mes .reserva-mini {
  font-size: 0.68rem;
  padding: 0.05rem 0.3rem;
  border-radius: 0.25rem;
  margin-bottom: 0.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #fff;
}

.calendario-mes .reserva-mas {
  font-size: 0.68rem;
  color: #6c757d;
}

/* ============================================================
   Calendario — vista de día (grilla de horas x consultorios)
   ============================================================ */
.grilla-dia {
  width: 100%;
  border-collapse: collapse;
}

.grilla-dia th, .grilla-dia td {
  border: 1px solid var(--bs-border-color);
}

.grilla-dia th {
  text-align: center;
  padding: 0.6rem 0.4rem;
  font-size: 0.8rem;
}

.grilla-dia td.hora-label {
  width: 70px;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: #6c757d;
  white-space: nowrap;
  vertical-align: middle;
}

.grilla-dia td.celda-libre {
  cursor: pointer;
  height: 52px;
  transition: background 0.15s;
}

.grilla-dia td.celda-libre:hover {
  background-color: rgba(var(--bs-primary-rgb), 0.1);
}

.grilla-dia td.celda-libre:hover::after {
  content: '+ Reservar';
  display: block;
  text-align: center;
  font-size: 0.72rem;
  color: var(--bs-primary);
  font-weight: 600;
}

.grilla-dia td.celda-ocupada {
  padding: 0.5rem;
  vertical-align: top;
  color: #fff;
}

.grilla-dia .reserva-cliente {
  font-weight: 700;
  font-size: 0.82rem;
}

.grilla-dia .reserva-horario {
  font-size: 0.72rem;
  opacity: 0.9;
}

/* ============================================================
   Inventario de horas
   ============================================================ */
.saldo-horas {
  font-weight: 700;
}

.saldo-horas.saldo-bajo { color: #dc3545; }
.saldo-horas.saldo-ok   { color: #198754; }

/* ============================================================
   Autofill del browser — dark only
   ============================================================ */
[data-bs-theme="dark"] input:-webkit-autofill,
[data-bs-theme="dark"] input:-webkit-autofill:hover,
[data-bs-theme="dark"] input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0px 1000px var(--dark-surface) inset !important;
  -webkit-text-fill-color: var(--dark-text) !important;
  caret-color: var(--dark-text);
  transition: background-color 5000s ease-in-out 0s;
}

/* ============================================================
   DataTables — layout y temas
   ============================================================ */
div.dt-container .dt-layout-row:first-child {
  padding: 0.75rem 1rem 0.5rem;
  align-items: center;
}

div.dt-container .dt-layout-row:last-child {
  padding: 0.6rem 1rem 0.75rem;
  align-items: center;
}

[data-bs-theme="dark"] div.dt-container .dt-layout-row:last-child {
  border-top: 1px solid var(--dark-border);
}

div.dt-container select,
div.dt-container input[type="search"] {
  border-radius: 0.375rem;
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
}

[data-bs-theme="dark"] div.dt-container select,
[data-bs-theme="dark"] div.dt-container input[type="search"] {
  background-color: var(--dark-surface) !important;
  border-color: var(--dark-border) !important;
  color: var(--dark-text) !important;
}

div.dt-container label,
div.dt-container .dt-info {
  font-size: 0.82rem;
}

[data-bs-theme="dark"] div.dt-container label,
[data-bs-theme="dark"] div.dt-container .dt-info {
  color: var(--dark-muted);
}

div.dt-container .dt-paging nav button {
  border-radius: 0.375rem !important;
  padding: 0.2rem 0.55rem;
  margin: 0 1px;
  font-size: 0.82rem;
}

[data-bs-theme="dark"] div.dt-container .dt-paging nav button {
  color: var(--dark-text) !important;
  background: transparent !important;
  border: 1px solid var(--dark-border) !important;
}

div.dt-container .dt-paging nav button.current,
div.dt-container .dt-paging nav button:hover:not(:disabled) {
  background: var(--bs-primary) !important;
  border-color: var(--bs-primary) !important;
  color: #fff !important;
}

div.dt-container .dt-paging nav button:disabled {
  opacity: .35;
}

/* ============================================================
   Select2 — dark theme override
   ============================================================ */
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection {
  background-color: var(--dark-surface) !important;
  border-color: var(--dark-border) !important;
  color: var(--dark-text) !important;
}
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered {
  color: var(--dark-text) !important;
}
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-dropdown {
  background-color: var(--dark-surface) !important;
  border-color: var(--dark-border) !important;
  color: var(--dark-text) !important;
}
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-search__field {
  background-color: var(--dark-bg) !important;
  border-color: var(--dark-border) !important;
  color: var(--dark-text) !important;
}
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-results__option {
  color: var(--dark-text) !important;
}
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-results__option--selected {
  background-color: rgba(var(--bs-primary-rgb),.2) !important;
}

.select2-container--bootstrap-5 .select2-results__option--highlighted {
  background-color: var(--bs-primary) !important;
  color: #fff !important;
}

/* ============================================================
   Sidebar overlay backdrop (mobile)
   ============================================================ */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1015;
  cursor: pointer;
}
#sidebar-overlay.show { display: block; }

/* ============================================================
   Responsive: mobile layout
   ============================================================ */
@media (max-width: 767.98px) {
  #sidebar {
    transform: translateX(calc(-1 * var(--sidebar-width)));
    z-index: 1020;
  }
  #sidebar.show {
    transform: translateX(0);
  }
  #main-content {
    margin-left: 0;
    padding: 0.875rem 0.75rem;
  }

  h4.fw-bold { font-size: 1.05rem; }

  .btn { min-height: 38px; }
  .btn-sm { min-height: 34px; min-width: 34px; }

  .stat-card { padding: 0.7rem 0.85rem; gap: 0.65rem; }
  .stat-icon { width: 38px; height: 38px; font-size: 1.1rem; }
  .stat-value { font-size: 1.1rem; }
  .stat-label { font-size: 0.72rem; }

  .card-body.p-4 { padding: 1rem !important; }

  #main-content .d-flex.justify-content-between.mb-4 {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 0.75rem;
  }

  .calendario-mes td { height: 72px; }
  .grilla-dia { font-size: 0.78rem; }
}
