/* ===== Theme =====
   The :root block below holds the light-theme variable values, but dark is
   the default a first-time visitor actually sees: theme.js sets
   html[data-theme="dark"] whenever nothing is stored yet in localStorage.
   Light applies only once the user explicitly picks it; picking "system"
   removes the attribute so the OS preference (prefers-color-scheme) takes
   over instead. The dark variable block therefore appears twice — keep both
   copies identical. */

:root {
    color-scheme: light;
    --accent: #2563eb;
    --accent-strong: #1d4ed8;
    --accent-soft: rgba(37, 99, 235, 0.12);
    --accent-glow: rgba(37, 99, 235, 0.35);
    --header-from: #0f2238;
    --header-to: #1e3a5f;
    --page-bg: #eef2f7;
    --surface: #ffffff;
    --surface-2: #f4f7fb;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --text-muted: #64748b;
    --glow-a: rgba(37, 99, 235, 0.07);
    --glow-b: rgba(45, 212, 191, 0.08);
    --ok-bg: #ecfdf5;
    --ok-border: #a7f3d0;
    --ok-text: #065f46;
    --ok-icon: #10b981;
    --warn-bg: #fffbeb;
    --warn-border: #fde68a;
    --warn-text: #92400e;
    --warn-icon: #f59e0b;
    --err-bg: #fef2f2;
    --err-border: #fecaca;
    --err-text: #991b1b;
    --err-icon: #ef4444;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05), 0 4px 12px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 2px 4px rgba(15, 23, 42, 0.06), 0 12px 28px rgba(15, 23, 42, 0.10);
    --radius: 14px;
    --radius-sm: 9px;
    --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4' fill='none' stroke='%2364748b' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --accent: #3b82f6;
    --accent-strong: #7caefa;
    --accent-soft: rgba(96, 165, 250, 0.15);
    --accent-glow: rgba(59, 130, 246, 0.40);
    --header-from: #15181e;
    --header-to: #232a36;
    --page-bg: #131518;
    --surface: #1e2126;
    --surface-2: #181a1f;
    --border: #2b2f36;
    --border-strong: #404652;
    --text: #e6e8eb;
    --text-muted: #99a0aa;
    --glow-a: rgba(59, 130, 246, 0.05);
    --glow-b: rgba(45, 212, 191, 0.04);
    --ok-bg: #122119;
    --ok-border: #1f4d33;
    --ok-text: #8fdfac;
    --ok-icon: #22c55e;
    --warn-bg: #241e10;
    --warn-border: #5c4716;
    --warn-text: #f0ca6b;
    --warn-icon: #f59e0b;
    --err-bg: #261517;
    --err-border: #5f2428;
    --err-text: #f2a0a0;
    --err-icon: #ef4444;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.4), 0 12px 28px rgba(0, 0, 0, 0.45);
    --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4' fill='none' stroke='%2399a0aa' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        color-scheme: dark;
        --accent: #3b82f6;
        --accent-strong: #7caefa;
        --accent-soft: rgba(96, 165, 250, 0.15);
        --accent-glow: rgba(59, 130, 246, 0.40);
        --header-from: #15181e;
        --header-to: #232a36;
        --page-bg: #131518;
        --surface: #1e2126;
        --surface-2: #181a1f;
        --border: #2b2f36;
        --border-strong: #404652;
        --text: #e6e8eb;
        --text-muted: #99a0aa;
        --glow-a: rgba(59, 130, 246, 0.05);
        --glow-b: rgba(45, 212, 191, 0.04);
        --ok-bg: #122119;
        --ok-border: #1f4d33;
        --ok-text: #8fdfac;
        --ok-icon: #22c55e;
        --warn-bg: #241e10;
        --warn-border: #5c4716;
        --warn-text: #f0ca6b;
        --warn-icon: #f59e0b;
        --err-bg: #261517;
        --err-border: #5f2428;
        --err-text: #f2a0a0;
        --err-icon: #ef4444;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.4), 0 12px 28px rgba(0, 0, 0, 0.45);
        --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4' fill='none' stroke='%2399a0aa' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    }
}

/* ===== Base ===== */

/* border-box makes width include padding and border — the sane box model;
   practically every modern stylesheet starts with this rule. */
* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    background:
        radial-gradient(1100px 420px at 85% -10%, var(--glow-a), transparent 60%),
        radial-gradient(900px 400px at 0% 110%, var(--glow-b), transparent 60%),
        var(--page-bg);
    background-attachment: fixed;
    transition: background 0.25s ease, color 0.25s ease;
}

::selection {
    background: var(--accent-glow);
    color: #fff;
}

.icon {
    flex-shrink: 0;
    vertical-align: -3px;
}

/* ===== Header ===== */

.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.7rem 1.5rem;
    background: linear-gradient(135deg, var(--header-from), var(--header-to));
    box-shadow: 0 2px 16px rgba(2, 8, 20, 0.35);
}

.topbar::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 2px;
    background: linear-gradient(90deg, #60a5fa, #2dd4bf 45%, transparent 80%);
    opacity: 0.85;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    color: #f1f5f9;
    font-size: 1.07rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.brand .icon {
    color: #2dd4bf;
    filter: drop-shadow(0 0 6px rgba(45, 212, 191, 0.55));
}

/* ===== Theme toggle ===== */

.theme-toggle {
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.10);
    border: 1px solid rgba(255, 255, 255, 0.12);
}

.theme-toggle button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 27px;
    height: 27px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: rgba(241, 245, 249, 0.6);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.theme-toggle button:hover {
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    transform: translateY(-1px);
}

.theme-toggle button:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.25);
}

/* ===== Header actions (theme toggle + sign out) ===== */

/* Groups the toggle and the sign-out button as one flex item so .topbar's
   space-between still puts exactly two things at opposite ends (brand, and
   this group) regardless of whether sign-out is showing. */
.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* The <form> around the sign-out button would otherwise be a block box that
   breaks the flex row; display:contents makes only its button participate
   in layout. */
.logout-form {
    display: contents;
}

.sign-out-button {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.10);
    color: rgba(241, 245, 249, 0.85);
    font: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.sign-out-button:hover {
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    transform: translateY(-1px);
}

.sign-out-button:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.25);
}

.signed-in-as {
    color: rgba(241, 245, 249, 0.75);
    font-size: 0.85rem;
    /* Long emails shouldn't push the sign-out button off the header on a
       narrow viewport; they truncate instead. */
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

:root[data-theme="light"] .theme-toggle [data-set-theme="light"],
:root[data-theme="dark"] .theme-toggle [data-set-theme="dark"],
:root:not([data-theme]) .theme-toggle [data-set-theme="system"] {
    background: #ffffff;
    color: #1e293b;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.35);
}

/* ===== Page & cards ===== */

.page {
    max-width: 880px;
    margin: 2rem auto 4rem;
    padding: 0 1.25rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem 1.75rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.25s ease, border-color 0.25s ease, background 0.25s ease;
}

.card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--border-strong);
}

.card h2 {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0 0 1.25rem;
    font-size: 1.08rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.card h2 .icon {
    color: var(--accent);
}

/* ===== Form layout ===== */

fieldset {
    border: none;
    margin: 0;
    padding: 0;
    transition: opacity 0.25s ease, filter 0.25s ease;
}

/* The page disables the whole generator <fieldset> until a request is loaded;
   this is the matching visual: faded and desaturated, so "locked" is obvious
   at a glance. */
fieldset:disabled {
    opacity: 0.55;
    filter: saturate(0.55);
}

.form-row {
    display: grid;
    grid-template-columns: 175px 1fr;
    gap: 0.5rem 1.25rem;
    align-items: start;
    margin-bottom: 1.05rem;
}

.form-row > label:first-child,
.form-row > span:first-child {
    padding-top: 0.45rem;
    font-weight: 600;
    font-size: 0.92rem;
    color: var(--text);
}

/* ===== Inputs ===== */

input[type="text"],
input[type="date"],
input[type="number"],
input[type="password"],
input[type="email"],
select {
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 0.48rem 0.7rem;
    font: inherit;
    color: inherit;
    background: var(--surface);
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

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

input[type="text"]:focus,
input[type="date"]:focus,
input[type="number"]:focus,
input[type="password"]:focus,
input[type="email"]:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3.5px var(--accent-soft);
}

select {
    appearance: none;
    padding-right: 2.1rem;
    background-image: var(--chevron);
    background-repeat: no-repeat;
    background-position: right 0.65rem center;
    background-size: 16px;
    cursor: pointer;
}

input[type="file"] {
    font: inherit;
    color: var(--text-muted);
}

/* ::file-selector-button is the standard pseudo-element for the "Choose file"
   button inside a file input — the only way to style it without replacing the
   input with custom markup. */
input[type="file"]::file-selector-button {
    font: inherit;
    font-weight: 600;
    color: var(--text);
    background: var(--surface);
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 0.45rem 1.1rem;
    margin-right: 1rem;
    cursor: pointer;
    transition: border-color 0.18s ease, color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

input[type="file"]::file-selector-button:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
    box-shadow: 0 2px 10px var(--accent-soft);
}

/* ===== Radios & checkboxes ===== */

/* appearance:none strips the browser's native control rendering so the boxes
   can be drawn from scratch with borders/backgrounds; the checkmark is an
   inline SVG data-URI applied as a background image on :checked, and the
   radio "dot" is faked by growing the border to 5.5px. */
input[type="radio"],
input[type="checkbox"] {
    appearance: none;
    width: 18px;
    height: 18px;
    margin: 0;
    flex-shrink: 0;
    border: 1.5px solid var(--border-strong);
    background: var(--surface);
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

input[type="radio"] {
    border-radius: 50%;
}

input[type="checkbox"] {
    border-radius: 5px;
}

input[type="radio"]:hover,
input[type="checkbox"]:hover {
    border-color: var(--accent);
}

input[type="radio"]:focus-visible,
input[type="checkbox"]:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3.5px var(--accent-soft);
}

input[type="radio"]:checked {
    border-width: 5.5px;
    border-color: var(--accent);
    animation: pop 0.18s ease;
}

input[type="checkbox"]:checked {
    border-color: var(--accent);
    background-color: var(--accent);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 8.5l3 3 6-7' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-size: 12px;
    background-position: center;
    background-repeat: no-repeat;
    animation: pop 0.18s ease;
}

@keyframes pop {
    50% {
        transform: scale(0.82);
    }
}

.license-type {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.license-type label {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    cursor: pointer;
    width: fit-content;
}

.floating-count {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    margin-left: 1.5rem;
    color: var(--text-muted);
    font-size: 0.92rem;
}

.floating-count input {
    width: 5.5rem;
}

.expiry-controls {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* ===== Variant list ===== */

.variant-list {
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--surface-2);
    max-height: 270px;
    overflow-y: auto;
    padding: 0.4rem;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

.variant-list::-webkit-scrollbar {
    width: 10px;
}

.variant-list::-webkit-scrollbar-track {
    background: transparent;
}

.variant-list::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 8px;
    border: 2.5px solid var(--surface-2);
}

.variant-list::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

.variant-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.42rem 0.65rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.13s ease, transform 0.13s ease;
}

.variant-row:hover {
    background: var(--accent-soft);
    transform: translateX(2px);
}

/* :has() styles the PARENT based on a child's state — "a row that contains a
   checked checkbox". Supported in all evergreen browsers; older ones simply
   skip the highlight (the checkbox itself still shows the state). */
.variant-row:has(input:checked) {
    background: var(--accent-soft);
}

.variant-row:has(input:checked) span {
    color: var(--accent-strong);
    font-weight: 500;
}

.variant-actions {
    display: flex;
    gap: 1.1rem;
    align-items: baseline;
    margin-top: 0.55rem;
}

/* ===== Buttons & links ===== */

.linklike {
    position: relative;
    background: none;
    border: none;
    padding: 0 0 2px;
    color: var(--accent);
    cursor: pointer;
    font: inherit;
    font-weight: 600;
    transition: color 0.15s ease;
}

.linklike::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 2px;
    border-radius: 2px;
    background: currentColor;
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.2s ease;
}

.linklike:hover {
    color: var(--accent-strong);
}

.linklike:hover::after {
    transform: scaleX(1);
}

.linklike:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3.5px var(--accent-soft);
    border-radius: 4px;
}

fieldset:disabled .linklike {
    color: var(--text-muted);
    cursor: default;
}

fieldset:disabled .linklike::after {
    display: none;
}

button.primary {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: linear-gradient(180deg, #3b82f6, #2563eb);
    border: none;
    border-radius: var(--radius-sm);
    color: #fff;
    font: inherit;
    font-weight: 600;
    letter-spacing: 0.01em;
    padding: 0.55rem 1.5rem;
    cursor: pointer;
    box-shadow: 0 2px 10px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.18);
    transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

button.primary:hover {
    transform: translateY(-1.5px);
    box-shadow: 0 5px 18px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.18);
    filter: brightness(1.06);
}

button.primary:active {
    transform: translateY(0);
    box-shadow: 0 1px 5px var(--accent-glow);
    filter: brightness(0.97);
}

button.primary:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3.5px var(--accent-soft), 0 2px 10px var(--accent-glow);
}

fieldset:disabled button.primary {
    background: var(--border-strong);
    box-shadow: none;
    transform: none;
    cursor: default;
}

/* ===== Parsed request fields ===== */

.request-fields {
    display: grid;
    grid-template-columns: 175px 1fr;
    gap: 0.45rem 1.25rem;
    align-items: center;
    margin: 1.1rem 0 0;
    padding: 1rem 1.15rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 11px;
    animation: rise-in 0.3s ease;
}

.request-fields dt {
    font-weight: 600;
    font-size: 0.92rem;
}

.request-fields dd {
    margin: 0;
    width: fit-content;
    font-family: Consolas, "Cascadia Mono", monospace;
    font-size: 0.92rem;
    padding: 0.18rem 0.6rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 7px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.request-fields dd:hover {
    border-color: var(--accent);
    box-shadow: 0 1px 6px var(--accent-soft);
}

/* ===== Alerts ===== */

.alert {
    position: relative;
    border-radius: 11px;
    padding: 0.75rem 1rem 0.75rem 2.9rem;
    margin: 0.9rem 0;
    border: 1px solid;
    border-left-width: 4px;
    animation: rise-in 0.25s ease;
}

.alert::before {
    position: absolute;
    left: 0.95rem;
    top: 0.78rem;
    width: 21px;
    height: 21px;
    border-radius: 50%;
    color: #fff;
    font-size: 12.5px;
    font-weight: 700;
    line-height: 21px;
    text-align: center;
}

.alert ul {
    margin: 0.3rem 0 0;
    padding-left: 1.1rem;
}

.alert li {
    margin: 0.15rem 0;
}

.alert-error {
    background: var(--err-bg);
    border-color: var(--err-border);
    border-left-color: var(--err-icon);
    color: var(--err-text);
}

.alert-error::before {
    content: "✕";
    background: var(--err-icon);
}

.alert-warning {
    background: var(--warn-bg);
    border-color: var(--warn-border);
    border-left-color: var(--warn-icon);
    color: var(--warn-text);
}

.alert-warning::before {
    content: "!";
    background: var(--warn-icon);
}

.alert-success {
    background: var(--ok-bg);
    border-color: var(--ok-border);
    border-left-color: var(--ok-icon);
    color: var(--ok-text);
}

.alert-success::before {
    content: "✓";
    background: var(--ok-icon);
}

.alert a {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: inherit;
    font-weight: 600;
    text-underline-offset: 2px;
    transition: opacity 0.15s ease;
}

.alert a:hover {
    opacity: 0.75;
}

@keyframes rise-in {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
}

/* ===== Misc ===== */

.hint {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 0.4rem 0 0;
}

@media (max-width: 640px) {
    .form-row,
    .request-fields {
        grid-template-columns: 1fr;
        gap: 0.3rem;
    }

    .form-row > label:first-child,
    .form-row > span:first-child {
        padding-top: 0;
    }

    .card {
        padding: 1.1rem 1.2rem;
    }
}

/* Accessibility: users can ask the OS to minimise motion (vestibular
   disorders, distraction). This kills every animation/transition globally, so
   any new ones added above are covered automatically. */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }

    html {
        scroll-behavior: auto;
    }
}

/* ===== Blazor framework styles ===== */

h1:focus {
    outline: none;
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid #26b050;
}

.invalid {
    outline: 1px solid #e50000;
}

.validation-message {
    color: #e50000;
}

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem;
    border-radius: var(--radius-sm);
    color: white;
}

    .blazor-error-boundary::after {
        content: "An error has occurred."
    }
