/* ==========================================================================
   ConsultorioPlus - Unified Modern App Shell & Theme System
   Complete Light & Dark Mode Clinical Styling
   ========================================================================== */

:root, [data-bs-theme="light"] {
  --app-bg: #f8fafc;
  --app-surface: #ffffff;
  --app-surface-subtle: #f1f5f9;
  --app-border: #e2e8f0;
  --app-border-subtle: #f1f5f9;
  --app-text: #334155;
  --app-text-title: #0f172a;
  --app-text-muted: #64748b;
  --app-sidebar-bg: #ffffff;
  --app-topbar-bg: #ffffff;
  --app-card-bg: #ffffff;
  --app-card-header-bg: #ffffff;
  --app-input-bg: #ffffff;
  --app-input-border: #cbd5e1;
  --app-input-color: #0f172a;
  --app-primary: #0284c7;
  --app-primary-hover: #0369a1;
  --app-primary-light: #e0f2fe;
  --app-teal: #0d9488;
  --app-emerald: #059669;
  --app-amber: #d97706;
  --app-rose: #e11d48;
  --app-sidebar-w: 260px;
  --app-topbar-h: 64px;
  --app-radius: 12px;
  --app-radius-sm: 8px;
  --app-shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.05);
  --app-shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --app-shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
  --app-shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.04);
}

[data-bs-theme="dark"] {
  --app-bg: #0b1329;
  --app-surface: #131d36;
  --app-surface-subtle: #1a2744;
  --app-border: #223254;
  --app-border-subtle: #1c2b4a;
  --app-text: #cbd5e1;
  --app-text-title: #f8fafc;
  --app-text-muted: #94a3b8;
  --app-sidebar-bg: #101930;
  --app-topbar-bg: #101930;
  --app-card-bg: #131d36;
  --app-card-header-bg: #131d36;
  --app-input-bg: #16223f;
  --app-input-border: #2a3c63;
  --app-input-color: #f8fafc;
  --app-primary: #38bdf8;
  --app-primary-hover: #0284c7;
  --app-primary-light: rgba(56, 189, 248, 0.15);
  --app-teal: #2dd4bf;
  --app-emerald: #10b981;
  --app-amber: #fbbf24;
  --app-rose: #f43f5e;
  --app-shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.2);
  --app-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --app-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --app-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

/* Global Reset & Typography */
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--app-bg);
  color: var(--app-text);
  transition: background-color 0.2s ease, color 0.2s ease;
  -webkit-font-smoothing: antialiased;
}

/* App Shell Structure */
.app-wrapper {
  display: flex;
  min-height: 100vh;
  position: relative;
  background-color: var(--app-bg);
}

/* Sidebar */
.app-sidebar {
  width: var(--app-sidebar-w);
  background: var(--app-sidebar-bg);
  border-right: 1px solid var(--app-border);
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 1045;
  display: flex;
  flex-direction: column;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.2s ease;
  overflow-y: auto;
}

/* Brand */
.sidebar-brand {
  height: var(--app-topbar-h);
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid var(--app-border);
  text-decoration: none;
  color: var(--app-text-title);
}

.brand-icon-box {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 1.15rem;
  box-shadow: 0 2px 4px rgba(2, 132, 199, 0.3);
}

.brand-name {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--app-text-title);
  margin: 0;
}

.brand-name span {
  color: var(--app-primary);
}

/* User Profile in Sidebar */
.sidebar-user {
  padding: 0.85rem 1.1rem;
  margin: 0.75rem 0.75rem 0.25rem;
  background: var(--app-surface-subtle);
  border-radius: var(--app-radius);
  border: 1px solid var(--app-border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sidebar-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--app-primary-light);
  color: var(--app-primary);
  font-weight: 700;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 2px solid var(--app-surface);
  box-shadow: var(--app-shadow-xs);
}

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

.sidebar-user-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--app-text-title);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
}

.sidebar-user-role {
  font-size: 0.75rem;
  color: var(--app-text-muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.15rem;
}

.role-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--app-emerald);
}

/* Sidebar Navigation */
.sidebar-nav {
  padding: 0.5rem 0.75rem;
  flex: 1;
  list-style: none;
  margin: 0;
}

.nav-section-title {
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--app-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.85rem 0.75rem 0.35rem;
  list-style: none;
}

.nav-link-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.85rem;
  margin-bottom: 0.2rem;
  border-radius: var(--app-radius-sm);
  color: var(--app-text);
  font-weight: 500;
  font-size: 0.8875rem;
  text-decoration: none;
  transition: all 0.15s ease;
}

.nav-link-item:hover {
  background: var(--app-surface-subtle);
  color: var(--app-primary);
}

.nav-link-item.active {
  background: var(--app-primary-light);
  color: var(--app-primary);
  font-weight: 600;
}

.nav-link-item i {
  font-size: 1.05rem;
  width: 20px;
  text-align: center;
  color: var(--app-text-muted);
  transition: color 0.15s ease;
}

.nav-link-item:hover i,
.nav-link-item.active i {
  color: var(--app-primary);
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid var(--app-border);
  background: var(--app-sidebar-bg);
}

.btn-logout {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.6rem 0.85rem;
  border-radius: var(--app-radius-sm);
  color: var(--app-rose);
  font-weight: 500;
  font-size: 0.875rem;
  text-decoration: none;
  transition: all 0.15s ease;
}

.btn-logout:hover {
  background: rgba(225, 29, 72, 0.12);
  color: var(--app-rose);
}

/* Main Content Area */
.app-main-wrapper {
  flex: 1;
  margin-left: var(--app-sidebar-w);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
  background-color: var(--app-bg);
}

/* Topbar */
.app-topbar {
  height: var(--app-topbar-h);
  background: var(--app-topbar-bg);
  border-bottom: 1px solid var(--app-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 1030;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.topbar-toggle-btn {
  background: var(--app-surface-subtle);
  border: 1px solid var(--app-border);
  width: 38px;
  height: 38px;
  border-radius: var(--app-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--app-text);
  cursor: pointer;
  transition: all 0.15s ease;
}

.topbar-toggle-btn:hover {
  background: var(--app-primary-light);
  color: var(--app-primary);
  border-color: var(--app-primary);
}

/* Theme Toggle Button */
.theme-toggle-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--app-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--app-border);
  background: var(--app-surface-subtle);
  color: var(--app-text);
  cursor: pointer;
  transition: all 0.2s ease;
}

.theme-toggle-btn:hover {
  background: var(--app-primary-light);
  color: var(--app-primary);
}

/* App Content Padding */
.app-content {
  flex: 1;
  padding: 1.5rem;
  background-color: var(--app-bg);
}

/* Cards & Containers */
.card {
  background-color: var(--app-card-bg) !important;
  border: 1px solid var(--app-border) !important;
  border-radius: var(--app-radius) !important;
  box-shadow: var(--app-shadow-sm) !important;
  color: var(--app-text);
}

.card-header {
  background-color: var(--app-card-header-bg) !important;
  border-bottom: 1px solid var(--app-border) !important;
  color: var(--app-text-title) !important;
}

/* Forms & Inputs */
.form-control, .form-select, .form-control-modern {
  background-color: var(--app-input-bg) !important;
  border: 1px solid var(--app-input-border) !important;
  color: var(--app-input-color) !important;
  border-radius: var(--app-radius-sm);
  padding: 0.6rem 0.85rem;
  font-size: 0.9rem;
  transition: all 0.15s ease;
}

.form-control:focus, .form-select:focus, .form-control-modern:focus {
  border-color: var(--app-primary) !important;
  box-shadow: 0 0 0 3px var(--app-primary-light) !important;
  outline: none;
}

.input-group-text {
  background-color: var(--app-surface-subtle) !important;
  border-color: var(--app-input-border) !important;
  color: var(--app-text-muted) !important;
}

/* Modals */
.modal-content {
  background-color: var(--app-surface) !important;
  border: 1px solid var(--app-border) !important;
  border-radius: 16px !important;
  color: var(--app-text);
  box-shadow: var(--app-shadow-lg);
}

.modal-header {
  border-bottom: 1px solid var(--app-border) !important;
  color: var(--app-text-title);
}

.modal-footer {
  border-top: 1px solid var(--app-border) !important;
}

/* Tables */
.table-modern {
  width: 100% !important;
  color: var(--app-text);
}

.table-modern thead th {
  background: var(--app-surface-subtle) !important;
  color: var(--app-text-title) !important;
  border-bottom: 1px solid var(--app-border) !important;
  font-weight: 600;
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.85rem 1rem;
}

.table-modern tbody td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--app-border) !important;
  color: var(--app-text);
  background: transparent !important;
}

.table-modern tbody tr:hover td {
  background-color: var(--app-primary-light) !important;
}

/* Select2 Dark Mode Fixes */
[data-bs-theme="dark"] .select2-container--default .select2-selection--single {
  background-color: var(--app-input-bg) !important;
  border: 1px solid var(--app-input-border) !important;
  color: var(--app-input-color) !important;
  height: 38px;
  border-radius: var(--app-radius-sm);
}

[data-bs-theme="dark"] .select2-container--default .select2-selection--single .select2-selection__rendered {
  color: var(--app-input-color) !important;
  line-height: 36px;
}

[data-bs-theme="dark"] .select2-dropdown {
  background-color: var(--app-surface) !important;
  border: 1px solid var(--app-border) !important;
  color: var(--app-text);
}

[data-bs-theme="dark"] .select2-search--dropdown .select2-search__field {
  background-color: var(--app-input-bg) !important;
  border: 1px solid var(--app-input-border) !important;
  color: var(--app-input-color) !important;
}

[data-bs-theme="dark"] .select2-container--default .select2-results__option--highlighted[aria-selected] {
  background-color: var(--app-primary) !important;
  color: #ffffff !important;
}

/* Mobile Drawer Overlay */
.sidebar-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(3px);
  z-index: 1040;
  display: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.sidebar-backdrop.show {
  display: block;
  opacity: 1;
}

/* Responsive */
@media (max-width: 991.98px) {
  .app-sidebar {
    transform: translateX(-100%);
  }

  .app-sidebar.show {
    transform: translateX(0);
    box-shadow: var(--app-shadow-lg);
  }

  .app-main-wrapper {
    margin-left: 0 !important;
  }
}

/* Modern Login Screen */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 10% 20%, var(--app-primary-light) 0%, var(--app-bg) 90%);
  padding: 1.5rem;
}

.login-card {
  max-width: 420px;
  width: 100%;
  background: var(--app-surface);
  border: 1px solid var(--app-border);
  border-radius: 16px;
  padding: 2.25rem;
  box-shadow: var(--app-shadow-lg);
}

.btn-modern-primary {
  background: var(--app-primary);
  color: #ffffff;
  font-weight: 600;
  border-radius: var(--app-radius-sm);
  padding: 0.7rem 1.25rem;
  border: none;
  box-shadow: 0 2px 4px rgba(2, 132, 199, 0.25);
  transition: all 0.15s ease;
}

.btn-modern-primary:hover {
  background: var(--app-primary-hover);
  color: #ffffff;
  box-shadow: 0 4px 8px rgba(2, 132, 199, 0.35);
}

/* SweetAlert2 Integration */
.swal2-popup {
  font-family: inherit !important;
  border-radius: var(--app-radius) !important;
}

[data-bs-theme="dark"] .swal2-popup {
  background: var(--app-surface, #131d36) !important;
  color: var(--app-text, #cbd5e1) !important;
  border: 1px solid var(--app-border, #223254) !important;
}

[data-bs-theme="dark"] .swal2-title,
[data-bs-theme="dark"] .swal2-html-container {
  color: var(--app-text, #cbd5e1) !important;
}

[data-bs-theme="dark"] .swal2-close {
  color: var(--app-text-muted, #64748b) !important;
}

