/*
 * FA-Soft UI 1.0: the look and feel of every FA-Soft web app. Plain CSS, no framework.
 * Values come from tokens/fa-soft-tokens.json. Do not change them per app: change the tokens, then every template.
 *
 * Page frame:      .shell > header.topbar + nav.sidenav + main.content + footer.footbar
 * Themes:          <html data-theme="standard|light|dark">; Standard (the company colors) is the default the app sets;
 *                  without the attribute ("System") the system's light or dark setting applies.
 * Two-variant images (logos): .only-light / .only-dark; only the one of the active theme is shown.
 */

/* ---- Tokens ---- */

:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --text: #1d2430;
    --muted: #5b6574;
    --border: #d9dee5;
    --accent: #1f5fbf;
    --accent-text: #ffffff;
    --ok: #1d7a46;
    --ok-bg: #e5f4eb;
    --warn: #8a5a00;
    --warn-bg: #fff4d6;
    --danger: #b3261e;
    --danger-bg: #fde8e7;
    --danger-text: #ffffff;
    --info-bg: #e8f0fc;
    --radius: 8px;
    --control-radius: 6px;
    --focus: 0 0 0 3px rgba(31, 95, 191, 0.45);
    --sidenav-width: 220px;
    --font-mono: ui-monospace, "Cascadia Code", Consolas, monospace;
    color-scheme: light dark;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.5;
}

:root[data-theme="light"] { color-scheme: light; }

/* Standard: the FA-Soft company colors. Navy on white and white on navy are about 9:1; light blue is only for lines
   and tints; amber marks where you are. */
:root[data-theme="standard"] {
    color-scheme: light;
    --brand-navy: #1e4a8c;
    --brand-light: #7aa7dc;
    --brand-amber: #e8a33d;
    --bg: #f2f5fa;
    --surface: #ffffff;
    --text: #152238;
    --muted: #526079;
    --border: #d2dbe8;
    --accent: var(--brand-navy);
    --accent-text: #ffffff;
    --info-bg: #e5eef9;
    --focus: 0 0 0 3px rgba(122, 167, 220, 0.75);
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #12161c;
    --surface: #1b2129;
    --text: #e6e9ee;
    --muted: #a3acb9;
    --border: #313a46;
    --accent: #6ea2ff;
    --accent-text: #0b1220;
    --ok: #6fd49a;
    --ok-bg: #173325;
    --warn: #f2c35b;
    --warn-bg: #3a2e12;
    --danger: #ff8f87;
    --danger-bg: #3d1a18;
    --danger-text: #0b1220;
    --info-bg: #172338;
    --focus: 0 0 0 3px rgba(110, 162, 255, 0.5);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --bg: #12161c;
        --surface: #1b2129;
        --text: #e6e9ee;
        --muted: #a3acb9;
        --border: #313a46;
        --accent: #6ea2ff;
        --accent-text: #0b1220;
        --ok: #6fd49a;
        --ok-bg: #173325;
        --warn: #f2c35b;
        --warn-bg: #3a2e12;
        --danger: #ff8f87;
        --danger-bg: #3d1a18;
    --danger-text: #0b1220;
        --info-bg: #172338;
        --focus: 0 0 0 3px rgba(110, 162, 255, 0.5);
    }
}

/* Images in two variants: only the one of the active theme is shown. */
:root[data-theme="standard"] .only-dark,
:root[data-theme="light"] .only-dark,
:root[data-theme="dark"] .only-light { display: none; }
@media (prefers-color-scheme: light) { :root:not([data-theme]) .only-dark { display: none; } }
@media (prefers-color-scheme: dark) { :root:not([data-theme]) .only-light { display: none; } }

/* ---- Base ---- */

* { box-sizing: border-box; }
/* Anchor jumps and focus scrolling stop below the sticky top bar instead of under it. */
html { scroll-padding-top: 4.5rem; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 4px; }
h1 { font-size: 1.6rem; margin: 0 0 1rem; display: flex; align-items: center; gap: 0.5rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 0.5rem; display: flex; align-items: center; gap: 0.5rem; }
:root[data-theme="standard"] h1 { color: var(--brand-navy); }
.muted { color: var(--muted); font-size: 0.9rem; margin: 0.25rem 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.skip-link { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--accent-text); padding: 0.5rem 1rem; z-index: 30; }
.skip-link:focus { left: 0.5rem; top: 0.5rem; }

/* ---- Page frame: top bar, left menu, body, foot bar ---- */

.shell {
    display: grid;
    grid-template-columns: var(--sidenav-width) minmax(0, 1fr);
    grid-template-rows: auto 1fr auto;
    grid-template-areas: "top top" "nav main" "foot foot";
    min-height: 100vh;
    /* On very wide screens the whole page is centred, at most 1920px wide. */
    max-width: 1920px;
    margin: 0 auto;
}
/* A page without a left menu (sign-in, a small app): body and foot bar take the whole width. */
.shell-no-nav { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "main" "foot"; }

@media (min-width: 1921px) {
    .shell { border-left: 1px solid var(--border); border-right: 1px solid var(--border); background: var(--bg); }
}

/* Top bar: the app's mark and name on the left; status, theme, language, account and sign-out on the right. Stays
   visible while the page scrolls. */
.topbar {
    grid-area: top;
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: 0.5rem; font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.brand-mark { width: 28px; height: 28px; }
.topbar-end { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.topbar-end form { margin: 0; }
.topbar-end .button { padding: 0.35rem 0.9rem; }
.account-link { color: var(--text); }

/* Left menu. */
.sidenav {
    grid-area: nav;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 1rem 0.75rem;
    background: var(--surface);
    border-right: 1px solid var(--border);
}
.sidenav a { color: var(--text); text-decoration: none; padding: 0.5rem 0.75rem; border-radius: var(--radius); }
.sidenav a:hover { background: var(--bg); }
.sidenav a.active, .sidenav a[aria-current="page"] { background: var(--accent); color: var(--accent-text); }
/* A group heading in a long menu. */
.sidenav-heading { margin: 0.75rem 0.75rem 0.25rem; font-size: 0.8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* Body. Running text keeps a readable line length; tables, charts and tiles use the whole width. */
.content { grid-area: main; padding: 1.5rem 2rem 3rem; min-width: 0; }
.content > p, .content > section > p, .content .field-help, .content .muted { max-width: 110ch; }

/* Foot bar: the FA-Soft logo (to fa-soft.eu) on the left; Learn and Support on the right. Scrolls with the page. */
.footbar {
    grid-area: foot;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 1.5rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
}
.footbar-brand { line-height: 0; }
.footbar-brand img { height: 33px; width: auto; display: block; }
.footbar-links { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.footbar-links a { color: var(--accent); }

/* Standard theme: the brand line (navy to light blue) under the top bar and over the foot bar; amber marks the
   selected page. */
:root[data-theme="standard"] .topbar { border-bottom: 3px solid transparent; border-image: linear-gradient(90deg, var(--brand-navy), var(--brand-light)) 1; }
:root[data-theme="standard"] .footbar { border-top: 3px solid transparent; border-image: linear-gradient(90deg, var(--brand-navy), var(--brand-light)) 1; }
:root[data-theme="standard"] .brand { color: var(--brand-navy); }
:root[data-theme="standard"] .sidenav a:hover { background: var(--info-bg); }
:root[data-theme="standard"] .sidenav a.active,
:root[data-theme="standard"] .sidenav a[aria-current="page"] { box-shadow: inset 4px 0 0 var(--brand-amber); }
:root[data-theme="standard"] .button-secondary:hover { border-color: var(--brand-light); }

/* Narrow screens: top bar, menu, body and foot bar below each other; the menu takes only the height it needs. */
@media (max-width: 720px) {
    .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto 1fr auto; grid-template-areas: "top" "nav" "main" "foot"; }
    .shell-no-nav { grid-template-rows: auto 1fr auto; grid-template-areas: "top" "main" "foot"; }
    .topbar { flex-wrap: wrap; padding: 0.75rem 1rem; }
    .sidenav { flex-direction: row; flex-wrap: wrap; align-items: flex-start; border-right: none; border-bottom: 1px solid var(--border); }
    .sidenav-heading { display: none; }
    .content { padding: 1rem; }
    .content table { display: block; max-width: 100%; overflow-x: auto; }
    .content h1 { flex-wrap: wrap; overflow-wrap: anywhere; }
    .footbar { padding: 0.75rem 1rem; }
}

/* ---- Theme and language switches in the top bar: a disclosure with one button per choice (no script) ---- */

.menu-switch { position: relative; }
.menu-switch summary {
    list-style: none; cursor: pointer; padding: 0.3rem 0.65rem;
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--muted); font-size: 0.875rem;
}
.menu-switch summary::-webkit-details-marker { display: none; }
.menu-switch summary::after { content: " ▾"; }
.menu-switch summary:hover { color: var(--text); }
.menu-switch form {
    position: absolute; right: 0; top: calc(100% + 0.25rem); z-index: 10;
    display: flex; flex-direction: column; min-width: 10rem; padding: 0.25rem;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 4px 16px rgb(0 0 0 / 0.15);
}
.menu-switch button {
    text-align: left; padding: 0.35rem 0.6rem; border: 0; border-radius: calc(var(--radius) - 2px);
    background: transparent; color: var(--text); font: inherit; font-size: 0.9rem; cursor: pointer;
}
.menu-switch button:hover { background: var(--bg); }
.menu-switch button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }

/* ---- Badges, alerts, cards ---- */

.badge { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.85rem; font-weight: 600; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warning { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-muted { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
td .badge { white-space: nowrap; }

.alert { border-radius: var(--radius); padding: 0.75rem 1rem; margin: 0 0 1rem; border: 1px solid var(--border); }
.alert p, .alert ul { margin: 0.5rem 0 0; }
.alert-info { background: var(--info-bg); border-color: var(--accent); }
.alert-ok { background: var(--ok-bg); border-color: var(--ok); }
.alert-warning { background: var(--warn-bg); border-color: var(--warn); }
.alert-danger { background: var(--danger-bg); border-color: var(--danger); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.card h2, .card .card-heading { margin: 0 0 0.5rem; font-size: 1rem; color: var(--muted); }
.metric { font-size: 1.6rem; font-weight: 700; margin: 0; }

/* ---- Tables ---- */

table { position: relative; width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
tr.disabled td { color: var(--muted); }
.table-scroll { overflow-x: auto; position: relative; max-width: 100%; }
.row-actions { white-space: nowrap; display: flex; gap: 0.5rem; align-items: center; }
.row-actions form { margin: 0; }

/* ---- Forms ---- */

.form { max-width: 720px; }
.field { margin-bottom: 1rem; flex: 1; min-width: 200px; }
.field-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.field label, .label { display: block; font-weight: 600; margin-bottom: 0.15rem; }
.field-optional { font-weight: normal; color: var(--muted); font-size: 0.9rem; margin-left: 0.3rem; }
.field-help { margin: 0 0 0.35rem; color: var(--muted); font-size: 0.9rem; }
.field-error, .validation-message { color: var(--danger); font-size: 0.9rem; margin-top: 0.25rem; }
input[type="text"], input[type="search"], input[type="number"], input[type="password"], input[type="email"], input[type="url"], input[type="date"], input:not([type]), select, textarea {
    width: 100%; padding: 0.5rem 0.6rem; font: inherit; color: var(--text);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--control-radius);
}
select { max-width: 100%; }
input.invalid, select.invalid, textarea.invalid { border-color: var(--danger); }
textarea.code, code, pre { font-family: var(--font-mono); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem 1rem 0.25rem; margin: 0 0 1rem; background: var(--surface); min-width: 0; }
legend { font-weight: 700; padding: 0 0.35rem; }
.checkbox-field { display: grid; grid-template-columns: auto 1fr; column-gap: 0.5rem; align-items: center; }
.checkbox-field .field-help { grid-column: 2; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin: 0.75rem 0; }
.actions form { margin: 0; }
.details { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 0.25rem 1rem; }
.details dt { font-weight: 600; }
.details dd { margin: 0; overflow-wrap: anywhere; }

/* ---- Buttons ---- */

.button {
    display: inline-block; text-decoration: none; font: inherit; font-weight: 600; padding: 0.55rem 1.25rem;
    border: none; border-radius: var(--control-radius); background: var(--accent); color: var(--accent-text); cursor: pointer;
}
.button-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.button-danger { background: var(--danger); color: var(--danger-text); --spinner: var(--danger-text); }
.link-button { font: inherit; color: var(--accent); background: none; border: none; padding: 0; cursor: pointer; text-decoration: underline; }
.icon-button {
    display: inline-flex; align-items: center; justify-content: center; width: 2.25rem; height: 2.25rem; padding: 0;
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none;
}
.icon-button:hover { border-color: var(--accent); color: var(--accent); }
.icon-button-danger:hover { border-color: var(--danger); color: var(--danger); }
.icon-button:disabled { opacity: 0.45; cursor: not-allowed; border-color: var(--border); color: var(--muted); }
.icon-button svg { display: block; }
.button, .icon-button, .link-button, button { transition: transform 0.06s ease-out, filter 0.12s, box-shadow 0.12s; }
.button:hover { filter: brightness(1.08); }
/* Pressed: the button sinks a little and darkens, so a click is seen at once. */
.button:active, .icon-button:active, button:active { transform: translateY(1px) scale(0.98); filter: brightness(0.9); }

/* Busy (a form on its way): a spinner takes the place of the label; nothing reacts to another click. */
.is-busy { position: relative; cursor: progress; pointer-events: none; }
.button.is-busy { color: transparent !important; }
.button.is-busy::after {
    content: ""; position: absolute; inset: 0; margin: auto; width: 1.1em; height: 1.1em;
    border: 2px solid var(--spinner, var(--accent-text)); border-right-color: transparent; border-radius: 50%;
    animation: busy-spin 0.7s linear infinite;
}
.button-secondary { --spinner: var(--text); }
@keyframes busy-spin { to { transform: rotate(360deg); } }

/* ---- On/off switch: a button that looks like a switch; green when on ---- */

.switch { display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.2rem 0; border: none; background: none; font: inherit; color: var(--text); cursor: pointer; }
.switch-track { position: relative; flex: none; width: 2.6rem; height: 1.5rem; border-radius: 999px; background: var(--border); transition: background-color 0.15s; }
.switch-thumb { position: absolute; top: 0.15rem; left: 0.15rem; width: 1.2rem; height: 1.2rem; border-radius: 50%; background: #ffffff; box-shadow: 0 1px 2px rgb(0 0 0 / 0.3); transition: left 0.15s; }
.switch[aria-checked="true"] .switch-track { background: var(--ok); }
.switch[aria-checked="true"] .switch-thumb { left: calc(100% - 1.35rem); }
.switch-text { font-size: 0.9rem; color: var(--muted); min-width: 1.8rem; text-align: left; }
.switch:focus-visible { box-shadow: none; }
.switch:focus-visible .switch-track { box-shadow: var(--focus); }

/* ---- Inline help: a "?" that opens a short explanation ---- */

.help { display: inline-block; position: relative; font-size: 0.9rem; font-weight: normal; }
.help > summary {
    list-style: none; cursor: pointer; width: 1.4rem; height: 1.4rem; border-radius: 50%;
    border: 1px solid var(--border); background: var(--surface); color: var(--muted);
    display: inline-flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 700;
}
.help > summary::-webkit-details-marker { display: none; }
.help[open] > summary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.help-body {
    position: absolute; z-index: 5; top: 1.8rem; left: 0; width: min(320px, 80vw); padding: 0.75rem;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15); color: var(--text);
}
.help-body p { margin: 0.25rem 0 0; }
.help:not([open]) > .help-body { display: none; }
@media (max-width: 720px) { .help-body { position: fixed; left: 1rem; right: 1rem; top: auto; width: auto; } }

/* ---- Charts: the series colors, dark enough for white labels and visible in every theme ---- */

:root {
    --pie-1: #1f5fbf;
    --pie-2: #b3261e;
    --pie-3: #1d7a46;
    --pie-4: #8e44ad;
    --pie-5: #b35900;
    --pie-6: #0e7c86;
    --pie-7: #7a5c00;
    --pie-8: #4b5563;
}

/* ---- Motion ---- */

@media (prefers-reduced-motion: reduce) {
    .button, .icon-button, .link-button, button, .switch-track, .switch-thumb { transition: none; }
    .button.is-busy::after { animation-duration: 2s; }
}
