:root {
    --line: #DDD6FE;
}

body {
    font-family: "Cairo", "Segoe UI", Tahoma, Arial, sans-serif;
    color: var(--ink);
    min-height: 100vh;
    overflow-x: hidden;
    background: linear-gradient(120deg, #F5F3FF, #EDE9FE, #DDD6FE, #F5F3FF);
    background-size: 300% 300%;
    animation: drift 18s ease-in-out infinite;
}

@keyframes drift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

/* ===== Animated background ===== */
.bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(70px);
    opacity: 0.5;
}

.blob.b1 { width: 440px; height: 440px; background: var(--p-300); top: -120px; right: -100px; animation: float1 16s ease-in-out infinite; }
.blob.b2 { width: 520px; height: 520px; background: var(--p-500); bottom: -220px; left: -140px; opacity: 0.35; animation: float2 20s ease-in-out infinite; }
.blob.b3 { width: 320px; height: 320px; background: #C4B5FD; top: 45%; left: 42%; animation: float3 14s ease-in-out infinite; }

@keyframes float1 { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(-90px, 120px); } }
@keyframes float2 { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(140px, -90px); } }
@keyframes float3 { 0%, 100% { transform: translate(0, 0) scale(1); } 50% { transform: translate(-120px, -60px) scale(1.2); } }

/* ===== Header ===== */
.title {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 60px;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    color: #fff;
    background: linear-gradient(100deg, var(--p-950), var(--p-700) 55%, var(--p-500));
    box-shadow: 0 8px 28px rgba(59, 7, 100, 0.28);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand svg {
    width: 36px;
    height: 36px;
}

.brand h2 {
    font-size: 20px;
    font-weight: 800;
    line-height: 1;
}

.brand small {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    font-weight: 400;
    color: #DDD6FE;
}

.back-home {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 44px;
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.14);
    border-radius: 999px;
    transition: background 0.2s;
}

.back-home:hover {
    background: rgba(255, 255, 255, 0.26);
}

.back-home:focus-visible {
    outline: 3px solid var(--p-300);
    outline-offset: 2px;
}

.back-home svg {
    width: 16px;
    height: 16px;
}

@media (max-width: 359px) {
    .title {
        gap: 8px;
        padding-inline: 12px;
    }

    .title .brand {
        flex: 1 1 auto;
        min-width: 0;
        gap: 8px;
    }

    .title .brand svg {
        width: 32px;
        height: 32px;
        flex: 0 0 32px;
    }

    .title .brand h2 {
        font-size: 17px;
    }

    .title .brand small {
        font-size: 10px;
        white-space: nowrap;
    }

    .title .back-home {
        flex: 0 0 auto;
        gap: 4px;
        padding-inline: 8px;
        font-size: 12px;
        white-space: nowrap;
    }
}

/* ===== Layout ===== */
.body {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    padding: 84px 14px 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cards {
    direction: ltr;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
    gap: 16px;
    width: 100%;
    max-width: 460px;
}

/* ===== Form (left) ===== */
.left {
    direction: rtl;
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(14px);
    border-radius: 20px;
    padding: 26px 20px 24px;
    box-shadow: 0 20px 50px rgba(91, 33, 182, 0.18);
}

.left form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.left label {
    font-size: 14px;
    font-weight: 600;
}

.left input,
.left select {
    width: 100%;
    height: 46px;
    padding: 0 14px;
    font-family: inherit;
    font-size: 16px;
    color: var(--ink);
    background: #FAF9FF;
    border: 1.5px solid var(--line);
    border-radius: 12px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.left input {
    text-align: right;
}

.left input[type="tel"],
.left input[type="email"],
.left input[type="password"],
#studentId {
    direction: ltr;
}

.left input::placeholder {
    color: #A8A1C4;
}

.left input:focus,
.left select:focus {
    background: #fff;
    border-color: var(--p-500);
    box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.14);
}

.left .submit {
    margin-top: auto;
    height: 48px;
    border: none;
    border-radius: 12px;
    font-family: inherit;
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    cursor: pointer;
    background: linear-gradient(100deg, var(--p-500), var(--p-700));
    transition: transform 0.2s, box-shadow 0.2s;
}

.left .submit:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 22px rgba(124, 58, 237, 0.35);
}

.left .submit:focus-visible {
    outline: 3px solid var(--p-300);
    outline-offset: 3px;
}

/* ===== Tabs + forms ===== */
.tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 5px;
    margin-bottom: 22px;
    background: #EDE9FE;
    border-radius: 14px;
}

.tab {
    height: 40px;
    border: none;
    border-radius: 10px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 700;
    color: var(--p-700);
    background: transparent;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

.tab[aria-selected="true"] {
    background: #fff;
    color: var(--p-500);
    box-shadow: 0 4px 12px rgba(91, 33, 182, 0.18);
}

.tab:focus-visible {
    outline: 3px solid var(--p-300);
}

.forms {
    display: grid;
}

.forms > form {
    grid-area: 1 / 1;
}

.forms[data-view="login"] #regForm,
.forms[data-view="signup"] #loginForm {
    display: none;
}

#loginForm {
    justify-content: center;
    gap: 18px;
}

#loginForm .submit {
    margin-top: 6px;
}

.ok {
    display: none;
    text-align: center;
    font-size: 14px;
    font-weight: 700;
    color: #15803D;
}

.ok.show {
    display: block;
}

.status {
    min-height: 22px;
    margin-top: 14px;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
}

.status.success {
    color: #15803D;
}

.status.error {
    color: #B91C1C;
}

.status.loading {
    color: var(--p-700);
}

.disabled-account-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    text-align: center;
}

.disabled-account-actions[hidden],
.disabled-account-actions small[hidden] {
    display: none;
}

.disabled-account-contact {
    display: inline-flex;
    min-height: 42px;
    align-items: center;
    justify-content: center;
    padding: 8px 18px;
    border-radius: 12px;
    color: #fff;
    background: linear-gradient(100deg, var(--p-700), var(--p-500));
    box-shadow: 0 8px 20px rgba(91, 33, 182, 0.18);
    font-weight: 800;
    text-decoration: none;
    transition: transform 0.2s, box-shadow 0.2s;
}

.disabled-account-contact:hover {
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(91, 33, 182, 0.24);
}

.disabled-account-contact:focus-visible {
    outline: 3px solid var(--p-300);
    outline-offset: 3px;
}

.disabled-account-actions small {
    color: var(--p-700);
    line-height: 1.7;
}

.submit:disabled {
    opacity: 0.65;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.form-switch,
.success-actions {
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
}

.form-switch {
    margin-top: -4px;
}

.success-actions {
    margin-top: 8px;
}

.success-actions[hidden] {
    display: none;
}

.switch-link {
    border: 0;
    padding: 0;
    font-family: inherit;
    font-size: inherit;
    font-weight: 800;
    color: var(--p-500);
    background: transparent;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 4px;
}

.switch-link:focus-visible {
    outline: 3px solid var(--p-300);
    outline-offset: 4px;
    border-radius: 6px;
}

/* ===== Validation ===== */
.err {
    display: none;
    font-size: 12.5px;
    font-weight: 600;
    color: #B91C1C;
}

.field.invalid .err {
    display: block;
}

.field.invalid input,
.field.invalid select {
    border-color: #DC2626;
    background: #FEF2F2;
}

.field.invalid input:focus,
.field.invalid select:focus {
    box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.14);
}

/* ===== Logo card (right) ===== */
.right {
    position: relative;
    overflow: hidden;
    border-radius: 20px;
    order: -1;
    padding: 28px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    color: #fff;
    text-align: center;
    background: linear-gradient(135deg, var(--p-300) 0%, var(--p-500) 50%, var(--p-950) 100%);
    box-shadow: 0 20px 50px rgba(91, 33, 182, 0.3);
}

.right::before,
.right::after {
    content: "";
    position: absolute;
    border-radius: 50%;
    background: #fff;
    opacity: 0.07;
}

.right::before { width: 300px; height: 300px; top: -90px; right: -90px; }
.right::after { width: 240px; height: 240px; bottom: -80px; left: -70px; }

.logo-icon {
    position: relative;
    width: 96px;
    height: 96px;
    filter: drop-shadow(0 14px 22px rgba(59, 7, 100, 0.35));
    animation: bob 4.5s ease-in-out infinite;
}

@keyframes bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.logo-name {
    position: relative;
    font-size: 52px;
    font-weight: 800;
    line-height: 1;
}

.logo-sub {
    position: relative;
    margin-top: -10px;
    font-size: 16px;
    color: #DDD6FE;
}

/* ===== Tablet (768px+) ===== */
@media (min-width: 768px) {
    .title { height: 66px; padding: 0 32px; }
    .brand svg { width: 40px; height: 40px; }
    .brand h2 { font-size: 22px; }
    .body { padding: 100px 24px 36px; }
    .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 900px; gap: 20px; }
    .left { padding: 28px 24px; }
    .right { order: 0; padding: 24px; gap: 18px; border-radius: 22px; }
    .left { border-radius: 22px; }
    .logo-icon { width: 130px; height: 130px; }
    .logo-name { font-size: 64px; }
    .logo-sub { font-size: 17px; }
}

/* ===== Desktop (1024px+) ===== */
@media (min-width: 1024px) {
    .title { height: 70px; padding: 0 40px; }
    .brand svg { width: 42px; height: 42px; }
    .brand h2 { font-size: 24px; }
    .body { padding: 110px 24px 40px; }
    .cards { max-width: 888px; gap: 24px; }
    .left { padding: 34px; border-radius: 24px; }
    .right { border-radius: 24px; gap: 22px; }
    .left input, .left select { font-size: 14px; height: 44px; }
    .logo-icon { width: 150px; height: 150px; }
    .logo-name { font-size: 78px; }
    .logo-sub { font-size: 18px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
    }
}


/* ===== اختيار نوع الحساب (طالب / مدرس) ===== */
.role-pick {
    display: flex;
    flex-direction: column;
    gap: 14px;
    text-align: center;
}

.role-title {
    margin: 0;
    font-size: 24px;
    font-weight: 800;
    color: var(--p-700);
}

.role-sub {
    margin: 0 0 6px;
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
}

.role-btn {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 16px 18px;
    border: 2px solid var(--line);
    border-radius: 16px;
    background: #fff;
    font-family: inherit;
    text-align: right;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.role-btn:hover {
    transform: translateY(-2px);
    border-color: var(--p-500);
    box-shadow: 0 10px 22px rgba(124, 58, 237, 0.2);
}

.role-btn:focus-visible {
    outline: 3px solid var(--p-300);
    outline-offset: 3px;
}

.role-icon {
    display: grid;
    place-items: center;
    flex: 0 0 52px;
    height: 52px;
    border-radius: 14px;
    background: #EDE9FE;
    font-size: 26px;
}

.role-text { display: flex; flex-direction: column; gap: 2px; }
.role-text strong { font-size: 18px; font-weight: 800; color: var(--p-700); }
.role-text small { font-size: 13px; font-weight: 600; color: #6B6785; }

.role-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 14px;
    font-size: 14px;
    font-weight: 700;
    color: var(--p-700);
}

/* قبل الاختيار: نخفي نماذج الدخول، وبعده نخفي شاشة الاختيار */
.left[data-role=""] .tabs,
.left[data-role=""] .forms,
.left[data-role=""] .role-bar,
.left[data-role=""] .status,
.left[data-role=""] .success-actions { display: none; }

.left:not([data-role=""]) .role-pick { display: none; }

/* المدرس: دخول فقط */
.left[data-role="teacher"] .tabs,
.left[data-role="teacher"] #regForm,
.left[data-role="teacher"] .form-switch { display: none; }

.recovery-note {
    margin: 0;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
}

.recovery-note[hidden] {
    display: none;
}
