:root {
    --primary: #236b8c;
    --primary-dark: #17506b;
    --primary-light: #eaf3f7;
    --accent: #2e86ad;
    --gold: #a8813f;
    --bg-color: #f7f5f1;
    --card-bg: #ffffff;
    --text-color: #1e293b;
    --text-muted: #64748b;
    --border-color: #e4e0d9;
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.08);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* قواعد display اللاحقة تتجاوز إخفاء المتصفح الافتراضي لـ [hidden] */
[hidden] { display: none !important; }

body {
    background-color: var(--bg-color);
    background-image: linear-gradient(180deg, #f7f5f1 0%, #f2efe9 100%);
    color: var(--text-color);
    min-height: 100vh;
    padding-bottom: 40px;
    font-family: 'Tajawal', sans-serif;
    position: relative;
    overflow-x: hidden;
}

body::before {
    content: "";
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(92vw, 920px);
    height: min(92vw, 920px);
    background: url('../logo.jpg') center center / contain no-repeat;
    opacity: 0.1;
    mix-blend-mode: multiply;
    pointer-events: none;
    z-index: 0;
}

.login-choice-overlay {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(5px);
    display: flex; justify-content: center; align-items: center;
    z-index: 1000;
    overflow: hidden;
}

.login-choice-box {
    background: #f7f5f1;
    padding: 40px 30px;
    border-radius: 20px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    text-align: center;
    max-width: 460px;
    width: 90%;
    border-top: 5px solid var(--primary);
    animation: scaleIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    position: relative;
    z-index: 2;
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.92); }
    to { opacity: 1; transform: scale(1); }
}

.login-choice-box h2 { margin-bottom: 5px; color: var(--primary); font-size: 1.5rem; }
.login-choice-box p { color: var(--text-muted); margin-bottom: 25px; font-size: 0.9rem; }

.login-buttons { display: flex; flex-direction: column; gap: 12px; }
.login-buttons-row { flex-direction: row; flex-wrap: wrap; justify-content: center; margin-top: 20px; }
.login-buttons-row .btn-primary-custom,
.login-buttons-row .btn-secondary-custom { width: auto; min-width: 130px; flex: 1; max-width: 180px; }
.login-presentation-fab {
    position: absolute;
    top: calc(10px + env(safe-area-inset-top, 0px));
    right: calc(10px + env(safe-area-inset-right, 0px));
    left: auto;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.16);
    color: #eaf3f7;
    font-size: 0.7rem;
    cursor: pointer;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-presentation-fab:hover {
    background: rgba(255, 255, 255, 0.28);
}

.btn-primary-custom, .btn-secondary-custom {
    padding: 13px; border: none; border-radius: 12px;
    font-size: 1rem; font-weight: bold; cursor: pointer;
    transition: var(--transition);
    display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
}

.btn-primary-custom {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: 0 4px 12px rgba(35, 107, 140, 0.25);
}

.btn-primary-custom:hover { transform: translateY(-2px); }
.btn-primary-custom:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-secondary-custom {
    background: #f2efe9; color: #334155; border: 1px solid var(--border-color);
}

.main-container { max-width: 1280px; margin: 0 auto; padding: 25px; display: none; position: relative; z-index: 1; }

header, .page-header {
    background: var(--card-bg);
    padding: 16px 25px;
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    display: flex; justify-content: space-between; align-items: center;
    flex-wrap: wrap; gap: 15px;
    margin-bottom: 25px;
    border: 1px solid var(--border-color);
}

.btn-logout {
    background: #fef2f2; color: #ef4444; border: 1px solid #fecaca;
    padding: 10px 16px; border-radius: 10px; cursor: pointer;
    font-weight: bold; display: flex; align-items: center; gap: 8px;
}

.btn-logout:hover { background: #ef4444; color: white; }

.row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 15px; text-align: right; }
.row label { font-size: 0.88rem; font-weight: 600; color: var(--text-muted); }
.row input, .row textarea, .row select {
    padding: 10px 14px; border: 1px solid var(--border-color);
    border-radius: 10px; font-size: 0.95rem; outline: none;
    font-family: 'Tajawal', sans-serif; background: #fff;
}
.row input:focus, .row textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(35, 107, 140, 0.1); }
.row textarea { resize: vertical; min-height: 90px; }

.input-center-lg { text-align: center; font-size: 1.2rem; letter-spacing: 5px; }
.input-center-md { text-align: center; font-size: 1.1rem; }

.login-error-banner,
.login-hint-banner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
    margin-bottom: 14px;
    padding: 12px 14px;
    border-radius: 14px;
    text-align: right;
    animation: loginErrorIn 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.login-error-banner[hidden],
.login-hint-banner[hidden] {
    display: none !important;
}

.login-error-banner {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

.login-error-banner i {
    color: #ef4444;
    font-size: 1.15rem;
    margin-top: 2px;
}

.login-error-banner strong {
    display: block;
    font-size: 0.92rem;
    margin-bottom: 2px;
}

.login-error-banner span {
    display: block;
    font-size: 0.82rem;
    color: #b91c1c;
    font-weight: 600;
}

.login-hint-banner {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1d4ed8;
    font-size: 0.84rem;
    font-weight: 700;
}

.login-hint-banner i {
    margin-top: 1px;
}

@keyframes loginErrorIn {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes codePinShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

.code-pin-wrap.code-pin-wrap--error .code-pin-slots {
    animation: codePinShake 0.42s ease;
}

.code-pin-wrap.code-pin-wrap--error .code-pin-slot {
    border-color: #ef4444;
    background: #fff5f5;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
}

.code-entry-row {
    align-items: stretch;
}

.code-pin-wrap {
    width: 100%;
}

.code-pin-slots {
    display: flex;
    justify-content: center;
    gap: 10px;
    direction: ltr;
}

.code-pin-slot {
    width: 52px;
    height: 56px;
    border: 2px solid var(--border-color);
    border-radius: 14px;
    background: #fff;
    text-align: center;
    font-family: 'Tajawal', sans-serif;
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--text-color);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
    -webkit-text-security: none;
}

.code-pin-wrap[data-pin-secret="true"] .code-pin-slot {
    -webkit-text-security: disc;
    font-size: 1.5rem;
    letter-spacing: 0;
}

.code-pin-slot:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(35, 107, 140, 0.12);
    transform: translateY(-1px);
}

.code-pin-clear-btn {
    margin-top: 10px;
    align-self: center;
    border: 1px solid #d5d0c6;
    background: #f7f5f1;
    color: #475569;
    border-radius: 999px;
    padding: 8px 14px;
    font-family: 'Tajawal', sans-serif;
    font-size: 0.82rem;
    font-weight: 800;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.code-pin-clear-btn:hover {
    background: #eef2f7;
    border-color: #94a3b8;
}

@media (max-width: 600px) {
    .code-pin-slot {
        width: 46px;
        height: 52px;
        font-size: 1.2rem;
    }

    .code-pin-slots {
        gap: 8px;
    }
}

.modal {
    display: none; position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.6); backdrop-filter: blur(5px);
    justify-content: center; align-items: center; z-index: 1001;
}

.modal-content {
    background: white; padding: 30px; border-radius: 20px;
    width: 90%; max-width: 480px; position: relative;
    box-shadow: var(--shadow-md); border-top: 4px solid var(--primary);
    text-align: center;
}

.close-btn { position: absolute; top: 18px; left: 20px; font-size: 1.5rem; cursor: pointer; color: var(--text-muted); }
.modal-title { color: var(--primary); margin-bottom: 20px; }

.btn-action {
    padding: 12px 20px; border: none; border-radius: 12px;
    font-weight: bold; cursor: pointer; color: white;
    display: flex; align-items: center; gap: 10px;
}

.btn-add { background: linear-gradient(135deg, #26749a, #236b8c); }

@media (max-width: 600px) {
    .login-buttons-row .btn-primary-custom,
    .login-buttons-row .btn-secondary-custom { max-width: 100%; width: 100%; }

.ios-install-hint {
    margin: 14px 0 4px;
    padding: 12px 14px;
    border-radius: 12px;
    background: #eff6ff;
    border: 1px solid #93c5fd;
    text-align: right;
    font-size: 0.82rem;
    color: #1e3a5f;
}
.ios-install-hint p {
    margin: 0 0 8px;
    font-weight: 800;
}
.ios-install-hint ol {
    margin: 0;
    padding-right: 18px;
    line-height: 1.55;
}
.ios-install-hint li { margin-bottom: 4px; }
    .main-container { padding: 16px; }
}
