@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

/* ==========================================================================
   Base Theme Variables (Dark & Light)
   ========================================================================== */

/* Dark Theme (Default) */
html[data-theme="dark"], html[data-bs-theme="dark"], :root {
  --font-primary: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-heading: 'Outfit', sans-serif;
  
  --bg-app: #0f172a;
  --bg-surface: #1e293b;
  --bg-card: #1e293b;
  --bg-card-hover: #26354a;
  
  --primary-accent: #6366f1;
  --primary-gradient: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  --secondary-accent: #0ea5e9;
  --success-accent: #10b981;
  --warning-accent: #f59e0b;
  --danger-accent: #ef4444;
  --info-accent: #8b5cf6;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-heading: #ffffff;
  --border-color: rgba(255, 255, 255, 0.12);
  
  --form-bg: #0f172a;
  --form-border: rgba(255, 255, 255, 0.18);
  --form-text: #ffffff;
  --form-placeholder: #64748b;
  
  --table-th-bg: #0f172a;
  --table-td-border: rgba(255, 255, 255, 0.06);
  --table-hover: rgba(255, 255, 255, 0.04);
  
  --nav-bg: rgba(15, 23, 42, 0.9);
  --dropdown-bg: #1e293b;
  
  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.4), 0 10px 10px -5px rgba(0, 0, 0, 0.3);
}

/* Light Theme */
html[data-theme="light"], html[data-bs-theme="light"] {
  --bg-app: #f8fafc;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  
  --primary-accent: #4f46e5;
  --primary-gradient: linear-gradient(135deg, #4f46e5 0%, #3730a3 100%);
  --secondary-accent: #0284c7;
  --success-accent: #059669;
  --warning-accent: #d97706;
  --danger-accent: #dc2626;
  --info-accent: #7c3aed;

  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-heading: #0f172a;
  --border-color: #e2e8f0;
  
  --form-bg: #ffffff;
  --form-border: #cbd5e1;
  --form-text: #0f172a;
  --form-placeholder: #94a3b8;
  
  --table-th-bg: #f1f5f9;
  --table-td-border: #f1f5f9;
  --table-hover: #f8fafc;
  
  --nav-bg: rgba(255, 255, 255, 0.95);
  --dropdown-bg: #ffffff;
  
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* ==========================================================================
   Global Typography & Layout
   ========================================================================== */
body {
  font-family: var(--font-primary);
  background-color: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.25s ease, color 0.25s ease;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 600;
  color: var(--text-heading);
}

.text-muted {
  color: var(--text-muted) !important;
}

/* ==========================================================================
   Navbar & Navigation
   ========================================================================== */
.navbar-custom {
  background: var(--nav-bg);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  padding: 0.85rem 1.5rem;
  transition: background 0.25s ease;
}

.navbar-brand {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.35rem;
  background: linear-gradient(135deg, #6366f1 0%, #0284c7 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-link {
  color: var(--text-muted) !important;
  font-weight: 500;
  padding: 0.5rem 1rem !important;
  border-radius: 0.5rem;
  transition: all 0.2s ease;
}

.nav-link:hover, .nav-link.active {
  color: var(--text-heading) !important;
  background: rgba(99, 102, 241, 0.1);
}

.dropdown-menu-custom {
  background-color: var(--dropdown-bg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
}

.dropdown-item {
  color: var(--text-main);
  font-weight: 500;
  padding: 0.6rem 1.2rem;
}

.dropdown-item:hover {
  background: rgba(99, 102, 241, 0.12);
  color: var(--primary-accent);
}

/* ==========================================================================
   Cards & Surfaces
   ========================================================================== */
.card {
  background-color: var(--bg-card);
  color: var(--text-main);
  border-color: var(--border-color);
}

.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: 1rem;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.25s ease;
}

.glass-card:hover {
  box-shadow: var(--shadow-lg);
}

.metric-card {
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
}

.metric-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--primary-gradient);
}

.metric-icon {
  width: 52px;
  height: 52px;
  border-radius: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn-primary-custom {
  background: var(--primary-gradient);
  color: #fff !important;
  border: none;
  font-weight: 600;
  padding: 0.6rem 1.25rem;
  border-radius: 0.5rem;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-primary-custom:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
  color: #fff !important;
}

.btn-outline-custom {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  transition: all 0.2s ease;
}

.btn-outline-custom:hover {
  background: rgba(99, 102, 241, 0.1);
  color: var(--primary-accent);
  border-color: var(--primary-accent);
}

/* ==========================================================================
   Form Controls
   ========================================================================== */
.form-control, .form-select {
  background-color: var(--form-bg);
  border: 1px solid var(--form-border);
  color: var(--form-text);
  border-radius: 0.5rem;
  padding: 0.65rem 1rem;
}

.form-control:focus, .form-select:focus {
  background-color: var(--form-bg);
  border-color: var(--primary-accent);
  color: var(--form-text);
  box-shadow: 0 0 0 0.25rem rgba(99, 102, 241, 0.25);
}

.form-control::placeholder {
  color: var(--form-placeholder);
}

.form-label {
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--text-main);
  margin-bottom: 0.4rem;
}

/* ==========================================================================
   Tables
   ========================================================================== */
.custom-table, .table {
  width: 100%;
  margin-bottom: 0;
  color: var(--text-main);
  border-collapse: separate;
  border-spacing: 0;
}

.custom-table th, .table thead th {
  background: var(--table-th-bg);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.custom-table td, .table td {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--table-td-border);
  vertical-align: middle;
  color: var(--text-main);
}

.custom-table tbody tr, .table tbody tr {
  transition: background 0.15s ease;
}

.custom-table tbody tr:hover, .table tbody tr:hover {
  background: var(--table-hover);
}

/* ==========================================================================
   Badges & Status Indicators
   ========================================================================== */
.badge-custom {
  padding: 0.35rem 0.75rem;
  border-radius: 2rem;
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.badge-disease {
  background: rgba(14, 165, 233, 0.15);
  color: #0284c7;
  border: 1px solid rgba(14, 165, 233, 0.3);
}

.badge-lead {
  background: rgba(139, 92, 246, 0.15);
  color: #7c3aed;
  border: 1px solid rgba(139, 92, 246, 0.3);
}

.badge-returned {
  background: rgba(239, 68, 68, 0.15);
  color: #dc2626;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge-active {
  background: rgba(16, 185, 129, 0.15);
  color: #059669;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-repeat {
  background: rgba(245, 158, 11, 0.15);
  color: #d97706;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

/* WhatsApp & Phone Action Buttons */
.btn-whatsapp {
  background: rgba(37, 211, 102, 0.15);
  color: #16a34a;
  border: 1px solid rgba(37, 211, 102, 0.3);
  font-size: 0.85rem;
  padding: 0.3rem 0.75rem;
  border-radius: 0.5rem;
  text-decoration: none;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.2s ease;
}

.btn-whatsapp:hover {
  background: #25d366;
  color: #fff !important;
}

.btn-call {
  background: rgba(56, 189, 248, 0.15);
  color: #0284c7;
  border: 1px solid rgba(56, 189, 248, 0.3);
  font-size: 0.85rem;
  padding: 0.3rem 0.75rem;
  border-radius: 0.5rem;
  text-decoration: none;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.2s ease;
}

.btn-call:hover {
  background: #38bdf8;
  color: #0f172a !important;
}

footer {
  margin-top: auto;
  border-top: 1px solid var(--border-color);
  padding: 1.5rem 0;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ==========================================================================
   COMPREHENSIVE DARK MODE OVERRIDES (HIGH CONTRAST & READABLE FONTS)
   ========================================================================== */
html[data-theme="dark"], html[data-bs-theme="dark"] {
  /* Typography & Text */
  --bs-body-color: #f8fafc;
  --bs-body-bg: #0f172a;
  --bs-heading-color: #ffffff;
  --bs-secondary-color: #94a3b8;
  --bs-tertiary-color: #64748b;
  --bs-emphasis-color: #ffffff;
}

/* Global text contrast in Dark Mode */
html[data-theme="dark"] .text-dark,
html[data-bs-theme="dark"] .text-dark {
  color: #f8fafc !important;
}

html[data-theme="dark"] .text-body,
html[data-bs-theme="dark"] .text-body {
  color: #f8fafc !important;
}

html[data-theme="dark"] .text-muted,
html[data-bs-theme="dark"] .text-muted {
  color: #94a3b8 !important;
}

html[data-theme="dark"] .text-secondary,
html[data-bs-theme="dark"] .text-secondary {
  color: #cbd5e1 !important;
}

html[data-theme="dark"] .text-black-50,
html[data-bs-theme="dark"] .text-black-50 {
  color: rgba(248, 250, 252, 0.7) !important;
}

html[data-theme="dark"] code,
html[data-bs-theme="dark"] code {
  color: #38bdf8 !important;
  background-color: rgba(14, 165, 233, 0.15) !important;
  padding: 0.15rem 0.4rem;
  border-radius: 0.35rem;
}

/* Surface backgrounds in Dark Mode */
html[data-theme="dark"] .bg-white,
html[data-bs-theme="dark"] .bg-white {
  background-color: #1e293b !important;
  color: #f8fafc !important;
  border-color: rgba(255, 255, 255, 0.1) !important;
}

html[data-theme="dark"] .bg-light,
html[data-bs-theme="dark"] .bg-light {
  background-color: #1e293b !important;
  color: #cbd5e1 !important;
  border-color: rgba(255, 255, 255, 0.1) !important;
}

/* Cards & Headers in Dark Mode */
html[data-theme="dark"] .card,
html[data-bs-theme="dark"] .card {
  background-color: #1e293b !important;
  color: #f8fafc !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
}

html[data-theme="dark"] .card-header,
html[data-bs-theme="dark"] .card-header {
  background-color: rgba(15, 23, 42, 0.5) !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
  color: #f8fafc !important;
}

html[data-theme="dark"] .card-footer,
html[data-bs-theme="dark"] .card-footer {
  background-color: rgba(15, 23, 42, 0.5) !important;
  border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
  color: #f8fafc !important;
}

/* Tables in Dark Mode */
html[data-theme="dark"] .table,
html[data-bs-theme="dark"] .table {
  --bs-table-color: #f8fafc !important;
  --bs-table-bg: transparent !important;
  --bs-table-striped-bg: rgba(255, 255, 255, 0.02) !important;
  --bs-table-hover-bg: rgba(255, 255, 255, 0.05) !important;
  --bs-table-border-color: rgba(255, 255, 255, 0.08) !important;
  color: #f8fafc !important;
}

html[data-theme="dark"] .table thead,
html[data-theme="dark"] .table thead.bg-light,
html[data-theme="dark"] .table thead th {
  background-color: #0f172a !important;
  color: #94a3b8 !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15) !important;
}

html[data-theme="dark"] .table td {
  border-bottom: 1px solid rgba(255, 255, 255, 0.06) !important;
  color: #f8fafc;
}

/* Inputs & Addons in Dark Mode */
html[data-theme="dark"] .input-group-text,
html[data-bs-theme="dark"] .input-group-text {
  background-color: #1e293b !important;
  color: #94a3b8 !important;
  border-color: rgba(255, 255, 255, 0.18) !important;
}

html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select,
html[data-bs-theme="dark"] .form-control,
html[data-bs-theme="dark"] .form-select {
  background-color: #0f172a !important;
  color: #ffffff !important;
  border-color: rgba(255, 255, 255, 0.18) !important;
}

html[data-theme="dark"] select option {
  background-color: #1e293b !important;
  color: #f8fafc !important;
}

/* Badges in Dark Mode */
html[data-theme="dark"] .badge.bg-light,
html[data-bs-theme="dark"] .badge.bg-light {
  background-color: rgba(255, 255, 255, 0.12) !important;
  color: #f8fafc !important;
  border: 1px solid rgba(255, 255, 255, 0.18) !important;
}

html[data-theme="dark"] .badge.bg-secondary-subtle,
html[data-bs-theme="dark"] .badge.bg-secondary-subtle {
  background-color: rgba(148, 163, 184, 0.2) !important;
  color: #cbd5e1 !important;
  border: 1px solid rgba(148, 163, 184, 0.3) !important;
}

html[data-theme="dark"] .badge.bg-warning-subtle,
html[data-bs-theme="dark"] .badge.bg-warning-subtle {
  background-color: rgba(245, 158, 11, 0.2) !important;
  color: #fbbf24 !important;
  border: 1px solid rgba(245, 158, 11, 0.3) !important;
}

html[data-theme="dark"] .badge.bg-info-subtle,
html[data-bs-theme="dark"] .badge.bg-info-subtle {
  background-color: rgba(14, 165, 233, 0.2) !important;
  color: #38bdf8 !important;
  border: 1px solid rgba(14, 165, 233, 0.3) !important;
}

html[data-theme="dark"] .badge.bg-success-subtle,
html[data-bs-theme="dark"] .badge.bg-success-subtle {
  background-color: rgba(16, 185, 129, 0.2) !important;
  color: #34d399 !important;
  border: 1px solid rgba(16, 185, 129, 0.3) !important;
}

html[data-theme="dark"] .badge.bg-danger-subtle,
html[data-bs-theme="dark"] .badge.bg-danger-subtle {
  background-color: rgba(239, 68, 68, 0.2) !important;
  color: #f87171 !important;
  border: 1px solid rgba(239, 68, 68, 0.3) !important;
}

html[data-theme="dark"] .badge.bg-primary-subtle,
html[data-bs-theme="dark"] .badge.bg-primary-subtle {
  background-color: rgba(99, 102, 241, 0.2) !important;
  color: #a5b4fc !important;
  border: 1px solid rgba(99, 102, 241, 0.3) !important;
}

html[data-theme="dark"] .badge-disease {
  color: #38bdf8 !important;
}

html[data-theme="dark"] .badge-lead {
  color: #c084fc !important;
}

html[data-theme="dark"] .badge-returned {
  color: #f87171 !important;
}

html[data-theme="dark"] .badge-active {
  color: #34d399 !important;
}

html[data-theme="dark"] .badge-repeat {
  color: #fbbf24 !important;
}

/* Modals & Dropdowns in Dark Mode */
html[data-theme="dark"] .modal-content,
html[data-bs-theme="dark"] .modal-content {
  background-color: #1e293b !important;
  color: #f8fafc !important;
  border: 1px solid rgba(255, 255, 255, 0.15) !important;
}

html[data-theme="dark"] .modal-header,
html[data-theme="dark"] .modal-footer {
  border-color: rgba(255, 255, 255, 0.1) !important;
}

html[data-theme="dark"] .dropdown-menu {
  background-color: #1e293b !important;
  border: 1px solid rgba(255, 255, 255, 0.15) !important;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5) !important;
}

html[data-theme="dark"] .dropdown-item {
  color: #f8fafc !important;
}

html[data-theme="dark"] .dropdown-item:hover {
  background-color: rgba(99, 102, 241, 0.2) !important;
  color: #ffffff !important;
}

/* Nav Tabs in Dark Mode */
html[data-theme="dark"] .nav-tabs .nav-link {
  color: #94a3b8;
  border-color: transparent;
}

html[data-theme="dark"] .nav-tabs .nav-link:hover {
  color: #f8fafc;
  border-color: rgba(255, 255, 255, 0.15);
}

html[data-theme="dark"] .nav-tabs .nav-link.active {
  color: #818cf8 !important;
  background-color: #1e293b;
  border-color: rgba(255, 255, 255, 0.15) rgba(255, 255, 255, 0.15) #1e293b;
}

/* Pagination in Dark Mode */
html[data-theme="dark"] .pagination .page-link {
  background-color: #1e293b;
  border-color: rgba(255, 255, 255, 0.15);
  color: #cbd5e1;
}

html[data-theme="dark"] .pagination .page-item.active .page-link {
  background-color: #6366f1;
  border-color: #6366f1;
  color: #ffffff;
}

html[data-theme="dark"] .pagination .page-item.disabled .page-link {
  background-color: rgba(15, 23, 42, 0.5);
  border-color: rgba(255, 255, 255, 0.08);
  color: #64748b;
}

/* Alerts in Dark Mode */
html[data-theme="dark"] .alert-warning {
  background-color: rgba(245, 158, 11, 0.15) !important;
  color: #fef08a !important;
  border-color: rgba(245, 158, 11, 0.3) !important;
}

html[data-theme="dark"] .alert-warning h5,
html[data-theme="dark"] .alert-warning p,
html[data-theme="dark"] .alert-warning div,
html[data-theme="dark"] .alert-warning span {
  color: #fef08a !important;
}

html[data-theme="dark"] .alert-danger {
  background-color: rgba(239, 68, 68, 0.15) !important;
  color: #fecaca !important;
  border-color: rgba(239, 68, 68, 0.3) !important;
}

html[data-theme="dark"] .alert-success {
  background-color: rgba(16, 185, 129, 0.15) !important;
  color: #a7f3d0 !important;
  border-color: rgba(16, 185, 129, 0.3) !important;
}

html[data-theme="dark"] .alert-info {
  background-color: rgba(14, 165, 233, 0.15) !important;
  color: #bae6fd !important;
  border-color: rgba(14, 165, 233, 0.3) !important;
}

/* Patient Notes Container */
.patient-notes-container {
  background-color: rgba(0, 0, 0, 0.03);
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

html[data-theme="dark"] .patient-notes-container,
html[data-bs-theme="dark"] .patient-notes-container {
  background-color: rgba(15, 23, 42, 0.6) !important;
  border: 1px solid rgba(255, 255, 255, 0.12) !important;
  color: #f1f5f9 !important;
}
