/* ========== إزالة الفراغات الافتراضية ========== */
html, body {
    margin: 0;
    padding: 0;
}

#login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

#main-system {
    margin: 0;
    padding: 0;
    height: 100vh;
    position: relative;
    overflow-x: hidden;
}

/* ========== المتغيرات العامة والثيم (فاتح/داكن) ========== */
:root {
    --primary-dark: #003F5C;
    --primary-light: #2F9BDB;
    --accent-color: #F4A623;
    --table-header: #2B7AA9;
    --bg-body: #F2F7FC;
    --bg-card: rgba(255, 255, 255, 0.92);
    --text-main: #1A2A3A;
    --border-light: #DAE5F0;

    --chat-bg: #EBF2FA;
    --msg-sent-bg: #D6EDFF;
    --msg-received-bg: #FFFFFF;

    --sidebar-bg: #002F47;
    --sidebar-text: #FFFFFF;

    --toast-success: #27AE60;
    --toast-error: #E74C3C;
    --toast-info: #2F9BDB;
    --toast-warning: #F39C12;
}

/* ✨ تفعيل الوضع الداكن تلقائيًا إذا كان النظام يفضّله */
@media (prefers-color-scheme: dark) {
    :root {
        --primary-dark: #1A5B7A;
        --primary-light: #4DB8FF;
        --bg-body: #121F2B;
        --bg-card: rgba(20, 35, 50, 0.88);
        --text-main: #EAF0F6;
        --border-light: #2A3D50;
        --chat-bg: #182A37;
        --msg-sent-bg: #1F5670;
        --msg-received-bg: #1E3340;
        --sidebar-bg: #0A1E2C;
        --sidebar-text: #EAF0F6;
    }
}

/* الثيم الداكن عند تفعيله يدوياً */
body.dark {
    --primary-dark: #1A5B7A;
    --primary-light: #4DB8FF;
    --bg-body: #121F2B;
    --bg-card: rgba(20, 35, 50, 0.88);
    --text-main: #EAF0F6;
    --border-light: #2A3D50;
    --chat-bg: #182A37;
    --msg-sent-bg: #1F5670;
    --msg-received-bg: #1E3340;
    --sidebar-bg: #0A1E2C;
    --sidebar-text: #EAF0F6;
}

/* ========== إعدادات عامة ========== */
* {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    direction: rtl;
    background: var(--bg-body);
    color: var(--text-main);
    font-size: 1rem;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.hidden { display: none !important; }

/* ========== شاشة البداية (Splash Screen) ========== */
#splash-screen {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: linear-gradient(135deg, #0B3D5F, #051C2C);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    transition: opacity 0.8s ease, visibility 0.8s;
}

#splash-screen.fade-out {
    opacity: 0;
    visibility: hidden;
}

.splash-content {
    text-align: center;
    color: white;
}

.splash-logo {
    width: 140px;
    height: auto;
    border-radius: 30px;
    background: rgba(255,255,255,0.9);
    padding: 12px;
    margin-bottom: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    animation: splashPulse 2s infinite;
}

@keyframes splashPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.08); }
    100% { transform: scale(1); }
}

.splash-title {
    font-size: 2rem;
    font-weight: 700;
    margin: 0 0 5px;
    text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

.splash-subtitle {
    font-size: 1.2rem;
    margin-bottom: 30px;
    opacity: 0.9;
}

.loading-bar {
    width: 200px;
    height: 4px;
    background: rgba(255,255,255,0.3);
    margin: 0 auto;
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}

.loading-bar::after {
    content: '';
    position: absolute;
    top: 0; left: -50%;
    width: 40%;
    height: 100%;
    background: var(--accent-color);
    border-radius: 2px;
    animation: loadingSlide 1.5s infinite;
}

@keyframes loadingSlide {
    0% { left: -40%; }
    100% { left: 100%; }
}

.splash-percent {
    margin-top: 15px;
    font-size: 1rem;
    font-weight: bold;
    letter-spacing: 1px;
}

/* ========== خلفية متحركة (موجات ودوائر) ========== */
#main-system::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 20% 50%, rgba(47, 155, 219, 0.08) 0%, rgba(0,63,92,0.02) 100%);
    pointer-events: none;
    z-index: -1;
    animation: subtleMove 20s infinite alternate;
}
@keyframes subtleMove {
    0% { transform: scale(1) translate(0, 0); opacity: 0.6; }
    100% { transform: scale(1.2) translate(2%, -2%); opacity: 0.3; }
}
.wave-bg {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 200px;
    background: repeating-linear-gradient( transparent 0px, transparent 29px, rgba(47,155,219,0.05) 30px);
    pointer-events: none;
    z-index: -1;
    animation: waveMove 12s linear infinite;
}
@keyframes waveMove {
    from { background-position: 0 0; }
    to { background-position: 0 60px; }
}

/* ========== خلفيات خاصة بالوضع الفاتح والداكن ========== */
body:not(.dark) #main-system::before {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" opacity="0.05"><path d="M30 10 L40 20 L30 30 L20 20 Z" fill="%23003F5C"/><circle cx="150" cy="50" r="15" fill="%232F9BDB"/></svg>');
    background-repeat: repeat;
    opacity: 0.2;
}
body.dark #main-system::before {
    background-image: radial-gradient(2px 2px at 20px 30px, #fff, rgba(0,0,0,0)), radial-gradient(1px 1px at 70px 120px, #ffcc44, rgba(0,0,0,0));
    background-size: 50px 50px, 80px 80px;
    opacity: 0.15;
}

/* ========== تصميم زجاجي محسّن لبطاقة الدخول ========== */
.glass-card {
    background: rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(25px);
    border: 1px solid rgba(255,255,255,0.25);
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.5);
}

/* أيقونات داخل الحقول */
.input-icon-wrapper {
    position: relative;
}

.input-icon {
    position: absolute;
    right: 18px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.2rem;
    opacity: 0.7;
    z-index: 1;
}

.input-icon-wrapper input {
    padding-right: 45px !important;
}

/* زر إظهار كلمة المرور */
.toggle-password {
    position: absolute;
    left: 18px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    font-size: 1.2rem;
    z-index: 1;
    user-select: none;
}

/* رسائل الخطأ المدمجة */
.login-error {
    color: #ff6b6b;
    background: rgba(255,0,0,0.1);
    border: 1px solid rgba(255,0,0,0.3);
    padding: 8px 15px;
    border-radius: 12px;
    font-size: 0.9rem;
    text-align: center;
    margin-top: -5px;
    margin-bottom: 5px;
}

/* ========== بطاقات الإحصائيات للمدير ========== */
.admin-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}

.stat-card {
    background: var(--bg-card);
    backdrop-filter: blur(15px);
    border-radius: 20px;
    padding: 25px 20px;
    text-align: center;
    border: 1px solid var(--border-light);
    transition: 0.3s;
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 30px rgba(0,0,0,0.1);
}

.stat-icon {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.stat-number {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-dark);
}

.stat-label {
    font-size: 0.95rem;
    color: var(--text-main);
    opacity: 0.8;
}

/* ========== تأثير التموج (Ripple) ========== */
.ripple-btn, button {
    position: relative;
    overflow: hidden;
}

.ripple-effect {
    position: absolute;
    border-radius: 50%;
    background: rgba(255,255,255,0.5);
    transform: scale(0);
    animation: ripple 0.6s linear;
    pointer-events: none;
}

@keyframes ripple {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

/* ========== هياكل عظمية (Skeleton Loading) ========== */
.skeleton {
    background: linear-gradient(90deg, var(--border-light) 25%, rgba(150,150,150,0.2) 50%, var(--border-light) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.2s infinite;
    border-radius: 8px;
}
.skeleton-title { width: 60%; height: 28px; margin-bottom: 15px; }
.skeleton-line { width: 100%; height: 16px; margin-bottom: 8px; }
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* ========== تحسين انتقالات الألسنة ========== */
main section, .admin-sub-tab {
    transition: opacity 0.2s cubic-bezier(0.2, 0.9, 0.4, 1.1), transform 0.2s ease-out;
    will-change: opacity, transform;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    pointer-events: none;
    backface-visibility: hidden;
}

main section:not(.hidden), .admin-sub-tab:not(.hidden) {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
    position: relative;
    z-index: 1;
}

main section.hidden, .admin-sub-tab.hidden {
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
    position: absolute;
    z-index: 0;
}

#content-area {
    position: relative;
    min-height: 100vh;
}

/* ========== تخطيط الصفحة الرئيسية ========== */
#main-system {
    display: grid;
    grid-template-columns: 270px 1fr;
    height: 100vh;
    transition: grid-template-columns 0.3s ease;
}

/* الشريط الجانبي */
aside {
    background: linear-gradient(145deg, var(--sidebar-bg), #0F3A55);
    color: var(--sidebar-text);
    padding: 35px 15px;
    text-align: center;
    overflow-x: hidden;
    overflow-y: auto;
    white-space: nowrap;
    box-shadow: 4px 0 25px rgba(0, 0, 0, 0.2);
    z-index: 10;
    backdrop-filter: blur(15px);
    border-left: 1px solid rgba(255,255,255,0.1);
}

/* زر القائمة (الهامبرغر) */
.hamburger-menu {
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 32px;
    background: none;
    border: none;
    padding: 5px;
    border-radius: 8px;
    z-index: 1200;
}

.hamburger-menu span {
    width: 28px;
    height: 3px;
    background-color: var(--primary-light);
    border-radius: 3px;
    transition: 0.2s;
}

@media (min-width: 769px) {
    .hamburger-menu { display: none; }
}

/* صورة المستخدم */
#user-pfp-container {
    display: flex;
    justify-content: center;
    margin-bottom: 15px;
}

.pfp-wrapper {
    position: relative;
    display: inline-block;
    width: 70px;
    height: 70px;
    border-radius: 50%;
    cursor: pointer;
    overflow: hidden;
    border: 3px solid var(--accent-color);
    box-shadow: 0 8px 18px rgba(0,0,0,0.3);
    transition: transform 0.2s, box-shadow 0.2s;
}

.pfp-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.pfp-edit-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.35);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: bold;
    letter-spacing: 0.5px;
    opacity: 0.25;
    transition: opacity 0.3s ease;
    pointer-events: none;
    border-radius: 50%;
}

.pfp-wrapper:hover .pfp-edit-overlay {
    opacity: 0.8;
}

.pfp-wrapper:hover {
    transform: scale(1.03);
}

.user-role {
    font-size: 0.9rem;
    background: rgba(255, 255, 255, 0.2);
    display: inline-block;
    padding: 5px 15px;
    border-radius: 25px;
    margin-top: 5px;
    margin-bottom: 8px;
    letter-spacing: 0.3px;
}

.school-info-side {
    font-size: 0.8rem;
    opacity: 0.9;
    margin-top: 8px;
    line-height: 1.5;
}

.principal-side {
    font-size: 0.75rem;
    opacity: 0.8;
    margin-top: 4px;
}

/* أزرار التنقل في الشريط الجانبي */
aside nav button {
    width: 100%;
    padding: 14px 12px;
    margin-bottom: 10px;
    background: rgba(255, 255, 255, 0.12);
    color: white;
    border: none;
    border-radius: 16px;
    cursor: pointer;
    text-align: right;
    font-size: 1.05rem;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: 0.25s;
    font-weight: 500;
}

aside nav button:hover {
    background: var(--accent-color);
    color: #000;
    transform: translateX(-4px);
    box-shadow: 0 6px 15px rgba(244, 166, 35, 0.3);
}

/* ========== صفحة تسجيل الدخول ========== */
#login-page {
    height: 100vh;
    background: radial-gradient(circle at 20% 30%, #0B3D5F, #051C2C);
    animation: gradientShift 12s ease infinite;
    display: flex;
    justify-content: center;
    align-items: center;
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-10px); }
    20%, 40%, 60%, 80% { transform: translateX(10px); }
}
.shake { animation: shake 0.5s ease-in-out; }

.login-container { text-align: center; width: 100%; display: flex; justify-content: center; }

.login-card {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(20px);
    padding: 2.5rem;
    border-radius: 48px;
    width: 90%;
    max-width: 440px;
    box-shadow: 0 30px 50px rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255,255,255,0.25);
    transition: transform 0.4s, box-shadow 0.4s;
}
.login-card:hover {
    transform: translateY(-6px);
    box-shadow: 0 40px 65px rgba(0, 0, 0, 0.55);
}

.school-logo img {
    width: 130px;
    height: auto;
    border-radius: 25px;
    background: rgba(255, 255, 255, 0.95);
    padding: 10px;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.2);
    animation: gentlePulse 3s infinite ease-in-out;
}

@keyframes gentlePulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.04); }
    100% { transform: scale(1); }
}

.school-logo-mini img {
    width: 75px;
    height: 75px;
    object-fit: cover;
    border-radius: 50%;
    background: white;
    padding: 5px;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.15);
}

.login-title {
    color: white;
    font-size: 1.9rem;
    margin: 15px 0 8px;
    font-weight: 700;
    text-shadow: 0 2px 6px rgba(0,0,0,0.4);
    border-bottom: 3px solid var(--accent-color);
    display: inline-block;
    padding-bottom: 8px;
}

.principal-name {
    color: #FFE0B2;
    font-size: 1rem;
    margin: 10px 0 20px;
    background: rgba(0,0,0,0.25);
    display: inline-block;
    padding: 6px 20px;
    border-radius: 40px;
    letter-spacing: 0.5px;
}

.login-inputs { display: flex; flex-direction: column; gap: 18px; margin-top: 10px; }
.login-inputs input {
    border: 1px solid rgba(255,255,255,0.3);
    padding: 14px 20px;
    border-radius: 60px;
    font-size: 1.1rem;
    outline: none;
    background: rgba(255,255,255,0.9);
    text-align: right;
    color: #000;
}
.login-inputs input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(244, 166, 35, 0.4);
}
.login-inputs button {
    background: var(--accent-color);
    color: #0B3D5F;
    border: none;
    padding: 14px;
    border-radius: 60px;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    transition: 0.2s;
    letter-spacing: 0.8px;
}
.login-inputs button:hover { background: #FFB74D; transform: scale(0.98); }

.login-footer {
    margin-top: 25px;
    font-size: 0.8rem;
    color: rgba(255,255,255,0.7);
    border-top: 1px solid rgba(255,255,255,0.2);
    padding-top: 12px;
}

/* ========== الهيدر ========== */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 25px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(18px);
    border-bottom: 1px solid var(--border-light);
}

.theme-toggle { background: none; border: none; font-size: 1.7rem; cursor: pointer; margin-left: 10px; }

/* ========== البطاقات والجداول ========== */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(15px);
    padding: 25px;
    border-radius: 28px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
    margin-bottom: 25px;
    border: 1px solid rgba(255,255,255,0.5);
    transition: box-shadow 0.3s, transform 0.3s;
    position: relative;
}
.card:hover {
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.12);
    transform: translateY(-3px);
}

/* 🌐 زر ملء الشاشة للبطاقات */
.fullscreen-btn {
    position: absolute;
    top: 15px;
    left: 15px;
    background: var(--primary-dark);
    color: white;
    border: none;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    font-size: 1.3rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    transition: 0.2s;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}
.fullscreen-btn:hover { background: var(--accent-color); color: #000; }

/* وضع ملء الشاشة للبطاقة */
.card.fullscreen {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    z-index: 9998;
    margin: 0;
    border-radius: 0;
    overflow: auto;
}

.main-table, table {
    width: 100%;
    border-collapse: collapse;
    border-radius: 20px;
    overflow-x: auto;
    display: block;
    white-space: nowrap;
    background: rgba(255,255,255,0.6);
}

@media (min-width: 769px) {
    .main-table, table { display: table; white-space: normal; }
}

th, td {
    border: 1px solid var(--border-light);
    padding: 12px 10px;
    text-align: center;
    vertical-align: middle;
}

th {
    background: var(--table-header);
    color: white;
    font-weight: 600;
    font-size: 1rem;
}

/* تنسيق الحصة الحالية */
td.current-period {
    background-color: #FFF3CD !important;
    border: 2px solid var(--accent-color);
    font-weight: bold;
    border-radius: 8px;
}

/* 📱 تثبيت عمود "اليوم" في الجداول على الشاشات الصغيرة */
@media (max-width: 768px) {
    .sticky-first-col {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .sticky-first-col table {
        border-collapse: separate;
        border-spacing: 0;
    }
    .sticky-first-col td:first-child,
    .sticky-first-col th:first-child {
        position: sticky;
        right: 0;
        background: var(--bg-card);
        z-index: 1;
        border-left: 2px solid var(--border-light);
        box-shadow: 2px 0 8px rgba(0,0,0,0.1);
    }
}

/* ========== الإشعارات المنبثقة (Toast) ========== */
#toast-container {
    position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
    z-index: 10001; display: flex; flex-direction: column; align-items: center;
    gap: 10px; pointer-events: none;
}
.toast {
    padding: 14px 28px; border-radius: 50px; color: white; font-weight: bold;
    box-shadow: 0 8px 20px rgba(0,0,0,0.2); pointer-events: auto;
    animation: toastIn 0.3s ease; transition: opacity 0.3s;
    font-size: 1rem;
}
.toast-success { background: var(--toast-success); }
.toast-error { background: var(--toast-error); }
.toast-info { background: var(--toast-info); }
.toast-warning { background: var(--toast-warning); }

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

/* ========== نافذة التأكيد ========== */
#confirm-modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.6); display: flex; justify-content: center;
    align-items: center; z-index: 10002;
}
#confirm-modal .modal-content {
    background: var(--bg-card); padding: 30px; border-radius: 24px;
    text-align: center; min-width: 300px; box-shadow: 0 20px 40px rgba(0,0,0,0.3);
}
#confirm-modal .modal-content button {
    margin: 12px; padding: 10px 25px; border-radius: 30px; border: none;
    cursor: pointer; font-weight: bold; font-size: 1rem;
}
.btn-confirm { background: #e74c3c; color: white; }
.btn-cancel { background: #bdc3c7; color: #2c3e50; }

/* ========== المحادثات ========== */
.chat-container {
    display: grid;
    grid-template-columns: 310px 1fr;
    height: calc(100vh - 85px);
    background: var(--bg-card);
    border-radius: 30px;
    overflow: hidden;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border-light);
}

.chat-sidebar {
    border-left: 1px solid var(--border-light);
    overflow-y: auto;
    background: rgba(255,255,255,0.8);
    backdrop-filter: blur(12px);
}

.chat-item {
    display: flex;
    align-items: center;
    padding: 14px 15px;
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
    font-size: 0.95rem;
    background: transparent;
}

.chat-item:hover {
    background: var(--primary-light);
    color: white;
    transform: translateX(-2px);
}

.chat-item:active {
    background: var(--primary-dark);
    color: white;
}

.chat-avatar {
    width: 48px; height: 48px;
    background: #D0E1F5;
    border-radius: 50%;
    margin-left: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    overflow: hidden;
    flex-shrink: 0;
}

.chat-main-area {
    display: flex;
    flex-direction: column;
    background: linear-gradient(135deg, #EBF2FA 0%, #FFFFFF 100%);
    background-size: 300% 300%;
    animation: chatBgAnimate 20s ease infinite;
    position: relative;
}

@keyframes chatBgAnimate {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

#chat-header {
    padding: 15px 20px;
    background: rgba(0, 47, 71, 0.92);
    backdrop-filter: blur(8px);
    color: white;
    font-weight: bold;
    font-size: 1.1rem;
    border-bottom: 2px solid var(--accent-color);
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 1;
}

#chat-box {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    background: transparent;
    z-index: 1;
}

.message {
    margin-bottom: 18px;
    display: flex;
    flex-direction: column;
}

.message.sent { align-items: flex-end; }
.message.received { align-items: flex-start; }

.bubble {
    padding: 12px 16px;
    border-radius: 20px;
    max-width: 75%;
    font-size: 0.95rem;
    line-height: 1.5;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    word-wrap: break-word;
    transition: transform 0.2s;
    position: relative;
}

.sent .bubble {
    background: var(--msg-sent-bg);
    color: var(--text-main);
    border-bottom-left-radius: 6px;
    margin-right: auto;
}

.received .bubble {
    background: var(--msg-received-bg);
    border: 1px solid var(--border-light);
    border-bottom-right-radius: 6px;
    margin-left: auto;
}

.time {
    font-size: 0.7rem;
    color: #6C7A89;
    margin-top: 4px;
    display: block;
    text-align: left;
}

.sent .time { color: #3A4A5A; }

.system-message {
    text-align: center;
    margin: 25px auto;
    padding: 12px 18px;
    background: rgba(0,0,0,0.05);
    border-radius: 40px;
    font-size: 0.85rem;
    max-width: 80%;
    color: var(--text-main);
}

.chat-input-area {
    padding: 12px 15px;
    background: rgba(255,255,255,0.9);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border-light);
    display: flex;
    gap: 8px;
    align-items: center;
    z-index: 1;
}

.chat-input-area input {
    flex: 1;
    padding: 12px 18px;
    border-radius: 30px;
    border: 1px solid var(--border-light);
    background: white;
    color: var(--text-main);
    outline: none;
    font-size: 0.95rem;
}

.chat-input-area button {
    background: var(--primary-dark);
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 30px;
    cursor: pointer;
    font-weight: bold;
    transition: 0.2s;
    font-size: 0.9rem;
    white-space: nowrap;
}

.chat-input-area button:hover { background: var(--accent-color); color: #000; }

#image-preview-area {
    background: rgba(255,255,255,0.9);
    border-top: 1px solid var(--border-light);
    padding: 8px;
    display: flex;
    gap: 8px;
    overflow-x: auto;
}

.preview-item { position: relative; display: inline-block; flex-shrink: 0; }
.preview-item img { width: 65px; height: 65px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border-light); }
.preview-item .remove-btn {
    position: absolute; top: -6px; right: -6px;
    background: #dc3545; color: white; border: none; border-radius: 50%;
    width: 20px; height: 20px; font-size: 12px; cursor: pointer;
}

#upload-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.6); z-index: 10000;
    justify-content: center; align-items: center; flex-direction: column;
    display: none;
}
#upload-overlay .loader {
    border: 4px solid rgba(255,255,255,0.3);
    border-top: 4px solid #fff;
    border-radius: 50%;
    width: 45px; height: 45px;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}
#upload-overlay .progress-text { color: white; font-weight: bold; font-size: 1.1rem; }

@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* ========== منتقي الإيموجي ========== */
#emoji-picker {
    position: absolute;
    bottom: 70px;
    right: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 18px;
    padding: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    z-index: 100;
    box-shadow: 0 8px 20px rgba(0,0,0,0.15);
}

#emoji-picker span {
    cursor: pointer;
    font-size: 1.6rem;
    padding: 5px;
    border-radius: 10px;
    transition: 0.1s;
}

#emoji-picker span:hover { background: var(--primary-light); color: white; }

/* ========== أزرار الصور والإشعارات ========== */
.chat-image-btn { background: none; border: none; font-size: 1.6rem; cursor: pointer; padding: 0 10px; color: var(--primary-dark); }

.notif-wrapper { position: relative; display: inline-block; cursor: pointer; }
.notif-bell { font-size: 28px; position: relative; }

#bell-count {
    position: absolute; top: -5px; right: -5px; background: red; color: white;
    border-radius: 50%; padding: 3px 8px; font-size: 11px; display: none;
}

@keyframes bellPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}
.notif-bell.has-notifications {
    animation: bellPulse 0.6s ease-in-out 3;
}

#notif-dropdown {
    position: absolute; top: 45px; left: 0; background: var(--bg-card); border: 1px solid var(--border-light);
    width: 300px; border-radius: 18px; box-shadow: 0 12px 30px rgba(0,0,0,0.15);
    z-index: 1000; padding: 15px; color: var(--text-main); text-align: right;
    backdrop-filter: blur(20px);
}

/* ========== تصميم متجاوب ========== */
@media (max-width: 768px) {
    #main-system { grid-template-columns: 1fr; }

    aside {
        position: fixed;
        top: 0;
        right: -280px;
        height: 100%;
        width: 260px;
        z-index: 1100;
        transition: right 0.3s;
        padding-top: 80px;
    }

    aside.open { right: 0; }

    .hamburger-menu {
        display: flex;
        position: fixed;
        top: 15px;
        right: 15px;
        background: rgba(0,0,0,0.3);
        padding: 6px;
        border-radius: 8px;
    }

    .back-btn { display: inline-block; }

    .chat-container { grid-template-columns: 1fr; }
    .chat-sidebar { display: none; }

    .chat-container.show-sidebar .chat-sidebar { display: block; }
    .chat-container.show-sidebar .chat-main-area { display: none; }
    .chat-container.show-chat .chat-sidebar { display: none; }
    .chat-container.show-chat .chat-main-area { display: flex; }

    .bubble { max-width: 85%; }
    .card { padding: 18px; }
    .login-title { font-size: 1.4rem; }
    .school-logo img { width: 100px; }
}

/* ========== شريط التنقل السفلي (موبايل) ========== */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255,255,255,0.9);
    backdrop-filter: blur(15px);
    border-top: 1px solid var(--border-light);
    justify-content: space-around;
    padding: 10px 0;
    z-index: 1000;
}

.mobile-nav button {
    background: none;
    border: none;
    font-size: 1.7rem;
    cursor: pointer;
    color: var(--primary-dark);
}

@media (max-width: 768px) {
    .mobile-nav { display: flex; }
    #content-area { padding-bottom: 65px; }
}

/* ========== إدارة المستخدمين ========== */
.user-management-table input,
.user-management-table select {
    padding: 8px 10px;
    border: 1px solid var(--border-light);
    border-radius: 10px;
    background: var(--bg-body);
    color: var(--text-main);
    font-size: 0.95rem;
}

.btn-save {
    background: #28a745;
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 10px;
    cursor: pointer;
    margin: 3px;
    font-size: 0.9rem;
    font-weight: bold;
}

.btn-delete {
    background: #dc3545;
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 10px;
    cursor: pointer;
    margin: 3px;
    font-size: 0.9rem;
    font-weight: bold;
}

/* ========== المودال العام ========== */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.55);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10003;
}

.modal-overlay .modal-content {
    background: var(--bg-card);
    padding: 25px;
    border-radius: 24px;
    min-width: 310px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0,0,0,0.25);
}

.modal-overlay input {
    width: 100%;
    padding: 12px;
    margin-top: 15px;
    border-radius: 12px;
    border: 1px solid var(--border-light);
    background: var(--bg-body);
    color: var(--text-main);
    font-size: 1rem;
}

/* ========== تنسيقات شهادة PDF ========== */
.report-card-pdf {
    width: 210mm;
    min-height: 297mm;
    padding: 20mm;
    margin: 0 auto;
    background: white;
    font-family: 'Segoe UI', Tahoma, sans-serif;
    direction: rtl;
    box-sizing: border-box;
    color: #000;
}

.report-card-pdf .header {
    text-align: center;
    border-bottom: 3px double #000;
    padding-bottom: 10px;
    margin-bottom: 20px;
}

.report-card-pdf .header img {
    height: 80px;
    margin-bottom: 10px;
}

.report-card-pdf h2, .report-card-pdf h3 {
    margin: 5px 0;
    color: #000;
}

.report-card-pdf table.report-table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
}

.report-card-pdf table.report-table th,
.report-card-pdf table.report-table td {
    border: 1px solid black;
    padding: 8px;
    text-align: center;
    font-size: 14px;
    color: #000;
}

.report-card-pdf .signatures {
    display: flex;
    justify-content: space-between;
    margin-top: 50px;
}

.report-card-pdf .signatures div {
    text-align: center;
    width: 30%;
}

.report-card-pdf .signatures hr {
    width: 80%;
    margin: 5px auto;
    border-top: 1px solid #000;
}

@media print {
    body * { visibility: hidden; }
    .report-card-pdf, .report-card-pdf * { visibility: visible; }
    .report-card-pdf {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
    }
}

/* تأثيرات إضافية */
.stat-card {
    background: var(--bg-card);
    backdrop-filter: blur(15px);
    border-radius: 20px;
    padding: 25px 20px;
    text-align: center;
    border: 1px solid var(--border-light);
    transition: 0.3s;
}
.stat-number { font-size: 2.5rem; font-weight: bold; color: var(--primary-dark); }

#reply-preview {
    margin: 5px 10px;
}

/* تنسيق أزرار قائمة "المزيد" للجوال */
#mobile-more-menu button {
    white-space: nowrap;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
}
#mobile-more-menu button:hover {
    background: var(--accent-color) !important;
    color: #000 !important;
}

/* وضع القراءة للواجبات */
.reader-modal .reader-content {
    background: var(--bg-card);
    border-radius: 28px;
    padding: 28px;
    max-width: 600px;
    width: 90%;
}
.reader-modal .reader-content p {
    font-size: 1.2rem;
    line-height: 1.6;
}