/* ===========================
   CSS Variables & Reset
   =========================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Colors - Can be overridden by white-label branding */
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --primary-light: #3b82f6;
    --secondary: #10b981;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    
    /* White-label brand colors (set dynamically when enabled) */
    --brand-primary: var(--primary);
    --brand-secondary: var(--primary-dark);
    --brand-primary-hover: var(--primary-dark);
    --brand-primary-light: var(--primary-light);
    
    /* Grays */
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    
    /* Sidebar */
    --sidebar-width: 260px;
    --sidebar-bg: #1e293b;
    --sidebar-text: #e2e8f0;
    --sidebar-active: var(--primary);
    
    /* Layout */
    --header-height: 80px;
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2rem;
    --spacing-xl: 3rem;
    
    /* Typography */
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    
    /* Border Radius */
    --radius-sm: 0.25rem;
    --radius: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
}

body {
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.6;
    color: var(--gray-800);
    background: var(--gray-50);
    display: flex;
    min-height: 100vh;
}

/* ===========================
   Sidebar Navigation
   =========================== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    box-shadow: var(--shadow-lg);
    z-index: 100;
}

.sidebar-header {
    padding: var(--spacing-lg);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header h1 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
    color: #fff;
}

.sidebar-logo {
    width: 100%;
    max-width: 180px;
    margin-bottom: 0.5rem;
}

.sidebar-logo img {
    width: 100%;
    height: auto;
    max-height: 60px;
    object-fit: contain;
}

.sidebar-subtitle {
    font-size: 0.875rem;
    color: var(--gray-400);
}

.sidebar-nav {
    flex: 1;
    padding: var(--spacing-md) 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-lg);
    color: var(--sidebar-text);
    text-decoration: none;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
}

.nav-item.active {
    background: rgba(37, 99, 235, 0.1);
    border-left-color: var(--sidebar-active);
    color: #fff;
}

.nav-icon {
    font-size: 1.25rem;
}

.sidebar-footer {
    padding: var(--spacing-md);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.user-info {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.user-name {
    font-weight: 600;
    color: #fff;
    font-size: 0.875rem;
}

.user-role {
    font-size: 0.75rem;
    color: var(--gray-400);
}

/* ===========================
   Main Content Area
   =========================== */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: var(--spacing-lg);
    max-width: calc(100vw - var(--sidebar-width));
}

.page-header {
    margin-bottom: var(--spacing-xl);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: var(--spacing-md);
}

.page-header h1 {
    font-size: 2rem;
    color: var(--gray-900);
    margin-bottom: 0.25rem;
}

.header-subtitle {
    color: var(--gray-500);
    font-size: 0.95rem;
}

.header-date {
    text-align: right;
}

.date-label {
    display: block;
    font-size: 0.75rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.date-value {
    display: block;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--gray-900);
}

.header-actions {
    display: flex;
    gap: var(--spacing-sm);
}

.back-link {
    display: inline-block;
    color: var(--primary);
    text-decoration: none;
    font-size: 0.95rem;
    margin-bottom: var(--spacing-sm);
    transition: color 0.2s;
}

.back-link:hover {
    color: var(--primary-dark);
}

/* ===========================
   Buttons
   =========================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

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

.btn-primary:hover {
    background: var(--brand-primary-hover, var(--primary-dark));
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
}

.btn-icon {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.25rem;
    transition: transform 0.2s;
}

.btn-icon:hover {
    transform: scale(1.1);
}

.btn-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.95rem;
    transition: color 0.2s;
}

.btn-link:hover {
    color: var(--primary-dark);
}

.btn-text {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 0.875rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    transition: color 0.2s;
}

.btn-text:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

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

/* ===========================
   Stats Cards (Dashboard)
   =========================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-xl);
}

.stat-card {
    background: #fff;
    padding: var(--spacing-lg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
}

.stat-content {
    flex: 1;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--gray-500);
    margin-bottom: 0.25rem;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--gray-900);
}

.stat-trend {
    font-size: 0.8rem;
    color: var(--gray-500);
}

.stat-trend.up {
    color: var(--success);
}

/* ===========================
   Quick Actions
   =========================== */
.quick-actions {
    margin-bottom: var(--spacing-xl);
}

.section-title {
    font-size: 1.5rem;
    color: var(--gray-900);
    margin-bottom: var(--spacing-md);
}

.action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: var(--spacing-md);
}

.action-card {
    background: #fff;
    padding: var(--spacing-lg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    text-decoration: none;
    color: inherit;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.action-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}

.action-icon {
    font-size: 2.5rem;
    margin-bottom: var(--spacing-sm);
}

.action-card h3 {
    font-size: 1.125rem;
    color: var(--gray-900);
    margin-bottom: 0.5rem;
}

.action-card p {
    font-size: 0.875rem;
    color: var(--gray-500);
}

/* ===========================
   Schedule Preview/List
   =========================== */
.schedule-preview,
.recent-patients {
    background: #fff;
    padding: var(--spacing-lg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin-bottom: var(--spacing-lg);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-md);
}

.schedule-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.schedule-item {
    display: flex;
    align-items: center;
    padding: var(--spacing-md);
    background: var(--gray-50);
    border-radius: var(--radius);
    gap: var(--spacing-md);
    transition: background 0.2s;
}

.schedule-item:hover {
    background: var(--gray-100);
}

.schedule-item.gap {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
}

.schedule-time {
    font-weight: 600;
    color: var(--primary);
    min-width: 90px;
}

.schedule-details {
    flex: 1;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.patient-name {
    font-weight: 500;
    color: var(--gray-900);
}

.patient-type {
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.8rem;
    font-weight: 500;
}

.patient-type.medical-aid {
    background: #dbeafe;
    color: #1e40af;
}

.patient-type.cash {
    background: #d1fae5;
    color: #065f46;
}

.patient-type.gap-time {
    background: rgba(0,0,0,0.1);
    color: #78350f;
}

/* ===========================
   Data Table
   =========================== */
.table-container {
    overflow-x: auto;
}

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

.data-table thead {
    background: var(--gray-100);
}

.data-table th {
    text-align: left;
    padding: var(--spacing-sm) var(--spacing-md);
    font-weight: 600;
    color: var(--gray-700);
    font-size: 0.875rem;
    border-bottom: 2px solid var(--gray-200);
}

.data-table td {
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--gray-200);
}

.data-table tbody tr {
    transition: background 0.2s;
    cursor: pointer;
}

.data-table tbody tr:hover {
    background: var(--gray-50);
}

.patient-info {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.patient-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-light);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
}

.patient-name-cell {
    font-weight: 500;
    color: var(--gray-900);
}

.patient-meta {
    font-size: 0.8rem;
    color: var(--gray-500);
}

/* ===========================
   Badges
   =========================== */
.badge {
    display: inline-block;
    padding: 0.25rem 0.625rem;
    border-radius: var(--radius);
    font-size: 0.8rem;
    font-weight: 500;
}

.badge-medical {
    background: #dbeafe;
    color: #1e40af;
}

.badge-cash {
    background: #d1fae5;
    color: #065f46;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

.count {
    color: var(--gray-500);
    font-weight: normal;
}

/* ===========================
   Calendar/Appointments Page
   =========================== */
.calendar-controls {
    background: #fff;
    padding: var(--spacing-lg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin-bottom: var(--spacing-lg);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.date-navigator {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.current-date {
    text-align: center;
}

.date-display {
    display: block;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--gray-900);
}

.day-of-week {
    font-size: 0.875rem;
    color: var(--gray-500);
}

.daily-schedule {
    background: #fff;
    padding: var(--spacing-lg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.schedule-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-lg);
    padding-bottom: var(--spacing-md);
    border-bottom: 2px solid var(--gray-200);
}

.schedule-summary {
    display: flex;
    gap: var(--spacing-md);
    font-size: 0.9rem;
}

.summary-item {
    color: var(--gray-600);
}

.timeline-container {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.time-slot {
    display: flex;
    gap: var(--spacing-md);
    align-items: start;
}

.time-label {
    min-width: 90px;
    font-weight: 600;
    color: var(--gray-600);
    padding-top: var(--spacing-md);
}

.appointment-card {
    flex: 1;
    background: var(--gray-50);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    border-left: 4px solid var(--gray-300);
    transition: all 0.2s;
}

.appointment-card.booked {
    background: #fff;
    border-left-color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.appointment-card.booked:hover {
    box-shadow: var(--shadow-md);
}

.appointment-card.cash-patient {
    border-left-color: var(--success);
}

.appointment-card.available {
    cursor: pointer;
    border-style: dashed;
}

.appointment-card.available:hover {
    background: var(--gray-100);
    border-color: var(--primary);
}

.appointment-card.gap {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border-left-color: var(--warning);
}

.available-slot {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-md);
    color: var(--gray-500);
}

.available-icon {
    font-size: 1.5rem;
    color: var(--primary);
}

.appointment-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-sm);
}

.appointment-details {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: var(--spacing-sm);
}

.detail-item {
    font-size: 0.875rem;
    color: var(--gray-600);
}

.appointment-actions {
    display: flex;
    gap: var(--spacing-md);
    padding-top: var(--spacing-sm);
    border-top: 1px solid var(--gray-200);
}

.gap-content {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.gap-icon {
    font-size: 2rem;
}

.gap-title {
    font-weight: 600;
    color: var(--gray-900);
}

.gap-description {
    font-size: 0.875rem;
    color: var(--gray-600);
}

/* ===========================
   Patient Pages
   =========================== */
.search-section {
    background: #fff;
    padding: var(--spacing-lg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin-bottom: var(--spacing-lg);
}

.search-box {
    position: relative;
    margin-bottom: var(--spacing-md);
}

.search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.25rem;
}

.search-input {
    width: 100%;
    padding: 0.875rem 1rem 0.875rem 3rem;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-lg);
    font-size: 1rem;
    transition: border-color 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
}

.search-filters {
    display: flex;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
}

.filter-chip {
    padding: 0.5rem 1rem;
    border: 1px solid var(--gray-300);
    background: #fff;
    border-radius: var(--radius-lg);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
}

.filter-chip:hover {
    border-color: var(--primary);
    background: var(--gray-50);
}

.filter-chip.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.patient-list {
    background: #fff;
    padding: var(--spacing-lg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-md);
}

.sort-options {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 0.875rem;
}

.form-control-sm {
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.875rem;
}

/* ===========================
   Patient Detail Page
   =========================== */
.patient-profile {
    margin-bottom: var(--spacing-lg);
}

.profile-card {
    background: #fff;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.profile-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    padding: var(--spacing-xl);
    display: flex;
    align-items: center;
    gap: var(--spacing-lg);
}

.profile-avatar-large {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: 700;
    border: 4px solid rgba(255, 255, 255, 0.3);
}

.profile-info h2 {
    font-size: 2rem;
    margin-bottom: var(--spacing-sm);
}

.profile-meta {
    display: flex;
    gap: var(--spacing-md);
    flex-wrap: wrap;
    align-items: center;
}

.meta-item {
    font-size: 0.95rem;
    opacity: 0.95;
}

.profile-details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--spacing-lg);
    padding: var(--spacing-xl);
}

.detail-section h3 {
    font-size: 1.125rem;
    color: var(--gray-900);
    margin-bottom: var(--spacing-md);
    padding-bottom: var(--spacing-sm);
    border-bottom: 2px solid var(--gray-200);
}

.detail-item {
    display: flex;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
    font-size: 0.95rem;
}

.detail-label {
    color: var(--gray-600);
    min-width: 140px;
}

.detail-value {
    color: var(--gray-900);
    font-weight: 500;
}

/* Visit History */
.visit-history-section {
    background: #fff;
    padding: var(--spacing-lg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.visit-timeline {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
}

.visit-card {
    display: flex;
    gap: var(--spacing-lg);
    padding: var(--spacing-lg);
    background: var(--gray-50);
    border-radius: var(--radius-lg);
    border-left: 4px solid var(--primary);
}

.visit-date-badge {
    min-width: 80px;
    background: var(--primary);
    color: #fff;
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    text-align: center;
    height: fit-content;
}

.visit-day {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
}

.visit-month {
    font-size: 0.875rem;
    font-weight: 600;
}

.visit-year {
    font-size: 0.75rem;
    opacity: 0.9;
}

.visit-content {
    flex: 1;
}

.visit-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: var(--spacing-sm);
}

.visit-header h3 {
    font-size: 1.25rem;
    color: var(--gray-900);
}

.visit-codes {
    display: flex;
    gap: var(--spacing-sm);
}

.code-badge {
    padding: 0.25rem 0.625rem;
    background: var(--gray-200);
    border-radius: var(--radius);
    font-size: 0.8rem;
    color: var(--gray-700);
    font-weight: 500;
}

.visit-notes {
    margin-bottom: var(--spacing-md);
    line-height: 1.7;
    color: var(--gray-700);
}

.visit-footer {
    display: flex;
    gap: var(--spacing-lg);
    padding-top: var(--spacing-sm);
    border-top: 1px solid var(--gray-200);
}

.visit-meta {
    font-size: 0.875rem;
    color: var(--gray-500);
}

/* ===========================
   Modal
   =========================== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-lg);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: #fff;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-large {
    max-width: 800px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-lg);
    border-bottom: 2px solid var(--gray-200);
}

.modal-header h2 {
    font-size: 1.5rem;
    color: var(--gray-900);
}

.modal-close {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--gray-400);
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.modal-close:hover {
    color: var(--gray-700);
}

.modal-body {
    padding: var(--spacing-lg);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-sm);
    padding-top: var(--spacing-lg);
    border-top: 2px solid var(--gray-200);
}

/* ===========================
   Forms
   =========================== */
.form-section-title {
    font-size: 1.125rem;
    color: var(--gray-900);
    margin: var(--spacing-lg) 0 var(--spacing-md);
    padding-bottom: var(--spacing-sm);
    border-bottom: 2px solid var(--gray-200);
}

.form-section-title:first-child {
    margin-top: 0;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-md);
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 0.5rem;
}

.form-control {
    padding: 0.625rem 0.875rem;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
}

textarea.form-control {
    resize: vertical;
    font-family: inherit;
}

select.form-control {
    cursor: pointer;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 2px solid var(--gray-200);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    max-height: 200px;
    overflow-y: auto;
    display: none;
    z-index: 10;
}

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

/* ===========================
   Side Panel
   =========================== */
.side-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    display: none;
}

.side-panel.active {
    display: flex;
    justify-content: flex-end;
}

.side-panel-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    cursor: pointer;
}

.side-panel-content {
    position: relative;
    width: 100%;
    max-width: 600px;
    background: #fff;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.side-panel-header {
    background: var(--primary);
    color: #fff;
    padding: var(--spacing-lg);
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.side-panel-header h2 {
    font-size: 24px;
    font-weight: 700;
    margin: 0;
    color: #fff;
}

.side-panel-header .header-subtitle {
    font-size: 14px;
    opacity: 0.9;
    margin-top: var(--spacing-xs);
}

.side-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-lg);
}

/* ===========================
   Info Cards (for patient details)
   =========================== */
.info-card {
    background: var(--gray-100);
    border-radius: var(--radius);
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-md);
}

.info-card-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: var(--spacing-md);
    color: var(--gray-900);
}

.info-grid {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.info-item {
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-sm);
}

.info-label {
    font-size: 14px;
    font-weight: 500;
    min-width: 130px;
    color: var(--gray-700);
}

.info-value {
    font-size: 14px;
    color: var(--gray-900);
}

.info-message {
    background: var(--gray-100);
    padding: var(--spacing-md);
    border-radius: var(--radius);
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
    color: var(--gray-700);
    font-size: 14px;
}

/* ===========================
   Calendar Grid
   =========================== */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: var(--spacing-sm);
}

.calendar-day {
    background: #fff;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    padding: var(--spacing-sm);
    min-height: 150px;
    display: flex;
    flex-direction: column;
}

.calendar-day.today {
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary);
}

.calendar-day-header {
    text-align: center;
    margin-bottom: var(--spacing-sm);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--gray-200);
}

.day-name {
    font-size: 12px;
    color: var(--gray-600);
    text-transform: uppercase;
}

.day-number {
    font-size: 20px;
    font-weight: 700;
    color: var(--gray-900);
    margin-top: var(--spacing-xs);
}

.day-number.today {
    color: var(--primary);
}

.calendar-appointments {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.calendar-appointment {
    background: var(--gray-100);
    padding: var(--spacing-xs);
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
}

.calendar-appointment:hover {
    background: var(--gray-200);
}

.calendar-appointment.cancelled {
    text-decoration: line-through;
    opacity: 0.5;
}

.appointment-time {
    font-weight: 600;
    color: var(--gray-900);
}

.appointment-patient {
    color: var(--gray-700);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.no-appointments {
    font-size: 12px;
    text-align: center;
    color: var(--gray-500);
    margin-top: var(--spacing-md);
}

.more-appointments {
    font-size: 12px;
    text-align: center;
    color: var(--gray-600);
    margin-top: var(--spacing-xs);
}

/* ===========================
   Loading States
   =========================== */
.loading-spinner {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: var(--spacing-lg);
}

.spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 4px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.htmx-transition {
    transition: opacity 0.2s ease-in-out;
}

/* ===========================
   Responsive Design
   =========================== */
@media (max-width: 968px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s;
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
        max-width: 100vw;
    }
    
    .profile-header {
        flex-direction: column;
        text-align: center;
    }
    
    .profile-details-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .action-grid {
        grid-template-columns: 1fr;
    }
    
    .header-content {
        flex-direction: column;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
}

/* ===========================
   Generic Components
   =========================== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-lg);
}

.page-title {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--gray-900);
}

.card {
    background: #fff;
    padding: var(--spacing-lg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin-bottom: var(--spacing-lg);
}

.search-box {
    margin-bottom: var(--spacing-md);
    position: relative;
}

.search-input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.5rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 1rem;
    transition: border-color 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
    pointer-events: none;
}

/* ===========================
   Responsive Layout & Mobile
   =========================== */

/* Mobile Header (Hidden by default) */
.mobile-header {
    display: none;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-sm) var(--spacing-md);
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px; /* Slightly smaller than desktop header var */
    z-index: 90;
    box-shadow: var(--shadow-sm);
}

.mobile-header h1 {
    font-size: 1.125rem;
    margin: 0;
    color: var(--gray-900);
    font-weight: 600;
}

.mobile-logo {
    height: 36px;
    width: auto;
    max-width: 150px;
    object-fit: contain;
}

/* Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 95;
    opacity: 0;
    transition: opacity 0.3s;
    backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* Responsive Breakpoints */
@media (max-width: 1024px) {
    /* Layout Adjustments */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: var(--shadow-xl);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        max-width: 100%;
        padding-top: calc(60px + var(--spacing-md)); /* Match mobile header height */
    }

    .mobile-header {
        display: flex;
    }

    /* Adjust Page Header */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-sm);
    }

    .header-content {
        flex-direction: column;
        width: 100%;
        gap: var(--spacing-sm);
    }

    .header-actions {
        width: 100%;
        justify-content: flex-start;
        margin-top: var(--spacing-sm);
        flex-wrap: wrap;
    }
    
    .header-date {
        text-align: left;
        margin-top: var(--spacing-xs);
    }
}

@media (max-width: 640px) {
    :root {
        --spacing-lg: 1.25rem;
        --spacing-xl: 1.5rem;
    }

    .main-content {
        padding: var(--spacing-md);
        padding-top: calc(60px + var(--spacing-md));
    }

    /* Tables */
    table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }

    /* Cards */
    .card {
        padding: var(--spacing-md);
        border-radius: var(--radius);
    }

    /* Forms */
    .form-row {
        grid-template-columns: 1fr !important;
        gap: var(--spacing-sm);
    }
    
    .form-group {
        margin-bottom: var(--spacing-sm);
    }

    /* Buttons */
    .btn {
        width: 100%;
        justify-content: center;
        margin-bottom: var(--spacing-xs);
    }
    
    .header-actions .btn {
        width: 100%;
        margin-bottom: var(--spacing-xs);
    }
    
    .btn-icon {
        width: auto;
        margin-bottom: 0;
    }

    /* Modals */
    .modal-content {
        width: 95%;
        margin: var(--spacing-md) auto;
        max-height: 90vh;
        overflow-y: auto;
    }
}

/* ===========================
   Calendar & Schedule
   =========================== */
.calendar-layout {
    display: grid;
    grid-template-columns: 3fr 1fr;
    gap: 2rem;
}

.calendar-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-md);
    flex-wrap: wrap;
    gap: var(--spacing-md);
}

.date-navigator {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.current-date {
    text-align: center;
}

.current-date .date-display {
    display: block;
    font-weight: 600;
    font-size: 1.125rem;
}

.current-date .day-of-week {
    display: block;
    font-size: 0.875rem;
    color: var(--gray-500);
}

/* Timeline */
.timeline-container {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.time-slot {
    display: flex;
    gap: var(--spacing-md);
}

.time-label {
    width: 80px;
    flex-shrink: 0;
    font-weight: 500;
    color: var(--gray-500);
    padding-top: var(--spacing-sm);
}

@media (max-width: 1024px) {
    .calendar-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .calendar-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .date-navigator {
        justify-content: space-between;
    }
    
    .view-options {
        justify-content: space-between;
        width: 100%;
    }
    
    .time-slot {
        flex-direction: column;
        gap: var(--spacing-xs);
        padding-bottom: var(--spacing-sm);
        border-bottom: 1px solid var(--gray-100);
    }
    
    .time-label {
        width: auto;
        padding-top: 0;
        font-size: 0.875rem;
        color: var(--primary);
        font-weight: 600;
    }
}

/* ===========================
   Mobile Table Responsive
   =========================== */
.show-on-mobile {
    display: none;
}

@media (max-width: 768px) {
    .hide-on-mobile {
        display: none !important;
    }
    
    .show-on-mobile {
        display: inline-block;
    }
    
    .data-table th, .data-table td {
        padding: 0.75rem 0.5rem;
    }
    
    /* Ensure Actions column is visible and aligned */
    .data-table td:last-child {
        text-align: right;
        white-space: nowrap;
    }
}

/* ===========================
   Side Panel Mobile
   =========================== */
@media (max-width: 640px) {
    .side-panel-content {
        max-width: 100%;
        width: 100%;
    }
    
    .side-panel-header {
        padding: var(--spacing-md);
    }
    
    .side-panel-body {
        padding: var(--spacing-md);
    }
}

/* ===========================
   Profile Grid
   =========================== */
.profile-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

@media (min-width: 768px) {
    .profile-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

/* ===========================
   Dialog Modals
   =========================== */
dialog.modal {
    border: none;
    border-radius: var(--radius-lg);
    padding: 0;
    max-width: 600px;
    width: 90%;
    box-shadow: var(--shadow-xl);
    background: white;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
    margin: 0;
}

dialog.modal:not([open]) {
    display: none;
}

dialog.modal[open] {
    display: block;
}

dialog.modal::backdrop {
    background: rgba(0, 0, 0, 0.5);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.modal-content {
    padding: var(--spacing-md);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: var(--spacing-md);
    border-bottom: 1px solid var(--gray-200);
    margin-bottom: var(--spacing-md);
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--gray-500);
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.close-btn:hover {
    color: var(--gray-700);
}

/* Form Actions */
.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-sm);
    padding-top: var(--spacing-md);
    margin-top: var(--spacing-md);
    border-top: 1px solid var(--gray-200);
}

/* Checkbox Labels */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 400;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
}

/* Color Input */
.color-input {
    height: 40px;
    padding: 0.25rem;
    cursor: pointer;
}

