/* DMS visual design. Tokens first; every component uses them. */
:root {
  --bg: #f4f5f9;
  --card: #ffffff;
  --text: #1c2230;
  --text-2: #3d4657;
  --muted: #6b7382;
  --line: #e6e8ef;
  --line-strong: #d6d9e3;
  --accent: #3f4fd8;
  --accent-2: #7b86ee;
  --accent-3: #98b7ff;
  --accent-soft: #eef0fd;
  --accent-text: #ffffff;
  --gradient: linear-gradient(90deg, #4148d6 0%, #7b86ee 100%);
  /* Bloom around the active nav tab. Biased upward: the bar sits on the topbar's bottom edge,
     and an even spread would smudge the light page below it. */
  --glow: 0 0 4px rgba(179, 187, 255, 0.95), 0 -3px 12px rgba(161, 171, 255, 0.7), 0 -6px 22px rgba(80, 97, 255, 0.5);
  --topbar: #1f2233;
  --topbar-text: #ffffff;
  --topbar-muted: #8f95a8;
  --error: #c1352b;
  --ok: #1d7a4f;
  --ok-soft: #e4f4ea;
  --warn: #b25b0f;
  --warn-soft: #fff1e1;
  --danger-soft: #fdeae7;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 2px 6px rgba(28, 34, 48, .04), 0 12px 32px rgba(28, 34, 48, .06);
  /* Open Sans is self-hosted under vendor/opensans; the rest catches the moment
     before it loads and any browser that refuses woff2. */
  font-family: 'Open Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; } /* beats any display rule below */
html { background: var(--bg); }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h2, h3 { font-weight: 650; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: .92rem; }
.error { color: var(--error); }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: stretch; gap: 1.5rem; padding: 0 2rem; height: 64px; background: var(--topbar); color: var(--topbar-text); }
.topbar .brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.55rem; letter-spacing: -.03em; color: var(--topbar-text); margin-right: .5rem; }
.brand .mark { width: 1.5em; height: 1.5em; flex: none; display: block; }
.brand-lg { display: flex; align-items: center; gap: .7rem; font-weight: 700; font-size: 2rem; letter-spacing: -.03em; color: var(--text); }
.topbar .brand:hover { text-decoration: none; }
.topbar nav { display: flex; gap: .25rem; }
.topbar nav a { display: flex; align-items: center; padding: 0 .9rem; color: var(--topbar-text); font-weight: 500; font-size: 1.02rem; position: relative; }
.topbar nav a:hover { text-decoration: none; color: #fff; }
.topbar nav a.active::after { content: ""; position: absolute; left: .9rem; right: .9rem; bottom: 0; height: 5px; border-radius: 3px; background: var(--accent-3); box-shadow: var(--glow); }
.topbar nav a[aria-disabled="true"] { color: var(--topbar-muted); cursor: default; }
.topbar .spacer { flex: 1; }
.topbar #me { display: flex; align-items: center; color: #cfd3e0; }
.topbar form { display: flex; align-items: center; }
.topbar button.link { color: #8fa2ff; font-weight: 600; font-size: 1rem; }
/* The menu is a plain part of the bar until there is no room for it; display:
   contents keeps the wrapper out of the layout entirely on a wide screen. */
.topbar-menu { display: contents; }
.nav-toggle { display: none; background: none; border: 0; padding: 0; color: var(--topbar-text); cursor: pointer; }

@media (max-width: 1024px) {
  .topbar { gap: .75rem; padding: 0 1rem; position: relative; }
  .nav-toggle { display: inline-flex; align-items: center; justify-content: center; align-self: center; margin-left: auto;
    width: 44px; height: 44px; font-size: 1.35rem; border-radius: 10px; }
  .nav-toggle:hover { background: rgba(255, 255, 255, .09); filter: none; }
  .nav-toggle:active { transform: none; }
  /* The panel hangs under the bar rather than pushing the page down, so opening
     it never moves the content behind it. */
  .topbar-menu { display: none; position: absolute; top: 64px; left: 0; right: 0; z-index: 50;
    flex-direction: column; align-items: stretch; padding: .5rem 0 .75rem;
    background: var(--topbar); border-top: 1px solid rgba(255, 255, 255, .1);
    box-shadow: 0 14px 30px rgba(0, 0, 0, .35);
    max-height: calc(100vh - 64px); overflow-y: auto; }
  .topbar-menu.open { display: flex; }
  .topbar-menu .spacer { display: none; }
  .topbar nav { flex-direction: column; gap: 0; }
  .topbar nav a { padding: .8rem 1.25rem; font-size: 1.05rem; }
  /* Stacked, there is no bottom edge for the marker to sit on: it moves to the left. */
  .topbar nav a.active::after { left: 0; right: auto; top: .35rem; bottom: .35rem; width: 5px; height: auto; border-radius: 0 3px 3px 0;
    /* --glow leans upward for a bar sitting under the text; upright against the
       panel edge it has to lean inward instead. */
    box-shadow: 0 0 4px rgba(139, 150, 255, .95), 3px 0 12px rgba(123, 134, 238, .7), 6px 0 22px rgba(95, 110, 255, .5); }
  .topbar #me { padding: .9rem 1.25rem .5rem; margin-top: .4rem; border-top: 1px solid rgba(255, 255, 255, .1); }
  .topbar form { padding: 0 1.25rem .3rem; }
}
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
button.link:hover { text-decoration: underline; }
button.link:disabled:hover { text-decoration: none; }

/* ---------- layout & cards ---------- */
/* minmax(0, 1fr): grid items default to min-width:auto, which would let a wide
   table stretch its card past max-width and scroll the whole page sideways. */
main { max-width: 1280px; margin: 2rem auto; padding: 0 1.25rem; display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.5rem; }
main > * { min-width: 0; }
.card { background: var(--card); border: 0; border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.75rem 2rem 2rem; }
.card h2 { margin: 0 0 1rem; font-size: 1.45rem; }
.card h3 { margin: 1.25rem 0 .5rem; font-size: 1.05rem; }
.card-head { display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.card-head h2 { margin: 0; }
.card-head .spacer { flex: 1; }
.crumbs { margin: 0; color: var(--muted); }

/* ---------- buttons ---------- */
button, .btn { background: var(--gradient); color: var(--accent-text); border: 0; border-radius: var(--radius-sm); padding: .7rem 1.4rem; font: inherit; font-weight: 600; font-size: 1rem; cursor: pointer; transition: filter .15s, transform .05s; }
button:hover { filter: brightness(1.06); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .55; cursor: default; }
button.secondary { background: var(--card); color: var(--text); border: 1px solid var(--line-strong); }
button.secondary:hover { background: #f7f8fb; filter: none; }
button.small-btn { padding: .4rem .8rem; font-size: .88rem; margin-top: .45rem; }
button.link.danger { color: var(--error); font-weight: 500; }

/* ---------- inputs ---------- */
input, select, textarea { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: .7rem .9rem; min-width: 0; }
input::placeholder, textarea::placeholder { color: #9aa1b1; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-2); outline-offset: 0; border-color: var(--accent-2); }
select { appearance: none; -webkit-appearance: none; padding-right: 2.2rem; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' fill='none' stroke='%233d4657' stroke-width='1.8' stroke-linecap='round'/></svg>"); background-repeat: no-repeat; background-position: right .9rem center; }
input[type="date"] { color: var(--text-2); }

/* ---------- upload ---------- */
.dropzone { border: 2px dashed #c9cff2; border-radius: 14px; padding: 2.4rem 1rem 2rem; text-align: center; background: #fbfbfe; transition: border-color .15s, background .15s; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone:focus { outline: 2px solid var(--accent-2); }
.dropzone .icon { font-size: 2.6rem; margin: 0 auto .7rem; display: block; width: fit-content; color: var(--accent); }
.dropzone p { margin: .3rem 0; }
.dropzone p:first-of-type { font-size: 1.2rem; }
.dropzone p strong { font-weight: 650; }
.link-label { color: var(--accent); cursor: pointer; font-weight: 600; }
.link-label:hover { text-decoration: underline; }
.inline { display: inline-flex; gap: .75rem; align-items: center; margin-top: 1rem; color: var(--text-2); }
.inline select { padding: .6rem 2.2rem .6rem 1rem; }
.upload-list { list-style: none; padding: 0; margin: 1rem 0 0; display: grid; gap: .4rem; }
.upload-item { display: grid; grid-template-columns: minmax(0, 1fr) 180px minmax(0, 1.2fr); gap: .75rem; align-items: center; font-size: .92rem; }
.upload-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-item.ok span:last-child { color: var(--ok); }
.upload-item.error { color: var(--error); grid-template-columns: 1fr; }
.upload-item.error span:last-child { color: var(--error); }
progress { width: 100%; height: 8px; accent-color: var(--accent); border-radius: 4px; overflow: hidden; }

/* ---------- filters ---------- */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .8rem; margin: 1rem 0 1.25rem; align-items: center; }
.input-icon { position: relative; display: block; }
.input-icon > i { position: absolute; left: .95rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; font-size: .9rem; }
.input-icon > input { width: 100%; padding-left: 2.5rem; }
.filters .grow { grid-column: span 2; }
.filters button { width: 100%; }
@media (max-width: 640px) { .filters { grid-template-columns: 1fr 1fr; } .filters .grow { grid-column: span 2; } }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 1rem; }
.table th { text-align: left; color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .12em; padding: .7rem .8rem; border-bottom: 1px solid var(--line); }
.table td { padding: .9rem .8rem; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
.table td.wrap { white-space: normal; }
.table tbody tr:hover td { background: #fafbfe; }
.table tr:last-child td { border-bottom: 0; }
.table td a { font-weight: 600; }
.table .num, .table th.num { text-align: right; }
/* max-width:0 lets these columns absorb the leftover width and ellipsize,
   instead of forcing the table wider than its card. */
.table .ellipsis { max-width: 0; min-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Name and Counterparty share whatever the fixed-content columns leave, in
   this ratio; Name gets the larger share because file names are long. */
#doc-table th:nth-child(1), #doc-table td:nth-child(1) { width: 38%; }
#doc-table th:nth-child(6), #doc-table td:nth-child(6) { width: 20%; }
/* Workflows: fixed layout; the small columns are sized in pixels (Chrome resolves
   percentage <col> widths inconsistently) so Name takes the remainder — 60% at
   the card's full width, more on wider screens. */
#wf-table { table-layout: fixed; min-width: 900px; }
#wf-table th, #wf-table td { padding-left: .4rem; padding-right: .4rem; }
#wf-table .actions > * { margin-left: .45rem; }
#wf-table td { overflow: hidden; text-overflow: ellipsis; }
#wf-table td.ellipsis { min-width: 0; }
#wf-table th:nth-child(1), #wf-table td:nth-child(1) { width: 100%; min-width: 640px; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions > * { margin-left: .85rem; font-weight: 500; }
.table.edit input, .table.edit select { width: 100%; min-width: 80px; padding: .45rem .6rem; border-radius: 8px; }
.pager { display: flex; gap: 1rem; align-items: center; justify-content: flex-end; margin-top: 1rem; }
.pager button { padding: .5rem 1rem; font-size: .9rem; }

/* ---------- badges & stats ---------- */
.badge { display: inline-block; padding: .2rem .75rem; border-radius: 999px; font-size: .84rem; font-weight: 500; background: #eef0f3; color: var(--muted); }
.badge.status-new { background: var(--accent-soft); color: var(--accent); }
.badge.status-processing, .badge.status-review { background: var(--warn-soft); color: var(--warn); }
.badge.status-done { background: var(--ok-soft); color: var(--ok); }
.badge.status-failed { background: var(--danger-soft); color: var(--error); }
.stats { display: flex; gap: 2.5rem; margin: .5rem 0 1rem; }
.stats div { display: grid; }
.stats dt { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .12em; font-weight: 600; }
.stats dd { margin: 0; font-size: 1.7rem; font-weight: 650; }
.row, #debug-tools { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }

/* ---------- login ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; }
.login-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 2.5rem; width: min(400px, 92vw); display: grid; gap: .9rem; }
.login-card h1 { margin: 0; font-size: 2rem; letter-spacing: -.02em; }
.login-card .brand-lg { margin-bottom: .1rem; }
.login-card p { margin: 0; }
.login-card form { display: grid; gap: .9rem; margin-top: .5rem; }
.login-card label { display: grid; gap: .35rem; font-size: .92rem; color: var(--text-2); }
.login-card button { margin-top: .25rem; }

/* ---------- detail ---------- */
.meta { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .9rem 1.5rem; margin: 1.25rem 0; }
.meta div { display: grid; gap: .15rem; }
.meta dt { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .12em; font-weight: 600; }
.meta dd { margin: 0; font-size: 1.02rem; }
/* A property list: one row per property, label on the left, value on the right. */
.props { margin: 1.25rem 0; max-width: 46rem; border-top: 1px solid var(--line); }
.props div { display: grid; grid-template-columns: 9.5rem minmax(0, 1fr); gap: 1rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.props dt { color: var(--muted); }
.props dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 640px) { .props div { grid-template-columns: 1fr; gap: .15rem; } }
/* The property list with a side panel (the document summary) to its right. */
.props-layout { display: grid; grid-template-columns: minmax(0, 46rem) minmax(0, 1fr); gap: 1rem 2.5rem; align-items: start; margin: 1.25rem 0; }
.props-layout .props { margin: 0; }
.props-layout h3 { margin-top: .6rem; }
@media (max-width: 900px) { .props-layout { grid-template-columns: 1fr; } }
.prewrap { white-space: pre-wrap; color: var(--text-2); }
.exform { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .9rem 1.2rem; margin: 1rem 0 1.25rem; }
.exform .field { display: grid; gap: .3rem; }
.exform .field > span { color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
.exform .field.wide, .exform fieldset.nested { grid-column: 1 / -1; }
.exform input, .exform select, .exform textarea { width: 100%; }
.exform fieldset.nested { border: 1px solid var(--line); border-radius: 12px; padding: .75rem 1rem 1rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .75rem 1.2rem; margin: 0; }
.exform legend { color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; padding: 0 .4rem; }
.history { list-style: none; padding: 0; margin: .5rem 0 0; display: grid; gap: .45rem; font-size: .95rem; }

/* ---------- search ---------- */

/* ---------- ask ---------- */
.ask-layout { display: grid; grid-template-columns: minmax(0, 280px) minmax(0, 1fr); gap: 1.5rem; align-items: start; }
.ask-layout > * { min-width: 0; }
@media (max-width: 860px) { .ask-layout { grid-template-columns: 1fr; } }
.conv-list { list-style: none; padding: 0; margin: .5rem 0 0; display: grid; gap: .6rem; }
.conv-list li { display: grid; font-size: .95rem; }
.conv-list li a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.conv-list li.active a { font-weight: 650; }
.chat { display: grid; gap: 1rem; margin: 1.25rem 0; max-height: 60vh; overflow-y: auto; padding-right: .25rem; }
.msg { display: grid; gap: .35rem; max-width: 85%; }
.msg.user { justify-self: end; }
.msg .bubble { padding: .8rem 1rem; border-radius: 14px; background: #f1f2f7; line-height: 1.5; }
.msg.user .bubble { background: var(--gradient); color: var(--accent-text); border-bottom-right-radius: 4px; }
.msg.assistant .bubble { border-bottom-left-radius: 4px; }
.msg.error .bubble { background: var(--danger-soft); color: var(--error); }
.msg .cite { font-size: .8rem; background: #fff; border: 1px solid var(--line-strong); border-radius: 6px; padding: .05rem .4rem; margin-left: .2rem; font-weight: 600; }
.trace { font-size: .82rem; color: var(--muted); }
.trace summary { cursor: pointer; }
.trace-item { margin: .25rem 0 0 .5rem; }
.trace-item code { font-size: .78rem; word-break: break-all; }
.ask-form { display: flex; gap: .75rem; align-items: flex-end; }
.ask-form textarea { flex: 1; resize: vertical; border-radius: 14px; padding: .9rem 1rem; }
.table-wrap { overflow-x: auto; min-width: 0; max-width: 100%; }

/* ---------- icons (Font Awesome, vendored) ---------- */
button > i, a > i, .link-label > i, .topbar nav a > i, .status > i, .card-head a > i, .small > i { margin-right: .5rem; }
button > i.trail { margin-right: 0; margin-left: .5rem; }
.topbar nav a > i { font-size: .95rem; opacity: .9; }
.table .actions i { margin-right: .35rem; font-size: .9rem; }
.trace-item i { margin-right: .3rem; }

/* ---------- search results inside the list ---------- */
.table tr.snippet-row td { padding-top: 0; border-bottom: 1px solid var(--line); white-space: normal; }
.table tr.snippet-row + tr td { border-top: 0; }
.table tr:has(+ tr.snippet-row) td { border-bottom: 0; }
.table .snippet { margin: 0 0 .25rem; font-size: .92rem; color: var(--text-2); }
.table .snippet i { margin-right: .35rem; }

/* ---------- document types (settings) ---------- */
input[readonly] { background: #f5f6fa; color: var(--muted); }
.table code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9rem; background: #f1f2f7; padding: .1rem .4rem; border-radius: 5px; }

/* ---------- list: search bar, sortable headers, filter popovers, chips ---------- */
.searchbar { display: flex; gap: .8rem; margin: 1rem 0 .75rem; align-items: center; flex-wrap: wrap; }
.searchbar .grow { flex: 1; min-width: 260px; }
.chips { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .75rem; }
.chips:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: .4rem; padding: .25rem .4rem .25rem .7rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: .85rem; font-weight: 500; }
.chip button { background: none; border: 0; color: inherit; padding: 0 .2rem; font-size: .8rem; line-height: 1; cursor: pointer; }
.chip button i { margin: 0; }
.table th { white-space: nowrap; }
.th-sort { background: none; border: 0; padding: 0; color: inherit; font: inherit; font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .12em; cursor: pointer; display: inline-flex; align-items: center; gap: .4rem; }
.th-sort i { margin: 0; font-size: .72rem; line-height: 1; vertical-align: middle; }
.th-sort:hover, .th-sort.active { color: var(--text); }
.th-sort.active i { color: var(--accent); }
.th-filter { background: none; border: 0; padding: .1rem .3rem; margin-left: .35rem; color: #b8bdcb; cursor: pointer; font-size: .78rem; border-radius: 4px; }
.th-filter i { margin: 0; }
.th-filter:hover { color: var(--text); background: var(--accent-soft); }
.th-filter.active { color: var(--accent); }
.popover { z-index: 50; min-width: 240px; background: var(--card); border: 1px solid var(--line-strong); border-radius: 12px; box-shadow: var(--shadow); padding: .9rem 1rem; text-transform: none; letter-spacing: 0; font-weight: 400; font-size: .95rem; color: var(--text); text-align: left; white-space: normal; }
.popover-title { font-weight: 600; margin-bottom: .6rem; }
.popover-body { display: grid; gap: .5rem; }
.popover-body label { display: grid; grid-template-columns: 3.2rem 1fr; align-items: center; gap: .4rem; color: var(--muted); font-size: .9rem; }
.popover-body input, .popover-body select { width: 100%; padding: .5rem .7rem; font-size: .95rem; }
.popover-actions { display: flex; gap: .5rem; margin-top: .75rem; }
.popover-actions .small-btn { margin-top: 0; }

/* ---------- forms ---------- */
.form-actions { grid-column: 1 / -1; display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-top: .25rem; }
.form-actions button { width: auto; }

/* ---------- workflows ---------- */
.badge.status-rejected { background: var(--danger-soft); color: var(--error); }
.badge.status-archived { background: #eef0f3; color: var(--muted); }
textarea.code, .code-view { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .86rem; line-height: 1.45; }
textarea.code { width: 100%; }
.code-view { background: #f7f8fb; border: 1px solid var(--line); border-radius: 10px; padding: 1rem; overflow-x: auto; margin: 0; white-space: pre; }
.problems:empty { display: none; }
.problems { display: grid; gap: .3rem; margin: .75rem 0; }
.problem { color: var(--error); font-size: .92rem; }
.problem code { background: var(--danger-soft); padding: .05rem .4rem; border-radius: 4px; margin-right: .3rem; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin: 1rem 0 1rem; }
.tab { background: none; border: 0; border-bottom: 3px solid transparent; border-radius: 0; color: var(--muted); padding: .6rem 1rem; font-weight: 600; }
.tab:hover { color: var(--text); filter: none; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-panel { min-height: 4rem; }
.nl { font-size: 1rem; line-height: 1.55; margin: 0; }
.nl-line { margin: .5rem 0 .4rem; }
.nl-line:first-child { margin-top: 0; }
.nl-list { margin: .35rem 0; padding-left: 1.2rem; display: grid; gap: .35rem; }
.nl-list li::marker { color: var(--muted); }
/* Flowchart canvas: dotted grid, centred diagram, soft shadowed nodes.
   Node fills/strokes come from the classDefs in the Mermaid source. */
/* Centred with auto margins, not flex: a centred flex child that overflows
   becomes unreachable on the left when the box scrolls. */
.chart { overflow-x: auto; padding: 1.5rem 1rem;
  border: 1px solid var(--line); border-radius: 14px;
  background-color: #fbfbfe;
  background-image: radial-gradient(circle, #d6dae7 1px, transparent 1.3px);
  background-size: 18px 18px; background-position: center center; }
.chart svg { max-width: 100%; height: auto; display: block; margin: 0 auto; }
.chart .node rect, .chart .node polygon, .chart .node circle, .chart .node ellipse, .chart .node path {
  rx: 10px; ry: 10px; stroke-width: 1.5px; stroke-linejoin: round;
  filter: drop-shadow(0 1px 2px rgba(28, 34, 48, .10)) drop-shadow(0 4px 10px rgba(28, 34, 48, .07)); }
.chart .node .nodeLabel { line-height: 1.35; }
/* Mermaid sizes edge-label boxes from the measured text, so only the colour
   is ours — changing the size or padding here clips the label. */
.chart .edgeLabel, .chart .edgeLabel p, .chart .edgeLabel span { color: var(--text-2); white-space: nowrap; }
.chart .edgeLabels foreignObject, .chart .edgeLabel { overflow: visible; }
.chart .flowchart-link, .chart .edgePath path { stroke-width: 1.5px; }
.chart .marker { stroke-width: 1px; }
.approve-card { width: min(560px, 94vw); }
.approve-card textarea { width: 100%; font: inherit; padding: .6rem .8rem; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); }
.approve-card label { display: grid; gap: .35rem; }
button.danger-btn { color: var(--error); border-color: #f1c4bf; }

/* ---------- designer ---------- */
.design-layout { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 1.5rem; align-items: start; }
@media (max-width: 1000px) { .design-layout { grid-template-columns: 1fr; } }
.design-layout > * { min-width: 0; }
.design-messages { max-height: 55vh; }
.msg .bubble.edit { background: var(--accent-soft); color: var(--accent); font-style: italic; }
.msg .bubble.attachment, .msg.user .bubble.attachment { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.msg .bubble.attachment > i { margin-right: .5rem; }
.switch { display: inline-flex; align-items: center; gap: .55rem; font-weight: 600; cursor: pointer; }
.switch input { width: 1.15rem; height: 1.15rem; margin: 0; accent-color: var(--accent); cursor: pointer; }
.switch input:disabled { cursor: default; }
.sample-box { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-top: .75rem; font-size: .92rem; }
.sample-box label.link { cursor: pointer; font-weight: 600; color: var(--accent); }
.sample-box label.link > i { margin-right: .45rem; }
.test-table td.low { color: var(--warn); font-weight: 600; }
.test-table .sub { margin: .25rem 0 .25rem 1rem; width: auto; font-size: .88rem; }
.dry-result .warn { color: var(--warn); margin: .25rem 0; }
.change { background: var(--accent-soft); color: var(--accent); border-radius: 10px; padding: .6rem .9rem; font-size: .92rem; margin: .5rem 0; }
.dryrun { border-top: 1px solid var(--line); margin-top: 1.25rem; padding-top: 1rem; }
.dryrun h3 { margin: 0 0 .6rem; }
.dryrun select { min-width: 280px; }
.dry-result { margin-top: .75rem; font-size: .92rem; }
.dry-result .ok { color: var(--ok); margin: .25rem 0; }
.dry-result .error { margin: .25rem 0; }
.dry-steps { margin: .25rem 0; padding-left: 1.4rem; display: grid; gap: .3rem; }
.dry-steps code { background: #f1f2f7; padding: .05rem .4rem; border-radius: 4px; font-size: .85rem; }

/* ---------- users ---------- */
.badge.role-admin { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.badge.role-superuser { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.badge.role-user { background: #eef0f3; color: var(--muted); }

/* ---------- icon-only actions ---------- */
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; padding: 0; border-radius: 7px; color: var(--accent); }
.icon-btn i { margin: 0; font-size: .95rem; }
.icon-btn:hover { background: var(--accent-soft); text-decoration: none; }
button.link.danger.icon-btn { color: var(--error); }
button.link.danger.icon-btn:hover { background: var(--danger-soft); }
#doc-table .actions > * { margin-left: .2rem; }

/* ---------- approvals ---------- */
.nav-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; margin-left: .45rem;
  padding: 0 .35rem; border-radius: 999px; background: #ef6461; color: #fff; font-size: .72rem; font-weight: 700; }
.approvals { display: grid; gap: .9rem; margin-top: .5rem; }
.approval { border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.1rem; display: grid; gap: .5rem; }
.approval:hover { border-color: var(--line-strong); }
.approval-head { display: flex; gap: .75rem; align-items: baseline; flex-wrap: wrap; }
.approval-head strong { font-size: 1.05rem; }
.approval .ap-comment { width: 100%; font: inherit; padding: .5rem .7rem; border: 1px solid var(--line-strong); border-radius: 8px; resize: vertical; }
.approval.overdue { border-left: 3px solid var(--error); }
.approval .task-body { margin: 0; }
.warn-text { color: var(--warn); margin: 0; }
.tk-tabs { margin: 0; border-bottom: 0; }
#ap-history { table-layout: fixed; min-width: 860px; }
#ap-history td.ellipsis { max-width: 0; }

/* ---------- workflow overview: the two readable views side by side ---------- */
.wf-actions { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin: .25rem 0 1.25rem; padding-bottom: 1.25rem; border-bottom: 1px solid var(--line); }
.wf-actions .link.danger { margin-left: auto; }
.wf-views { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.75rem; margin-top: .5rem; align-items: start; }
/* Workflow details as one running line: "Steps: 3, Version: 2, …". */
.meta-inline { display: flex; flex-wrap: wrap; gap: .2rem .55rem; margin: 0 0 1.1rem; padding-bottom: .85rem; font-size: .85rem; border-bottom: 1px solid var(--line); }
.meta-inline > div { display: flex; gap: .35rem; }
/* The comma hangs off the value, not the flex row, so it does not pick up the gap. */
.meta-inline > div:not(:last-child) dd::after { content: ","; color: var(--muted); }
.meta-inline dt { color: var(--muted); font-weight: 500; }
.meta-inline dd { margin: 0; color: var(--text); }
.wf-views > * { min-width: 0; }
@media (max-width: 960px) { .wf-views { grid-template-columns: 1fr; } }

/* ---------- audit log viewer (settings) ---------- */
#audit-table tbody tr.clickable { cursor: pointer; }
#audit-table tbody tr.clickable:hover { background: #f7f8fb; }
#audit-table tbody tr.clickable:focus-visible { outline: 2px solid var(--accent-2); outline-offset: -2px; }
#audit-table tbody tr.selected, #audit-table tbody tr.selected:hover { background: var(--accent-soft); }
#audit-table code { font-size: .85rem; }
.audit-detail { margin-top: 1.25rem; padding-top: 1.25rem; border-top: 1px solid var(--line); }
.audit-detail .card-head { margin-bottom: .75rem; }
/* A recorded prompt runs to thousands of characters, so the panel scrolls
   rather than pushing the pager off the screen. */
.audit-detail .code-view { max-height: 26rem; overflow: auto; white-space: pre-wrap; word-break: break-word; }

/* ---------- reports ---------- */
#rp-table { table-layout: fixed; min-width: 900px; }
#rp-table td { overflow: hidden; text-overflow: ellipsis; }
#rp-table td.ellipsis { min-width: 0; }
#rp-table th:nth-child(1), #rp-table td:nth-child(1) { width: 100%; min-width: 320px; }
#rp-table .actions > * { margin-left: .45rem; }
#r-runs td.ellipsis { max-width: 0; }
.mockup-box { min-width: 0; }
.report-page { padding: 1.75rem 2rem 2rem; }
.report-page.preview { margin-top: 1rem; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.report-page.preview:empty { display: none; }
.report-head { margin-bottom: 1.5rem; }
.rp-title { margin: 0 0 .25rem; font-size: 1.6rem; letter-spacing: -.02em; }
.rp-desc { margin: 0 0 .6rem; }
.report-head .meta-inline { margin-bottom: 0; }
.rp-section { margin: 1.5rem 0; break-inside: avoid; page-break-inside: avoid; }
.rp-section h3 { margin: 0 0 .6rem; font-size: 1.05rem; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; }
.stat { padding: .85rem 1rem; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fbfbfe; min-width: 0; }
.stat .label { font-size: .78rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin-bottom: .3rem; }
.stat .value { font-size: 1.35rem; font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.stat .value + .value { font-size: 1rem; font-weight: 500; color: var(--text-2); }
.rp-chart { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .75rem .5rem .25rem; background: #fff; }
.rp-svg { width: 100%; height: auto; display: block; max-width: 720px; margin: 0 auto; font-family: inherit; }
.rp-svg .rp-grid { stroke: var(--line); stroke-width: 1; }
.rp-svg .rp-axis-line { stroke: var(--line-strong); stroke-width: 1; }
.rp-svg .rp-axis { font-size: 11px; fill: var(--muted); }
.rp-svg .rp-value { font-size: 11px; fill: var(--text-2); font-weight: 600; }
.rp-svg .rp-legend { font-size: 13px; fill: var(--text); }
.rp-svg .rp-legend.muted { fill: var(--muted); }
.rp-svg .rp-empty { font-size: 14px; fill: var(--muted); }
.rp-svg .rp-slice { stroke: #fff; stroke-width: 2; }
.rp-table td, .rp-table th { white-space: nowrap; }
.rp-table td.wrap { white-space: normal; }
.rp-table tr.rp-total td { font-weight: 600; border-top: 2px solid var(--line-strong); background: #fbfbfe; }
.rp-text { margin: 0; white-space: pre-wrap; }
.rp-note { margin: .5rem 0 0; }
.rp-footer { margin-top: 2rem; padding-top: .75rem; border-top: 1px solid var(--line); }
.print-actions { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.print-actions .row { gap: .5rem; align-items: center; }
a.btn { display: inline-flex; align-items: center; text-decoration: none; }
a.btn.secondary { background: var(--card); color: var(--text); border: 1px solid var(--line-strong); }
a.btn.secondary:hover { background: #f7f8fb; text-decoration: none; }
/* Mockup: the shape of the report in grey, with placeholder data. */
.mockup { color: var(--muted); border: 1px dashed var(--line-strong); border-radius: 14px; background: #fbfbfe; padding: 1.25rem 1.5rem 1.5rem; }
.mockup .rp-title { font-size: 1.3rem; color: var(--text-2); }
.mockup .stat { background: #fff; }
.mockup .stat .value { color: var(--line-strong); }
.mockup .rp-svg .rp-bar, .mockup .rp-svg .rp-dot, .mockup .rp-svg .rp-slice, .mockup .rp-svg .rp-line { opacity: .45; }
.mockup .rp-svg .rp-value, .mockup .rp-svg .rp-legend { fill: var(--muted); }
.mockup .rp-table td { color: var(--line-strong); letter-spacing: .05em; }
.mockup .rp-table th { color: var(--muted); }
.mockup .rp-chart { background: #fff; }


/* ---------- document versions ---------- */
#d-versions td .badge { margin-left: .5rem; }
.v-add { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: .6rem; margin-top: 1rem; align-items: center; }
.v-add input[type="file"] { padding: .45rem .6rem; }
.v-add input[type="text"] { padding: .55rem .8rem; }
.v-add button { padding: .6rem 1.1rem; font-size: .95rem; }
@media (max-width: 900px) { .v-add { grid-template-columns: 1fr; } }

/* ---------- viewer ---------- */
main.viewer-main { max-width: none; margin: 0; padding: 0; display: block; }
.vw-bar { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; padding: .5rem 1rem; background: var(--card); border-bottom: 1px solid var(--line); position: relative; z-index: 2; }
.vw-bar .spacer { flex: 1; }
.vw-back { display: inline-flex; align-items: center; gap: .5rem; font-weight: 650; color: var(--text); max-width: 22rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; margin-right: .5rem; }
.vw-back > i { margin: 0; color: var(--muted); }
.vw-bar select { padding: .35rem 2rem .35rem .6rem; font-size: .88rem; background-position: right .6rem center; }
.vw-group { display: inline-flex; align-items: center; gap: .15rem; padding: 0 .4rem; border-left: 1px solid var(--line); }
.vw-btn { display: inline-flex; align-items: center; justify-content: center; gap: .3rem; min-width: 32px; height: 32px; padding: 0 .45rem; border-radius: 7px; background: none; border: 1px solid transparent; color: var(--text-2); font-size: .92rem; cursor: pointer; }
.vw-btn > i { margin: 0; }
.vw-btn:hover { background: var(--accent-soft); color: var(--accent); filter: none; text-decoration: none; }
.vw-btn:active { transform: none; }
.vw-btn.active { background: var(--accent-soft); border-color: #c9cff2; color: var(--accent); }
.vw-btn:disabled { opacity: .4; }
.vw-page { width: 3rem; padding: .3rem .4rem; text-align: center; font-size: .9rem; }
.vw-save { padding: .4rem .9rem; font-size: .9rem; }
.vw-status { max-width: 28rem; }
.vw-count { font-size: .75rem; font-weight: 700; }
.vw-note { padding: .5rem 1rem; background: var(--warn-soft); color: var(--warn); font-size: .9rem; border-bottom: 1px solid var(--line); }
.vw-extract { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; padding: .5rem 1rem; background: var(--accent-soft); border-bottom: 1px solid var(--line); }
.vw-extract input { padding: .35rem .6rem; width: 10rem; }
.vw-extract button { padding: .35rem .8rem; font-size: .88rem; }
.vw-body { position: relative; height: calc(100vh - 64px - 50px); display: flex; }
.vw-container { position: absolute; inset: 0 320px 0 0; overflow: auto; background: #e9ebf1; }
.vw-container.commenting .page { cursor: crosshair; }
.vw-panel { position: absolute; top: 0; right: 0; bottom: 0; width: 320px; overflow: auto; background: var(--card); border-left: 1px solid var(--line); padding: 1rem; }
.vw-panel.closed { display: none; }
.vw-panel:not(.closed) ~ .vw-container { right: 320px; }
.vw-body:has(.vw-panel.closed) .vw-container { right: 0; }
.vw-panel h3 { margin: 0 0 .75rem; font-size: 1rem; }
.vw-notes { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.vw-notes li { border: 1px solid var(--line); border-radius: 10px; padding: .55rem .7rem; cursor: pointer; display: grid; gap: .2rem; }
.vw-notes li:hover { border-color: var(--accent-2); }
.vw-note-head { display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; }
.vw-note-text { font-size: .92rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.vw-comment { position: absolute; z-index: 30; width: 260px; background: var(--card); border: 1px solid var(--line-strong); border-radius: 10px; box-shadow: var(--shadow); padding: .6rem; display: grid; gap: .5rem; transform: translate(8px, 8px); }
.vw-comment textarea { width: 100%; font: inherit; font-size: .92rem; padding: .45rem .55rem; border-radius: 8px; resize: vertical; }
.vw-comment button { padding: .35rem .8rem; font-size: .88rem; }
.vw-image { max-width: 100%; display: block; margin: 1rem auto; box-shadow: var(--shadow); }
@media (max-width: 900px) {
  .vw-panel { width: 100%; top: auto; height: 40%; border-left: 0; border-top: 1px solid var(--line); }
  .vw-container { inset: 0 0 40% 0; }
  .vw-body:has(.vw-panel.closed) .vw-container { bottom: 0; }
}

/* ---------- editor ---------- */
.editor-main .ed-root { height: calc(100vh - 64px - 50px); }
.editor-main:has(#ed-note:not([hidden])) .ed-root { height: calc(100vh - 64px - 50px - 38px); }
#ed-version { white-space: nowrap; }
#ed-lease { white-space: nowrap; }
.ec-actions { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.ec-table { margin-top: 1rem; }
.ec-table td { vertical-align: top; font-size: .9rem; }
.ec-table .ok { color: var(--ok); font-weight: 600; }
.ec-table .bad { color: var(--error); font-weight: 600; }
.ec-table pre { white-space: pre-wrap; font-size: .78rem; max-height: 14rem; overflow: auto; margin: .3rem 0 0; background: #f6f7fa; padding: .4rem; border-radius: 6px; }
.ec-host { position: fixed; left: -12000px; top: 0; width: 1100px; height: 900px; }

/* ---------- compare ---------- */
.doc-compare { display: inline-flex; gap: .75rem; align-items: center; }
.doc-compare .btn { padding: .45rem 1rem; font-size: .92rem; }
#doc-table input.pick { width: 1rem; height: 1rem; margin: 0 .35rem 0 0; vertical-align: middle; accent-color: var(--accent); cursor: pointer; }
.cmp-pick-box { margin: 0 0 1rem; display: grid; gap: .5rem; max-width: 44rem; }
.cmp-results { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; }
.cmp-sides { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 1rem; align-items: start; }
.cmp-side { border: 1px solid var(--line); border-radius: 12px; padding: .8rem 1rem; display: grid; gap: .35rem; min-width: 0; }
.cmp-label { font-size: .74rem; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.cmp-name { font-weight: 650; font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmp-meta { gap: .6rem; }
.cmp-meta select { padding: .3rem 2rem .3rem .6rem; font-size: .88rem; background-position: right .6rem center; }
.cmp-arrow { align-self: center; color: var(--muted); font-size: 1.2rem; }
.cmp-summary { font-size: 1.05rem; margin: 0 0 1rem; }
.cmp-diffs { list-style: none; margin: 0; padding: 0; display: grid; gap: .8rem; }
.cmp-diffs li { border: 1px solid var(--line); border-left: 3px solid var(--line-strong); border-radius: 10px; padding: .7rem .9rem; display: grid; gap: .45rem; }
.cmp-diffs li.sig-major { border-left-color: var(--error); }
.cmp-diffs li.sig-notable { border-left-color: var(--warn); }
.cmp-diff-head { display: flex; gap: .6rem; align-items: baseline; }
.badge.sig { text-transform: uppercase; font-size: .7rem; letter-spacing: .08em; font-weight: 600; }
.badge.sig.major { background: var(--danger-soft); color: var(--error); }
.badge.sig.notable { background: var(--warn-soft); color: var(--warn); }
.cmp-ab { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.cmp-ab > div { display: grid; gap: .2rem; align-content: start; }
.cmp-k { font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.cmp-ab q { color: var(--text-2); font-style: italic; font-size: .92rem; }
.cmp-table td { vertical-align: top; }
.cmp-table .cmp-field { color: var(--text-2); font-weight: 600; white-space: nowrap; width: 1%; }
.cmp-table tr.st-different td { background: #fffaf0; }
.cmp-table tr.st-only_a td, .cmp-table tr.st-only_b td { background: #f8f9fc; }
.cmp-table .chg { color: var(--warn); font-weight: 700; }
.cmp-grid { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; font-size: .93rem; }
.cmp-gh { padding: .45rem .8rem; font-size: .74rem; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); background: #fafbfe; border-bottom: 1px solid var(--line); }
.cmp-gh + .cmp-gh, .cmp-ctx + .cmp-ctx, .cmp-chg + .cmp-chg { border-left: 1px solid var(--line); }
.cmp-same { grid-column: 1 / -1; padding: .35rem .8rem; color: var(--muted); background: #fafbfe; font-size: .85rem; border-bottom: 1px solid var(--line); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmp-ctx, .cmp-chg { padding: .45rem .8rem .45rem 3rem; position: relative; border-bottom: 1px solid var(--line); min-width: 0; }
.cmp-ctx { color: var(--text-2); }
.cmp-chg { background: #fffdf6; }
.cmp-ln { position: absolute; left: .7rem; top: .5rem; color: #a9afbb; font-size: .78rem; font-variant-numeric: tabular-nums; }
.cmp-seg { white-space: pre-wrap; overflow-wrap: anywhere; }
.cmp-seg del { background: #fde4e1; color: #8f1d14; text-decoration: line-through; text-decoration-color: rgba(143, 29, 20, .5); border-radius: 3px; }
.cmp-seg ins { background: #dff3e7; color: #135c39; text-decoration: none; border-radius: 3px; }
@media (max-width: 760px) {
  .cmp-sides { grid-template-columns: 1fr; }
  .cmp-arrow { transform: rotate(90deg); justify-self: center; }
  .cmp-ab { grid-template-columns: 1fr; }
}
@media print {
  #cmp-swap, #cmp-print, .cmp-meta select, #cmp-meaning button { display: none !important; }
  .cmp-grid, .cmp-diffs li, .cmp-side { break-inside: avoid; }
  .cmp-seg del, .cmp-seg ins, .cmp-table tr td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ---------- groups (settings) ---------- */
.groups { display: grid; gap: .75rem; margin: .5rem 0 1rem; }
.g-row { border: 1px solid var(--line); border-radius: 12px; padding: .8rem 1rem; display: grid; gap: .5rem; }
.g-head { display: flex; gap: .75rem; align-items: baseline; }
.g-head .spacer { flex: 1; }
.g-head code, .card code { font-size: .85rem; color: var(--text-2); background: #f3f4f8; padding: .1rem .4rem; border-radius: 6px; }
.g-row .chips { margin: 0; }
.g-editor { display: grid; gap: .6rem; padding-top: .5rem; border-top: 1px solid var(--line); }
.g-name { display: grid; gap: .25rem; max-width: 22rem; }
.g-picks { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: .35rem 1rem; }
.g-picks .switch { font-weight: 400; }
.g-new { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.g-new input { min-width: 16rem; }

/* ---------- calendar ---------- */
.cal-head { align-items: center; }
.cal-head h2 { min-width: 11ch; }
.cal-nav { display: flex; gap: .4rem; align-items: center; }
.cal-nav button { height: 36px; padding: 0 .9rem; font-size: .92rem; }
.cal-nav .icon-btn { width: 36px; padding: 0; color: var(--text-2); }
.cal-tabs { margin: 0; border-bottom: 0; }
.cal-filters { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; margin: .25rem 0 1.25rem; }
.cal-filters select { padding: .5rem 2.2rem .5rem .8rem; }
.cal-month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.cal-dow { padding: .5rem .6rem; font-size: .74rem; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: #fafbfe; }
.cal-cell { min-height: 7.2rem; padding: .35rem .4rem .45rem; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--card); text-align: left; color: var(--text);
  display: flex; flex-direction: column; gap: .2rem; cursor: pointer; border-radius: 0; font: inherit; font-weight: 400; min-width: 0; }
.cal-cell:hover { background: #fafbfe; filter: none; }
.cal-cell:active { transform: none; }
.cal-cell:focus-visible { outline: 2px solid var(--accent-2); outline-offset: -2px; }
.cal-cell.other { background: #fbfbfd; }
.cal-cell.other .cal-num { color: #b3b8c4; }
.cal-cell.weekend { background: #fcfcfe; }
.cal-cell.selected { box-shadow: inset 0 0 0 2px var(--accent-2); }
.cal-num { font-size: .85rem; font-weight: 600; color: var(--text-2); width: 1.7rem; height: 1.7rem; display: inline-grid; place-items: center; border-radius: 50%; }
.cal-cell.today .cal-num { background: var(--accent); color: #fff; }
.cal-chip { display: block; font-size: .78rem; line-height: 1.25; padding: .14rem .45rem; border-radius: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.cal-chip.done { text-decoration: line-through; opacity: .6; }
.cal-chip.overdue { box-shadow: inset 2px 0 0 var(--error); }
.cal-more { font-size: .76rem; color: var(--muted); padding-left: .3rem; }
.cal-day { margin-top: 1.25rem; }
.cal-day h3, .cal-agenda h3 { margin: 1.1rem 0 .4rem; font-size: 1rem; }
.cal-day h3:first-child, .cal-agenda h3:first-child { margin-top: 0; }
.cal-agenda h3.overdue { color: var(--error); }
.cal-list { list-style: none; padding: 0; margin: 0; display: grid; }
.cal-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: .35rem 1rem; align-items: center; padding: .7rem .2rem; border-bottom: 1px solid var(--line); }
.cal-item:last-child { border-bottom: 0; }
.cal-item.nodate { grid-template-columns: minmax(0, 1fr) auto; }
.cal-item .what { display: grid; gap: .1rem; min-width: 0; }
.cal-item .what strong { font-weight: 600; }
.cal-item .what .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-item.done .what strong { text-decoration: line-through; color: var(--muted); }
.cal-item .when { font-variant-numeric: tabular-nums; color: var(--text-2); font-weight: 600; min-width: 6.5rem; }
.cal-item .when.overdue { color: var(--error); }
.cal-item .acts { display: flex; gap: .75rem; align-items: center; white-space: nowrap; }
.cal-item .acts .switch { font-weight: 500; font-size: .92rem; }
.cal-add { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: .6rem; margin-top: 1rem; align-items: center; }
.cal-add input, .cal-add select { padding: .55rem .8rem; }
.cal-add select { padding-right: 2.2rem; }
.cal-add button { padding: .6rem 1.1rem; font-size: .95rem; }
.cal-sub { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 2.5rem; }
.cal-sub h3 { margin-top: 0; }
.cal-feed-link { display: flex; gap: .5rem; margin: .5rem 0; }
.cal-feed-link input { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }
@media (max-width: 900px) {
  .cal-sub { grid-template-columns: 1fr; gap: 1.25rem; }
  .cal-add { grid-template-columns: 1fr 1fr; }
  .cal-add input[type="text"] { grid-column: 1 / -1; order: -1; }
}
@media (max-width: 640px) {
  .cal-cell { min-height: 3.6rem; padding: .25rem; align-items: center; }
  .cal-dow { padding: .4rem 0; text-align: center; letter-spacing: 0; }
  /* No room for labels: each event becomes a dot in its type's colour. */
  .cal-chip { width: .5rem; height: .5rem; padding: 0; border-radius: 50%; font-size: 0; display: inline-block; }
  .cal-dots { display: flex; gap: .2rem; flex-wrap: wrap; justify-content: center; }
  .cal-more { display: none; }
  .cal-item { grid-template-columns: minmax(0, 1fr) auto; }
  .cal-item .when { grid-column: 1 / -1; }
}

@media print {
  .topbar, .print-actions, .crumbs, button, nav, .nav-toggle { display: none !important; }
  html, body { background: #fff; }
  main { margin: 0; max-width: none; padding: 0; display: block; }
  .card, .report-page { box-shadow: none; border: 0; padding: 0; border-radius: 0; }
  .rp-section, .stat-row, .stat, .rp-chart, tr { break-inside: avoid; page-break-inside: avoid; }
  thead { display: table-header-group; }
  .table-wrap { overflow: visible; }
  a { color: inherit; text-decoration: none; }
  .report-page { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  @page { margin: 16mm; }
}

/* ---- templates ---- */
.tp-new-buttons { gap: .5rem; flex-wrap: wrap; }
.tp-upload { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .9rem 1.2rem; margin: 1rem 0; padding: 1rem; border: 1px solid var(--line); border-radius: 12px; }
.tp-upload .field { display: grid; gap: .3rem; }
.tp-upload .field > span { color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
.tp-upload .row, .tp-upload .wide { grid-column: 1 / -1; }
.tp-upload input, .tp-upload select { width: 100%; }
.tt-problems { border: 1px solid var(--line); border-left: 3px solid #c0392b; border-radius: 8px; padding: .5rem 1rem; margin: .75rem 0; }
.tt-problems ul { margin: .25rem 0 .5rem; padding-left: 1.2rem; }
.tt-start { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; margin: .5rem 0 0; }
.tt-start-box { display: grid; gap: .4rem; align-content: start; }
.tt-start-box > span.small { color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; }
.tt-start-box input[type="search"] { flex: 1; min-width: 0; }
.tt-start-box textarea { width: 100%; }
.tt-docname { display: grid; gap: .3rem; flex: 1; max-width: 32rem; }
.tt-docname > span { color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
#tt-fields tr.error td { color: #c0392b; }
#tt-pdf select { width: 100%; }
label.btn.secondary { display: inline-flex; align-items: center; gap: .4rem; background: var(--card); color: var(--text); border: 1px solid var(--line-strong); }
label.btn.secondary:hover { background: #f7f8fb; filter: none; }
.exform fieldset.nested > p.wide { grid-column: 1 / -1; margin: 0; }
.exform input[type="checkbox"] { width: auto; justify-self: start; }

/* ---- bulk runs ---- */
.tb-query { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .5rem .8rem; }
.tb-query .field { display: grid; gap: .25rem; }
.tb-query .field > span { color: var(--muted); font-size: .75rem; font-weight: 600; }
.tb-query .tb-check { display: flex; align-items: center; gap: .4rem; align-self: end; }
.tb-query .tb-check > span { text-transform: none; font-weight: 400; font-size: .85rem; color: var(--text); }
.bk-counts { display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0; }
.bk-count { border: 1px solid var(--line-strong); border-radius: 999px; padding: .15rem .65rem; font-size: .85rem; }
.bk-count.ok { border-color: #2e8b57; color: #2e7d4f; }
.bk-count.bad { border-color: #c0392b; color: #c0392b; }
.bk-bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: .5rem 0; }
.bk-bar > span { display: block; height: 100%; background: var(--gradient); transition: width .4s; }
.bk-notes { margin: .25rem 0 0; padding-left: 1.1rem; color: #c0392b; }
#bk-items tr.bk-edit > td { background: var(--bg, #f7f8fb); }
.bk-key { display: flex; align-items: center; gap: .5rem; }
.bk-key > span { color: var(--muted); font-size: .85rem; }
#bk-map select { width: 100%; }
#bk-go-row, #bk-out-row { margin: .5rem 0 1rem; }

/* ---- cases ---- */
.ca-chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.ca-chip { border: 1px solid var(--line-strong); border-radius: 999px; padding: .05rem .55rem; font-size: .8rem; white-space: nowrap; }
.ca-chip.present, .ca-chip.approved { border-color: #2e8b57; color: #2e7d4f; }
.ca-chip.waiting { border-color: #d97706; color: #8a4b06; }
.ca-chip.rejected { border-color: #c0392b; color: #c0392b; }
.ca-chip.missing { border-style: dashed; color: var(--muted); }
.ca-link { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto; gap: .6rem; align-items: center; margin-top: 1rem; }
#cs-new { margin: .5rem 0 1rem; }
#cs-new input { flex: 1; min-width: 12rem; }
.tt-task { border: 1px solid var(--line); border-left: 3px solid #3f4fd8; border-radius: 8px; padding: .5rem .8rem; margin: .5rem 0; }
.cal-list li.done { opacity: .6; text-decoration: line-through; }
@media (max-width: 640px) { .ca-link { grid-template-columns: 1fr; } }
.problem.warning { border-color: #d97706; background: #fff8ec; color: #8a4b06; }

/* ---- signatures ---- */
.me-link { color: var(--muted); text-decoration: none; }
.me-link:hover { text-decoration: underline; }
.vw-sign { margin-left: .4rem; }
.vw-container.signing .page { cursor: crosshair; }
.vw-place { position: absolute; z-index: 20; border: 2px dashed #15803d; background: rgba(21, 128, 61, .08); color: #14532d; font: 600 12px/1.2 "Open Sans", system-ui, sans-serif; border-radius: 4px; cursor: pointer; padding: 2px 4px; display: flex; align-items: flex-end; justify-content: flex-start; }
.vw-place:hover { background: rgba(21, 128, 61, .18); }
.vw-sigbox { position: absolute; z-index: 21; border: 2px solid #15803d; background: rgba(21, 128, 61, .1); pointer-events: none; }
.vw-sigform { position: absolute; z-index: 40; top: 64px; left: 50%; transform: translateX(-50%); width: min(420px, calc(100% - 32px)); background: var(--card); border: 1px solid var(--line-strong); border-radius: 12px; box-shadow: var(--shadow); padding: .9rem; display: grid; gap: .55rem; }
.vw-sigform p { margin: 0; }
.vw-sigform input { width: 100%; }
.vw-sigform input[readonly] { color: var(--muted); background: transparent; border-style: dashed; }
.sig-item { border: 1px solid var(--line); border-left: 3px solid #15803d; border-radius: 8px; padding: .45rem .7rem; display: grid; gap: .15rem; list-style: none; }
.sig-item.bad { border-left-color: #c0392b; }
.sig-item .fa-circle-check { color: #15803d; }
.sig-item .fa-triangle-exclamation { color: #c0392b; }
.d-sigs { display: grid; gap: .5rem; margin: .5rem 0; padding: 0; }
#vw-sigs { margin-bottom: 1.25rem; }
#vw-sigs-state.ok, #d-sigs-state.ok, #me-check-result .ok { color: #15803d; }
.me-sig { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1.5rem; align-items: start; }
.me-sig-draw { width: 100%; height: auto; aspect-ratio: 3 / 1; border: 1px dashed var(--line-strong); border-radius: 10px; background: #fff; touch-action: none; cursor: crosshair; }
.me-sig-preview { display: grid; gap: .4rem; border: 1px solid var(--line); border-radius: 10px; padding: .8rem; background: repeating-conic-gradient(#f3f4f7 0% 25%, #fff 0% 50%) 50% / 16px 16px; }
.me-sig-preview img { max-width: 100%; max-height: 160px; }
@media (max-width: 760px) { .me-sig { grid-template-columns: 1fr; } }
