/* ============ Admin Page Layout ============ */
.admin-page {
    min-height: 100vh;
    background: var(--bg-primary);
    padding: 20px;
}

.admin-header {
    max-width: 1200px;
    margin: 0 auto 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}

.admin-title {
    font-size: 24px;
    font-weight: 800;
    color: var(--text-primary);
}

.admin-title span { color: var(--green-400); }

.admin-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    margin-right: 8px;
}

.badge-owner { background: rgba(234,179,8,0.15); color: #facc15; }
.badge-admin { background: rgba(59,130,246,0.15); color: #60a5fa; }
.badge-student { background: rgba(99,102,241,0.15); color: #A5B4FC; }

.admin-nav {
    display: flex;
    gap: 8px;
    align-items: center;
}

.admin-nav a, .admin-nav button {
    padding: 8px 16px;
    border-radius: 8px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    background: transparent;
    cursor: pointer;
    font-family: 'Tajawal', sans-serif;
    transition: all 0.3s;
}

.admin-nav a:hover, .admin-nav button:hover {
    border-color: var(--green-400);
    color: var(--green-400);
}

.admin-nav .logout-btn { border-color: #ef4444; color: #ef4444; }
.admin-nav .logout-btn:hover { background: rgba(239,68,68,0.1); }

/* ============ Tabs ============ */
.admin-tabs {
    max-width: 1200px;
    margin: 0 auto 24px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.admin-tab {
    padding: 12px 24px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    background: var(--bg-card);
    cursor: pointer;
    font-family: 'Tajawal', sans-serif;
    transition: all 0.3s;
}

.admin-tab:hover {
    border-color: var(--green-400);
    color: var(--green-400);
}

.admin-tab.active {
    background: linear-gradient(135deg, #6366F1, #4F46E5);
    border-color: #6366F1;
    color: white;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ============ Stats Grid ============ */
.stats-grid {
    max-width: 1200px;
    margin: 0 auto 30px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px;
    text-align: center;
}

.stat-icon { font-size: 32px; margin-bottom: 8px; color: var(--text-secondary); }
.stat-value { font-size: 28px; font-weight: 800; color: var(--text-primary); }
.stat-label { font-size: 14px; color: var(--text-secondary); margin-top: 4px; }

/* ============ Admin Section ============ */
.admin-section {
    max-width: 1200px;
    margin: 0 auto 30px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    overflow: hidden;
}

.section-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.section-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

/* ============ Users Table ============ */
.users-table {
    width: 100%;
    border-collapse: collapse;
}

.users-table th {
    padding: 12px 20px;
    text-align: right;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.users-table td {
    padding: 14px 20px;
    font-size: 14px;
    color: var(--text-primary);
    border-bottom: 1px solid rgba(255,255,255,0.03);
}

.users-table tr:hover td {
    background: rgba(255,255,255,0.02);
}

.role-select {
    padding: 4px 10px;
    border-radius: 6px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-family: 'Tajawal', sans-serif;
    font-size: 13px;
    cursor: pointer;
}

/* ============ Activity/History ============ */
.history-item {
    padding: 16px 24px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.history-item:last-child { border-bottom: none; }

.history-info { flex: 1; }
.history-name { font-weight: 600; color: var(--text-primary); font-size: 14px; }
.history-detail { color: var(--text-secondary); font-size: 13px; margin-top: 2px; }

.history-score {
    font-size: 18px;
    font-weight: 700;
}

.score-high { color: #6366F1; }
.score-mid { color: #f59e0b; }
.score-low { color: #ef4444; }

/* ============ Loading & Empty States ============ */
.empty-state {
    padding: 40px;
    text-align: center;
    color: var(--text-muted);
}

.loading-state {
    padding: 40px;
    text-align: center;
    color: var(--text-muted);
}

.loading-state .spinner {
    width: 30px; height: 30px;
    border: 3px solid var(--border-color);
    border-top-color: var(--green-400);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin: 0 auto 12px;
}

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

/* ============ Filters ============ */
.filters-container {
    padding: 20px 24px;
}

.filter-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.filter-row:last-child {
    margin-bottom: 0;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 150px;
}

.filter-group.search-group {
    flex: 1;
    min-width: 250px;
}

.filter-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.filter-group select,
.filter-group input {
    padding: 10px 14px;
    border-radius: 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-family: 'Tajawal', sans-serif;
    font-size: 14px;
    transition: border-color 0.3s;
}

.filter-group select:focus,
.filter-group input:focus {
    outline: none;
    border-color: var(--green-400);
}

.filter-actions {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.btn-primary,
.btn-secondary {
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    font-family: 'Tajawal', sans-serif;
    transition: all 0.3s;
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, #6366F1, #4F46E5);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.btn-secondary:hover {
    border-color: var(--green-400);
    color: var(--green-400);
}

/* ============ Questions List ============ */
.questions-list {
    padding: 16px;
}

.question-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    transition: border-color 0.3s;
}

.question-card:hover {
    border-color: rgba(99, 102, 241, 0.3);
}

.question-card.invalid {
    border-color: rgba(239, 68, 68, 0.3);
    background: rgba(239, 68, 68, 0.05);
}

.question-card.valid {
    border-color: rgba(34, 197, 94, 0.2);
}

.question-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 8px;
}

.question-meta {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.question-bank {
    font-size: 12px;
    padding: 4px 10px;
    background: rgba(99, 102, 241, 0.15);
    color: #A5B4FC;
    border-radius: 6px;
    font-weight: 500;
}

.question-id {
    font-size: 12px;
    color: var(--text-muted);
    font-family: monospace;
}

.question-valid {
    font-size: 14px;
}

.btn-edit {
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.3);
    color: #A5B4FC;
    cursor: pointer;
    font-family: 'Tajawal', sans-serif;
    transition: all 0.3s;
}

.btn-edit:hover {
    background: rgba(99, 102, 241, 0.2);
    border-color: #6366F1;
}

.question-text {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
    line-height: 1.6;
}

.question-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.question-options .option {
    padding: 8px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.question-options .option.correct {
    background: rgba(34, 197, 94, 0.1);
    border-color: rgba(34, 197, 94, 0.3);
    color: #4ade80;
}

.question-explanation {
    font-size: 13px;
    color: var(--text-secondary);
    background: rgba(99, 102, 241, 0.05);
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 8px;
    line-height: 1.5;
}

.question-type {
    font-size: 12px;
    color: var(--text-muted);
}

/* ============ Pagination ============ */
.pagination-info {
    font-size: 14px;
    color: var(--text-muted);
}

.pagination-controls {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
}

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.page-btn {
    min-width: 36px;
    height: 36px;
    padding: 0 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: 'Tajawal', sans-serif;
    transition: all 0.2s;
}

.page-btn:hover:not(:disabled) {
    border-color: var(--green-400);
    color: var(--green-400);
}

.page-btn.active {
    background: linear-gradient(135deg, #6366F1, #4F46E5);
    border-color: #6366F1;
    color: white;
}

.page-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.page-ellipsis {
    color: var(--text-muted);
    padding: 0 4px;
}

/* ============ Modal ============ */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
    padding: 20px;
}

.modal.show {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    width: 100%;
    max-width: 650px;
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.95);
    transition: transform 0.3s;
}

.modal.show .modal-content {
    transform: scale(1);
}

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

.modal-header h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-close:hover {
    border-color: #ef4444;
    color: #ef4444;
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* ============ Form Elements ============ */
.form-group {
    margin-bottom: 20px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.form-group label .required {
    color: #ef4444;
}

.form-group label small {
    font-weight: 400;
    color: var(--text-muted);
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 12px 14px;
    border-radius: 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-family: 'Tajawal', sans-serif;
    font-size: 14px;
    transition: border-color 0.3s;
    resize: vertical;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--green-400);
}

.form-group .readonly-input {
    background: var(--bg-primary);
    color: var(--text-muted);
    cursor: not-allowed;
}

.options-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.option-input {
    display: flex;
    align-items: center;
    gap: 10px;
}

.option-label {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
}

.option-input input[type="text"] {
    flex: 1;
}

.correct-radio {
    width: 20px;
    height: 20px;
    accent-color: #22c55e;
    cursor: pointer;
}

.help-text {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
}

/* ============ Validation Errors ============ */
.validation-errors {
    margin-top: 16px;
}

.error-item {
    padding: 10px 14px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 8px;
    color: #f87171;
    font-size: 13px;
    margin-bottom: 8px;
}

.error-item:last-child {
    margin-bottom: 0;
}

/* ============ Toast ============ */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 14px 24px;
    background: var(--bg-card);
    border: 1px solid var(--green-400);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    z-index: 1100;
    opacity: 0;
    transition: all 0.3s;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ============ Responsive ============ */
@media (max-width: 768px) {
    .admin-page {
        padding: 12px;
    }
    
    .users-table { font-size: 13px; }
    .users-table th, .users-table td { padding: 10px 12px; }
    .history-item { flex-direction: column; align-items: flex-start; }
    
    .filter-row {
        flex-direction: column;
    }
    
    .filter-group {
        width: 100%;
    }
    
    .filter-actions {
        width: 100%;
        justify-content: stretch;
    }
    
    .filter-actions button {
        flex: 1;
    }
    
    .question-options {
        grid-template-columns: 1fr;
    }
    
    .modal-content {
        max-height: 85vh;
    }
    
    .admin-tabs {
        gap: 6px;
    }
    
    .admin-tab {
        padding: 10px 16px;
        font-size: 13px;
        flex: 1;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .stat-card {
        padding: 16px;
    }
    
    .stat-value {
        font-size: 24px;
    }
    
    .question-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .btn-edit {
        width: 100%;
        text-align: center;
    }
}
