:root {
    --primary: #2563eb;
    --primary-light: #eff6ff;
    --primary-hover: #1d4ed8;
    --secondary: #0ea5e9;
    --accent: #f59e0b;
    --background: #f4f7fc;
    --surface: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    
    --success: #10b981;
    --success-light: #ecfdf5;
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    
    --purple: #8b5cf6;
    --purple-light: #f3e8ff;
    
    --sidebar-bg: #0f172a;
    --sidebar-text: #94a3b8;
    --sidebar-hover: #2563eb;
    --sidebar-active-text: #ffffff;
    
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.05);
    
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-full: 9999px;
    
    --transition: all 0.2s ease-in-out;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--background);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Layout */
.layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 250px;
    flex-shrink: 0;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 15px rgba(0,0,0,0.05);
    z-index: 10;
    border-top-right-radius: 1.5rem;
    border-bottom-right-radius: 1.5rem;
    position: relative;
    padding-bottom: 2rem;
}

.sidebar-logo {
    background: white;
    margin: 1.5rem;
    padding: 1rem;
    border-radius: var(--radius-lg);
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: var(--shadow-sm);
}

.sidebar nav {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0 1rem;
    margin-top: 1rem;
}

.nav-link {
    color: var(--sidebar-text);
    text-decoration: none;
    padding: 0.85rem 1rem;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 0.9rem;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-link i {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
}

.nav-link:hover, .nav-link.active {
    background-color: var(--sidebar-hover);
    color: var(--sidebar-active-text);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

/* Main Content */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0; /* Important for flex child to not overflow */
}

/* Top Navbar */
.top-navbar {
    height: 70px;
    background: white;
    padding: 0 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.search-bar {
    display: flex;
    align-items: center;
    background: #f1f5f9;
    padding: 0.6rem 1rem;
    border-radius: var(--radius-md);
    width: 350px;
    border: 1px solid #e2e8f0;
}

.search-bar i {
    color: var(--text-muted);
    margin-right: 0.5rem;
}

.search-bar input {
    border: none;
    background: transparent;
    width: 100%;
    outline: none;
    font-size: 0.9rem;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.notification-bell {
    position: relative;
    color: var(--text-muted);
    font-size: 1.25rem;
    cursor: pointer;
    background: #f1f5f9;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.notification-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: var(--danger);
    color: white;
    font-size: 0.65rem;
    font-weight: bold;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
}

.user-profile img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-main);
}

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

/* Main Dashboard Content */
.main-content {
    flex: 1;
    padding: 1.5rem 2rem;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.dashboard-title h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
}

.dashboard-title p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

.dashboard-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}

.date-display {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 500;
    margin-left: 1rem;
    background: white;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    white-space: nowrap;
}

.date-display i {
    font-size: 1.1rem;
    color: var(--primary);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    font-size: 0.85rem;
    gap: 0.5rem;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.2);
}

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

.btn-outline {
    background: white;
    border: 1px solid var(--border);
    color: var(--text-main);
}

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

/* Layout Columns */
.dashboard-columns {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 1.5rem;
    align-items: start;
}

/* Responsive adjustments */
@media (max-width: 1200px) {
    .dashboard-columns {
        grid-template-columns: 1fr;
    }
}

.column-left {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    min-width: 0; /* Prevents overflow */
}

.column-right {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    min-width: 0;
}

/* Top Stat Cards */
.top-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

@media (max-width: 1400px) {
    .top-stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.stat-card-new {
    background: white;
    border-radius: var(--radius-lg);
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    overflow: hidden;
}

.stat-icon-wrapper {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.blue .stat-icon-wrapper { background: var(--primary-light); color: var(--primary); }
.green .stat-icon-wrapper { background: var(--success-light); color: var(--success); }
.orange .stat-icon-wrapper { background: var(--warning-light); color: var(--warning); }
.red .stat-icon-wrapper { background: var(--danger-light); color: var(--danger); }
.purple .stat-icon-wrapper { background: var(--purple-light); color: var(--purple); }

.stat-content {
    flex: 1;
    min-width: 0; 
}

.stat-title {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat-value-row {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1;
}

.stat-change {
    font-size: 0.75rem;
    font-weight: 600;
}
.stat-change.positive { color: var(--success); }

.stat-subtitle {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Middle Section Grid */
.middle-grid {
    display: grid;
    grid-template-columns: 1fr 2fr 1.5fr;
    gap: 1rem;
}

@media (max-width: 1400px) {
    .middle-grid {
        grid-template-columns: 1fr 1fr;
    }
    .emergency-card {
        grid-column: span 2;
    }
}

.emergency-card {
    background: linear-gradient(135deg, #a855f7, #7e22ce);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    color: white;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    overflow: hidden;
    box-shadow: 0 10px 15px -3px rgba(126, 34, 206, 0.3);
}

.emergency-card .stat-icon-wrapper {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    margin-bottom: 1rem;
    width: 40px;
    height: 40px;
    font-size: 1.25rem;
}

.emergency-card .stat-title {
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    white-space: nowrap;
}

.emergency-card .stat-value {
    color: white;
    font-size: 2.5rem;
    font-weight: 800;
    line-height: 1;
}

.emergency-card .stat-subtitle {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.75rem;
    margin-top: 0.5rem;
}

/* Chart Cards */
.chart-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chart-header {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 1rem;
    color: var(--text-main);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chart-header span {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.75rem;
}

.chart-container {
    flex: 1;
    position: relative;
    min-height: 140px; 
    width: 100%;
}

.doughnut-layout {
    display: flex;
    align-items: center;
    height: 100%;
    gap: 1rem;
}

.doughnut-chart-wrapper {
    flex: 1;
    position: relative;
    height: 140px;
    min-width: 0;
}

.doughnut-legend {
    width: 100px;
    flex-shrink: 0;
    font-size: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.legend-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.legend-color {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 0.25rem;
}

.legend-text { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60px; }
.legend-value { font-weight: 600; color: var(--text-main); }

/* Tables */
.table-card {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    padding: 1.25rem;
    overflow-x: auto;
}

.table-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.table-header-flex h3 {
    font-size: 1rem;
    font-weight: 700;
}

.btn-sm {
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
    border-radius: var(--radius-md);
}

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

.data-table th {
    text-transform: uppercase;
    font-size: 0.7rem;
    color: var(--text-muted);
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

.data-table td {
    padding: 0.75rem;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
    font-size: 0.85rem;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.patient-info-cell {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #e2e8f0;
    object-fit: cover;
    flex-shrink: 0;
}

.patient-details strong {
    display: block;
    font-size: 0.85rem;
    color: var(--text-main);
}

.patient-details span {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* Badges */
.badge {
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 600;
    display: inline-block;
    text-align: center;
}
.badge-waiting { background: var(--warning-light); color: #d97706; }
.badge-confirmed { background: var(--success-light); color: var(--success); }
.badge-regular { background: var(--primary-light); color: var(--primary); }
.badge-followup { background: var(--purple-light); color: var(--purple); }
.badge-cataract { background: var(--danger-light); color: var(--danger); }
.badge-glaucoma { background: #dcfce7; color: #15803d; }
.badge-completed { background: #ccfbf1; color: #0f766e; }

/* Right Sidebar Widgets */
.widget {
    background: white;
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.widget-title {
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0;
    border-bottom: 1px solid #f1f5f9;
}
.list-item:last-child { border-bottom: none; padding-bottom: 0; }

.list-item-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0; /* Important */
}

.list-item-info {
    min-width: 0; /* Important for ellipsis */
}

.list-item-info strong {
    display: block;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-item-info span {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* Quick Actions Grid */
.quick-actions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.quick-action-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-size: 0.75rem;
    font-weight: 600;
    text-decoration: none;
    transition: var(--transition);
}

.quick-action-btn:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.qa-icon {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1rem;
}

.qa-icon.new-patient { color: var(--primary); background: var(--primary-light); }
.qa-icon.book-appt { color: var(--success); background: var(--success-light); }
.qa-icon.opd { color: var(--warning); background: var(--warning-light); }
.qa-icon.emergency { color: white; background: var(--danger); }
.quick-action-btn.emergency { border-color: #fca5a5; }

/* Dashboard Login Page Overrides */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--background);
}
.login-card {
    background: white;
    padding: 3rem;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}
.login-header { text-align: center; margin-bottom: 2rem; }
.form-group { margin-bottom: 1.5rem; }
.form-control { width: 100%; padding: 0.75rem; border: 1px solid var(--border); border-radius: var(--radius-md); }
.alert { padding: 1rem; border-radius: var(--radius-md); margin-bottom: 1rem; }
.alert-error { background: #fee2e2; color: #b91c1c; }
