/* ============================================================
   School Jobs System - Main Stylesheet (Arabic RTL)
   ============================================================ */

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

:root {
    --primary: #1a3a5c;
    --primary-light: #2d5f8a;
    --primary-dark: #0f2338;
    --accent: #c8973a;
    --accent-light: #e8b55a;
    --success: #1a7a4a;
    --danger: #b5271e;
    --warning: #d4820a;
    --info: #1a6a8c;
    --bg: #f4f6f9;
    --bg-white: #ffffff;
    --bg-card: #ffffff;
    --border: #dee2e8;
    --text: #1a2332;
    --text-muted: #6b7a8d;
    --text-light: #9aacbe;
    --sidebar-w: 280px;
    --shadow-sm: 0 1px 4px rgba(26,58,92,0.08);
    --shadow: 0 4px 16px rgba(26,58,92,0.12);
    --shadow-lg: 0 8px 32px rgba(26,58,92,0.18);
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 16px;
    --transition: all 0.22s cubic-bezier(0.4,0,0.2,1);
}

*, *::before, *::after { box-sizing: border-box; }

html { direction: rtl; scroll-behavior: smooth; }

body {
    font-family: 'Tajawal', 'Cairo', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    font-size: 15px;
    margin: 0;
}

/* ============================================================
   TYPOGRAPHY
   ============================================================ */
h1, h2, h3, h4, h5, h6 {
    font-family: 'Cairo', 'Tajawal', sans-serif;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.4;
}

.display-title {
    font-family: 'Cairo', sans-serif;
    font-weight: 900;
    letter-spacing: -0.5px;
}

/* ============================================================
   ADMIN LAYOUT
   ============================================================ */
.admin-wrapper {
    display: flex;
    min-height: 100vh;
    direction: rtl;
}

.sidebar {
    width: var(--sidebar-w);
    min-height: 100vh;
    background: linear-gradient(180deg, var(--primary-dark) 0%, var(--primary) 40%, var(--primary-light) 100%);
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 20px rgba(0,0,0,0.15);
    transition: var(--transition);
}

.sidebar-brand {
    padding: 24px 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    text-align: center;
}

.sidebar-brand .brand-logo {
    width: 56px;
    height: 56px;
    background: var(--accent);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 12px;
    font-size: 24px;
    color: white;
    box-shadow: 0 4px 12px rgba(200,151,58,0.4);
}

.sidebar-brand h4 {
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    margin: 0;
    line-height: 1.4;
}

.sidebar-brand small {
    color: rgba(255,255,255,0.55);
    font-size: 11px;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.nav-section-label {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 1.5px;
    color: rgba(255,255,255,0.35);
    text-transform: uppercase;
    padding: 16px 10px 6px;
    margin-bottom: 4px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    color: rgba(255,255,255,0.75);
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
    margin-bottom: 2px;
    position: relative;
}

.sidebar-link i {
    font-size: 16px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-link:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
    text-decoration: none;
}

.sidebar-link.active {
    background: rgba(255,255,255,0.15);
    color: #fff;
    font-weight: 600;
}

.sidebar-link.active::before {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--accent);
    border-radius: 2px 0 0 2px;
}

.sidebar-footer {
    padding: 14px 12px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.sidebar-footer .user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: var(--radius-sm);
    background: rgba(255,255,255,0.08);
}

.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: white;
    flex-shrink: 0;
    font-weight: 700;
}

.user-info-text {
    flex: 1;
    min-width: 0;
}

.user-info-text .name {
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-info-text .role {
    font-size: 11px;
    color: rgba(255,255,255,0.5);
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
    margin-right: var(--sidebar-w);
    flex: 1;
    min-width: 0;
}

.topbar {
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
    padding: 0 28px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.topbar-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    margin: 0;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.page-body {
    padding: 28px;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
}

.card-header {
    padding: 16px 22px;
    border-bottom: 1px solid var(--border);
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.card-header h5, .card-header h6 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
}

.card-body {
    padding: 22px;
}

/* ============================================================
   STAT CARDS
   ============================================================ */
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px;
    display: flex;
    align-items: center;
    gap: 18px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.stat-card:hover {
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

.stat-icon.blue { background: rgba(26,58,92,0.1); color: var(--primary); }
.stat-icon.gold { background: rgba(200,151,58,0.12); color: var(--accent); }
.stat-icon.green { background: rgba(26,122,74,0.1); color: var(--success); }
.stat-icon.red { background: rgba(181,39,30,0.1); color: var(--danger); }
.stat-icon.teal { background: rgba(26,106,140,0.1); color: var(--info); }

.stat-info .stat-number {
    font-size: 28px;
    font-weight: 800;
    line-height: 1;
    color: var(--primary);
    font-family: 'Cairo', sans-serif;
}

.stat-info .stat-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    font-family: 'Tajawal', sans-serif;
    font-size: 14px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    padding: 8px 18px;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 7px;
    cursor: pointer;
    border: none;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-light); color: #fff; }

.btn-accent {
    background: var(--accent);
    color: #fff;
}
.btn-accent:hover { background: var(--accent-light); color: #fff; }

.btn-success {
    background: var(--success);
    color: #fff;
}
.btn-success:hover { background: #22a05f; color: #fff; }

.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover { background: #d63030; color: #fff; }

.btn-outline-primary {
    background: transparent;
    color: var(--primary);
    border: 1.5px solid var(--primary);
}
.btn-outline-primary:hover { background: var(--primary); color: #fff; }

.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-lg { padding: 12px 28px; font-size: 16px; }
.btn-icon { padding: 7px 10px; }

/* ============================================================
   FORMS
   ============================================================ */
.form-label {
    font-weight: 600;
    font-size: 14px;
    color: var(--text);
    margin-bottom: 6px;
}

.form-control, .form-select {
    font-family: 'Tajawal', sans-serif;
    font-size: 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 13px;
    color: var(--text);
    background: #fff;
    transition: var(--transition);
    direction: rtl;
    width: 100%;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,58,92,0.1);
    outline: none;
}

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

.required-star { color: var(--danger); }

/* ============================================================
   TABLES
   ============================================================ */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.table {
    width: 100%;
    margin: 0;
    font-size: 14px;
    border-collapse: collapse;
}

.table th {
    background: #f1f4f8;
    font-weight: 700;
    font-size: 13px;
    color: var(--primary);
    padding: 12px 16px;
    white-space: nowrap;
    border-bottom: 2px solid var(--border);
    text-align: right;
}

.table td {
    padding: 12px 16px;
    border-bottom: 1px solid #f0f2f5;
    vertical-align: middle;
    text-align: right;
}

.table tbody tr:hover { background: #f8fafd; }
.table tbody tr:last-child td { border-bottom: none; }

/* ============================================================
   BADGES
   ============================================================ */
.badge {
    font-family: 'Tajawal', sans-serif;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.badge-new { background: rgba(26,106,140,0.1); color: var(--info); }
.badge-review { background: rgba(200,151,58,0.12); color: var(--warning); }
.badge-shortlisted { background: rgba(26,58,92,0.1); color: var(--primary); }
.badge-accepted { background: rgba(26,122,74,0.1); color: var(--success); }
.badge-rejected { background: rgba(181,39,30,0.1); color: var(--danger); }

/* ============================================================
   FORM BUILDER SPECIFIC
   ============================================================ */
.builder-canvas {
    min-height: 400px;
    background: #f8fafd;
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.builder-canvas.drag-over {
    border-color: var(--primary);
    background: rgba(26,58,92,0.04);
}

.field-card {
    background: #fff;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 10px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    cursor: grab;
    transition: var(--transition);
    position: relative;
}

.field-card:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow);
}

.field-card.sortable-ghost {
    opacity: 0.4;
    background: rgba(26,58,92,0.05);
}

.field-card.sortable-chosen {
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}

.field-drag-handle {
    color: var(--text-light);
    cursor: grab;
    padding: 2px 4px;
    margin-top: 2px;
    font-size: 16px;
}

.field-type-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: rgba(26,58,92,0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    font-size: 15px;
    flex-shrink: 0;
}

.field-info { flex: 1; min-width: 0; }
.field-info .field-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 3px;
}

.field-info .field-meta {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.field-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}

.field-tag {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(26,58,92,0.07);
    color: var(--primary);
}

.field-tag.required { background: rgba(181,39,30,0.08); color: var(--danger); }
.field-tag.searchable { background: rgba(26,122,74,0.08); color: var(--success); }
.field-tag.permission { background: rgba(200,151,58,0.1); color: var(--accent); }

/* Page tabs in builder */
.page-tab {
    background: #fff;
    border: 1.5px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 10px 18px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    margin-left: 4px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition);
}

.page-tab.active {
    border-color: var(--primary);
    border-bottom-color: #fff;
    color: var(--primary);
    background: #fff;
    position: relative;
    bottom: -1px;
}

.page-tab:hover:not(.active) { background: #f0f4f8; }

/* ============================================================
   APPLICANT FORM (Public)
   ============================================================ */
.app-public {
    background: var(--bg);
    min-height: 100vh;
}

.form-header {
    padding: 36px 24px;
    text-align: center;
    color: #fff;
    position: relative;
    overflow: hidden;
}

.form-header::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-light) 100%);
    z-index: 0;
}

.form-header::after {
    content: '';
    position: absolute;
    bottom: -30px;
    left: 0; right: 0;
    height: 60px;
    background: var(--bg);
    clip-path: ellipse(55% 100% at 50% 100%);
    z-index: 1;
}

.form-header-content { position: relative; z-index: 2; }

.form-progress {
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: 16px 24px;
    box-shadow: var(--shadow-sm);
}

.progress-steps {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    flex-wrap: wrap;
}

.progress-step {
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
}

.step-num {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #e8ecf0;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    transition: var(--transition);
    flex-shrink: 0;
    z-index: 1;
}

.step-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}

.progress-step.active .step-num { background: var(--primary); color: #fff; }
.progress-step.active .step-label { color: var(--primary); }
.progress-step.done .step-num { background: var(--success); color: #fff; }

.step-connector {
    width: 40px;
    height: 2px;
    background: #e0e4ea;
    margin: 0 6px;
    flex-shrink: 0;
}

.progress-step.done ~ .step-connector { background: var(--success); }

.form-body {
    max-width: 760px;
    margin: 40px auto;
    padding: 0 20px 60px;
}

/* Repeater */
.repeater-row {
    background: #f8fafd;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 10px;
    position: relative;
}

.repeater-row .remove-row {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(181,39,30,0.08);
    color: var(--danger);
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    transition: var(--transition);
}

.repeater-row .remove-row:hover { background: var(--danger); color: #fff; }

.add-row-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    background: rgba(26,58,92,0.06);
    color: var(--primary);
    border: 1.5px dashed var(--primary-light);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: var(--transition);
    margin-top: 4px;
}

.add-row-btn:hover { background: rgba(26,58,92,0.1); }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 60%, var(--primary-light) 100%);
    position: relative;
    overflow: hidden;
}

.login-page::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -20%;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    background: rgba(255,255,255,0.04);
}

.login-page::after {
    content: '';
    position: absolute;
    bottom: -30%;
    left: -10%;
    width: 400px;
    height: 400px;
    border-radius: 50%;
    background: rgba(200,151,58,0.08);
}

.login-card {
    background: #fff;
    border-radius: var(--radius-lg);
    padding: 44px 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    position: relative;
    z-index: 1;
}

/* ============================================================
   MODALS
   ============================================================ */
.modal-content {
    border-radius: var(--radius-lg);
    border: none;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
    direction: rtl;
}

.modal-title {
    font-family: 'Cairo', sans-serif;
    font-weight: 700;
    font-size: 17px;
}

.modal-body { padding: 24px; direction: rtl; }
.modal-footer { padding: 14px 24px; direction: rtl; }

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
    border-radius: var(--radius);
    padding: 14px 18px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

/* ============================================================
   UTILITIES
   ============================================================ */
.text-primary { color: var(--primary) !important; }
.text-accent { color: var(--accent) !important; }
.text-muted { color: var(--text-muted) !important; }
.bg-primary { background: var(--primary) !important; }

.divider {
    height: 1px;
    background: var(--border);
    margin: 20px 0;
}

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(2px);
}

.spinner-ring {
    width: 42px;
    height: 42px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 48px;
    opacity: 0.3;
    margin-bottom: 16px;
    display: block;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 992px) {
    :root { --sidebar-w: 0px; }
    .sidebar { transform: translateX(100%); }
    .sidebar.open { transform: translateX(0); --sidebar-w: 280px; }
    .main-content { margin-right: 0; }
}

@media (max-width: 576px) {
    .page-body { padding: 16px; }
    .topbar { padding: 0 16px; }
    .login-card { padding: 28px 20px; margin: 16px; }
}

/* ============================================================
   PRINT
   ============================================================ */
@media print {
    .sidebar, .topbar, .no-print { display: none !important; }
    .main-content { margin: 0 !important; }
}

/* ============================================================
   DRAG & DROP TOOL PALETTE
   ============================================================ */
.tool-palette {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.tool-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: #fff;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: grab;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    transition: var(--transition);
    user-select: none;
}

.tool-item:hover {
    border-color: var(--primary-light);
    background: rgba(26,58,92,0.04);
    color: var(--primary);
}

.tool-item i {
    font-size: 16px;
    color: var(--primary);
    width: 18px;
    text-align: center;
}

/* ============================================================
   VISIBILITY RULES UI
   ============================================================ */
.rule-row {
    background: #f8fafd;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.rule-logic-badge {
    background: var(--primary);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 10px;
    border-radius: 10px;
    letter-spacing: 0.5px;
}

/* ============================================================
   FILE UPLOAD ZONE
   ============================================================ */
.file-upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 28px 20px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: #f8fafd;
}

.file-upload-zone:hover, .file-upload-zone.drag-over {
    border-color: var(--primary);
    background: rgba(26,58,92,0.04);
}

.file-upload-zone i {
    font-size: 32px;
    color: var(--primary-light);
    margin-bottom: 10px;
    display: block;
}

/* ============================================================
   APPLICATION VIEW
   ============================================================ */
.app-view-section {
    margin-bottom: 24px;
}

.app-view-section .section-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--primary);
    padding-bottom: 10px;
    border-bottom: 2px solid var(--primary);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.app-answer-row {
    display: flex;
    gap: 16px;
    padding: 10px 0;
    border-bottom: 1px solid #f0f2f5;
    align-items: flex-start;
}

.app-answer-row:last-child { border-bottom: none; }

.answer-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    min-width: 180px;
    flex-shrink: 0;
}

.answer-value {
    font-size: 14px;
    color: var(--text);
    flex: 1;
}

.answer-value a {
    color: var(--primary);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.answer-value a:hover { text-decoration: underline; }
