/* ==========================================================================
   Great Marcys AML/CFT Compliance Management System — design system
   One stylesheet, no external requests. Sections:
   1 Tokens · 2 Base · 3 Shell · 4 Page · 5 Components · 6 Forms · 7 Tables
   8 Patterns · 9 Auth · 10 Utilities · 11 Responsive · 12 Motion/Print
   ========================================================================== */

/* 1 — Tokens ------------------------------------------------------------- */
:root {
  /* Navy scale (sidebar, headings) */
  --navy-950: #07142a;
  --navy-900: #0b1f3a;
  --navy-800: #122a4d;
  --navy-700: #1c3c69;
  /* Blue (actions, links, focus) */
  --blue-700: #17479a;
  --blue-600: #1d58b8;
  --blue-100: #dfeafb;
  --blue-50:  #eef4fd;
  /* Gold (restrained: brand mark, active marker, key rule) */
  --gold-500: #a8813c;
  --gold-400: #c9a45c;
  --gold-100: #f6eedc;
  /* Ink + greys */
  --ink-900: #0f1b2d;
  --ink-700: #2a3a52;
  --ink-600: #435269;
  --ink-500: #5a6a80;
  --ink-300: #9aa7ba;
  --line:        #e2e7ef;
  --line-strong: #c9d2e0;
  --page:        #f3f5f9;
  --surface:     #ffffff;
  --surface-2:   #f8f9fc;
  /* Status tones: bg / text / mark */
  --ok-bg:   #e4f3ea; --ok-fg:   #14633a; --ok-mk:   #1f9d5d;
  --warn-bg: #fdf0d8; --warn-fg: #7e5200; --warn-mk: #d99a1c;
  --bad-bg:  #fce8e6; --bad-fg:  #9b221a; --bad-mk:  #d64536;
  --info-bg: #e3edfb; --info-fg: #1a4a96; --info-mk: #3b79d8;
  --neu-bg:  #eceff4; --neu-fg:  #404f66; --neu-mk:  #8593a8;

  /* Type */
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Source Serif 4", "Iowan Old Style", "Palatino Linotype", Charter, Georgia, serif;
  --fs-xs: .75rem; --fs-sm: .8125rem; --fs-base: .9375rem; --fs-md: 1.0625rem;
  --fs-lg: 1.25rem; --fs-xl: 1.625rem; --fs-2xl: 2rem;

  /* Space (4px base) */
  --s-1: .25rem; --s-2: .5rem; --s-3: .75rem; --s-4: 1rem; --s-5: 1.25rem;
  --s-6: 1.5rem; --s-8: 2rem; --s-10: 2.5rem; --s-12: 3rem;

  /* Shape + depth */
  --r-sm: 6px; --r-md: 8px; --r-lg: 12px; --r-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(11, 31, 58, .06);
  --shadow-md: 0 4px 14px rgba(11, 31, 58, .08);
  --shadow-lg: 0 18px 40px rgba(11, 31, 58, .16);
  --ring: 0 0 0 3px rgba(29, 88, 184, .28);

  --sidebar-w: 268px;
  --topbar-h: 60px;
  --content-max: 1360px;
}

/* 2 — Base --------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--topbar-h) + 16px); }
body {
  margin: 0; background: var(--page); color: var(--ink-900);
  font-family: var(--font-sans); font-size: var(--fs-base); line-height: 1.55;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; color: var(--navy-900); line-height: 1.25; }
h1 { font-family: var(--font-serif); font-size: var(--fs-xl); font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: var(--fs-md); font-weight: 650; }
h3 { font-size: var(--fs-base); font-weight: 650; }
p { margin: 0 0 var(--s-3); }
a { color: var(--blue-600); text-decoration: none; }
a:hover { color: var(--blue-700); text-decoration: underline; text-underline-offset: 3px; }
small { font-size: var(--fs-sm); }
ul, ol { padding-left: 1.2rem; margin: 0 0 var(--s-3); }
hr { border: 0; border-top: 1px solid var(--line); margin: var(--s-6) 0; }
dl, dd { margin: 0; }
:focus-visible { outline: 2px solid var(--blue-600); outline-offset: 2px; border-radius: 3px; }
.icon { width: 1.15em; height: 1.15em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; vertical-align: -.2em; }
.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; }
.skip-link { position: absolute; left: var(--s-4); top: -60px; z-index: 100; padding: var(--s-2) var(--s-4); background: var(--navy-900); color: #fff; border-radius: var(--r-md); }
.skip-link:focus { top: var(--s-3); color: #fff; }

/* 3 — Application shell -------------------------------------------------- */
.app { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 40; width: var(--sidebar-w);
  display: flex; flex-direction: column; padding: var(--s-5) var(--s-3) var(--s-4);
  background: var(--navy-900); color: #cfd9e8; overflow-y: auto; overscroll-behavior: contain;
}
.brand { display: flex; align-items: center; gap: var(--s-3); padding: 0 var(--s-2) var(--s-5); margin-bottom: var(--s-2); border-bottom: 1px solid rgba(255,255,255,.09); }
.brand:hover { text-decoration: none; }
.monogram {
  position: relative; display: grid; place-items: center; width: 40px; height: 40px; flex: none;
  border-radius: 10px; background: var(--navy-700); color: #fff;
  font-family: var(--font-serif); font-weight: 700; font-size: 1.05rem; letter-spacing: .02em;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.14);
}
.monogram::after { content: ""; position: absolute; left: 9px; right: 9px; bottom: 6px; height: 2px; border-radius: 2px; background: var(--gold-400); }
.brand-text strong { display: block; color: #fff; font-size: var(--fs-base); font-weight: 650; line-height: 1.2; }
.brand-text span { display: block; margin-top: 2px; color: #93a5bf; font-size: var(--fs-xs); }
.nav-group { margin-top: var(--s-5); }
.nav-group-label { padding: 0 var(--s-3); margin-bottom: var(--s-2); color: #8ea1bd; font-size: var(--fs-xs); font-weight: 600; }
.nav { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; }
.nav a {
  position: relative; display: flex; align-items: center; gap: var(--s-3); min-height: 40px;
  padding: 0 var(--s-3); border-radius: var(--r-md); color: #cfd9e8; font-size: var(--fs-sm); font-weight: 500;
  transition: background-color .15s ease, color .15s ease;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav a[aria-current="page"] { background: rgba(255,255,255,.10); color: #fff; font-weight: 600; }
.nav a[aria-current="page"]::before { content: ""; position: absolute; left: -12px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--gold-400); }
.nav .icon { width: 18px; height: 18px; opacity: .9; }
.sidebar :focus-visible { outline-color: #9ec1ff; }
.sidebar-foot { margin-top: auto; padding: var(--s-5) var(--s-3) 0; color: #8ea1bd; font-size: var(--fs-xs); line-height: 1.5; }
.sidebar-foot .icon { margin-right: 4px; }

.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h); display: flex; align-items: center; gap: var(--s-3);
  padding: 0 var(--s-8); background: rgba(255,255,255,.94); backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-org { color: var(--ink-500); font-size: var(--fs-sm); font-weight: 500; margin-right: auto; }
.nav-toggle { display: none; }
.user-menu { position: relative; }
.user-menu > summary {
  display: flex; align-items: center; gap: var(--s-3); padding: 5px var(--s-2) 5px 5px; border-radius: var(--r-pill);
  cursor: pointer; list-style: none; border: 1px solid transparent;
}
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary:hover, .user-menu[open] > summary { background: var(--surface-2); border-color: var(--line); }
.avatar { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--blue-100); color: var(--blue-700); font-size: var(--fs-sm); font-weight: 700; flex: none; }
.user-meta { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; text-align: left; }
.user-meta strong { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-sm); font-weight: 600; color: var(--ink-900); }
.user-meta small { color: var(--ink-500); font-size: var(--fs-xs); }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 50; min-width: 240px; padding: var(--s-2);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
}
.menu-panel .menu-head { padding: var(--s-2) var(--s-3) var(--s-3); border-bottom: 1px solid var(--line); margin-bottom: var(--s-2); overflow-wrap: anywhere; }
.menu-panel .menu-head small { display: block; color: var(--ink-500); }
.menu-item {
  display: flex; align-items: center; gap: var(--s-3); width: 100%; padding: var(--s-2) var(--s-3); border: 0; border-radius: var(--r-md);
  background: transparent; color: var(--ink-700); font: inherit; font-size: var(--fs-sm); font-weight: 500; text-align: left; cursor: pointer;
}
.menu-item:hover { background: var(--surface-2); color: var(--ink-900); text-decoration: none; }
.menu-panel form { margin: 0; }
.content { width: 100%; max-width: var(--content-max); margin: 0 auto; padding: var(--s-8) var(--s-8) var(--s-12); flex: 1; }
.footer { padding: var(--s-4) var(--s-8); border-top: 1px solid var(--line); color: var(--ink-500); font-size: var(--fs-xs); }
.scrim { display: none; }

/* 4 — Page structure ----------------------------------------------------- */
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-6); flex-wrap: wrap; margin-bottom: var(--s-6); }
.page-header-main { min-width: 0; flex: 1 1 420px; }
.lede { margin: var(--s-2) 0 0; max-width: 72ch; color: var(--ink-600); font-size: var(--fs-base); }
.page-actions { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }
.crumbs { margin-bottom: var(--s-2); }
.crumbs ol { display: flex; flex-wrap: wrap; align-items: center; gap: 2px var(--s-2); margin: 0; padding: 0; list-style: none; font-size: var(--fs-sm); color: var(--ink-500); }
.crumbs li + li::before { content: "/"; margin-right: var(--s-2); color: var(--ink-300); }
.crumbs a { color: var(--ink-500); }
.crumbs a:hover { color: var(--blue-700); }
.crumbs [aria-current] { color: var(--ink-700); font-weight: 500; }
.stack > * + * { margin-top: var(--s-6); }
.stack-sm > * + * { margin-top: var(--s-3); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-6); align-items: start; }
.grid-main-side { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: var(--s-6); align-items: start; }
.cluster { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s-2) var(--s-3); }

/* 5 — Components --------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; padding: var(--s-5) var(--s-6) 0; }
.card-head h2 { margin: 0; }
.card-head p { margin: var(--s-1) 0 0; color: var(--ink-500); font-size: var(--fs-sm); max-width: 70ch; }
.card-body { padding: var(--s-5) var(--s-6) var(--s-6); }
.card-flush { padding: 0; }
.card-foot { padding: var(--s-4) var(--s-6); border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); color: var(--ink-500); font-size: var(--fs-sm); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2); min-height: 40px; padding: 0 var(--s-4);
  border: 1px solid transparent; border-radius: var(--r-md); font: inherit; font-size: var(--fs-sm); font-weight: 600; line-height: 1;
  cursor: pointer; white-space: nowrap; text-decoration: none; transition: background-color .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.btn:hover { text-decoration: none; }
.btn:focus-visible { outline: 0; box-shadow: var(--ring); }
.btn-primary { background: var(--blue-600); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--blue-700); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--ink-700); border-color: var(--line-strong); }
.btn-secondary:hover { background: var(--surface-2); color: var(--ink-900); border-color: var(--ink-300); }
.btn-danger { background: var(--surface); color: var(--bad-fg); border-color: #e9b8b3; }
.btn-danger:hover { background: var(--bad-bg); color: var(--bad-fg); }
.btn-ghost { background: transparent; color: var(--blue-600); padding: 0 var(--s-2); }
.btn-ghost:hover { background: var(--blue-50); }
.btn-sm { min-height: 32px; padding: 0 var(--s-3); font-size: var(--fs-xs); }
.btn-block { width: 100%; }
.btn[disabled], .btn[aria-busy="true"] { opacity: .6; cursor: not-allowed; }
/* Raw submit controls rendered by WTForms (input[type=submit]) pick up the primary style */
input[type="submit"] { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 var(--s-5); border: 0; border-radius: var(--r-md); background: var(--blue-600); color: #fff; font: inherit; font-size: var(--fs-sm); font-weight: 600; cursor: pointer; box-shadow: var(--shadow-sm); }
input[type="submit"]:hover { background: var(--blue-700); }
input[type="submit"]:focus-visible { outline: 0; box-shadow: var(--ring); }
button:not(.btn):not(.menu-item):not(.tab):not(.nav-toggle):not(.alert-close) { /* legacy bare buttons inside forms */
  min-height: 36px; padding: 0 var(--s-4); border: 1px solid var(--line-strong); border-radius: var(--r-md); background: var(--surface); color: var(--ink-700); font: inherit; font-size: var(--fs-sm); font-weight: 600; cursor: pointer;
}

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 8px; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 600; line-height: 1.4; white-space: nowrap; }
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--ok-bg); color: var(--ok-fg); }
.badge-warning { background: var(--warn-bg); color: var(--warn-fg); }
.badge-danger  { background: var(--bad-bg); color: var(--bad-fg); }
.badge-info    { background: var(--info-bg); color: var(--info-fg); }
.badge-neutral { background: var(--neu-bg); color: var(--neu-fg); }
.badge-gold { background: var(--gold-100); color: #6a4f12; }
.badge-gold .badge-dot { background: var(--gold-500); }
.badge-success .badge-dot { background: var(--ok-mk); }
.badge-warning .badge-dot { background: var(--warn-mk); }
.badge-danger .badge-dot  { background: var(--bad-mk); }
.badge-info .badge-dot    { background: var(--info-mk); }
.badge-neutral .badge-dot { background: var(--neu-mk); }
.badge-risk { font-weight: 650; }

.callout { display: flex; gap: var(--s-3); padding: var(--s-4); border: 1px solid; border-left-width: 4px; border-radius: var(--r-md); font-size: var(--fs-sm); line-height: 1.55; }
.callout p:last-child, .callout ul:last-child { margin-bottom: 0; }
.callout ul { margin: var(--s-2) 0 0; }
.callout-icon { flex: none; line-height: 0; padding-top: 2px; }
.callout-icon .icon { width: 18px; height: 18px; }
.callout-body strong { display: block; margin-bottom: 2px; }
.callout-info    { background: var(--info-bg); border-color: #b9d0f3; color: var(--info-fg); }
.callout-warning { background: var(--warn-bg); border-color: #f0d49a; color: var(--warn-fg); }
.callout-danger  { background: var(--bad-bg);  border-color: #f0b9b3; color: var(--bad-fg); }
.callout-success { background: var(--ok-bg);   border-color: #b3dcc3; color: var(--ok-fg); }
.callout-lock    { background: var(--gold-100); border-color: #e5d2a3; color: #5e4713; }

.flashes { display: grid; gap: var(--s-3); margin-bottom: var(--s-6); }
.alert { display: flex; align-items: flex-start; gap: var(--s-3); padding: var(--s-3) var(--s-4); border: 1px solid; border-radius: var(--r-md); font-size: var(--fs-sm); }
.alert .icon { margin-top: 2px; }
.alert-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.alert-close { border: 0; background: transparent; color: inherit; cursor: pointer; padding: 2px; line-height: 0; border-radius: 4px; opacity: .7; }
.alert-close:hover { opacity: 1; }
.alert-success { background: var(--ok-bg);   border-color: #b3dcc3; color: var(--ok-fg); }
.alert-danger, .alert-error { background: var(--bad-bg); border-color: #f0b9b3; color: var(--bad-fg); }
.alert-warning { background: var(--warn-bg); border-color: #f0d49a; color: var(--warn-fg); }
.alert-info, .alert-message { background: var(--info-bg); border-color: #b9d0f3; color: var(--info-fg); }

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; padding: var(--s-10) var(--s-4); color: var(--ink-500); }
.empty-icon { display: grid; place-items: center; width: 48px; height: 48px; margin-bottom: var(--s-3); border-radius: 50%; background: var(--neu-bg); color: var(--ink-500); }
.empty-icon .icon { width: 22px; height: 22px; }
.empty strong { color: var(--ink-900); font-size: var(--fs-base); }
.empty p { max-width: 46ch; margin: var(--s-1) 0 var(--s-4); font-size: var(--fs-sm); }

.seg { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-2); gap: 2px; }
.seg a { padding: 5px var(--s-4); border-radius: 6px; color: var(--ink-600); font-size: var(--fs-sm); font-weight: 500; }
.seg a:hover { color: var(--ink-900); text-decoration: none; }
.seg a.is-active { background: var(--surface); color: var(--navy-900); font-weight: 650; box-shadow: var(--shadow-sm); }

.tabs { display: flex; gap: var(--s-1); margin-bottom: var(--s-6); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: thin; }
.tab { position: relative; padding: var(--s-3) var(--s-4); border: 0; background: transparent; color: var(--ink-600); font: inherit; font-size: var(--fs-sm); font-weight: 550; cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--ink-900); }
.tab[aria-selected="true"] { color: var(--navy-900); font-weight: 650; }
.tab[aria-selected="true"]::after { content: ""; position: absolute; left: var(--s-3); right: var(--s-3); bottom: -1px; height: 2px; background: var(--blue-600); border-radius: 2px; }
.tab:focus-visible { outline: 2px solid var(--blue-600); outline-offset: -2px; }
.tab-count { margin-left: 6px; padding: 1px 7px; border-radius: var(--r-pill); background: var(--neu-bg); color: var(--neu-fg); font-size: var(--fs-xs); }
[data-tabs].is-ready [role="tabpanel"][hidden] { display: none; }

/* key/value lists */
.kv { display: grid; grid-template-columns: minmax(130px, 220px) minmax(0, 1fr); }
.kv dt, .kv dd { padding: var(--s-3) 0; border-bottom: 1px solid var(--line); }
.kv dt { color: var(--ink-500); font-size: var(--fs-sm); padding-right: var(--s-4); }
.kv dd { color: var(--ink-900); font-weight: 500; overflow-wrap: anywhere; }
.kv dt:last-of-type, .kv dd:last-of-type { border-bottom: 0; }
.muted { color: var(--ink-500); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }

/* 6 — Forms -------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field + .field { margin-top: 0; }
.field label, label.label { display: flex; align-items: baseline; gap: var(--s-2); color: var(--ink-900); font-size: var(--fs-sm); font-weight: 600; }
.req { color: var(--bad-mk); font-weight: 700; }
.opt { margin-left: auto; color: var(--ink-500); font-size: var(--fs-xs); font-weight: 500; }
.hint { margin: 0; color: var(--ink-500); font-size: var(--fs-xs); line-height: 1.5; }
.field-error { margin: 0; color: var(--bad-fg); font-size: var(--fs-xs); font-weight: 600; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--bad-mk); background: #fffafa; }
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]), select, textarea {
  width: 100%; min-height: 42px; padding: 9px var(--s-3); border: 1px solid var(--line-strong); border-radius: var(--r-md);
  background: var(--surface); color: var(--ink-900); font: inherit; font-size: var(--fs-base); line-height: 1.4;
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { min-height: 96px; resize: vertical; }
select { appearance: none; padding-right: 36px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235a6a80' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
input::placeholder, textarea::placeholder { color: #64738a; opacity: 1; }
input:hover:not(:disabled), select:hover:not(:disabled), textarea:hover:not(:disabled) { border-color: var(--ink-300); }
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--blue-600); box-shadow: var(--ring); }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--ink-500); cursor: not-allowed; }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--blue-600); flex: none; }
.check { display: flex; align-items: flex-start; gap: var(--s-3); padding: var(--s-3); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-2); font-size: var(--fs-sm); font-weight: 500; color: var(--ink-700); cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-5) var(--s-5); }
.form-grid .field-full { grid-column: 1 / -1; }
.form-section + .form-section { margin-top: var(--s-6); }
.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: var(--s-3); flex-wrap: wrap; padding-top: var(--s-5); margin-top: var(--s-6); border-top: 1px solid var(--line); }
.form-stack { display: grid; gap: var(--s-4); }
.inline-form { margin-top: var(--s-2); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); }
.inline-form > summary { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-2) var(--s-3); cursor: pointer; list-style: none; color: var(--blue-600); font-size: var(--fs-sm); font-weight: 600; border-radius: var(--r-md); }
.inline-form > summary::-webkit-details-marker { display: none; }
.inline-form > summary::after { content: ""; margin-left: auto; width: 14px; height: 14px; background: currentColor; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat; transition: transform .15s ease; }
.inline-form[open] > summary::after { transform: rotate(180deg); }
.inline-form[open] > summary { border-bottom: 1px solid var(--line); border-radius: var(--r-md) var(--r-md) 0 0; }
.inline-form > .form-stack, .inline-form > form { padding: var(--s-4); }
.inline-form form { margin: 0; }
td .inline-form { min-width: 280px; max-width: 420px; white-space: normal; }

.toolbar { display: flex; align-items: flex-end; gap: var(--s-3); flex-wrap: wrap; padding: var(--s-4) var(--s-6); border-bottom: 1px solid var(--line); }
.toolbar .field { flex: 0 1 200px; }
.toolbar .field-grow { flex: 1 1 280px; }
.search { position: relative; }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-500); pointer-events: none; }
.search input { padding-left: 38px !important; }
.toolbar-meta { margin-left: auto; color: var(--ink-500); font-size: var(--fs-sm); align-self: center; }

/* 7 — Tables ------------------------------------------------------------- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap:focus-visible { outline-offset: -2px; }
table.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); text-align: left; }
.table th { position: sticky; top: 0; padding: var(--s-3) var(--s-4); background: var(--surface-2); border-bottom: 1px solid var(--line); color: var(--ink-500); font-size: var(--fs-xs); font-weight: 650; letter-spacing: .02em; white-space: nowrap; }
.table td { padding: var(--s-4); border-bottom: 1px solid var(--line); vertical-align: top; color: var(--ink-700); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #fafbfd; }
.table .num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .nowrap { white-space: nowrap; }
.cell-title { display: block; max-width: 34ch; color: var(--ink-900); font-weight: 600; overflow-wrap: anywhere; }
.cell-sub { display: block; max-width: 38ch; margin-top: 2px; color: var(--ink-500); font-size: var(--fs-xs); overflow-wrap: anywhere; }
.cell-wrap { min-width: 220px; max-width: 520px; overflow-wrap: anywhere; white-space: normal; }
.table td.cell-empty { padding: 0; }
.table-link { font-weight: 600; white-space: nowrap; }
.money { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; color: var(--ink-900); }
.money-cur { margin-right: 2px; color: var(--ink-500); font-size: var(--fs-xs); font-weight: 600; }
.row-overdue td:first-child { box-shadow: inset 3px 0 var(--bad-mk); }
.detail-row td { padding-top: 0; background: var(--surface-2); }
.detail-row:hover td { background: var(--surface-2) !important; }

/* 8 — Patterns ----------------------------------------------------------- */
/* Dashboard: attention list */
.attn { margin: 0; padding: 0; list-style: none; }
.attn li { border-bottom: 1px solid var(--line); }
.attn li:last-child { border-bottom: 0; }
.attn-row { display: flex; align-items: center; gap: var(--s-4); padding: var(--s-4) var(--s-6); color: inherit; }
a.attn-row:hover { background: var(--surface-2); text-decoration: none; }
.attn-count { min-width: 3.2ch; font-family: var(--font-serif); font-size: var(--fs-xl); font-weight: 600; color: var(--navy-900); font-variant-numeric: tabular-nums; }
.attn-count.is-zero { color: var(--ink-300); }
.attn-label { flex: 1; min-width: 0; }
.attn-label strong { display: block; color: var(--ink-900); font-size: var(--fs-base); font-weight: 600; }
.attn-label small { color: var(--ink-500); }
.attn-go { color: var(--ink-300); }
a.attn-row:hover .attn-go { color: var(--blue-600); }
.summary-strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.summary-strip > * { padding: var(--s-5) var(--s-6); border-right: 1px solid var(--line); }
.summary-strip > *:last-child { border-right: 0; }
.summary-strip .sv { display: block; font-family: var(--font-serif); font-size: var(--fs-2xl); font-weight: 600; color: var(--navy-900); line-height: 1.1; font-variant-numeric: tabular-nums; }
.summary-strip .sl { display: block; margin-top: var(--s-1); color: var(--ink-500); font-size: var(--fs-sm); }
.modules { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: var(--s-3); padding: var(--s-5) var(--s-6) var(--s-6); }
.module { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-4); border: 1px solid var(--line); border-radius: var(--r-md); color: var(--ink-900); font-size: var(--fs-sm); font-weight: 600; background: var(--surface); transition: border-color .15s ease, box-shadow .15s ease; }
.module:hover { border-color: var(--blue-600); box-shadow: var(--shadow-md); text-decoration: none; color: var(--blue-700); }
.module .icon { width: 20px; height: 20px; color: var(--blue-600); }

/* Profile header */
.profile { display: flex; align-items: center; gap: var(--s-5); flex-wrap: wrap; padding: var(--s-5) var(--s-6); }
.profile-avatar { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 14px; background: var(--navy-900); color: #fff; font-family: var(--font-serif); font-size: 1.5rem; font-weight: 600; flex: none; }
.profile-id { flex: 1 1 260px; min-width: 0; }
.profile-id h2 { font-family: var(--font-serif); font-size: var(--fs-lg); overflow-wrap: anywhere; }
.profile-id p { margin: 2px 0 var(--s-2); color: var(--ink-500); font-size: var(--fs-sm); }
.profile-facts { display: flex; gap: var(--s-8); flex-wrap: wrap; }
.profile-facts div { display: flex; flex-direction: column; gap: 6px; }
.profile-facts span.l { color: var(--ink-500); font-size: var(--fs-xs); font-weight: 500; }

/* Review / audit timeline */
.timeline { margin: 0; padding: 0; list-style: none; }
.timeline li { position: relative; padding: 0 0 var(--s-5) var(--s-6); border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li:last-child { padding-bottom: 0; border-left-color: transparent; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--blue-600); }
.timeline .t-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3); font-weight: 600; color: var(--ink-900); }
.timeline .t-meta { color: var(--ink-500); font-size: var(--fs-sm); }
.timeline p { margin: var(--s-1) 0 0; color: var(--ink-700); font-size: var(--fs-sm); overflow-wrap: anywhere; }
.note { padding: var(--s-4); border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line); font-size: var(--fs-sm); }
.note strong { color: var(--ink-900); }
.note p:last-child { margin-bottom: 0; }
.request { padding: var(--s-4); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); }
.request + .request { margin-top: var(--s-3); }
.request-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-2); }
.factor { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: var(--s-1) var(--s-3); font-size: var(--fs-sm); }
.factor dt { color: var(--ink-500); }
.factor dd { color: var(--ink-700); overflow-wrap: anywhere; }
.pending-items { margin: var(--s-3) 0 0; }
.pending-items li { margin-bottom: var(--s-1); }
.pct { display: inline-flex; align-items: center; gap: var(--s-2); font-variant-numeric: tabular-nums; font-weight: 600; }
.pct-bar { width: 72px; height: 6px; border-radius: 3px; background: var(--neu-bg); overflow: hidden; }
.pct-bar span { display: block; height: 100%; background: var(--blue-600); }
.type-choice { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-4); }
.type-note { padding: var(--s-3) var(--s-4); border-radius: var(--r-md); background: var(--blue-50); color: var(--info-fg); font-size: var(--fs-sm); }

/* 9 — Auth screens ------------------------------------------------------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 520px); }
.auth-aside { position: relative; display: flex; flex-direction: column; justify-content: space-between; padding: var(--s-12); background: var(--navy-950); color: #cfd9e8; overflow: hidden; }
.auth-aside::before { content: ""; position: absolute; inset: 0; background: linear-gradient(160deg, var(--navy-900) 0%, var(--navy-950) 70%); }
.auth-aside > * { position: relative; }
.auth-aside .brand { border-bottom: 0; padding: 0; margin: 0; }
.auth-aside h2 { max-width: 20ch; color: #fff; font-family: var(--font-serif); font-size: 2.1rem; font-weight: 600; line-height: 1.2; letter-spacing: -.01em; }
.auth-aside h2 + p { max-width: 46ch; margin-top: var(--s-4); color: #aebcd2; }
.auth-aside .rule { width: 56px; height: 2px; margin-bottom: var(--s-5); background: var(--gold-400); border-radius: 2px; }
.auth-aside small { color: #8ea1bd; }
.auth-main { display: flex; align-items: center; justify-content: center; padding: var(--s-8); background: var(--surface); }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h1 { font-size: var(--fs-xl); }
.auth-card .lede { margin-bottom: var(--s-6); }
.auth-card .brand-compact { display: none; }
.auth-card form { display: grid; gap: var(--s-5); }
.auth-card .foot { margin-top: var(--s-6); padding-top: var(--s-5); border-top: 1px solid var(--line); color: var(--ink-500); font-size: var(--fs-xs); text-align: center; }
.rules { margin: 0; padding: var(--s-3) var(--s-4) var(--s-3) var(--s-6); border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line); font-size: var(--fs-sm); color: var(--ink-600); }

/* 10 — Utilities --------------------------------------------------------- */
.mt-0 { margin-top: 0 !important; } .mt-4 { margin-top: var(--s-4) !important; } .mt-6 { margin-top: var(--s-6) !important; }
.mb-0 { margin-bottom: 0 !important; } .text-right { text-align: right; } .w-full { width: 100%; }
.hide-sm { }

/* 11 — Responsive -------------------------------------------------------- */
@media (max-width: 1100px) {
  .grid-main-side { grid-template-columns: minmax(0, 1fr); }
  .content { padding: var(--s-6) var(--s-6) var(--s-10); }
  .topbar { padding: 0 var(--s-6); }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); visibility: hidden; transition: transform .22s ease, visibility 0s linear .22s; box-shadow: var(--shadow-lg); }
  .sidebar.is-open { transform: none; visibility: visible; transition: transform .22s ease; }
  .main { margin-left: 0; }
  .nav-toggle { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); color: var(--navy-900); cursor: pointer; margin-left: -4px; }
  .nav-toggle .icon { width: 20px; height: 20px; }
  .scrim { position: fixed; inset: 0; z-index: 35; background: rgba(7, 20, 42, .5); }
  .scrim.is-open { display: block; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .auth { grid-template-columns: minmax(0, 1fr); }
  .auth-aside { display: none; }
  .auth-card .brand-compact { display: flex; margin-bottom: var(--s-8); }
  .auth-card .brand-compact .brand-text strong { color: var(--navy-900); }
  .auth-card .brand-compact .brand-text span { color: var(--ink-500); }
  .topbar-org { display: none; }
  .topbar .spacer { flex: 1; }
}
@media (max-width: 680px) {
  .content { padding: var(--s-5) var(--s-4) var(--s-10); }
  .topbar { padding: 0 var(--s-4); }
  .footer { padding: var(--s-4); }
  h1 { font-size: 1.4rem; }
  .form-grid, .type-choice { grid-template-columns: minmax(0, 1fr); }
  .card-head, .card-body, .toolbar, .attn-row, .profile, .modules { padding-left: var(--s-4); padding-right: var(--s-4); }
  .kv { grid-template-columns: minmax(0, 1fr); }
  .kv dt { padding-bottom: 0; border-bottom: 0; }
  .kv dd { padding-top: 2px; }
  .summary-strip { grid-template-columns: minmax(0, 1fr); }
  .summary-strip > * { border-right: 0; border-bottom: 1px solid var(--line); }
  .summary-strip > *:last-child { border-bottom: 0; }
  .user-meta { display: none; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1 1 auto; }
  .toolbar .field, .toolbar .field-grow { flex: 1 1 100%; }
  .toolbar-meta { margin-left: 0; }
  .profile-facts { gap: var(--s-5); }
  .factor { grid-template-columns: minmax(0, 1fr); }
  .auth-main { padding: var(--s-6) var(--s-4); align-items: flex-start; }
}

/* 12 — Motion + print ---------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .001ms !important; animation-duration: .001ms !important; scroll-behavior: auto !important; }
}
@media print {
  .sidebar, .topbar, .scrim, .footer, .page-actions, .btn, .nav-toggle { display: none !important; }
  .main { margin: 0; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}

/* Confirmation dialog ---------------------------------------------------- */
.dialog { width: min(440px, calc(100vw - 2rem)); padding: var(--s-6); border: 0; border-radius: var(--r-lg); background: var(--surface); color: var(--ink-900); box-shadow: var(--shadow-lg); }
.dialog::backdrop { background: rgba(7, 20, 42, .55); }
.dialog form { margin: 0; }
.dialog h2 { margin-bottom: var(--s-2); }
.dialog p { color: var(--ink-600); }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--s-3); margin-top: var(--s-5); }

/* Multi-tbody tables (task + detail row groups) keep a divider between groups */
.table tbody:not(:last-child) tr:last-child td { border-bottom: 1px solid var(--line); }
[data-tabs]:not(.is-ready) > .tabs { display: none; }
[data-tabs]:not(.is-ready) > [role="tabpanel"] + [role="tabpanel"] { margin-top: var(--s-6); }
