:root {
  --bg: #f4f6f9; --card: #fff; --ink: #1c2330; --muted: #667085; --line: #e2e6ed;
  --accent: #2457d6; --accent-ink: #fff; --ok: #127a43; --warn: #a15c00; --bad: #b42318;
  --zone: #d92d20; --mask: #f79009; --box: #2457d6; --boy: #2457d6; --girl: #c11574;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418; --card: #1a1f26; --ink: #e8ebf0; --muted: #98a2b3; --line: #2a313b;
    --accent: #6b93ff; --accent-ink: #0b1020; --ok: #4ac283; --warn: #f0b04a; --bad: #ff8a80; --boy: #8fb0ff; --girl: #ff86c8;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; }
a { color: var(--accent); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 12px; align-items: start; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; min-width: 0; }
.card h3:first-child { margin-top: 0; }
.stat .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .v { font-size: 24px; font-weight: 650; }
.sub, .muted { color: var(--muted); font-size: 12px; }
.tablewrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: start; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover, tr.sel { background: color-mix(in srgb, var(--accent) 9%, transparent); }
td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; border: 1px solid var(--line); white-space: nowrap; }
.pill.ok { color: var(--ok); border-color: var(--ok); }
.pill.warn { color: var(--warn); border-color: var(--warn); }
.pill.bad { color: var(--bad); border-color: var(--bad); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
label.f { display: grid; gap: 3px; font-size: 12px; color: var(--muted); }
label.f > span { font-weight: 600; }
label.inline { display: inline-flex; gap: 6px; align-items: center; }
input, select, textarea, button.btn { font: inherit; padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); min-width: 0; }
input[type="number"] { width: 72px; }
input.wide, select.wide, textarea.wide { width: 100%; }
textarea { min-height: 70px; resize: vertical; }
button.btn { cursor: pointer; white-space: nowrap; }
button.btn:hover { border-color: var(--accent); }
button.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.btn.danger { color: var(--bad); border-color: var(--bad); }
button.btn.small { padding: 3px 8px; font-size: 12px; }
button.btn:disabled { opacity: .5; cursor: default; }
.msg { padding: 8px 12px; border-radius: 8px; margin: 8px 0; border: 1px solid var(--line); }
.msg.ok { color: var(--ok); border-color: var(--ok); }
.msg.bad { color: var(--bad); border-color: var(--bad); }
.msg.warn { color: var(--warn); border-color: var(--warn); }
.login { max-width: 360px; margin: 10vh auto; padding: 0 16px; }
.login form { display: grid; gap: 10px; }
.login h1 { font-size: 18px; }
.err { color: var(--bad); min-height: 1.2em; }
.panel { margin-top: 12px; }
.empty { color: var(--muted); padding: 18px; text-align: center; }
.token { font-family: ui-monospace, Consolas, monospace; background: color-mix(in srgb, var(--accent) 10%, transparent); padding: 8px; border-radius: 8px; word-break: break-all; user-select: all; }
.qimg { max-width: 100%; max-height: 420px; border: 1px solid var(--line); border-radius: 8px; }
iframe.pdf { width: 100%; height: 75vh; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

/* Layout editor */
.editor { display: grid; grid-template-columns: minmax(300px, 460px) 1fr; gap: 14px; align-items: start; }
@media (max-width: 900px) { .editor { grid-template-columns: 1fr; } }
.sheet-wrap { position: sticky; top: 64px; }
svg.sheet { width: 100%; height: auto; background: #fff; border: 1px solid var(--line); border-radius: 4px; touch-action: none; user-select: none; }
svg.sheet .margin { fill: none; stroke: #98a2b3; stroke-dasharray: 2 1.5; stroke-width: .3; }
svg.sheet .zone { fill: rgba(217, 45, 32, .14); stroke: var(--zone); stroke-width: .4; }
svg.sheet .mask { fill: rgba(247, 144, 9, .10); stroke: var(--mask); stroke-dasharray: 1.5 1; stroke-width: .4; }
svg.sheet .box { fill: rgba(36, 87, 214, .08); stroke: var(--box); stroke-width: .4; cursor: move; }
svg.sheet .box.block { stroke-dasharray: 2 1; }
svg.sheet .sel { stroke-width: .9; fill: rgba(36, 87, 214, .18); }
svg.sheet .zone.sel { fill: rgba(217, 45, 32, .25); }
svg.sheet .handle { fill: var(--box); cursor: nwse-resize; }
svg.sheet text { font: 3px sans-serif; fill: #344054; pointer-events: none; }
svg.sheet .grid5 { stroke: #e4ecf7; stroke-width: .15; }
svg.sheet .grid10 { stroke: #c9d7ee; stroke-width: .25; }
.elist { display: grid; gap: 6px; }
.el { border: 1px solid var(--line); border-radius: 10px; padding: 8px; display: grid; gap: 6px; }
.el.sel { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.el .head { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.el .kind { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 1px 6px; border-radius: 6px; }
.kind.field, .kind.block { color: var(--box); border: 1px solid var(--box); }
.kind.zone { color: var(--zone); border: 1px solid var(--zone); }
.kind.mask { color: var(--mask); border: 1px solid var(--mask); }
.mm { display: flex; gap: 6px; flex-wrap: wrap; }
.mm label { display: inline-flex; gap: 3px; align-items: center; font-size: 12px; color: var(--muted); }
.mm input { width: 62px; }
[dir="rtl"] .mm input, [dir="rtl"] input[type="number"] { direction: ltr; }
.mt8 { margin-top: 8px; }
.mt12 { margin-top: 12px; }
.mt16 { margin-top: 16px; }
.hidden { display: none !important; }
.pdfpages { display: grid; gap: 10px; justify-items: center; background: #8a8f98; padding: 10px; border-radius: 8px; overflow-x: auto; }
canvas.pdfpage { background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .35); max-width: 100%; height: auto; }
a.btn { text-decoration: none; display: inline-block; }

/* Documents (home) and agencies */
.doclist { display: grid; gap: 12px; }
.gc { padding: 0; overflow: hidden; }
.stale { padding: 8px 14px; color: var(--warn); background: color-mix(in srgb, var(--warn) 8%, transparent); border-bottom: 1px solid var(--line); }
.doc { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.doc:last-child { border-bottom: 0; }
.doc-icon { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; font-size: 20px; font-weight: 700; }
.doc-icon.m { background: color-mix(in srgb, var(--boy) 16%, transparent); color: var(--boy); }
.doc-icon.f { background: color-mix(in srgb, var(--girl) 16%, transparent); color: var(--girl); }
.doc-name { font-size: 14px; }
.doc .muted { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 2px; }
.doc-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.doc-actions .btn { padding: 7px 12px; }
button.btn.icon { padding: 7px 10px; }
@media (max-width: 640px) {
  .doc { grid-template-columns: 36px 1fr; }
  .doc-actions { grid-column: 1 / -1; justify-content: stretch; }
  .doc-actions .btn { flex: 1; }
}
.agencies { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.agency h3 { margin: 0; font-size: 15px; }
.agency.off { opacity: .55; }
.agency-nums { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 12px 0; text-align: center; }
.agency-nums .v { font-size: 20px; font-weight: 650; }
.agency-nums .k { font-size: 11px; color: var(--muted); }
.link { color: var(--accent); font-weight: 600; font-size: 13px; }
.printframe { position: fixed; left: -10000px; top: 0; width: 10px; height: 10px; border: 0; }
.modal { position: fixed; inset: 0; background: rgba(10, 14, 20, .55); z-index: 20; display: grid; place-items: center; padding: 16px; }
.modal-card { background: var(--card); border-radius: 14px; width: min(980px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; overflow: hidden; }
.modal-head { padding: 10px 14px; border-bottom: 1px solid var(--line); }
.modal-body { overflow: auto; padding: 12px; }
#toasts { position: fixed; bottom: 16px; inset-inline-end: 16px; display: grid; gap: 8px; z-index: 30; }
.toast { background: var(--card); border: 1px solid var(--line); border-inline-start: 4px solid var(--ok); border-radius: 10px; padding: 10px 14px; box-shadow: 0 4px 16px rgba(0, 0, 0, .15); max-width: 340px; }
.toast.bad { border-inline-start-color: var(--bad); }

/* App shell: side menu (bottom bar on phones), search bar, pages */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 6px; padding: 18px 12px; background: var(--card); border-inline-end: 1px solid var(--line); }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 10px 16px; color: var(--ink); text-decoration: none; font-weight: 700; font-size: 16px; }
.brand img { width: 28px; height: 28px; }
.nav { display: grid; gap: 4px; }
.nav-item { display: flex; gap: 12px; align-items: center; padding: 11px 12px; border-radius: 10px; color: var(--ink); text-decoration: none; font-weight: 550; }
.nav-item:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.nav-item.on { background: var(--accent); color: var(--accent-ink); }
.nav-icon { font-size: 18px; width: 24px; text-align: center; }
.nav-item .badge { margin-inline-start: auto; min-width: 22px; padding: 1px 7px; border-radius: 99px; background: var(--bad); color: #fff; font-size: 12px; text-align: center; }
.side-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--line); }
.who-name { font-weight: 600; }
.content { min-width: 0; display: flex; flex-direction: column; }
.bar { position: sticky; top: 0; z-index: 5; display: flex; gap: 10px; align-items: center; padding: 12px 24px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.search-form { flex: 1; position: relative; max-width: 640px; }
.search-icon { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); opacity: .6; pointer-events: none; }
input.search { width: 100%; padding: 11px 14px; padding-inline-start: 38px; border-radius: 12px; font-size: 15px; }
button.btn.add-btn { margin-inline-start: auto; padding: 10px 16px; border-radius: 12px; }
main { padding: 24px; max-width: 1100px; width: 100%; margin: 0 auto; }
.page-head { margin-bottom: 18px; }
.crumbs { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 13px; margin-bottom: 6px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }
.crumbs .sep { color: var(--muted); }
.crumbs .sep:last-child { display: none; }
.page-title { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.page-title h1 { margin: 0; font-size: 24px; line-height: 1.2; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
h2 { font-size: 16px; margin: 26px 0 10px; }
h3 { font-size: 14px; margin: 14px 0 6px; }
.section-head { display: flex; gap: 10px; align-items: center; margin: 26px 0 10px; }
.section-head h2 { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { display: flex; gap: 12px; align-items: center; color: var(--ink); text-decoration: none; padding: 14px 16px; }
.stat-icon { font-size: 22px; width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: color-mix(in srgb, var(--accent) 10%, transparent); flex: none; }
.stat .v { font-size: 22px; font-weight: 700; line-height: 1.15; }
.stat .k { font-size: 12.5px; color: var(--muted); }
.stat.warn .stat-icon { background: color-mix(in srgb, var(--warn) 16%, transparent); }
.stat.ok .stat-icon { background: color-mix(in srgb, var(--ok) 16%, transparent); }
.stat.bad .stat-icon { background: color-mix(in srgb, var(--bad) 16%, transparent); }
.stats.small .stat { padding: 10px 14px; }
.stats.small .stat-icon { width: 36px; height: 36px; font-size: 18px; }
.card.click { cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.card.click:hover { border-color: var(--accent); box-shadow: 0 4px 16px color-mix(in srgb, var(--accent) 14%, transparent); }
a.card { color: var(--ink); text-decoration: none; display: block; }
.banner { display: flex; gap: 10px; align-items: center; padding: 12px 16px; border-radius: 12px; margin-bottom: 10px; background: var(--card); border: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.banner.warn { border-color: color-mix(in srgb, var(--warn) 50%, var(--line)); background: color-mix(in srgb, var(--warn) 8%, var(--card)); }
.gc-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.gc-title { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; color: var(--ink); text-decoration: none; min-width: 0; }
.gc-title:hover strong { color: var(--accent); }
.gc-title strong { font-size: 16px; }
a.btn { display: inline-block; font: inherit; padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: var(--card); white-space: nowrap; }
a.btn:hover { border-color: var(--accent); }
span.btn.primary { display: inline-block; padding: 6px 12px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); white-space: nowrap; }
.linkbtn { border: 0; background: none; color: var(--muted); font: inherit; cursor: pointer; padding: 6px 0; }
.linkbtn:hover { color: var(--accent); }
.list { padding: 0; overflow: hidden; }
.list-row { display: flex; gap: 12px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.list-row:last-child { border-bottom: 0; }
a.list-row:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.list-sub { padding: 8px 16px; font-size: 12px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; color: var(--muted); background: var(--bg); border-bottom: 1px solid var(--line); }
.list-n { width: 24px; text-align: end; color: var(--muted); font-variant-numeric: tabular-nums; }
.grow { flex: 1; min-width: 0; }
input.grow { max-width: 280px; }
.doc-icon.tiny { width: 28px; height: 28px; font-size: 15px; border-radius: 8px; flex: none; }
details.more { position: relative; }
details.more summary { list-style: none; cursor: pointer; }
details.more summary::-webkit-details-marker { display: none; }
details.more .menu { position: absolute; inset-inline-end: 0; top: calc(100% + 6px); z-index: 10; min-width: 200px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .14); padding: 6px; display: grid; }
.menu-item { text-align: start; border: 0; background: none; color: var(--ink); font: inherit; padding: 9px 12px; border-radius: 8px; cursor: pointer; }
.menu-item:hover { background: var(--bg); }
.menu-item.danger { color: var(--bad); }
button.btn.icon.danger { color: var(--bad); }
.settings { display: grid; grid-template-columns: 220px 1fr; gap: 20px; align-items: start; }
.set-nav { display: grid; gap: 2px; position: sticky; top: 80px; }
.set-item { padding: 9px 12px; border-radius: 9px; color: var(--ink); text-decoration: none; }
.set-item:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.set-item.on { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); font-weight: 600; }
.set-body { min-width: 0; }
.set-title { margin-top: 0; }
.modal-card.wide { width: min(1000px, 100%); }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: auto 0 0 0; height: auto; z-index: 15; flex-direction: row; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); border-inline-end: 0; border-top: 1px solid var(--line); }
  .brand, .side-foot { display: none; }
  .nav { grid-template-columns: repeat(4, 1fr); width: 100%; gap: 2px; }
  .nav-item { flex-direction: column; gap: 2px; padding: 6px 4px; font-size: 11.5px; position: relative; }
  .nav-item .badge { position: absolute; top: 2px; inset-inline-end: 18%; margin: 0; min-width: 18px; padding: 0 5px; font-size: 11px; }
  .bar { padding: 10px 12px; }
  .add-label { display: none; }
  main { padding: 16px 12px 96px; }
  .page-title h1 { font-size: 21px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings { grid-template-columns: 1fr; }
  .set-nav { position: static; display: flex; overflow-x: auto; gap: 4px; padding-bottom: 4px; }
  .set-item { white-space: nowrap; border: 1px solid var(--line); background: var(--card); }
  input.grow { max-width: none; }
}
.stat .k { text-transform: none; letter-spacing: 0; }
summary.btn { display: inline-block; font: inherit; padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: var(--card); white-space: nowrap; }
summary.btn:hover { border-color: var(--accent); }
button.btn.icon.danger { color: var(--muted); border-color: transparent; background: none; }
button.btn.icon.danger:hover { color: var(--bad); border-color: var(--bad); }
