/* Knowledge Capture Pro -- design system, rebuilt against the Limestone Technology
   Group Company Style Guide v2.0 (Sept 23, 2026), full fidelity: told
   explicitly to follow the guide over what the app already had, rather
   than treat the earlier warm-canvas/orange-button choices as fixed.
   Signature (light) and Midnight (dark) tokens below are v2's own named
   values (pages 7-8), not an approximation of them.
   The one structural change worth naming: --action/--on-action are new,
   separate from --accent. v2 p.16 specifies the PRIMARY button as
   navy-filled/white-text in Signature and soft-blue-filled/navy-text in
   Midnight -- orange is reserved for a sparingly-used focal action (p.16,
   p.9's ~5% heuristic), not the default button fill every button used
   before. --accent stays for that sparing use (see .btn-accent) and for
   existing restrained uses elsewhere (progress fill, the sidebar's own
   always-navy active marker, an emphasis card border) -- none of which
   are "the button", so none of them needed to change.
   Also structural: dark-mode secondary text used to BE the action color
   (--text-soft was literally --accent's blue). v2 gives text-secondary
   its own dimmer value (page 8) distinct from action -- doing otherwise
   made ordinary labels compete visually with real buttons. */
/* Light is the default -- an explicit user choice (stored server-side,
   see app.py's THEME_COOKIE), not prefers-color-scheme, decides dark mode
   now. Plain :root carries light's values so it's the true fallback if
   the data-theme attribute is ever missing for any reason. */
:root, :root[data-theme="light"] {
  /* v2 p.7 Signature: canvas / surface / subtle. panel-3 (a fourth, more
     saturated inset tier this app already relies on in a few spots) is
     not a named v2 tier -- derived one step further from subtle, in the
     same family. */
  --bg: #f3f6f9; --panel: #ffffff; --panel-2: #edf3f7; --panel-3: #e1eaf0;
  --line: #d4dee6; --line-strong: #718393; /* v2 p.7 divider / control-border */
  --text: #183149; --text-soft: #536674; --text-faint: #7d8b94; /* p.7 text/text-secondary; -faint derived, not a named tier */
  --link: #245c80; /* v2 p.7 -- distinct from --text, so a link reads as a link before you notice its underline */
  --action: #102b46; --on-action: #ffffff; /* v2 p.7 action/on-action -- the actual primary-button spec */
  --action-hover: #183149; /* one navy step lighter, already used elsewhere in this palette as --sidebar-active-bg */
  --accent: #ff8200; --accent-2: #cc6800; --accent-soft: #fff1e0;
  --ok: #206446; --ok-soft: #edf8f1;   /* v2 p.7 success / success-surface */
  --warn: #854700; --warn-soft: #fff3e4; /* v2 p.7 warning / warning-surface */
  --danger: #aa293d; --danger-soft: #fff0f2; /* v2 p.7 danger / danger-surface */
  --shadow-sm: 0 1px 2px rgba(16, 43, 70, 0.06);
  --shadow: 0 1px 3px rgba(16, 43, 70, 0.07), 0 4px 14px rgba(16, 43, 70, 0.06);
  --shadow-lg: 0 8px 30px rgba(16, 43, 70, 0.12);
}
:root[data-theme="dark"] {
  /* v2 p.8 Midnight: canvas / surface / subtle. panel-3 again derived,
     not a named tier -- kept close to this app's existing value since it
     already sat almost exactly where the guide's own scale would put it. */
  --bg: #0b1725; --panel: #13283d; --panel-2: #1b354e; --panel-3: #223c54;
  --line: #344d63; --line-strong: #819ab1; /* v2 p.8 divider / control-border */
  --text: #f4f7fa; --text-soft: #b7c9d8; --text-faint: #7e93a6; /* p.8 text/text-secondary; -faint derived */
  --link: #a8d1ef; /* v2 p.8 */
  --action: #8fb9d8; --on-action: #102b46; /* v2 p.8 action/on-action */
  --action-hover: #a8d1ef; /* one blue step lighter -- the same value as --link, the natural next step up from soft blue */
  --accent: #ff8200; --accent-2: #ff9e33; --accent-soft: #3a2413;
  --ok: #9ddec0; --ok-soft: #163c31;   /* v2 p.8 success / success-surface */
  --warn: #ffc781; --warn-soft: #493317; /* v2 p.8 warning / warning-surface */
  --danger: #ffb7c2; --danger-soft: #4b2330; /* v2 p.8 danger / danger-surface */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.35), 0 6px 18px rgba(0, 0, 0, 0.28);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.45);
}
/* v2 p.12: controls 8px, cards 12px, dialogs 14px */
:root { --radius-sm: 8px; --radius: 12px; --radius-lg: 14px; }
/* v2 p.8 names one explicit exception: destructive filled buttons may use
   #AA293D with white text in either theme. Fixed here rather than swapped
   per-theme, because dark mode's own --danger token is the pale-pink TEXT
   value (#FFB7C2) -- correct for a status label on a dark surface, wrong
   as a button fill, which is exactly the case the guide calls out. */
:root { --danger-fill: #aa293d; }

/* Sidebar is always dark navy -- doesn't toggle with light/dark mode, so
   these live outside the theme blocks above (matches admin.limestonetg.com:
   its sidebar doesn't change with light/dark either). */
:root {
  --sidebar-width: 232px;  /* v2 style guide, p.14: expanded rail is 232px */
  --sidebar-bg: #102b46;
  --sidebar-active-bg: #183149;
  --sidebar-text: #ffffff;
  --sidebar-text-soft: #8fb9d8;
  --sidebar-text-faint: #6e8ca6;
  --sidebar-line: #24405c;
  --sidebar-accent: #ff8200;
}

* { box-sizing: border-box; }
/* The plain HTML hidden attribute only wins by specificity, not by
   meaning -- any author rule setting `display` on the same element (a
   class, or even a bare tag selector like `button { display: inline-flex }`)
   ties or beats the browser's own `[hidden] { display: none }` UA rule,
   so a "hidden" element can render anyway depending purely on what else
   happens to match it. Found live, twice, in two different places in the
   same pass (a bulk-action bar's own class, then a plain <button>) --
   third time isn't a coincidence, it's every future `hidden` toggle in
   this app. One universal, deliberately loud rule fixes the whole class
   of bug instead of patching each element that happens to collide with it. */
[hidden] { display: none !important; }
html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; overflow-x: hidden; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  /* v2 p.11: body/reading is 16/26px. Was 15/23.25 -- close enough that
     nothing was obviously wrong, which is exactly why it's worth matching
     the spec exactly now rather than leaving a small, permanent drift. */
  font: 16px/26px "Sora", Aptos, "Segoe UI", Arial, sans-serif;
  letter-spacing: -0.001em;
  overflow-x: hidden;
  display: flex; align-items: flex-start;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
.main { flex: 1; min-width: 0; }
.wrap { max-width: 1020px; margin: 0 auto; padding: 28px 24px 64px; }
@media (max-width: 640px) { .wrap { padding: 18px 14px 48px; } }

/* --------------------------------------------------- global mobile safety */
table { display: block; overflow-x: auto; white-space: nowrap; }
table.wrap-ok { white-space: normal; }
table .dropdown-menu { white-space: normal; }  /* an in-cell edit-row dropdown (e.g. admin_users.html) shouldn't inherit the table's nowrap trick */
summary.btn-small::-webkit-details-marker { display: none; }  /* a button-styled <summary> (e.g. the per-row "Edit" toggle) shouldn't also show the default disclosure triangle */
.item, .qcard, .card, .qa-context, .chat-bubble, td, th { overflow-wrap: break-word; word-break: break-word; }

/* ----------------------------------------------- generic dropdown menu */
/* Details/summary-based dropdown, used for in-page toggles (e.g. an
   in-cell "Edit" row in admin_users.html) -- independent of the sidebar. */
.dropdown { position: relative; }
.dropdown[open] summary { color: var(--text); background: var(--panel-2); }
.dropdown:not([open]) .dropdown-menu { display: none; }
.dropdown-menu {
  position: absolute; top: calc(100% + 6px); left: 0; min-width: 190px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); padding: 6px; z-index: 30;
}
.dropdown-menu a {
  display: block; padding: 8px 10px; border-radius: 6px; color: var(--text); font-size: 13.5px; font-weight: 500;
}
.dropdown-menu a:hover { background: var(--panel-2); text-decoration: none; }

/* ------------------------------------------------------------ sidebar */
.sidebar-toggle-checkbox { position: absolute; opacity: 0; pointer-events: none; }

.sidebar {
  /* One text gutter for the whole rail. The nav's links carry a 3px
     transparent border-left for the active marker, so everything without
     one adds that 3px back as padding to line up with them. */
  --sidebar-gutter: 16px;  /* v2 p.14: 16px horizontal inset */
  width: var(--sidebar-width); flex-shrink: 0; background: var(--sidebar-bg);
  height: 100vh; display: flex; flex-direction: column;
  position: sticky; top: 0; align-self: flex-start;
}
.sidebar-header { display: flex; align-items: center; gap: 9px; padding: 14px 14px 12px; }
.sidebar-header .sidebar-icon { width: 24px; height: 24px; flex-shrink: 0; }
.sidebar-header .sidebar-wordmark { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.sidebar-header .sidebar-brand { font-weight: 700; font-size: 14.5px; color: var(--sidebar-text); letter-spacing: -0.01em; }
.sidebar-header .sidebar-brand-sub { font-size: 10.5px; color: var(--sidebar-text-faint); }
.sidebar-collapse-btn {
  margin-left: auto; background: none; border: none; box-shadow: none; padding: 4px 5px;
  font: inherit; font-size: 13px; line-height: 1; letter-spacing: -0.05em;
  color: var(--sidebar-text-faint); border-radius: var(--radius-sm); cursor: pointer;
}
.sidebar-collapse-btn:hover { background: rgba(255, 255, 255, 0.08); color: var(--sidebar-text); }
.sidebar-collapse-btn:active { transform: none; }
.sidebar-module { padding: 0 14px 10px; margin-bottom: 2px; border-bottom: 1px solid var(--sidebar-line); }
.sidebar-module-name { font-weight: 600; font-size: 13px; color: var(--sidebar-text-soft); }
.sidebar-module-program { display: block; font-size: 11px; color: var(--sidebar-text-faint); margin-top: 1px; }

/* The destination list scrolls, and it must never look like it simply
   stopped: the style guide (v2, p.14) requires the account controls to sit
   below the destinations "without covering it". A fade plus a visible
   scrollbar is what makes a cut-off row read as "more below" rather than
   as a broken layout. is-scrollable is set by base.html only when the list
   actually overflows, so a short list isn't dimmed for no reason. */
.sidebar-nav {
  flex: 1; overflow-y: auto; padding: 4px 8px 8px;
  scrollbar-width: thin; scrollbar-color: var(--sidebar-line) transparent;
}
.sidebar-nav.is-scrollable {
  mask-image: linear-gradient(to bottom, #000 calc(100% - 22px), transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 22px), transparent 100%);
}
.sidebar-nav::-webkit-scrollbar { width: 8px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb {
  background: var(--sidebar-line); border-radius: 4px;
  border: 2px solid transparent; background-clip: content-box;
}
.sidebar-nav::-webkit-scrollbar-thumb:hover { background: var(--sidebar-text-faint); background-clip: content-box; }
/* A hard edge where the list ends, so the account block below reads as a
   separate region rather than as the next nav item. */
.sidebar-bottom { border-top: 1px solid var(--sidebar-line); }
.sidebar-section { margin-bottom: 4px; padding-bottom: 4px; }
.sidebar-section + .sidebar-section { border-top: 1px solid var(--sidebar-line); padding-top: 4px; }
/* A real heading rather than a faint whisper over the links: brighter, and
   the whole row is the hit target for collapsing the group. */
.sidebar-label {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  width: 100%; background: none; border: none; box-shadow: none; border-radius: var(--radius-sm);
  font: inherit; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--sidebar-text-soft); padding: 6px 10px 6px var(--sidebar-gutter); margin: 2px 0 1px; cursor: pointer;
}
.sidebar-label:hover { background: rgba(255, 255, 255, 0.06); color: var(--sidebar-text); }
.sidebar-label:active { transform: none; }
.sidebar-chev {
  width: 9px; height: 6px; flex-shrink: 0; opacity: 0.8;
  transition: transform .12s ease;
}
.sidebar-section.collapsed .sidebar-links { display: none; }
.sidebar-section.collapsed .sidebar-chev { transform: rotate(-90deg); }
/* v2 p.14/p.25: 44px minimum row target -- this used to be 34px, which
   is a real house-standard miss (found while implementing the nav's own
   spec page), not a rounding difference. Padding uses --sidebar-gutter
   directly rather than a hardcoded number, so the 3px active-state
   border and every other rail element share one true left edge. */
.sidebar-nav a {
  display: flex; align-items: center; gap: 8px;
  padding: 8px calc(var(--sidebar-gutter) - 3px);
  min-height: 44px; border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 500;
  color: var(--sidebar-text-soft); border-left: 3px solid transparent;
  text-decoration: none; transition: background .12s, color .12s;
}
.sidebar-nav a:hover { color: var(--sidebar-text); background: rgba(255, 255, 255, 0.06); text-decoration: none; }
/* v2 p.14: the selected destination is a fill plus a 3px orange leading
   marker -- "a hover fill alone is not a selected state", which is why the
   hover above is deliberately weaker than this. */
.sidebar-nav a.active {
  color: var(--sidebar-text); background: #254d6c;
  border-left-color: var(--sidebar-accent); font-weight: 500;
}
/* v2 p.14: a pale-blue focus ring on navy, never an invisible navy one. */
.sidebar-nav a:focus-visible,
.sidebar-label:focus-visible,
.sidebar-bottom a:focus-visible,
.sidebar-signout:focus-visible {
  outline: 2px solid #a8d1ef; outline-offset: -2px;
}

.sidebar-bottom { padding: 6px 10px 10px; border-top: 1px solid var(--sidebar-line); }
.sidebar-bottom a, .sidebar-signout {
  display: block; width: 100%; padding: 5px var(--sidebar-gutter); font-size: 12.5px;
  text-align: left; color: var(--sidebar-text-faint); text-decoration: none;
}
.sidebar-bottom a:hover, .sidebar-signout:hover { color: var(--sidebar-text-soft); text-decoration: none; }
.sidebar-theme-toggle {
  display: flex; gap: 2px; margin: 6px 0 2px; padding: 2px;
  background: rgba(0, 0, 0, 0.2); border-radius: var(--radius-sm);
}
.sidebar-theme-toggle button {
  flex: 1; background: none; border: none; box-shadow: none; padding: 5px 0;
  font: inherit; font-size: 12px; font-weight: 500; color: var(--sidebar-text-faint);
  border-radius: 5px; cursor: pointer;
}
/* Both of these have to out-specify the base `button:hover`/`:active`,
   which would otherwise paint a segment accent-orange on hover. */
.sidebar-theme-toggle button:hover { background: none; color: var(--sidebar-text-soft); }
.sidebar-theme-toggle button:active { transform: none; }
.sidebar-theme-toggle button.active { background: var(--sidebar-active-bg); color: var(--sidebar-text); }
.sidebar-user { display: flex; align-items: center; gap: 8px; padding: 8px var(--sidebar-gutter) 4px; }
.sidebar-user-info { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.sidebar-user-name { font-size: 13px; font-weight: 600; color: var(--sidebar-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 11.5px; color: var(--sidebar-text-faint); }
/* A plain button, not a .linklike one: it's the last row of a list of
   links and should read as one, rather than as the only underlined,
   full-size, differently-indented thing in the sidebar. */
.sidebar-signout {
  background: none; border: none; box-shadow: none; border-radius: 0;
  font: inherit; font-size: 12.5px; font-weight: 400; cursor: pointer;
}
.sidebar-signout:hover { background: none; }
.sidebar-signout:active { transform: none; }
.sidebar-footer-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sidebar-footer-row .sidebar-signout { width: auto; }
.sidebar-version {
  padding-right: var(--sidebar-gutter); font-size: 11px;
  color: var(--sidebar-text-faint); letter-spacing: 0.02em;
}

.nav-avatar {
  width: 24px; height: 24px; border-radius: 999px; background: var(--sidebar-accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; flex-shrink: 0;
}

/* ------------------------------------------------------------- topbar */
/* Desktop: the sidebar is its own navigation, so no topbar is needed --
   unless the rail has been collapsed away, in which case this is the only
   thing left that can bring it back. Mobile: the sidebar is off-canvas, so
   this carries the app label + the toggle that reveals it. */
.sidebar-overlay { display: none; }
.topbar {
  display: none; align-items: center; gap: 12px; height: 48px; padding: 0 14px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.topbar-menu-btn {
  font-size: 19px; line-height: 1; color: var(--text-soft); cursor: pointer; padding: 4px;
  background: none; border: none; box-shadow: none; border-radius: var(--radius-sm);
}
.topbar-menu-btn:hover { background: var(--panel-2); color: var(--text); }
.topbar-menu-btn:active { transform: none; }
.topbar-brand { font-weight: 700; font-size: 15px; color: var(--text); }
/* Only ever one of the two menu controls: the label drives the CSS-only
   off-canvas checkbox (mobile), the button drives the stored collapse
   (wide screens). Default here is the wide-screen pair. */
.topbar > .topbar-menu-btn:not(.topbar-expand-btn) { display: none; }

html[data-sidebar="collapsed"] .sidebar { display: none; }
html[data-sidebar="collapsed"] .topbar { display: flex; }

@media (max-width: 760px) {
  body { display: block; }
  /* Off-canvas already gives the screen back here, so the stored collapse
     must not also apply -- it would hide the rail with no way to open it. */
  .sidebar, html[data-sidebar="collapsed"] .sidebar {
    display: flex; position: fixed; top: 0; left: 0; height: 100vh; z-index: 40;
    transform: translateX(-100%); transition: transform .18s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar-toggle-checkbox:checked ~ .sidebar { transform: translateX(0); }
  .sidebar-toggle-checkbox:checked ~ .sidebar-overlay {
    display: block; position: fixed; inset: 0; background: rgba(16, 20, 30, 0.4); z-index: 35;
  }
  .topbar { display: flex; }
  .topbar > .topbar-menu-btn:not(.topbar-expand-btn) { display: block; }
  .topbar-expand-btn, .sidebar-collapse-btn { display: none; }
}

/* -------------------------------------------------------------- type */
/* v2 p.11 exact scale -- page title/H1 28/36 600, section/H2 20/28 600,
   subsection/H3 17/24 600. Weight 600 rather than the house 650/700 this
   used before: the guide is explicit that 400/500/600/700 are the only
   weights in use. */
h1 { font-size: 28px; line-height: 36px; font-weight: 600; margin: 4px 0 8px; letter-spacing: -0.015em; }
h2 { font-size: 20px; line-height: 28px; font-weight: 600; margin: 0 0 12px; letter-spacing: -0.005em; }
h3 { font-size: 17px; line-height: 24px; font-weight: 600; margin: 0 0 8px; }
.sub { color: var(--text-soft); margin: 0 0 22px; font-size: 14px; }

/* -------------------------------------------------------------- cards */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px; margin-bottom: 16px; box-shadow: var(--shadow-sm);
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 700px) { .grid-2 { grid-template-columns: 1fr; } }

.stat-row { display: flex; gap: 12px; flex-wrap: wrap; margin: 18px 0 22px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px 20px; min-width: 128px; box-shadow: var(--shadow-sm);
}
.stat .num { font-size: 25px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.stat .label { color: var(--text-soft); font-size: 12.5px; margin-top: 2px; }

/* ------------------------------------------------------------- forms */
/* v2 p.18 field anatomy: label above the control, helper text below/
   before, error beside the field -- this file's part of that contract is
   just making sure the label always renders first and stays visible
   (nothing here truncates or hides it), which it already did. */
label { display: block; margin: 14px 0 5px; font-size: 13px; font-weight: 600; color: var(--text-soft); }
.fineprint { font-weight: 400; color: var(--text-faint); }
/* v2 p.18: at least 44px height, 12px inner horizontal padding, visible
   border, 16px default entry text. Measured before changing this: text
   inputs already cleared 44px on this app's line-height, but <select>
   rendered at 43px -- one pixel under, browser-dependent rather than
   something the old padding number guaranteed. min-height makes it a
   real floor instead of an emergent side effect of unrelated CSS. */
input[type=text], input[type=email], input[type=password], input[type=date], textarea, select {
  width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--panel); color: var(--text); font: inherit; transition: border-color .12s, box-shadow .12s;
}
/* v2 p.3/p.17: the changelog explicitly names this pattern -- a
   translucent box-shadow glow instead of a real outline -- as one of the
   two things v2 replaces from v1. border-color still gives pointer users
   a highlight; the outline below is the actual accessibility-relevant
   part, and only shows for keyboard/programmatic focus.
   border-color is --action (navy/soft-blue), not --accent (orange): once
   orange became a sparingly-used focal color (p.16), every input glowing
   orange on click no longer fit -- an engaged field now reads with the
   same color as an engaged button. */
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--action); }
a:focus-visible, button:focus-visible, .btn:focus-visible,
input:focus-visible, textarea:focus-visible, select:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--link); outline-offset: 4px;
}
textarea { min-height: 84px; resize: vertical; }
input[type=checkbox], input[type=radio] { width: auto; margin-right: 6px; accent-color: var(--accent); flex-shrink: 0; }
/* v2 p.18: "Labels are clickable, and the full label area contributes to
   the target." .check is applied to a <label> wrapping its checkbox (see
   the templates), not a bare <div> -- that's what makes clicking the
   sentence next to the box actually toggle it, not just the box itself. */
.check { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text); margin: 8px 0; cursor: pointer; }
/* v2 p.18: "Do not indicate failure with a red border alone" -- read as
   "not ALONE": a border plus a connected, visible message is the right
   combination, which is what these two rules do together. invalid uses
   aria-invalid to double as the accessibility hook and the visual one,
   so a screen reader and a sighted user learn the same thing the same way. */
input[aria-invalid=true], textarea[aria-invalid=true], select[aria-invalid=true] {
  border-color: var(--danger);
}
.field-error {
  display: flex; align-items: baseline; gap: 5px;
  color: var(--danger); font-size: 12.5px; font-weight: 500; margin: 5px 0 0;
}

/* ----------------------------------------------------------- buttons */
/* v2 p.16: Primary is navy with white text in Signature; soft blue with
   navy text in Midnight. --action/--on-action carry that per theme (see
   the token block above) -- this is the actual primary-button spec, not
   --accent, which every button used before this pass. */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--action); color: var(--on-action); border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 9px 16px; font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none;
  box-shadow: var(--shadow-sm); transition: background .12s, box-shadow .12s, transform .05s;
}
button:hover, .btn:hover { background: var(--action-hover); text-decoration: none; }
button:active, .btn:active { transform: translateY(1px); }
button:disabled, .btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--line-strong); }
.btn-secondary:hover { background: var(--panel-3); }
.btn-danger { background: var(--danger-fill); color: #ffffff; }
.btn-danger:hover { background: var(--danger-fill); filter: brightness(0.88); }
/* v2 p.16: orange-filled actions used sparingly, with navy text and a
   contrasting boundary. The one place --accent is still a button fill,
   opt-in per call site for the rare single focal action a page wants to
   raise above its own primary button, not applied automatically anywhere. */
.btn-accent { background: var(--accent); color: #102b46; border: 1px solid #102b46; }
.btn-accent:hover { background: var(--accent-2); }
.btn-small { padding: 5px 11px; font-size: 12.5px; }
.linklike {
  background: none; border: none; color: var(--link); font: inherit; font-size: inherit;
  cursor: pointer; padding: 0; text-decoration: underline;
}

/* ------------------------------------------------------------- flash */
.flash { padding: 11px 15px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 13.5px; font-weight: 500; }
.flash.success { background: var(--ok-soft); color: var(--ok); border: 1px solid color-mix(in srgb, var(--ok) 35%, transparent); }
.flash.error { background: var(--danger-soft); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); }
.flash.warning { background: var(--warn-soft); color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); }

/* ------------------------------------------------------------- toast */
.toast-region {
  position: fixed; top: 16px; right: 16px; z-index: 95;
  display: flex; flex-direction: column; gap: 10px;
  width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--ok);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); padding: 12px 10px 12px 14px;
  font-size: 13.5px; font-weight: 500; color: var(--text);
  pointer-events: auto;
  opacity: 0; transform: translateY(-6px);
  transition: opacity 180ms ease, transform 180ms ease;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast-msg { flex: 1; padding-top: 1px; }
.toast-close {
  background: none; border: none; box-shadow: none; padding: 2px 6px;
  font: inherit; font-size: 17px; line-height: 1; color: var(--text-soft); cursor: pointer;
}
.toast-close:hover { background: var(--panel-2); color: var(--text); }
.toast-close:active { transform: none; }
@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}

/* --------------------------------------------------------- confirm dialog */
.confirm-dialog {
  width: clamp(480px, 90vw, 560px);
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  padding: 0; margin: auto; border: none; border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); background: var(--panel); color: var(--text);
}
.confirm-dialog::backdrop { background: rgba(16, 20, 30, 0.4); }
.confirm-dialog-body {
  display: flex; flex-direction: column; gap: 22px;
  padding: 26px; max-height: calc(100vh - 32px); overflow-y: auto;
}
.confirm-dialog-msg { margin: 0; font-size: 15px; line-height: 1.55; color: var(--text); }
.confirm-dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }
@media (max-width: 560px) {
  .confirm-dialog { width: calc(100vw - 32px); }
  .confirm-dialog-actions { flex-direction: column-reverse; }
  .confirm-dialog-actions button { width: 100%; }
}

/* -------------------------------------------------------------- tooltip */
.tooltip-bubble {
  position: fixed; z-index: 100; max-width: 260px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); padding: 6px 10px; font-size: 12.5px; line-height: 1.4;
  color: var(--text); pointer-events: none;
}

/* ---------------------------------------------------------- dropzone */
.dropzone {
  border: 2px dashed var(--line-strong); border-radius: var(--radius); padding: 38px 20px; text-align: center;
  color: var(--text-soft); margin-bottom: 16px; transition: border-color .15s, background .15s;
}
.dropzone.drag-active { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .btn { margin-top: 8px; }

/* -------------------------------------------------------------- misc */
.item { border-bottom: 1px solid var(--line); padding: 13px 0; }
.item:last-child { border-bottom: none; }
.item .meta { color: var(--text-faint); font-size: 12px; margin-top: 3px; }
.md-content p { margin: 0 0 8px; }
.md-content p:last-child { margin-bottom: 0; }
.md-content ul, .md-content ol { margin: 4px 0 8px; padding-left: 20px; }
.md-content li { margin: 2px 0; }
.md-content strong { color: var(--text); }
.md-content code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; font-size: 0.92em; }
.md-content pre { background: var(--panel-2); padding: 8px 10px; border-radius: 6px; overflow-x: auto; }
.md-content blockquote { margin: 6px 0; padding-left: 10px; border-left: 2px solid var(--line); color: var(--text-soft); }

.badge {
  display: inline-flex; align-items: center; font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  background: var(--panel-2); color: var(--text-soft); border: 1px solid transparent; letter-spacing: 0.01em;
}
.badge.open { color: var(--warn); background: var(--warn-soft); }
.badge.answered, .badge.done { color: var(--ok); background: var(--ok-soft); }
.badge.queued { color: var(--accent-2); background: var(--accent-soft); }
.badge.dismissed { text-decoration: line-through; opacity: 0.7; }

/* v2 p.11's own type-scale row for this: "UI label / dense table: 14/20px;
   500 labels; 400 cell content." Headers were 11px uppercase (smaller
   than the 14px minimum body text p.19 also names) and cells were 13.5 --
   both real, checkable misses against a spec that gives exact numbers,
   not a house approximation of them. Sentence case now, not uppercase --
   the guide's own table example shows "Request / Status / Owner", not
   small caps, and it's the header's weight and color doing the
   structural-label job now, the same as everywhere else in this app. */
table { width: 100%; border-collapse: collapse; }
/* p.19: "12-16px cell padding" -- 12px matches the number already chosen
   for form-control padding a few rules up, so a table's own leftmost
   text lines up with a field's on the same page. */
th, td { text-align: left; padding: 12px; border-bottom: 1px solid var(--line); font-size: 14px; line-height: 20px; }
th { color: var(--text-soft); font-weight: 500; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--panel-2); }

/* p.19: "expose sort state in the header." aria-sort carries the state
   for assistive tech; the glyph is the same state for sighted users. */
th[data-sort-key] { cursor: pointer; user-select: none; }
th[data-sort-key]:hover { color: var(--text); }
th[data-sort-key]::after { content: ''; display: inline-block; width: 12px; }
th[aria-sort="ascending"]::after { content: '▲'; font-size: 10px; margin-left: 4px; }
th[aria-sort="descending"]::after { content: '▼'; font-size: 10px; margin-left: 4px; }

/* p.19: "labeled filter controls ... and a clear result count." */
.table-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.table-filter { display: flex; align-items: center; gap: 8px; margin: 0; }
.table-filter input { width: auto; min-width: 220px; margin: 0; }
.table-filter-count { font-size: 13px; color: var(--text-soft); }

.qcard { background: var(--panel-2); border-radius: var(--radius); padding: 17px; margin-bottom: 14px; }
.qcard .origin { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.03em; font-weight: 650; }

.qa-progress { margin: 18px 0; }
.qa-progress-label { font-size: 13px; color: var(--text-soft); margin-bottom: 6px; }
.qa-progress-bar { height: 6px; border-radius: 999px; background: var(--panel-2); overflow: hidden; }
.qa-progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .2s ease; }

.qa-context {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 12px; margin: 6px 0 12px; font-size: 13px;
}
.qa-context-label { color: var(--text-soft); }
.qa-context-label a { color: var(--link); }
.qa-context-note { margin-top: 6px; font-weight: 600; }
.qa-context-snippet {
  margin: 8px 0 0; padding-left: 10px; border-left: 2px solid var(--line);
  color: var(--text-soft); font-style: italic; white-space: pre-wrap;
}

.progress-empty { color: var(--text-faint); text-align: center; padding: 34px 0; font-size: 14px; }

.report-section { margin-bottom: 22px; }
.report-section h3 { margin: 0 0 8px; font-size: 14.5px; color: var(--link); }
.report-section ul { margin: 0; padding-left: 20px; }
.recommendation-badge {
  display: inline-block; padding: 5px 14px; border-radius: 999px; font-weight: 700; font-size: 12.5px;
  background: var(--accent-soft); border: 1px solid transparent; color: var(--accent-2); letter-spacing: 0.01em;
}

/* -------------------------------------------------- Ask Knowledge Capture Pro -- chat */
.chat-shell {
  display: flex; flex-direction: column;
  height: calc(100vh - 190px); min-height: 420px;
}
.chat-thread {
  flex: 1; overflow-y: auto; padding: 6px 4px 18px;
  display: flex; flex-direction: column; gap: 16px;
}
.chat-empty { color: var(--text-faint); text-align: center; margin: auto; font-size: 14px; }
.chat-bubble-row { display: flex; flex-direction: column; max-width: 76%; }
@media (max-width: 640px) { .chat-bubble-row { max-width: 92%; } }
.chat-bubble-row.from-manager { align-self: flex-end; align-items: flex-end; }
.chat-bubble-row.from-knowledgepro { align-self: flex-start; align-items: flex-start; }
.chat-bubble {
  border-radius: 16px; padding: 11px 15px; white-space: pre-wrap; line-height: 1.5;
  box-shadow: var(--shadow-sm);
}
.chat-bubble-row.from-manager .chat-bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.chat-bubble-row.from-knowledgepro .chat-bubble { background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.chat-bubble-row.from-knowledgepro .chat-bubble.thinking { color: var(--text-soft); font-style: italic; }
.chat-bubble-row.from-knowledgepro .chat-bubble.failed { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.chat-meta { font-size: 11px; color: var(--text-faint); margin-top: 5px; }
.chat-composer {
  display: flex; gap: 10px; padding-top: 14px; border-top: 1px solid var(--line);
  position: sticky; bottom: 0; background: var(--bg);
}
.chat-composer textarea {
  flex: 1; resize: none; min-height: 46px; max-height: 160px; margin: 0;
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.chat-composer button { align-self: flex-end; }

/* --------------------------------------------------- auth (login/setup) */
.auth-shell {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 40px 20px;
}
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth-brand .auth-logo { height: 76px; width: auto; }
.auth-brand .auth-product { font-weight: 600; font-size: 15px; color: var(--text-soft); letter-spacing: 0.01em; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h1 { text-align: center; margin-top: 0; }
.auth-card .sub { text-align: center; }

/* ------------------------------------------- watch-a-window indicator */
/* Fixed rather than in-flow: in a browser tab the watch dies with this
   page, so whoever started it needs to see that it's running -- and be
   able to stop it -- without scrolling back to the card that started it. */
/* One container holding a row per active watch, so any number of them
   stack instead of landing on top of each other. */
.watch-indicator {
  position: fixed; right: 18px; bottom: 18px; z-index: 50;
  display: flex; flex-direction: column; gap: 8px;
  max-width: min(380px, calc(100vw - 36px));
  padding: 10px 12px;
  background: var(--panel); border: 1px solid var(--accent); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); font-size: 13px; color: var(--text);
}
.watch-indicator-row { display: flex; align-items: center; gap: 10px; }
.watch-indicator .watch-dot {
  flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--accent);
}
.watch-indicator .watch-label {
  flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ------------------------------------------------------------- errors */
.error-card { max-width: 440px; margin: 64px auto; text-align: center; }
.error-card .error-code { font-size: 13px; font-weight: 700; letter-spacing: 0.06em; color: var(--text-faint); text-transform: uppercase; }
.error-card h1 { margin: 6px 0 8px; }
.error-card .sub { margin: 0 0 20px; }

/* --------------------------------------------- workflow designer canvas */
/* A whiteboard, not a scrolling document: the stage is a fixed viewport
   and the graph is panned and zoomed inside it (see workflow_designer.html's
   #wf-viewport transform). A left-to-right process is routinely wider than
   any screen, and dragging a 3,000px scrollbar is not navigation. */
.wf-stage {
  position: relative; display: flex; align-items: stretch;
  flex: 1; min-height: 0;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
}
.wf-stage:fullscreen { height: 100vh; margin-top: 0; border: none; border-radius: 0; }
#wf-canvas { display: block; flex: 1; min-width: 0; height: 100%; cursor: grab; }
#wf-canvas.panning { cursor: grabbing; }

.wf-toolbar {
  position: absolute; left: 12px; bottom: 12px; z-index: 2;
  display: flex; gap: 6px; align-items: center;
  background: var(--panel); padding: 6px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-sm);
}
.wf-toolbar button { white-space: nowrap; }

/* Floats over the canvas instead of taking a column, so the graph gets the
   full width. Hidden until a step is selected -- renderPanel() sets the
   inline display, this is only the resting state. */
/* Docked, not floating: a full-height column beside the canvas. Floating
   it over the graph meant it covered the very node you had just clicked
   and needed its own scrollbar for a form that fits a screen easily. As a
   flex sibling it takes width from the canvas instead, which is what makes
   the graph appear to slide left when a step opens. */
.wf-panel {
  flex: 0 0 360px; height: 100%; overflow-y: auto; z-index: 3;
  display: none; margin: 0; border: none; border-radius: 0;
  /* A real edge, not a hairline: this separates two different modes of
     interaction (a canvas you drag, a form you fill), so it should read as
     a wall. The inset shadow gives the canvas side a soft falloff without
     drawing a second line. */
  border-left: 2px solid var(--line-strong);
  box-shadow: -8px 0 16px -10px rgba(16, 43, 70, 0.28);
}
.wf-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 4px;
}
.wf-panel-head h2 { margin: 0; }
.wf-panel-close {
  background: none; border: none; box-shadow: none; padding: 2px 6px;
  font: inherit; font-size: 18px; line-height: 1; color: var(--text-soft); cursor: pointer;
}
.wf-panel-close:hover { background: var(--panel-2); color: var(--text); }
.wf-panel-close:active { transform: none; }
@media (max-width: 900px) {
  /* Too narrow to give up 360px, so it goes back to overlaying. */
  .wf-panel { position: absolute; top: 0; right: 0; flex: none; width: 320px; box-shadow: var(--shadow-lg); }
}

/* Both clamped: a fixed-height node with unclamped text slices the last
   line in half, which reads as a rendering bug rather than as truncation. */
.wf-node-title {
  font-weight: 600; margin-top: 4px; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.wf-node-sub {
  color: var(--text-soft); font-size: 11px; margin-top: 3px; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
/* Badges on their own tight row: inside the node's 13px text they'd
   otherwise claim a full 1.55 line box and push the clamped title and
   instructions past the bottom of a fixed-height box. */
.wf-node-tags { line-height: 1; margin-bottom: 2px; }
.wf-node-tags .badge { font-size: 10px; }

/* The designer runs edge to edge and fills the viewport: the canvas is the
   page, not a widget on it. Set via base.html's wrap_class block so no
   other page is affected. True OS fullscreen still needs the toolbar
   button -- browsers refuse requestFullscreen() without a user gesture,
   so "full screen on load" is not something a page can do to itself. */
.wrap.wrap-canvas {
  max-width: none; padding: 0;
  height: 100vh; display: flex; flex-direction: column;
}
.wrap.wrap-canvas > .flash { margin: 10px 14px 0; }
.wf-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 10px 12px; padding: 10px 14px;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.wf-header-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.wf-header-title h1 {
  margin: 0; font-size: 17px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 40vw;
}
.wf-header-title .sub { margin: 0; font-size: 12.5px; }
.wf-back { font-size: 17px; color: var(--text-soft); padding: 0 2px; }
.wf-back:hover { color: var(--text); text-decoration: none; }
.wf-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.wf-stage { border-left: none; border-right: none; border-bottom: none; border-radius: 0; }

/* Drag one of these from a step to another step to create a transition.
   Drawn as an SVG circle rather than inside the node's div, which has
   overflow:hidden and would clip anything on its edge. */
.wf-handle {
  fill: var(--accent); stroke: var(--panel); stroke-width: 2;
  cursor: crosshair; opacity: 0.55; transition: opacity .12s, r .12s;
}
.wf-handle:hover { opacity: 1; }
/* Every handle lights up while a connection is in flight, so it reads as
   "these are the things you can aim at" rather than leaving the target
   ambiguous mid-drag. */
.wf-stage.connecting .wf-handle { opacity: 1; }
.wf-stage.connecting #wf-canvas { cursor: crosshair; }
