/* Northstar ID design system (DESIGN 8.1, ENTSCHEIDUNGEN I1/I4/I5/K1).
   Binding: white frosted glass, border-radius 0 everywhere, auth panel on
   the right, full-screen nature photos. Dark mode follows the system unless
   the viewer chose light or dark (data-theme on <html>, see the dark tokens).
   No inline styles anywhere (CSP) – everything lives here.

   Contrast: every text/UI token is chosen for WCAG AA on the panel
   surfaces. Panels are frosted glass at 72 % (light and dark, user
   request for more transparency) with a 30px blur; text and muted text keep
   AA even over a pure black/white photo pixel (muted tokens chosen for that),
   the blur averages the photo so real backgrounds stay near the surface range
   the accent tokens are checked against (internal/platform/theme).

   Accent: the --accent* tokens below are the SkyKopf default. A user's own
   accent colour is applied by /theme/v<N>/accent-<rrggbb>.css (generated by
   internal/platform/theme, linked after this file), which overrides exactly
   these custom properties per colour scheme. Components must only use the
   tokens, never raw accent colours. */

/* ---------- Fonts (SIL OFL 1.1, see /about) ---------- */
@font-face { font-family: "Open Sauce Sans"; src: url("../fonts/OpenSauceSans-Regular.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Open Sauce Sans"; src: url("../fonts/OpenSauceSans-SemiBold.woff2") format("woff2"); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: "Open Sauce Sans"; src: url("../fonts/OpenSauceSans-Bold.woff2") format("woff2"); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: "Google Sans"; src: url("../fonts/GoogleSans-Regular.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Google Sans"; src: url("../fonts/GoogleSans-Italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Google Sans"; src: url("../fonts/GoogleSans-Medium.woff2") format("woff2"); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: "Google Sans"; src: url("../fonts/GoogleSans-SemiBold.woff2") format("woff2"); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: "Google Sans"; src: url("../fonts/GoogleSans-Bold.woff2") format("woff2"); font-weight: 700; font-style: normal; font-display: swap; }

/* ---------- Tokens: light ---------- */
:root {
  color-scheme: light dark;

  --font-heading: "Open Sauce Sans", "Google Sans", system-ui, sans-serif;
  --font-body: "Google Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  /* Surfaces */
  --surface: rgba(255, 255, 255, 0.72);         /* glass panels, cards */
  --surface-strong: rgba(255, 255, 255, 0.92);  /* dialogs, fields, menus */
  --surface-hover: rgba(16, 20, 26, 0.06);      /* row/item hover on a surface */
  --surface-sunken: rgba(16, 20, 26, 0.04);     /* stat boxes, code blocks */
  --glass-blur: blur(30px) saturate(1.6);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.12);
  --backdrop: rgba(10, 12, 16, 0.55);

  /* Text */
  --text: #10141a;
  --text-muted: #3a414b;
  --link: var(--accent-text);

  /* No borders anywhere (user decision): things are separated by fills,
     spacing and shadows. --border / --border-strong survive only as colours:
     --border = a subtle tint, --border-strong = the >= 3:1 indicator colour
     (field underline, inset shadow), never as a border line. */
  --border: rgba(16, 20, 26, 0.10);
  --border-strong: #5b636e;

  /* Fills: fields and secondary controls are filled, never outlined. On the
     light glass the fills are lighter than the panel (keeps text AA even
     where the glass greys over a dark photo); on the dark glass lighter too. */
  --fill: rgba(255, 255, 255, 0.82);          /* fields */
  --fill-hover: rgba(255, 255, 255, 0.95);
  --btn-fill: rgba(255, 255, 255, 0.62);      /* secondary buttons, chips, tiles */
  --btn-fill-hover: rgba(255, 255, 255, 0.92);
  --fill-active: rgba(255, 255, 255, 1);
  --danger-fill: color-mix(in srgb, var(--danger-solid) 7%, var(--surface-strong));
  --danger-fill-hover: color-mix(in srgb, var(--danger-solid) 14%, var(--surface-strong));
  --field-indicator: inset 0 -2px 0 var(--text-muted); /* >= 3:1 bottom edge of a field */
  --zebra: rgba(255, 255, 255, 0.34);

  /* Status: text colour (>= 4.5:1 on surfaces), solid fill + its text, tint */
  --danger: #a1221b;
  --danger-solid: #b3261e;
  --on-danger: #ffffff;
  --danger-bg: rgba(179, 38, 30, 0.10);
  --success: #0f5f27;
  --success-solid: #146c2e;
  --on-success: #ffffff;
  --success-bg: rgba(20, 108, 46, 0.10);
  --warning: #7a4900;
  --warning-solid: #8a5300;
  --on-warning: #ffffff;
  --warning-bg: rgba(138, 83, 0, 0.12);
  --info: var(--accent-text);
  --info-bg: var(--accent-subtle);

  /* Accent: SkyKopf default (#1257c7). BEGIN generated defaults (theme.CSS) */
  --accent: #1257c7;
  --accent-hover: #0048b4;
  --accent-active: #003c99;
  --on-accent: #ffffff;
  --accent-text: #0045af;
  --accent-subtle: #e8f1ff;
  --accent-border: #1257c7;
  --focus-color: #004ab9;
  --selection-bg: #b2cfff;
  --selection-text: #10141a;
  /* END generated defaults */

  /* Compatibility aliases (module stylesheets) */
  --glass-bg: var(--surface);
  --glass-bg-strong: var(--surface-strong);
  --line: var(--border);
  --field-bg: var(--fill);
  --field-border: var(--border-strong);
  --focus-outline: 3px solid var(--focus-color);
  --focus-ring: 0 0 0 3px var(--focus-color);

  /* Scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;

  --text-xs: 0.8rem;
  --text-sm: 0.875rem;
  --text-md: 1rem;
  --text-lg: 1.125rem;

  --radius: 0;
  /* Control size system: every input, select and button of the default size
     is exactly --control-h tall, the small size (tables, inline, chips)
     exactly --control-h-sm. Same font size, line-height and icon gap per size. */
  --control-h: 2.75rem;
  --control-h-sm: 2.125rem;
  --control-px: var(--space-4);
  --control-px-sm: var(--space-3);
  --control-font: var(--text-md);
  --control-font-sm: var(--text-sm);
  --control-gap: var(--space-2);
  --panel-width: 30rem;
  --sidebar-width: 16rem;
  --content-max: 80rem;
  --transition: 120ms ease-out;
}

/* ---------- Tokens: dark ----------
   Theme switcher (layout/partials/theme.html, js/theme.js): <html> carries
   data-theme="light" or "dark" when the viewer chose a mode, nothing for
   "System". Every dark rule therefore applies twice: under the OS preference
   unless light was forced, and when dark was forced. The two token blocks
   below must stay identical (checked by internal/platform/theme tests);
   page stylesheets use the same two selectors for their dark rules. */
:root[data-theme="light"] { color-scheme: light; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface: rgba(18, 20, 23, 0.72);
    --surface-strong: rgba(24, 27, 31, 0.93);
    --surface-hover: rgba(255, 255, 255, 0.08);
    --surface-sunken: rgba(255, 255, 255, 0.05);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --backdrop: rgba(0, 0, 0, 0.65);

    --text: #f3f5f8;
    --text-muted: #ccd3dc;

    --border: rgba(255, 255, 255, 0.10);
    --border-strong: #9aa2ad;

    --fill: rgba(255, 255, 255, 0.10);
    --fill-hover: rgba(255, 255, 255, 0.15);
    --btn-fill: rgba(255, 255, 255, 0.12);
    --btn-fill-hover: rgba(255, 255, 255, 0.18);
    --fill-active: rgba(255, 255, 255, 0.22);
    --danger-fill: rgba(255, 180, 171, 0.12);
    --danger-fill-hover: rgba(255, 180, 171, 0.2);
    --field-indicator: inset 0 -2px 0 var(--border-strong);
    --zebra: rgba(0, 0, 0, 0.16);           /* darker rows keep light text AA over bright photos */

    --danger: #ffb4ab;
    --danger-solid: #ffb4ab;
    --on-danger: #3b0906;
    --danger-bg: rgba(255, 180, 171, 0.14);
    --success: #8fd9a0;
    --success-solid: #8fd9a0;
    --on-success: #062411;
    --success-bg: rgba(143, 217, 160, 0.14);
    --warning: #ffcf87;
    --warning-solid: #ffcf87;
    --on-warning: #2e1b00;
    --warning-bg: rgba(255, 207, 135, 0.14);

    /* BEGIN generated dark defaults (theme.CSS) */
    --accent: #4387fb;
    --accent-hover: #5d99ff;
    --accent-active: #78aaff;
    --on-accent: #0b0d10;
    --accent-text: #79abff;
    --accent-subtle: #17243a;
    --accent-border: #4387fb;
    --focus-color: #4387fb;
    --selection-bg: #2b4c83;
    --selection-text: #f3f5f8;
    /* END generated dark defaults */
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface: rgba(18, 20, 23, 0.72);
  --surface-strong: rgba(24, 27, 31, 0.93);
  --surface-hover: rgba(255, 255, 255, 0.08);
  --surface-sunken: rgba(255, 255, 255, 0.05);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --backdrop: rgba(0, 0, 0, 0.65);

  --text: #f3f5f8;
  --text-muted: #ccd3dc;

  --border: rgba(255, 255, 255, 0.10);
  --border-strong: #9aa2ad;

  --fill: rgba(255, 255, 255, 0.10);
  --fill-hover: rgba(255, 255, 255, 0.15);
  --btn-fill: rgba(255, 255, 255, 0.12);
  --btn-fill-hover: rgba(255, 255, 255, 0.18);
  --fill-active: rgba(255, 255, 255, 0.22);
  --danger-fill: rgba(255, 180, 171, 0.12);
  --danger-fill-hover: rgba(255, 180, 171, 0.2);
  --field-indicator: inset 0 -2px 0 var(--border-strong);
  --zebra: rgba(0, 0, 0, 0.16);           /* darker rows keep light text AA over bright photos */

  --danger: #ffb4ab;
  --danger-solid: #ffb4ab;
  --on-danger: #3b0906;
  --danger-bg: rgba(255, 180, 171, 0.14);
  --success: #8fd9a0;
  --success-solid: #8fd9a0;
  --on-success: #062411;
  --success-bg: rgba(143, 217, 160, 0.14);
  --warning: #ffcf87;
  --warning-solid: #ffcf87;
  --on-warning: #2e1b00;
  --warning-bg: rgba(255, 207, 135, 0.14);

  /* BEGIN generated forced dark defaults (theme.CSS) */
  --accent: #4387fb;
  --accent-hover: #5d99ff;
  --accent-active: #78aaff;
  --on-accent: #0b0d10;
  --accent-text: #79abff;
  --accent-subtle: #17243a;
  --accent-border: #4387fb;
  --focus-color: #4387fb;
  --selection-bg: #2b4c83;
  --selection-text: #f3f5f8;
  /* END generated forced dark defaults */
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; border-radius: 0 !important; }
/* The fallback colour lives on html only: a body background would paint above
   the fixed photo (z-index -1). The per-photo tint stylesheet overrides it. */
html { font-size: 100%; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: #5d6b5c; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: var(--text-md);
  line-height: 1.55;
  color: var(--text);
  overflow-wrap: break-word;
}
h1, h2, h3, h4 { font-family: var(--font-heading); font-weight: 700; line-height: 1.25; margin: 0 0 var(--space-3); color: var(--text); }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; font-weight: 600; }
h3 { font-size: 1.05rem; font-weight: 600; }
p { margin: 0 0 var(--space-4); }
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }
code, kbd, samp { font-family: var(--font-mono); font-size: 0.9em; }
pre { font-family: var(--font-mono); font-size: var(--text-sm); background: var(--surface-sunken); padding: var(--space-3); overflow-x: auto; }
img { max-width: 100%; }
ul, ol { margin: 0 0 var(--space-4); padding-left: 1.25rem; }
hr { border: 0; height: 0; margin: var(--space-5) 0; }
fieldset { min-width: 0; }
::selection { background: var(--selection-bg); color: var(--selection-text); }
progress, meter { accent-color: var(--accent); }

.muted { color: var(--text-muted); }
.small { font-size: var(--text-sm); }
.mono { font-family: var(--font-mono); font-size: 0.9em; overflow-wrap: anywhere; }
.sr-only, .visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

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

.skip-link {
  position: absolute; left: var(--space-2); top: -100px; z-index: 100;
  padding: var(--space-2) var(--space-4);
  background: var(--accent); color: var(--on-accent); font-weight: 600;
}
.skip-link:focus { top: var(--space-2); }

.icon {
  width: 1.25em; height: 1.25em;
  flex: none; vertical-align: -0.25em;
  stroke: currentColor; color: inherit;
}

/* ---------- Glass ---------- */
.glass {
  background: var(--surface);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 0;
  box-shadow: var(--glass-shadow);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass { background: var(--surface-strong); }
}

/* ---------- Background photo ---------- */
.bg-photo {
  position: fixed; inset: 0; z-index: -1;
  width: 100%; height: 100%; max-width: none;
  object-fit: cover; object-position: center;
  pointer-events: none; user-select: none;
}
.photo-credit {
  position: fixed; left: var(--space-4); bottom: var(--space-3); z-index: 1;
  margin: 0; padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs); color: #ffffff;
  background: rgba(0, 0, 0, 0.66);
  display: inline-flex; align-items: center; gap: var(--space-2);
}
.photo-credit a { color: #ffffff; }
.photo-credit a:focus-visible { outline-color: #ffffff; }

/* ---------- Logo ---------- */
.logo { display: inline-block; line-height: 0; }
.logo__img { width: 11rem; height: auto; }
.logo-mark { display: inline-block; line-height: 0; }
.logo-mark__img { width: 2.5rem; height: auto; }

/* ---------- Auth layout: panel on the RIGHT ---------- */
/* Desktop: the panel runs full height and sits clearly off the right edge. Inside it,
   text fields and block buttons run edge to edge (no gap left/right) and the
   fields have no underline; their text lines up with the labels because the
   field padding equals the panel padding. */
.auth-shell { --auth-pad: var(--space-6); --auth-gap: clamp(5rem, 11.7vw, 15rem); display: flex; min-height: 100vh; padding: 0 var(--auth-gap) 0 0; }
.auth-aside { flex: 1 1 auto; }
.auth-panel {
  flex: 0 0 var(--panel-width);
  width: var(--panel-width);
  max-width: 100%;
  min-height: 100vh;
  display: flex; flex-direction: column;
  padding: var(--auth-pad) var(--auth-pad) var(--space-4);
}
.auth-panel__header { margin-bottom: var(--space-7); }
.auth-panel__content { flex: 1 0 auto; }
.auth-panel__content > .btn--block + .btn--block,
.auth-panel__content form + .btn--block { margin-top: var(--space-3); }
.panel-title { font-size: 1.9rem; }
.auth-panel__content :is(input[type="text"], input[type="email"], input[type="password"], input[type="search"],
  input[type="url"], input[type="number"], input[type="tel"], input:not([type]), select, textarea) {
  width: calc(100% + 2 * var(--auth-pad));
  max-width: none;
  margin-inline: calc(-1 * var(--auth-pad));
  padding-inline: var(--auth-pad);
  background-color: var(--surface-strong);
  box-shadow: none;
}
.auth-panel__content :is(input, select, textarea):hover { background-color: var(--fill-hover); }
.auth-panel__content :is(input, select, textarea):focus-visible { outline: 2px solid var(--focus-color); outline-offset: -2px; box-shadow: none; }
.auth-panel__content :is(input, select, textarea)[aria-invalid="true"] { background-color: var(--danger-bg); box-shadow: inset 0 -3px 0 var(--danger); }
.auth-panel__content .btn--block {
  width: calc(100% + 2 * var(--auth-pad));
  max-width: none;
  margin-inline: calc(-1 * var(--auth-pad));
}

@media (max-width: 48rem) {
  .auth-shell { --auth-pad: var(--space-4); --auth-gap: 0; padding: 0; }
  .auth-aside { display: none; }
  .auth-panel { flex-basis: 100%; width: 100%; min-height: 100vh; padding: var(--space-5) var(--auth-pad) var(--space-4); }
  .auth-panel__header { margin-bottom: var(--space-6); }
  .panel-title { font-size: 1.6rem; }
  .layout-auth .photo-credit { position: static; margin: var(--space-4) 0 0; }
}

/* ---------- Plain layout ---------- */
.plain-shell { min-height: 100vh; display: flex; align-items: flex-start; justify-content: center; padding: var(--space-7) var(--space-4); }
.plain-card { width: 100%; max-width: 46rem; padding: var(--space-6); }
.plain-card__header { margin-bottom: var(--space-5); }
.about-section { margin-top: var(--space-5); }
@media (max-width: 40rem) {
  .plain-shell { padding: var(--space-4) var(--space-3) var(--space-7); }
  .plain-card { padding: var(--space-5) var(--space-4); }
}

/* ---------- App layout ---------- */
.app-shell { display: flex; min-height: 100vh; }
.app-sidebar {
  flex: 0 0 var(--sidebar-width); width: var(--sidebar-width);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  padding: var(--space-5) var(--space-3);
}
.app-sidebar__brand { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: 0 var(--space-3) var(--space-5); }
.app-sidebar .logo__img { width: 9rem; }
.btn.app-menu-toggle { display: none; }
.app-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; padding: var(--space-5); gap: var(--space-5); }
.app-main > * { width: 100%; max-width: var(--content-max); }
.app-topbar { padding: var(--space-4) var(--space-5); }
.app-topbar__title { margin: 0; font-size: 1.5rem; overflow-wrap: anywhere; }
.app-content { flex: 1 0 auto; min-width: 0; }
.app-main > .site-footer { margin-top: 0; padding: var(--space-2) var(--space-4); background: var(--surface); width: max-content; max-width: 100%; }

.nav-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-1); }
.nav-link {
  display: flex; align-items: center; gap: var(--space-3);
  width: 100%; min-height: var(--control-h);
  padding: var(--space-2) var(--space-3);
  color: var(--text); text-decoration: none; font-weight: 500;
  border: 0;
  transition: background var(--transition), color var(--transition);
}
.nav-link:hover { background: var(--surface-hover); text-decoration: none; }
/* Sidebar entries run edge to edge like the active indicator (hover included);
   the text stays where it was: the extra padding equals the sidebar padding. */
.app-sidebar .nav-link { width: calc(100% + 2 * var(--space-3)); margin-inline: calc(-1 * var(--space-3)); padding-inline: calc(2 * var(--space-3)); }
.nav-link.is-active, .nav-link[aria-current="page"] { background: var(--accent-subtle); color: var(--text); font-weight: 600; }
.nav-link.is-active .icon, .nav-link[aria-current="page"] .icon { color: var(--accent-text); }
/* Logout button of the dashboard navigation, styled like a nav link */
.app-nav__logout { margin-top: var(--space-5); }
.app-nav__logout form { margin: 0; }
.app-nav__button { font: inherit; background: transparent; border: 0; cursor: pointer; text-align: left; }

@media (max-width: 56rem) {
  .app-shell { flex-direction: column; }
  .app-sidebar {
    position: sticky; top: 0; z-index: 20; width: 100%; height: auto; max-height: 100vh;
    flex-basis: auto; padding: var(--space-3) var(--space-3);
  }
  .app-sidebar__brand { padding: 0 var(--space-1); }
  .app-sidebar .logo__img { width: 7.5rem; }
  .js .btn.app-menu-toggle { display: inline-flex; }
  .js .app-nav { display: none; }
  .js .app-nav.is-open { display: block; padding-top: var(--space-3); }
  .app-nav .nav-list { flex-direction: column; }
  .app-main { padding: var(--space-3); gap: var(--space-3); }
  .app-topbar { padding: var(--space-3) var(--space-4); }
  .app-topbar__title { font-size: 1.3rem; }
}

/* ---------- Cards, grids, sections ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(20rem, 100%), 1fr)); gap: var(--space-5); margin-bottom: var(--space-5); align-items: start; }
.grid > * { min-width: 0; } /* wide tables scroll instead of widening the column */
.card { padding: var(--space-5); min-width: 0; }
.card + .card { margin-top: var(--space-5); }
.grid > .card + .card { margin-top: 0; }
.card--wide { grid-column: 1 / -1; }
.card__title { display: flex; align-items: center; gap: var(--space-2); }
.card__title .icon { color: var(--accent-text); }
.card__header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--space-3); margin-bottom: var(--space-4); }
.card__header > * { margin: 0; }
.card > :last-child { margin-bottom: 0; }
@media (max-width: 40rem) {
  .grid { gap: var(--space-3); margin-bottom: var(--space-3); }
  .card { padding: var(--space-4); }
  .card + .card { margin-top: var(--space-3); }
}

.empty-state { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); padding: var(--space-6) var(--space-4); text-align: center; color: var(--text-muted); background: var(--surface-sunken); }
.empty-state .icon { width: 2rem; height: 2rem; }
.empty-state p { margin: 0; }

.dl { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-2) var(--space-4); margin: 0 0 var(--space-4); }
.dl dt { font-weight: 600; color: var(--text-muted); }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 30rem) {
  .dl { grid-template-columns: 1fr; gap: 0; }
  .dl dd { margin-bottom: var(--space-2); }
}

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: var(--space-4); margin-bottom: var(--space-4); }
/* The hidden attribute always wins over component display rules (e.g. .btn inline-flex). */
[hidden] { display: none !important; }

/* A lone submit in a column form keeps its natural width (not stretched). */
.form > .btn, .form > .form-actions, .form > .btn-row { align-self: flex-start; }
.form > .btn--block { align-self: stretch; }
.form-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.field { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.field label, .field .label { font-weight: 600; font-size: 0.95rem; }
.field__hint { font-size: var(--text-sm); color: var(--text-muted); margin: 0; }
.field__error { font-size: var(--text-sm); color: var(--danger); font-weight: 600; margin: 0; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 600; padding: 0; margin-bottom: var(--space-2); }

/* Fields: tinted fill + a >= 3:1 bottom indicator (inset shadow, not a border).
   Single-line fields are exactly --control-h tall, like buttons. */
input[type="text"], input[type="email"], input[type="password"], input[type="search"],
input[type="url"], input[type="number"], input[type="tel"], input[type="date"],
input[type="datetime-local"], input[type="time"], input:not([type]), select, textarea {
  width: 100%;
  height: var(--control-h);
  margin: 0;
  font: inherit; font-size: var(--control-font); line-height: 1.25; color: var(--text);
  padding: 0 var(--space-3);
  background: var(--fill);
  border: 0;
  box-shadow: var(--field-indicator);
  transition: background var(--transition), box-shadow var(--transition);
}
textarea { height: auto; min-height: 6rem; padding: var(--space-2) var(--space-3); line-height: 1.5; resize: vertical; }
select[multiple], select[size] { height: auto; padding: var(--space-1) var(--space-2); }
select:not([multiple]):not([size]) {
  -webkit-appearance: none; appearance: none; padding-right: 2.25rem;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 1.05rem) 52%, calc(100% - 0.7rem) 52%;
  background-size: 0.35rem 0.35rem, 0.35rem 0.35rem;
  background-repeat: no-repeat;
  background-color: var(--fill);
}
select option { color: var(--text); background: var(--surface-strong); }
input::placeholder, textarea::placeholder { color: var(--text-muted); opacity: 1; }
input:hover, select:hover, textarea:hover { background-color: var(--fill-hover); }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--focus-color); outline-offset: 0; box-shadow: inset 0 -2px 0 var(--focus-color);
}
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { background-color: var(--danger-bg); box-shadow: inset 0 -3px 0 var(--danger); }
input:disabled, select:disabled, textarea:disabled { opacity: 0.6; cursor: not-allowed; }
input[readonly] { background-color: var(--surface-sunken); box-shadow: none; }
/* Small fields (tables, inline editors) match .btn--small. */
.input--sm, .table input[type="text"], .table input[type="number"], .table input:not([type]), .table select:not([multiple]):not([size]) { height: var(--control-h-sm); font-size: var(--control-font-sm); padding-left: var(--space-2); }
input[type="color"] { width: 4rem; height: var(--control-h); padding: 0.25rem 0.25rem 0.375rem; background: var(--fill); border: 0; box-shadow: var(--field-indicator); cursor: pointer; }
input[type="file"] { font: inherit; color: var(--text); width: 100%; max-width: 100%; padding: var(--space-2); background: var(--fill); border: 0; box-shadow: var(--field-indicator); }
input[type="file"]::file-selector-button {
  font: inherit; font-weight: 600; font-size: var(--control-font-sm); margin-right: var(--space-3);
  min-height: var(--control-h-sm); padding: 0 var(--control-px-sm);
  color: var(--text); background: var(--btn-fill-hover); box-shadow: var(--shadow-sm); border: 0; cursor: pointer;
}

.check { display: inline-flex; align-items: flex-start; gap: var(--space-2); cursor: pointer; line-height: 1.4; }
.check > input { margin-top: 0.1em; }
input[type="checkbox"], input[type="radio"] { width: 1.15rem; height: 1.15rem; margin: 0; flex: none; accent-color: var(--accent); cursor: pointer; }
input[type="checkbox"]:focus-visible, input[type="radio"]:focus-visible { outline: 3px solid var(--focus-color); outline-offset: 2px; }

/* ---------- Buttons ----------
   Variants: --primary (one main action per card), --secondary (tinted fill),
   --ghost (tertiary, transparent until hover; icon-only / pager only),
   --danger (tinted danger), --danger-solid (final destructive step).
   Sizes: default (= field height) and --small (tables, card headers, inline).
   No borders; height comes from the size token, never from padding. */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--control-gap);
  min-height: var(--control-h);
  margin: 0;
  padding: 0 var(--control-px);
  font: inherit; font-size: var(--control-font); font-weight: 600; line-height: 1.2; text-align: center; text-decoration: none;
  vertical-align: middle;
  color: var(--text); background: transparent;
  border: 0; cursor: pointer;
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
}
.btn .icon { width: 1.25em; height: 1.25em; }
.btn:hover { text-decoration: none; }
.btn:focus-visible { outline: 3px solid var(--focus-color); outline-offset: 2px; }
.btn--primary { background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow-sm); }
.btn--primary:hover { background: var(--accent-hover); color: var(--on-accent); }
.btn--primary:active { background: var(--accent-active); }
.btn--secondary { background: var(--btn-fill); color: var(--text); box-shadow: var(--shadow-sm); }
.btn--secondary:hover { background: var(--btn-fill-hover); }
.btn--secondary:active { background: var(--fill-active); }
.btn--ghost { background: transparent; color: var(--text); }
.btn--ghost:hover { background: var(--btn-fill); }
.btn--ghost:active { background: var(--btn-fill-hover); }
.btn--danger { background: var(--danger-fill); color: var(--danger); box-shadow: var(--shadow-sm); }
.btn--danger:hover { background: var(--danger-fill-hover); color: var(--danger); }
.btn--danger-solid { background: var(--danger-solid); color: var(--on-danger); box-shadow: var(--shadow-sm); }
.btn--danger-solid:hover { filter: brightness(0.92); }
.btn--block { display: flex; width: 100%; }
.btn--small { min-height: var(--control-h-sm); padding: 0 var(--control-px-sm); font-size: var(--control-font-sm); }
.btn--icon { padding-left: 0; padding-right: 0; min-width: var(--control-h); }
.btn--small.btn--icon { min-width: var(--control-h-sm); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; filter: none; }
.btn--secondary[disabled]:hover, .btn--secondary[aria-disabled="true"]:hover { background: var(--btn-fill); }
.btn--ghost[disabled]:hover, .btn--ghost[aria-disabled="true"]:hover { background: transparent; }
.btn--primary[disabled]:hover { background: var(--accent); }
.htmx-request .btn[type="submit"], .btn.htmx-request { opacity: 0.7; cursor: progress; }

.btn-row { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.btn-row form { margin: 0; }
/* Card header actions are always the small size; forms inside keep the row. */
.card__header .btn { min-height: var(--control-h-sm); padding: 0 var(--control-px-sm); font-size: var(--control-font-sm); }
.card__header form { margin: 0; }
/* Table row actions are always the small size. */
.table .btn { min-height: var(--control-h-sm); padding: 0 var(--control-px-sm); font-size: var(--control-font-sm); white-space: nowrap; }
.table .btn--icon { padding: 0; min-width: var(--control-h-sm); }

.divider { display: flex; align-items: center; justify-content: center; gap: var(--space-3); margin: var(--space-5) 0; color: var(--text-muted); font-size: 0.9rem; }

/* ---------- Alerts ---------- */
.alert {
  display: flex; align-items: flex-start; gap: var(--space-3);
  padding: var(--space-3) var(--space-4); margin-bottom: var(--space-4);
  color: var(--text); background: var(--alert-bg, var(--accent-subtle));
  border: 0;
}
.alert p { margin: 0; color: var(--text); }
.alert > p, .alert > div { flex: 1 1 auto; min-width: 0; }
.alert > .icon { margin-top: 0.15em; color: var(--info); }
.alert--danger { --alert-bg: color-mix(in srgb, var(--danger-solid) 14%, var(--surface-strong)); }
.alert--danger > .icon { color: var(--danger); }
.alert--success { --alert-bg: color-mix(in srgb, var(--success-solid) 14%, var(--surface-strong)); }
.alert--success > .icon { color: var(--success); }
.alert--warning { --alert-bg: color-mix(in srgb, var(--warning-solid) 14%, var(--surface-strong)); }
.alert--warning > .icon { color: var(--warning); }
.alert--info { --alert-bg: var(--accent-subtle); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 0.1rem var(--space-2);
  font-size: var(--text-xs); font-weight: 600; line-height: 1.5; white-space: nowrap; vertical-align: middle;
  background: var(--accent); color: var(--on-accent); border: 0;
}
.badge .icon { width: 1em; height: 1em; }
.badge--muted, .badge--neutral { background: var(--surface-strong); color: var(--text); }
.badge--subtle { background: var(--accent-subtle); color: var(--text); }
.badge--success { background: var(--success-solid); color: var(--on-success); }
.badge--danger { background: var(--danger-solid); color: var(--on-danger); }
.badge--warning { background: var(--warning-solid); color: var(--on-warning); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; max-width: 100%; }
.table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.table th, .table td { text-align: left; padding: var(--space-2) var(--space-3); border: 0; vertical-align: middle; }
.table thead th { font-family: var(--font-heading); font-weight: 600; font-size: var(--text-sm); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; padding-top: var(--space-1); padding-bottom: var(--space-3); }
.table tbody th { font-weight: 600; }
/* Rows are separated by zebra tint, not lines. */
.table tbody tr:nth-child(odd) { background: var(--zebra); }
.table tbody tr:hover { background: var(--surface-hover); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table td form { margin: 0; }
@media (max-width: 40rem) {
  .table { display: block; overflow-x: auto; } /* narrow screens: scroll wide tables */
  /* .table--stack: rows become cards, cells carry data-label */
  .table.table--stack { display: table; overflow: visible; }
  .table--stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .table--stack, .table--stack tbody, .table--stack tr, .table--stack td, .table--stack tbody th { display: block; width: 100%; }
  .table--stack tbody tr { padding: var(--space-3); margin-bottom: var(--space-2); background: var(--zebra); }
  .table--stack tbody tr:nth-child(odd) { background: var(--zebra); }
  .table--stack td, .table--stack tbody th { border: 0; padding: var(--space-1) 0; }
  .table--stack td[data-label]::before { content: attr(data-label); display: block; font-size: var(--text-xs); font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
}

/* ---------- Toolbar, pager ---------- */
/* Filter bars: label above each field, every control's bottom edge on one
   line (buttons align with the fields, not with the labels). */
.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-3); margin: 0 0 var(--space-4); }
.toolbar .field { margin: 0; flex: 1 1 12rem; }
.toolbar .field--grow { flex: 3 1 16rem; }
.toolbar > .btn, .toolbar > .form-actions { flex: none; }
@media (max-width: 40rem) {
  .toolbar > .btn { flex: 1 1 100%; }
}
.pager { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; justify-content: space-between; margin-top: var(--space-4); }

/* ---------- Confirmation dialog (js/confirm.js) ---------- */
.confirm-dialog {
  width: min(30rem, calc(100vw - 2rem)); max-height: calc(100vh - 2rem);
  padding: 0; margin: auto;
  color: var(--text); background: var(--surface-strong);
  border: 0;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
}
.confirm-dialog::backdrop { background: var(--backdrop); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.confirm-dialog__box { display: flex; flex-direction: column; gap: var(--space-4); padding: var(--space-5); margin: 0; }
.confirm-dialog__head { display: flex; align-items: center; gap: var(--space-3); }
.confirm-dialog__icon { display: inline-flex; align-items: center; justify-content: center; width: 2.5rem; height: 2.5rem; flex: none; color: var(--accent-text); background: var(--accent-subtle); }
.confirm-dialog__icon .icon { width: 1.5rem; height: 1.5rem; }
.confirm-dialog__icon--danger { display: none; color: var(--danger); background: var(--danger-bg); }
.confirm-dialog--danger .confirm-dialog__icon--danger { display: inline-flex; }
.confirm-dialog--danger .confirm-dialog__icon--normal { display: none; }
.confirm-dialog__title { margin: 0; font-size: 1.2rem; }
.confirm-dialog__body { margin: 0; color: var(--text); white-space: pre-line; }
.confirm-dialog__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-2); padding-top: var(--space-2); }
@media (max-width: 30rem) {
  .confirm-dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; }
  .confirm-dialog__actions { flex-direction: column-reverse; }
  .confirm-dialog__actions .btn { width: 100%; }
}

/* ---------- Password visibility toggle (js/pwtoggle.js) ---------- */
.pw-field { position: relative; display: block; }
.pw-field > input { padding-right: calc(var(--space-3) + var(--control-h)); }
.pw-toggle {
  position: absolute; top: 0; right: 0;
  width: var(--control-h); height: var(--control-h);
  display: inline-flex; align-items: center; justify-content: center;
  margin: 0; padding: 0; border: 0; background: transparent;
  color: var(--text-muted); cursor: pointer;
}
.pw-toggle:hover { color: var(--text); }
.pw-toggle:focus-visible { outline: 2px solid var(--focus-color); outline-offset: -4px; }
.pw-toggle .icon { width: 1.25rem; height: 1.25rem; }
input::-ms-reveal, input::-ms-clear { display: none; }
/* Auth panel: fields run edge to edge; the eye sits where the text column ends. */
.auth-panel__content .pw-field > input { padding-right: calc(var(--auth-pad) + var(--control-h)); }

/* ---------- Shared auth pieces (login, 2FA, recovery codes) ---------- */
.login-providers { display: flex; flex-direction: column; gap: var(--space-2); margin: 0 0 var(--space-4); }
.login-link { display: inline-block; margin-top: var(--space-2); }
.passkey-form { margin: 0 0 var(--space-3); }
.totp-qr { display: block; width: 14rem; max-width: 100%; height: auto; padding: var(--space-2); background: #ffffff; margin: 0 0 var(--space-3); }
.totp-secret { font-family: var(--font-mono); overflow-wrap: anywhere; user-select: all; background: var(--surface-sunken); padding: 0.1rem var(--space-1); }
.backup-codes { display: grid; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); gap: var(--space-2); list-style: none; padding: 0; margin: 0 0 var(--space-4); }
.backup-codes li, .backup-codes code { font-family: var(--font-mono); font-size: 1.05rem; letter-spacing: 0.04em; }
.backup-codes li { padding: var(--space-2); background: var(--fill); text-align: center; }

/* ---------- Theme switcher (layout/partials/theme.html, js/theme.js) ----------
   A segmented radio group: System / Hell / Dunkel. The radios are visually
   hidden (still focusable, arrow keys move the choice); the labels are the
   segments. App sidebar: at the bottom, icon above label (desktop) or one row
   (mobile, inside the opened menu). Auth/plain layouts: icons only, next to
   the footer links. Selected = accent tint, like the active menu entry. */
.theme-switch { margin: 0; }
.theme-switch__group { margin: 0; }
.theme-switch__legend { font-size: var(--text-xs); font-weight: 600; color: var(--text-muted); margin-bottom: var(--space-2); }
.theme-switch__options { display: flex; gap: 2px; }
.theme-switch__opt {
  position: relative; flex: 1 1 0; min-width: 0;
  display: flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--control-h-sm); padding: var(--space-1) var(--space-2);
  background: var(--btn-fill); color: var(--text-muted);
  font-size: var(--text-sm); font-weight: 500; line-height: 1.2; cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.theme-switch__opt:hover { background: var(--btn-fill-hover); color: var(--text); }
.theme-switch__opt:has(.theme-switch__input:checked) { background: var(--accent-subtle); color: var(--text); font-weight: 600; }
.theme-switch__opt:has(.theme-switch__input:checked) .icon { color: var(--accent-text); }
.theme-switch__opt:has(.theme-switch__input:focus-visible) { outline: 3px solid var(--focus-color); outline-offset: 0; z-index: 1; }
.theme-switch__opt .icon { flex: none; }
.theme-switch__input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.theme-switch__input:focus-visible { outline: none; }
.theme-switch__text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.theme-switch__apply { margin-top: var(--space-2); }

/* App sidebar: pinned to the bottom of the (scrollable) sidebar. */
.app-sidebar { display: flex; flex-direction: column; }
.app-sidebar > * { flex-shrink: 0; }
.app-sidebar > .theme-switch { margin-top: auto; padding: var(--space-5) var(--space-3) 0; }
@media (min-width: 56.01rem) {
  .app-sidebar .theme-switch__opt { flex-direction: column; gap: var(--space-1); min-height: 3.25rem; font-size: var(--text-xs); }
}
@media (max-width: 56rem) {
  .app-sidebar > .theme-switch { margin-top: 0; padding: var(--space-3) 0 var(--space-1); }
  .js .app-sidebar:not(:has(> .app-nav.is-open)) > .theme-switch { display: none; }
}

/* Auth panel / plain card: icons only, at the right end of the footer row. */
.theme-switch--compact { position: absolute; right: var(--ts-right); bottom: var(--ts-bottom); }
.theme-switch--compact .theme-switch__opt { flex: none; width: var(--control-h-sm); padding: 0; }
.theme-switch--compact .theme-switch__text {
  position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap;
}
.theme-switch--compact .theme-switch__apply { position: absolute; right: 0; bottom: 100%; margin: 0 0 var(--space-2); }
.auth-panel, .plain-card { position: relative; }
.auth-panel { --ts-right: var(--auth-pad); --ts-bottom: calc(var(--space-4) - 0.4rem); }
.plain-card { --ts-right: var(--space-6); --ts-bottom: calc(var(--space-6) - 0.4rem); }
:is(.auth-panel, .plain-card) > .site-footer { padding-right: calc(3 * var(--control-h-sm) + 4px + var(--space-3)); }
@media (max-width: 40rem) {
  .plain-card { --ts-right: var(--space-4); --ts-bottom: calc(var(--space-5) - 0.4rem); }
}
/* Narrow auth panel: the dev badge sits bottom right, so the switcher moves
   up next to the logo (vertically centred on it). */
@media (max-width: 48rem) {
  .auth-panel > .theme-switch--compact { bottom: auto; top: calc(var(--space-5) + (11rem * 225 / 846 - var(--control-h-sm)) / 2); }
  .auth-panel > .site-footer { padding-right: 0; }
}

/* Switching crossfades the whole page once (js/theme.js: view transition
   with html.ns-theme-switch): one root snapshot, no named parts, so nothing
   moves and the glass keeps its blur. Reduced motion: no transition at all. */
html.ns-theme-switch :is(.auth-panel, .app-sidebar, .app-topbar, .dev-badge, .photo-credit, .nav-indicator, #app-nav, .app-topbar__title) { view-transition-name: none !important; }
html.ns-theme-switch::view-transition-old(root) { animation: 220ms ease both ns-theme-out; display: block; }
html.ns-theme-switch::view-transition-new(root) { animation: 220ms ease both ns-theme-in; }
@keyframes ns-theme-out { to { opacity: 0; } }
@keyframes ns-theme-in { from { opacity: 0; } }

/* ---------- Footer, error id, dev badge ---------- */
.site-footer { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-6); font-size: var(--text-sm); color: var(--text-muted); }
.site-footer a { color: inherit; }
.error-id { margin-top: var(--space-5); font-size: var(--text-xs); color: var(--text-muted); }
.error-id code { user-select: all; }
.dev-badge {
  position: fixed; right: var(--space-3); bottom: var(--space-3); z-index: 50; margin: 0;
  padding: var(--space-1) var(--space-3); font-size: 0.75rem; font-weight: 700;
  background: var(--warning-solid); color: var(--on-warning); pointer-events: none;
}
.layout-auth .dev-badge { right: auto; left: var(--space-3); bottom: auto; top: var(--space-3); }
@media (max-width: 48rem) {
  .layout-auth .dev-badge { left: auto; right: var(--space-3); top: auto; bottom: var(--space-3); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* Buttons placed straight on the photo (back links outside a card) get an
   opaque surface so their text keeps its contrast. */
.app-content > .btn--ghost, .app-content > p > .btn--ghost, .app-content > nav > .btn--ghost,
.app-content > .btn--secondary, .app-content > p > .btn--secondary, .app-content > nav > .btn--secondary { background: var(--surface-strong); box-shadow: var(--shadow-sm); }
.app-content > .btn--ghost:hover, .app-content > p > .btn--ghost:hover, .app-content > nav > .btn--ghost:hover,
.app-content > .btn--secondary:hover, .app-content > p > .btn--secondary:hover, .app-content > nav > .btn--secondary:hover { background: var(--surface-strong); color: var(--accent-text); }

/* Guard: no borders on anything (user decision). Focus rings are outlines. */
.card, .glass, .table, .btn, .badge, .alert, .empty-state, .confirm-dialog { border: 0; }
