/* ==============================================================================
   لوحة تحكم المدير - مدرسة محمد الفاتح للبنين
   ============================================================================== */

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

:root {
    --font-main: 'Cairo', system-ui, -apple-system, sans-serif;
    --font-heading: 'Tajawal', var(--font-main);
    
    --admin-primary: #0f172a;
    --admin-sidebar-bg: #0f172a;
    --admin-accent: #2563eb;
    --admin-accent-hover: #1d4ed8;
    --admin-gold: #d97706;
    --admin-gold-hover: #b45309;
    --admin-danger: #dc2626;
    --admin-success: #059669;

    --bg-page: #f8fafc;
    --bg-card: #ffffff;
    --border-color: #e2e8f0;
    --text-primary: #0f172a;
    --text-muted: #64748b;
    --text-light: #94a3b8;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-full: 9999px;

    --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);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

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

html, body {
    direction: rtl;
    font-family: var(--font-main);
    background-color: var(--bg-page);
    color: var(--text-primary);
    min-height: 100vh;
}

/* نافذة إدخال رمز الأمان PIN */
.pin-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(8px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.pin-card {
    background: #ffffff;
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    max-width: 420px;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border-color);
}

.pin-icon {
    width: 64px;
    height: 64px;
    background: #fef3c7;
    color: var(--admin-gold);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.25rem;
    font-size: 1.8rem;
}

.pin-input {
    width: 100%;
    padding: 0.85rem;
    font-size: 1.4rem;
    text-align: center;
    letter-spacing: 0.35rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    margin: 1.5rem 0 1rem;
    font-family: inherit;
    transition: all 0.2s ease;
}

.pin-input:focus {
    outline: none;
    border-color: var(--admin-accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.pin-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.pin-btn {
    width: 100%;
    padding: 0.85rem;
    background: var(--admin-primary);
    color: #ffffff;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s ease;
}

.pin-btn:hover {
    background: #1e293b;
}

/* التخطيط العام للوحة التحكم */
.admin-layout {
    display: flex;
    min-height: 100vh;
}

/* الشريط الجانبي */
.admin-sidebar {
    width: 270px;
    background: var(--admin-sidebar-bg);
    color: #f8fafc;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
}

.sidebar-brand {
    padding: 1.75rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.85rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-logo {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--admin-gold);
}

.sidebar-brand h3 {
    font-family: var(--font-heading);
    font-size: 1.05rem;
    font-weight: 800;
    color: #ffffff;
}

.sidebar-brand p {
    font-size: 0.75rem;
    color: var(--text-light);
}

.sidebar-nav {
    padding: 1.25rem 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    flex: 1;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.8rem 1rem;
    border-radius: var(--radius-md);
    color: #cbd5e1;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: right;
    font-family: inherit;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #ffffff;
}

.nav-link.active {
    background: var(--admin-accent);
    color: #ffffff;
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.btn-public-portal {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #ffffff;
    border-radius: var(--radius-md);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.btn-public-portal:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* منطقة المحتوى الرئيسية للوحة */
.admin-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* الشريط العلوي */
.admin-topbar {
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.topbar-title h2 {
    font-family: var(--font-heading);
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--text-primary);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.supabase-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.4rem 0.85rem;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 700;
}

.supabase-status-pill.connected {
    background: #ecfdf5;
    color: #059669;
    border: 1px solid #6ee7b7;
}

.supabase-status-pill.local {
    background: #fffbeb;
    color: #b45309;
    border: 1px solid #fde68a;
}

.btn-lock {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.9rem;
    background: #f1f5f9;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s ease;
}

.btn-lock:hover {
    background: #fee2e2;
    color: var(--admin-danger);
    border-color: #fca5a5;
}

/* مساحة المحتوى القابل للتمرير */
.admin-content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
}

.admin-tab-pane {
    display: none;
    animation: fadeIn 0.3s ease-out;
}

.admin-tab-pane.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* شبكة الإحصائيات (Stats) */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: #ffffff;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
}

.stat-info h4 {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 0.3rem;
}

.stat-info .stat-number {
    font-family: var(--font-heading);
    font-size: 1.9rem;
    font-weight: 800;
    color: var(--text-primary);
}

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

/* بطاقات لوحة التحكم العامة */
.dashboard-card {
    background: #ffffff;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    padding: 1.75rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 2rem;
}

.card-header-flex {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.card-header-flex h3 {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text-primary);
}

/* أزرار العمليات */
.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1.25rem;
    background: var(--admin-accent);
    color: #ffffff;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    background: var(--admin-accent-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1.25rem;
    background: #f1f5f9;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s ease;
}

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

.btn-success {
    background: var(--admin-success);
    color: #ffffff;
}
.btn-success:hover {
    background: #047857;
}

/* شريط الفلترة والبحث */
.filter-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.shift-filters {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.filter-btn {
    padding: 0.5rem 1rem;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s ease;
    color: var(--text-secondary);
}

.filter-btn.active {
    background: var(--admin-primary);
    color: #ffffff;
    border-color: var(--admin-primary);
}

.search-box {
    position: relative;
    max-width: 300px;
    width: 100%;
}

.search-box input {
    width: 100%;
    padding: 0.55rem 2.25rem 0.55rem 0.85rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
}

.search-box svg {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

/* جدول وقائمة الصفوف الدراسية */
.classes-table-container {
    overflow-x: auto;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    text-align: right;
    font-size: 0.95rem;
}

.admin-table th {
    background: #f8fafc;
    padding: 0.85rem 1rem;
    color: var(--text-muted);
    font-weight: 700;
    border-bottom: 2px solid var(--border-color);
}

.admin-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.admin-table tr:hover td {
    background: #f8fafc;
}

.class-thumb {
    width: 54px;
    height: 40px;
    border-radius: 6px;
    object-fit: cover;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: transform 0.2s ease;
}

.class-thumb:hover {
    transform: scale(1.15);
}

.badge-shift {
    display: inline-flex;
    padding: 0.25rem 0.65rem;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 700;
}

.badge-shift.shift-a {
    background: #eff6ff;
    color: #2563eb;
    border: 1px solid #bfdbfe;
}

.badge-shift.shift-b {
    background: #ecfdf5;
    color: #059669;
    border: 1px solid #a7f3d0;
}

.table-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.action-icon-btn {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    background: #ffffff;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.action-icon-btn:hover {
    background: #f1f5f9;
    color: var(--text-primary);
}

.action-icon-btn.danger:hover {
    background: #fee2e2;
    color: var(--admin-danger);
    border-color: #fca5a5;
}

/* نافذة الحوار Modal */
.admin-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    overflow-y: auto;
}

.admin-modal-overlay.active {
    display: flex;
}

.admin-modal {
    background: #ffffff;
    border-radius: var(--radius-lg);
    max-width: 640px;
    width: 100%;
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    animation: modalIn 0.25s ease-out;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}

.modal-header {
    padding: 1.25rem 1.75rem;
    background: #f8fafc;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    font-weight: 800;
}

.modal-body {
    padding: 1.75rem;
    max-height: 75vh;
    overflow-y: auto;
}

.modal-footer {
    padding: 1rem 1.75rem;
    background: #f8fafc;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* حقول الإدخال Forms */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-weight: 700;
    font-size: 0.9rem;
    margin-bottom: 0.45rem;
    color: var(--text-primary);
}

.form-control {
    width: 100%;
    padding: 0.7rem 0.9rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--admin-accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* منطقة رفع الصورة السحب والإفلات */
.upload-dropzone {
    border: 2px dashed #cbd5e1;
    border-radius: var(--radius-md);
    padding: 2rem;
    text-align: center;
    background: #f8fafc;
    cursor: pointer;
    transition: all 0.2s ease;
}

.upload-dropzone:hover, .upload-dropzone.dragover {
    border-color: var(--admin-accent);
    background: #eff6ff;
}

.upload-icon {
    font-size: 2.5rem;
    color: var(--admin-accent);
    margin-bottom: 0.5rem;
}

.image-preview-box {
    margin-top: 1rem;
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-color);
    max-height: 240px;
    display: none;
}

.image-preview-box img {
    width: 100%;
    height: 240px;
    object-fit: contain;
    background: #0f172a;
}

.btn-remove-preview {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    background: rgba(220, 38, 38, 0.9);
    color: #ffffff;
    border: none;
    border-radius: var(--radius-full);
    padding: 0.35rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
}

/* كود SQL وإرشادات سوبابيز */
.sql-box {
    background: #0f172a;
    color: #e2e8f0;
    padding: 1.25rem;
    border-radius: var(--radius-md);
    font-family: monospace;
    font-size: 0.85rem;
    max-height: 250px;
    overflow-y: auto;
    direction: ltr;
    text-align: left;
    margin: 1rem 0;
}

/* رسائل التنبيه والتوست Toast */
.admin-toast {
    position: fixed;
    bottom: 2rem;
    left: 2rem;
    background: #0f172a;
    color: #ffffff;
    padding: 0.85rem 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    z-index: 99999;
    display: none;
    align-items: center;
    gap: 0.75rem;
    font-weight: 600;
    animation: toastUp 0.3s ease-out;
}

.admin-toast.success {
    background: #059669;
}

.admin-toast.error {
    background: #dc2626;
}

@keyframes toastUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 900px) {
    .admin-layout {
        flex-direction: column;
    }
    .admin-sidebar {
        width: 100%;
    }
    .form-row {
        grid-template-columns: 1fr;
    }
}
