/* MojoPay PMO — design system (DESIGN §9.2).
   Tokens first, then base elements, layout, components and utilities; responsive and print
   rules last. Feature styles live in css/features/<app>.css and must reuse these classes. */

/* ---------------------------------------------------------------------------------------
   Font: Inter (variable, SIL Open Font License 1.1), self-hosted from static/vendor/fonts.
   The optical-size axis gives text sizes open spacing and headings tighter display forms.
   ------------------------------------------------------------------------------------- */
@font-face {
  font-family: "Inter Variable";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("../vendor/fonts/inter-latin-opsz-normal.woff2") format("woff2-variations"),
    url("../vendor/fonts/inter-latin-opsz-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308,
    U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Inter Variable";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("../vendor/fonts/inter-latin-ext-opsz-normal.woff2") format("woff2-variations"),
    url("../vendor/fonts/inter-latin-ext-opsz-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F,
    U+A720-A7FF;
}

@font-face {
  font-family: "Inter Variable";
  font-style: italic;
  font-display: swap;
  font-weight: 100 900;
  src: url("../vendor/fonts/inter-latin-wght-italic.woff2") format("woff2-variations"),
    url("../vendor/fonts/inter-latin-wght-italic.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308,
    U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------------------------------------------------------------------------------------
   Tokens
   ------------------------------------------------------------------------------------- */
:root {
  color-scheme: light;
  --font-sans: "Inter Variable", "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    "Noto Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  /* Type scale: 14px body, a calm step to page titles. */
  --fs-xs: 11.5px;
  --fs-sm: 13px;
  --fs-base: 14px;
  --fs-md: 15px;
  --fs-lg: 17px;
  --fs-xl: 20px;
  --fs-2xl: 25px;
  --lh: 1.5;
  --lh-tight: 1.25;
  /* Weight scale for Inter (variable): 550 sits between medium and semibold for labels and leads. */
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-strong: 550;
  --fw-semibold: 600;
  --fw-bold: 650;
  --fw-heavy: 700;
  --tracking-tight: -0.018em;
  --tracking-caps: 0.06em;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-7: 32px;
  --sp-8: 48px;

  /* Two radii carry the system: 8px for controls, 12px for surfaces. */
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-pill: 999px;

  /* Calm neutrals with a faint blue cast, so the accent sits naturally among them. */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --surface-hover: #f3f5f8;
  --surface-sunken: #eef1f5;
  --border: #e3e7ed;
  --border-strong: #cfd5de;
  --text: #111827;
  --text-muted: #4b5565;
  --text-subtle: #667085;
  --link: #2150c0;

  /* One confident accent, derived from the original MojoPay PMO blue (#2451b8). */
  --accent: #2150c0;
  --accent-hover: #1b44a6;
  --accent-active: #163a8f;
  --accent-soft: #edf2fd;
  --accent-soft-border: #cad8f6;
  --accent-contrast: #ffffff;

  --good: #137547;
  --good-soft: #e7f5ed;
  --warn: #965800;
  --warn-soft: #fdf2df;
  --bad: #b42318;
  --bad-soft: #fdedeb;
  --info: #1d5ca6;
  --info-soft: #e8f1fb;
  --live: #0d6c64;
  --live-soft: #e2f4f1;
  --muted: #5b6474;
  --muted-soft: #eef0f3;
  /* Text on solid --bad / --warn fills (buttons, badges). */
  --on-bad: #ffffff;
  --on-warn: #ffffff;
  /* Progress track: visible on cards and at least 3:1 against the bar. */
  --track: #d5dae2;

  /* Focus: a soft halo for fields (their border turns accent too) and a crisp two-ring
     indicator for buttons and other controls that have no border of their own. */
  --focus: 0 0 0 3px color-mix(in srgb, var(--accent) 24%, transparent);
  --focus-ring: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent);

  /* Elevation, used sparingly: cards rest on xs/sm, menus and dialogs float on md/lg. */
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 12px 28px -6px rgba(16, 24, 40, 0.14), 0 4px 10px -4px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 24px 48px -12px rgba(16, 24, 40, 0.22), 0 8px 16px -8px rgba(16, 24, 40, 0.1);
  --shadow-btn: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-btn-primary: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 1px 2px rgba(16, 24, 40, 0.16);

  /* Select chevron, drawn in --text-muted (a data URI cannot read custom properties). */
  --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='%234b5565' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4.5 6.5 8 10l3.5-3.5'/%3E%3C/svg%3E");

  --ease: cubic-bezier(0.2, 0, 0, 1);
  --dur-fast: 120ms;
  --dur: 180ms;

  --sidebar-bg: #fbfcfd;
  --sidebar-w: 240px;
  --topbar-h: 56px;
  --bottombar-h: 62px;
  --page-max: 1560px;
  --gutter: var(--sp-6);
}

@media screen and (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0b0e13;
    --surface: #12161c;
    --surface-2: #161b22;
    --surface-hover: #1b2129;
    --surface-sunken: #0e1217;
    --border: #232a33;
    --border-strong: #343d49;
    --text: #e7eaef;
    --text-muted: #a7b0bd;
    --text-subtle: #8c96a5;
    --link: #93b4f7;

    --accent: #7099f2;
    --accent-hover: #86a8f4;
    --accent-active: #5d89ec;
    --accent-soft: #172442;
    --accent-soft-border: #2b3f6c;
    --accent-contrast: #070d1c;

    --good: #52c690;
    --good-soft: #10271d;
    --warn: #e7ab52;
    --warn-soft: #2a2113;
    --bad: #f38a7e;
    --bad-soft: #311a18;
    --info: #79aeef;
    --info-soft: #13233a;
    --live: #47c8b7;
    --live-soft: #0f2826;
    --muted: #9ea7b3;
    --muted-soft: #1d232b;
    --on-bad: #1a0b09;
    --on-warn: #1f1405;
    --track: #313a46;

    --focus: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent);
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.32), 0 1px 3px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 12px 28px -6px rgba(0, 0, 0, 0.6), 0 4px 10px -4px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, 0.7), 0 8px 16px -8px rgba(0, 0, 0, 0.5);
    --shadow-btn: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-btn-primary: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 1px 2px rgba(0, 0, 0, 0.4);
    --sidebar-bg: #0f1318;
    --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='%23a7b0bd' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4.5 6.5 8 10l3.5-3.5'/%3E%3C/svg%3E");
  }
}

/* ---------------------------------------------------------------------------------------
   Base
   ------------------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Numbers line up wherever they are compared: tables, KPIs, counts, dates and meters. */
.table,
.kpi-value,
.badge,
.nav-badge,
.bottom-badge,
.progress-value,
.timeline-date,
.num,
time {
  font-variant-numeric: tabular-nums;
}

h1,
h2,
h3,
h4 {
  margin: 0 0 var(--sp-2);
  line-height: var(--lh-tight);
  font-weight: var(--fw-bold);
  letter-spacing: -0.01em;
}

h1 {
  font-size: var(--fs-2xl);
}

h2 {
  font-size: var(--fs-lg);
}

h3 {
  font-size: var(--fs-md);
}

h4 {
  font-size: var(--fs-base);
}

p {
  margin: 0 0 var(--sp-3);
}

p:last-child {
  margin-bottom: 0;
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
  text-decoration-thickness: from-font;
  text-underline-offset: 3px;
}

img,
svg {
  vertical-align: middle;
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--sp-5) 0;
}

code,
kbd,
pre,
samp {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

code {
  background: var(--surface-sunken);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
}

pre {
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-3);
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

blockquote {
  margin: 0;
  padding: var(--sp-2) var(--sp-3);
  border-left: 3px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-muted);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

dl {
  margin: 0;
}

::selection {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}

:focus {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Subtle, consistent motion on interactive surfaces (switched off for reduced motion below). */
a,
button,
summary,
.btn,
.chip,
.tab,
.nav-link,
.menu-item,
.icon-btn,
.kpi,
.bottom-link {
  transition-property: color, background-color, border-color, box-shadow, opacity, transform;
  transition-duration: var(--dur-fast);
  transition-timing-function: var(--ease);
}

[hidden] {
  display: none !important;
}

.icon {
  flex: none;
  width: 18px;
  height: 18px;
}

/* ---------------------------------------------------------------------------------------
   App shell: sidebar, top bar, main column, bottom bar
   ------------------------------------------------------------------------------------- */
.skip-link {
  position: absolute;
  top: -100px;
  left: var(--sp-3);
  z-index: 100;
  padding: var(--sp-2) var(--sp-3);
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: var(--radius);
  font-weight: var(--fw-semibold);
}

.skip-link:focus {
  top: var(--sp-3);
}

/* The classification label printed at the top of every page (the sidebar that shows it on
   screen is not printed). */
.print-classification {
  display: none;
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  /* Paints the sidebar column full height even when the page outgrows the viewport. */
  background: linear-gradient(
    to right,
    var(--sidebar-bg) calc(var(--sidebar-w) - 1px),
    var(--border) calc(var(--sidebar-w) - 1px),
    var(--border) var(--sidebar-w),
    transparent var(--sidebar-w)
  );
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
  z-index: 40;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  height: var(--topbar-h);
  padding: 0 var(--sp-4) 0 var(--sp-5);
  border-bottom: 1px solid var(--border);
  flex: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--text);
  min-width: 0;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: var(--radius);
  background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 82%, #fff), var(--accent) 60%);
  color: var(--accent-contrast);
  font-weight: var(--fw-heavy);
  font-size: 15px;
  letter-spacing: -0.02em;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, #000 8%, transparent), var(--shadow-xs);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}

.brand-org {
  font-weight: var(--fw-bold);
  font-size: var(--fs-md);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-app {
  color: var(--text-subtle);
  font-size: 10.5px;
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
}

.sidebar-nav {
  flex: 1;
  padding: var(--sp-3) var(--sp-3);
}

.nav-group + .nav-group {
  margin-top: var(--sp-5);
}

/* Section labels stay quiet so the links carry the eye. */
.nav-heading {
  margin: 0 0 6px;
  padding: 0 10px;
  color: var(--text-subtle);
  font-size: 10.5px;
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1px;
}

.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  padding: 6px 10px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-weight: var(--fw-medium);
}

.nav-link .icon {
  color: var(--text-subtle);
}

.nav-link:hover {
  background: var(--surface-hover);
  color: var(--text);
  text-decoration: none;
}

.nav-link:hover .icon {
  color: var(--text-muted);
}

.nav-link.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: var(--fw-semibold);
}

/* A short bar on the left edge marks the current page without shouting. */
.nav-link.is-active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

.nav-link.is-active .icon {
  color: var(--accent);
}

.nav-link:focus-visible {
  outline: 2px solid transparent;
  outline-offset: -2px;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.nav-label {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-badge {
  min-width: 20px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: var(--fw-bold);
  line-height: 18px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  background: var(--info-soft);
  color: var(--info);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 16%, transparent);
}

.nav-badge-warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.nav-badge-bad {
  background: var(--bad-soft);
  color: var(--bad);
}

.sidebar-footer {
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--border);
  color: var(--text-subtle);
  font-size: var(--fs-xs);
  letter-spacing: 0.01em;
  flex: none;
}

.drawer-backdrop {
  display: none;
}

.main-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  height: var(--topbar-h);
  padding: 0 var(--gutter);
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  -webkit-backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  flex: 0 1 auto;
  min-width: 0;
  font-weight: var(--fw-semibold);
  font-size: var(--fs-md);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 360px;
  max-width: 520px;
  margin-left: auto;
}

.topbar-search .icon {
  position: absolute;
  left: 10px;
  color: var(--text-subtle);
  pointer-events: none;
}

.topbar-search input[type="search"] {
  width: 100%;
  padding-left: 34px;
  padding-right: 34px;
  background: var(--surface-2);
  border-color: var(--border);
  box-shadow: none;
}

.topbar-search input[type="search"]:hover {
  background: var(--surface);
  border-color: var(--border-strong);
}

.topbar-search input[type="search"]:focus {
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: var(--focus);
}

.topbar-search .kbd {
  position: absolute;
  right: 8px;
}

.topbar-capture {
  flex: none;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.icon-btn:focus-visible {
  outline: 2px solid transparent;
  outline-offset: 2px;
  box-shadow: var(--focus-ring);
}

/* Drawer controls exist only in the narrow layout (see the 900px breakpoint). */
.icon-btn.sidebar-close,
.icon-btn.menu-btn {
  display: none;
}

/* User menu (a <details> dropdown; works without JavaScript) */
.user-menu {
  position: relative;
  flex: none;
}

.user-menu-toggle {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  height: 36px;
  padding: 0 var(--sp-2) 0 4px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  list-style: none;
  color: var(--text-muted);
}

.user-menu-toggle::-webkit-details-marker {
  display: none;
}

.user-menu-toggle:hover,
.user-menu[open] .user-menu-toggle {
  background: var(--surface-hover);
  color: var(--text);
}

.avatar {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: var(--fw-bold);
  font-size: var(--fs-sm);
  box-shadow: inset 0 0 0 1px var(--accent-soft-border);
}

.user-menu-name {
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: var(--fw-medium);
}

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 50;
  min-width: 240px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  transform-origin: top right;
  animation: menu-in var(--dur) var(--ease);
}

@keyframes menu-in {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }
}

.menu-header {
  margin: 0 -6px 6px;
  padding: 6px var(--sp-4) 10px;
  border-bottom: 1px solid var(--border);
}

.menu-form {
  margin: 0;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.menu-item .icon {
  color: var(--text-subtle);
}

.menu-item:hover {
  background: var(--surface-hover);
  text-decoration: none;
}

.menu-item:hover .icon {
  color: var(--text-muted);
}

.demo-banner {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 9px var(--gutter);
  background: var(--warn-soft);
  color: var(--warn);
  border-bottom: 1px solid color-mix(in srgb, var(--warn) 22%, transparent);
  font-size: var(--fs-sm);
}

.demo-banner .icon {
  width: 16px;
  height: 16px;
}

.demo-banner code {
  background: color-mix(in srgb, var(--warn) 12%, transparent);
}

.page {
  width: 100%;
  max-width: var(--page-max);
  padding: var(--sp-7) var(--gutter) var(--sp-8);
  flex: 1;
}

.page:focus {
  outline: none;
}

.bottom-bar {
  display: none;
}

.kbd {
  display: inline-block;
  min-width: 20px;
  padding: 0 5px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface);
  box-shadow: inset 0 -1px 0 var(--border-strong);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: var(--fw-medium);
  line-height: 18px;
  text-align: center;
}

/* ---------------------------------------------------------------------------------------
   Page structure
   ------------------------------------------------------------------------------------- */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
  margin-bottom: var(--sp-6);
}

.page-heading {
  min-width: 0;
}

/* App headings only: report documents keep their own type (templates/reports/render). */
.page-header h1 {
  margin: 0;
  font-weight: var(--fw-bold);
  letter-spacing: var(--tracking-tight);
  overflow-wrap: anywhere;
}

.page-subtitle {
  margin: 6px 0 0;
  max-width: 72ch;
  color: var(--text-muted);
  font-size: var(--fs-md);
  line-height: 1.45;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.breadcrumbs ol {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 6px;
  padding: 0;
  list-style: none;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.breadcrumbs li + li::before {
  content: "/";
  margin-right: 6px;
  color: var(--border-strong);
}

.breadcrumbs a {
  color: var(--text-muted);
}

.breadcrumbs a:hover {
  color: var(--text);
}

.section-title {
  margin: var(--sp-7) 0 var(--sp-3);
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
  letter-spacing: -0.01em;
}

.section-title:first-child {
  margin-top: 0;
}

.grid {
  display: grid;
  gap: var(--sp-4);
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

/* Vertical rhythm between stacked blocks (zero specificity, so grids can reset it). */
:where(.grid, .card, .table-wrap, .list, .empty-state) + :where(.grid, .card, .table-wrap, .empty-state) {
  margin-top: var(--sp-4);
}

.grid > * {
  margin-top: 0;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.stack > * {
  margin: 0;
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
}

.split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: var(--sp-4) 0;
  border: 0;
}

/* ---------------------------------------------------------------------------------------
   Cards
   ------------------------------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  min-height: 52px;
  padding: var(--sp-3) var(--sp-5);
  border-bottom: 1px solid var(--border);
}

.card-title {
  margin: 0;
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  letter-spacing: -0.01em;
}

.card-body {
  padding: var(--sp-5);
}

.card-footer {
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.card--flush .card-body {
  padding: 0;
}

.card--flush .table-wrap {
  border: 0;
  border-radius: 0;
}

.card > .table-wrap:last-child,
.card > .list:last-child {
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ---------------------------------------------------------------------------------------
   KPIs
   ------------------------------------------------------------------------------------- */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}

.kpi {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px var(--sp-4) 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  color: var(--text);
  overflow: hidden;
}

a.kpi:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
}

a.kpi:focus-visible {
  outline: 2px solid transparent;
  outline-offset: 2px;
  box-shadow: var(--focus-ring);
}

/* The tone shows as a slim inset bar, so the number stays the hero. */
.kpi::before {
  content: "";
  position: absolute;
  left: 0;
  top: 14px;
  bottom: 14px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: transparent;
}

.kpi-value {
  font-size: 28px;
  font-weight: var(--fw-bold);
  line-height: 1.15;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
}

.kpi-label {
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
}

.kpi-sub {
  color: var(--text-subtle);
  font-size: var(--fs-xs);
}

.kpi.tone-good::before {
  background: var(--good);
}

.kpi.tone-warn::before {
  background: var(--warn);
}

.kpi.tone-bad::before {
  background: var(--bad);
}

.kpi.tone-info::before {
  background: var(--info);
}

.kpi.tone-live::before {
  background: var(--live);
}

.kpi.tone-muted::before {
  background: var(--border-strong);
}

.kpi.tone-good .kpi-value {
  color: var(--good);
}

.kpi.tone-warn .kpi-value {
  color: var(--warn);
}

.kpi.tone-bad .kpi-value {
  color: var(--bad);
}

.kpi.tone-info .kpi-value {
  color: var(--info);
}

.kpi.tone-live .kpi-value {
  color: var(--live);
}

.kpi.tone-muted .kpi-value {
  color: var(--muted);
}

/* Tone utilities for text anywhere (e.g. a due date cell) */
.tone-good {
  color: var(--good);
}

.tone-warn {
  color: var(--warn);
}

.tone-bad {
  color: var(--bad);
}

.tone-info {
  color: var(--info);
}

.tone-live {
  color: var(--live);
}

.tone-muted {
  color: var(--muted);
}

.kpi.tone-good,
.kpi.tone-warn,
.kpi.tone-bad,
.kpi.tone-info,
.kpi.tone-live,
.kpi.tone-muted {
  color: var(--text);
}

/* ---------------------------------------------------------------------------------------
   Tables
   ------------------------------------------------------------------------------------- */
.table-wrap {
  position: relative;
  overflow: auto;
  max-height: 75vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.card .table-wrap {
  border-width: 0;
  border-radius: 0;
  box-shadow: none;
}

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--fs-base);
}

.table th,
.table td {
  padding: 11px var(--sp-3);
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}

.table th:first-child,
.table td:first-child {
  padding-left: var(--sp-4);
}

.table th:last-child,
.table td:last-child {
  padding-right: var(--sp-4);
}

.table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding-top: 9px;
  padding-bottom: 9px;
  background: var(--surface-2);
  color: var(--text-subtle);
  font-size: 11px;
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  white-space: nowrap;
  vertical-align: bottom;
}

.table thead th a {
  color: inherit;
}

.table thead th a:hover {
  color: var(--text);
  text-decoration: none;
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

.table tbody tr:hover td {
  background: color-mix(in srgb, var(--surface-hover) 70%, var(--surface));
}

.table td.num,
.table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.table--compact th,
.table--compact td {
  padding-top: 7px;
  padding-bottom: 7px;
}

.table .row-link {
  cursor: pointer;
}

.table td a {
  font-weight: var(--fw-medium);
}

.table-actions {
  text-align: right;
  white-space: nowrap;
}

.table-actions > * + * {
  margin-left: var(--sp-1);
}

.table-actions form {
  display: inline;
}

.table caption {
  caption-side: top;
  padding: var(--sp-3);
  text-align: left;
  color: var(--text-muted);
}

/* ---------------------------------------------------------------------------------------
   Badges, chips, progress
   ------------------------------------------------------------------------------------- */
/* Soft tinted pills: a pale fill, a hairline of the same hue and AA-contrast text. */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 1px 8px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  line-height: 18px;
  letter-spacing: 0.005em;
  white-space: nowrap;
  vertical-align: middle;
  background: var(--muted-soft);
  color: var(--muted);
  border: 1px solid color-mix(in srgb, currentColor 16%, transparent);
}

.badge-good {
  background: var(--good-soft);
  color: var(--good);
}

.badge-warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge-bad {
  background: var(--bad-soft);
  color: var(--bad);
}

.badge-info {
  background: var(--info-soft);
  color: var(--info);
}

.badge-live {
  background: var(--live-soft);
  color: var(--live);
}

.badge-muted {
  background: var(--muted-soft);
  color: var(--muted);
}

.provenance {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
}

.source-link {
  font-size: var(--fs-sm);
}

.progress-meter {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 110px;
  width: 100%;
  max-width: 180px;
}

.progress {
  position: relative;
  display: block;
  flex: 1;
  height: 6px;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text) 4%, transparent);
  min-width: 48px;
  border-radius: var(--radius-pill);
  background: var(--track);
  overflow: hidden;
}

.progress-bar {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 80%, var(--surface)), var(--accent));
}

.progress-value {
  flex: none;
  min-width: 34px;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
}

/* :is() and :not() raise specificity above the generic input rules in "Forms", which would
   otherwise make text, search and date inputs full width. */
.filter-bar :is(input, select):not([type="checkbox"]):not([type="radio"]) {
  display: inline-block;
  flex: 0 1 220px;
  width: auto;
  min-width: 140px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 3px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text-muted);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  cursor: pointer;
  white-space: nowrap;
}

.chip:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}

.chip:focus-visible {
  outline: 2px solid transparent;
  outline-offset: 2px;
  box-shadow: var(--focus-ring);
}

.chip.is-active {
  background: var(--accent-soft);
  border-color: var(--accent-soft-border);
  color: var(--accent);
  font-weight: var(--fw-semibold);
}

.chip .icon {
  width: 14px;
  height: 14px;
}

/* ---------------------------------------------------------------------------------------
   Tabs
   ------------------------------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: var(--sp-1);
  margin-bottom: var(--sp-5);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: thin;
}

.tab {
  flex: none;
  padding: 10px var(--sp-3);
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-weight: var(--fw-medium);
  white-space: nowrap;
}

.tab:hover {
  color: var(--text);
  border-bottom-color: var(--border-strong);
  text-decoration: none;
}

.tab:focus-visible {
  outline: 2px solid transparent;
  outline-offset: -2px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.tab.is-active {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: var(--fw-semibold);
}

.tab .badge {
  margin-left: 4px;
}

/* ---------------------------------------------------------------------------------------
   Lists and timeline
   ------------------------------------------------------------------------------------- */
.list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.list-item {
  padding: 14px var(--sp-5);
  border-bottom: 1px solid var(--border);
}

.list-item:last-child {
  border-bottom: 0;
}

.list-item-title {
  font-weight: var(--fw-semibold);
  color: var(--text);
  overflow-wrap: anywhere;
}

a.list-item-title {
  color: var(--text);
}

a.list-item-title:hover {
  color: var(--link);
}

.list-item-meta {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

.timeline {
  list-style: none;
  margin: 0;
  padding: 0 0 0 var(--sp-5);
  position: relative;
}

.timeline::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--border);
}

.timeline-item {
  position: relative;
  padding: 0 0 var(--sp-4);
}

.timeline-item:last-child {
  padding-bottom: 0;
}

.timeline-item::before {
  content: "";
  position: absolute;
  left: calc(-1 * var(--sp-5) + 1px);
  top: 5px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
}

.timeline-date {
  display: block;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------------------------------
   Empty states and alerts
   ------------------------------------------------------------------------------------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  padding: 40px var(--sp-5);
  text-align: center;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
}

.card .empty-state {
  border: 0;
  background: transparent;
}

.empty-state-icon {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: var(--sp-1);
  border-radius: var(--radius-lg);
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent-soft-border);
}

.empty-state-title {
  margin: 0;
  color: var(--text);
  font-weight: var(--fw-semibold);
  font-size: var(--fs-md);
}

.empty-state-text {
  margin: 0;
  max-width: 460px;
}

.messages:empty {
  display: none;
}

.messages {
  display: grid;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
}

/* The message loop leaves whitespace behind (so :empty never matches): take no room while
   there is nothing to say, but stay in the page as the live region. */
.messages:not(:has(*)) {
  margin-bottom: 0;
}

/* Flash messages and inline alerts: a tinted panel with a slim tone bar on the left. */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: 10px 14px 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: inset 3px 0 0 var(--alert-tone, var(--border-strong));
  color: var(--text);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.alert.is-hiding {
  opacity: 0;
  transform: translateY(-4px);
}

.alert-text {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.alert-close {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  margin: -2px -4px -2px 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: inherit;
  opacity: 0.65;
  cursor: pointer;
}

.alert-close:hover {
  opacity: 1;
  background: color-mix(in srgb, currentColor 10%, transparent);
}

.alert-close .icon {
  width: 14px;
  height: 14px;
}

.alert-success {
  --alert-tone: var(--good);
  background: var(--good-soft);
  border-color: color-mix(in srgb, var(--good) 24%, transparent);
}

.alert-info {
  --alert-tone: var(--info);
  background: var(--info-soft);
  border-color: color-mix(in srgb, var(--info) 22%, transparent);
}

.alert-warning {
  --alert-tone: var(--warn);
  background: var(--warn-soft);
  border-color: color-mix(in srgb, var(--warn) 24%, transparent);
}

.alert-error {
  --alert-tone: var(--bad);
  background: var(--bad-soft);
  border-color: color-mix(in srgb, var(--bad) 24%, transparent);
}

.alert .errorlist {
  margin: 0;
}

.alert .errorlist li {
  color: var(--text);
}

/* ---------------------------------------------------------------------------------------
   Buttons
   ------------------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 6px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-btn);
  color: var(--text);
  font: inherit;
  font-weight: var(--fw-semibold);
  line-height: 20px;
  letter-spacing: -0.003em;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.btn:hover {
  background: var(--surface-2);
  border-color: color-mix(in srgb, var(--border-strong) 70%, var(--text-subtle));
  text-decoration: none;
}

.btn:active {
  transform: translateY(0.5px);
}

.btn:focus-visible {
  outline: 2px solid transparent;
  outline-offset: 2px;
  box-shadow: var(--focus-ring);
}

.btn .icon {
  width: 16px;
  height: 16px;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: var(--shadow-btn-primary);
  color: var(--accent-contrast);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-primary:active {
  background: var(--accent-active);
  border-color: var(--accent-active);
}

.btn-primary:focus-visible,
.btn-danger:focus-visible {
  box-shadow: var(--shadow-btn-primary), var(--focus-ring);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: var(--surface-hover);
  border-color: transparent;
  color: var(--text);
}

.btn-danger {
  background: var(--bad);
  border-color: var(--bad);
  box-shadow: var(--shadow-btn-primary);
  color: var(--on-bad);
}

.btn-danger:hover {
  background: color-mix(in srgb, var(--bad) 88%, #000);
  border-color: color-mix(in srgb, var(--bad) 88%, #000);
  color: var(--on-bad);
}

.btn-sm {
  min-height: 28px;
  padding: 3px 10px;
  font-size: var(--fs-sm);
}

.btn-block {
  width: 100%;
}

.btn[disabled],
.btn[aria-disabled="true"] {
  opacity: 0.5;
  box-shadow: none;
  cursor: not-allowed;
  pointer-events: none;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  margin-top: var(--sp-4);
}

.pagination-info {
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

/* ---------------------------------------------------------------------------------------
   Forms (element selectors so plain Django widgets look right)
   ------------------------------------------------------------------------------------- */
.form {
  margin: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-4) var(--sp-5);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field--full {
  grid-column: 1 / -1;
}

.field-label,
.field > label {
  font-weight: var(--fw-strong);
  font-size: var(--fs-sm);
  color: var(--text);
}

.required {
  color: var(--bad);
  font-weight: var(--fw-heavy);
}

.help,
.helptext {
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

.errorlist {
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--bad);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
}

.form-errors {
  margin-bottom: var(--sp-4);
}

.form-errors .errorlist {
  color: var(--text);
}

/* Someone else changed the record while it was being edited (core.concurrency). */
.conflict-panel {
  display: grid;
  gap: var(--sp-3);
  margin: 0 0 var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
  border-left-width: 4px;
  border-left-color: var(--warn);
  border-radius: var(--radius);
  background: var(--warn-soft);
}

.conflict-panel-title {
  margin: 0;
  font-weight: 600;
}

.conflict-panel-intro {
  margin: calc(-1 * var(--sp-2)) 0 0;
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

.conflict {
  display: grid;
  gap: var(--sp-2);
  min-width: 0;
  margin: 0;
  padding: var(--sp-2) 0 0;
  border: 0;
  border-top: 1px solid color-mix(in srgb, var(--warn) 25%, transparent);
}

.conflict-label {
  padding: 0;
  font-weight: 600;
  font-size: var(--fs-sm);
}

.conflict-choice {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
}

.conflict-choice input {
  margin-top: 3px;
}

.conflict-choice-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.conflict-choice-name {
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

.conflict-value {
  overflow-wrap: anywhere;
  white-space: pre-line;
}

input[type="text"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="month"],
input[type="week"],
input[type="search"],
input[type="password"],
input[type="url"],
input[type="tel"],
input:not([type]),
select,
textarea {
  display: block;
  width: 100%;
  min-height: 36px;
  padding: 7px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-base);
  line-height: 20px;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease),
    background-color var(--dur-fast) var(--ease);
}

select {
  padding-right: 34px;
  appearance: none;
  background-image: var(--select-chevron);
  background-position: right 10px center;
  background-size: 16px 16px;
  background-repeat: no-repeat;
}

select[multiple] {
  padding-right: 10px;
  background-image: none;
  min-height: 120px;
}

textarea {
  min-height: 110px;
  resize: vertical;
  line-height: var(--lh);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-subtle);
}

input:hover,
select:hover,
textarea:hover {
  border-color: color-mix(in srgb, var(--border-strong) 60%, var(--text-subtle));
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
input:focus,
select:focus,
textarea:focus {
  outline: 2px solid transparent;
  outline-offset: 0;
  border-color: var(--accent);
  box-shadow: var(--focus);
}

input[disabled],
select[disabled],
textarea[disabled],
input[readonly],
textarea[readonly] {
  background: var(--surface-sunken);
  box-shadow: none;
  color: var(--text-muted);
  cursor: not-allowed;
}

input[type="checkbox"],
input[type="radio"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
  flex: none;
}

input[type="file"] {
  font: inherit;
  max-width: 100%;
}

input[type="file"]::file-selector-button {
  margin-right: var(--sp-3);
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-btn);
  color: var(--text);
  font: inherit;
  font-weight: var(--fw-semibold);
  cursor: pointer;
}

input[type="file"]::file-selector-button:hover {
  background: var(--surface-2);
}

.field.has-error input,
.field.has-error select,
.field.has-error textarea,
[aria-invalid="true"] {
  border-color: var(--bad);
}

.field.has-error input:focus,
.field.has-error select:focus,
.field.has-error textarea:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 25%, transparent);
}

.field--checkbox {
  justify-content: center;
}

.checkbox {
  display: inline-flex;
  align-items: flex-start;
  gap: var(--sp-2);
  font-weight: var(--fw-medium);
  cursor: pointer;
}

.checkbox input {
  margin-top: 2px;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

legend {
  padding: 0;
  margin-bottom: 6px;
}

/* Django's RadioSelect / CheckboxSelectMultiple markup */
fieldset > div,
.field ul:not(.errorlist) {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2) var(--sp-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

fieldset label,
.field ul:not(.errorlist) label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: var(--fw-regular);
  cursor: pointer;
}

.form-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.card-footer.form-actions {
  justify-content: flex-start;
}

.form-card {
  max-width: 920px;
}

.form-card--narrow {
  max-width: 560px;
}

.form-card--narrow .form-grid {
  grid-template-columns: minmax(0, 1fr);
}

.form-intro {
  margin-bottom: var(--sp-4);
}

/* ---------------------------------------------------------------------------------------
   Suggestion review (shared by capture and documents)
   ------------------------------------------------------------------------------------- */
.suggestion-review {
  margin: 0;
}

.suggestion-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.suggestion-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
}

.suggestion-head .list-item-title {
  flex: 1 1 240px;
}

.suggestion-head label.list-item-title {
  cursor: pointer;
}

.suggestion-confidence {
  margin-left: auto;
}

.suggestion-fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--sp-1) var(--sp-4);
  margin: var(--sp-2) 0 0;
  font-size: var(--fs-sm);
}

.suggestion-fields dt {
  color: var(--text-muted);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.suggestion-fields dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.suggestion .evidence {
  margin-top: var(--sp-2);
  font-size: var(--fs-sm);
  white-space: pre-line;
}

.suggestion-actions {
  margin-top: var(--sp-3);
}

.suggestion.is-accepted,
.suggestion.is-rejected,
.suggestion.is-superseded {
  background: var(--surface-2);
}

.suggestion.is-rejected .list-item-title,
.suggestion.is-superseded .list-item-title {
  color: var(--text-muted);
  text-decoration: line-through;
}

.suggestion-bulk {
  margin-top: var(--sp-3);
}

/* ---------------------------------------------------------------------------------------
   Placeholder pages, search, home
   ------------------------------------------------------------------------------------- */
.stub {
  max-width: 760px;
}

.stub-lead {
  font-size: var(--fs-md);
}

.search-form {
  margin-bottom: var(--sp-4);
}

.search-form .search-input {
  flex: 1 1 280px;
  width: auto;
}

.search-count {
  margin: 0 0 var(--sp-2);
}

.search-snippet {
  margin: var(--sp-1) 0 0;
}

.home-tip {
  margin-top: var(--sp-5);
}

.bullets {
  margin: 0;
  padding-left: var(--sp-5);
}

/* ---------------------------------------------------------------------------------------
   Sign-in and error pages
   ------------------------------------------------------------------------------------- */
.minimal {
  min-height: 100vh;
  background:
    radial-gradient(1000px 480px at 50% -12%, color-mix(in srgb, var(--accent-soft) 90%, transparent), transparent 70%),
    var(--bg);
}

.minimal-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--sp-6) var(--sp-4);
}

.minimal-card {
  width: 100%;
  max-width: 420px;
  padding: var(--sp-7) var(--sp-7) var(--sp-6);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
}

.minimal-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-6);
}

.minimal-brand .brand-mark {
  width: 40px;
  height: 40px;
  font-size: 19px;
  border-radius: 11px;
}

.minimal-title {
  font-size: 22px;
  letter-spacing: var(--tracking-tight);
  margin-bottom: 6px;
}

.minimal-lead {
  color: var(--text-muted);
  margin-bottom: var(--sp-5);
}

.minimal-code {
  margin: 0 0 var(--sp-1);
  color: var(--accent);
  font-weight: var(--fw-heavy);
  font-size: var(--fs-sm);
  letter-spacing: 0.08em;
}

.minimal-card .cluster {
  margin-top: var(--sp-5);
}

.minimal-card > .alert {
  margin-bottom: var(--sp-4);
}

.minimal-card .form .btn-block {
  margin-top: var(--sp-2);
  min-height: 40px;
}

.minimal-footer {
  /* Kept clear of the card's shadow and in the muted ink, so the marking stays at AA. */
  margin-top: var(--sp-6);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  text-align: center;
}

/* Sign-in and first run: a quiet branded panel beside the card on wide screens. */
.brand-panel {
  display: none;
}

@media (min-width: 960px) {
  .minimal--split {
    display: grid;
    grid-template-columns: minmax(400px, 5fr) 7fr;
    background: var(--bg);
  }

  .minimal--split .minimal-main {
    background: radial-gradient(900px 420px at 50% -10%, var(--accent-soft), transparent 70%), var(--bg);
  }

  .minimal--split .minimal-card {
    box-shadow: var(--shadow-md);
  }

  /* The panel carries the brand, so the card leads with its title. */
  .minimal--split .minimal-card > .minimal-brand {
    display: none;
  }

  .brand-panel {
    --bp-ink: #ffffff;
    --bp-soft: rgba(255, 255, 255, 0.94);
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: var(--sp-7);
    height: 100vh;
    padding: 40px 48px;
    overflow: hidden;
    color: var(--bp-ink);
    background:
      radial-gradient(520px 360px at 85% 8%, rgba(255, 255, 255, 0.16), transparent 70%),
      radial-gradient(640px 420px at 0% 100%, rgba(10, 22, 60, 0.45), transparent 70%),
      linear-gradient(155deg, #2a5bd0 0%, #1f4bb4 45%, #173a8f 100%);
    isolation: isolate;
  }

  /* A faint grid gives the panel texture without a picture. */
  .brand-panel::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background-image:
      linear-gradient(rgba(255, 255, 255, 0.06) 1px, transparent 1px),
      linear-gradient(90deg, rgba(255, 255, 255, 0.06) 1px, transparent 1px);
    background-size: 32px 32px;
    mask-image: radial-gradient(ellipse at 60% 45%, #000 20%, transparent 75%);
  }

  .brand-panel-brand {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
  }

  .brand-panel .brand-mark {
    width: 40px;
    height: 40px;
    font-size: 19px;
    border-radius: 11px;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
  }

  .brand-panel .brand-org {
    font-size: var(--fs-lg);
  }

  .brand-panel .brand-app {
    color: var(--bp-soft);
  }

  .brand-panel-art {
    display: grid;
    place-items: center;
    flex: 1;
    min-height: 0;
  }

  .bp-board {
    display: grid;
    gap: 14px;
    width: min(100%, 360px);
    padding: 22px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.1);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18), 0 30px 60px -20px rgba(5, 12, 35, 0.5);
    backdrop-filter: blur(6px);
    transform: perspective(900px) rotateX(8deg) rotateZ(-3deg);
  }

  .bp-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
  }

  .bp-dot {
    width: 8px;
    height: 8px;
    flex: none;
    border-radius: 50%;
  }

  .bp-line {
    height: 7px;
    width: 62%;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.55);
  }

  .bp-row:nth-child(2) .bp-line {
    width: 48%;
  }

  .bp-row:nth-child(3) .bp-line {
    width: 70%;
  }

  .bp-row:nth-child(4) .bp-line {
    width: 40%;
  }

  .bp-pill {
    width: 46px;
    height: 16px;
    margin-left: auto;
    flex: none;
    border-radius: 999px;
    opacity: 0.9;
  }

  .bp-good {
    background: #6ee7b0;
  }

  .bp-warn {
    background: #fcd27b;
  }

  .bp-bad {
    background: #fca5a0;
  }

  .bp-bars {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    height: 84px;
    padding: 12px 12px 0;
  }

  .bp-bars span {
    flex: 1;
    height: 50%;
    border-radius: 5px 5px 2px 2px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0.25));
  }

  .bp-bars span:nth-child(2) {
    height: 64%;
  }

  .bp-bars span:nth-child(3) {
    height: 52%;
  }

  .bp-bars span:nth-child(4) {
    height: 78%;
  }

  .bp-bars span:nth-child(5) {
    height: 70%;
  }

  .bp-bars span:nth-child(6) {
    height: 92%;
  }

  .brand-panel-lead {
    max-width: 30ch;
    margin: 0;
    color: var(--bp-ink);
    font-size: 22px;
    font-weight: var(--fw-strong);
    line-height: 1.3;
    letter-spacing: -0.015em;
    text-wrap: balance;
  }
}

/* Short wide screens: the decoration would run into the headline, so the panel keeps only words. */
@media (min-width: 960px) and (max-height: 640px) {
  .brand-panel-art {
    display: none;
  }
}

@media screen and (min-width: 960px) and (prefers-color-scheme: dark) {
  .brand-panel {
    background:
      radial-gradient(520px 360px at 85% 8%, rgba(112, 153, 242, 0.18), transparent 70%),
      radial-gradient(640px 420px at 0% 100%, rgba(0, 0, 0, 0.5), transparent 70%),
      linear-gradient(155deg, #1a2f63 0%, #14244b 50%, #0e1934 100%);
    border-right: 1px solid var(--border);
  }
}

/* ---------------------------------------------------------------------------------------
   Utilities
   ------------------------------------------------------------------------------------- */
.muted {
  color: var(--text-muted);
}

.small {
  font-size: var(--fs-sm);
}

.mono {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

.truncate {
  display: block;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.nowrap {
  white-space: nowrap;
}

.text-right {
  text-align: right;
}

.meta {
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* htmx: requests in flight */
.htmx-request {
  opacity: 0.6;
  transition: opacity var(--dur) var(--ease);
}

.htmx-indicator {
  display: none;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  display: inline-flex;
}

/* ---------------------------------------------------------------------------------------
   Responsive: tablet (drawer navigation)
   ------------------------------------------------------------------------------------- */
@media (max-width: 1200px) {
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  :root {
    --gutter: var(--sp-4);
  }

  .app {
    grid-template-columns: minmax(0, 1fr);
    background: none;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(300px, 86vw);
    height: 100%;
    transform: translateX(-102%);
    transition: transform 0.26s var(--ease), visibility 0s linear 0.26s;
    border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
    box-shadow: var(--shadow-lg);
    visibility: hidden;
  }

  body.drawer-open .sidebar {
    transition: transform 0.26s var(--ease);
  }

  body.drawer-open .sidebar {
    transform: none;
    visibility: visible;
  }

  body.drawer-open {
    overflow: hidden;
  }

  .drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(10, 14, 20, 0.4);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    animation: backdrop-in var(--dur) var(--ease);
  }

  @keyframes backdrop-in {
    from {
      opacity: 0;
    }
  }

  .icon-btn.sidebar-close,
  .icon-btn.menu-btn {
    display: inline-grid;
  }

  .topbar {
    gap: var(--sp-2);
  }

  .topbar-title {
    flex: 1 1 auto;
  }

  .topbar-search {
    flex: 0 1 260px;
  }

  .topbar-search .kbd,
  .user-menu-name,
  .user-menu-toggle > .icon {
    display: none;
  }

  .topbar-capture {
    display: none;
  }

  .page {
    padding-bottom: calc(var(--bottombar-h) + var(--sp-6) + env(safe-area-inset-bottom));
  }

  .bottom-bar {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 30;
    display: grid;
    grid-auto-columns: minmax(0, 1fr);
    grid-auto-flow: column;
    height: calc(var(--bottombar-h) + env(safe-area-inset-bottom));
    padding: 0 var(--sp-1) env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: saturate(1.6) blur(14px);
    -webkit-backdrop-filter: saturate(1.6) blur(14px);
    border-top: 1px solid var(--border);
    box-shadow: 0 -6px 16px -10px rgba(16, 24, 40, 0.12);
  }

  .bottom-link {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 44px;
    border: 0;
    background: none;
    color: var(--text-muted);
    font: inherit;
    font-size: 11px;
    font-weight: var(--fw-medium);
    letter-spacing: 0.01em;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  /* The icon sits in a pill that fills in for the current section. */
  .bottom-link .icon {
    box-sizing: content-box;
    width: 22px;
    height: 22px;
    padding: 3px 14px;
    border-radius: var(--radius-pill);
    transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
  }

  .bottom-link:hover {
    text-decoration: none;
    color: var(--text);
  }

  .bottom-link:focus-visible {
    outline: 2px solid transparent;
    outline-offset: -2px;
  }

  .bottom-link:focus-visible .icon {
    box-shadow: 0 0 0 2px var(--accent);
  }

  .bottom-link.is-active {
    color: var(--accent);
    font-weight: var(--fw-semibold);
  }

  .bottom-link.is-active .icon {
    background: var(--accent-soft);
  }

  .bottom-badge {
    position: absolute;
    top: 4px;
    left: calc(50% + 7px);
    min-width: 17px;
    padding: 0 4px;
    border-radius: var(--radius-pill);
    background: var(--warn);
    color: var(--on-warn);
    font-size: 10px;
    font-weight: var(--fw-heavy);
    line-height: 16px;
    text-align: center;
    box-shadow: 0 0 0 2px var(--surface);
  }

  .bottom-badge-bad {
    background: var(--bad);
    color: var(--on-bad);
  }

  .table-wrap {
    max-height: none;
  }

  .table thead th {
    position: static;
  }

  /* Comfortable touch targets */
  .btn,
  .nav-link,
  .menu-item,
  .chip,
  .icon-btn {
    min-height: 40px;
  }

  .icon-btn {
    width: 40px;
  }

  .btn-sm {
    min-height: 36px;
  }

  input[type="text"],
  input[type="email"],
  input[type="number"],
  input[type="date"],
  input[type="search"],
  input[type="password"],
  input[type="url"],
  input[type="tel"],
  input:not([type]),
  select,
  textarea {
    min-height: 40px;
    font-size: 16px; /* stops iOS zooming into focused fields */
  }
}

/* Responsive: phone */
@media (max-width: 600px) {
  h1 {
    font-size: var(--fs-xl);
  }

  .grid-2,
  .grid-3,
  .grid-4,
  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .topbar-title {
    display: none;
  }

  .topbar-search {
    flex: 1 1 auto;
    max-width: none;
  }

  .page {
    padding-top: var(--sp-5);
  }

  .page-header {
    align-items: flex-start;
    flex-direction: column;
    margin-bottom: var(--sp-5);
  }

  .page-subtitle {
    font-size: var(--fs-base);
  }

  .card-header {
    min-height: 48px;
    padding: var(--sp-3) var(--sp-4);
  }

  .card-footer {
    padding: var(--sp-3) var(--sp-4);
  }

  .page-actions {
    width: 100%;
  }

  .page-actions .btn {
    flex: 1 1 auto;
  }

  .kpi-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .kpi-value {
    font-size: 22px;
  }

  .card-body {
    padding: var(--sp-4);
  }

  .list-item {
    padding: var(--sp-3) var(--sp-4);
  }

  .minimal-card {
    padding: var(--sp-6) var(--sp-5);
  }

  .demo-banner {
    align-items: flex-start;
  }
}

/* Windows High Contrast (forced colours) removes box-shadow, which most focus rings here use,
   so draw a real outline in the system colour instead. */
@media (forced-colors: active) {
  .nav-link:focus-visible,
  .tab:focus-visible,
  .bottom-link:focus-visible,
  .icon-btn:focus-visible,
  a.kpi:focus-visible,
  .chip:focus-visible,
  .btn:focus-visible,
  input:focus-visible,
  select:focus-visible,
  textarea:focus-visible {
    outline: 2px solid Highlight;
  }
}

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

/* ---------------------------------------------------------------------------------------
   Print: content only, black on white
   ------------------------------------------------------------------------------------- */
@media print {
  :root {
    color-scheme: light;
    --bg: #fff;
    --surface: #fff;
    --surface-2: #fff;
    --text: #000;
    --text-muted: #333;
    --text-subtle: #555;
    --border: #999;
    --border-strong: #666;
  }

  body {
    background: #fff;
    color: #000;
    font-size: 11pt;
  }

  .sidebar,
  .drawer-backdrop,
  .topbar,
  .bottom-bar,
  .skip-link,
  .messages,
  .page-actions,
  .filter-bar,
  .tabs,
  .pagination,
  .btn,
  .table-actions,
  .alert-close,
  form[role="search"],
  .no-print {
    display: none !important;
  }

  .app {
    display: block;
    background: none;
  }

  .main-col {
    display: block;
  }

  .page {
    max-width: none;
    padding: 0;
  }

  .print-classification {
    display: block;
    margin: 0 0 8pt;
    font-size: 9pt;
    font-weight: var(--fw-semibold);
    text-transform: uppercase;
    letter-spacing: 0.06em;
  }

  .demo-banner {
    border: 1px solid #000;
    color: #000;
    background: #fff;
    margin-bottom: 12pt;
  }

  a,
  a:visited {
    color: #000;
    text-decoration: none;
  }

  .card,
  .kpi,
  .empty-state {
    box-shadow: none;
    border-color: #999;
    break-inside: avoid;
  }

  .table-wrap {
    overflow: visible;
    max-height: none;
    border: 0;
    box-shadow: none;
  }

  .table {
    border-collapse: collapse;
  }

  .table th,
  .table td {
    border: 1px solid #999;
    background: #fff !important;
  }

  .table thead th {
    position: static;
    color: #000;
  }

  .table thead {
    display: table-header-group;
  }

  .table tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .badge {
    border: 1px solid #666;
    background: #fff !important;
    color: #000 !important;
  }

  .progress {
    border: 1px solid #666;
    background: #fff;
  }

  .progress-bar {
    background: #444;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
}
