:root {
    --sahla-orange: #f58220;
    --sahla-orange-dark: #e07012;
    --sahla-ink: #111111;
    --sahla-text: #1f2937;
    --sahla-muted: #6b7280;
    --sahla-border: #e5e7eb;
    --sahla-bg: #f3f4f6;
    --sahla-white: #ffffff;
    --sahla-error: #b42318;
    --sahla-error-bg: #fef3f2;
    --sahla-info: #175cd3;
    --sahla-info-bg: #eff8ff;
    --radius: 12px;
    --touch: 52px;
    --page-pad: 1.5rem;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans Arabic", sans-serif;
}

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

html {
    margin: 0;
    width: 100%;
    height: 100%;
    overflow-x: hidden;
}

body {
    margin: 0;
    width: 100%;
    min-height: 100%;
    min-height: 100dvh;
    font-family: var(--font);
    color: var(--sahla-text);
    background: var(--sahla-white);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    overflow-x: hidden;
}

:focus-visible {
    outline: 3px solid rgba(245, 130, 32, 0.4);
    outline-offset: 2px;
}

/* ===== Full-screen mobile login (Android WebView) ===== */
.auth-center {
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: stretch;
    justify-content: stretch;
}

.auth-card {
    width: 100%;
    max-width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-top: max(var(--page-pad), env(safe-area-inset-top));
    padding-right: max(var(--page-pad), env(safe-area-inset-right));
    padding-bottom: max(var(--page-pad), env(safe-area-inset-bottom));
    padding-left: max(var(--page-pad), env(safe-area-inset-left));
    background: var(--sahla-white);
    border-radius: 0;
    box-shadow: none;
    overflow-x: hidden;
}

.auth-card__logo {
    display: block;
    width: min(88vw, 320px);
    height: auto;
    max-width: 100%;
    aspect-ratio: 669 / 373;
    object-fit: contain;
    margin: 0 auto 1.5rem;
    flex-shrink: 0;
}

.auth-card__hint {
    margin: 0 0 1.25rem;
    font-size: 0.95rem;
    line-height: 1.45;
    color: var(--sahla-muted);
    text-align: center;
}

/* "By creating an account, you accept the Terms of use and the Privacy policy." under the signup button. */
.auth-legal {
    margin: 0.75rem 0 0;
    font-size: 0.8rem;
    line-height: 1.45;
    color: var(--sahla-muted);
    text-align: center;
}

.auth-legal a {
    color: var(--sahla-orange);
    font-weight: 600;
}

/* Opened at least once: ticked. */
.auth-legal a.is-read::after {
    content: " \2713";
    color: #12b76a;
}

.auth-legal__error {
    margin-top: 0.5rem;
    text-align: center;
}

/* Signup button until both legal links are opened (still clickable, to explain why). */
.btn-primary.is-locked,
.btn-primary.is-locked:hover {
    background: #f9bf8e;
    box-shadow: none;
    cursor: not-allowed;
}

.auth-view {
    width: 100%;
    min-width: 0;
}

.auth-view[hidden] {
    display: none !important;
}

.auth-view.is-active {
    animation: fade-in 0.2s ease;
}

@keyframes fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
}

/* ===== Form ===== */
.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
    width: 100%;
    min-width: 0;
    text-align: start;
}

.field {
    width: 100%;
    min-width: 0;
}

.field label {
    display: block;
    margin-bottom: 0.45rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--sahla-ink);
}

.field input {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: var(--touch);
    padding: 0.75rem 1rem;
    border: 1.5px solid var(--sahla-border);
    border-radius: var(--radius);
    background: var(--sahla-white);
    color: var(--sahla-text);
    font: inherit;
    font-size: 16px; /* prevents iOS zoom */
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input::placeholder {
    color: #9ca3af;
}

.field input:hover {
    border-color: color-mix(in srgb, var(--sahla-muted) 55%, var(--sahla-border));
}

.field input:focus {
    border-color: var(--sahla-orange);
    box-shadow: 0 0 0 3px rgba(245, 130, 32, 0.18);
}

.field input.is-invalid {
    border-color: var(--sahla-error);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--sahla-error) 18%, transparent);
}

.field-error {
    margin: 0.4rem 0 0;
    font-size: 0.8125rem;
    line-height: 1.35;
    color: var(--sahla-error);
}

.field-error[hidden] {
    display: none !important;
}

.password-wrap {
    position: relative;
    width: 100%;
    min-width: 0;
}

.password-wrap input {
    padding-inline-end: 3rem;
}

.password-toggle {
    position: absolute;
    inset-inline-end: 0.2rem;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--sahla-muted);
    cursor: pointer;
}

.password-toggle svg {
    width: 20px;
    height: 20px;
}

.password-toggle .icon-hide,
.password-toggle.is-visible .icon-show {
    display: none;
}

.password-toggle.is-visible .icon-hide {
    display: block;
}

.auth-form[hidden] {
    display: none;
}

.link-btn:disabled {
    opacity: 0.6;
    cursor: default;
    text-decoration: none;
}

.form-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
    min-width: 0;
}

.check {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 44px;
    font-size: 0.875rem;
    white-space: nowrap;
    cursor: pointer;
}

.check input {
    width: 1.1rem;
    height: 1.1rem;
    margin: 0;
    flex-shrink: 0;
    accent-color: var(--sahla-orange);
}

.link-btn {
    border: 0;
    background: none;
    padding: 0;
    min-height: 44px;
    font: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--sahla-orange);
    white-space: nowrap;
    cursor: pointer;
    flex-shrink: 0;
}

.link-btn:hover {
    text-decoration: underline;
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    max-width: 100%;
    min-height: var(--touch);
    margin-top: 0.35rem;
    padding: 0.85rem 1rem;
    border: 0;
    border-radius: var(--radius);
    background: var(--sahla-orange);
    color: var(--sahla-white);
    font: inherit;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
}

.btn-primary:hover {
    background: var(--sahla-orange-dark);
}

.btn-primary:disabled {
    opacity: 0.75;
    cursor: progress;
}

.btn-primary__spinner {
    display: none;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.btn-primary.is-loading .btn-primary__spinner {
    display: inline-block;
}

.btn-ghost {
    width: 100%;
    max-width: 100%;
    min-height: var(--touch);
    border: 1px solid var(--sahla-border);
    border-radius: var(--radius);
    background: var(--sahla-white);
    color: var(--sahla-text);
    font: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
}

.alert {
    margin-bottom: 1rem;
    padding: 0.75rem 0.9rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    line-height: 1.4;
    text-align: start;
    word-break: break-word;
    background: var(--sahla-error-bg);
    color: var(--sahla-error);
}

.alert--info {
    background: var(--sahla-info-bg);
    color: var(--sahla-info);
}

/* ===== Signup ===== */
/* Long form: the card keeps a fixed height (measured once by login.js, not on keyboard resize — Android WebView)
   and only the signup panel scrolls. */
.auth-card.is-signup {
    height: var(--app-height, 100vh);
    min-height: 0;
    justify-content: flex-start;
    overflow: hidden;
}

.auth-card.is-signup .auth-card__logo {
    width: min(52vw, 200px);
    margin-bottom: 0.75rem;
}

.auth-card.is-signup #panel-signup {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    /* Room for the 3px focus ring, which the scroll box would clip. */
    margin-inline: -4px;
    padding: 4px 4px 1rem;
}

.auth-switch {
    margin: 0.25rem 0 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    font-size: 0.92rem;
    color: var(--sahla-muted);
}

.field-pair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    min-width: 0;
}

.role-picker {
    margin: 0;
    padding: 0;
    border: 0;
}

.role-picker legend {
    padding: 0;
    margin-bottom: 0.45rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--sahla-ink);
}

.role-picker__options {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.6rem;
}

.role-option {
    position: relative;
    display: block;
    cursor: pointer;
}

.role-option input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    min-height: 0;
    padding: 0;
}

.role-option__card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-height: 76px;
    padding: 0.6rem 0.35rem;
    border: 1.5px solid var(--sahla-border);
    border-radius: var(--radius);
    background: var(--sahla-white);
    color: var(--sahla-text);
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
    transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.role-option__card svg {
    width: 24px;
    height: 24px;
    color: var(--sahla-muted);
}

.role-option:hover .role-option__card {
    border-color: var(--sahla-orange);
}

.role-option input:checked + .role-option__card {
    border-color: var(--sahla-orange);
    background: #fff4ea;
    color: var(--sahla-orange-dark);
}

.role-option input:checked + .role-option__card svg {
    color: var(--sahla-orange);
}

.role-option input:focus-visible + .role-option__card {
    outline: 2px solid var(--sahla-orange);
    outline-offset: 2px;
}

.role-picker__note {
    margin: 0.55rem 0 0;
    padding: 0.55rem 0.75rem;
    border-radius: 10px;
    background: var(--sahla-info-bg);
    color: var(--sahla-info);
    font-size: 0.85rem;
    line-height: 1.4;
}

.role-picker__note[hidden] {
    display: none;
}

/* ===== Admin contact (seller awaiting approval) ===== */
.admin-contact {
    margin-top: 0.75rem;
}

.admin-contact__label {
    margin: 0 0 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
}

.admin-contact__links {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.5rem;
}

.admin-contact__link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-height: 48px;
    padding: 0.5rem 0.75rem;
    border-radius: 10px;
    background: #ffffff;
    border: 1px solid rgba(16, 24, 40, 0.1);
    color: #1f2937;
    text-decoration: none;
}

.admin-contact__link svg {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
}

.admin-contact__link--call svg {
    color: #f58220;
}

.admin-contact__link--whatsapp svg {
    color: #25d366;
}

.admin-contact__link:hover {
    border-color: currentColor;
}

.admin-contact__text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.2;
}

.admin-contact__kind {
    font-size: 0.75rem;
    color: #6b7280;
}

.admin-contact__number {
    font-weight: 700;
    font-size: 0.95rem;
    unicode-bidi: isolate;
    text-align: start;
}

.role-picker__note p {
    margin: 0;
}

@media (max-width: 340px) {
    .field-pair {
        grid-template-columns: 1fr;
    }
}

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

@media (prefers-reduced-motion: reduce) {
    .auth-view.is-active {
        animation: none;
    }
}

/* Very narrow phones: stack remember / forgot */
@media (max-width: 360px) {
    .form-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.15rem;
    }
}

/* Desktop / large tablet: centered card */
@media (min-width: 768px) {
    body {
        background: var(--sahla-bg);
    }

    .auth-center {
        align-items: center;
        justify-content: center;
        padding: 2rem;
    }

    .auth-card {
        width: 100%;
        max-width: 420px;
        min-height: 0;
        padding: 2.5rem 2rem 2rem;
        border-radius: 16px;
        box-shadow: 0 8px 30px rgba(16, 24, 40, 0.08);
    }

    .auth-card__logo {
        width: 340px;
        max-width: 340px;
        margin-bottom: 1.75rem;
    }

    .auth-card.is-signup {
        height: min(860px, calc(var(--app-height, 100vh) - 4rem));
        padding-bottom: 1rem;
    }

    .auth-card.is-signup .auth-card__logo {
        width: 200px;
        max-width: 200px;
        margin-bottom: 1rem;
    }
}

/* ===== Stub pages ===== */
.stub-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    background: var(--sahla-bg);
}

.stub-card {
    width: 100%;
    max-width: 400px;
    padding: 2rem 1.5rem;
    border-radius: 16px;
    background: var(--sahla-white);
    box-shadow: 0 8px 30px rgba(16, 24, 40, 0.08);
    text-align: center;
}

.stub-logo {
    width: min(72vw, 160px);
    height: auto;
    aspect-ratio: 669 / 373;
    object-fit: contain;
    margin: 0 auto 1rem;
}

.stub-card h1 {
    margin: 0 0 0.5rem;
    font-size: 1.35rem;
    color: var(--sahla-ink);
}

.stub-card p {
    margin: 0 0 1.5rem;
    line-height: 1.5;
    color: var(--sahla-muted);
}

.stub-card .btn-primary {
    max-width: 280px;
    margin-inline: auto;
    text-decoration: none;
}

/* ===== Terms / privacy popup on signup (legal-popup.js) ===== */
:root:has(.legal-dialog[open]) {
    overflow: hidden;
}

.legal-dialog {
    width: min(100% - 2rem, 42rem);
    max-width: none;
    max-height: min(85dvh, 48rem);
    padding: 0;
    border: 0;
    border-radius: 16px;
    background: var(--sahla-white);
    color: var(--sahla-text);
    box-shadow: 0 24px 60px rgba(16, 24, 40, 0.25);
}

.legal-dialog[open] {
    display: flex;
    flex-direction: column;
}

.legal-dialog::backdrop {
    background: rgba(17, 17, 17, 0.55);
}

.legal-dialog__head {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-block: 0.85rem;
    padding-inline: 1.25rem 0.75rem;
    border-bottom: 1px solid var(--sahla-border);
}

.legal-dialog__title {
    flex: 1;
    min-width: 0;
    margin: 0;
    font-size: 1.15rem;
    color: var(--sahla-ink);
}

.legal-dialog__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--sahla-muted);
    cursor: pointer;
}

.legal-dialog__close:hover {
    background: var(--sahla-bg);
    color: var(--sahla-ink);
}

.legal-dialog__close svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
}

.legal-dialog__body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 1rem 1.25rem 1.5rem;
    font-size: 0.95rem;
    line-height: 1.55;
    overflow-wrap: anywhere;
}

.legal-dialog__foot {
    padding: 0.75rem 1.25rem max(0.75rem, env(safe-area-inset-bottom));
    border-top: 1px solid var(--sahla-border);
}

.legal-dialog__foot .btn-primary {
    margin-top: 0;
}

.legal-dialog__status {
    margin: 1rem 0;
    color: var(--sahla-muted);
    text-align: center;
}

/* The loaded page's content (same classes as on /privacy, /terms). */
.legal-dialog__body h2 {
    margin: 1.5rem 0 0.5rem;
    font-size: 1.05rem;
    color: var(--sahla-ink);
}

.legal-dialog__body h3 {
    margin: 1rem 0 0.4rem;
    font-size: 0.98rem;
    color: var(--sahla-ink);
}

.legal-dialog__body p {
    margin: 0 0 0.75rem;
}

.legal-dialog__body ul,
.legal-dialog__body ol {
    margin: 0 0 0.85rem;
    padding-inline-start: 1.25rem;
}

.legal-dialog__body li + li {
    margin-top: 0.4rem;
}

.legal-dialog__body strong {
    color: var(--sahla-ink);
}

.legal-dialog__body a {
    color: var(--sahla-orange-dark);
    font-weight: 600;
}

.legal-dialog__body .legal-kicker {
    margin-bottom: 0.75rem;
    font-size: 0.8rem;
    color: var(--sahla-muted);
}

.legal-dialog__body .legal-jump {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.75rem 0;
}

.legal-dialog__body .legal-jump a {
    padding: 0.35rem 0.8rem;
    border: 1px solid var(--sahla-border);
    border-radius: 999px;
    color: var(--sahla-ink);
    font-size: 0.85rem;
    text-decoration: none;
}

.legal-dialog__body .legal-highlight {
    padding: 0.7rem 0.9rem;
    border-inline-start: 4px solid var(--sahla-orange);
    border-radius: 8px;
    background: rgba(245, 130, 32, 0.12);
    color: var(--sahla-ink);
    font-weight: 600;
}

.legal-dialog__body .legal-steps,
.legal-dialog__body .legal-contact {
    padding: 0.85rem 1rem;
    border: 1px solid var(--sahla-border);
    border-radius: var(--radius);
}

.legal-dialog__body .legal-steps {
    padding-inline-start: 2.1rem;
}

.legal-dialog__body .legal-contact {
    margin-top: 1.25rem;
}

.legal-dialog__body .legal-contact h2 {
    margin-top: 0;
}

.legal-dialog__body .legal-contact__list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.legal-dialog__body .legal-contact__list li {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.75rem;
}

.legal-dialog__body .legal-contact__list span {
    min-width: 6rem;
    color: var(--sahla-muted);
}

/* Phones: almost full screen, but the page stays visible around the box. */
@media (max-width: 520px) {
    .legal-dialog {
        width: calc(100% - 2rem);
        max-height: calc(100dvh - 4rem);
        border-radius: 14px;
    }
}
