/* ==================== Substitution Page Styles ==================== */

/* ========== Redesigned Teacher Card ========== */
.substitute-card {
    background: white;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: all 0.3s;
    border: 2px solid #E0E0E0;
    min-height: 180px;
    display: flex;
    flex-direction: column;
    position: relative;
}

.substitute-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    transform: translateY(-2px);
}

/* الصف الأول: الاسم والحالة */
.card-header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    width: 100%;
}

.teacher-name-section {
    flex: 1;
}

.teacher-name {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin-bottom: 2px;
}

.teacher-subject {
    font-size: 12px;
    color: #999;
    height: 16px; /* ارتفاع ثابت حتى لو كان فارغاً */
}

.state-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
}

.state-badge .material-icons-round {
    font-size: 14px;
}

/* المسافة الفارغة */
.card-spacer {
    flex: 1;
    min-height: 16px;
}

/* الصف الثاني: المقاييس */
.card-metrics-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: #F8F9FA;
    border-radius: 8px;
    margin: 8px 0;
}

/* نقاط الأولوية */
.priority-score {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
}

.score-label {
    font-size: 11px;
    color: #666;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.score-value {
    font-size: 24px;
    font-weight: 700;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* مؤشر التوازن */
.balance-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 14px;
}

.balance-indicator .material-icons-round {
    font-size: 18px;
}

.balance-negative {
    background: rgba(76, 175, 80, 0.1);
    color: #4CAF50;
}

.balance-positive {
    background: rgba(244, 67, 54, 0.1);
    color: #F44336;
}

.balance-neutral {
    background: rgba(158, 158, 158, 0.1);
    color: #9E9E9E;
}

/* زر الإسناد */
.card-action {
    margin-top: auto;
}

.card-action button {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s;
}

.btn-assign {
    color: white;
}

/* ========== حالات البطاقات ========== */

/* حالة متاح - أخضر */
.substitute-card.available {
    border-color: #4CAF50;
}

.substitute-card.available:hover {
    border-color: #45a049;
    box-shadow: 0 4px 16px rgba(76, 175, 80, 0.2);
}

.state-badge.available {
    background: rgba(76, 175, 80, 0.1);
    color: #4CAF50;
}

.substitute-card.available .btn-assign {
    background: #4CAF50;
    color: white;
}

.substitute-card.available .btn-assign:hover:not(:disabled) {
    background: #45a049;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(76, 175, 80, 0.3);
}

/* حالة قابل للدمج - برتقالي */
.substitute-card.mergeable {
    border-color: #F2994A;
}

.substitute-card.mergeable:hover {
    border-color: #E88A3A;
    box-shadow: 0 4px 16px rgba(242, 153, 74, 0.2);
}

.state-badge.mergeable {
    background: rgba(242, 153, 74, 0.1);
    color: #F2994A;
}

.btn-merge {
    background: #F2994A;
    color: white;
}

.btn-merge:hover:not(:disabled) {
    background: #E88A3A;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(242, 153, 74, 0.3);
}

/* حالة مشغول - أحمر */
.substitute-card.busy {
    opacity: 0.6;
    border-color: #F44336;
    background: #FAFAFA;
}

.state-badge.busy {
    background: rgba(244, 67, 54, 0.1);
    color: #F44336;
}

.btn-disabled-red {
    background: #FFEBEE !important;
    color: #F44336 !important;
    cursor: not-allowed !important;
    opacity: 0.6;
}

/* حالة لديه احتياط - بنفسجي */
.substitute-card.hasSubstitute {
    opacity: 0.6;
    border-color: #9C27B0;
    background: #FAFAFA;
}

.state-badge.hasSubstitute {
    background: rgba(156, 39, 176, 0.1);
    color: #9C27B0;
}

.btn-disabled-purple {
    background: #F3E5F5 !important;
    color: #9C27B0 !important;
    cursor: not-allowed !important;
    opacity: 0.6;
}

/* حالة غائب - رمادي */
.substitute-card.absent {
    opacity: 0.5;
    border-color: #9E9E9E;
    background: #FAFAFA;
}

.state-badge.absent {
    background: rgba(158, 158, 158, 0.1);
    color: #9E9E9E;
}

.btn-disabled-gray {
    background: #F5F5F5 !important;
    color: #9E9E9E !important;
    cursor: not-allowed !important;
    opacity: 0.6;
}

/* ========== أزرار معطلة عامة ========== */
.btn-disabled-green,
.btn-disabled-orange {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ========== زر الفلتر/الترتيب ========== */
.btn-filter-visible {
    background: white !important;
    color: #2F80ED !important;
    border: 1px solid #2F80ED !important;
    padding: 8px 16px !important;
    border-radius: 8px !important;
    font-weight: 500 !important;
    transition: all 0.2s !important;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-filter-visible:hover {
    background: #2F80ED !important;
    color: white !important;
}

/* ========== القائمة المنسدلة - محدثة للفتح لليسار ========== */
.sort-menu-enhanced {
    position: absolute;
    left: 0; /* تغيير من right إلى left */
    top: 40px;
    background: white !important;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15) !important;
    z-index: 1000;
    min-width: 250px;
    overflow: hidden;
    border: 1px solid #E0E0E0;
    transform-origin: top left; /* نقطة الأصل للأنيميشن */
}

/* إضافة أنيميشن للقائمة */
@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.sort-menu-enhanced {
    animation: slideDown 0.2s ease-out;
}

.sort-menu-enhanced .sort-option {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: background 0.2s;
    color: #333 !important;
    background: white !important;
    font-weight: 500;
}

.sort-menu-enhanced .sort-option:hover {
    background: #F5F5F5 !important;
}

.sort-menu-enhanced .sort-option.active {
    background: rgba(47, 128, 237, 0.1) !important;
    color: #2F80ED !important;
}

.sort-menu-enhanced .sort-option .material-icons-round {
    font-size: 20px;
    color: #666;
}

.sort-menu-enhanced .sort-option.active .material-icons-round {
    color: #2F80ED;
}

/* ========== نوافذ الحوار (Dialogs) ========== */
/* Reset Stats Dialog */
#reset-stats-dialog .modal {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

#reset-stats-dialog .modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1999;
}

#reset-stats-dialog .modal-content {
    position: relative;
    z-index: 2001;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    max-width: 500px;
    width: 90%;
}

#reset-stats-dialog .modal-header {
    padding: 20px;
    border-bottom: 1px solid #E0E0E0;
}

#reset-stats-dialog .modal-header h2 {
    margin: 0;
    font-size: 20px;
    color: #333;
}

#reset-stats-dialog .modal-body {
    padding: 20px;
}

#reset-stats-dialog .modal-body ul {
    text-align: right;
    margin: 16px auto;
    max-width: 300px;
    list-style-position: inside;
}

#reset-stats-dialog .modal-body li {
    margin: 8px 0;
    color: #666;
}

#reset-stats-dialog .modal-footer {
    padding: 20px;
    border-top: 1px solid #E0E0E0;
    display: flex;
    gap: 12px;
    justify-content: center;
}

#reset-stats-dialog .btn {
    min-width: 120px;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 0.3s;
}

#reset-stats-dialog .btn-text {
    background: transparent;
    color: #666;
}

#reset-stats-dialog .btn-text:hover {
    background: #F5F5F5;
}

#reset-stats-dialog .btn-filled {
    background-color: var(--md-sys-color-error, #DC2626);
    color: white;
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

#reset-stats-dialog .btn-filled:hover {
    background-color: #B91C1C;
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.25);
}

/* Delete Substitution Dialog */
#delete-substitute-dialog .modal {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1500;
    align-items: center;
    justify-content: center;
}

#delete-substitute-dialog .modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
}

#delete-substitute-dialog .modal-content {
    position: relative;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    max-width: 500px;
    width: 90%;
    z-index: 1501;
}

#delete-substitute-dialog .delete-details {
    background: #F5F5F5;
    border-radius: 8px;
    padding: 16px;
    margin: 16px 0;
}

#delete-substitute-dialog .detail-row {
    display: flex;
    justify-content: space-between;
    margin: 8px 0;
    font-size: 14px;
}

#delete-substitute-dialog .detail-label {
    color: #666;
}

#delete-substitute-dialog .detail-value {
    font-weight: 600;
    color: #333;
}

#delete-substitute-dialog .text-error {
    color: var(--md-sys-color-error, #DC2626);
    font-weight: 500;
    text-align: center;
}

/* ========== رقائق المعلمين ========== */
.teacher-chip-selectable {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    margin: 4px;
    background: white;
    border: 2px solid #E0E0E0;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s;
}

.teacher-chip-selectable:hover {
    border-color: #2F80ED;
    background: rgba(47, 128, 237, 0.05);
}

.teacher-chip-selectable.selected {
    background: #2F80ED;
    color: white;
    border-color: #2F80ED;
}

.teacher-chip-selectable .material-icons-round {
    font-size: 18px;
}

.teacher-chip-confirmed-absent {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    margin: 4px;
    background: #FFEBEE;
    border: 2px solid #F44336;
    border-radius: 20px;
    opacity: 0.7;
}

.teacher-chip-confirmed-absent .material-icons-round {
    font-size: 18px;
    color: #F44336;
}

.chip-class {
    font-size: 12px;
    opacity: 0.8;
}

.chip-status {
    font-size: 11px;
    color: #F44336;
    font-weight: 600;
}

/* ========== قائمة الملخص ========== */
.summary-list {
    padding: 8px 0;
}

.summary-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    margin: 8px 0;
    background: white;
    border: 1px solid #E0E0E0;
    border-radius: 8px;
    transition: all 0.3s;
}

.summary-item:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.summary-period {
    font-weight: 600;
    color: #2F80ED;
    min-width: 60px;
}

.summary-details {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 16px;
}

.absent-name {
    color: #F44336;
    font-weight: 500;
}

.substitute-name {
    color: #4CAF50;
    font-weight: 500;
}

.arrow {
    color: #999;
}

.btn-delete-sub {
    background: transparent;
    border: none;
    color: #999;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.3s;
}

.btn-delete-sub:hover {
    background: #FFEBEE;
    color: #F44336;
}

.btn-delete-sub .material-icons-round {
    font-size: 20px;
}

/* ========== الحالة الفارغة ========== */
.empty-state-small {
    padding: 32px;
    text-align: center;
}

.text-secondary {
    color: #999;
    font-size: 14px;
}

.helper-text {
    color: #666;
    font-size: 14px;
    margin-bottom: 16px;
}

/* ========== التصميم التجاوبي ========== */
@media (max-width: 768px) {
    /* القائمة المنسدلة تبقى على اليسار في الموبايل أيضاً */
    .sort-menu-enhanced {
        left: 0;
        right: auto;
        max-width: calc(100vw - 32px);
    }
    
    .substitute-card {
        margin: 8px 0;
    }
    
    .card-metrics-row {
        flex-direction: column;
        gap: 8px;
    }
    
    .priority-score {
        width: 100%;
        border-bottom: 1px solid #E0E0E0;
        padding-bottom: 8px;
    }
    
    .balance-indicator {
        width: 100%;
        justify-content: center;
    }
    
    #reset-stats-dialog .modal-content,
    #delete-substitute-dialog .modal-content {
        width: 95%;
        margin: 16px;
    }
}

/* ========== شبكة البطاقات ========== */
#teachers-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-top: 20px;
}

@media (max-width: 768px) {
    #teachers-cards-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
}