/* =============================================================================
   Admin sign-in.

   Self-contained on purpose: the sign-in screen is reached before the dashboard
   shell loads, so nothing in here may depend on style.css or admin-modern.css.

   Every colour comes from the custom properties on .cstore-login, which
   login.php fills in from settings.websiteColor (see caBrandPalette()).
   Fallbacks below are the ones used when a store has configured nothing.
   ============================================================================= */

/* ---------------------------------------------------------------- canvas ----
   The page behind the two panels, set on html as well as the body on purpose: html paints the
   viewport (what shows while overscrolling, and behind the browser chrome on a phone), the body
   paints its own box.

   Dark mode has to be decided here rather than by the palette: login.php writes the brand colours
   as an inline style on the body, and an inline value beats every rule in this file — so a neutral
   that must follow the system preference cannot be one of those variables. */
:root {
    --cstore-canvas: #eef1f5;
    color-scheme: light;
}

html {
    background: var(--cstore-canvas);
}

@media (prefers-color-scheme: dark) {
    :root {
        --cstore-canvas: #0e1219;
        color-scheme: dark;
    }
}

.cstore-login {
    --cstore-accent: #4ccfae;
    --cstore-accent-dark: #37997f;
    --cstore-accent-deep: #1d5949;
    --cstore-accent-soft: #eaf9f4;
    --cstore-accent-tint: #f5fdfa;
    --cstore-on-accent: #10221d;
    --cstore-on-accent-soft: rgba(16, 34, 29, .32);
    --cstore-ring: rgba(76, 207, 174, .45);
    --cstore-glow: rgba(76, 207, 174, .35);

    --cstore-ink: #182029;
    --cstore-ink-soft: #454f5c;
    --cstore-muted: #6d7787;
    --cstore-line: #e4e9f0;
    --cstore-line-strong: #cdd5e0;
    --cstore-card: #ffffff;
    --cstore-field: #ffffff;
    --cstore-danger: #d8453c;
    --cstore-danger-soft: #fdeceb;

    --cstore-radius: 18px;
    --cstore-radius-sm: 11px;

    margin: 0;
    min-height: 100vh;
    /* dvh keeps the panels the height of what is actually visible when a phone's address bar is
       showing; a browser that does not know it keeps the vh above. */
    min-height: 100dvh;
    background: var(--cstore-accent-tint);
    color: var(--cstore-ink);
    font-family: system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

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

.cstore-login img {
    max-width: 100%;
    display: block;
}

/* ---------------------------------------------------------------- shell ---- */

.ca-login-shell {
    display: grid;
    grid-template-columns: minmax(300px, 1.02fr) minmax(340px, .98fr);
    min-height: 100vh;
    min-height: 100dvh;
}

/* ---------------------------------------------------------- brand panel ---- */

.ca-login-brand {
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 32px;
    padding: 44px 52px 40px;
    color: #fff;
    /* The dark scrim is not decoration: the panel puts white text over whatever accent the store
       configured, and a light accent (this default is a pale teal) would leave that text unreadable
       without it. Keeping it as its own layer means one rule covers every possible colour. */
    background:
        linear-gradient(rgba(7, 24, 20, .34), rgba(7, 24, 20, .34)),
        linear-gradient(135deg,
            var(--cstore-accent-deep) 0%,
            var(--cstore-accent-dark) 38%,
            var(--cstore-accent) 72%,
            var(--cstore-accent-dark) 100%);
    background-size: 220% 220%;
    animation: ca-pan 22s ease-in-out infinite;
    text-shadow: 0 1px 2px rgba(6, 22, 18, .22);
}

/* A faint grid keeps the gradient from looking flat on large screens. */
.ca-login-brand::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, .07) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, .07) 1px, transparent 1px);
    background-size: 46px 46px;
    mask-image: radial-gradient(circle at 30% 30%, #000 0%, transparent 78%);
    -webkit-mask-image: radial-gradient(circle at 30% 30%, #000 0%, transparent 78%);
    pointer-events: none;
}

.ca-login-brand > * {
    position: relative;
    z-index: 2;
}

/* Drifting light: two soft orbs, deliberately slow so it reads as alive, not busy. */
.ca-login-orbs {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
}

.ca-login-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(42px);
    opacity: .55;
    will-change: transform;
}

.ca-login-orb-a {
    width: 380px;
    height: 380px;
    top: -90px;
    left: -60px;
    background: radial-gradient(circle, rgba(255, 255, 255, .65), transparent 68%);
    animation: ca-drift-a 19s ease-in-out infinite;
}

.ca-login-orb-b {
    width: 300px;
    height: 300px;
    right: -70px;
    bottom: -80px;
    background: radial-gradient(circle, var(--cstore-glow), transparent 70%);
    animation: ca-drift-b 23s ease-in-out infinite;
}

.ca-login-orb-c {
    width: 170px;
    height: 170px;
    right: 22%;
    top: 12%;
    background: radial-gradient(circle, rgba(255, 255, 255, .5), transparent 70%);
    animation: ca-drift-a 27s ease-in-out infinite reverse;
}

.ca-login-brand-top {
    display: flex;
    align-items: center;
    gap: 14px;
}

/* ------------------------------------------------------------------ logo ---- */

.ca-login-mark {
    position: relative;
    display: grid;
    place-items: center;
    width: 58px;
    height: 58px;
    flex: 0 0 58px;
    border-radius: 16px;
    background: rgba(255, 255, 255, .16);
    border: 1px solid rgba(255, 255, 255, .34);
    backdrop-filter: blur(6px);
    box-shadow: 0 10px 26px rgba(6, 22, 18, .22);
    animation: ca-pop .7s cubic-bezier(.2, .8, .25, 1) both;
}

/* A slow halo so the mark is the first thing the eye lands on. */
.ca-login-mark::after {
    content: "";
    position: absolute;
    inset: -6px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, .45);
    animation: ca-halo 3.4s ease-out infinite;
    pointer-events: none;
}

.ca-login-mark img {
    width: 34px;
    height: 34px;
    object-fit: contain;
    border-radius: 9px;
}

.ca-login-monogram {
    font-weight: 700;
    font-size: 20px;
    letter-spacing: .06em;
    color: #fff;
}

.ca-login-brand-name {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: .01em;
}

.ca-login-brand-name span {
    display: block;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: .14em;
    text-transform: uppercase;
    opacity: .78;
    margin-top: 2px;
}

/* ------------------------------------------------------------------ copy ---- */

.ca-login-pitch {
    max-width: 460px;
}

.ca-login-pitch h1 {
    margin: 0 0 12px;
    font-size: clamp(26px, 2.6vw, 38px);
    line-height: 1.15;
    font-weight: 700;
    letter-spacing: -.01em;
    animation: ca-rise .7s cubic-bezier(.2, .8, .25, 1) .06s both;
}

.ca-login-pitch p {
    margin: 0;
    font-size: 15px;
    opacity: .86;
    animation: ca-rise .7s cubic-bezier(.2, .8, .25, 1) .14s both;
}

.ca-login-points {
    display: grid;
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.ca-login-points li {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13.5px;
    opacity: .92;
    animation: ca-rise .6s cubic-bezier(.2, .8, .25, 1) both;
}

.ca-login-points li:nth-child(1) { animation-delay: .2s; }
.ca-login-points li:nth-child(2) { animation-delay: .28s; }
.ca-login-points li:nth-child(3) { animation-delay: .36s; }

.ca-login-points svg {
    width: 17px;
    height: 17px;
    flex: 0 0 17px;
    opacity: .95;
}

/* The panel side is a column: card, then a quiet footer. */
.ca-login-panel {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 18px;
    padding: 44px 34px;
    background:
        radial-gradient(1000px 520px at 100% 0%, var(--cstore-accent-soft) 0%, transparent 60%),
        var(--cstore-card);
}

.ca-login-card {
    width: 100%;
    max-width: 400px;
}

/* ------------------------------------------------------------------- form ---- */

.ca-login-form {
    display: grid;
    gap: 16px;
}

.ca-login-head {
    margin-bottom: 6px;
    animation: ca-rise .6s cubic-bezier(.2, .8, .25, 1) both;
}

.ca-login-head h2 {
    margin: 0 0 4px;
    font-size: 22px;
    font-weight: 650;
    letter-spacing: -.01em;
}

.ca-login-head p {
    margin: 0;
    color: var(--cstore-muted);
    font-size: 13.5px;
}

.ca-field {
    position: relative;
    animation: ca-rise .6s cubic-bezier(.2, .8, .25, 1) both;
}

/* Staggered by position rather than nth-of-type, which would count the heading divs too. */
.ca-login-head + .ca-field { animation-delay: .1s; }
.ca-field + .ca-field { animation-delay: .16s; }

.ca-field label {
    display: block;
    margin-bottom: 7px;
    font-size: 13px;
    font-weight: 600;
    color: var(--cstore-ink-soft);
}

.ca-field-control {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 50px;
    padding: 0 14px;
    background: var(--cstore-field);
    border: 1px solid var(--cstore-line-strong);
    border-radius: var(--cstore-radius-sm);
    transition: border-color .18s, box-shadow .18s, background .18s;
}

.ca-field-control:focus-within {
    border-color: var(--cstore-accent);
    box-shadow: 0 0 0 4px var(--cstore-ring);
}

.ca-field-icon {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    color: var(--cstore-muted);
    transition: color .18s;
}

.ca-field-control:focus-within .ca-field-icon {
    color: var(--cstore-accent-dark);
}

.ca-field input {
    flex: 1 1 auto;
    min-width: 0;
    height: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    font: inherit;
    color: var(--cstore-ink);
}

.ca-field input::placeholder {
    color: #a2abb8;
}

/* An autofilled field is painted by the browser over the top of ours, which would put a bright
   (or, in dark mode, black) box in the middle of the field. The inset shadow is the one background
   a browser leaves us to override it with; the very long transition stops the flash of its own
   colour on the way in. Split into two rules rather than one list: a browser that does not know a
   pseudo-class drops the whole rule it appears in, and an unknown selector must not cost us the
   one that does work. */
.cstore-login .ca-field input:-webkit-autofill,
.cstore-login .ca-field input:-webkit-autofill:hover,
.cstore-login .ca-field input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--cstore-ink);
    -webkit-box-shadow: 0 0 0 60px var(--cstore-field) inset;
    box-shadow: 0 0 0 60px var(--cstore-field) inset;
    caret-color: var(--cstore-ink);
    transition: background-color 100000s ease-out 0s;
}

.cstore-login .ca-field input:autofill {
    color: var(--cstore-ink);
    box-shadow: 0 0 0 60px var(--cstore-field) inset;
    caret-color: var(--cstore-ink);
}

/* Reveal button sits inside the field so the row height never moves. */
.ca-field-reveal {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--cstore-muted);
    cursor: pointer;
    transition: background .18s, color .18s;
}

.ca-field-reveal:hover {
    background: var(--cstore-accent-tint);
    color: var(--cstore-accent-dark);
}

.ca-field-reveal svg {
    width: 18px;
    height: 18px;
}

/* The underline grows out of the middle when the field takes focus. */
.ca-field-bar {
    position: absolute;
    left: 14px;
    right: 14px;
    bottom: -1px;
    height: 2px;
    border-radius: 2px;
    background: var(--cstore-accent);
    transform: scaleX(0);
    transform-origin: center;
    transition: transform .28s cubic-bezier(.2, .8, .25, 1);
    pointer-events: none;
}

.ca-field-control:focus-within ~ .ca-field-bar {
    transform: scaleX(1);
}

/* --------------------------------------------------------------- options ---- */

.ca-login-options {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    animation: ca-rise .6s cubic-bezier(.2, .8, .25, 1) .22s both;
}

.ca-switch {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 13.5px;
    color: var(--cstore-ink-soft);
    cursor: pointer;
    user-select: none;
}

.ca-switch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.ca-switch-track {
    position: relative;
    width: 40px;
    height: 22px;
    flex: 0 0 40px;
    border-radius: 999px;
    background: #d7dde6;
    transition: background .2s;
}

.ca-switch-track::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(15, 23, 42, .3);
    transition: transform .22s cubic-bezier(.2, .8, .25, 1);
}

.ca-switch input:checked + .ca-switch-track {
    background: var(--cstore-accent);
}

.ca-switch input:checked + .ca-switch-track::after {
    transform: translateX(18px);
}

.ca-switch input:focus-visible + .ca-switch-track {
    box-shadow: 0 0 0 4px var(--cstore-ring);
}

[dir="rtl"] .ca-switch input:checked + .ca-switch-track::after {
    transform: translateX(-18px);
}

.ca-login-hint {
    font-size: 12.5px;
    color: var(--cstore-muted);
}

/* ---------------------------------------------------------------- submit ---- */

.ca-login-submit {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    height: 52px;
    margin-top: 4px;
    border: 0;
    border-radius: var(--cstore-radius-sm);
    background: linear-gradient(135deg, var(--cstore-accent-dark), var(--cstore-accent));
    color: var(--cstore-on-accent);
    font: inherit;
    font-weight: 650;
    letter-spacing: .01em;
    cursor: pointer;
    overflow: hidden;
    box-shadow: 0 12px 26px var(--cstore-glow);
    transition: transform .16s, box-shadow .16s, filter .16s;
    animation: ca-rise .6s cubic-bezier(.2, .8, .25, 1) .28s both;
}

.ca-login-submit:hover {
    transform: translateY(-1px);
    box-shadow: 0 16px 32px var(--cstore-glow);
    filter: saturate(1.06);
}

.ca-login-submit:active {
    transform: translateY(0);
}

.ca-login-submit:focus-visible {
    outline: 0;
    box-shadow: 0 0 0 4px var(--cstore-ring), 0 12px 26px var(--cstore-glow);
}

/* A single sweep of light across the button, on hover only. */
.ca-login-submit::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    width: 45%;
    left: -60%;
    background: linear-gradient(100deg, transparent, rgba(255, 255, 255, .5), transparent);
    transform: skewX(-18deg);
    pointer-events: none;
}

.ca-login-submit:hover::after {
    animation: ca-sheen .85s ease-out;
}

.ca-login-submit[data-state="loading"] {
    cursor: progress;
    filter: saturate(.9);
}

.ca-login-submit[data-state="loading"] .ca-login-submit-label {
    opacity: .78;
}

.ca-login-submit[data-state="loading"]::before {
    content: "";
    width: 17px;
    height: 17px;
    border-radius: 50%;
    border: 2px solid var(--cstore-on-accent-soft);
    border-top-color: var(--cstore-on-accent);
    animation: ca-spin .7s linear infinite;
}

/* ----------------------------------------------------------------- alerts ---- */

.ca-login-alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    margin-bottom: 16px;
    border: 1px solid rgba(216, 69, 60, .28);
    border-radius: var(--cstore-radius-sm);
    background: var(--cstore-danger-soft);
    color: #8f2b24;
    font-size: 13.5px;
    animation: ca-shake .5s cubic-bezier(.36, .07, .19, .97) both;
}

.ca-login-alert svg {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    margin-top: 1px;
}

.ca-login-alert strong {
    display: block;
    font-weight: 650;
}

/* -------------------------------------------------------- language switch ---- */

.ca-login-lang {
    position: absolute;
    top: 26px;
    inset-inline-end: 30px;
    z-index: 3;
    display: inline-flex;
    padding: 3px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .18);
    border: 1px solid rgba(255, 255, 255, .32);
    backdrop-filter: blur(6px);
}

.ca-login-lang a {
    padding: 4px 13px;
    border-radius: 999px;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .04em;
    text-decoration: none;
    opacity: .8;
    transition: background .18s, opacity .18s;
}

.ca-login-lang a:hover {
    opacity: 1;
    background: rgba(255, 255, 255, .18);
}

.ca-login-lang a.is-active {
    background: #fff;
    color: var(--cstore-accent-deep);
    opacity: 1;
}

/* ----------------------------------------------------------------- footer ---- */

.ca-login-foot {
    width: 100%;
    max-width: 400px;
    text-align: center;
    color: var(--cstore-muted);
    font-size: 12.5px;
    animation: ca-rise .6s cubic-bezier(.2, .8, .25, 1) .34s both;
}

.ca-login-foot a {
    color: var(--cstore-accent-dark);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color .18s;
}

.ca-login-foot a:hover {
    border-color: currentColor;
}

/* ------------------------------------------------------------- keyframes ---- */

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

@keyframes ca-drift-a {
    0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
    50% { transform: translate3d(38px, 30px, 0) scale(1.08); }
}

@keyframes ca-drift-b {
    0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
    50% { transform: translate3d(-44px, -26px, 0) scale(1.12); }
}

@keyframes ca-rise {
    from { opacity: 0; transform: translateY(14px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes ca-pop {
    from { opacity: 0; transform: scale(.82) rotate(-6deg); }
    to { opacity: 1; transform: scale(1) rotate(0); }
}

@keyframes ca-halo {
    0% { opacity: .7; transform: scale(1); }
    70%, 100% { opacity: 0; transform: scale(1.22); }
}

@keyframes ca-sheen {
    from { left: -60%; }
    to { left: 120%; }
}

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

@keyframes ca-shake {
    10%, 90% { transform: translateX(-2px); }
    20%, 80% { transform: translateX(3px); }
    30%, 50%, 70% { transform: translateX(-5px); }
    40%, 60% { transform: translateX(5px); }
}

/* --------------------------------------------------------------- responsive ---- */

@media (max-width: 960px) {
    /* Stacked, the brand panel becomes a header rather than half the screen. Left to the default
       stretch it took 40% of the height and pushed the form down the page, which on a sign-in screen
       is the wrong thing to make the reader scroll to: auto sizes the header to its content, and the
       1fr gives everything left over to the form, which centres its card in that space. */
    .ca-login-shell {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        min-height: 100vh;
        min-height: 100dvh;
    }

    .ca-login-brand {
        padding: 26px 22px 28px;
        gap: 18px;
    }

    .ca-login-brand::before {
        mask-image: radial-gradient(circle at 50% 20%, #000 0%, transparent 85%);
        -webkit-mask-image: radial-gradient(circle at 50% 20%, #000 0%, transparent 85%);
    }

    .ca-login-points {
        display: none;
    }

    .ca-login-pitch h1 {
        font-size: 24px;
    }

    /* The headline stays; the sentence explaining the panel is desktop copy. */
    .ca-login-pitch p {
        display: none;
    }

    .ca-login-panel {
        padding: 28px 22px 34px;
    }

    .ca-login-lang {
        top: 18px;
        inset-inline-end: 18px;
    }
}

@media (max-width: 420px) {
    .ca-login-orb-a,
    .ca-login-orb-c {
        display: none;
    }
}

/* Dark rooms: the card follows the system preference, the brand panel is unchanged. */
@media (prefers-color-scheme: dark) {
    .cstore-login {
        --cstore-ink: #eef2f7;
        --cstore-ink-soft: #c3ccd9;
        --cstore-muted: #939eae;
        --cstore-line: #2b323d;
        --cstore-line-strong: #39424f;
        --cstore-card: #161a21;
        --cstore-field: #1b2029;
        --cstore-danger-soft: #34201f;
    }

    /* Replaces the pale accent tint the light theme puts behind the card — it is a colour derived
       from the store's accent, so it cannot be read back from the inline palette and overridden. */
    .cstore-login {
        background: var(--cstore-canvas);
    }

    .cstore-login .ca-login-panel {
        background:
            radial-gradient(1000px 520px at 100% 0%, rgba(255, 255, 255, .05) 0%, transparent 60%),
            var(--cstore-card);
    }

    .cstore-login .ca-field-control {
        background: var(--cstore-field);
    }

    .cstore-login .ca-switch-track {
        background: #39424f;
    }

    .cstore-login .ca-login-alert {
        color: #ffbdb7;
    }
}

/* Motion is decoration here, so it is the first thing to go when asked. */
@media (prefers-reduced-motion: reduce) {
    .cstore-login *,
    .cstore-login *::before,
    .cstore-login *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
    }
}
