﻿/* ============================================================
   Catalis Core design tokens, mirrored from WebSiteManagement
   (WebMgmt.Blazor.App/wwwroot/css/catalis-tokens.css and Layout/CatalisTheme.cs).
   Keep the brand values in step with that file.

   Everything is self-hosted (Roboto included) so the Content-Security-Policy
   can stay 'self'-only: no Google Fonts, no CDNs.
   ============================================================ */

@font-face {
    font-family: "Roboto";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/Roboto-Regular.ttf") format("truetype");
}

@font-face {
    font-family: "Roboto";
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url("../fonts/Roboto-Bold.ttf") format("truetype");
}

:root {
    /* Brand */
    --catalis-navy: #013970;
    --catalis-navy-700: #012a54;
    --catalis-navy-400: #4E73C9;
    --catalis-mint: #2e9e7d;
    --catalis-mint-100: #cde8df;

    /* Semantic (MudBlazor light palette) */
    --color-primary: var(--catalis-navy);
    --color-primary-hover: var(--catalis-navy-700);
    --color-secondary: var(--catalis-mint);
    --color-error: #D32F2F;
    --color-success: #2E7D32;
    --color-info: #01579B;

    /* Alerts (Material "standard" variant) */
    --alert-error-bg: #fdeded;
    --alert-error-fg: #5f2120;
    --alert-success-bg: #edf7ed;
    --alert-success-fg: #1e4620;
    --alert-info-bg: #e5f6fd;
    --alert-info-fg: #014361;

    /* Surfaces */
    --bg-canvas: #ffffff;
    --bg-shell: #f8fafd;          /* AppBar tone, used behind the card */
    --bg-surface: #ffffff;
    --bg-subtle: #f5f6f8;
    --bg-hover: rgba(0, 0, 0, 0.04);
    --bg-selected: rgba(1, 57, 112, 0.08);

    /* Text */
    --fg-primary: rgba(0, 0, 0, 0.87);
    --fg-secondary: rgba(0, 0, 0, 0.60);
    --fg-disabled: rgba(0, 0, 0, 0.38);
    --fg-on-primary: #ffffff;

    /* Lines */
    --line-default: #e8e8e8;
    --line-input: rgba(0, 0, 0, 0.23);
    --line-input-hover: rgba(0, 0, 0, 0.87);
    --divider: rgba(0, 0, 0, 0.12);

    /* Elevation (Material) */
    --elev-2: 0 3px 1px -2px rgba(0,0,0,.2), 0 2px 2px 0 rgba(0,0,0,.14), 0 1px 5px 0 rgba(0,0,0,.12);
    --elev-3: 0 3px 3px -2px rgba(0,0,0,.2), 0 3px 4px 0 rgba(0,0,0,.14), 0 1px 8px 0 rgba(0,0,0,.12);
    --elev-4: 0 2px 4px -1px rgba(0,0,0,.2), 0 4px 5px 0 rgba(0,0,0,.14), 0 1px 10px 0 rgba(0,0,0,.12);

    --radius-sm: 4px;
    --font-sans: "Roboto", "Helvetica Neue", Helvetica, Arial, sans-serif;

    color-scheme: light;
}

/* Dark palette (WebMgmt [data-theme="dark"]), following the OS setting. */
@media (prefers-color-scheme: dark) {
    :root {
        --color-primary: var(--catalis-navy-400);
        --color-primary-hover: #6d8cd4;
        --color-error: #ef5350;
        --color-success: #66bb6a;
        --alert-error-bg: #2c1515;
        --alert-error-fg: #f4c7c7;
        --alert-success-bg: #14261a;
        --alert-success-fg: #cce8cd;
        --alert-info-bg: #0d2433;
        --alert-info-fg: #b8e7fb;
        --bg-canvas: #101216;
        --bg-shell: #101216;
        --bg-surface: #181c20;
        --bg-subtle: #1f2329;
        --bg-hover: rgba(255, 255, 255, 0.08);
        --bg-selected: rgba(78, 115, 201, 0.16);
        --fg-primary: rgba(255, 255, 255, 0.87);
        --fg-secondary: rgba(255, 255, 255, 0.70);
        --fg-disabled: rgba(255, 255, 255, 0.50);
        --fg-on-primary: #ffffff;
        --line-default: rgba(255, 255, 255, 0.12);
        --line-input: rgba(255, 255, 255, 0.23);
        --line-input-hover: rgba(255, 255, 255, 0.87);
        --divider: rgba(255, 255, 255, 0.12);
        color-scheme: dark;
    }
}

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

html, body {
    margin: 0;
    background: var(--bg-shell);
    color: var(--fg-primary);
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.5;
    letter-spacing: 0.00938em;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Reserve the scrollbar's width on both sides, so a scrollbar appearing never pushes the
   card off the horizontal center. */
html { scrollbar-gutter: stable both-edges; }

a { color: var(--color-primary); }

:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: 16px; top: 8px; background: var(--bg-surface); padding: 8px 12px; z-index: 10; border-radius: var(--radius-sm); }

.visually-hidden {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Shell: card centered on the screen, like WebMgmt's public login page ----------
   Column: [spacer] [card] [spacer holding the footer]. Both spacers grow equally from zero,
   so when there is room the card's center sits exactly on the viewport's center at any size.
   The footer spacer can't shrink below the footer's own height, while the top spacer can
   shrink to nothing. On a screen too short for everything, the top space is given up
   first, so the card moves up and the page scrolls; it is never pushed down.
   Padding is the same top and bottom, so it doesn't skew the center either. */
.auth-shell {
    min-height: 100vh;
    min-height: 100dvh;            /* mobile browsers: excludes the collapsing address bar */
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 16px;
}

.auth-shell::before { content: ""; flex: 1 1 0; }

.auth-shell > .card { flex: none; width: 100%; max-width: 520px; }

.auth-shell > .site-footer {
    flex: 1 1 0;
    width: 100%;
    max-width: 520px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    margin-bottom: 28px;
}

.brand img { height: 40px; width: auto; display: block; }

/* Same treatment as .cx-brand-sub in the WebMgmt AppBar. */
.brand-sub {
    color: var(--color-secondary);
    font-weight: 400;
    font-size: 0.7rem;
    line-height: 1;
    letter-spacing: 1.5px;
    text-transform: uppercase;
}

.card {
    background: var(--bg-surface);
    border-radius: var(--radius-sm);
    box-shadow: var(--elev-3);
    padding: 32px;
    outline: none;                 /* focus target of the skip link, not an interactive control */
}

.site-footer {
    color: var(--fg-secondary);
    font-size: 0.75rem;
    line-height: 1.66;
    letter-spacing: 0.03333em;
    text-align: center;
}

/* Spacing above the footer lives on the first line, not as padding on .site-footer: a flex
   item can't start smaller than its padding, which would make the bottom spacer taller than
   the top one and pull the card above center. */
.site-footer p { margin: 0; }
.footer-help { font-size: 0.8125rem; margin: 24px 0 8px; }
.site-footer a { color: var(--color-primary); font-weight: 500; text-decoration: none; overflow-wrap: anywhere; }
.site-footer a:hover { text-decoration: underline; }
.footer-sep { margin: 0 8px; color: var(--divider); }

/* ---------- Type (Material Design 2 scale) ---------- */
h1 {
    color: var(--color-primary);
    font-size: 1.5rem;          /* h5 */
    font-weight: 400;
    line-height: 1.334;
    margin: 0 0 8px;
}

h2 { font-size: 1.25rem; font-weight: 500; line-height: 1.6; letter-spacing: 0.0075em; margin: 0 0 8px; }
p { margin: 0 0 16px; }

.lead {                         /* body2, secondary */
    color: var(--fg-secondary);
    font-size: 0.875rem;
    line-height: 1.43;
    letter-spacing: 0.01786em;
    margin-bottom: 24px;
}

.hint { color: var(--fg-secondary); font-size: 0.75rem; line-height: 1.66; letter-spacing: 0.03333em; margin: 4px 0 0; }

/* ---------- Form fields (Material outlined) ---------- */
.field { margin-bottom: 24px; }

.field > label, .field-label {
    display: block;
    color: var(--fg-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: 0.00714em;
    margin-bottom: 6px;
}

input[type="email"], input[type="password"], input[type="text"] {
    width: 100%;
    font: inherit;
    color: var(--fg-primary);
    background: var(--bg-surface);
    border: 1px solid var(--line-input);
    border-radius: var(--radius-sm);
    padding: 14px 14px;
    transition: border-color 120ms, box-shadow 120ms;
}

input[type="email"]:hover, input[type="password"]:hover, input[type="text"]:hover { border-color: var(--line-input-hover); }

input[type="email"]:focus, input[type="password"]:focus, input[type="text"]:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: inset 0 0 0 1px var(--color-primary);  /* 2px focused border without layout shift */
}

input.invalid, input.invalid:hover { border-color: var(--color-error); }
input.invalid:focus { border-color: var(--color-error); box-shadow: inset 0 0 0 1px var(--color-error); }

.validation-message, .field-error {
    color: var(--color-error);
    font-size: 0.75rem;
    line-height: 1.66;
    letter-spacing: 0.03333em;
    margin: 4px 14px 0;
}

/* ---------- Buttons (Material filled / text) ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 8px 22px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--color-primary);
    color: var(--fg-on-primary);
    box-shadow: var(--elev-2);
    font: inherit;
    font-size: 0.9375rem;
    font-weight: 500;
    line-height: 1.75;
    letter-spacing: 0.02857em;
    text-transform: uppercase;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 150ms, box-shadow 150ms;
}

.btn:hover:not(:disabled) { background: var(--color-primary-hover); box-shadow: var(--elev-4); }
.btn:disabled { background: var(--bg-subtle); color: var(--fg-disabled); box-shadow: none; cursor: not-allowed; }
.btn-block { width: 100%; }

.btn-link {
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--color-primary);
    cursor: pointer;
    font: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: 0.02857em;
    text-transform: uppercase;
    padding: 4px 6px;
    margin-left: -6px;
}

.btn-link:hover { background: var(--bg-selected); }

/* Material outlined button (MudBlazor Variant.Outlined, Color.Primary). */
.btn-outline {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--color-primary);
    border-radius: var(--radius-sm);
    color: var(--color-primary);
    cursor: pointer;
    font: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.75;
    letter-spacing: 0.02857em;
    text-transform: uppercase;
    padding: 5px 15px;
    white-space: nowrap;
    transition: background-color 150ms;
}

.btn-outline:hover { background: var(--bg-selected); }
.btn-sm { font-size: 0.8125rem; padding: 3px 10px; }

/* ---------- Alerts (Material standard) ---------- */
.alert {
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    margin-bottom: 20px;
    font-size: 0.875rem;
    line-height: 1.43;
    letter-spacing: 0.01071em;
}

.alert-error { background: var(--alert-error-bg); color: var(--alert-error-fg); }
.alert-ok { background: var(--alert-success-bg); color: var(--alert-success-fg); }
.alert-info { background: var(--alert-info-bg); color: var(--alert-info-fg); }
.alert .btn-link { color: inherit; margin-top: 4px; }

/* ---------- Website checklist ---------- */
/* Header row: "Websites" on the left, "x of y selected" + Select all on the right. */
.list-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 12px;
    margin-bottom: 8px;
}

.list-header .field-label { margin-bottom: 0; }
.list-actions { display: inline-flex; align-items: center; gap: 12px; margin-left: auto; }
.list-actions .hint { margin: 0; }

.site-list { border: 1px solid var(--line-input); border-radius: var(--radius-sm); margin: 0; padding: 0; min-width: 0; }
.site-list .site-item {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 12px 14px;
    border-top: 1px solid var(--line-default);
    cursor: pointer;
    transition: background-color 120ms;
}
.site-list .site-item:first-of-type { border-top: none; }
.site-list .site-item:hover { background: var(--bg-hover); }
.site-list .site-item:has(input:checked) { background: var(--bg-selected); }
.site-list .site-item input { width: 18px; height: 18px; margin-top: 3px; flex: none; accent-color: var(--color-primary); }
.site-name { font-weight: 500; display: block; overflow-wrap: anywhere; }
.site-meta { color: var(--fg-secondary); font-size: 0.875rem; line-height: 1.43; overflow-wrap: anywhere; }

/* ---------- Password ---------- */
.password-row { display: flex; gap: 8px; }
.password-row input { flex: 1; min-width: 0; }

.toggle {
    flex: none;
    font: inherit;
    font-size: 0.8125rem;
    font-weight: 500;
    letter-spacing: 0.02857em;
    text-transform: uppercase;
    border: 1px solid var(--line-input);
    background: var(--bg-surface);
    color: var(--color-primary);
    border-radius: var(--radius-sm);
    padding: 0 14px;
    cursor: pointer;
}

.toggle:hover { background: var(--bg-selected); }

.rules { list-style: none; padding: 0; margin: 10px 0 0; font-size: 0.8125rem; line-height: 1.6; display: grid; gap: 2px; color: var(--fg-secondary); }
.rules li::before { content: "○"; display: inline-block; width: 1.5em; }
.rules li.met { color: var(--color-success); }
.rules li.met::before { content: "✓"; font-weight: 700; }

.done-list { padding-left: 20px; margin: 0 0 16px; }

/* ---------- Progress ---------- */
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    display: inline-block;
    vertical-align: -3px;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner, .spinner-ring { animation-duration: 3s; } }

/* ---------- Full-screen loaders: always dead-center ----------
   Used by the Blazor startup loader (.boot in index.html) and <PageLoader> (in-app waits).
   The layer covers the viewport and places the ring in the exact center of one grid
   cell. Labels are positioned absolutely, either inside the ring or below it, so text
   never pushes the ring off center. */
.boot, .page-loader {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    background: var(--bg-shell);
    z-index: 900;
}

/* Startup: progress ring filled by Blazor's --blazor-load-percentage, percentage inside it. */
.loading-progress { display: block; width: 6rem; height: 6rem; }
.loading-progress circle { fill: none; stroke: var(--line-default); stroke-width: 0.5rem; transform-origin: 50% 50%; transform: rotate(-90deg); }
.loading-progress circle:last-child {
    stroke: var(--color-primary);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}
.loading-progress-text {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    transform: translateY(-50%);
    text-align: center;
    color: var(--color-primary);
    font-size: 0.875rem;
    font-weight: 500;
}
.loading-progress-text::after { content: var(--blazor-load-percentage-text, "Loading"); }

/* In-app waits: same position, spinning arc, label under the ring. */
.spinner-ring { display: block; width: 3.5rem; height: 3.5rem; animation: spin 0.9s linear infinite; }
.spinner-ring circle { fill: none; stroke-width: 4; }
.spinner-ring .track { stroke: var(--line-default); }
.spinner-ring .arc { stroke: var(--color-primary); stroke-linecap: round; stroke-dasharray: 34 104; }
.page-loader-text {
    position: absolute;
    top: calc(50% + 2.75rem);     /* ring radius (1.75rem) + 1rem gap */
    left: 16px;
    right: 16px;
    text-align: center;
    color: var(--fg-secondary);
    font-size: 0.875rem;
}

#blazor-error-ui {
    background: var(--alert-error-bg);
    color: var(--alert-error-fg);
    bottom: 0;
    box-shadow: var(--elev-4);
    display: none;
    left: 0;
    padding: 0.6rem 3rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
    font-size: 0.875rem;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.35rem; background: none; border: none; color: inherit; font-size: 1.4rem; line-height: 1; }
.blazor-error-boundary { background: var(--alert-error-bg); color: var(--alert-error-fg); padding: 1rem; border-radius: var(--radius-sm); }
.blazor-error-boundary::after { content: "Something went wrong. Reload the page."; }

/* ---------- Small screens ---------- */
@media (max-width: 480px) {
    .auth-shell { padding: 16px 12px; }
    .card { padding: 24px 16px; }
    .brand img { height: 32px; }
}
