/* Sign-in, access-denied and error screens (option L1, decision D21.07). Every colour is a token, so a client's
   theme (css/themes/{client}.css) dresses these pages too; without one they keep BetaAdmin's standard colours. */
@layer pages {
    html, body { height: 100%; background: var(--page-bg); color: var(--text); }

    .login-root { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); min-height: 100vh; }

    /* ── The panel: brand, promise, scene ── */
    .login-visual {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        gap: 32px;
        padding: clamp(32px, 3vw, 64px) clamp(32px, 4vw, 80px);
        background: var(--surface-sunken);
        border-inline-end: var(--hairline) solid var(--border);
    }
    /* One column in the middle of the panel, which grows with the screen up to 640px (decision D21.13), so a wide
       screen shows a larger promise and scene instead of empty space. */
    .login-visual > * { width: min(100%, 640px); margin-inline: auto; }
    .visual-brand { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 600; }
    .visual-brand .visual-icon { width: 32px; height: 32px; object-fit: contain; }
    /* A client with its own logos shows the full logo in both modes (D21.14, D21.16); a very wide logo stays within
       the row, beside the language and theme buttons. */
    .brand-logo-light, .brand-logo-dark { display: block; height: 36px; width: auto; max-width: 200px; object-fit: contain; object-position: left center; }
    [dir="rtl"] :is(.brand-logo-light, .brand-logo-dark) { object-position: right center; }
    .brand-logo-dark { display: none; }
    [data-theme="dark"] .brand-logo-light { display: none; }
    [data-theme="dark"] .brand-logo-dark { display: block; }
    .visual-headline { font-size: clamp(26px, 1.4vw + 12px, 40px); font-weight: 600; line-height: 1.25; letter-spacing: -.01em; }
    .visual-lead { max-width: 560px; margin-block-start: 10px; color: var(--text-sub); font-size: clamp(14px, .3vw + 10px, 17px); line-height: 1.6; }
    .visual-copy { font-size: 12px; color: var(--text-muted); }

    .login-scene { margin-block-start: clamp(24px, 2vw, 40px); }
    .login-scene svg { display: block; width: 100%; height: auto; }

    /* The default scene: a small dashboard that fills in (decision D21.08). */
    .default-scene { display: grid; gap: 10px; padding: 16px; border: var(--hairline) solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
    .default-scene-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
    .default-scene-tile {
        padding: 10px 12px;
        border: var(--hairline) solid var(--border);
        border-radius: var(--radius-sm);
        animation: scene-in .6s var(--ease) both;
    }
    .default-scene-tile:first-child { border-inline-start: 3px solid var(--primary); }
    .default-scene-tile:nth-child(2) { animation-delay: .15s; }
    .default-scene-tile:nth-child(3) { animation-delay: .3s; }
    .default-scene-tile span { display: block; overflow: hidden; font-size: 11.5px; color: var(--text-sub); text-overflow: ellipsis; white-space: nowrap; }
    .default-scene-tile b { display: block; font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
    .default-scene-chart { display: block; width: 100%; height: 80px; }
    [dir="rtl"] .default-scene-chart { transform: scaleX(-1); }
    .default-scene-area { fill: var(--primary); opacity: .08; animation: scene-fade 1s .9s both; }
    .default-scene-line {
        fill: none;
        stroke: var(--primary);
        stroke-width: 2.4;
        stroke-linejoin: round;
        /* No non-scaling-stroke here: it would measure the dash in screen pixels, not in pathLength. */
        stroke-dasharray: 1;
        stroke-dashoffset: 1;
        animation: scene-draw 1.6s .5s var(--ease) forwards;
    }
    @keyframes scene-in { from { opacity: 0; transform: translateY(8px); } }
    @keyframes scene-fade { from { opacity: 0; } }
    @keyframes scene-draw { to { stroke-dashoffset: 0; } }

    /* ── The form side ── */
    .login-form-panel { display: flex; flex-direction: column; justify-content: space-between; gap: 24px; padding: clamp(24px, 2.5vw, 48px) clamp(32px, 4vw, 80px); background: var(--page-bg); }
    .login-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
    .mobile-brand { display: none; align-items: center; gap: 8px; font-weight: 600; }
    .mobile-brand img { width: 28px; height: 28px; object-fit: contain; }
    .mobile-brand :is(.brand-logo-light, .brand-logo-dark) { width: auto; height: 28px; max-width: 160px; }

    .top-actions { display: flex; align-items: center; gap: 4px; margin-inline-start: auto; }
    .top-action-form { display: contents; }
    .top-action {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 34px;
        height: 34px;
        padding-inline: 10px;
        border: 0;
        border-radius: var(--radius-sm);
        background: none;
        color: var(--text-sub);
        font: 500 13px var(--font-sans);
        cursor: pointer;
    }
    .top-action:hover { background: var(--hover); color: var(--text); }
    .top-action:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
    .top-action svg { width: 17px; height: 17px; }
    .theme-toggle .icon-sun { display: none; }
    [data-theme="dark"] .theme-toggle .icon-sun { display: inline; }
    [data-theme="dark"] .theme-toggle .icon-moon { display: none; }

    /* The form grows a little with the screen (decision D21.13). */
    .form-wrap { width: 100%; max-width: clamp(380px, 22vw, 440px); margin-inline: auto; }
    .form-title { font-size: clamp(26px, .8vw + 16px, 32px); font-weight: 600; letter-spacing: -.01em; }
    .form-subtitle { margin-block-start: 6px; color: var(--text-sub); font-size: 14px; }

    #login-form { display: grid; gap: 16px; margin-block-start: 28px; }
    .field-group { display: grid; gap: 6px; }
    .field-label { font-size: 13px; font-weight: 500; }
    .field-wrap { position: relative; }
    .field-input {
        width: 100%;
        height: 42px;
        padding: 0 12px;
        border: 1px solid var(--input-border);
        border-radius: var(--radius-sm);
        background: var(--input-bg);
        color: var(--text);
        font: 400 14px var(--font-sans);
        transition: border-color .15s, box-shadow .15s;
    }
    .field-input::placeholder { color: var(--text-muted); }
    /* A field the browser filled in keeps the theme's colours, not the browser's blue (decision D21.13). */
    .field-input:-webkit-autofill,
    .field-input:-webkit-autofill:hover {
        -webkit-text-fill-color: var(--text);
        caret-color: var(--text);
        box-shadow: 0 0 0 1000px var(--input-bg) inset;
        transition: background-color 600000s 0s;
    }
    .field-input:-webkit-autofill:focus { box-shadow: 0 0 0 1000px var(--input-bg) inset, 0 0 0 3px var(--primary-glow); }
    .field-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }
    .field-input.input-validation-error { border-color: var(--error); }
    .field-wrap .field-input { padding-inline-end: 72px; }
    .field-toggle {
        position: absolute;
        inset-inline-end: 6px;
        top: 50%;
        translate: 0 -50%;
        padding: 5px 8px;
        border: 0;
        border-radius: var(--radius-xs);
        background: none;
        color: var(--text-sub);
        font: 500 12.5px var(--font-sans);
        cursor: pointer;
    }
    .field-toggle:hover { background: var(--hover); color: var(--text); }
    .field-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
    .field-toggle .toggle-hide, .field-toggle[aria-pressed="true"] .toggle-show { display: none; }
    .field-toggle[aria-pressed="true"] .toggle-hide { display: inline; }
    .field-error { font-size: 12px; color: var(--error); }
    .field-error:empty { display: none; }

    .btn-login {
        position: relative;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        width: 100%;
        height: 44px;
        border: 0;
        border-radius: var(--radius-sm);
        background: var(--primary);
        color: var(--on-primary);
        font: 500 14px var(--font-sans);
        text-decoration: none;
        cursor: pointer;
        transition: background .15s;
    }
    .btn-login:hover { background: var(--primary-dark); }
    .btn-login:focus-visible { outline: 3px solid var(--primary-glow); outline-offset: 2px; }
    .btn-login:disabled { opacity: .7; cursor: progress; }
    .btn-spinner { display: none; width: 16px; height: 16px; border: 2px solid currentColor; border-inline-end-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
    .btn-login.is-loading .btn-spinner { display: inline-block; }
    @keyframes spin { to { transform: rotate(360deg); } }

    .form-hint { font-size: 12.5px; color: var(--text-sub); }

    .alert-error {
        display: flex;
        align-items: flex-start;
        gap: 10px;
        margin-block-start: 20px;
        padding: 12px 14px;
        border: 1px solid var(--danger-border);
        border-radius: var(--radius-md);
        background: var(--danger-bg);
        color: var(--error);
        font-size: 13px;
    }
    .alert-error svg { flex-shrink: 0; width: 16px; height: 16px; margin-block-start: 2px; }

    /* The foot keeps near the form instead of the far corners of a wide screen. */
    .login-foot { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; width: min(100%, 560px); margin-inline: auto; font-size: 12px; color: var(--text-muted); }
    .login-foot a { color: var(--text-muted); text-decoration: none; }
    .login-foot a:hover { color: var(--primary-text); }
    .login-foot img { height: 15px; vertical-align: middle; opacity: .75; margin-inline-start: 4px; }
    .login-secure { display: inline-flex; align-items: center; gap: 6px; }
    .login-secure svg { width: 14px; height: 14px; }

    /* ── The AI assistant's consent page (D20.21): who asks, as whom, what it may do, and the answer ── */
    .consent-user { display: flex; align-items: center; gap: 12px; margin-block-start: 24px; padding: 12px 14px; border: var(--hairline) solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
    .consent-user p { margin: 0; font-size: 13.5px; color: var(--text); }
    .consent-avatar { display: grid; place-items: center; flex-shrink: 0; width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--primary-text); font-size: 13px; font-weight: 600; }
    .consent-list { display: grid; gap: 12px; margin: 20px 0 0; padding: 0; list-style: none; }
    .consent-list li { display: flex; align-items: flex-start; gap: 10px; font-size: 13.5px; line-height: 1.5; color: var(--text-sub); }
    .consent-list .icon { flex-shrink: 0; width: 18px; height: 18px; margin-block-start: 1px; color: var(--text-muted); }
    .consent-list .is-allowed { color: var(--text); }
    .consent-list .is-allowed .icon { color: var(--success); }
    /* Customers personal data shared with the app (D31.17): a warning, so it is read before Allow (D20.23). */
    .consent-list .is-warning, .consent-list .is-warning .icon { color: var(--warning); }
    .consent-actions { display: grid; gap: 10px; margin-block-start: 28px; }
    .btn-quiet {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        height: 44px;
        border: var(--hairline) solid var(--border-strong);
        border-radius: var(--radius-sm);
        background: var(--surface);
        color: var(--text);
        font: 500 14px var(--font-sans);
        cursor: pointer;
        transition: background .15s;
    }
    .btn-quiet:hover { background: var(--hover); }
    .btn-quiet:focus-visible { outline: 3px solid var(--primary-glow); outline-offset: 2px; }

    /* ── Access denied and the error page ── */
    .error-page { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 40px 24px; text-align: center; }
    .error-link { width: auto; margin-block-start: 16px; padding-inline: 28px; }

    /* ── Every screen size (decision D21.12) ── */
    /* Small laptops: a tighter panel. */
    @media (max-width: 1199.98px) {
        .login-visual { padding: 32px; }
        .login-form-panel { padding: 24px 32px; }
        .visual-headline { font-size: 26px; }
    }
    /* Tablets: the panel becomes a band above the form, with a smaller scene. */
    @media (max-width: 899.98px) {
        .login-root { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
        .login-visual {
            display: grid;
            grid-template-columns: minmax(0, 1fr) minmax(0, 300px);
            align-items: center;
            gap: 8px 24px;
            padding: 20px 24px;
            border-inline-end: 0;
            border-block-end: var(--hairline) solid var(--border);
        }
        .login-visual > * { width: auto; margin-inline: 0; }
        .visual-brand { grid-column: 1 / -1; }
        .visual-body { display: contents; }
        .visual-headline { grid-column: 1; font-size: 22px; }
        .visual-lead { grid-column: 1; margin-block-start: 0; font-size: 13.5px; }
        .login-scene { grid-column: 2; grid-row: 2 / span 2; margin-block-start: 0; }
        .visual-copy { display: none; }
        /* The language and theme buttons sit on the band's brand row, at the other end. */
        .login-root { position: relative; }
        .login-top { position: absolute; inset-block-start: 14px; inset-inline-end: 16px; }
        .login-form-panel { padding: 24px; gap: 32px; }
        .form-wrap { margin-block: auto; }
    }
    /* Phones: the form alone, with the brand above it. */
    @media (max-width: 599.98px) {
        .login-root { grid-template-rows: 1fr; }
        .login-visual { display: none; }
        .login-top { position: static; }
        .login-form-panel { padding: 16px 20px 20px; }
        .mobile-brand { display: flex; }
        .form-title { font-size: 24px; }
        .login-foot { justify-content: center; }
    }

    @media (prefers-reduced-motion: reduce) {
        .default-scene-tile, .default-scene-area { animation: none; }
        .default-scene-line { animation: none; stroke-dashoffset: 0; }
    }
}
