@font-face {
    font-family: 'Rudaw';
    src: url('fonts/rudaw.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

:root { 
    --primary: #6366f1;
    --secondary: #a855f7;
    --accent: #06b6d4;
    --dark: #1a1a2e; 
    --card-bg: rgba(255, 255, 255, 0.8);
    --card-radius: 20px; 
    --shadow: 0 6px 20px rgba(0,0,0,0.1); 
    --text-main: #0f172a;
    --text-muted: #475569;
    --bg-gradient: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
}

* { 
    box-sizing: border-box; 
    -webkit-user-select: none; 
    user-select: none; 
    margin: 0;
    padding: 0;
}

input, textarea, [contenteditable="true"] {
    -webkit-user-select: text;
    user-select: text;
}

html, body {
    height: 100%;
    overflow-x: hidden;
}

body { 
    font-family: 'Rudaw', Tahoma, sans-serif;
    background: var(--bg-gradient);
    color: var(--text-main); 
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.7;
    direction: rtl; 
    touch-action: pan-x pan-y;
}

body::before { 
    content: ''; 
    position: fixed; 
    top: -50%; 
    left: -50%; 
    width: 200%; 
    height: 200%; 
    background: radial-gradient(circle, rgba(99,102,241,0.05) 1px, transparent 1px); 
    background-size: 50px 50px; 
    z-index: 0; 
    pointer-events: none; 
}

/* ===== LOGIN SCREEN ===== */
#loginScreen {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(145deg, #f8fafc 0%, #eef2ff 50%, #f1f5f9 100%);
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 9999;
    -webkit-overflow-scrolling: touch;
}

#loginScreen::before {
    content: '';
    position: fixed;
    top: -50%; left: -50%;
    width: 200%; height: 200%;
    background: radial-gradient(circle, rgba(99,102,241,0.03) 1px, transparent 1px);
    background-size: 40px 40px;
    z-index: 0;
    pointer-events: none;
}

.ls-wrap {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
    padding: 48px 20px 60px;
    animation: lsFadeUp 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes lsFadeUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.ls-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    margin-bottom: 32px;
    text-align: center;
}

.ls-logo-ring {
    width: 80px; height: 80px;
    background: linear-gradient(135deg, #4F46E5 0%, #7C3AED 50%, #8B5CF6 100%);
    border-radius: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    box-shadow: 0 10px 40px rgba(79, 70, 229, 0.35), 0 0 0 8px rgba(79, 70, 229, 0.08);
    animation: logoFloat 4s ease-in-out infinite;
}

@keyframes logoFloat {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-8px) rotate(2deg); }
}

.ls-brand-name {
    font-size: 26px; font-weight: 800; color: #1e293b; margin: 0; line-height: 1.3;
}

.ls-brand-name em {
    font-style: normal;
    background: linear-gradient(135deg, #4F46E5 0%, #7C3AED 50%, #EC4899 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.ls-brand-sub { font-size: 14px; color: #64748b; font-weight: 500; margin: 0; }

.attempts-warning {
    display: none;
    background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
    border: 1.5px solid #fbbf24;
    border-radius: 14px;
    padding: 16px 20px;
    margin-bottom: 16px;
    font-size: 13px; font-weight: 600; color: #92400e;
    text-align: center;
    box-shadow: 0 4px 16px rgba(251, 191, 36, 0.15);
}

.attempts-warning.show { display: block; }

.attempts-dots { display: flex; justify-content: center; gap: 8px; margin-top: 12px; }

.attempt-dot {
    width: 12px; height: 12px;
    border-radius: 50%;
    border: 2px solid #d97706;
    background: transparent;
    transition: all 0.3s ease;
}

.attempt-dot.used { background: #ef4444; border-color: #ef4444; box-shadow: 0 0 8px rgba(239,68,68,0.4); }
.attempt-dot.last { background: #f59e0b; border-color: #f59e0b; animation: dotBlink 1s infinite; }

@keyframes dotBlink {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.9); }
}

.lockout-banner {
    display: none;
    background: linear-gradient(135deg, #fff1f2 0%, #ffe4e6 100%);
    border: 1.5px solid #f87171;
    border-radius: 18px;
    padding: 28px 24px;
    margin-bottom: 20px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(239,68,68,0.12);
}

.lockout-banner.show { display: block; }

.lockout-banner .lock-icon {
    font-size: 40px; display: block; margin-bottom: 14px;
    animation: lockShake 0.5s ease-in-out;
}

@keyframes lockShake {
    0%, 100% { transform: rotate(0); }
    25% { transform: rotate(-10deg); }
    75% { transform: rotate(10deg); }
}

.lockout-banner .lock-title { font-size: 15px; font-weight: 700; color: #be123c; margin-bottom: 14px; }

.lockout-banner .lock-timer {
    font-size: 36px; font-weight: 800; color: #e11d48;
    font-variant-numeric: tabular-nums; letter-spacing: 4px;
    background: white; border: 2px solid #fecdd3; border-radius: 14px;
    padding: 12px 32px; display: inline-block; margin: 12px 0;
}

.lockout-banner .lock-sub { font-size: 12px; color: #9f1239; margin-top: 10px; }

.ls-login-card {
    background: white;
    border: 1px solid rgba(148,163,184,0.2);
    border-radius: 20px;
    padding: 28px 24px;
    margin-bottom: 14px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.04);
}

.ls-field-label {
    font-size: 14px; font-weight: 700; color: #334155;
    margin-bottom: 12px;
    display: flex; align-items: center; gap: 8px;
}

.ls-field-label::before { content: "🔑"; font-size: 16px; }

.ls-code-field-wrap {
    display: flex; align-items: center;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border: 2px solid #e2e8f0;
    border-radius: 14px;
    overflow: hidden;
    transition: all 0.25s ease;
}

.ls-code-field-wrap:focus-within {
    border-color: #4F46E5;
    box-shadow: 0 0 0 4px rgba(79,70,229,0.1);
    background: white;
}

.ls-code-icon {
    display: flex; align-items: center; justify-content: center;
    padding: 0 18px; font-size: 22px; color: #94a3b8;
    border-left: 1px solid #e2e8f0;
    background: rgba(248,250,252,0.5);
}

.login-input {
    flex: 1; border: none; outline: none;
    padding: 18px 18px 18px 0;
    font-size: 18px; font-weight: 700; color: #1e293b;
    background: transparent;
    direction: ltr;
    font-family: 'Courier New', monospace;
    letter-spacing: 3px; text-align: center;
}

.login-input::placeholder {
    color: #cbd5e1; font-weight: 400; font-size: 14px;
    letter-spacing: 0; font-family: 'Rudaw', Tahoma, sans-serif;
}

.login-input:disabled { opacity: 0.5; cursor: not-allowed; }

.ls-code-hint {
    font-size: 12px; color: #64748b; margin-top: 14px;
    line-height: 1.7; display: flex; align-items: center; gap: 6px;
}

.ls-code-hint::before { content: "💡"; font-size: 14px; }

.login-btn {
    width: 100%;
    background: linear-gradient(135deg, #4F46E5 0%, #7C3AED 50%, #8B5CF6 100%);
    border: none; border-radius: 14px; padding: 18px;
    font-size: 16px; font-weight: 700; color: white;
    font-family: inherit; cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 6px 24px rgba(79,70,229,0.4);
    display: flex; align-items: center; justify-content: center; gap: 10px;
    margin-top: 22px; position: relative; overflow: hidden;
}

.login-btn:hover:not(:disabled) { transform: translateY(-3px); box-shadow: 0 10px 36px rgba(79,70,229,0.5); }
.login-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.ls-divider {
    display: flex; align-items: center; gap: 16px; margin: 28px 0;
}

.ls-divider-line { flex: 1; height: 1px; background: linear-gradient(90deg, transparent, #cbd5e1, transparent); }
.ls-divider-text { font-size: 12px; color: #64748b; white-space: nowrap; font-weight: 600; }

.ls-pay-box {
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
    border: 1.5px solid #86efac;
    border-radius: 20px; padding: 24px;
    position: relative; overflow: hidden;
}

.ls-pay-header { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }

.ls-pay-icon {
    width: 48px; height: 48px;
    background: linear-gradient(135deg, #10B981 0%, #059669 100%);
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
    box-shadow: 0 6px 20px rgba(16,185,129,0.35);
}

.ls-pay-title { font-size: 15px; font-weight: 700; color: #065f46; }
.ls-pay-desc { font-size: 13px; color: #047857; line-height: 1.9; margin-bottom: 18px; }

.ls-phone-row {
    display: flex; align-items: center; gap: 12px;
    background: white; border: 2px solid #a7f3d0;
    border-radius: 14px; padding: 16px 20px; margin-bottom: 16px;
}

.ls-phone-num {
    flex: 1;
    font-family: 'Courier New', monospace;
    font-size: 22px; font-weight: 800; color: #059669;
    letter-spacing: 3px; direction: ltr;
}

.copy-btn {
    display: flex; align-items: center; gap: 8px;
    background: linear-gradient(135deg, #10B981 0%, #059669 100%);
    border: none; border-radius: 10px; padding: 12px 18px;
    color: white; font-size: 13px; font-weight: 700;
    font-family: inherit; cursor: pointer; transition: all 0.2s ease;
}

.copy-btn:hover { transform: translateY(-2px); }

.ls-methods { display: flex; gap: 10px; }

.method-tag {
    background: white; border: 1.5px solid #a7f3d0;
    border-radius: 10px; padding: 10px 18px;
    font-size: 13px; font-weight: 700; color: #047857;
}

.login-error {
    display: none;
    background: linear-gradient(135deg, #fff1f2 0%, #ffe4e6 100%);
    border: 1.5px solid #fca5a5;
    border-radius: 14px; padding: 16px 20px; margin-top: 14px;
    font-size: 14px; font-weight: 600; color: #be123c; text-align: center;
}

.login-success {
    display: none;
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
    border: 1.5px solid #86efac;
    border-radius: 14px; padding: 16px 20px; margin-top: 14px;
    font-size: 14px; font-weight: 600; color: #166534; text-align: center;
}

.ls-footer {
    text-align: center; margin-top: 36px;
    font-size: 13px; color: #94a3b8; font-weight: 500; padding-bottom: 20px;
}

/* ===== MAIN APP ===== */
#mainApp { display: none; }

.container {
    max-width: 1000px; margin: 0 auto;
    padding: 24px; position: relative; z-index: 1; flex: 1;
}

h1 { 
    font-size: clamp(28px, 5vw, 42px); font-weight: 800;
    text-align: center; 
    background: var(--accent); 
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent; 
    margin-bottom: 30px; 
}

.card { 
    background: var(--card-bg); border-radius: var(--card-radius); 
    box-shadow: var(--shadow); padding: 30px; margin-bottom: 25px; 
    border: 2px solid rgba(99,102,241,0.1); 
}

.controls { 
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; 
}

.autocomplete-wrapper { position: relative; width: 100%; }

input, select { 
    padding: 14px 20px; border: 2px solid transparent; 
    background: #f8f8f8; border-radius: 12px; outline: none; 
    transition: all 0.3s ease; font-size: 13px; width: 100%; font-family: inherit;
}

input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(99,102,241,0.2); }

.autocomplete-items {
    position: absolute; border: 2px solid var(--primary); border-top: none;
    z-index: 99; top: 100%; left: 0; right: 0;
    background: white; border-radius: 0 0 12px 12px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.15);
    max-height: 300px; overflow-y: auto; display: none;
}

.autocomplete-items.show { display: block; }

.autocomplete-item {
    padding: 12px 20px; cursor: pointer; background-color: #fff;
    border-bottom: 1px solid #f0f0f0; transition: all 0.2s ease; font-size: 14px;
}

.autocomplete-item:hover { background-color: #f5f3ff; }
.autocomplete-item.active { background: linear-gradient(90deg, #f5f3ff, #ede9fe); border-right: 4px solid var(--primary); }
.autocomplete-item strong { color: var(--primary); font-weight: 800; }

.no-suggestions { padding: 12px 20px; color: #999; font-style: italic; font-size: 13px; text-align: center; }

.suggestion-count {
    padding: 8px 20px; background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    font-size: 12px; color: #666; font-weight: 600;
    border-bottom: 2px solid #dee2e6; position: sticky; top: 0; z-index: 1;
}

/* Toggle */
.toggle-container { 
    display: flex; align-items: center; justify-content: center; gap: 15px;
    padding: 15px;
    background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
    border-radius: 12px; margin: 15px 0; border: 2px solid #0ea5e9; 
}

.toggle-label { font-size: 14px; font-weight: 600; color: #0c4a6e; }
.toggle-switch { position: relative; display: inline-block; width: 60px; height: 30px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider { 
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; 
    background-color: #cbd5e1; transition: 0.4s; border-radius: 30px; 
}
.toggle-slider:before { 
    position: absolute; content: ""; height: 22px; width: 22px; left: 4px; bottom: 4px; 
    background-color: white; transition: 0.4s; border-radius: 50%; 
}
input:checked + .toggle-slider { background: linear-gradient(135deg, #6366f1, #8b5cf6); }
input:checked + .toggle-slider:before { transform: translateX(30px); }
.toggle-status { font-size: 16px; font-weight: 700; min-width: 100px; text-align: center; }
.toggle-status.on { color: #6366f1; }
.toggle-status.off { color: #64748b; }
.toggle-info { 
    margin-top: 10px; padding: 12px; background: white; border-radius: 8px; 
    font-size: 12px; color: #475569; border-right: 3px solid #0ea5e9; 
}

/* Credit Input */
.credit-input-card {
    background: linear-gradient(135deg, #ede9fe, #ddd6fe);
    border-radius: 16px; padding: 25px; margin-bottom: 25px; border: 2px solid #c4b5fd;
}

.credit-input-card h3 { color: #6366f1; font-size: 20px; margin-bottom: 15px; display: flex; align-items: center; gap: 10px; }

.credit-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 15px; }

.credit-input-group label { display: block; font-weight: 600; font-size: 12px; color: #475569; margin-bottom: 6px; }
.credit-input-group input { width: 100%; padding: 10px 12px; font-size: 14px; }

.credit-status { background: white; padding: 15px; border-radius: 10px; margin-top: 15px; display: none; }
.credit-status.show { display: block; }

.credit-status-item {
    display: flex; justify-content: space-between;
    padding: 8px 0; border-bottom: 1px solid #e2e8f0;
}
.credit-status-item:last-child { border-bottom: none; }

/* Analysis Navigation Button */
.analysis-nav-btn {
    width: 100%;
    margin-top: 15px;
    padding: 14px 20px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    border: none; border-radius: 12px; cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 10px;
    font-family: inherit; font-size: 15px; font-weight: 700; color: white;
    box-shadow: 0 4px 15px rgba(245,158,11,0.4);
    transition: all 0.3s ease;
    animation: btnPulse 2s ease-in-out infinite;
    text-decoration: none;
}

.analysis-nav-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(245,158,11,0.5);
}

.analysis-nav-btn:active { transform: translateY(-1px); }

@keyframes btnPulse {
    0%, 100% { box-shadow: 0 4px 15px rgba(245,158,11,0.4); }
    50% { box-shadow: 0 4px 25px rgba(245,158,11,0.6); }
}

.analysis-btn-icon { font-size: 20px; }
.analysis-btn-text { flex: 1; }
.analysis-btn-arrow { font-size: 18px; animation: arrowBounce 1s ease-in-out infinite; }

@keyframes arrowBounce {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(-4px); }
}

.dept-filter-wrapper { display: flex; flex-direction: column; gap: 6px; }
#filterDeptDropdown { font-family: 'Rudaw', Tahoma, sans-serif; font-size: 14px; }
.dept-count-badge { 
    display: none; font-size: 11px; font-weight: 700; color: #6366f1; 
    background: #eef2ff; padding: 2px 8px; border-radius: 12px; 
    text-align: center; margin-top: 2px; border: 1px solid #c7d2fe; 
}
.dept-count-badge.show { display: block; }

/* Table */
.table-wrapper { overflow-x: auto; border-radius: 12px; }

table { width: 100%; border-collapse: separate; border-spacing: 0; background: white; }

thead tr { background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; }

th { padding: 12px 8px; border: 1px solid #ddd; font-weight: 700; white-space: nowrap; font-size: 13px; }

td { padding: 10px 8px; text-align: center; border: 1px solid #eee; font-size: 12px; line-height: 1.5; }

tbody tr:nth-child(even) { background: #faf5ff; }
tbody tr:hover { background: #ede9fe; }

.badge { padding: 5px 12px; border-radius: 15px; font-weight: 600; font-size: 11px; display: inline-block; }
.eligible { background: #28a745; color: white; }
.not { background: #f8d7da; color: #721c24; }

.loading { text-align: center; color: #666; padding: 30px; font-size: 16px; }

.details-btn {
    padding: 8px 16px;
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white; border: none; border-radius: 10px; cursor: pointer;
    font-size: 13px; font-weight: 700; transition: 0.3s;
    box-shadow: 0 3px 10px rgba(52,152,219,0.4);
}

.details-btn:hover { transform: translateY(-2px); }

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
    .ls-wrap { padding: 32px 16px 50px; }
    .ls-logo-ring { width: 70px; height: 70px; font-size: 32px; }
    .ls-brand-name { font-size: 22px; }
    .ls-login-card { padding: 22px 18px; }
    .login-input { font-size: 16px; padding: 16px 14px 16px 0; }
    .ls-phone-num { font-size: 18px; }
    .copy-btn { padding: 10px 14px; font-size: 12px; }
    .container { padding: 16px; }
    .card { padding: 20px; }
    .credit-grid { grid-template-columns: 1fr; }
    td, th { font-size: 11px; padding: 6px 4px; }
}