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

:root {
    /* Brand Colors */
    --primary: #0F766E;
    --primary-hover: #115E59;
    --primary-soft: #F0FDFA;
    --primary-light: #CCFBF1;

    /* Backgrounds */
    --bg-main: #F8FAFC;
    --bg-card: #FFFFFF;
    --sidebar-bg: #0F172A;
    --sidebar-text: #94A3B8;
    --sidebar-text-active: #FFFFFF;

    /* Text Colors */
    --text-main: #1E293B;
    --text-muted: #64748B;
    --text-light: #94A3B8;

    /* Borders & Shadows */
    --border-subtle: #E2E8F0;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px 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);

    /* Font */
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;

    /* Layout Dimensions */
    --sidebar-width: 260px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: var(--font-sans);
    background: var(--bg-main);
    color: var(--text-main);
    -webkit-font-smoothing: antialiased;
}

/* App Shell - Container for the whole layout */
.app-shell {
    display: flex;
    width: 100%;
    min-height: 100vh;
    position: relative;
    /* Context for absolute positioning if needed */
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 50;
    /* High z-index to sit above content on mobile */
    top: 0;
    left: 0;
    /* Desktop Default: Visible (handled by media queries below for mobile) */
    transform: translateX(0);
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 32px;
    padding: 0 12px;
}

.sidebar-logo {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    object-fit: contain;
}

.sidebar-title {
    font-weight: 700;
    font-size: 18px;
    color: #fff;
    letter-spacing: -0.025em;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
    /* Allow scrolling if menu is tall */
}

.nav-item {
    border: none;
    background: transparent;
    color: var(--sidebar-text);
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    width: 100%;
}

.nav-item i {
    font-size: 20px;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--sidebar-text-active);
}

.nav-item.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 4px 12px rgba(15, 118, 110, 0.4);
}

/* Sidebar Overlay (Mobile Only) */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(2px);
    z-index: 40;
    /* Below sidebar, above everything else */
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

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

/* --- Main Content --- */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-left: var(--sidebar-width);
    /* Width logic for desktop */
    width: calc(100% - var(--sidebar-width));
    transition: margin-left 0.3s ease, width 0.3s ease;
}

.topbar {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 32px;
    position: sticky;
    top: 0;
    z-index: 30;
    border-bottom: 1px solid var(--border-subtle);
}

/* Hamburger Menu (Hidden on Desktop) */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-main);
    padding: 4px;
    margin-right: 12px;
}

.topbar-title {
    font-weight: 700;
    font-size: 20px;
    color: var(--text-main);
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 16px;
}

.topbar-user-info {
    text-align: right;
}

.topbar-user-info span {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-main);
    display: block;
}

.topbar-user-info small {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
}

.chip.logout-btn {
    border-radius: 99px;
    border: 1px solid var(--border-subtle);
    padding: 8px 16px;
    background: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
    color: var(--text-muted);
}

.chip.logout-btn:hover {
    background: #FEF2F2;
    color: #EF4444;
    border-color: #FECACA;
}

/* --- Layout & Cards --- */
.content {
    padding: 32px;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-subtle);
    transition: transform 0.2s, box-shadow 0.2s;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    /* Allows title and button to wrap on mobile */
    gap: 12px;
}

.card-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-main);
}

/* Stat Cards */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.stat-card {
    background: linear-gradient(135deg, #ffffff 0%, #f8faff 100%);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--border-subtle);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.stat-card::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    width: 64px;
    height: 64px;
    background: radial-gradient(circle at top right, rgba(15, 118, 110, 0.03), transparent 70%);
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
    border-color: var(--primary-light);
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    flex-shrink: 0;
    transition: transform 0.3s ease;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}

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

/* Soft colors for icons - Enhanced with subtle text shadows and gradients */
.soft-green {
    background: #f0fdf4;
    color: #166534;
}

.soft-blue {
    background: #eff6ff;
    color: #1e40af;
}

.soft-beige {
    background: #fffbeb;
    color: #92400e;
}

.soft-orange {
    background: #fff7ed;
    color: #9a3412;
}

.stat-text {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-weight: 700;
    font-size: 28px;
    color: var(--text-main);
    line-height: 1.2;
}

.stat-label {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 4px;
    font-weight: 500;
}

/* --- Tables --- */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    /* Essential for mobile responsiveness */
    -webkit-overflow-scrolling: touch;
    /* Smooth scroll on iOS */
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    white-space: nowrap;
    /* Prevents text wrapping causing messy heights */
}

.data-table thead {
    background: #F1F5F9;
    position: sticky;
    top: 0;
    z-index: 10;
}

.data-table th {
    text-align: left;
    padding: 14px 20px;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.data-table td {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-main);
}

.data-table tbody tr {
    transition: background 0.15s;
}

.data-table tbody tr:hover {
    background: #F8FAFC;
}

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

/* --- Buttons --- */
.btn-primary,
.btn-secondary {
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: #FFFFFF;
    box-shadow: 0 4px 6px -1px rgba(15, 118, 110, 0.2);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 8px -1px rgba(15, 118, 110, 0.3);
}

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

.btn-secondary:hover {
    background: #F8FAFC;
    border-color: #CBD5E1;
}

/* Loading Spinner for buttons */
.btn-loading {
    opacity: 0.8;
    pointer-events: none;
}

.btn-loading::after {
    content: "";
    width: 16px;
    height: 16px;
    margin-left: 8px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* --- Forms --- */
.field-label {
    display: block;
    margin: 0 0 6px 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
}

.form-input,
.form-select,
textarea.form-input {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-subtle);
    font-size: 14px;
    font-family: var(--font-sans);
    outline: none;
    transition: all 0.2s;
    background: white;
    color: var(--text-main);
}

.form-input:focus,
.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-row-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 16px;
}

.form-row-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 16px;
}

.form-row {
    margin-bottom: 16px;
}

/* --- Status Badges --- */
.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 99px;
    font-size: 12px;
    font-weight: 600;
    text-transform: capitalize;
}

.status-badge.active {
    background: #DCFCE7;
    color: #166534;
}

.status-badge.pending {
    background: #FEF3C7;
    color: #92400E;
}

.status-badge.inactive {
    background: #F1F5F9;
    color: #64748B;
}

/* --- Actions --- */
.table-actions {
    display: flex;
    gap: 6px;
}

.table-action-btn {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.table-action-btn.edit {
    background: #E0F2FE;
    color: #0284C7;
}

.table-action-btn.edit:hover {
    background: #BAE6FD;
}

.table-action-btn.delete {
    background: #FEE2E2;
    color: #DC2626;
}

.table-action-btn.delete:hover {
    background: #FECACA;
}

.table-action-btn.attach-quiz {
    background: #DCFCE7;
    color: #16A34A;
}

.table-action-btn.attach-quiz:hover {
    background: #BBF7D0;
}

.table-action-btn.assign-patients-btn {
    width: auto;
    padding: 0 12px;
    font-size: 12px;
    font-weight: 600;
    background: #F3E8FF;
    color: #7E22CE;
}

/* --- Assign Patients Modal Scroll --- */
#assign-patients-modal .modal-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
    min-height: 0;
}

.assign-patient-list {
    max-height: 350px;
    overflow-y: auto;
    padding-right: 4px;
}

.assign-patient-list::-webkit-scrollbar {
    width: 6px;
}

.assign-patient-list::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 3px;
}

.assign-patient-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.assign-patient-list::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* --- Views & Animations --- */
.view {
    display: none;
    animation: fadeIn 0.3s ease-out;
}

.view.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Modals --- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 60;
    /* Higher than sidebar */
    opacity: 0;
    transition: opacity 0.2s;
    padding: 16px;
    /* Padding for mobile so modal doesn't touch edges */
}

.modal-backdrop.open {
    display: flex;
    opacity: 1;
}

.modal {
    background: #FFFFFF;
    border-radius: 20px;
    padding: 0;
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    /* Don't exceed viewport height */
    transform: scale(0.95);
    transition: transform 0.2s;
    overflow: hidden;
}

.modal-backdrop.open .modal {
    transform: scale(1);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.modal-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.modal-close-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.modal-close-btn:hover {
    color: var(--text-main);
}

/* Form wrapper inside modal needs padding and scroll */
.modal form {
    padding: 24px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding-top: 20px;
    flex-shrink: 0;
}

/* Quiz Modal Specifics */
.quiz-modal {
    max-width: 650px;
    height: 80vh;
}

.quiz-scroll-area {
    padding: 24px;
    overflow-y: auto;
    background: #F8FAFC;
    flex: 1;
}

.quiz-modal .modal-footer {
    padding: 16px 24px;
    background: white;
    border-top: 1px solid var(--border-subtle);
    margin-top: 0;
}

.quiz-question-block {
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-sm);
    border-radius: 8px;
    margin-bottom: 16px;
    background: white;
    padding: 20px !important;
}

/* ========================================= */
/* --- RESPONSIVE MEDIA QUERIES --- */
/* ========================================= */

/* Tablet and below (max-width: 1024px) */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
        /* Hidden by default */
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }

    .sidebar.open {
        transform: translateX(0);
        /* Visible when toggled */
    }

    .main {
        margin-left: 0;
        /* Content takes full width */
        width: 100%;
    }

    .menu-toggle {
        display: block;
        /* Show hamburger button */
    }
}

/* Mobile (max-width: 768px) */
@media (max-width: 768px) {
    .topbar {
        padding: 12px 16px;
    }

    .content {
        padding: 16px;
    }

    .card-header {
        flex-direction: row;
        align-items: center;
    }

    .card-header h2 {
        font-size: 16px;
    }

    /* Stack form grids vertically on mobile */
    .form-row-3,
    .form-row-2 {
        grid-template-columns: 1fr !important;
        /* Force single column */
        gap: 12px;
    }

    .stat-card {
        padding: 16px;
    }

    .stat-value {
        font-size: 24px;
    }
}

/* Small Mobile (max-width: 480px) */
@media (max-width: 480px) {
    .topbar-user-info {
        display: none;
        /* Hide Name/Role on very small screens to save space */
    }

    .btn-primary,
    .btn-secondary {
        width: 100%;
        /* Full width buttons for easier tapping */
        justify-content: center;
    }

    .modal-footer {
        flex-direction: column-reverse;
        /* Stack buttons vertically */
        gap: 10px;
    }

    .modal-footer button {
        width: 100%;
    }

    /* Adjust specific input widths */
    #videoPosition {
        width: 100% !important;
    }

    .card-grid {
        grid-template-columns: 1fr;
        /* Single column stats */
    }

    /* Ensure table actions wrap if needed */
    .table-actions {
        flex-wrap: wrap;
    }
}