/* Scan to Exel — design tokens + components. Logical properties keep RTL/LTR symmetric. */
:root {
  --primary: #2563eb;
  --primary-ink: #ffffff;
  --secondary: #0f172a;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --border-strong: #cfd4dc;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #8a94a6;
  --ok: #15803d;
  --ok-bg: #e8f6ee;
  --warn: #b45309;
  --warn-bg: #fdf3e2;
  --err: #b91c1c;
  --err-bg: #fdecec;
  --info-bg: #eaf1fe;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 1px rgba(15, 23, 42, .03);
  --shadow-lg: 0 8px 24px rgba(15, 23, 42, .08);
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px; --space-6: 32px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-fa: "Vazirmatn", "Segoe UI", Tahoma, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sidebar: 236px;
  --ctl-h: 38px; --ctl-h-sm: 32px; --ctl-gap: 12px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0b1120; --surface: #111827; --surface-2: #1a2333; --border: #243045; --border-strong: #33415a;
  --text: #e5e9f0; --text-2: #aab4c3; --text-3: #7b8799;
  --ok: #4ade80; --ok-bg: #11291c; --warn: #fbbf24; --warn-bg: #2d2311; --err: #f87171; --err-bg: #2f1517; --info-bg: #14223c;
  --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 8px 24px rgba(0,0,0,.4);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #0b1120; --surface: #111827; --surface-2: #1a2333; --border: #243045; --border-strong: #33415a;
    --text: #e5e9f0; --text-2: #aab4c3; --text-3: #7b8799;
    --ok: #4ade80; --ok-bg: #11291c; --warn: #fbbf24; --warn-bg: #2d2311; --err: #f87171; --err-bg: #2f1517; --info-bg: #14223c;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
html[lang="fa"] body { font-family: var(--font-fa); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 var(--space-3); line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; overflow-wrap: anywhere; } h2 { font-size: 17px; } h3 { font-size: 15px; }
p { margin: 0 0 var(--space-3); }
.icon { display: inline-block; vertical-align: -3px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--text-2); } .faint { color: var(--text-3); } .small { font-size: 12.5px; }
.num, .ltr { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
html[dir="rtl"] .num { text-align: end; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* layout */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-inline-end: 1px solid var(--border); padding: var(--space-4) var(--space-3);
  position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: var(--space-1); }
.brand { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-2) var(--space-4); font-weight: 700; font-size: 15px; color: var(--text); }
.brand img { height: 28px; max-width: 140px; object-fit: contain; }
.brand .mark { width: 28px; height: 28px; border-radius: 7px; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: 13px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--text-2); font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--info-bg); color: var(--primary); }
.nav .sep { height: 1px; background: var(--border); margin: var(--space-2) 0; }
.nav .label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); padding: var(--space-3) 10px var(--space-1); }
.sidebar .foot { margin-top: auto; font-size: 12px; color: var(--text-3); padding: var(--space-3) var(--space-2) 0; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 56px; display: flex; align-items: center; gap: var(--space-3); padding: 0 var(--space-5);
  border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.topbar .spacer { flex: 1; }
.btn.menu-btn { display: none; }
.content { padding: var(--space-5); max-width: 1320px; width: 100%; margin: 0 auto; flex: 1; }
.footer { padding: var(--space-4) var(--space-5); color: var(--text-3); font-size: 12px; display: flex; gap: var(--space-3); justify-content: space-between; border-top: 1px solid var(--border); }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-5); flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--text-2); }

/* surfaces */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: var(--space-5); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); }
.card-head h2, .card-head h3 { margin: 0; }
.card-body { padding: var(--space-4) var(--space-5); }
.grid { display: grid; gap: var(--space-4); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stack > * + * { margin-top: var(--space-4); }
.row { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stat { padding: var(--space-4) var(--space-5); }
.stat .v { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .k { color: var(--text-2); font-size: 12.5px; }

/* buttons & forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: var(--ctl-h); padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(.94); }
.btn.danger { color: var(--err); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { height: var(--ctl-h-sm); padding: 0 10px; font-size: 13px; }
.btn.lg { height: 44px; padding: 0 20px; font-size: 15px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn, .linkbtn { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.linkbtn { border: 0; background: none; padding: 2px 0; color: var(--primary); font: inherit; font-weight: 550; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.linkbtn:hover { text-decoration: underline; }
/* one control style for every field type: same height, border, radius, padding, font */
label, label.small { display: block; font-weight: 550; font-size: 13px; margin-bottom: 6px; color: var(--text); line-height: 1.35; }
.field { margin-bottom: var(--space-4); min-width: 0; }
.hint { font-size: 12px; color: var(--text-3); margin-top: 6px; }
input:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=file]):not([type=hidden]):not([type=range]):not([type=submit]):not([type=button]),
select, textarea {
  display: block; width: 100%; height: var(--ctl-h); padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; line-height: normal; margin: 0; min-width: 0;
  transition: border-color .12s, box-shadow .12s; -webkit-appearance: none; appearance: none; }
select { padding-inline-end: 32px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a94a6' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
html[dir="rtl"] select { background-position: left 12px center; }
input:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=file]):hover, select:hover, textarea:hover { border-color: var(--text-3); }
input:not([type=checkbox]):not([type=radio]):focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); outline: none; }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--text-2); cursor: not-allowed; }
input::placeholder, textarea::placeholder { color: var(--text-3); }
input[type=number] { font-variant-numeric: tabular-nums; }
textarea { height: auto; min-height: 76px; padding: 9px 12px; line-height: 1.5; resize: vertical; }
input[type=file] { display: block; width: 100%; max-width: 100%; height: var(--ctl-h); padding: 3px; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text-2); font: inherit; font-size: 13px; cursor: pointer; }
input[type=file]::file-selector-button { height: calc(var(--ctl-h) - 8px); margin-inline-end: 10px; padding: 0 12px; border: 1px solid var(--border-strong);
  border-radius: 5px; background: var(--surface-2); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; }
input[type=color] { width: 48px; height: var(--ctl-h); padding: 3px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); vertical-align: -4px; flex: none; cursor: pointer; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; min-height: 28px; cursor: pointer; margin-bottom: 0; }
.check.field { margin-bottom: var(--space-3); }
.inline-form { display: inline; }
.input-sm, select.input-sm { height: var(--ctl-h-sm) !important; font-size: 13px; }
.row > input, .row > select, .row > .btn { width: auto; }
.row > input:not([type=checkbox]), .row > select { flex: 1 1 160px; }
.page-head .row > select, .doc-actions > select, .toolbar select { flex: 0 1 210px; }
.page-head > .row { justify-content: flex-end; }
.doc-head { flex-direction: column; align-items: stretch; gap: 12px; }
.doc-head > .row { justify-content: flex-start; }
.doc-actions { gap: 8px; flex-wrap: nowrap; }

/* form layouts: labels on top, controls bottom-aligned on one baseline */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: var(--ctl-gap) 14px; align-items: end; }
.form-grid.wide { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.form-grid > .field { margin: 0; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid-btn .btn { width: 100%; }
.form-line { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--ctl-gap); }
.form-line > .field { margin: 0; flex: 0 1 200px; }
.form-line > .field.grow { flex: 1 1 240px; }
.form-line > .field.w-num { flex: 0 0 132px; }
.form-line > .btn, .form-line > .ctl-check { flex: none; }
.ctl-check { height: var(--ctl-h); }
.checks { display: flex; flex-wrap: wrap; gap: 8px 24px; margin: 4px 0 var(--space-4); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: var(--space-4); }
.kv > div > label, .grid > div > label { margin-bottom: 6px; }

/* AI providers */
.chain { list-style: none; margin: 0 0 4px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chain-step { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border: 1px solid var(--border); border-radius: 20px; background: var(--surface-2); font-weight: 550; }
html[dir="rtl"] .chain-step { padding: 6px 6px 6px 12px; }
.chain-step + .chain-step::before { content: "→"; color: var(--text-3); margin-inline-start: -2px; position: relative; inset-inline-start: -14px; width: 0; }
html[dir="rtl"] .chain-step + .chain-step::before { content: "←"; }
.chain { gap: 8px 22px; }
details.prov { margin-bottom: 12px; overflow: hidden; }
.prov-sum { display: flex; align-items: center; gap: 12px; padding: 14px var(--space-5); cursor: pointer; list-style: none; min-height: 64px; }
.prov-sum::-webkit-details-marker { display: none; }
.prov-sum:hover { background: var(--surface-2); }
.prov-ic { width: 36px; height: 36px; border-radius: 9px; background: var(--info-bg); color: var(--primary); display: grid; place-items: center; flex: none; }
.prov-title { display: grid; gap: 2px; flex: 1; min-width: 0; }
.prov-title .small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prov-badges { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.chev { width: 10px; height: 10px; border-inline-end: 2px solid var(--text-3); border-bottom: 2px solid var(--text-3); transform: rotate(45deg); margin: 0 4px 4px; transition: transform .15s; flex: none; }
details[open] > .prov-sum .chev { transform: rotate(-135deg); margin-bottom: -4px; }
details[open] > .prov-sum { border-bottom: 1px solid var(--border); }
.prov-body { padding: 0 var(--space-5); }
.step { padding: var(--space-4) 0 var(--space-5); border-bottom: 1px dashed var(--border); }
.step:last-child { border-bottom: 0; }
.step h3 { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.step-n { width: 22px; height: 22px; border-radius: 50%; background: var(--primary); color: var(--primary-ink); display: inline-grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.step > form.hint { margin-top: 8px; }
.model { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; margin-top: 12px; background: var(--surface); }
.model-name { min-height: var(--ctl-h); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
details.sub { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 8px; }
details.sub > summary { cursor: pointer; font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-height: 32px; }
details.sub[open] > summary { margin-bottom: 10px; }
details.sub .form-grid { margin-top: 12px; }

/* alerts & badges */
.alert { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: var(--space-4); border: 1px solid transparent; }
.alert.ok { background: var(--ok-bg); color: var(--ok); } .alert.err { background: var(--err-bg); color: var(--err); }
.alert.warn { background: var(--warn-bg); color: var(--warn); } .alert.info { background: var(--info-bg); color: var(--text); }
.alert ul { margin: 0; padding-inline-start: 18px; }
.badge { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 11px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge.ok, .badge.s-COMPLETED, .badge.s-APPROVED, .badge.s-ACTIVE, .badge.s-success, .badge.s-READY { background: var(--ok-bg); color: var(--ok); }
.badge.warn, .badge.s-NEEDS_REVIEW, .badge.s-PENDING_APPROVAL, .badge.s-PENDING_EMAIL_VERIFICATION { background: var(--warn-bg); color: var(--warn); }
.badge.err, .badge.s-FAILED, .badge.s-REJECTED, .badge.s-SUSPENDED, .badge.s-error, .badge.s-timeout, .badge.s-blocked { background: var(--err-bg); color: var(--err); }
.badge.info, .badge.s-QUEUED, .badge.s-PROCESSING, .badge.s-UPLOADED { background: var(--info-bg); color: var(--primary); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* tables */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
.t th, .t td { padding: 10px 12px; text-align: start; border-bottom: 1px solid var(--border); vertical-align: middle; }
.t th { font-size: 12px; font-weight: 600; color: var(--text-2); background: var(--surface-2); text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.t tr:last-child td { border-bottom: none; }
.t tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.t td.num, .t th.num { text-align: end; }
.t .cell-title { font-weight: 550; color: var(--text); }
.empty { padding: var(--space-6); text-align: center; color: var(--text-2); }
.empty .icon { color: var(--text-3); margin-bottom: 8px; }

/* toolbar / filters */
.toolbar { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); }
.toolbar input, .toolbar select { width: auto; min-width: 120px; height: var(--ctl-h-sm); }
.toolbar .grow { flex: 1; min-width: 180px; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.seg a { padding: 5px 10px; color: var(--text-2); } .seg a.on { background: var(--surface-2); color: var(--text); }
.bulkbar { display: none; gap: var(--space-2); align-items: center; padding: var(--space-2) var(--space-4); background: var(--info-bg); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.bulkbar.show { display: flex; }
.pager { display: flex; gap: var(--space-2); justify-content: center; padding: var(--space-4); }

/* document grid */
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--space-4); padding: var(--space-4); }
.doc-tile { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; display: flex; flex-direction: column; }
.doc-tile .thumb { aspect-ratio: 3 / 4; background: var(--surface-2); display: block; overflow: hidden; }
.doc-tile .thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.doc-tile .meta { padding: 10px 12px; display: grid; gap: 4px; }

/* upload */
.dropzone { border: 2px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface); padding: 48px 24px; text-align: center; transition: border-color .15s, background .15s; }
.dropzone.drag { border-color: var(--primary); background: var(--info-bg); }
.dropzone .big { width: 56px; height: 56px; border-radius: 14px; background: var(--info-bg); color: var(--primary); display: inline-grid; place-items: center; margin-bottom: 12px; }
.uplist { list-style: none; margin: 0; padding: 0; }
.uplist li { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); align-items: center; }
.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; grid-column: 1 / -1; }
.progress > span { display: block; height: 100%; background: var(--primary); width: 0; transition: width .2s; }
.progress.ok > span { background: var(--ok); } .progress.err > span { background: var(--err); }
.hero { display: grid; grid-template-columns: 1.4fr 1fr; gap: var(--space-5); align-items: center; padding: var(--space-6); background: linear-gradient(135deg, var(--surface), var(--info-bg)); }
.hero h1 { font-size: 26px; }
.flow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; color: var(--text-2); font-size: 12.5px; font-weight: 600; }
.flow span { padding: 4px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }

/* review */
.review { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(380px, 1fr); gap: var(--space-5); align-items: start; }
.viewer { position: sticky; top: 72px; max-height: calc(100vh - 90px); overflow: auto; }
.viewer .pages { display: grid; gap: var(--space-3); padding: var(--space-3); background: var(--surface-2); }
.viewer figure { margin: 0; position: relative; }
.viewer img { width: 100%; display: block; border-radius: 4px; box-shadow: var(--shadow); background: #fff; }
.viewer figcaption { position: absolute; top: 8px; inset-inline-start: 8px; }
.inv-card .fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.inv-card .f-wide { grid-column: 1 / -1; }
.fld input { font-variant-numeric: tabular-nums; }
.fld.st-uncertain input { border-color: var(--warn); background: var(--warn-bg); }
.fld.st-missing input { border-color: var(--err); background: var(--err-bg); }
.fld.st-corrected input, .fld.st-confirmed input { border-color: var(--ok); }
.fld .meta { display: flex; flex-wrap: wrap; gap: 2px 8px; align-items: center; font-size: 11.5px; color: var(--text-3); margin-top: 4px; min-height: 16px; line-height: 1.35; }
.fld .meta .m { white-space: nowrap; }
.fld .meta .note { flex-basis: 100%; }
.fld.st-uncertain .meta .note { color: var(--warn); }
.fld .err { color: var(--err); font-size: 12px; }
.conf { display: inline-block; width: 36px; height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; vertical-align: middle; }
.conf > i { display: block; height: 100%; background: var(--ok); }
.conf.lo > i { background: var(--warn); } .conf.vlo > i { background: var(--err); }
.pagechips { display: flex; gap: 4px; flex-wrap: wrap; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-inline-end: 4px; vertical-align: -1px; }

/* designer */
.designer { display: grid; grid-template-columns: minmax(360px, 430px) minmax(0, 1fr); gap: var(--space-5); align-items: start; }
.designer details { border-bottom: 1px solid var(--border); }
.designer summary { cursor: pointer; padding: 12px var(--space-5); font-weight: 600; list-style: none; display: flex; justify-content: space-between; }
.designer summary::after { content: "+"; color: var(--text-3); }
.designer details[open] summary::after { content: "–"; }
.designer .sec { padding: 0 var(--space-5) var(--space-4); }
.colrow { display: grid; grid-template-columns: 22px 20px minmax(0, 1fr) 62px 74px; gap: 6px; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--border); }
.colrow .handle { cursor: grab; color: var(--text-3); display: grid; gap: 0; }
.colrow .handle button { border: 0; background: none; color: var(--text-3); cursor: pointer; padding: 0; line-height: 1; font-size: 11px; }
.colrow input, .colrow select { height: var(--ctl-h-sm); font-size: 13px; padding: 0 6px; }
.colrow select { padding-inline-end: 22px; background-position: right 6px center; }
html[dir="rtl"] .colrow select { background-position: left 6px center; }
.colrow.off { opacity: .55; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.xlsx-preview { overflow: auto; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); max-height: 70vh; }
.xlsx-preview table { border-collapse: collapse; font-family: Calibri, Arial, sans-serif; color: #000; table-layout: fixed; }
.xlsx-preview td { padding: 2px 6px; border: 1px solid #e5e7eb; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 12px; }
.xlsx-preview .rh { background: #f3f4f6; color: #6b7280; text-align: center; font-size: 11px; width: 34px; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: var(--space-5); background: radial-gradient(1200px 500px at 50% -10%, var(--info-bg), var(--bg)); }
.auth .box { width: 100%; max-width: 410px; }
.auth .logo { text-align: center; margin-bottom: var(--space-5); }
.auth .logo img { max-height: 48px; max-width: 220px; }
.auth .logo .name { font-size: 20px; font-weight: 700; margin-top: 8px; }
.auth .logo .desc { color: var(--text-2); font-size: 13px; }
.auth .foot { text-align: center; color: var(--text-3); font-size: 12px; margin-top: var(--space-4); }
.auth .card-pad { padding: 28px; }

/* email popover */
.email-pop { position: relative; display: inline-block; }
.email-pop > summary { list-style: none; }
.email-pop > summary::-webkit-details-marker { display: none; }
.email-pop .email-menu { position: absolute; z-index: 20; inset-inline-end: 0; top: calc(100% + 6px); min-width: 260px; padding: 12px; box-shadow: var(--shadow-lg); display: grid; gap: 6px; }
.bulkbar .email-pop > summary { height: 30px; padding: 0 10px; font-size: 13px; }

/* misc */
.kpi-bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.kpi-bar > span { display: block; height: 100%; background: var(--primary); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: none; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); font-size: 11.5px; margin: 1px; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--border-strong); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.htmx-request .htmx-hide { display: none; }
.htmx-indicator { display: none; } .htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline-block; }
pre.changelog { white-space: pre-wrap; font: 13px/1.6 var(--mono); background: var(--surface-2); padding: var(--space-4); border-radius: var(--radius-sm); max-height: 420px; overflow: auto; }
.tree-indent { display: inline-block; }
.swatch { width: 14px; height: 14px; border-radius: 4px; display: inline-block; vertical-align: -2px; border: 1px solid var(--border); }

/* grid children must be allowed to shrink (prevents horizontal overflow from wide tables/previews) */
.grid > *, .review > *, .designer > *, .main { min-width: 0; }
.dash-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.bottom-nav, .install-btn, .scrim { display: none; }
.filters-toggle { display: none; }

@media (max-width: 1080px) {
  .review, .designer, .dash-main { grid-template-columns: 1fr; }
  .viewer { position: static; max-height: none; }
  .hero { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  :root { --bottom-nav: calc(62px + env(safe-area-inset-bottom)); }
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; width: 272px; z-index: 40; transform: translateX(-105%);
    transition: transform .2s; box-shadow: var(--shadow-lg); padding-bottom: calc(16px + env(safe-area-inset-bottom)); visibility: hidden; }
  html[dir="rtl"] .sidebar { transform: translateX(105%); }
  .sidebar.open { transform: none !important; visibility: visible; }
  .scrim { position: fixed; inset: 0; background: rgba(15, 23, 42, .35); z-index: 35; display: none; }
  .sidebar.open + .scrim { display: block; }
  .btn.menu-btn { display: inline-flex; }
  .topbar { padding: 0 12px; padding-top: env(safe-area-inset-top); height: calc(52px + env(safe-area-inset-top)); gap: 8px; }
  .topbar .mobile-title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .hide-sm, .topbar .lang-form { display: none; }
  .content { padding: 14px 12px calc(var(--bottom-nav) + 16px); }
  .footer { display: none; }
  .page-head { margin-bottom: 14px; gap: 10px; }
  .page-head > .row, .page-head > form.row { width: 100%; }
  h1 { font-size: 20px; }
  .card-pad { padding: 16px; } .card-head, .card-body { padding: 12px 14px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .g4.keep-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat { padding: 12px 14px; } .stat .v { font-size: 20px; }
  .hero { padding: 18px; gap: 16px; } .hero h1 { font-size: 21px; }
  .hero .grid.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .hero .row .btn { flex: 1; }
  /* 16px inputs: iOS does not zoom on focus; finger-sized targets (>= 44px) */
  :root { --ctl-h: 46px; --ctl-h-sm: 42px; --ctl-gap: 14px; }
  input:not([type=checkbox]):not([type=radio]):not([type=color]), select, textarea { font-size: 16px; }
  .btn { font-size: 15px; padding: 0 16px; border-radius: 9px; }
  .btn.sm { font-size: 14px; padding: 0 14px; }
  .btn.ghost.sm { min-width: 42px; }
  .input-sm, select.input-sm { font-size: 16px; }
  input[type=checkbox], input[type=radio] { width: 22px; height: 22px; }
  .check { min-height: 44px; gap: 12px; }
  .nav a { padding: 12px 12px; }
  /* forms stack; primary actions span the full width */
  .form-line > .field, .form-line > .field.grow, .form-line > .field.w-num { flex: 1 1 100%; }
  .form-line > .btn { flex: 1 1 100%; }
  .form-line > .ctl-check { height: auto; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid.wide { grid-template-columns: 1fr; }
  .form-grid .span-2, .form-grid-btn { grid-column: 1 / -1; }
  .actions > .btn, .card-pad form > .btn, .card-body form > .btn, .card-pad > form > .btn { flex: 1 1 100%; width: 100%; }
  .row > input:not([type=checkbox]), .row > select { flex: 1 1 100%; }
  .row > .btn { flex: 1 1 auto; }
  .checks { flex-direction: column; gap: 4px; }
  .prov-sum { padding: 12px 14px; flex-wrap: wrap; }
  .prov-badges { width: 100%; justify-content: flex-start; padding-inline-start: 48px; }
  .prov-sum .chev { position: absolute; inset-inline-end: 18px; margin-top: 12px; }
  details.prov { position: relative; }
  .prov-body { padding: 0 14px; }
  .linkbtn { min-height: 40px; }
  .chain { flex-direction: column; align-items: flex-start; gap: 6px; }
  .chain-step + .chain-step::before { content: "↓" !important; position: static; width: auto; margin: 0; }
  .t td .btn.sm, .t td button.btn { min-height: 42px; }
  /* bottom tab bar (app-like) */
  .bottom-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; inset-inline: 0; bottom: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); height: var(--bottom-nav); }
  .bottom-nav a, .bottom-nav button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    font: 500 11px var(--font); color: var(--text-2); background: none; border: 0; text-decoration: none; min-height: 56px; }
  html[lang="fa"] .bottom-nav a, html[lang="fa"] .bottom-nav button { font-family: var(--font-fa); }
  .bottom-nav a.active { color: var(--primary); }
  .bottom-nav .fab { width: 50px; height: 50px; border-radius: 16px; background: var(--primary); color: #fff; display: grid; place-items: center;
    margin-top: -18px; box-shadow: 0 6px 16px color-mix(in srgb, var(--primary) 40%, transparent); }
  /* tables become cards */
  table.stack-sm, .stack-sm thead, .stack-sm tbody, .stack-sm tr, .stack-sm td { display: block; width: 100%; }
  .stack-sm thead { display: none; }
  .stack-sm tr { padding: 12px 14px; border-bottom: 1px solid var(--border); }
  .stack-sm td { border: 0; padding: 3px 0; display: flex; gap: 10px; justify-content: space-between; align-items: center; text-align: start; }
  .stack-sm td[data-label]::before { content: attr(data-label); color: var(--text-3); font-size: 12px; flex: none; }
  .stack-sm td.cell-main { display: block; font-size: 15px; padding-bottom: 6px; }
  .stack-sm td.cell-check { position: absolute; width: auto; inset-inline-end: 12px; margin-top: -2px; padding: 0; }
  .stack-sm tr { position: relative; }
  .stack-sm td.num { justify-content: space-between; }
  .stack-sm td.actions { justify-content: flex-start; flex-wrap: wrap; padding-top: 8px; }
  .stack-sm td.actions form.row { flex-wrap: wrap; }
  .t.stack-sm tbody tr:hover td { background: none; }
  .hide-sm { display: none !important; }
  /* filters collapse behind a toggle */
  .filters-toggle { display: inline-flex; }
  .toolbar .more { display: none; width: 100%; gap: 8px; flex-wrap: wrap; }
  .toolbar.filters-open .more { display: flex; }
  .toolbar .more > * { flex: 1 1 45%; min-width: 0 !important; }
  .toolbar .grow { min-width: 0; }
  .bulkbar { position: fixed; inset-inline: 0; bottom: var(--bottom-nav); z-index: 25; box-shadow: var(--shadow-lg); max-height: 50vh; overflow-y: auto; }
  /* review: swipe through pages, fields below */
  .viewer .pages { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: 10px; padding: 10px; }
  .viewer figure { flex: 0 0 86%; scroll-snap-align: center; }
  .viewer img { max-height: 58vh; object-fit: contain; }
  .viewer .swipe-hint { display: block; }
  .inv-card .fields { grid-template-columns: 1fr; }
  .inv-card .row.between .btn { flex: 1; }
  .doc-actions { display: grid !important; grid-template-columns: 1fr 1fr; width: 100%; }
  .doc-actions > * { width: 100%; }
  .doc-actions select { grid-column: 1 / -1; }
  .doc-actions .email-pop, .doc-actions .email-pop > summary { width: 100%; }
  .doc-head > .row > .btn { flex: 1 1 100%; }
  /* email popover becomes a bottom sheet */
  .email-pop .email-menu { position: fixed; inset-inline: 0; bottom: 0; top: auto; border-radius: 16px 16px 0 0; z-index: 50;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
  .email-pop[open]::before { content: ""; position: fixed; inset: 0; background: rgba(15, 23, 42, .35); z-index: 45; }
  /* designer */
  .colrow { grid-template-columns: 22px 22px minmax(0, 1fr) 58px 70px; }
  .kv { grid-template-columns: 1fr; }
  .designer summary { padding: 12px 14px; } .designer .sec { padding: 0 14px 14px; }
  .xlsx-preview { max-height: 50vh; }
  .doc-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 10px; }
  .dropzone { padding: 24px 16px; }
  .dropzone .row .btn { width: 100%; }
  .auth { padding: 16px; align-items: start; padding-top: max(32px, env(safe-area-inset-top)); }
  .install-btn.show { display: inline-flex; }
}
.swipe-hint { display: none; text-align: center; font-size: 12px; color: var(--text-3); padding-bottom: 8px; }
@media (pointer: coarse) { .dz-desktop { display: none; } }
@media (pointer: fine) { .dz-touch { display: none; } }
@media (display-mode: standalone) { .install-btn { display: none !important; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

@media (pointer: fine) { .dz-touch-alt { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); } }

/* touch devices of any size (tablets): never smaller than a fingertip */
@media (pointer: coarse) {
  :root { --ctl-h: 44px; --ctl-h-sm: 40px; }
  .bottom-nav a, .bottom-nav button { min-width: 44px; }
}
