/* main.css - the whole panel stylesheet (error pages use error-debug.css instead).
   1. DESIGN TOKENS   dark default + light theme variables
   2. BASE ELEMENTS   reset and typography
   3. LAYOUT          header, nav, page shell, footer, cookie note, landing page
   4. COMPONENTS      buttons, cards, forms, tables, menus, dialogs
   5. UTILITIES + PRINT (kept last on purpose)
   Where two rules have the same specificity the later one wins, so keep the order. */

/* ==========================================================================
   DESIGN TOKENS
   ========================================================================== */
:root {
  color-scheme: dark;
  --bg: #0f1115;
  --surface: #161a21;
  --surface-raised: #1d222b;
  --surface-high: #252b36;
  --border: #2a303b;
  --border-strong: #3a4351;
  --text: #e6e8ec;
  --muted: #9aa3b2;
  --subtle: #8994a3;
  --accent: #6099ff;
  --accent-hover: #86b3ff;
  --accent-active: #3779ed;
  --accent-soft: color-mix(in srgb, var(--accent) 16%, transparent);
  --focus: #8ab4ff;
  --success: #39c98a;
  --warning: #e7b65a;
  --danger: #f07474;
  --success-soft: color-mix(in srgb, var(--success) 13%, transparent);
  --warning-soft: color-mix(in srgb, var(--warning) 13%, transparent);
  --danger-soft: color-mix(in srgb, var(--danger) 7%, transparent);
  --shadow-1: 0 1px 2px rgb(0 0 0 / 0.18);
  --shadow-2: 0 10px 28px rgb(0 0 0 / 0.24);
  --shadow-3: 0 24px 56px rgb(0 0 0 / 0.32);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --content-width: 1160px;
  --gutter: 16px;
  --font:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --duration: 180ms;
  --accent-ink: #081326;
}
[data-theme='light'] {
  color-scheme: light;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-raised: #f8f9fc;
  --surface-high: #eef1f6;
  --border: #d9dfe8;
  --border-strong: #c1cad8;
  --text: #17202e;
  --muted: #4f5b6d;
  --subtle: #5f6b7d;
  --accent: #175cd3;
  --accent-hover: #124db4;
  --accent-active: #0d419a;
  --accent-soft: color-mix(in srgb, var(--accent) 10%, transparent);
  --focus: #175cd3;
  --success: #147a50;
  --warning: #815600;
  --danger: #b42318;
  --success-soft: #e8f6ef;
  --warning-soft: #fff4d6;
  --danger-soft: #fdecea;
  --shadow-1: 0 1px 2px rgb(20 32 50 / 0.06);
  --shadow-2: 0 10px 28px rgb(20 32 50 / 0.09);
  --shadow-3: 0 24px 56px rgb(20 32 50 / 0.14);
  --accent-ink: #ffffff;
}

/* ==========================================================================
   BASE ELEMENTS
   ========================================================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  min-width: 320px;
  scroll-behavior: smooth;
  scroll-padding-top: 6rem;
}
body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition:
    background-color var(--duration) var(--ease),
    color var(--duration) var(--ease);
}
img,
svg,
video,
canvas {
  max-width: 100%;
}
img {
  height: auto;
}
a {
  color: var(--accent);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
}
a:hover {
  color: var(--accent-hover);
}
button,
input,
select,
textarea {
  font: inherit;
}
button,
[type='button'],
[type='submit'],
[role='button'] {
  cursor: pointer;
}
button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}
::selection {
  background: var(--accent);
  color: #fff;
}
h1,
h2,
h3,
h4,
p {
  margin-top: 0;
}
h1 {
  font-size: clamp(1.7rem, 1.25rem + 1.7vw, 2.5rem);
  line-height: 1.15;
  letter-spacing: -0.035em;
}
h2 {
  font-size: clamp(1.25rem, 1.05rem + 0.8vw, 1.75rem);
  line-height: 1.25;
  letter-spacing: -0.02em;
}
h3 {
  font-size: clamp(1.05rem, 0.98rem + 0.35vw, 1.25rem);
  line-height: 1.3;
}
small,
.small {
  font-size: 0.875rem;
}
code,
kbd,
pre {
  font-family: var(--mono);
}
hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--space-6) 0;
}
[hidden] {
  display: none !important;
}

/* ==========================================================================
   LAYOUT - site header, navigation, page shell, footer, cookie note, back-to-top, landing page
   ========================================================================== */
.site-header {
  position: sticky;
  z-index: 40;
  top: 0;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 82%, transparent);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.site-nav {
  position: relative;
  width: min(100% - var(--gutter) * 2, var(--content-width));
  min-height: 68px;
  margin-inline: auto;
  display: flex;
  align-items: center;
  gap: var(--space-4);
}
.header-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 750;
  letter-spacing: -0.025em;
  white-space: nowrap;
}
.header-brand .icon {
  width: 1.35em;
  height: 1.35em;
  color: var(--accent);
}
.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  min-height: 42px;
  margin-left: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  color: var(--text);
}

/* links (left/centre) and tools (search + theme, right) */
.header-links {
  order: 2;
  display: flex;
  align-items: center;
  gap: 4px;
  list-style: none;
  padding: 0;
  margin: 0 0 0 auto;
}
.header-links a {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 11px;
  color: var(--muted);
  border-radius: var(--radius-sm);
  text-decoration: none;
  white-space: nowrap;
  font-size: 0.925rem;
  transition:
    color var(--duration),
    background var(--duration);
}
.header-links a:hover {
  color: var(--text);
  background: var(--surface-raised);
}
.header-links a[aria-current='page'] {
  position: relative;
  color: var(--text);
  background: var(--surface-raised);
}
.header-links a[aria-current='page']::after {
  content: '';
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 3px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}
.header-links .icon {
  width: 1.05em;
  height: 1.05em;
  vertical-align: 0;
}
.header-links__end {
  margin-left: var(--space-2);
}
.header-tools {
  order: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: var(--space-3);
  margin-left: var(--space-1);
  border-left: 1px solid var(--border);
}
@media (max-width: 820px) {
  .nav-toggle {
    display: inline-flex;
    margin-left: 0;
  }
  .header-links {
    position: absolute;
    z-index: 45;
    left: 16px;
    right: 16px;
    top: calc(100% + 8px);
    order: 0;
    display: none;
    align-items: stretch;
    flex-direction: column;
    max-height: calc(100dvh - 90px);
    overflow-y: auto;
    margin-left: 0;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: var(--shadow-2);
  }
  .header-links.is-open {
    display: flex;
  }
  .header-links a {
    padding: 12px;
  }
  .header-links a[aria-current='page']::after {
    display: none;
  }
  .header-links__end {
    margin-left: 0;
    margin-top: 4px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
  }
  .header-tools {
    order: 0;
    margin-left: auto;
    padding-left: 0;
    border-left: 0;
  }
}
@media (max-width: 440px) {
  .site-nav {
    gap: 8px;
  }
}

/* "Manage" drop-down group (admin links) */
.nav-group {
  position: relative;
}
.nav-group summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 0.925rem;
  white-space: nowrap;
  list-style: none;
  cursor: pointer;
  user-select: none;
  transition:
    color var(--duration),
    background var(--duration);
}
.nav-group summary::-webkit-details-marker {
  display: none;
}
.nav-group summary:hover,
.nav-group details[open] > summary,
.nav-group details.has-current > summary {
  color: var(--text);
  background: var(--surface-raised);
}
.nav-group__caret {
  width: 0.8em !important;
  height: 0.8em !important;
  margin-left: 2px;
  transition: transform var(--duration) var(--ease);
}
.nav-group details[open] .nav-group__caret {
  transform: rotate(180deg);
}
.nav-group__panel {
  position: absolute;
  z-index: 46;
  top: calc(100% + 8px);
  inset-inline-end: 0;
  min-width: 220px;
  margin: 0;
  padding: 6px;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-2);
}
.nav-group__panel a {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 8px 10px;
  border-radius: 7px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.nav-group__panel a:hover,
.nav-group__panel a[aria-current='page'] {
  background: var(--surface-raised);
}
.nav-group__panel a[aria-current='page']::after {
  display: none;
}
@media (max-width: 820px) {
  /* in the mobile sheet the group is an inline section, not a second popup */
  .nav-group summary {
    padding: 12px;
  }
  .nav-group__panel {
    position: static;
    min-width: 0;
    margin-top: 2px;
    padding: 0 0 0 10px;
    border: 0;
    background: transparent;
    box-shadow: none;
  }
}

/* page shell */
.site-main {
  width: min(100% - var(--gutter) * 2, var(--content-width));
  margin: 0 auto;
  flex: 1 0 auto;
  padding-block: clamp(24px, 4vw, 52px);
}
.page-shell,
.page-narrow {
  display: grid;
  gap: var(--space-4);
  align-content: start;
}
.page-shell {
  width: min(100%, var(--content-width));
  margin-inline: auto;
}
.page-narrow {
  max-width: 720px;
  margin-inline: auto;
}
.page-shell--narrow {
  max-width: 760px;
}
.page-shell--wide {
  max-width: 1440px;
}
.page-shell > .card,
.page-shell > .grid,
.page-shell > .page-frame {
  margin: 0;
}
.page-frame {
  display: grid;
  gap: var(--space-4);
}
.page-frame > .grid,
.page-frame > .card[style] {
  margin-top: 0 !important;
}
.page-status:empty,
.page-status:not(:has(*)) {
  display: none;
}
.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 340px);
  gap: var(--space-4);
  align-items: start;
}
@media (max-width: 900px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

/* footer */
.site-footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  margin-top: auto;
}
.site-footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  width: min(100% - var(--gutter) * 2, var(--content-width));
  margin-inline: auto;
  padding: 20px 0 calc(20px + env(safe-area-inset-bottom));
}
.footer-text {
  color: var(--muted);
}
.footer-links {
  display: flex;
  align-items: center;
  gap: 16px;
}
.footer-links a {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  text-decoration: none;
}
.footer-links a:hover,
.footer-links a:focus-visible {
  color: var(--text);
}
.footer-links a .icon {
  width: 1.05em;
  height: 1.05em;
  vertical-align: 0;
}
@media (min-width: 641px) {
  .footer-links {
    margin-inline-end: 56px;
  }
} /* keeps the back-to-top button off the link */
@media (max-width: 520px) {
  .site-footer-inner {
    align-items: flex-start;
    flex-direction: column;
  }
}

/* cookie note + back-to-top */
.cookie-notice {
  position: fixed;
  z-index: 60;
  inset-inline: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: min(680px, calc(100vw - 32px));
  margin-inline: auto;
  padding: 14px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-high);
  box-shadow: var(--shadow-2);
}
.cookie-notice p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}
@media (max-width: 560px) {
  .cookie-notice {
    align-items: flex-start;
    flex-direction: column;
  }
}
#back-to-top {
  position: fixed;
  z-index: 55;
  inset-inline-end: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  border-radius: 50%;
  background: var(--surface-high);
  box-shadow: var(--shadow-2);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition:
    opacity var(--duration) var(--ease),
    transform var(--duration) var(--ease);
}
#back-to-top.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}
.cookie-notice:not([hidden]) ~ #back-to-top {
  bottom: calc(112px + env(safe-area-inset-bottom));
}
@media (min-width: 641px) {
  .cookie-notice:not([hidden]) ~ #back-to-top {
    bottom: calc(84px + env(safe-area-inset-bottom));
  }
}

/* landing page (welcome_message.php) */
.landing-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.landing-header {
  width: min(1120px, calc(100% - 40px));
  margin: 20px auto 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
.landing-header .header-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
}
.landing-header .header-brand img {
  object-fit: contain;
}
.landing-nav {
  display: flex;
  align-items: center;
  gap: 18px;
}
.landing-nav a:not(.button) {
  color: var(--text);
  text-decoration: none;
}
.landing-shell {
  width: min(1120px, calc(100% - 40px));
  margin: auto;
  padding-block: clamp(44px, 9vh, 100px);
}
.landing-hero {
  min-height: 390px;
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(190px, 0.6fr);
  align-items: center;
  overflow: hidden;
}
.landing-copy {
  position: relative;
  z-index: 1;
  padding: clamp(26px, 5vw, 64px);
}
.landing-copy h1 {
  max-width: 12ch;
  margin: 10px 0 16px;
  font-size: clamp(2.5rem, 6vw, 4.4rem);
  line-height: 1.02;
  letter-spacing: -0.045em;
}
.landing-lead {
  max-width: 60ch;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1.7;
}
.landing-note {
  margin-top: 22px;
}
.landing-art {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    color-mix(in srgb, var(--accent) 18%, transparent),
    transparent 68%
  );
}
.landing-art img {
  width: min(72%, 196px);
  height: auto;
  object-fit: contain;
}
.landing-features {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-top: 18px;
}
.landing-features h2 {
  margin-bottom: 8px;
  font-size: 1.05rem;
}
.landing-footer {
  padding: 0 20px 28px;
  color: var(--muted);
  text-align: center;
}
@media (max-width: 700px) {
  .landing-hero {
    grid-template-columns: 1fr;
  }
  .landing-art {
    display: none;
  }
  .landing-features {
    grid-template-columns: 1fr;
  }
  .landing-copy {
    padding: 26px;
  }
}
@media (max-width: 460px) {
  .landing-header {
    width: calc(100% - 28px);
  }
  .landing-nav {
    gap: 10px;
  }
  .landing-nav .button {
    font-size: 0.82rem;
  }
  .landing-nav a:not(.button) {
    display: none;
  }
  .landing-shell {
    width: calc(100% - 28px);
  }
}

/* ==========================================================================
   Basics: icons, skip link, screen-reader text
   ========================================================================== */
.icon {
  width: 1em;
  height: 1em;
  fill: currentColor;
  vertical-align: -0.13em;
  flex: 0 0 auto;
}
.skip-link {
  position: fixed;
  z-index: 200;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  transform: translateY(-160%);
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
}
.skip-link:focus {
  transform: none;
}
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
.eyebrow {
  margin: 0;
  color: var(--accent-hover);
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

/* ==========================================================================
   Buttons  (.button is current; .btn is the older name, still used in a few views)
   Base styles use :where() (zero specificity) so every variant below can override them.
   ========================================================================== */
:where(.btn, .button) {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 15px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  text-align: center;
  text-decoration: none;
}
:where(.btn) {
  transition:
    background var(--duration),
    border-color var(--duration),
    color var(--duration),
    transform var(--duration);
}
:where(.button) {
  transition:
    background var(--duration) var(--ease),
    border-color var(--duration) var(--ease),
    transform var(--duration) var(--ease);
}
/* base.css `button { font: inherit }` and `a { color }` out-rank the :where() rules, so restate these: */
.btn,
.button {
  color: var(--text);
  font-weight: 620;
  line-height: 1.25;
}
.btn:hover,
.button:hover {
  color: var(--text);
  background: var(--surface-high);
}
.btn:active,
.button:active {
  transform: translateY(1px);
}
.button:focus-visible,
.btn:focus-visible {
  outline-offset: 2px;
}
.btn-primary,
.button--primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink) !important;
}
.btn-primary:hover,
.button--primary:hover {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
  color: var(--accent-ink) !important;
}
.button--secondary {
  background: transparent;
  color: var(--text);
}
.button--secondary:hover {
  background: var(--surface-raised);
}
.button--danger {
  border-color: color-mix(in srgb, var(--danger) 52%, var(--border));
  background: var(--danger-soft);
  color: var(--danger);
}
.button--danger:hover {
  background: color-mix(in srgb, var(--danger) 16%, transparent);
  color: var(--danger);
}
.btn-sm,
.button--small {
  min-height: 36px;
  padding: 6px 10px;
  font-size: 0.875rem;
}
.button--block,
.button--full {
  width: 100%;
}
/* icon-only buttons are true squares, so the icon sits dead centre */
.button--icon,
#back-to-top {
  width: 42px;
  height: 42px;
  min-height: 0;
  padding: 0;
  flex: 0 0 auto;
}
.button--icon .icon,
#back-to-top .icon {
  width: 1.15rem;
  height: 1.15rem;
  vertical-align: 0;
}
.action-group,
.auth-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.action-group--compact {
  gap: 6px;
}
.actions,
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* ==========================================================================
   Badges and alerts
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-raised);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 620;
  white-space: nowrap;
}
.badge-success {
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 30%, var(--border));
  background: var(--success-soft);
}
.badge-warning {
  color: var(--warning);
  border-color: color-mix(in srgb, var(--warning) 30%, var(--border));
  background: var(--warning-soft);
}
.badge-danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 30%, var(--border));
  background: var(--danger-soft);
}
.alert,
.msgStatus {
  margin-block: 0 16px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  color: var(--text);
  line-height: 1.5;
}
.alert > p {
  margin-block: 0 6px;
}
.alert > :last-child {
  margin-bottom: 0;
}
.alert-success,
.alert--success {
  border-color: color-mix(in srgb, var(--success) 45%, var(--border));
  background: var(--success-soft);
}
.alert-warning {
  border-color: color-mix(in srgb, var(--warning) 45%, var(--border));
  background: var(--warning-soft);
}
.alert-danger {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
  background: var(--danger-soft);
}
.page-status .alert,
.page-status .msgStatus {
  margin-bottom: 16px;
}
.page-shell > .alert,
.page-shell > .msgStatus,
.page-frame > .alert,
.page-status .alert {
  margin: 0;
}
.is-dismissing {
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition:
    opacity 240ms ease,
    transform 240ms ease;
}

/* ==========================================================================
   Cards and card headers
   ========================================================================== */
.card,
.panel,
.auth-card,
.settings-card,
.surface-card {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-1);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  font-weight: 650;
}
.card-body {
  padding: clamp(16px, 2.5vw, 24px);
}
.card .card-header h1,
.card .card-header h2 {
  margin: 0;
  font-size: clamp(1.15rem, 1rem + 0.6vw, 1.5rem);
}
.card__header,
.card__body {
  padding: clamp(16px, 2.5vw, 24px);
}
.card__header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 6px;
  border-bottom: 1px solid var(--border);
}
.card__header--split {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}
.card__header > div:not(.action-group),
.card__heading {
  min-width: 0;
  display: grid;
  gap: 4px;
}
.card__header--split > .action-group {
  flex: 0 0 auto;
}
.card__title {
  margin: 0;
  font-size: clamp(1.25rem, 1.05rem + 0.8vw, 1.8rem);
}
.card__header p {
  margin-bottom: 0;
}
.card__header .card__title + p {
  margin-top: 2px;
}
.card > .card-body,
.card > .card__body {
  min-width: 0;
}
.card > .card__header:last-child {
  border-bottom: 0;
} /* title-only cards must not draw a second line */
.stack {
  display: grid;
  gap: var(--space-4);
}
.grid {
  display: grid;
  gap: var(--space-4);
}
.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.stat-card {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}
.stat-value {
  font-size: clamp(1.5rem, 1.1rem + 1.2vw, 2rem);
  font-weight: 750;
  letter-spacing: -0.04em;
}
.stat-label,
.text-muted {
  color: var(--muted);
}
.detail-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.detail-list > li,
.detail-list__item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
}
.detail-list dt,
.detail-list dd {
  margin: 0;
}
.detail-list dt {
  color: var(--muted);
}
.detail-list dd,
.detail-list > li > strong {
  font-weight: 620;
  text-align: right;
  overflow-wrap: anywhere;
}
.surface-card__header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.surface-card__title {
  margin: 0;
  font-size: clamp(1.25rem, 1.05rem + 0.8vw, 1.8rem);
}
.surface-card__body {
  padding: clamp(16px, 2.5vw, 24px);
}
.surface-card__body form {
  display: grid;
  gap: 14px;
}
.surface-card__body .form-field {
  margin: 0;
}
.server-page {
  display: grid;
  gap: var(--space-4);
}

/* ==========================================================================
   Forms
   ========================================================================== */
.form-stack {
  display: grid;
  gap: 14px;
}
.form-group,
.form-field {
  display: grid;
  gap: 7px;
  margin-bottom: 16px;
}
.form-field {
  min-width: 0;
}
.form-field--actions {
  margin-top: 8px;
}
/* inside a .form-stack the grid gap does the spacing, so fields carry no margin of their own */
.form-stack > .form-field,
.form-stack > .form-check {
  margin: 0;
}
.form-stack > .form-field--actions {
  margin-top: var(--space-2);
}
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-2);
}
label,
.form-label {
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
}
.form-field > label,
.form-field > .form-label {
  line-height: 1.3;
}
.form-field small,
.form-error {
  font-size: 0.85rem;
  line-height: 1.4;
}
.form-error {
  color: var(--danger);
}
input:not([type='checkbox']):not([type='radio']):not([type='submit']),
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
}
.form-control {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
}
textarea {
  min-height: 120px;
  resize: vertical;
}
textarea.server-textarea {
  min-height: 96px;
}
input::placeholder,
textarea::placeholder {
  color: var(--subtle);
}
input:focus,
select:focus,
textarea:focus {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  box-shadow: none;
}
/* selects get a drawn chevron so they match the text inputs */
select,
select.form-control,
select.form-select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%239aa3b2'%3E%3Cpath d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  background-size: 13px;
}
input[type='file']::file-selector-button {
  margin-right: 12px;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface-raised);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
input[type='checkbox'],
input[type='radio'] {
  accent-color: var(--accent);
  width: 18px;
  height: 18px;
  vertical-align: middle;
}
.form-check {
  display: inline-flex;
  align-items: center;
  align-self: start;
  gap: 9px;
  min-height: 24px;
  cursor: pointer;
}
.form-check input {
  margin: 0;
}
.form-check__input {
  flex: 0 0 auto;
}
.form-check__label,
.form-check > label {
  line-height: 1.3;
}
.form-check__label {
  color: var(--muted);
}
/* input + button on one line, same height */
.form-control-group {
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: var(--space-2);
}
.form-control-group > .form-control {
  flex: 1 1 auto;
  min-width: 0;
}
.form-control-group > .button {
  flex: 0 0 auto;
  min-height: 44px;
  padding-inline: 14px;
}
/* toggle switch (Server settings) */
.switch-control {
  position: relative;
  display: inline-flex;
  flex: 0 0 auto;
  width: 46px;
  height: 26px;
}
.switch-control > input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.switch-track {
  width: 100%;
  height: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface-high);
  transition:
    background var(--duration) var(--ease),
    border-color var(--duration) var(--ease);
}
.switch-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--muted);
  transition:
    transform var(--duration) var(--ease),
    background var(--duration) var(--ease);
}
.switch-control > input:checked + .switch-track {
  border-color: var(--accent);
  background: var(--accent);
}
.switch-control > input:checked + .switch-track::after {
  transform: translateX(20px);
  background: var(--accent-ink);
}
.switch-control > input:focus-visible + .switch-track {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}
label.form-field > .d-flex {
  min-height: 32px;
  cursor: pointer;
}
/* file drop zone (Online LIB) - sits after .stat-card, which it also carries */
.upload-dropzone {
  position: relative;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 6px;
  min-height: 140px;
  padding: 24px 20px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  transition:
    border-color var(--duration),
    background var(--duration);
}
.upload-dropzone:hover,
.upload-dropzone:focus-within,
[data-file-drop].is-dragging .upload-dropzone {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}
.upload-dropzone:focus-within {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.upload-dropzone__icon {
  width: 1.9rem;
  height: 1.9rem;
  color: var(--accent);
  vertical-align: 0;
}
.upload-dropzone__title {
  color: var(--text);
  font-weight: 650;
  overflow-wrap: anywhere;
}
.upload-dropzone__hint {
  font-size: 0.85rem;
}
@media (hover: none) {
  .upload-dropzone__hint {
    display: none;
  }
} /* no drag and drop on touch screens */
[data-file-drop].is-dragging {
  outline: 2px dashed var(--accent);
  outline-offset: 4px;
  background: var(--accent-soft);
}

/* ==========================================================================
   Tables
   ========================================================================== */
.table-wrap,
.table-responsive,
.list-table-wrapper,
.dash-table-wrapper {
  width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.table-wrap,
.table-responsive {
  background: var(--bg);
}
table {
  width: 100%;
  border-collapse: collapse;
  color: var(--text);
  font-size: 0.92rem;
}
th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
th {
  color: var(--muted);
  background: var(--surface-raised);
  font-size: 0.82rem;
  font-weight: 650;
  letter-spacing: 0.025em;
}
tbody tr:hover {
  background: color-mix(in srgb, var(--surface-raised) 75%, transparent);
}
tbody tr:last-child td {
  border-bottom: 0;
}
.data-table th,
.data-table td,
.table th,
.table td {
  white-space: nowrap;
}
.table .action-group,
.data-table .action-group {
  flex-wrap: nowrap;
} /* row actions stay on one line; the table scrolls instead */
th[aria-sort] {
  cursor: pointer;
  user-select: none;
}
th[aria-sort='ascending']::after {
  content: ' ↑';
  color: var(--accent);
}
th[aria-sort='descending']::after {
  content: ' ↓';
  color: var(--accent);
}
.table-controls {
  justify-content: flex-start;
  flex-wrap: nowrap;
  padding: 12px 0;
}
.table-controls input {
  flex: 1 1 auto;
  width: min(100%, 340px) !important;
}
.table-size {
  flex: 0 0 auto;
  width: auto !important;
  min-width: 84px;
} /* page-size select next to the search box */
.table-pagination {
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding-top: 12px;
  color: var(--muted);
  text-align: center;
}
.empty-state {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: clamp(32px, 7vw, 72px) 18px;
  color: var(--muted);
  text-align: center;
}
td > .empty-state {
  padding-block: 24px;
}
.empty-state > strong,
.empty-state__title {
  color: var(--text);
}
.empty-state__title {
  font-weight: 650;
}
.empty-state__description {
  margin-top: 2px;
  font-size: 0.9rem;
}
.table-empty {
  padding: clamp(28px, 6vw, 56px) 16px !important;
  text-align: center !important;
  color: var(--muted);
}
.table-empty > span {
  display: block;
}

/* ==========================================================================
   Menus, dialogs, toasts, search
   ========================================================================== */
.menu {
  position: relative;
}
.menu summary {
  list-style: none;
  cursor: pointer;
}
.menu summary::-webkit-details-marker {
  display: none;
}
.menu summary.button::after {
  content: '';
  width: 0.5em;
  height: 0.5em;
  margin-left: 4px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-0.1em) rotate(45deg);
  transition: transform var(--duration) var(--ease);
}
.menu[open] summary.button::after {
  transform: translateY(0.1em) rotate(-135deg);
}
.menu__panel {
  position: absolute;
  z-index: 30;
  top: calc(100% + 8px);
  right: 0;
  left: auto;
  display: grid;
  min-width: 220px;
  max-width: calc(100vw - 32px);
  padding: 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-2);
}
.menu__item {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 9px 11px;
  border-radius: 7px;
  color: var(--text);
  text-decoration: none;
}
.menu__item:hover {
  background: var(--surface-raised);
}
dialog {
  max-width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-3);
}
dialog::backdrop {
  background: rgb(4 8 15 / 0.68);
  backdrop-filter: blur(3px);
}
.toast-region {
  position: fixed;
  z-index: 100;
  top: 16px;
  inset-inline-end: 16px;
  display: grid;
  gap: 8px;
  width: min(380px, calc(100vw - 32px));
}
.toast {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-high);
  box-shadow: var(--shadow-2);
}
.search-panel {
  position: fixed;
  z-index: 80;
  inset: 12vh 16px auto;
  width: min(640px, calc(100vw - 32px));
  margin-inline: auto;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-3);
}
.search-panel form {
  display: grid;
  gap: 12px;
}
.search-panel .actions {
  justify-content: space-between;
  align-items: center;
}
.search-results {
  display: grid;
  gap: 5px;
  max-height: min(45vh, 360px);
  overflow: auto;
  padding-block: 12px;
}
.dropdown-menu-link {
  display: block;
  padding: 10px 12px;
  border-radius: 7px;
  color: var(--text);
  text-decoration: none;
}
.dropdown-menu-link:hover,
.dropdown-menu-link:focus-visible {
  background: var(--surface-raised);
}
kbd {
  padding: 2px 6px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface-raised);
  color: var(--muted);
  font-size: 0.82em;
}

/* ==========================================================================
   Auth pages, offline page
   ========================================================================== */
.auth-page {
  align-content: center;
  padding-top: clamp(20px, 5vw, 64px);
}
.auth-card {
  max-width: 560px;
  margin-inline: auto;
}
.auth-card__header {
  align-items: center;
  text-align: center;
}
.auth-card__header .card__title {
  font-size: clamp(1.6rem, 1.2rem + 1.4vw, 2.1rem);
}
.auth-links {
  margin-top: var(--space-3);
}
.auth-links__item {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
  text-decoration: none;
}
.auth-links__item:hover {
  color: var(--text);
  background: var(--surface-raised);
}
.auth-register-link {
  margin-top: var(--space-3);
}
.offline-page {
  padding-top: 12vh;
  text-align: center;
}
.offline-page img {
  margin: 0 auto 18px;
}

/* ==========================================================================
   Narrow screens
   ========================================================================== */
@media (max-width: 640px) {
  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }
  .card-header {
    padding: 15px 16px;
  }
  .table-wrap,
  .table-responsive,
  .list-table-wrapper,
  .dash-table-wrapper {
    border-radius: var(--radius-sm);
  }
  .card__header--split {
    align-items: flex-start;
    flex-direction: column;
  }
  .action-group {
    align-items: stretch;
  }
  .action-group > .button {
    flex: 1;
  }
  .auth-links {
    flex-direction: column;
  }
}

/* ==========================================================================
   Utilities
   ========================================================================== */
.text-green {
  color: var(--success);
  font-weight: 650;
}
.text-red {
  color: var(--danger);
  font-weight: 650;
}
.text-danger {
  color: var(--danger);
}
.d-flex {
  display: flex;
}
.align-center {
  align-items: center;
}
.justify-between {
  justify-content: space-between;
}
.mt-4 {
  margin-top: 16px;
}
.mb-0 {
  margin-bottom: 0;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 1ms !important;
    animation-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}

/* ==========================================================================
   Print
   ========================================================================== */
@media print {
  :root,
  [data-theme='light'] {
    color-scheme: light;
    --bg: #fff;
    --surface: #fff;
    --surface-raised: #fff;
    --text: #000;
    --muted: #333;
    --border: #aaa;
  }
  body {
    background: #fff !important;
    color: #000 !important;
    font-size: 10pt;
  }
  .site-header,
  .site-footer,
  nav,
  button,
  .btn,
  .toolbar,
  #back-to-top,
  .toast-region {
    display: none !important;
  }
  .site-main {
    width: 100%;
    max-width: none;
    padding: 0;
  }
  a {
    color: #000;
    text-decoration: underline;
  }
  a[href^='http']::after {
    content: ' (' attr(href) ')';
    font-size: 8pt;
    overflow-wrap: anywhere;
  }
  tr,
  img,
  .card,
  .panel {
    break-inside: avoid;
  }
  table {
    border-collapse: collapse;
  }
  th,
  td {
    border: 1px solid #999;
  }
}
