/*
 * APS portal styles: matches the All-Pro portal UI design (portal-ui/v1).
 * Plain CSS with tokens, no framework.
 */
:root {
  --font: Inter, "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --bg: #f5f6f8;            /* page */
  --surface: #ffffff;       /* cards, header, sidebar */
  --surface-2: #fafbfc;     /* table head, group header */
  --surface-3: #ecedf0;     /* segmented control track */
  --line: #e9eaee;          /* card + chrome borders */
  --line-2: #e7e9ed;        /* input + button borders */
  --line-3: #f4f5f7;        /* row separators */
  --text: #1a1c20;
  --text-2: #3f4754;        /* nav, secondary buttons */
  --muted: #667085;
  --faint: #98a0ab;
  --label: #a8aeb8;         /* sidebar section labels */

  --brand: #3078bf;         /* primary buttons, avatar */
  --brand-ink: #26639f;     /* active nav text, links */
  --brand-soft: #eaf2fa;    /* active nav bg, icon tiles, count pills */
  --red: #d8232a;           /* All-Pro red: notification badges */
  --ok: #1e7a46; --ok-soft: #e7f5ed;
  --warn: #8a5a00; --warn-soft: #fff4dc;
  --danger: #b42318; --danger-soft: #fdecea;
  --pill: #f2f4f7; --pill-ink: #596273;

  --hover: #f7f9fc;
  --r-card: 16px; --r-ctl: 10px; --r-btn: 9px;
  --sidebar-w: 216px; --header-h: 61px;
  color-scheme: light;
}
/*
 * The portal is always light, as in the design, whatever the computer's own
 * dark-mode setting. A dark theme exists only if a page explicitly sets
 * <html data-theme="dark"> (not used anywhere today).
 */
:root[data-theme="dark"] {
  --bg: #0f1216; --surface: #171b21; --surface-2: #1c2128; --surface-3: #232932;
  --line: #2a313b; --line-2: #333b46; --line-3: #222830;
  --text: #e8ebf0; --text-2: #c3cad5; --muted: #98a2b3; --faint: #788290; --label: #6c7684;
  --brand: #4b8fd6; --brand-ink: #8cbcf0; --brand-soft: #1b2b40;
  --ok: #63d394; --ok-soft: #15301f; --warn: #f2c25c; --warn-soft: #33280f; --danger: #ff8a80; --danger-soft: #3a1714;
  --pill: #252b34; --pill-ink: #b3bcc8; --hover: #1f252d;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--header-h) + 16px); scroll-padding-bottom: 84px; }
html, body { margin: 0; }
body { font: 14px/1.45 var(--font); background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
a { color: var(--brand-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 18px; font-weight: 600; margin: 0; }
h2 { font-size: 14px; font-weight: 600; margin: 22px 0 10px; }
code, .mono { font-family: var(--mono); font-size: 11.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.ic { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ── App shell ─────────────────────────────────────────── */
.app-header { position: sticky; top: 0; z-index: 40; height: var(--header-h); display: flex; align-items: center; gap: 14px; padding: 0 18px; background: var(--surface); border-bottom: 1px solid var(--line); }
.app-header .logo img { height: 46px; width: auto; display: block; }
.app-header .spacer { flex: 1; }
.icon-btn { width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: var(--r-ctl); border: 0; background: transparent; color: var(--text-2); cursor: pointer; }
.icon-btn:hover { background: var(--surface-3); }
.reminder-bell { position: relative; }
.reminder-bell .bell-count { position: absolute; top: 2px; right: 0; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 600; line-height: 16px; text-align: center; }
.user-menu { position: relative; }
.user-menu > summary { list-style: none; display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 10px 0 4px; border: 1px solid var(--line-2); border-radius: 999px; background: var(--surface); cursor: pointer; font-size: 13px; font-weight: 500; }
.user-menu > summary::-webkit-details-marker { display: none; }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--brand); color: #fff; font-size: 10.5px; font-weight: 600; }
.user-menu .panel { position: absolute; right: 0; top: 44px; min-width: 230px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px rgba(20,22,26,.12); padding: 6px; }
.user-menu .panel .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--line-3); margin-bottom: 6px; }
.user-menu .panel button, .user-menu .panel a { display: flex; width: 100%; align-items: center; gap: 10px; padding: 8px 10px; border: 0; background: none; font: inherit; font-size: 13px; color: var(--text-2); border-radius: 8px; cursor: pointer; text-align: left; }
.user-menu .panel button:hover, .user-menu .panel a:hover { background: var(--surface-3); text-decoration: none; }

.app-body { display: flex; min-height: calc(100vh - var(--header-h)); }
.app-sidebar { width: var(--sidebar-w); flex: none; background: var(--surface); border-right: 1px solid var(--line); position: sticky; top: var(--header-h); height: calc(100vh - var(--header-h)); overflow-y: auto; padding: 14px 14px 20px; display: flex; flex-direction: column; }
.nav-section { margin-bottom: 10px; }
.nav-label { font-size: 10px; font-weight: 500; letter-spacing: .5px; text-transform: uppercase; color: var(--label); padding: 2px 11px 6px; }
.nav-item { display: flex; align-items: center; gap: 11px; white-space: nowrap; padding: 8px 11px; border-radius: var(--r-ctl); color: var(--text-2); font-size: 13.5px; text-decoration: none !important; margin-bottom: 1px; }
.nav-item:hover { background: var(--surface-3); }
.nav-item.active { background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; }
.nav-item.soon { color: var(--faint); cursor: default; }
.nav-item.soon:hover { background: none; }
.nav-item .tag { margin-left: auto; font-size: 10px; font-weight: 500; color: var(--faint); }
.nav-item .count { margin-left: auto; background: var(--red); color: #fff; font-size: 11px; font-weight: 500; padding: 1px 6px; border-radius: 999px; }
.app-sidebar .bottom { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--line-3); }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content { flex: 1; width: 100%; max-width: 1440px; padding: 30px 28px 40px; }
.content.full { max-width: none; }
.app-footer { text-align: center; color: var(--faint); font-size: 11px; padding: 18px; }

.crumbs { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--faint); margin-bottom: 18px; }
.crumbs a { color: var(--faint); }
.crumbs .here { color: var(--text); font-weight: 500; }
.crumbs svg.ic { width: 14px; height: 14px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .sub { font-size: 12px; font-weight: 300; color: var(--muted); margin-top: 4px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Components ────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); }
.card-body { padding: 18px 20px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; background: var(--surface-2); border-bottom: 1px solid var(--line-3); border-radius: var(--r-card) var(--r-card) 0 0; font-weight: 600; }
.card > table:first-child th:first-child { border-top-left-radius: var(--r-card); }
.card > table:first-child th:last-child { border-top-right-radius: var(--r-card); }
.grid { display: grid; gap: 14px; }
.grid > *, .form-grid > * { min-width: 0; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); }
@media (min-width: 1024px) {
  .lead-top-grid { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
  .lead-top-grid .form-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}
.stats { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(200px, calc(50% - 7px)), 1fr)); margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); padding: 18px 20px; }
.stat .top { display: flex; align-items: center; gap: 12px; color: var(--text-2); }
.tile { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-ink); }
.stat .stat-num { font-size: 30px; font-weight: 600; letter-spacing: -1px; margin-top: 12px; }
.stat .foot { font-size: 12px; color: var(--muted); margin-top: 4px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: var(--r-btn); border: 1px solid var(--line-2); background: var(--surface); color: var(--text-2); font: 500 12.5px var(--font); cursor: pointer; text-decoration: none !important; white-space: nowrap; }
.btn:hover { background: var(--surface-3); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-ink); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--line-2)); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { height: 30px; padding: 0 11px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.seg { display: inline-flex; gap: 3px; padding: 3px; background: var(--surface-3); border-radius: var(--r-ctl); flex-wrap: wrap; }
.seg button, .seg a { height: 30px; padding: 0 14px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font: 500 12.5px var(--font); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none !important; }
.seg .on, .seg button[aria-pressed="true"] { background: var(--surface); color: var(--brand-ink); box-shadow: 0 1px 3px rgba(20,22,26,.1); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 10.5px; font-weight: 500; background: var(--pill); color: var(--pill-ink); white-space: nowrap; }
.badge-info, .count-pill { background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; }
.count-pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.alert { padding: 11px 16px; border-radius: 12px; margin-bottom: 16px; font-size: 13px; border: 1px solid transparent; }
.alert-ok { background: var(--ok-soft); color: var(--ok); }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-info { background: var(--brand-soft); color: var(--brand-ink); }

/* Forms */
label { display: block; font-size: 11.5px; font-weight: 500; color: var(--text-2); margin-bottom: 6px; }
/* Every text-like input (text, email, date, datetime-local, tel, url, number, …) gets the same look. */
/* :where() keeps this at element specificity, so .input-icon, .has-error, [readonly] rules still override it. */
:where(input:not([type=checkbox], [type=radio], [type=hidden], [type=submit], [type=button], [type=reset], [type=file], [type=range], [type=color], [type=image])), :where(select, textarea) {
  width: 100%; height: 38px; padding: 0 11px; border: 1px solid var(--line-2); border-radius: var(--r-ctl); background: var(--surface); color: var(--text); font: 13px var(--font);
  box-shadow: none; appearance: none; -webkit-appearance: none;
}
textarea { height: auto; min-height: 76px; padding: 9px 11px; line-height: 1.45; resize: vertical; }
/* Dates: keep the native picker, same height and font as other fields. */
input[type=date], input[type=datetime-local], input[type=time], input[type=month] { padding-right: 8px; line-height: 36px; }
input::-webkit-datetime-edit { padding: 0; }
input::-webkit-calendar-picker-indicator { opacity: .55; cursor: pointer; }
input::-webkit-calendar-picker-indicator:hover { opacity: .9; }
/* Selects lost their arrow with appearance:none: draw one. */
select { appearance: none; -webkit-appearance: none; -moz-appearance: none; padding-right: 32px; cursor: pointer; background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") right 10px center / 14px no-repeat; }
select::picker-icon { display: none; }
select::-ms-expand { display: none; }
select[multiple] { padding-right: 11px; background-image: none; }
select:disabled { cursor: default; }
input::placeholder, textarea::placeholder { color: var(--faint); }
/* Checkboxes and radios in the brand colour. */
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; margin: 0; flex: none; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .seg button:focus-visible, .icon-btn:focus-visible { outline: 2px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: 1px; }
.input-icon { position: relative; }
.input-icon svg.ic { position: absolute; left: 11px; top: 11px; color: var(--faint); pointer-events: none; }
.input-icon input, .input-icon select { padding-left: 34px; }
.field { margin-bottom: 14px; }
.field .hint { font-weight: 400; color: var(--muted); }
.filters { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; }
.filters > div { min-width: 180px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type=search] { max-width: 340px; }
.toolbar select { width: auto; }
.check { display: flex; align-items: flex-start; gap: 9px; font-size: 13px; font-weight: 400; color: var(--text); margin: 0; cursor: pointer; }
.check input { margin-top: 2px; accent-color: var(--brand); }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; vertical-align: top; }
th { font-size: 11px; font-weight: 500; color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
th a.sort-link { display: inline-flex; align-items: center; gap: 4px; color: inherit; text-decoration: none; }
th a.sort-link:hover, th a.sort-link.sorted { color: var(--brand-ink); }
th a.sort-link .arrow { font-size: 11px; line-height: 1; }
td { font-size: 12.5px; border-bottom: 1px solid var(--line-3); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Role editor: permission groups */
details.group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); margin-bottom: 10px; overflow: hidden; }
details.group > summary { display: flex; align-items: center; gap: 10px; padding: 13px 18px; cursor: pointer; list-style: none; font-weight: 600; background: var(--surface-2); }
details.group > summary::-webkit-details-marker { display: none; }
details.group > summary::before { content: ""; width: 7px; height: 7px; border-right: 1.7px solid var(--faint); border-bottom: 1.7px solid var(--faint); transform: rotate(-45deg); transition: transform .15s; margin-right: 2px; }
details.group[open] > summary::before { transform: rotate(45deg); }
details.group > summary .spacer { flex: 1; }
.perm { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; padding: 10px 18px; border-top: 1px solid var(--line-3); align-items: start; margin: 0; font-size: 13px; color: var(--text); font-weight: 400; cursor: pointer; }
.perm.changed { background: var(--brand-soft); }
.perm .name { font-family: var(--mono); font-size: 11px; color: var(--faint); margin-left: 6px; }
.perm .desc { color: var(--muted); font-size: 12px; }
.perm .tags { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.savebar { position: fixed; left: 50%; transform: translateX(-50%); bottom: 18px; background: #1a1c20; color: #fff; border-radius: 14px; padding: 10px 12px 10px 18px; display: flex; gap: 12px; align-items: center; box-shadow: 0 10px 30px rgba(20,22,26,.25); z-index: 50; font-size: 13px; }
.savebar[hidden] { display: none; }
.savebar .btn { height: 32px; }
.savebar .btn:not(.btn-primary) { background: transparent; color: #fff; border-color: rgba(255,255,255,.25); }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 400px; }
.login-card .logo { display: block; margin: 0 auto 14px; height: 70px; }
.login-card h1 { text-align: center; margin-bottom: 20px; font-size: 16px; color: var(--muted); font-weight: 500; }

.pager { display: flex; gap: 8px; justify-content: space-between; margin-top: 14px; align-items: center; }

/* ── Permission matrix ─────────────────────────────────── */
.mx-wrap { overflow: auto; max-height: calc(100vh - 150px); border-radius: var(--r-card); }
.mx { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; }
.mx th, .mx td { border-bottom: 1px solid var(--line-3); padding: 0; }
.mx thead th { position: sticky; top: 0; z-index: 3; background: var(--surface-2); border-bottom: 1px solid var(--line); vertical-align: bottom; }
.mx .pcol { position: sticky; left: 0; z-index: 2; background: var(--surface); min-width: 320px; max-width: 360px; border-right: 1px solid var(--line); padding: 8px 14px; }
.mx thead .pcol { z-index: 4; background: var(--surface-2); padding: 12px 14px; }
.mx .rh { width: 86px; min-width: 86px; padding: 10px 6px; text-align: center; white-space: normal; }
.mx .rh a { display: block; color: var(--text-2); font-size: 10.5px; font-weight: 600; line-height: 1.25; text-decoration: none; overflow-wrap: normal; word-break: normal; hyphens: manual; }
.mx .rh a:hover { color: var(--brand-ink); }
.mx .rh .users { display: block; font-size: 10px; color: var(--faint); font-weight: 400; margin-top: 3px; }
.mx .rh.sys a { color: var(--brand-ink); }
.mx td.c { text-align: center; height: 38px; cursor: default; }
.mx td.c::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--line); vertical-align: middle; }
.mx td.c.y::before { width: 20px; height: 20px; border-radius: 6px; background: var(--ok-soft) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231e7a46' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E") center/13px no-repeat; }
.mx td.c.inh::before { width: 20px; height: 20px; border-radius: 6px; background: var(--pill); }
.mx.editable td.c:not(.lock) { cursor: pointer; }
.mx.editable td.c:not(.lock):hover::before { outline: 2px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 1px; }
.mx td.c.lock { cursor: not-allowed; }
.mx td.c.add::before { background-color: var(--brand); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round'%3E%3Cpath d='M12 6v12M6 12h12'/%3E%3C/svg%3E"); background-position: center; background-size: 12px; background-repeat: no-repeat; width: 20px; height: 20px; border-radius: 6px; }
.mx td.c.del::before { width: 20px; height: 20px; border-radius: 6px; background: var(--danger-soft) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23b42318' stroke-width='3' stroke-linecap='round'%3E%3Cpath d='M6 12h12'/%3E%3C/svg%3E") center/12px no-repeat; }
.mx tr.row:hover td, .mx tr.row:hover .pcol { background: var(--hover); }
.mx td.c.colhi { background: var(--hover); }
.mx .plabel { font-size: 12.5px; color: var(--text); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.mx .plabel a { color: inherit; }
.mx .pname { font-family: var(--mono); font-size: 10.5px; color: var(--faint); }
.mx .held { font-size: 10.5px; color: var(--faint); }
.mx tr.grp td { position: sticky; left: 0; background: var(--surface-2); padding: 0; border-bottom: 1px solid var(--line); }
.mx tr.grp button { all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 10px; padding: 11px 14px; cursor: pointer; font-weight: 600; font-size: 13px; position: sticky; left: 0; max-width: 100vw; }
.mx tr.grp button::before { content: ""; width: 6px; height: 6px; border-right: 1.7px solid var(--faint); border-bottom: 1.7px solid var(--faint); transform: rotate(45deg); transition: transform .15s; }
.mx tr.grp.closed button::before { transform: rotate(-45deg); }
.mx tr.row.hide, .mx tr.grp.hide { display: none; }
.mx col.hide, .mx .rh.hide, .mx td.c.hide { display: none; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); align-items: center; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 14px; height: 14px; border-radius: 4px; }
.role-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.role-chips label { margin: 0; display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border: 1px solid var(--line-2); border-radius: 999px; font-size: 12px; font-weight: 500; color: var(--text-2); cursor: pointer; background: var(--surface); }
.role-chips input { accent-color: var(--brand); margin: 0; }
.role-chips label:has(input:checked) { background: var(--brand-soft); border-color: transparent; color: var(--brand-ink); }

/* ── Responsive ────────────────────────────────────────── */
.only-mobile { display: none; }
@media (max-width: 900px) {
  .only-mobile { display: inline-grid; }
  .app-sidebar { position: fixed; left: 0; top: var(--header-h); z-index: 35; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 10px 30px rgba(20,22,26,.15); }
  body.nav-open .app-sidebar { transform: none; }
  .content { padding: 18px 16px 32px; }
  .app-header { padding: 0 12px; }
  .app-header .logo img { height: 38px; }
  .user-menu .name { display: none; }
  .perm { grid-template-columns: 22px 1fr; }
  .perm .tags { grid-column: 2; justify-content: flex-start; }
  .mx .pcol { min-width: 200px; max-width: 220px; }
}

/* Popover (Columns picker) */
details.popover { position: relative; }
details.popover > summary { list-style: none; }
details.popover > summary::-webkit-details-marker { display: none; }
details.popover .pop { position: absolute; right: 0; top: 38px; z-index: 20; width: 300px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px rgba(20,22,26,.12); padding: 12px; font-weight: 400; }
details.popover .pop-list { display: grid; gap: 6px; max-height: 320px; overflow: auto; }
details.popover .pop-list .check { align-items: center; }
dialog { color: var(--text); }
dialog::backdrop { background: rgba(20, 22, 26, .38); }
@media (max-width: 520px) {
  .stat { padding: 14px; }
  .stat .stat-num { font-size: 24px; margin-top: 8px; }
  .stat .top { gap: 8px; font-size: 13px; }
  .tile { width: 30px; height: 30px; border-radius: 9px; }
  .filters > div { min-width: 100% !important; }
  .seg { width: 100%; }
}

/* ── Lead queue ────────────────────────────────────────── */
.more-filters { margin-top: 12px; }
.more-filters > summary { cursor: pointer; font-size: 12px; font-weight: 500; color: var(--brand-ink); width: max-content; }
.lq-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 4px 0 12px; }
.lq-meta .spacer { flex: 1; }
.faint { color: var(--faint); }
.lq-panel { margin-bottom: 12px; overflow: hidden; }
.lq-head { all: unset; box-sizing: border-box; width: 100%; display: flex; align-items: center; gap: 10px; padding: 14px 18px; cursor: pointer; background: var(--surface-2); }
.lq-head:hover { background: var(--hover); }
.lq-head:focus-visible { outline: 2px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: -2px; }
.lq-head .chev { width: 7px; height: 7px; border-right: 1.7px solid var(--faint); border-bottom: 1.7px solid var(--faint); transform: rotate(-45deg); transition: transform .15s; margin-right: 2px; }
.lq-head[aria-expanded="true"] .chev { transform: rotate(45deg); }
.lq-head .title { font-weight: 600; font-size: 14px; }
.lq-head .hint { margin-left: auto; font-size: 11.5px; color: var(--faint); text-align: right; }
.lq-body { border-top: 1px solid var(--line-3); transition: opacity .15s; }
.lq-loading, .lq-empty { padding: 22px 18px; color: var(--muted); font-size: 13px; }
.lq-scroll { overflow-x: auto; position: relative; } /* positioned: keeps .sr-only header labels inside, so wide tables never widen the page */
.lq-table th { font-size: 10.5px; padding: 9px; }
.lq-table th a { color: var(--muted); text-decoration: none; }
.lq-table th a:hover, .lq-table th a.sorted { color: var(--brand-ink); }
.lq-table th .arrow { margin-left: 3px; }
.lq-table td { font-size: 11.5px; padding: 7px 9px; vertical-align: middle; }
.lq-table th:first-child, .lq-table td:first-child { padding-left: 18px; }
.lq-table th:last-child, .lq-table td:last-child { padding-right: 18px; }
.lq-table td.strong { font-weight: 500; }
.lq-table td.strong a { color: var(--text); }
.lq-table td.strong a:hover { color: var(--brand-ink); }
.lq-table td.col-charges { max-width: 220px; }
.lq-table td.col-quick { max-width: 240px; color: var(--muted); }
.lq-table svg.ic { width: 14px; height: 14px; }
.nowrap { white-space: nowrap; }
.idle { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--danger); color: var(--danger); font-weight: 700; font-size: 11px; }
.lq-pager { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 18px; border-top: 1px solid var(--line-3); }
.lq-pager .pages { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.lq-pager .btn.disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }
nav[role="navigation"] svg { width: 14px; height: 14px; max-width: 14px; max-height: 14px; }

/* ── Lead summary ──────────────────────────────────────── */
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px 18px; }
.kv .k { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.kv .v { font-size: 13px; font-weight: 500; }
.note-item { padding: 12px 18px; border-top: 1px solid var(--line-3); }
.note-item:first-child { border-top: 0; }
.note-item .meta { font-size: 11.5px; color: var(--muted); margin-bottom: 3px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.note-item .body { font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ── Lead edit form ────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px 16px; align-items: start; }
.form-grid .fld { margin: 0; }
.form-grid .fld input, .form-grid .fld select, .form-grid .fld textarea { max-width: 100%; }
.form-grid .fld-wide, .form-grid .fld-wrap { grid-column: 1 / -1; }
.form-grid .fld-wrap > .fld { max-width: 50%; }
.fld label { margin-bottom: 5px; }
.fld .req { color: var(--danger); margin-left: 2px; }
:is(.fld.has-error, .fld:has(.error-text:not(:empty))) > label { color: var(--danger); }
:is(.fld.has-error, .fld:has(.error-text:not(:empty))) :is(input, select, textarea) { border-color: var(--danger); background-color: color-mix(in srgb, var(--danger) 4%, var(--surface)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 12%, transparent); }
:is(.fld.has-error, .fld:has(.error-text:not(:empty))) :is(input, select, textarea):focus { border-color: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 22%, transparent); }
:is(.card.has-error, .card:has(.fld.has-error, .fld .error-text:not(:empty))):not(.aps-dialog) { border-color: color-mix(in srgb, var(--danger) 55%, var(--line)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 10%, transparent); }
:is(.card.has-error, .card:has(.fld.has-error, .fld .error-text:not(:empty))):not(.aps-dialog) > .card-head { background: color-mix(in srgb, var(--danger) 8%, var(--surface-2)); border-bottom-color: color-mix(in srgb, var(--danger) 25%, var(--line-3)); color: var(--danger); }
.error-text { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 12px; font-weight: 500; line-height: 1.35; color: var(--danger); }
.error-text:empty, .error-text[hidden] { display: none; }
.error-text::before { content: ""; width: 14px; height: 14px; flex: 0 0 auto; background: var(--danger); -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 8v5'/%3E%3Ccircle cx='12' cy='16.5' r='.75' fill='%23000'/%3E%3C/svg%3E") center/contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 8v5'/%3E%3Ccircle cx='12' cy='16.5' r='.75' fill='%23000'/%3E%3C/svg%3E") center/contain no-repeat; }
:is(.note-actions, .dlg-actions, .bond-forms-footer) .error-text { margin-top: 0; }
.fld-check { padding-top: 22px; }
.fld input[readonly], .fld textarea[readonly], .fld select:disabled { background-color: var(--surface-2); color: var(--muted); }
.seg-radio { display: flex; gap: 16px; flex-wrap: wrap; padding-top: 4px; }
details.form-section { margin-top: 14px; overflow: hidden; }
details.form-section > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
details.form-section > summary::-webkit-details-marker { display: none; }
details.form-section > summary::before { content: ""; width: 7px; height: 7px; border-right: 1.7px solid var(--faint); border-bottom: 1.7px solid var(--faint); transform: rotate(-45deg); transition: transform .15s; }
details.form-section[open] > summary::before { transform: rotate(45deg); }
details.form-section:not([open]) > summary { border-bottom: 0; border-radius: var(--r-card); }
.form-savebar { position: sticky; bottom: 8px; z-index: 20; display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 16px; padding: 12px 16px; background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(6px); border: 1px solid var(--line); border-radius: 14px; }
.form-savebar.dirty { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); box-shadow: 0 8px 24px rgba(20, 22, 26, .1); }
.form-savebar #dirty-flag { margin-right: auto; }
.form-savebar.dirty #dirty-flag { color: var(--warn); font-weight: 600; }
@media (max-width: 720px) { .form-grid .fld-wrap > .fld { max-width: none; } }

/* ── Dialogs & toasts (unsaved changes, session, address) ─ */
.aps-dialog { width: min(480px, calc(100% - 32px)); padding: 0; border: 1px solid var(--line); box-shadow: 0 20px 50px rgba(20,22,26,.25); }
.aps-dialog .card-head { gap: 10px; }
.aps-dialog .dlg-icon { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--warn-soft); color: var(--warn); font-weight: 700; font-size: 13px; flex: 0 0 auto; }
.aps-dialog .dlg-icon.danger { background: var(--danger-soft); color: var(--danger); }
.aps-dialog .dlg-icon.info { background: var(--pill); color: var(--accent); }
.aps-dialog .dlg-actions .btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.aps-dialog .dlg-actions .btn-danger:hover { filter: brightness(.95); }
.aps-dialog .dlg-body p { margin: 0 0 6px; font-size: 13.5px; }
.aps-dialog .dlg-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--line-3); }
.aps-dialog .dlg-foot { padding: 0 20px 14px; text-align: center; font-size: 12px; }
.aps-dialog .dlg-foot:empty { display: none; }
.addr-dialog { width: min(620px, calc(100% - 32px)); }
.address-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sess { text-align: center; }
.sess-count { font-size: 34px; font-weight: 600; letter-spacing: -1px; color: var(--danger); }
.aps-toast { position: fixed; top: 74px; right: 18px; z-index: 100; background: #1a1c20; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px; box-shadow: 0 8px 24px rgba(20,22,26,.25); opacity: 0; transform: translateY(-8px); transition: opacity .25s, transform .25s; }
.aps-toast.show { opacity: 1; transform: none; }

/* Settings */
.settings-tile { text-decoration: none !important; color: var(--text); transition: border-color .15s; }
.settings-tile:hover { border-color: var(--brand); }
.settings-tile .top { display: flex; align-items: center; gap: 12px; }
.seg-opt { display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 14px; border-radius: 7px; font-size: 12.5px; font-weight: 500; color: var(--muted); cursor: pointer; margin: 0; }
.seg-opt:has(input:checked) { background: var(--surface); color: var(--brand-ink); box-shadow: 0 1px 3px rgba(20,22,26,.1); }

/* ── Bonds ─────────────────────────────────────────────── */
.bonds-card { margin-top: 14px; overflow: hidden; }
.bonds-head { flex-wrap: wrap; }
.bonds-head .spacer { flex: 1; }
.bonds-table tfoot td { background: var(--surface-2); border-bottom: 0; }
.bond-dialog { width: min(860px, calc(100% - 32px)); max-height: calc(100dvh - 24px); }
.bond-dialog .card-body:first-of-type { max-height: calc(100dvh - 180px); overflow: auto; }
.input-icon.money .cur { position: absolute; left: 12px; top: 10px; color: var(--faint); font-size: 13px; pointer-events: none; }
.input-icon.money input { padding-left: 24px; }

/* ── RSOC ──────────────────────────────────────────────── */
.rsoc-section { padding: 14px 0; border-top: 1px solid var(--line-3); }
.rsoc-section:first-of-type { border-top: 0; padding-top: 0; }
.rsoc-section-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-weight: 600; font-size: 13px; margin-bottom: 10px; }
.rsoc-lines { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 14px; overflow: hidden; }
.rsoc-line { display: grid; grid-template-columns: minmax(180px, 1.2fr) 1fr minmax(140px, 180px); gap: 12px; align-items: center; padding: 8px 12px; border-top: 1px solid var(--line-3); }
.rsoc-line:first-child { border-top: 0; }
.rsoc-line .error-text { grid-column: 1 / -1; }
.rsoc-line.total { background: var(--surface-2); font-weight: 600; }
.rsoc-line .num { text-align: right; }
.rsoc-balance { height: 38px; display: flex; align-items: center; font-weight: 600; font-size: 15px; color: var(--ok); }
.rsoc-balance.due { color: var(--danger); }
@media (max-width: 720px) { .rsoc-line { grid-template-columns: 1fr; } .rsoc-line .num { text-align: left; } }

/* ── Lead edit: toolbar, panels, notes ─────────────────── */
.lead-toolbar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: -6px 0 14px; }
.lead-toolbar .spacer { flex: 1; }
.lead-toolbar svg.ic { width: 14px; height: 14px; }
.lead-toolbar .panel-jump select { width: auto; min-width: 200px; height: 30px; font-size: 12px; }
.lead-panels { margin-top: 14px; }
.lead-panels > .lead-panel, .lead-panels > section.card { margin-top: 14px; }
.lead-panel-pending > summary { color: var(--muted); }
.lead-panel-pending .card-body { color: var(--text-2); }
.note-cats { display: flex; gap: 6px; flex-wrap: wrap; }
.note-form { margin-top: 12px; }
.note-form textarea { min-height: 96px; }
.note-actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
.note-actions .error-text { margin: 0 auto 0 0; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: flex-end; }
.panel-actions > span.muted:first-child { flex: 1 1 240px; min-width: 0; }
.panel-actions:has(> [hidden]:only-child) { display: none; }
.panel-form { margin-top: 4px; }
.family-table th[scope=row] { font-weight: 600; white-space: nowrap; vertical-align: middle; }
.family-table input { width: 100%; min-width: 120px; }
.cosigner-dialog { width: min(980px, calc(100% - 32px)); max-height: calc(100dvh - 24px); }
.cosigner-dialog .cosigner-body { max-height: calc(100dvh - 180px); overflow: auto; }
.cosigner-group { border: 0; border-top: 1px solid var(--line-3); margin: 0; padding: 12px 0 4px; min-width: 0; }
.cosigner-group:first-of-type { border-top: 0; padding-top: 0; }
.cosigner-group legend { font-weight: 600; font-size: 13px; padding: 0 0 6px; }
.cosigner-dialog .dlg-actions .error-text { margin: 0 auto 0 0; }
.addr-input { display: flex; gap: 6px; }
.take-dialog { width: min(860px, calc(100% - 32px)); max-height: calc(100dvh - 24px); }
.take-dialog .take-body { max-height: calc(100dvh - 180px); overflow: auto; }
.take-dialog .dlg-actions .error-text { margin: 0 auto 0 0; }
.take-form [hidden] { display: none !important; }
.lq-table td.num, .lq-table th.num { text-align: right; white-space: nowrap; }
.addr-input input { flex: 1; min-width: 0; }
.panel-form [hidden], .cosigner-form [hidden] { display: none !important; }
.notes-table td.note-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12.5px; }
.notes-list, .story-list { border-top: 1px solid var(--line-3); }

/* Print: just the lead, every section open (Drupal "Print"). */
@media print {
  .app-header, .app-sidebar, .app-footer, .crumbs, .no-print, .form-savebar, .page-head .actions, .note-cats, .note-form, .panel-actions, .panel-form, .lead-panel-pending, .address-actions, .alert { display: none !important; }
  body, .content { background: #fff; padding: 0; }
  .card { border-color: #ccc; break-inside: avoid; }
  input, select, textarea { border: 0 !important; padding: 0 !important; height: auto !important; background: none !important; }
}

/* WP8: bond forms + signature doc */
.col-check { width: 32px; }
.nowrap { white-space: nowrap; }
.plain-list { margin: 0; padding-left: 16px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.signature-table tr.is-expired td { opacity: .5; }
.signature-dialog { width: min(760px, calc(100% - 32px)); max-height: calc(100dvh - 24px); }
.signature-dialog .sig-body { max-height: calc(100dvh - 180px); overflow: auto; overflow-x: hidden; }
.signature-dialog fieldset { min-width: 0; border: 1px solid var(--line-3); border-radius: 10px; padding: 8px 12px 10px; margin: 0 0 12px; }
.signature-dialog legend { font-size: 12.5px; font-weight: 600; padding: 0 4px; }
.signature-dialog .pick-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 4px 12px; }
.signature-dialog .pick-tools { display: flex; gap: 6px; margin: 0 0 6px; }
.signature-log { font-size: 12.5px; margin: 0; padding-left: 18px; }
.bond-forms-actions { margin-bottom: 12px; }
.bond-forms-btns { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.bond-forms-btns:empty { display: none; }
.bond-forms-btns form { margin: 0; display: flex; }
@media (max-width: 640px) {
  .bond-forms-btns { width: 100%; }
  .bond-forms-btns > * { flex: 1 1 auto; }
  .bond-forms-btns .btn, .bond-forms-footer .btn { width: 100%; min-height: 36px; font-size: 12.5px; }
  .bond-forms-footer .error-text:not(:empty) { flex: 1 1 100%; }
}

/* WP6: approvals + conditions */
.pick-list.conditions-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px 14px; margin: 0 0 12px; }
.ankle-fields { min-width: 0; border: 1px solid var(--line-3); border-radius: 10px; padding: 8px 12px 10px; margin: 0 0 12px; }
.ankle-fields legend { font-size: 12.5px; font-weight: 600; padding: 0 4px; }
.approval-banner { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.approval-banner .approval-text { flex: 1 1 260px; min-width: 0; }
.approval-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.approval-banner form { margin: 0; }
.alert-warn { background: var(--warn-soft); color: var(--warn); }
.card-body > .lq-scroll { border: 1px solid var(--line-3); border-radius: 10px; }

/* Lead History panel */
.history-summary-bar { display: flex; flex-wrap: wrap; gap: 16px 24px; padding: 10px 14px; background: var(--bg-subtle, rgba(0,0,0,0.02)); border: 1px solid var(--line-2, #e5e7eb); border-radius: 6px; margin-bottom: 12px; align-items: center; }
.history-summary-item { display: flex; flex-direction: column; gap: 2px; }
.history-summary-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.history-summary-value { font-size: 13.5px; font-weight: 700; color: var(--text); }
.history-summary-sub { font-size: 11px; color: var(--muted); }
.history-summary-action { flex: 1 1 200px; min-width: 0; }
.history-summary-text { font-size: 12.5px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }

.history-filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.history-filters select, .history-filters input[type=search] { width: auto; min-width: 160px; }
.history-list { list-style: none; margin: 0; padding: 0; }
.history-item { position: relative; border-left: 3px solid var(--line); padding: 8px 10px 10px 12px; margin-left: 4px; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; transition: background .15s ease; }
.history-item:hover { background: rgba(0, 0, 0, 0.015); }
.history-item + .history-item { border-top: 1px solid var(--line-3); }

/* Category accents */
.history-item-lead { border-left-color: #3b82f6; }
.history-item-bond { border-left-color: #6366f1; }
.history-item-payment { border-left-color: #10b981; }
.history-item-form { border-left-color: #f59e0b; }
.history-item-contact { border-left-color: #06b6d4; }
.history-item-note { border-left-color: #8b5cf6; }
.history-item-cosigner { border-left-color: #ec4899; }
.history-item-rsoc { border-left-color: #14b8a6; }

.history-main { flex: 1 1 auto; min-width: 0; }
.history-head { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: baseline; }
.history-summary { font-weight: 600; font-size: 13.5px; }
.history-meta { margin-left: auto; white-space: nowrap; font-size: 12px; }
.history-ip { font-family: monospace; font-size: 11px; }

/* Quick summary */
.history-quick-summary { margin-top: 5px; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: 12.5px; }
.history-chip { display: inline-flex; align-items: center; padding: 1px 7px; border-radius: 10px; font-size: 11px; font-weight: 600; line-height: 1.4; background: var(--line-3, #f1f5f9); color: var(--text); }
.history-chip-changes { background: #eff6ff; color: #1e40af; border: 1px solid #dbeafe; }
.history-chip-form { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.history-diff-inline { display: inline-flex; align-items: center; gap: 6px; background: rgba(0,0,0,0.02); padding: 2px 7px; border-radius: 4px; border: 1px solid var(--line-3); font-size: 12px; }
.history-diff-label { font-weight: 600; color: var(--muted); }
.history-arrow { color: var(--muted); font-size: 11px; }
.history-snippet { word-break: break-word; }

.history-actions { flex: none; align-self: flex-start; margin-top: 2px; }
.history-view-btn { font-size: 12px; padding: 0 10px; height: 28px; color: var(--primary, #0284c7); background: transparent; border: 1px solid var(--line); border-radius: 4px; cursor: pointer; transition: all .15s ease; }
.history-view-btn:hover { background: var(--primary, #0284c7); color: #fff; border-color: var(--primary, #0284c7); }

/* History modal dialog */
.history-detail-dialog { border-radius: 8px; box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25); }
.history-dialog-head { display: flex; justify-content: space-between; align-items: center; }
.history-dialog-meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px 14px; padding: 10px 12px; background: var(--bg-subtle, #f8fafc); border: 1px solid var(--line-3, #e2e8f0); border-radius: 6px; }
.history-meta-field { display: flex; flex-direction: column; gap: 2px; }
.history-meta-label { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.history-meta-value { font-size: 12.5px; color: var(--text); font-weight: 500; word-break: break-word; }
.history-detail-table { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 12.5px; }
.history-detail-table th, .history-detail-table td { padding: 6px 8px; border: 1px solid var(--line-3, #e2e8f0); text-align: left; vertical-align: top; }
.history-detail-table th { background: var(--bg-subtle, #f1f5f9); font-weight: 600; font-size: 11.5px; color: var(--text); }
.history-detail-table td.history-old { background: rgba(239, 68, 68, 0.05); color: var(--danger); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--danger) 40%, transparent); word-break: break-word; }
.history-detail-table td.history-new { background: rgba(16, 185, 129, 0.05); color: var(--ok); font-weight: 500; word-break: break-word; }

.history-forms { margin-top: 4px; }
.history-changes { margin-top: 6px; }
.history-changes > summary { cursor: pointer; color: var(--muted); }
.history-table { margin-top: 6px; font-size: 13px; }
.history-table td { vertical-align: top; overflow-wrap: anywhere; }
.history-table th:first-child, .history-table td:first-child { width: 28%; }
.history-old { color: var(--danger); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.history-new { color: var(--ok); }
.history-tag { flex: none; }
@media (max-width: 900px) {
  .lead-toolbar { gap: 8px; }
  .lead-toolbar .spacer { display: none; }
  .lead-toolbar .panel-jump { flex: 1 1 100%; }
  .lead-toolbar .panel-jump select { width: 100%; min-width: 0; height: 38px; font-size: 13px; }
}
@media (max-width: 640px) {
  .history-meta { margin-left: 0; white-space: normal; }
  .history-item { flex-direction: column; }
  .history-actions { align-self: flex-end; }
  .history-filters select, .history-filters input[type=search] { width: 100%; min-width: 0; }
  .page-head { align-items: flex-start; gap: 12px; }
  .page-head .actions { position: relative; width: 100%; }
  .page-head .actions details.popover { position: static; }
  .page-head .actions details.popover .pop { left: 0; right: 0; top: calc(100% + 6px); width: auto; max-width: 340px; }
  .form-savebar { position: static; flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .form-savebar.dirty { position: sticky; bottom: 8px; }
  .form-savebar #dirty-flag { flex: 1 1 100%; font-size: 12px; }
  .form-savebar .btn { flex: 1 1 auto; }
  .lead-toolbar .btn, .note-cats .btn, .note-actions .btn, .aps-dialog .dlg-actions .btn { flex: 1 1 auto; min-height: 36px; }
  .note-actions .error-text:not(:empty) { flex: 1 1 100%; }
  .lead-panels .btn-sm, .lead-toolbar .btn-sm, .ssn-tools .btn-sm, .address-actions .btn-sm, .history-view-btn, .aps-dialog .btn-sm { min-height: 36px; padding: 0 12px; font-size: 12.5px; }
  .approval-actions { width: 100%; }
  .approval-actions > form { flex: 1 1 auto; display: flex; }
  .approval-actions .btn { flex: 1 1 auto; width: 100%; }
  .aps-dialog { width: calc(100vw - 24px); max-width: none; }
  .rsoc-section-head select { width: 100%; }
  .addr-input { flex-wrap: wrap; }
  .addr-input input { flex: 1 1 180px; }
  .notes-table thead { display: none; }
  .notes-table, .notes-table tbody { display: block; width: 100%; }
  .notes-table tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 10px; padding: 12px 16px; border-bottom: 1px solid var(--line-3); align-items: start; }
  .notes-table tr:last-child { border-bottom: 0; }
  .notes-table tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
  .notes-table tbody tr:hover td { background: transparent; }
  .notes-table td { display: block; border: 0; padding: 0; }
  .notes-table td.note-date { grid-column: 1; font-size: 11.5px; color: var(--muted); }
  .notes-table td.note-author { grid-column: 1; font-size: 12px; font-weight: 500; color: var(--text-2); overflow-wrap: anywhere; }
  .notes-table td.note-del { grid-column: 2; grid-row: 1 / span 2; justify-self: end; }
  .notes-table td.note-text { grid-column: 1 / -1; font-size: 13px; padding-top: 4px; line-height: 1.45; }
  .family-form > .lq-scroll { border: 0; border-radius: 0; overflow: visible; }
  .family-table thead { display: none; }
  .family-table, .family-table tbody, .family-table tr, .family-table th, .family-table td { display: block; width: 100%; }
  .family-table tr { padding: 10px 0; border-bottom: 1px solid var(--line-3); }
  .family-table tr:first-child { padding-top: 0; }
  .family-table tr:last-child { border-bottom: 0; padding-bottom: 0; }
  .family-table th[scope=row] { background: none; border: 0; padding: 0 0 6px; font-size: 12.5px; color: var(--text); white-space: normal; }
  .family-table td { border: 0; padding: 0 0 6px; }
  .family-table td:last-child { padding-bottom: 0; }
  .family-table input { min-width: 0; }
}

/* WP10: reports */
.table tr.row-danger td { background: var(--danger-soft); }
.report-filters .form-grid { margin-bottom: 0; }

/* FMS Monthly Claims Report V2 */
.claims-filter-card { margin-bottom: 16px; }
.claims-filter-grid { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.claims-filter-grid .field { margin-bottom: 0; flex: 0 1 200px; min-width: 140px; }
.claims-filter-grid .field:nth-child(2) { flex: 0 1 130px; min-width: 110px; }
.claims-filter-grid .field:nth-child(3) { flex: 1 1 240px; max-width: 340px; }
.claims-filter-actions { display: flex; gap: 8px; align-items: center; }

.claims-card { margin-bottom: 18px; overflow: hidden; }
.claims-card .card-head a { color: inherit; text-decoration: none; }
.claims-card .card-head a:hover { color: var(--brand-ink); }
.claims-table-wrap { overflow-x: auto; }

.claims-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.claims-table th,
.claims-table td { padding: 8px 11px; border-bottom: 1px solid var(--line-3); }
.claims-table thead th { background: var(--surface-2); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; color: var(--muted); }
.claims-table thead th a { color: var(--text-2); text-decoration: none; }
.claims-table thead th a:hover { color: var(--brand-ink); }
.claims-table .claims-group-head { text-align: center; background: var(--surface-2); color: var(--text); font-size: 11.5px; }
.claims-table .claims-sub-head { text-align: center; }
.claims-table .claims-col-office { vertical-align: bottom; min-width: 150px; }
.claims-table .claims-divider { border-left: 1px solid var(--line); }
.claims-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.claims-table tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 65%, transparent); }
.claims-table .claims-office-name { font-weight: 600; text-transform: uppercase; white-space: nowrap; }
.claims-table .claims-row-label { font-weight: 500; }
.claims-table .claims-row-label a { color: var(--text); text-decoration: none; }
.claims-table .claims-row-label a:hover { color: var(--brand-ink); text-decoration: underline; }
.claims-table .claims-liab-cell { display: inline-flex; align-items: center; justify-content: flex-end; gap: 8px; }
.claims-table .claims-view-link { font-size: 11px; color: var(--muted); text-decoration: none; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line); }
.claims-table .claims-view-link:hover { color: var(--brand-ink); border-color: var(--brand-ink); background: var(--brand-soft); }
.claims-table tfoot td { background: var(--surface-2); font-weight: 700; border-top: 1px solid var(--line); border-bottom: 0; }
.claims-table tfoot tr.claims-pct-row td { font-weight: 600; color: var(--text-2); background: var(--surface); border-top: 1px solid var(--line-3); }

.claims-bottom-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.claims-side-stack { display: flex; flex-direction: column; gap: 0; }
@media (max-width: 980px) {
  .claims-bottom-grid { grid-template-columns: 1fr; }
}

@media print {
  @page { size: landscape; margin: 8mm; }
  .no-print, .app-header, .app-nav, .crumbs { display: none !important; }
  body { font-size: 10.5px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .claims-card { box-shadow: none !important; border: 1px solid #cbd5e1 !important; margin-bottom: 10px; }
  .claims-table th, .claims-table td { padding: 4px 6px !important; font-size: 10px !important; }
  .claims-bottom-grid { grid-template-columns: 1.35fr 1fr !important; gap: 10px !important; }
}

/* ---- Reports (Drupal `reports` module) ---- */
.report-group { font-size: 13px; font-weight: 600; color: var(--text-2); margin: 18px 0 10px; text-transform: uppercase; letter-spacing: .04em; }
.report-tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); }
.report-tile { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); color: var(--text); text-decoration: none !important; }
.report-tile:hover { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.report-tile strong { display: block; font-weight: 600; margin-bottom: 2px; }
.report-tile .tile { flex: 0 0 auto; }
.take-table td, .take-table th { white-space: nowrap; }
.take-manager th { background: var(--surface-2); text-align: left; font-weight: 600; }
.take-total td { font-weight: 600; border-bottom: 2px solid var(--line-2); }
.take-grand td { font-weight: 700; background: var(--brand-soft); color: var(--brand-ink); }
.take-as td { background: var(--surface-2); }
.take-gap td { padding: 4px; border: 0; }
.seo-charts { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(420px, 100%), 1fr)); }
.seo-chart-wide { grid-column: 1 / -1; }
.seo-chart svg { width: 100%; height: auto; display: block; }
.seo-chart .axis { stroke: var(--line-2); }
.seo-chart .line { fill: none; stroke: var(--brand); stroke-width: 2; }
.seo-chart circle { fill: var(--brand); }
.seo-chart text { font-size: 10px; fill: var(--muted); }
.inline-form { display: inline-flex; }
.inline-form select { height: 36px; }
.center { text-align: center; }
.fld > .label { display: block; font-size: 12px; font-weight: 500; color: var(--text-2); margin-bottom: 6px; }
/* Forms & Procedures library (resources/views/forms) */
.forms-add { margin-bottom: 16px; }
.forms-add > summary { cursor: pointer; list-style: none; }
.forms-add > summary::-webkit-details-marker { display: none; }
.forms-add:not([open]) > summary { border-bottom: 0; border-radius: var(--r-card); }
.forms-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.forms-cat .card-head { justify-content: space-between; }
.forms-table td { vertical-align: middle; }
.forms-table .forms-order { width: 36px; }
.forms-table .forms-ext { margin-left: 6px; }
.forms-actions { text-align: right; width: 1%; }
.forms-actions form { display: inline-flex; }
.forms-actions .btn-sm .ic { width: 14px; height: 14px; }
.forms-cat-table td { vertical-align: middle; }
.forms-cat-table .forms-cat-order input { width: 90px; }

/* ---- Agent policies / ROB (policies/*.blade.php, js/policies.js) ---- */
.pol-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: -6px 0 14px; }
.pol-tabs a { padding: 6px 12px; border-radius: 999px; font-size: 12.5px; color: var(--muted); border: 1px solid var(--line); background: var(--surface); text-decoration: none; }
.pol-tabs a.on, .pol-tabs a:hover { color: var(--brand-ink); background: var(--brand-soft); border-color: transparent; }
.pol-list { display: flex; flex-direction: column; gap: 10px; }
.pol-item > summary { display: flex; align-items: center; gap: 12px; padding: 14px 18px; cursor: pointer; font-weight: 600; list-style: none; }
.pol-item > summary::-webkit-details-marker { display: none; }
.pol-item > summary::before { content: '›'; font-size: 18px; line-height: 1; color: var(--muted); transition: transform .15s; }
.pol-item[open] > summary::before { transform: rotate(90deg); }
.pol-item[open] > summary { border-bottom: 1px solid var(--line); }
.pol-item .pol-cat { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.pol-title { margin: 0 0 12px; font-size: 17px; }
.pol-content { font-size: 14px; line-height: 1.6; overflow-wrap: anywhere; }
.pol-content p, .pol-content ul, .pol-content ol { margin: 0 0 1em; }
.pol-content ul, .pol-content ol { padding-left: 1.4em; }
.pol-content h2, .pol-content h3, .pol-content h4 { margin: 1em 0 .5em; }
.pol-content table { border-collapse: collapse; max-width: 100%; }
.pol-content td, .pol-content th { border: 1px solid var(--line); padding: 4px 8px; }
.pol-sign { margin-top: 20px; padding-top: 16px; border-top: 1px dashed var(--line); display: flex; flex-direction: column; gap: 8px; max-width: 640px; }
.pol-sig-box { border: 1px solid var(--line); border-radius: 10px; background: #fff; min-height: 80px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.pol-sig-box canvas { display: block; width: 100%; touch-action: none; cursor: crosshair; }
.pol-sig-box img { max-width: 100%; max-height: 220px; }
.pol-sign-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pol-err { color: var(--danger); }
.pol-sig-thumb { max-width: 150px; max-height: 60px; background: #fff; border: 1px solid var(--line); border-radius: 6px; }
.pol-order { width: 80px; }
tr.pol-deleted td { opacity: .6; }
.pol-check { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; margin-top: 8px; }
.pol-toolbar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.pol-source { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12.5px; width: 100%; }
.pol-preview { border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; min-height: 200px; }

/* Take Data + Deposits (resources/views/takes) */
.take-totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0; }
.take-totals > div { display: flex; flex-direction: column; gap: 2px; padding: 12px 16px; border-right: 1px solid var(--line); }
.take-totals > div:last-child { border-right: 0; }
.take-totals strong { font-size: 17px; font-variant-numeric: tabular-nums; }
.take-search { margin-top: 14px; }
.take-search > summary { cursor: pointer; font-weight: 600; font-size: 13px; color: var(--brand-ink); }
.take-lead-takes { margin-top: 16px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.take-lead-takes .card-head { border-bottom: 1px solid var(--line); }
.take-lead-takes > p { padding: 10px 14px; margin: 0; }
.take-lead-takes tr.is-current td { background: var(--brand-soft); }
.inline-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.deposit-report .dr-section th { background: var(--surface-2); text-align: left; }
.deposit-report .dr-total td { font-weight: 600; background: color-mix(in srgb, var(--surface-2) 50%, transparent); }
.deposit-report .dr-grand td { font-weight: 700; border-top: 2px solid var(--line-2); }
@media (max-width: 720px) { .take-totals > div { border-right: 0; border-bottom: 1px solid var(--line); } }

/* Admin → Data sync */
.sync-source { font-size: 15px; font-weight: 600; margin-top: 12px; word-break: break-all; }
.sync-actions { display: grid; grid-template-columns: minmax(200px, 260px) 1fr; gap: 24px; align-items: start; }
.sync-actions form + form { border-left: 1px solid var(--line-3); padding-left: 24px; }
.sync-parts { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px 16px; margin-bottom: 14px; }
.sync-progress { margin-bottom: 14px; }
.sync-progress-label { font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.sync-bar { height: 10px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.sync-bar-fill { height: 100%; background: var(--brand); border-radius: 999px; transition: width .4s ease; }
.sync-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.sync-log-wrap { margin-top: 14px; }
.sync-log-wrap summary { cursor: pointer; }
.sync-log { font: 11.5px/1.5 var(--mono); background: var(--surface-2); border: 1px solid var(--line-3); border-radius: 8px; padding: 10px 12px; margin: 8px 0 0; max-height: 280px; overflow: auto; white-space: pre-wrap; word-break: break-word; }
.table tr.row-selected td { background: var(--brand-soft); }
@media (max-width: 760px) { .sync-actions { grid-template-columns: 1fr; } .sync-actions form + form { border-left: 0; padding-left: 0; border-top: 1px solid var(--line-3); padding-top: 16px; } }

/* Call recordings (recordings/*) */
.rec-audio { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.rec-audio audio { width: 100%; max-width: 420px; }
.rec-summary { margin: 0 0 14px; white-space: pre-wrap; }
.rec-dialogue { display: grid; gap: 8px; max-height: 480px; overflow: auto; }
.rec-line { display: grid; grid-template-columns: 110px 1fr; gap: 10px; font-size: 13px; }
.rec-speaker { font-weight: 600; color: var(--muted); text-transform: capitalize; }
@media (max-width: 760px) { .rec-line { grid-template-columns: 1fr; gap: 2px; } }

/* Phone: numbers, call routing, campaigns, blacklist (resources/views/phone) */
.phone-tabs { margin-bottom: 14px; }
.phone-url { min-width: 200px; max-width: 320px; overflow-wrap: anywhere; font-size: 12px; }
.phone-reason { max-width: 420px; white-space: pre-wrap; overflow-wrap: anywhere; }
.phone-check-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.phone-check-grid textarea { width: 100%; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }

/* Powers inventory (bulk actions bar, dialog fieldsets) */
fieldset.plain { border: 0; padding: 0; margin: 0 0 10px; min-width: 0; }
fieldset.plain[disabled] { display: none; }
.bulk-bar { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.bulk-bar select { width: auto; min-width: 220px; }
/* SMS (log, message dialog, client page) */
tr.row-warn td { background: var(--warn-soft, #fff8e6); }
dl.sms-meta { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; font-size: 13px; }
dl.sms-meta dt { color: var(--muted); }
dl.sms-meta dd { margin: 0; }
.sms-preview { white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 13px; min-height: 44px; }
