:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --accent: #8b5cf6;
    --secondary: #64748b;
    --bg-light: #f8fafc;
    --white: #ffffff;
    --text-dark: #0f172a;
    --text-muted: #475569;
    --error: #ef4444;
    --success: #10b981;
    --border: rgba(255, 255, 255, 0.2);
    --glass-bg: rgba(255, 255, 255, 0.7);
    --shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
    background-color: var(--bg-light);
    color: var(--text-dark);
    line-height: 1.5;
}

/* Utils */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.hidden {
    display: none !important;
}

/* Premium Auth Redesign */
.auth-wrapper {
    min-height: 100vh;
    background: radial-gradient(circle at top right, #e0e7ff, #f8fafc, #f1f5f9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-container {
    width: 100%;
    max-width: 1000px;
    text-align: center;
}

.role-selector {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    margin-top: 40px;
}

.role-card {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    padding: 40px;
    border-radius: 20px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    text-align: center;
}

.role-card:hover {
    transform: translateY(-10px);
    background: var(--white);
    border-color: var(--primary);
}

.role-card i {
    font-size: 3rem;
    margin-bottom: 20px;
    display: block;
    color: var(--primary);
}

.role-card h3 {
    font-size: 1.5rem;
    margin-bottom: 10px;
    color: var(--text-dark);
}

.role-card p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.login-form-container {
    background: var(--white);
    padding: 40px;
    border-radius: 24px;
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 450px;
    margin: 40px auto;
}

.back-btn {
    display: inline-block;
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    margin-bottom: 20px;
    cursor: pointer;
    transition: 0.3s;
}

.back-btn:hover {
    color: var(--primary-dark);
    transform: translateX(-5px);
}

/* Global Form Styles */
.form-group {
    margin-bottom: 20px;
    text-align: left;
}

.form-group label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 8px;
}

.form-group input, 
.form-group select, 
.form-group textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid #e2e8f0;
    border-radius: 12px;
    font-size: 1rem;
    transition: all 0.3s;
    outline: none;
    background: #f8fafc;
}

.form-group input:focus {
    border-color: var(--primary);
    background: var(--white);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.btn {
    display: inline-block;
    padding: 12px 24px;
    border-radius: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    border: none;
    width: 100%;
    font-size: 1rem;
    text-align: center;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-secondary {
    background: #e2e8f0;
    color: #475569;
}

.btn-secondary:hover {
    background: #cbd5e1;
}

.error-message {
    color: var(--error);
    font-size: 0.85rem;
    margin-top: 10px;
    font-weight: 500;
}

/* Dashboard Modules */
.card {
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 20px;
    padding: 24px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    margin-bottom: 24px;
    transition: 0.3s;
}

.card:hover {
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.08);
}

.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

th {
    text-align: left;
    padding: 12px;
    background: var(--bg-light);
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    font-size: 0.9375rem;
}

.search-bar {
    width: 100%;
    max-width: 400px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 20px;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--white);
    padding: 30px;
    border-radius: 12px;
    width: 100%;
    max-width: 500px;
}

.dashboard-container { 
    display: grid; 
    grid-template-columns: 260px 1fr; 
    min-height: 100vh; 
    background: #f8fafc;
}

.sidebar { background: #1e293b; color: #f8fafc; padding: 24px; position: sticky; top: 0; height: 100vh; z-index: 1000; }

.sidebar h2 { font-size: 1.25rem; margin-bottom: 30px; font-weight: 800; color: #cbd5e1; }
.nav-link { display: block; color: #94a3b8; text-decoration: none; padding: 12px; border-radius: 8px; margin-bottom: 8px; transition: 0.2s; font-weight: 600; }
.nav-link:hover, .nav-link.active { background: #334155; color: #fff; }
.main-content { padding: 40px; background: #f8fafc; min-height: 100vh; }
header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 30px; position: relative; }

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-pending { background: #fef3c7; color: #92400e; }
.badge-confirmed { background: #dcfce7; color: #166534; }
.badge-inprogress { background: #dbeafe; color: #1e40af; animation: pulse 2s infinite; }
.badge-completed { background: #f1f5f9; color: #475569; }

/* Dashboard Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--white);
    padding: 20px;
    border-radius: 16px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    display: flex;
    align-items: center;
    gap: 16px;
    border: 1px solid rgba(0,0,0,0.05);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.stat-info h3 {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 2px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 700;
}

.stat-info .stat-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-dark);
}

/* Responsive Dashboard */
@media (max-width: 1024px) {
    .dashboard-container {
        grid-template-columns: 200px 1fr;
    }
}

@media (max-width: 768px) {
    .dashboard-container {
        grid-template-columns: 1fr;
    }
    .sidebar {
        display: none;
    }
    .main-content {
        padding: 20px;
    }
    .grid-2 {
        grid-template-columns: 1fr;
    }
}

/* Loading States */
.loader {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
    margin-right: 8px;
}

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

input:disabled, button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* Print Styles */
@media print {
    body { background: white; }
    .sidebar, header, .btn, .nav-link, .modal-overlay, #patients-view, #appointments-view, #billing-view {
        display: none !important;
    }
    .main-content { padding: 0; }
    .card { box-shadow: none; border: 1px solid #eee; }
    #prescriptions-view { display: block !important; }
    #add-prescription-form { border: none; }
    textarea { border: none; font-size: 1.1rem; }
}

@keyframes pulse {
    0% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.8; transform: scale(0.98); }
    100% { opacity: 1; transform: scale(1); }
}

/* Clinical UI Components */
.toast { 
    position: fixed; 
    bottom: 20px; 
    left: 50%; 
    transform: translateX(-50%); 
    padding: 12px 24px; 
    border-radius: 8px; 
    color: white; 
    font-weight: bold; 
    z-index: 10000; 
    transition: 0.3s; 
    box-shadow: 0 4px 12px rgba(0,0,0,0.1); 
    pointer-events: none;
}

.current-patient-card { 
    border-left: 10px solid var(--primary); 
    background: #fff; 
    padding: 25px; 
    margin-bottom: 30px; 
    border-radius: 16px; 
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1); 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
}

.status-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.dot-waiting { background: #f59e0b; }
.dot-inprogress { background: #3b82f6; }
.dot-done { background: #10b981; }

.badge-waiting { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.badge-inprogress { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; animation: pulse 2s infinite; }
.badge-done { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.badge-normal { background: #e0e7ff; color: #3730a3; border: 1px solid #c7d2fe; }
.badge-urgent { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.badge-followup { background: #f1f5f9; color: #475569; border: 1px solid #e2e8f0; }

[dir="rtl"] .current-patient-card {
    border-left: none;
    border-right: 10px solid var(--primary);
}


/* RTL Support */
[dir="rtl"] {
    font-family: 'Cairo', sans-serif;
    text-align: right;
}

[dir="rtl"] .dashboard-container {
    grid-template-columns: 260px 1fr;
    direction: rtl;
}

[dir="rtl"] .sidebar {
    border-left: none;
    border-right: 1px solid rgba(255,255,255,0.1);
}

[dir="rtl"] .stat-card {
    flex-direction: row-reverse;
}

[dir="rtl"] .current-patient-card {
    border-left: none;
    border-right: 10px solid #6366f1;
}

[dir="rtl"] table th, [dir="rtl"] table td {
    text-align: right;
}

[dir="rtl"] .badge {
    margin-right: 0;
    margin-left: 8px;
}

[dir="rtl"] .stat-icon {
    margin-right: 0;
    margin-left: 20px;
}

[dir="rtl"] .stat-card {
    display: flex;
    flex-direction: row; /* Icon on right, info on left in RTL */
    text-align: right;
}

[dir="rtl"] .stat-info h3 {
    text-align: right;
}

[dir="rtl"] .sidebar h2 {
    text-align: right;
}

[dir="rtl"] .nav-link {
    text-align: right;
}


[dir="rtl"] .grid-2 {
    direction: rtl;
}

[dir="rtl"] .modal-content {
    text-align: right;
}

[dir="rtl"] .back-btn i {
    transform: rotate(180deg);
}

@media (max-width: 1024px) {
    [dir="rtl"] .dashboard-container {
        grid-template-columns: 200px 1fr;
    }
}
@media (max-width: 768px) {
    [dir="rtl"] .dashboard-container {
        grid-template-columns: 1fr;
    }
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    .dashboard-container {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        left: -260px;
        z-index: 1000;
        transition: 0.3s;
        width: 260px;
        box-shadow: 10px 0 30px rgba(0,0,0,0.1);
    }

    [dir="rtl"] .sidebar {
        left: auto;
        right: -260px;
    }

    .sidebar.active {
        left: 0;
    }

    [dir="rtl"] .sidebar.active {
        right: 0;
    }

    .main-content {
        padding: 15px;
        padding-top: 80px; /* Space for fixed header if needed */
    }

    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        margin-bottom: 25px;
    }

    .header-left {
        display: flex;
        align-items: center;
        width: 100%;
        justify-content: flex-start;
    }

    #page-title {
        font-size: 1.5rem !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    #realtme-status {
        position: absolute;
        top: -10px;
        right: 0;
        font-size: 0.7rem !important;
    }

    /* Fixed FAB for mobile */
    .mobile-fab {
        display: flex !important;
        position: fixed;
        bottom: 30px;
        right: 30px;
        width: 60px;
        height: 60px;
        background: var(--primary);
        color: white;
        border-radius: 50%;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
        z-index: 2000;
        font-size: 1.5rem;
        border: none;
    }

    [dir="rtl"] .mobile-fab {
        right: auto;
        left: 30px;
    }

    .card h2 {
        font-size: 1.2rem;
    }

    /* Table to Card Refinement */
    table, thead, tbody, th, td, tr { 
        display: block; 
    }
    
    thead tr { 
        position: absolute; 
        top: -9999px; 
        left: -9999px; 
    }
    
    tr { 
        padding: 20px;
        border: none;
        box-shadow: 0 4px 12px rgba(0,0,0,0.05);
        margin-bottom: 20px;
        border-radius: 16px;
        background: white;
    }
    
    td { 
        border: none; 
        position: relative; 
        padding: 12px 0 12px 45% !important; 
        text-align: right !important;
        border-bottom: 1px solid #f1f5f9 !important;
        min-height: 45px;
        display: flex;
        align-items: center;
        justify-content: flex-end;
    }

    [dir="rtl"] td {
        padding-left: 0 !important;
        padding-right: 45% !important;
        text-align: left !important;
        justify-content: flex-start;
    }

    td:last-child {
        border-bottom: none !important;
    }

    td:before { 
        content: attr(data-label); 
        position: absolute; 
        left: 10px; 
        width: 40%; 
        white-space: nowrap; 
        font-weight: 800; 
        color: var(--text-muted);
        text-align: left;
        font-size: 0.65rem;
        text-transform: uppercase;
        opacity: 0.7;
    }

    [dir="rtl"] td:before {
        left: auto;
        right: 10px;
        text-align: right;
    }


    .stats-grid {
        gap: 15px;
    }

    .stat-card {
        padding: 15px;
    }

    .hamburger-menu {
        margin-right: 10px;
        width: 40px;
        height: 40px;
        display: flex !important;
        align-items: center;
        justify-content: center;
    }
}

.mobile-fab { display: none; }


[dir="rtl"] .nav-link i {
    margin-right: 0;
    margin-left: 12px;
}

[dir="rtl"] header {
    flex-direction: row; /* Grid item, don't force reverse if direction is rtl */
    justify-content: space-between;
}

[dir="rtl"] .current-patient-card {
    flex-direction: row;
    border-left: none;
    border-right: 10px solid #6366f1;
}

[dir="rtl"] .modal-content {
    text-align: right;
}

[dir="rtl"] .form-group label {
    display: block;
    text-align: right;
}

[dir="rtl"] .btn i {
    margin-right: 0;
    margin-left: 8px;
}

[dir="rtl"] .status-dot {
    margin-right: 0;
    margin-left: 6px;
}

