/* Self-hosted (CSP allows 'self' only). Latin subset; other scripts fall back to the system font. SIL OFL 1.1. */
@font-face {
    font-family: "Sora";
    font-style: normal;
    font-weight: 500 700;
    font-display: swap;
    src: url("fonts/sora-latin.woff2") format("woff2");
}
@font-face {
    font-family: "IBM Plex Sans";
    font-style: normal;
    font-weight: 400 600;
    font-display: swap;
    src: url("fonts/ibm-plex-sans-latin.woff2") format("woff2");
}
@font-face {
    font-family: "IBM Plex Mono";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("fonts/ibm-plex-mono-400-latin.woff2") format("woff2");
}
@font-face {
    font-family: "IBM Plex Mono";
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url("fonts/ibm-plex-mono-500-latin.woff2") format("woff2");
}

*, *::before, *::after { box-sizing: border-box; }

/* Thin, rounded scrollbars in the theme's colours (page, drawers, dropdown lists). */
* { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 999px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); background-clip: padding-box; }
::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
::-webkit-scrollbar-corner { background: transparent; }
html { -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.45;
}

h1, h2, h3, p, dl, dd, pre { margin: 0; }
h1, h2, h3, .display { font-family: "Sora", "Segoe UI", system-ui, sans-serif; font-weight: 600; }
a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); }
.mono, code, pre { font-family: "IBM Plex Mono", Consolas, monospace; }
.muted { color: var(--text-dim); font-weight: 400; }
.sr-only { position: absolute; left: -9999px; }
svg { flex-shrink: 0; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; border: 0; margin: 0; padding: 0; }
.field > label, .field-label { font-size: 13px; font-weight: 500; color: var(--label); }
.req { color: var(--link); }
.hint { font-size: 12px; color: var(--text-faint); line-height: 1.5; }
.field-error { font-size: 12px; color: var(--danger-text); }

.input, .field input[type="text"], .field input[type="password"], .field input[type="email"], .field input[type="tel"],
.field input[type="number"], .field input[type="search"], .field select, .select {
    height: 42px;
    width: 100%;
    padding: 0 12px;
    border-radius: 8px;
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    color: var(--text);
    font: inherit;
    font-size: 14px;
}
/* Native select arrow replaced by one drawn in the theme's text colour (data: URI allowed by img-src). */
.field select, .select {
    -webkit-appearance: none;
    appearance: none;
    padding-right: 36px;
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 12px 8px;
    background-image: var(--select-arrow);
    cursor: pointer;
}
.field select::-ms-expand, .select::-ms-expand { display: none; }

/* Themed dropdown (Scripts/select.js). The native select stays in the form, visually hidden. */
.dd { position: relative; width: 100%; }
.dd--inline { width: auto; min-width: 180px; }
.dd-native { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; left: 0; top: 0; }
.dd-button {
    width: 100%;
    height: 42px;
    padding: 0 36px 0 12px;
    border-radius: 8px;
    border: 1px solid var(--input-border);
    background: var(--input-bg) var(--select-arrow) no-repeat right 12px center / 12px 8px;
    color: var(--text);
    font: inherit;
    font-size: 14px;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}
.dd--inline .dd-button { border-radius: 10px; }
.dd--mono .dd-button, .dd--mono .dd-list { font-family: "IBM Plex Mono", Consolas, monospace; }
.dd-button:focus-visible, .dd.is-open .dd-button { outline: none; border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.dd-button:disabled { opacity: .6; cursor: not-allowed; }
.field--invalid .dd-button { border-color: var(--danger-line); }
.dd-list {
    display: none;
    position: absolute;
    z-index: 30;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    margin: 0;
    padding: 4px;
    list-style: none;
    max-height: 280px;
    overflow-y: auto;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: 0 12px 32px rgba(0, 0, 0, .18);
}
.dd.is-open .dd-list { display: block; }
.dd-list li { padding: 9px 10px 9px 32px; border-radius: 6px; font-size: 14px; color: var(--text); cursor: pointer; position: relative; }
.dd-list li.is-active { background: var(--surface-2); }
.dd-list li.is-selected { font-weight: 600; }
.dd-list li.dd-group { padding: 10px 10px 4px 12px; font-family: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-dim); cursor: default; }
.dd-list li.dd-group:first-child { padding-top: 4px; }
.dd-button-group { margin-left: 8px; font-family: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif; font-size: 12px; color: var(--text-dim); }
.dd-list li.is-selected::before { content: ""; position: absolute; left: 12px; top: 50%; width: 10px; height: 6px; margin-top: -5px; border-left: 2px solid var(--accent); border-bottom: 2px solid var(--accent); transform: rotate(-45deg); }
.field--invalid input, .field--invalid select { border-color: var(--danger-line); }
.field input.mono { font-family: "IBM Plex Mono", Consolas, monospace; }
/* Fields: the border itself turns to the accent (no outline ring outside the grey border). */
input:not([type="checkbox"]):not([type="radio"]):focus, select:focus { outline: none; }
input[type="checkbox"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.input:focus, .select:focus, .field input:focus, .field select:focus {
    border-color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent);
}
button:focus-visible, a:focus-visible, summary:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.check { display: flex; align-items: center; gap: 10px; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 44px;
    padding: 0 18px;
    border-radius: 10px;
    border: 1px solid transparent;
    font: inherit;
    font-size: 15px;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
}
.btn--primary { background: var(--primary-bg); color: var(--primary-text); font-weight: 600; }
.btn--primary:hover { background: var(--primary-hover); color: var(--primary-text); }
.btn--ghost { background: transparent; border-color: var(--input-border); color: var(--text); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }
.btn--danger { background: var(--danger-solid); color: #FFFFFF; font-weight: 600; }
.btn--sm { height: 36px; padding: 0 12px; border-radius: 8px; font-size: 14px; }
.btn--block { width: 100%; }
.btn--link { background: none; border: 0; padding: 0; height: auto; color: var(--link); font-size: 13px; }
.btn[disabled] { opacity: .6; cursor: progress; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }
.is-locked { opacity: .45; pointer-events: none; }
.icon-btn {
    width: 40px; height: 40px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 8px; border: 0;
    background: var(--surface-2); color: var(--text);
    cursor: pointer;
}

/* Alerts */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 8px; font-size: 13px; line-height: 1.45; }
.alert svg { margin-top: 1px; }
.alert--error { background: var(--danger-bg); border: 1px solid var(--danger-border); color: var(--danger-text); }
.alert--ok { background: var(--ok-bg); color: var(--ok-text); align-items: center; }
.alert--warn { background: var(--warn-bg); color: var(--warn-text); }
.alert--info { background: var(--info-bg); color: var(--info-text); font-size: 12px; line-height: 1.5; }

/* Borderless tinted card: layered shadow gives the edge, the round icon carries the status colour. */
#toast-container.toast-top-right { top: 16px; right: 16px; }
#toast-container > div {
    width: 360px;
    opacity: 1;
    color: var(--text);
    background-color: var(--surface);
    border: 0;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 12px 32px rgba(16, 24, 40, .14);
    font-family: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.45;
    padding: 12px 16px 12px 46px;
    background-repeat: no-repeat;
    background-position: 14px 12px;
    background-size: 20px 20px;
}
#toast-container > div:hover { box-shadow: 0 10px 28px rgba(20, 24, 33, .18); }
#toast-container > .toast-success { background-color: var(--toast-success-bg); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20'%3E%3Ccircle cx='10' cy='10' r='10' fill='%2322C55E'/%3E%3Cpath d='M6 10.3l2.6 2.6L14 7.5' fill='none' stroke='%23fff' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") !important; }
#toast-container > .toast-error { background-color: var(--toast-error-bg); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20'%3E%3Ccircle cx='10' cy='10' r='10' fill='%23EF4444'/%3E%3Cpath d='M7 7l6 6M13 7l-6 6' fill='none' stroke='%23fff' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E") !important; }
#toast-container > .toast-warning { background-color: var(--toast-warning-bg); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20'%3E%3Ccircle cx='10' cy='10' r='10' fill='%23F59E0B'/%3E%3Cpath d='M10 5.5v5.5M10 14.3v.2' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") !important; }
#toast-container > .toast-info { background-color: var(--toast-info-bg); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20'%3E%3Ccircle cx='10' cy='10' r='10' fill='%2364748B'/%3E%3Cpath d='M10 9v5.5M10 5.7v.2' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") !important; }
#toast-container .toast-progress { background-color: var(--text); opacity: .15; }

.signout-dialog { position: fixed; inset: 0; z-index: 20; }
.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: 1.2px; text-transform: uppercase; color: var(--text-faint); }

/* Sign-in family: centered card over the diamond backdrop */
.auth-page { position: relative; min-height: 100vh; overflow: hidden; display: flex; align-items: center; justify-content: center; padding: 32px 16px; }
.backdrop { position: absolute; left: 50%; top: 50%; width: 1440px; height: 900px; transform: translate(-50%, -50%); pointer-events: none; }
.backdrop g { stroke: var(--backdrop-line); }
.auth-stack { position: relative; width: 100%; max-width: 380px; display: flex; flex-direction: column; align-items: center; gap: 24px; }
.auth-stack--password, .auth-stack--enroll, .auth-stack--verify { gap: 28px; }
.auth-stack--password { max-width: 340px; }
.auth-stack--enroll { max-width: 420px; }
.auth-stack--verify { max-width: 360px; }
.auth-stack > .eyebrow { align-self: flex-start; margin-bottom: -18px; }
.brand { display: flex; align-items: center; gap: 10px; font-family: "Sora", "Segoe UI", system-ui, sans-serif; font-weight: 700; font-size: 18px; color: var(--text); }
.brand:hover { color: var(--text); }
.auth-card { width: 100%; padding: 28px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--card-shadow); display: flex; flex-direction: column; gap: 16px; }
.auth-card h1 { font-size: 20px; }
.auth-card .btn--primary { height: 44px; margin-top: 4px; border-radius: 8px; font-family: "Sora", "Segoe UI", system-ui, sans-serif; }
.auth-head { display: flex; flex-direction: column; gap: 6px; }
.auth-sub { font-size: 13px; color: var(--text-dim); line-height: 1.5; }
.auth-sub strong { color: var(--text); font-weight: 500; }
.auth-foot { font-size: 13px; color: var(--text-faint); text-align: center; line-height: 1.5; }
.auth-links { display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.auth-links form { margin: 0; }
.captcha-row { display: flex; gap: 8px; align-items: center; }
.captcha-img { width: 116px; height: 42px; flex-shrink: 0; border-radius: 8px; border: 1px solid var(--input-border); object-fit: cover; filter: var(--captcha-filter, none); }
.captcha-row .square-btn { flex-shrink: 0; }
.captcha-row .input { flex: 1 1 0; width: auto; min-width: 0; }
.pw-field { position: relative; display: block; }
.pw-field input { width: 100%; padding-right: 44px !important; }
.pw-field input::-ms-reveal, .pw-field input::-ms-clear { display: none; }
.pw-toggle { position: absolute; top: 50%; right: 4px; width: 36px; height: 36px; padding: 0; transform: translateY(-50%); border: 0; border-radius: 6px; background: transparent; color: var(--text-faint); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.pw-toggle:hover { color: var(--text); background: var(--surface-2); }
.pw-toggle[aria-pressed="true"] { color: var(--text); }
.square-btn.is-copied, .mini-btn.is-copied { color: var(--ok-text); }
.square-btn { width: 42px; height: 42px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; border: 1px solid var(--input-border); background: var(--input-bg); color: var(--label); cursor: pointer; }
.auth-card--otp { gap: 18px; }
.auth-card--otp .btn--primary { margin-top: 0; }
.auth-stack--verify .auth-card { padding: 24px; }
.otp-digits { display: flex; gap: 8px; }
.otp-digits input.otp-digit { flex: 0 1 45px; width: auto; min-width: 0; height: 48px; padding: 0; border-radius: 8px; border: 1px solid var(--input-border); background: var(--input-bg); color: var(--text); text-align: center; font-family: "IBM Plex Mono", Consolas, monospace; font-size: 20px; }
.otp-digits input.otp-digit:focus { border: 2px solid var(--accent); box-shadow: none; }
.auth-stack--enroll .otp-digits input.otp-digit { flex-basis: 52px; }
.enroll { display: flex; gap: 18px; align-items: center; }
.qr-white { padding: 10px; border-radius: 10px; background: #FFFFFF; display: flex; }
.qr-white img { display: block; width: 126px; height: 126px; image-rendering: pixelated; }
.key-row { display: flex; align-items: center; gap: 6px; }
.key-row .square-btn { width: 30px; height: 30px; flex-shrink: 0; border-radius: 6px; background: var(--surface-2); }
.key { padding: 6px 8px; border-radius: 6px; background: var(--bg); border: 1px solid var(--input-border); font-size: 12px; word-break: break-all; }
/* Groups are spans spaced by CSS, not space characters, so selecting and copying the key yields it unbroken. */
.key--grouped { word-break: normal; line-height: 1.6; }
.key--grouped span { display: inline-block; margin-right: 1ch; }
.key--grouped span:last-child { margin-right: 0; }
.key-hint { color: var(--text-dim); }

/* Status / error pages */
.status-card { width: 100%; max-width: 520px; padding: 40px; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); display: flex; flex-direction: column; gap: 22px; }
.status-icon { width: 56px; height: 56px; border-radius: 16px; display: flex; align-items: center; justify-content: center; background: var(--danger-bg); color: var(--danger-solid); }
.status-code { font-size: 13px; color: var(--text-dim); }
.status-card h1 { font-size: 28px; }
.status-card p { font-size: 15px; line-height: 1.55; color: var(--text-dim); }
.status-facts { padding: 18px; border-radius: 12px; background: var(--bg); display: grid; grid-template-columns: 120px 1fr; row-gap: 12px; font-size: 14px; }
.status-facts dt { color: var(--text-dim); }

@media (max-width: 480px) {
    .auth-card { padding: 20px; }
    .enroll { flex-direction: column; align-items: flex-start; }
    .status-card { padding: 24px; }
}
