/* ==========================================================================
   حصتي (Hesaty) - النظام الذكي لإدارة وجدولة الحصص المدرسية
   Design System & RTL Stylesheet (PHP 7.4 + SQLite Optimized)
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;500;600;700;800;900&family=Outfit:wght@400;600;700&display=swap');

:root {
    --font-arabic: 'Cairo', system-ui, -apple-system, sans-serif;
    --font-code: 'Outfit', monospace;

    /* Theme Customizer Variables (قابل للتخصيص الحي) */
    --site-bg: #f1f5f9;
    --sidebar-bg: #0f172a;
    --timetable-index-bg: #0f172a;
    --timetable-index-text: #ffffff;

    /* Primary Palette */
    --primary-50: #eff6ff;
    --primary-100: #dbeafe;
    --primary-500: #3b82f6;
    --primary-600: #2563eb;
    --primary-700: #1d4ed8;
    --primary-900: #1e3a8a;

    /* Neutrals */
    --slate-50: #f8fafc;
    --slate-100: #f1f5f9;
    --slate-200: #e2e8f0;
    --slate-300: #cbd5e1;
    --slate-400: #94a3b8;
    --slate-500: #64748b;
    --slate-600: #475569;
    --slate-700: #334155;
    --slate-800: #1e293b;
    --slate-900: #0f172a;

    /* Semantic Status */
    --success-bg: #ecfdf5;
    --success-border: #a7f3d0;
    --success-text: #065f46;
    --success-icon: #10b981;

    --warning-bg: #fffbeb;
    --warning-border: #fde68a;
    --warning-text: #92400e;
    --warning-icon: #f59e0b;

    --danger-bg: #fef2f2;
    --danger-border: #fecaca;
    --danger-text: #991b1b;
    --danger-icon: #ef4444;

    --info-bg: #f0f9ff;
    --info-border: #bae6fd;
    --info-text: #075985;
    --info-icon: #0284c7;

    /* Dimensions & Radii */
    --sidebar-width: 260px;
    --header-height: 70px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    direction: rtl;
    text-align: right;
    font-family: var(--font-arabic);
    font-size: 14.5px;
    line-height: 1.6;
    background-color: var(--site-bg);
    color: var(--slate-800);
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
    transition: background-color var(--transition-normal);
}

/* App Container */
.app-container {
    display: flex;
    width: 100%;
    min-height: 100vh;
    background-color: var(--site-bg);
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: #f8fafc;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    z-index: 40;
    transition: transform var(--transition-normal);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
}

.sidebar-header {
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-icon {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

.brand-text h1 {
    font-size: 19px;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: #ffffff;
}

.brand-text p {
    font-size: 11px;
    color: #94a3b8;
    margin-top: -2px;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 20px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-nav button,
.sidebar-nav span {
    color: #ffffff;
    font-weight: 700;
}

.nav-category {
    font-size: 12px;
    font-weight: 700;
    color: #ffffff !important;
    text-transform: uppercase;
    padding: 12px 14px 6px;
    letter-spacing: 0.5px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    color: #ffffff !important;
    text-decoration: none;
    font-weight: 700 !important;
    font-size: 14px;
    transition: all var(--transition-fast);
    cursor: pointer;
    border: none;
    background: transparent;
    width: 100%;
    text-align: right;
}

.nav-item span {
    color: #ffffff !important;
    font-weight: 700 !important;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff !important;
    transform: translateX(-3px);
}

.nav-item.active {
    background: #2563eb;
    color: #ffffff !important;
    font-weight: 700 !important;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.nav-item .icon {
    font-size: 18px;
    width: 24px;
    display: flex;
    justify-content: center;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    color: #ffffff;
    font-weight: 700;
}

.sidebar-settings-group {
    margin-top: 24px;
    padding-top: 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-scrollable-footer {
    margin-top: 24px;
    padding-top: 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item-settings {
    color: #ffffff !important;
    font-weight: 700 !important;
    opacity: 1;
    font-size: 13.5px;
}

.nav-item-settings:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.12);
}

.sidebar-term-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 12.5px;
    font-weight: 600;
    color: #38bdf8;
    background: rgba(56, 189, 248, 0.12);
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid rgba(56, 189, 248, 0.22);
}

.sidebar-logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    background: rgba(239, 68, 68, 0.12);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.25);
    border-radius: 8px;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--font-arabic);
}

.sidebar-logout-btn:hover {
    background: rgba(239, 68, 68, 0.28);
    color: #ffffff;
    border-color: #ef4444;
}

.sidebar-version-info {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: #64748b;
    padding-top: 2px;
}

.btn-icon-square {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 6px;
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    color: #334155;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-icon-square:hover {
    background: #e2e8f0;
    border-color: #94a3b8;
    transform: translateY(-1px);
}

/* Main Area */
.main-wrapper {
    flex: 1;
    margin-right: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header - Two Rows Layout */
.top-header {
    height: auto;
    min-height: 95px;
    background: #ffffff;
    border-bottom: 1px solid var(--slate-200);
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 10px 24px;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 30;
    box-shadow: var(--shadow-sm);
}

.header-row-1 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding-bottom: 8px;
    border-bottom: 1px solid #f1f5f9;
}

.header-row-2 {
    display: flex;
    align-items: center;
    width: 100%;
}

.school-section {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-and-user-section {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-actions-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
}

.normal-font {
    font-weight: 500 !important;
    font-size: 12.5px !important;
    letter-spacing: normal !important;
}

.inline-block {
    display: inline-flex !important;
    vertical-align: middle;
}

.status-btn-normal {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: var(--radius-md);
    font-size: 12.5px;
    font-weight: 500;
    font-family: var(--font-arabic);
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 1px solid transparent;
    white-space: nowrap;
}

.status-btn-normal.draft {
    background: #fffbeb;
    color: #92400e;
    border-color: #fde68a;
}

.status-btn-normal.draft:hover {
    background: #fef3c7;
}

.status-btn-normal.approved {
    background: #ecfdf5;
    color: #065f46;
    border-color: #a7f3d0;
}

.status-btn-normal.approved:hover {
    background: #d1fae5;
}

.btn-action-bar {
    background: #f8fafc;
    color: var(--slate-700);
    border: 1px solid var(--slate-200);
    padding: 5px 11px;
    border-radius: var(--radius-md);
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-arabic);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

.btn-action-bar:hover {
    background: #f1f5f9;
    border-color: var(--slate-300);
    color: var(--slate-900);
}

.btn-action-bar.btn-primary-action {
    background: var(--primary-600);
    color: #ffffff;
    border-color: var(--primary-600);
}

.btn-action-bar.btn-primary-action:hover {
    background: var(--primary-700);
}

.timetable-selector {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--slate-50);
    padding: 4px 10px;
    border-radius: var(--radius-md);
    border: 1px solid var(--slate-200);
    white-space: nowrap;
}

.user-pill-container {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--slate-100);
    padding: 3px 10px;
    border-radius: var(--radius-full);
    white-space: nowrap;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.school-badge {
    display: flex;
    align-items: center;
    gap: 10px;
}

.school-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--slate-900);
}

.term-pill {
    background: var(--slate-100);
    color: var(--slate-600);
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 500;
}

.timetable-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--slate-50);
    padding: 6px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--slate-200);
}

.timetable-selector select {
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--slate-800);
    outline: none;
    cursor: pointer;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 700;
}

.status-badge.draft {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}

.status-badge.approved {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.status-badge.archived {
    background: var(--slate-200);
    color: var(--slate-600);
}

/* Action Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 1px solid transparent;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary-600);
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
}

.btn-primary:hover {
    background: var(--primary-700);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.35);
}

.btn-success {
    background: #10b981;
    color: #ffffff;
}

.btn-success:hover {
    background: #059669;
}

.btn-secondary {
    background: #ffffff;
    border-color: var(--slate-300);
    color: var(--slate-700);
}

.btn-secondary:hover {
    background: var(--slate-50);
    border-color: var(--slate-400);
}

.btn-danger {
    background: var(--danger-icon);
    color: #ffffff;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
    border-radius: var(--radius-sm);
}

/* Page Content */
.content-area {
    padding: 28px;
    flex: 1;
}

.view-panel {
    display: none;
}

.view-panel.active {
    display: block;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Dashboard Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 28px;
}

.stat-card {
    background: #ffffff;
    padding: 22px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--slate-200);
    display: flex;
    align-items: center;
    gap: 18px;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.stat-icon.blue { background: #eff6ff; color: #2563eb; }
.stat-icon.green { background: #ecfdf5; color: #10b981; }
.stat-icon.amber { background: #fffbeb; color: #f59e0b; }
.stat-icon.purple { background: #faf5ff; color: #9333ea; }

.stat-info h3 {
    font-size: 26px;
    font-weight: 800;
    color: var(--slate-900);
    line-height: 1.1;
    font-family: var(--font-code);
}

.stat-info p {
    font-size: 13px;
    color: var(--slate-500);
    margin-top: 4px;
    font-weight: 500;
}

/* Section Header */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 14px;
}

.section-title {
    font-size: 20px;
    font-weight: 800;
    color: var(--slate-900);
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Timetable Toolbar */
.timetable-toolbar {
    background: #ffffff;
    padding: 16px 20px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--slate-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.filter-label {
    font-size: 13px;
    font-weight: 700;
    color: var(--slate-600);
}

.filter-select {
    padding: 7px 14px;
    border: 1px solid var(--slate-300);
    border-radius: var(--radius-md);
    background-color: var(--slate-50);
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--slate-800);
    outline: none;
    cursor: pointer;
    transition: border-color var(--transition-fast);
}

.filter-select:focus {
    border-color: var(--primary-500);
    background-color: #ffffff;
}

.view-tabs {
    display: flex;
    background: var(--slate-100);
    padding: 4px;
    border-radius: var(--radius-md);
    gap: 4px;
}

.view-tab {
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    color: var(--slate-600);
    border: none;
    background: transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.view-tab.active {
    background: #ffffff;
    color: var(--primary-600);
    font-weight: 700;
    box-shadow: var(--shadow-sm);
}

/* Timetable Matrix Grid */
.timetable-container {
    background: #ffffff;
    border-radius: var(--radius-lg);
    border: 1px solid var(--slate-200);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.timetable-grid {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.timetable-grid th, .timetable-grid td {
    border: 1px solid var(--slate-200);
    text-align: center;
    vertical-align: middle;
}

.timetable-grid th {
    background: var(--slate-50);
    padding: 12px 8px;
    font-size: 13px;
    font-weight: 700;
    color: var(--slate-700);
}

.timetable-grid th.day-header {
    width: 110px;
    background: var(--timetable-index-bg);
    color: var(--timetable-index-text);
    font-size: 14px;
    font-weight: 800;
    transition: background-color var(--transition-normal);
}

.period-header-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.period-name {
    font-weight: 700;
    font-size: 13.5px;
}

.period-time {
    font-size: 11px;
    font-family: var(--font-code);
    color: var(--slate-500);
    direction: ltr;
}

/* Lesson Cell */
.lesson-cell {
    min-height: 90px;
    height: 96px;
    padding: 6px;
    position: relative;
    transition: background-color var(--transition-fast);
}

.lesson-cell.empty-slot {
    background-color: #fafbfc;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.lesson-cell.empty-slot:hover {
    background-color: #f0fdf4 !important;
    border: 2px dashed #10b981 !important;
}

.empty-slot-prompt {
    color: #94a3b8;
    font-size: 11.5px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 100%;
}

.lesson-cell.empty-slot:hover .empty-slot-prompt {
    color: #059669;
    font-weight: 700;
}

.badge-delete {
    font-size: 11px;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity var(--transition-fast);
    color: #ef4444;
}

.badge-delete:hover {
    opacity: 1;
    color: #b91c1c;
}

/* Action Buttons for Management Tables */
.action-btns {
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-action-edit {
    background: #eff6ff;
    color: #2563eb;
    border: 1px solid #bfdbfe;
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-action-edit:hover {
    background: #2563eb;
    color: #ffffff;
}

.btn-action-delete {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-action-delete:hover {
    background: #dc2626;
    color: #ffffff;
}

/* Sub Tabs for Management Sections */
.sub-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 18px;
    border-bottom: 2px solid var(--slate-200);
    padding-bottom: 2px;
}

.sub-tab {
    padding: 8px 18px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--slate-600);
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    margin-bottom: -2px;
}

.sub-tab:hover {
    color: var(--primary-600);
}

.sub-tab.active {
    color: var(--primary-600);
    font-weight: 800;
    border-bottom-color: var(--primary-600);
}

.lesson-card {
    height: 100%;
    border-radius: var(--radius-md);
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
    cursor: grab;
    user-select: none;
    position: relative;
    border-right: 4px solid var(--primary-600);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    background: #ffffff;
}

.lesson-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.1);
}

.lesson-card:active {
    cursor: grabbing;
}

.lesson-card.is-pinned {
    border-left: 3px solid #f59e0b;
}

.lesson-card.is-double {
    background: linear-gradient(to left, rgba(239, 246, 255, 0.5), #ffffff);
}

.lesson-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.subject-name {
    font-weight: 800;
    font-size: 14px;
    color: var(--slate-900);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lesson-badges {
    display: flex;
    align-items: center;
    gap: 4px;
}

.badge-pin {
    font-size: 11px;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity var(--transition-fast);
}

.badge-pin:hover, .badge-pin.active {
    opacity: 1;
    color: #f59e0b;
}

.badge-double {
    font-size: 10px;
    background: #dbeafe;
    color: #1e40af;
    padding: 1px 5px;
    border-radius: 4px;
    font-weight: 700;
}

.lesson-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 4px;
}

.teacher-tag {
    font-size: 12px;
    font-weight: 600;
    color: var(--slate-600);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.room-tag {
    font-size: 10.5px;
    background: var(--slate-100);
    color: var(--slate-600);
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
}

/* Break & Assembly Cells */
.break-cell {
    background: #f8fafc;
    color: var(--slate-400);
    font-weight: 600;
    font-size: 12px;
    letter-spacing: 1px;
}

/* Drag & Drop Feedback */
.lesson-card.dragging {
    opacity: 0.4;
    transform: scale(0.95);
}

.lesson-cell.drag-over-valid {
    background-color: rgba(16, 185, 129, 0.15) !important;
    border: 2px dashed #10b981 !important;
}

.lesson-cell.drag-over-invalid {
    background-color: rgba(239, 68, 68, 0.15) !important;
    border: 2px dashed #ef4444 !important;
}

/* Selected for Swap */
.lesson-card.selected-for-swap {
    box-shadow: 0 0 0 3px #2563eb, 0 6px 15px rgba(37, 99, 235, 0.3);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

/* Readiness Report Card */
.readiness-banner {
    padding: 16px 20px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.readiness-banner.ready {
    background: var(--success-bg);
    border: 1px solid var(--success-border);
    color: var(--success-text);
}

.readiness-banner.not-ready {
    background: var(--danger-bg);
    border: 1px solid var(--danger-border);
    color: var(--danger-text);
}

.issues-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 14px;
}

.issue-item {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: flex-start;
    gap: 12px;
    font-size: 13.5px;
}

.issue-item.blocking {
    background: #fef2f2;
    border-right: 4px solid #ef4444;
    color: #991b1b;
}

.issue-item.warning {
    background: #fffbeb;
    border-right: 4px solid #f59e0b;
    color: #92400e;
}

/* Modal Dialogs */
.modal-overlay {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 50;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.modal-dialog {
    background: #ffffff;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 650px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-xl);
    overflow: hidden;
}

.modal-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--slate-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--slate-50);
}

.modal-title {
    font-size: 17px;
    font-weight: 800;
    color: var(--slate-900);
}

.modal-close {
    background: transparent;
    border: none;
    font-size: 20px;
    color: var(--slate-400);
    cursor: pointer;
    line-height: 1;
}

.modal-close:hover {
    color: var(--slate-800);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--slate-200);
    background: var(--slate-50);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
}

/* Candidate Teachers List in Replacement Modal */
.candidate-section {
    margin-bottom: 20px;
}

.candidate-section-title {
    font-size: 13px;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--slate-200);
}

.candidate-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--slate-200);
    margin-bottom: 8px;
    transition: all var(--transition-fast);
    cursor: pointer;
}

.candidate-item:hover {
    border-color: var(--primary-500);
    background: var(--primary-50);
}

.candidate-item.selected {
    border-color: var(--primary-600);
    background: #eff6ff;
    box-shadow: 0 0 0 2px var(--primary-600);
}

.candidate-item.disabled {
    opacity: 0.6;
    background: var(--slate-50);
    cursor: not-allowed;
    border-style: dashed;
}

.candidate-item.disabled:hover {
    border-color: var(--slate-200);
    background: var(--slate-50);
}

.candidate-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.candidate-name {
    font-weight: 700;
    font-size: 14px;
    color: var(--slate-900);
}

.candidate-role {
    font-size: 12px;
    color: var(--slate-500);
}

.candidate-reason {
    font-size: 12px;
    color: var(--danger-text);
    font-weight: 600;
}

/* Table Styles for Management Screens */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: #ffffff;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--slate-200);
}

.data-table th {
    background: var(--slate-50);
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 700;
    color: var(--slate-700);
    border-bottom: 1px solid var(--slate-200);
    text-align: right;
}

.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--slate-200);
    font-size: 13.5px;
    color: var(--slate-800);
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover td {
    background-color: var(--slate-50);
}

/* Form Styles */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: var(--slate-700);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 9px 14px;
    border: 1px solid var(--slate-300);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 14px;
    color: var(--slate-900);
    outline: none;
    transition: border-color var(--transition-fast);
}

.form-control:focus {
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

/* Solver Center Styling */
.solver-card {
    background: #ffffff;
    border-radius: var(--radius-lg);
    border: 1px solid var(--slate-200);
    padding: 32px;
    max-width: 980px;
    margin: 0 auto;
    box-shadow: var(--shadow-md);
    text-align: center;
}

/* لوحة خيارات وفلاتر التوليد المتقدمة */
.solver-filters-box {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 20px;
    margin: 20px 0;
    text-align: right;
}
.solver-filters-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e2e8f0;
    flex-wrap: wrap;
    gap: 10px;
}
.solver-filters-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 800;
    color: #0f172a;
}
.solver-filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}
.solver-filter-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: relative;
}
.solver-filter-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    font-weight: 700;
    color: #334155;
}
.filter-count-badge {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    background: #e0f2fe;
    color: #0369a1;
    transition: all 0.2s;
}
.filter-count-badge.custom {
    background: #fef3c7;
    color: #b45309;
}
.custom-multiselect {
    position: relative;
    width: 100%;
}
.multiselect-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s ease;
    min-height: 40px;
    box-sizing: border-box;
}
.multiselect-trigger:hover, .multiselect-trigger:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}
.multiselect-trigger .trigger-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 90%;
}
.multiselect-trigger .trigger-arrow {
    font-size: 11px;
    color: #64748b;
    transition: transform 0.2s ease;
}
.custom-multiselect.open .trigger-arrow {
    transform: rotate(180deg);
}
.multiselect-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.12), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
    z-index: 1050;
    max-height: 270px;
    flex-direction: column;
}
.custom-multiselect.open .multiselect-dropdown {
    display: flex;
}
.multiselect-actions {
    display: flex;
    justify-content: space-between;
    padding: 6px 10px;
    background: #f1f5f9;
    border-bottom: 1px solid #e2e8f0;
    border-radius: 8px 8px 0 0;
}
.multiselect-actions button {
    background: none;
    border: none;
    font-size: 11.5px;
    font-weight: 700;
    cursor: pointer;
    padding: 3px 8px;
    border-radius: 4px;
    transition: background 0.15s;
}
.multiselect-actions .btn-select-all {
    color: #2563eb;
}
.multiselect-actions .btn-select-all:hover {
    background: #dbeafe;
}
.multiselect-actions .btn-clear-all {
    color: #dc2626;
}
.multiselect-actions .btn-clear-all:hover {
    background: #fee2e2;
}
.multiselect-search-box {
    padding: 6px 10px;
    border-bottom: 1px solid #f1f5f9;
}
.multiselect-search {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 12px;
    outline: none;
    box-sizing: border-box;
}
.multiselect-search:focus {
    border-color: #3b82f6;
}
.multiselect-options {
    overflow-y: auto;
    max-height: 180px;
    padding: 4px 0;
}
.multiselect-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    font-size: 12.5px;
    font-weight: 500;
    color: #334155;
    cursor: pointer;
    transition: background 0.12s;
    user-select: none;
}
.multiselect-option:hover {
    background: #f8fafc;
}
.multiselect-option.all-option {
    font-weight: 700;
    color: #0f172a;
    background: #f8fafc;
    border-bottom: 1px dashed #e2e8f0;
}
.multiselect-option.all-option:hover {
    background: #f1f5f9;
}
.multiselect-option input[type="checkbox"] {
    cursor: pointer;
    width: 15px;
    height: 15px;
    accent-color: #2563eb;
}
.badge-all-active {
    font-size: 12px;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 20px;
    background: #ecfdf5;
    color: #047857;
    border: 1px solid #a7f3d0;
}
.badge-scoped-active {
    font-size: 12px;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 20px;
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
}

.solver-progress-bar {
    width: 100%;
    height: 12px;
    background: var(--slate-100);
    border-radius: var(--radius-full);
    overflow: hidden;
    margin: 20px 0;
    position: relative;
}

.solver-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #3b82f6, #10b981);
    transition: width 0.3s ease;
}

.solver-progress-fill.indeterminate {
    width: 40%;
    position: absolute;
    animation: solverSlide 1.5s infinite ease-in-out;
}

@keyframes solverSlide {
    0% { right: -40%; }
    100% { right: 100%; }
}

/* ==========================================================================
   طباعة الجداول المدرسية الرسمية (@media print)
   تنسيق A4 و A3 بالعرض وبالطول، مع الترويسة المعتمدة وعلامة المسودة
   ========================================================================== */

.print-only {
    display: none !important;
}

@media print {
    /* إخفاء عناصر التحكم والأشرطة الجانبية */
    .sidebar,
    .top-header,
    .timetable-toolbar,
    .btn,
    .badge-pin,
    .modal-overlay,
    #btnScopeClearTimetable,
    #modalConfirmClear,
    #modalBackupPrompt,
    .no-print {
        display: none !important;
    }

    body {
        background: #ffffff !important;
        color: #000000 !important;
        font-size: 11pt !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .main-wrapper {
        margin-right: 0 !important;
        width: 100% !important;
    }

    .content-area {
        padding: 0 !important;
    }

    .print-only {
        display: block !important;
    }

    /* الترويسة المدرسية الرسمية */
    .official-header {
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        border-bottom: 2px solid #000000;
        padding-bottom: 12px;
        margin-bottom: 15px;
    }

    .header-col {
        text-align: center;
    }

    .header-col.right { text-align: right; }
    .header-col.left { text-align: left; }

    .header-col h2 {
        font-size: 15pt;
        font-weight: 800;
        margin-bottom: 2px;
    }

    .header-col p {
        font-size: 10pt;
        color: #333333;
        margin: 0;
    }

    .print-title {
        font-size: 16pt;
        font-weight: 900;
        text-align: center;
        margin-bottom: 10px;
    }

    /* شبكة الجدول أثناء الطباعة */
    .timetable-container {
        border: 1.5px solid #000000 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
    }

    .timetable-grid {
        border-collapse: collapse !important;
    }

    .timetable-grid th, .timetable-grid td {
        border: 1px solid #000000 !important;
        padding: 6px 4px !important;
    }

    .timetable-grid th {
        background-color: #f0f0f0 !important;
        color: #000000 !important;
        font-weight: 700 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .lesson-card {
        border: none !important;
        box-shadow: none !important;
        padding: 4px !important;
        background: transparent !important;
    }

    .subject-name {
        font-size: 11pt !important;
        font-weight: 800 !important;
    }

    .teacher-tag {
        font-size: 9pt !important;
        color: #333333 !important;
    }

    /* تذييل الاعتمادات والتوقيعات الرسمية */
    .official-footer {
        display: flex !important;
        justify-content: space-between;
        margin-top: 30px;
        padding-top: 10px;
        page-break-inside: avoid;
    }

    .signature-box {
        text-align: center;
        width: 28%;
    }

    .signature-box .role {
        font-weight: 700;
        font-size: 11pt;
        margin-bottom: 45px;
    }

    .signature-box .name {
        border-top: 1px dotted #000000;
        padding-top: 5px;
        font-size: 10pt;
    }

    /* العلامة المائية للمسودة */
    .watermark-draft {
        position: fixed;
        top: 40%;
        left: 20%;
        transform: rotate(-30deg);
        font-size: 70pt;
        font-weight: 900;
        color: rgba(200, 200, 200, 0.35) !important;
        z-index: 1000;
        pointer-events: none;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

/* ==========================================================================
   Sub-Tabs & Management CRUD Styles
   ========================================================================== */
.sub-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--slate-200);
    padding-bottom: 2px;
}

.sub-tab {
    padding: 8px 18px;
    border: none;
    background: transparent;
    font-family: var(--font-arabic);
    font-size: 14px;
    font-weight: 600;
    color: var(--slate-500);
    cursor: pointer;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    transition: all var(--transition-fast);
    position: relative;
    bottom: -2px;
}

.sub-tab:hover {
    color: var(--primary-600);
    background: var(--slate-100);
}

.sub-tab.active {
    color: var(--primary-600);
    border-bottom: 2px solid var(--primary-600);
    background: #ffffff;
    font-weight: 700;
}

.action-btns {
    display: inline-flex;
    gap: 6px;
    align-items: center;
}

.btn-action-edit {
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
    padding: 3px 9px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-arabic);
}

.btn-action-edit:hover {
    background: #dbeafe;
    color: #1e40af;
}

.btn-action-delete {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
    padding: 3px 9px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-arabic);
}

.btn-action-delete:hover {
    background: #fee2e2;
    color: #991b1b;
}

.empty-slot {
    cursor: pointer;
    position: relative;
    transition: all var(--transition-fast);
}

.empty-slot:hover {
    background-color: #eff6ff !important;
}

.empty-slot-prompt {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: #94a3b8;
    font-size: 11.5px;
    transition: color var(--transition-fast);
}

.empty-slot:hover .empty-slot-prompt {
    color: var(--primary-600);
    font-weight: 700;
}

.badge-delete {
    font-size: 11px;
    color: #ef4444;
    cursor: pointer;
    padding: 1px 4px;
    border-radius: 4px;
    opacity: 0.6;
    transition: opacity var(--transition-fast);
}

.badge-delete:hover {
    opacity: 1;
    background: #fee2e2;
}

.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.subjects-checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
    max-height: 160px;
    overflow-y: auto;
    background: var(--slate-50);
    border: 1px solid var(--slate-200);
    padding: 10px;
    border-radius: var(--radius-md);
}

.subject-checkbox-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    cursor: pointer;
}

.days-checkbox-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 6px;
}

.day-checkbox-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 13px;
    background: var(--slate-50);
    border: 1.5px solid var(--slate-200);
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 600;
    color: var(--slate-700);
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.day-checkbox-item:hover {
    background: var(--slate-100);
    border-color: var(--primary-300);
}

.day-checkbox-item.checked {
    background: rgba(37, 99, 235, 0.08);
    border-color: var(--primary);
    color: var(--primary-800);
}

.day-checkbox-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary);
}

/* التبويبات في نافذة النسخ والاستعادة */
.btn-tab-backup {
    background: none;
    border: none;
    padding: 12px 18px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--slate-600);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
    font-family: inherit;
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
}
.btn-tab-backup:hover {
    color: var(--primary-600);
}
.btn-tab-backup.active {
    color: var(--primary-700);
    border-bottom-color: var(--primary-600);
    background: #ffffff;
}

/* Keep the timetable readable and controls reachable on narrow screens. */
.main-wrapper { min-width: 0; }
button:focus-visible, select:focus-visible, input:focus-visible {
    outline: 3px solid var(--primary-500, #3b82f6);
    outline-offset: 2px;
}
@media screen and (max-width: 900px) {
    .app-container { flex-direction: column; }
    .sidebar { position: relative; width: 100%; height: auto; }
    .sidebar-nav { display: flex; flex-wrap: wrap; overflow: visible; }
    .sidebar-nav .nav-category { width: 100%; }
    .sidebar-nav .nav-item { width: auto; flex: 1 1 170px; }
    .main-wrapper { margin-right: 0; width: 100%; }
    .top-header { position: relative; padding: 12px; }
    .header-row-1 { flex-wrap: wrap; gap: 12px; }
    .timetable-container { overflow-x: auto; }
    .timetable-grid { min-width: 760px; }
    .form-grid-2 { grid-template-columns: 1fr; }
}

/* Smart Matrix Planner Styles */
.smart-day-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    align-items: center;
}
.smart-day-chip {
    padding: 3px 9px;
    font-size: 11.5px;
    font-weight: 600;
    border-radius: 6px;
    border: 1px solid var(--slate-300);
    background: #f8fafc;
    color: var(--slate-600);
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
}
.smart-day-chip:hover {
    border-color: var(--primary-400);
    background: #f1f5f9;
}
.smart-day-chip.active {
    background: #ecfdf5;
    border-color: #10b981;
    color: #065f46;
    font-weight: 700;
    box-shadow: 0 1px 2px rgba(16,185,129,0.15);
}
.smart-matrix-row {
    transition: background 0.15s ease, opacity 0.2s ease;
}
.smart-matrix-row.disabled-row {
    opacity: 0.6;
    background: #fbfbfb;
}
.smart-matrix-row.disabled-row select {
    border-color: #e2e8f0;
    color: #64748b;
}
.smart-matrix-row:hover {
    background: #f8fafc;
}
.smart-teachers-cell {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.smart-teachers-cell select {
    font-size: 12.5px;
    padding: 6px 10px;
    border-radius: 6px;
}
