:root {
  --bg: #f3f4f7;
  --panel: #ffffff;
  --text: #1d2330;
  --muted: #6b7385;
  --border: #dde1e8;
  --brand: #E8772E;
  --brand-dark: #c85f1c;
  --blue: #1B75BB;
  --danger: #d63b3b;
  --radius: 8px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* the hidden attribute always wins over display rules */
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  display: flex; flex-direction: column;
}
button, input, select, textarea { font: inherit; color: inherit; }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 20px; padding: 10px 18px;
  background: #fff; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.tb-brand { display: flex; align-items: center; gap: 10px; }
.tb-brand strong { display: block; font-size: 15px; }
.tb-brand small { color: var(--muted); font-size: 12px; }
.tb-logo {
  width: 28px; height: 28px; border-radius: 6px;
  background: conic-gradient(#E53935 0 25%, #3FA34D 0 50%, #2AA7E0 0 75%, #F7B82E 0);
}
.tb-nav { display: flex; gap: 4px; }
.tb-nav button {
  border: 0; background: none; padding: 8px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); font-weight: 500;
}
.tb-nav button.active { background: #fff1e7; color: var(--brand-dark); }
.tb-nav button:hover { color: var(--text); }
.tb-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.db-pill { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 600; padding: 5px 11px; border-radius: 20px; margin-right: 6px; white-space: nowrap; }
.db-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.db-pill.db { background: #e6f6ec; color: #1f7a42; }
.db-pill.queued { background: #fff7da; color: #8a6400; }
.db-pill.local { background: #eef0f4; color: #5b6478; }

.btn {
  border: 1px solid var(--border); background: #fff; padding: 7px 13px; border-radius: 6px;
  cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: #b9c0cc; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn.danger { color: var(--danger); }
.btn.link { border: 0; background: none; color: var(--blue); padding: 4px 6px; }
.btn.link.danger { color: var(--danger); }

main { flex: 1; min-height: 0; }
.view { display: none; height: 100%; }
.view.active { display: flex; }

/* editor */
#view-editor { min-height: 0; }
.form {
  width: 420px; flex: none; overflow-y: auto; background: var(--panel);
  border-right: 1px solid var(--border); padding: 14px 16px 60px;
}
.fs { border: 0; margin: 0 0 6px; padding: 0 0 14px; border-bottom: 1px solid #eef0f4; min-width: 0; }   /* fieldsets won't shrink below their content without min-width: 0 */
.fs legend, .fs .legend {
  font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--brand-dark); padding: 12px 0 8px; display: block;
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.row.one { grid-template-columns: 1fr; }
.row.three { grid-template-columns: 1fr 1fr 1fr; }
label.f { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); min-width: 0; }
label.f input, label.f select, label.f textarea, .item-row input, .item-row textarea {
  border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; background: #fff; color: var(--text); font-size: 13.5px; width: 100%;
}
label.f textarea { resize: vertical; min-height: 70px; line-height: 1.35; }
input:focus, select:focus, textarea:focus { outline: 2px solid #f6c29d; border-color: var(--brand); }
label.chk { display: flex; align-items: center; gap: 7px; font-size: 13px; margin: 4px 0; cursor: pointer; }
.hint { font-size: 11.5px; color: var(--muted); margin: 2px 0 6px; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; width: 100%; }
.seg button { flex: 1; border: 0; background: #fff; padding: 7px 8px; cursor: pointer; font-weight: 500; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--brand); color: #fff; }

.item-row { display: grid; grid-template-columns: 1fr 110px 28px; gap: 6px; margin-bottom: 6px; align-items: start; }
.item-row textarea { resize: vertical; min-height: 36px; height: 36px; }
.item-row input { text-align: right; }
.icon-btn { border: 0; background: none; cursor: pointer; color: #9aa2b1; font-size: 18px; line-height: 34px; padding: 0; }
.icon-btn:hover { color: var(--danger); }
.items-actions { display: flex; gap: 6px; align-items: center; }
.items-actions select { flex: 1; border: 1px solid var(--border); border-radius: 6px; padding: 6px; font-size: 13px; }
.sum-box { background: #fafbfc; border: 1px solid #eef0f4; border-radius: 6px; padding: 8px 10px; margin-top: 8px; font-size: 13px; }
.sum-box div { display: flex; justify-content: space-between; }
.sum-box .t { font-weight: 700; }

/* preview */
.preview-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.preview-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 8px 14px; background: #fff; border-bottom: 1px solid var(--border);
}
.pt-right { display: flex; gap: 8px; align-items: center; }
.pt-right select { border: 1px solid var(--border); border-radius: 6px; padding: 6px; }
.doc-label { font-weight: 600; }
.dirty { color: var(--brand-dark); font-size: 12.5px; margin-left: 10px; }
.preview-scroll { flex: 1; overflow: auto; padding: 22px; background: #d9dce2; }
.pages { width: max-content; margin: 0 auto; }
.pages .page { margin: 0 auto 22px; box-shadow: 0 2px 12px rgba(0,0,0,.18); }

/* off-screen layout area */
#render-area { position: fixed; left: -12000px; top: 0; width: 794px; pointer-events: none; }

/* panels (docs / settings) */
.panel { flex: 1; overflow: auto; padding: 24px 28px 60px; }
.panel h2 { margin: 0 0 12px; font-size: 20px; }
.panel h3 { margin: 26px 0 10px; font-size: 15px; color: var(--brand-dark); }
.ico { width: 18px; height: 18px; display: block; flex: none; }
.muted { color: var(--muted); font-style: normal; }

/* saved documents */
.docs-panel { max-width: 1320px; margin: 0 auto; width: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h2 { margin: 0; font-size: 24px; letter-spacing: -.3px; }
.page-sub { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
  display: flex; gap: 14px; align-items: flex-start; background: #fff; border: 1px solid var(--border);
  border-radius: 12px; padding: 16px 18px; box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}
.stat-ic { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.stat-ic .ico { width: 20px; height: 20px; }
.stat-ic.blue { background: #e8f2fb; color: #1b75bb; }
.stat-ic.orange { background: #fff1e6; color: #d8651a; }
.stat-ic.green { background: #e6f6ec; color: #23884a; }
.stat-ic.red { background: #fdecec; color: #c73b3b; }
.stat-l { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.stat-v { font-size: 22px; font-weight: 700; letter-spacing: -.4px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat-v.sec { font-size: 15px; font-weight: 600; color: #3b4354; margin-top: 0; }
.stat-s { font-size: 12px; color: var(--muted); margin-top: 3px; }

.card { background: #fff; border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 1px 2px rgba(16, 24, 40, .04); }
.list-card { overflow: hidden; }
.list-toolbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.tabs { display: inline-flex; background: #f1f3f7; border-radius: 9px; padding: 3px; gap: 2px; }
.tabs button {
  border: 0; background: none; padding: 6px 12px; border-radius: 7px; cursor: pointer; font-weight: 600;
  color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 7px;
}
.tabs button span { background: #e1e5ec; color: #505a6d; border-radius: 10px; padding: 0 7px; font-size: 11.5px; line-height: 18px; }
.tabs button.on { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(16, 24, 40, .12); }
.tabs button.on span { background: #fff1e6; color: var(--brand-dark); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters select { border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; background: #fff; font-size: 13px; }
.search { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 8px; padding: 0 10px; background: #fff; width: 300px; max-width: 100%; }
.search:focus-within { outline: 2px solid #f6c29d; border-color: var(--brand); }
.search .ico { width: 16px; height: 16px; color: var(--muted); }
.search input { border: 0; outline: 0; padding: 7px 0; flex: 1; min-width: 0; font-size: 13px; background: none; }

.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.list th {
  background: #fafbfc; color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .5px; text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.list th.sortable { cursor: pointer; user-select: none; }
table.list th.sortable:hover { color: var(--text); }
table.list th .arrow { margin-left: 5px; font-size: 10px; opacity: .45; }
table.list th.on { color: var(--text); }
table.list th.on .arrow { opacity: 1; color: var(--brand-dark); }
table.list td { padding: 12px 14px; border-bottom: 1px solid #eef0f4; vertical-align: middle; }
table.list tbody tr { cursor: pointer; transition: background .12s; }
table.list tbody tr:hover td, table.list tbody tr:focus td { background: #fff9f4; }
table.list tbody tr:focus { outline: none; }
table.list tbody tr:last-child td { border-bottom: 0; }
table.list .num { text-align: right; }
table.list .num small { color: var(--muted); font-weight: 600; font-size: 11px; }
table.list .nowrap { white-space: nowrap; }
.cell-main { font-weight: 600; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.num .cell-main { justify-content: flex-end; font-variant-numeric: tabular-nums; }
.cell-sub { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; }
.type-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.type-dot.quotation { background: #1b75bb; }
.type-dot.invoice { background: var(--brand); }
.chip { display: inline-block; padding: 2px 9px; border-radius: 6px; background: #f1f3f7; font-size: 12px; font-weight: 600; color: #4a5366; }

.status-sel {
  appearance: none; -webkit-appearance: none; border: 0; border-radius: 20px; padding: 4px 26px 4px 11px;
  font-size: 12px; font-weight: 600; cursor: pointer; background-color: #eef0f4; color: #4a5366;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23666' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
.status-sel.s-Sent { background-color: #e8f2fb; color: #145c94; }
.status-sel.s-Accepted, .status-sel.s-Paid { background-color: #e6f6ec; color: #1f7a42; }
.status-sel.s-Unpaid { background-color: #fff1e6; color: #b4561b; }
.status-sel.s-Partially-Paid { background-color: #fff7da; color: #8a6400; }
.status-sel.s-Rejected, .status-sel.s-Cancelled { background-color: #fdecec; color: #a52f2f; }

.act-col { width: 1%; }
.acts { display: flex; gap: 2px; justify-content: flex-end; }
.icon-act {
  width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid transparent; border-radius: 8px;
  background: none; color: #6b7385; cursor: pointer; transition: .12s;
}
.icon-act:hover { background: #fff; border-color: var(--border); color: var(--text); box-shadow: 0 1px 2px rgba(16, 24, 40, .08); }
.icon-act.danger:hover { color: var(--danger); border-color: #f3c9c9; background: #fff6f6; }
.icon-act.busy { opacity: .5; cursor: progress; animation: pulse 1s infinite; }
.icon-gap { width: 32px; flex: none; }
@keyframes pulse { 50% { opacity: .2; } }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.list-foot {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 11px 16px;
  border-top: 1px solid var(--border); background: #fafbfc; font-size: 12.5px; color: var(--muted);
}
.list-foot:empty { display: none; }
.list-foot b { color: var(--text); }
.empty-state { text-align: center; padding: 56px 20px 60px; }
.empty-ic { width: 56px; height: 56px; border-radius: 14px; background: #fff1e6; color: var(--brand-dark); display: grid; place-items: center; margin: 0 auto 14px; }
.empty-ic .ico { width: 26px; height: 26px; }
.empty-state h3 { margin: 0 0 6px; font-size: 17px; color: var(--text); }
.empty-state p { margin: 0 auto 18px; color: var(--muted); max-width: 420px; }
.empty-actions { display: flex; gap: 8px; justify-content: center; }

/* dialog */
.dlg { border: 0; border-radius: 14px; padding: 0; width: min(420px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(16, 24, 40, .25); }
.dlg::backdrop { background: rgba(16, 24, 40, .45); }
.dlg form { padding: 22px 22px 18px; }
.dlg h3 { margin: 0 0 8px; font-size: 17px; }
.dlg p { margin: 0 0 20px; color: var(--muted); line-height: 1.5; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-solid:hover { background: #b92f2f; }

/* ===== settings ===== */
#view-settings .panel { max-width: 1320px; margin: 0 auto; width: 100%; }
.save-pill { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 600; color: #1f7a42; background: #e6f6ec; border-radius: 20px; padding: 6px 12px; }
.save-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.save-pill.saving { color: #8a6400; background: #fff7da; }
.settings-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; align-items: start; }
.settings-nav { position: sticky; top: 0; display: flex; flex-direction: column; gap: 2px; }
.settings-nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; font-size: 13.5px; }
.settings-nav a .ico { width: 17px; height: 17px; }
.settings-nav a:hover { background: #fff; color: var(--text); }
.settings-nav a.on { background: #fff; color: var(--brand-dark); box-shadow: 0 1px 2px rgba(16, 24, 40, .06); }
.settings-main { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.sect { scroll-margin-top: 8px; }
.sect-head { display: flex; gap: 14px; align-items: flex-start; padding: 18px 22px 16px; border-bottom: 1px solid var(--border); }
.sect-ic { width: 36px; height: 36px; border-radius: 9px; background: #fff1e6; color: var(--brand-dark); display: grid; place-items: center; flex: none; }
.sect-head h3 { margin: 0; font-size: 15.5px; color: var(--text); }
.sect-head p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.sect-body { padding: 20px 22px 22px; }
.sect-foot { margin-top: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 18px; }
.grid2.tight { gap: 14px; }
.sect-body label.f { font-size: 12.5px; font-weight: 500; color: #3b4354; gap: 5px; }
.sect-body label.f small { font-weight: 400; color: var(--muted); font-size: 11.5px; }
.sect-body label.f small.inl { display: inline; margin-left: 4px; }
.sect-body input:not([type=checkbox]):not([type=color]), .sect-body select, .sect-body textarea { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 13.5px; background: #fff; width: 100%; }
.sect-body textarea { line-height: 1.45; resize: vertical; }
.sect-body input.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.color-field { display: flex; align-items: center; gap: 10px; border: 1px solid var(--border); border-radius: 8px; padding: 4px 10px 4px 4px; background: #fff; }
.color-field input[type=color] { width: 44px; height: 30px; border: 0; padding: 0; background: none; cursor: pointer; }
.color-field code { font-size: 12.5px; color: var(--muted); }
.switch { display: flex; align-items: center; gap: 10px; margin-top: 16px; cursor: pointer; font-size: 13.5px; color: #3b4354; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 36px; height: 20px; border-radius: 10px; background: #cfd5df; position: relative; flex: none; transition: .15s; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track::after { left: 18px; }
.switch input:focus-visible + .track { outline: 2px solid #f6c29d; }
.img-card { display: flex; gap: 14px; border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: #fafbfc; }
.img-prev { position: relative; width: 120px; height: 84px; flex: none; border-radius: 8px; background: #fff repeating-conic-gradient(#f1f3f7 0 25%, #fff 0 50%) 0 0 / 16px 16px; border: 1px solid var(--border); display: grid; place-items: center; overflow: hidden; }
.img-prev.tall { height: 120px; }
.img-prev img { position: absolute; inset: 6px; width: calc(100% - 12px); height: calc(100% - 12px); object-fit: contain; }
.img-prev .ph { color: var(--muted); font-size: 12px; }
.img-meta b { display: block; font-size: 13.5px; }
.img-meta p { margin: 3px 0 10px; color: var(--muted); font-size: 12.5px; }
.img-actions { display: flex; gap: 6px; }
.brand-preview { margin-top: 16px; border: 1px dashed var(--border); border-radius: 10px; padding: 12px 16px; background: #fff; }
.brand-preview small { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-bottom: 8px; font-weight: 600; }
.bp-row { display: flex; align-items: center; gap: 12px; }
.bp-row .mark, .bp-row .p-mark { flex: none; display: block; }
.bp-row .p-mark { height: 46px; width: auto; }
.bp-full { height: 52px; object-fit: contain; }
.bp-name { font-family: Poppins, "Segoe UI", Arial, sans-serif; font-weight: 600; font-size: 22px; color: #1B2A4A; line-height: 1.1; }
.bp-name .acc { color: #F28C28; }
.bp-legal { font-size: 9.5px; font-weight: 600; letter-spacing: 2px; text-transform: uppercase; color: #7A8397; margin-top: 3px; }
.branch-card { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px 16px; background: #fafbfc; }
.branch-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.branch-head small { color: var(--muted); font-size: 12px; }
.branch-head code, .tokens code, .sect-head code { background: #eef0f4; border-radius: 4px; padding: 1px 5px; font-size: 12px; }
.branch-card .grid2 { gap: 12px 14px; }
#c2Wrap label.f { font-size: 12.5px; font-weight: 500; color: #3b4354; gap: 5px; }
#c2Wrap select { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 13.5px; background: #fff; width: 100%; }
.c2-preview { margin-top: 14px; font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.c2-chip { display: inline-flex; gap: 6px; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; color: var(--text); font-size: 13px; }
.c2-chip b { text-transform: uppercase; letter-spacing: .6px; font-size: 11.5px; color: var(--brand-dark); }
.c2-preview small { width: 100%; color: #8a6400; }
.num-preview { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.num-preview > div { background: #fafbfc; border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; font-size: 13px; color: var(--muted); }
.num-preview small { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; font-weight: 600; margin-bottom: 4px; }
.num-preview b { color: var(--text); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 600; }
.tokens { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 12px; font-size: 12.5px; color: var(--muted); }
.counter-grid { display: grid; grid-template-columns: 160px 1fr 1fr; gap: 10px 14px; align-items: center; margin-top: 14px; max-width: 560px; }
.cg-h { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.cg-l { font-size: 13px; font-weight: 500; color: #3b4354; }
.edit-table { width: 100%; border-collapse: collapse; }
.edit-table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 0 6px 8px; font-weight: 600; }
.edit-table td { padding: 3px 6px; }
.edit-table td.center { text-align: center; padding: 18px; }
.edit-table .w120 { width: 130px; }
.edit-table .w44 { width: 44px; }
.edit-table input[type=number] { text-align: right; }
.ta-foot { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); }
.ta-foot em { font-style: normal; }
.btn.link.sm { padding: 2px 4px; font-size: 12px; }
.backup-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.backup-card { border: 1px solid var(--border); border-radius: 10px; padding: 16px; background: #fafbfc; display: flex; flex-direction: column; }
.backup-card b { font-size: 13.5px; }
.backup-card p { margin: 4px 0 12px; color: var(--muted); font-size: 12.5px; flex: 1; }
.backup-card .btn { align-self: flex-start; }
.meter { height: 8px; border-radius: 4px; background: #e6e9ef; overflow: hidden; }
.meter span { display: block; height: 100%; background: #23884a; border-radius: 4px; min-width: 2px; }
.meter span.hot { background: var(--danger); }
.danger-zone { margin-top: 18px; display: flex; justify-content: space-between; align-items: center; gap: 16px; border: 1px solid #f3c9c9; background: #fff8f8; border-radius: 10px; padding: 14px 16px; }
.danger-zone b { font-size: 13.5px; color: #a52f2f; }
.danger-zone p { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }
.danger-zone .btn { flex: none; border-color: #f3c9c9; }
@media (max-width: 1000px) {
  .settings-layout { grid-template-columns: 1fr; }
  .settings-nav { position: static; flex-direction: row; overflow-x: auto; padding-bottom: 4px; }
  .settings-nav a span { white-space: nowrap; }
  .grid2, .grid3, .backup-row, .num-preview { grid-template-columns: 1fr; }
  .counter-grid { grid-template-columns: 120px 1fr 1fr; }
  .danger-zone { flex-direction: column; align-items: flex-start; }
}

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: #1d2330; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13.5px;
  opacity: 0; transition: .2s; pointer-events: none; z-index: 50; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); }

@media (max-width: 960px) {
  body { height: auto; }
  .view.active { flex-direction: column; height: auto; }
  .form { width: 100%; border-right: 0; border-bottom: 1px solid var(--border); }
  .preview-scroll { padding: 12px; }
  .tb-actions { margin-left: 0; }
  .panel { padding: 18px 16px 50px; }
  .search { width: 100%; }
  .filters { width: 100%; }
}

/* ===== printing: only the rendered pages ===== */
@media print {
  @page { size: A4; margin: 0; }
  html, body { background: #fff; height: auto; display: block; }
  body > *:not(#render-area) { display: none !important; }
  #render-area { position: static; left: auto; width: auto; }
  #render-area .page { break-after: page; page-break-after: always; margin: 0; box-shadow: none; }
  #render-area .page:last-child { break-after: auto; page-break-after: auto; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ===== sign in ===== */
.login { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 10% -10%, #ffe6d2 0, transparent 60%), radial-gradient(900px 500px at 110% 110%, #dcebf8 0, transparent 60%), var(--bg); }
.login-card { width: min(420px, 100%); background: #fff; border: 1px solid var(--border); border-radius: 16px; padding: 28px 28px 22px; box-shadow: 0 20px 60px rgba(16, 24, 40, .14); }
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.login-brand b { display: block; font-size: 15px; }
.login-brand small { color: var(--muted); font-size: 12px; }
.tb-logo.big { width: 36px; height: 36px; border-radius: 8px; }
.login h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -.3px; }
.login-sub { margin: 0 0 18px; color: var(--muted); font-size: 13.5px; }
.login-seg { margin-bottom: 14px; }
.login-seg button { padding: 9px 8px; font-size: 13.5px; }
.login-seg .flag { font-size: 15px; margin-right: 4px; }
.login form label.f { margin-bottom: 12px; font-size: 12.5px; font-weight: 500; color: #3b4354; }
.login form input { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.login-err { background: #fdecec; color: #a52f2f; border-radius: 8px; padding: 9px 12px; font-size: 13px; margin-bottom: 12px; }
.btn.wide { width: 100%; padding: 10px; font-size: 14px; }
.login-foot { margin: 16px 0 0; text-align: center; color: var(--muted); font-size: 12px; }

/* ===== user menu / region switch ===== */
.region-switch { width: auto; margin-right: 4px; }
.region-switch button { padding: 6px 12px; font-size: 12.5px; }
.user-menu { position: relative; }
.user-chip { display: flex; align-items: center; gap: 9px; border: 1px solid var(--border); background: #fff; border-radius: 22px; padding: 4px 10px 4px 4px; cursor: pointer; }
.user-chip:hover { border-color: #b9c0cc; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: #fff; font-weight: 700; font-size: 12px; display: grid; place-items: center; }
.user-txt { display: flex; flex-direction: column; line-height: 1.15; text-align: left; }
.user-txt b { font-size: 13px; }
.user-txt small { font-size: 11px; color: var(--muted); }
.caret { color: var(--muted); font-size: 11px; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 190px; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(16, 24, 40, .14); padding: 6px; z-index: 30; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 13.5px; }
.menu button:hover { background: #f4f5f8; }

/* read-only document */
.ro-banner { display: flex; gap: 10px; align-items: flex-start; background: #fff7da; border: 1px solid #f3e2a0; color: #6e5300; border-radius: 8px; padding: 10px 12px; font-size: 12.5px; margin-bottom: 12px; }
.ro-banner .ico { width: 16px; height: 16px; margin-top: 1px; color: #b58a00; }
.form.readonly input, .form.readonly select, .form.readonly textarea { background: #fafbfc; color: #5b6478; }
.branch-fixed { display: flex; align-items: center; gap: 8px; height: 36px; font-weight: 600; font-size: 13.5px; }

/* team page */
.team-tabs { margin-bottom: 0; }
.role-badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11.5px; font-weight: 600; background: #eef0f4; color: #4a5366; }
.role-badge.admin { background: #e8f2fb; color: #145c94; }
.inactive td { opacity: .55; }
.dlg-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.dlg-fields label.f { font-size: 12.5px; font-weight: 500; color: #3b4354; gap: 4px; }
.dlg-fields label.f.full { grid-column: 1 / -1; }
.dlg-fields input, .dlg-fields select { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 13.5px; width: 100%; }
.dlg-fields .seg { width: 100%; }
.dlg-err { background: #fdecec; color: #a52f2f; border-radius: 8px; padding: 8px 12px; font-size: 13px; margin-bottom: 12px; }
.dlg.wide { width: min(520px, calc(100vw - 32px)); }
@media (max-width: 600px) { .dlg-fields { grid-template-columns: 1fr; } }

.region-bar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.region-tabs button { font-size: 14px; padding: 8px 16px; }
.region-note { color: #8a6400; background: #fff7da; border-radius: 8px; padding: 6px 12px; font-size: 12.5px; }
.region-note:empty { display: none; }
.region-chip { vertical-align: middle; margin-left: 8px; font-size: 12px; background: #fff1e6; color: var(--brand-dark); }
.counter-grid.two { grid-template-columns: 160px 200px; }
.avatar.sm { width: 24px; height: 24px; font-size: 10px; background: #1b75bb; }
table.list .empty { padding: 26px; text-align: center; color: var(--muted); }

.prefix-field { display: flex; align-items: stretch; border: 1px solid var(--border); border-radius: 8px; background: #fff; overflow: hidden; }
.prefix-field:focus-within { outline: 2px solid #f6c29d; border-color: var(--brand); }
.prefix-field .prefix { display: flex; align-items: center; padding: 0 12px; background: #f4f5f8; color: #3b4354; font-weight: 600; border-right: 1px solid var(--border); white-space: nowrap; }
.login form .prefix-field input { border: 0; border-radius: 0; flex: 1; min-width: 0; outline: none; letter-spacing: .5px; }
.prefix-field .peek { border: 0; background: none; padding: 0 12px; cursor: pointer; color: var(--muted); font-size: 15px; }
.prefix-field .peek:hover { color: var(--text); }
.login-hint { display: block; font-weight: 400; color: var(--muted); font-size: 11.5px; margin-top: 5px; }

.no-backend { background: #fff7da; color: #6e5300; border-bottom: 1px solid #f3e2a0; padding: 10px 44px 10px 18px; font-size: 13px; position: relative; line-height: 1.45; }
.no-backend code { background: #fff; border: 1px solid #f3e2a0; border-radius: 4px; padding: 0 5px; }
.no-backend button { position: absolute; right: 10px; top: 6px; border: 0; background: none; font-size: 20px; cursor: pointer; color: #8a6400; }

/* =====================================================================
   Layout of the editor (desktop): form on the left, toolbar + preview on the right
   ===================================================================== */
#view-editor.view.active { display: grid; grid-template-columns: 420px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
#view-editor .form { grid-column: 1; grid-row: 1 / 3; min-height: 0; }
#view-editor .preview-toolbar { grid-column: 2; grid-row: 1; }
#view-editor .preview-wrap { grid-column: 2; grid-row: 2; min-height: 0; }
.editor-tabs, .nav-new, .new-sheet, .lbl-short, .nav-ico { display: none; }

/* =====================================================================
   PHONES & SMALL TABLETS
   ===================================================================== */
@media (max-width: 960px) {
  :root { --tb-h: 56px; --nav-h: 62px; }
  html, body { height: auto; }
  body { min-height: 100vh; min-height: 100dvh; }
  /* iOS zooms into any field under 16px – keep fields at 16px */
  input:not([type=checkbox]):not([type=radio]):not([type=color]), select, textarea { font-size: 16px !important; }

  /* ---- top bar: logo + status + avatar ---- */
  .topbar { position: sticky; top: 0; z-index: 20; height: var(--tb-h); flex-wrap: nowrap; gap: 10px; padding: 0 12px; }
  .tb-brand { min-width: 0; gap: 9px; }
  .tb-brand strong { font-size: 15px; white-space: nowrap; }
  .tb-brand small { display: none; }
  .tb-logo { width: 26px; height: 26px; flex: none; }
  .tb-actions { margin-left: auto; gap: 8px; flex: none; }
  #btnNewQ, #btnNewI { display: none; }
  .db-pill { font-size: 0; padding: 0; margin: 0; width: 22px; height: 22px; justify-content: center; background: none !important; }
  .db-pill::before { width: 9px; height: 9px; }
  .user-chip { padding: 2px; border-radius: 50%; }
  .user-txt, .caret { display: none; }
  .avatar { width: 32px; height: 32px; font-size: 12.5px; }
  .region-switch { margin-right: 0; }
  .region-switch button { padding: 5px 9px; font-size: 12px; }
  .menu { right: -4px; min-width: 210px; }

  /* ---- bottom tab bar ---- */
  .tb-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; gap: 0;
    display: flex; justify-content: space-around; align-items: stretch;
    background: rgba(255, 255, 255, .97); border-top: 1px solid var(--border);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 20px rgba(16, 24, 40, .06);
    -webkit-backdrop-filter: saturate(180%) blur(12px); backdrop-filter: saturate(180%) blur(12px);
  }
  .tb-nav button { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 6px 2px; border-radius: 10px; font-size: 11px; font-weight: 600; color: #7a8397; background: none; }
  .tb-nav button.active { background: none; color: var(--brand-dark); }
  .tb-nav button.active .nav-ico { background: #fff1e6; }
  .tb-nav .nav-ico { display: block; width: 44px; height: 28px; padding: 4px 12px; border-radius: 14px; }
  .lbl-long { display: none; }
  .lbl-short { display: inline; }
  .tb-nav .nav-new { display: flex; }
  .tb-nav .nav-new .nav-ico { width: 44px; height: 44px; padding: 11px; margin-top: -18px; border-radius: 50%; background: var(--brand); color: #fff; box-shadow: 0 6px 16px rgba(232, 119, 46, .45); }
  .tb-nav .nav-new[aria-expanded="true"] .nav-ico { transform: rotate(45deg); }
  .tb-nav .nav-new .nav-ico { transition: transform .15s; }
  .new-sheet:not([hidden]) {
    display: grid; gap: 8px; position: fixed; z-index: 26; left: 12px; right: 12px;
    bottom: calc(var(--nav-h) + 14px + env(safe-area-inset-bottom));
    background: #fff; border: 1px solid var(--border); border-radius: 16px; padding: 10px;
    box-shadow: 0 16px 40px rgba(16, 24, 40, .22);
  }
  .new-sheet button { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; border: 1px solid var(--border); background: #fafbfc; border-radius: 12px; padding: 13px 14px; cursor: pointer; }
  .new-sheet button b { font-size: 15px; }
  .new-sheet button small { color: var(--muted); font-size: 12.5px; }
  .new-sheet button:active { background: #fff1e6; border-color: #f6c29d; }

  main { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
  #toast { bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); }
  .no-backend { font-size: 12px; }

  /* ---- editor: toolbar + Edit/Preview tabs, one pane at a time ---- */
  #view-editor.view.active { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto; height: auto; }
  #view-editor .preview-toolbar { grid-column: 1; grid-row: 1; position: sticky; top: var(--tb-h); z-index: 10; padding: 8px 12px; gap: 8px; flex-wrap: nowrap; }
  #view-editor .pt-left { min-width: 0; flex: 1; display: flex; flex-direction: column; }
  .doc-label { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .dirty { margin-left: 0; font-size: 11.5px; }
  .pt-right { gap: 6px; flex: none; }
  #zoomSel, #btnPrint, #tplSel { display: none; }   /* design choice stays available in Settings > Company */
  #btnSave, #btnPdf { padding: 8px 12px; }
  .editor-tabs { display: flex; grid-column: 1; grid-row: 2; width: auto; margin: 10px 12px 0; background: #fff; }
  .editor-tabs button { padding: 9px 8px; font-size: 14px; font-weight: 600; }
  #view-editor .form, #view-editor .preview-wrap { grid-column: 1; grid-row: 3; }
  #view-editor.pane-form .preview-wrap, #view-editor.pane-preview .form { display: none; }
  #view-editor .form { width: 100%; border: 0; background: none; padding: 4px 12px 24px; overflow: visible; }
  #view-editor .form .fs { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 0 14px 14px; margin: 12px 0 0; }
  #view-editor .form .fs legend { float: left; width: 100%; padding: 14px 0 10px; }
  #view-editor .form .fs legend + * { clear: both; }
  .item-row { grid-template-columns: minmax(0, 1fr) 104px 34px; }
  .icon-btn { line-height: 40px; font-size: 22px; }
  .items-actions { flex-wrap: wrap; }
  .items-actions select { min-width: 0; }
  .ro-banner { margin: 12px 0 0; }
  .preview-scroll { padding: 12px; background: #d9dce2; min-height: 60vh; }
  .pages .page { margin-bottom: 12px; }

  /* ---- panels ---- */
  .panel { padding: 16px 14px 28px; overflow: visible; min-width: 0; }   /* min-width: 0 stops wide content stretching the page */
  .page-head { margin-bottom: 14px; align-items: flex-start; }
  .page-head h2 { font-size: 21px; }
  .page-actions { width: 100%; }
  .page-actions [data-new] { display: none; }

  /* saved documents */
  .region-bar { margin-bottom: 12px; }
  .region-tabs { width: 100%; }
  .region-tabs button { flex: 1; justify-content: center; font-size: 13.5px; padding: 8px 6px; }
  .region-note { width: 100%; }
  .list-toolbar { padding: 10px; }
  .list-toolbar .tabs { width: 100%; }
  .list-toolbar .tabs button { flex: 1; justify-content: center; padding: 6px 4px; }
  .filters { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto; }
  .search { width: auto; }
  .list-foot { flex-direction: column; gap: 4px; }

  /* settings */
  .settings-layout { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .settings-nav { position: sticky; top: var(--tb-h); z-index: 5; flex-direction: row; overflow-x: auto; margin: 0 -14px; padding: 8px 14px; background: var(--bg); scrollbar-width: none; min-width: 0; }
  .settings-nav::-webkit-scrollbar { display: none; }
  .settings-nav a { flex: none; background: #fff; border: 1px solid var(--border); padding: 7px 12px; }
  .settings-nav a.on { border-color: #f6c29d; }
  .sect-head { padding: 14px 16px 12px; }
  .sect-body { padding: 16px; }
  .img-card { flex-direction: column; }
  .img-prev, .img-prev.tall { width: 100%; height: 120px; }
  .danger-zone .btn { width: 100%; }
  .counter-grid, .counter-grid.two { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr); gap: 8px 10px; }
  .counter-grid.two { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); }
  .tokens { gap: 6px 12px; }

  /* dialogs */
  .dlg form { padding: 18px 16px 16px; }
  .dlg-actions .btn { flex: 1; padding: 10px; }
}

/* ---- tables become cards on phones and tablets ---- */
@media (max-width: 960px) {
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
  .stat { padding: 12px 13px; gap: 0; }
  .stat-ic { display: none; }
  .stat-l { font-size: 10.5px; }
  .stat-v { font-size: 17px; }
  .stat-v.sec { font-size: 13px; }
  .stat-s { font-size: 11px; }

  table.list thead { display: none; }
  table.list, table.list tbody { display: block; }
  table.list tbody tr { display: grid; column-gap: 12px; row-gap: 5px; padding: 14px; border-bottom: 1px solid #eef0f4; align-items: center; }
  table.list tbody tr:last-child { border-bottom: 0; }
  table.list td { display: block; padding: 0; border: 0; min-width: 0; background: none !important; }
  table.list tbody tr:hover, table.list tbody tr:focus { background: #fff9f4; }
  table.list .cell-main, table.list .cell-sub { overflow: hidden; text-overflow: ellipsis; }
  table.list .acts { justify-content: flex-start; gap: 6px; padding-top: 9px; margin-top: 4px; border-top: 1px dashed #e6e9ef; }
  table.list .icon-gap { display: none; }
  table.list .icon-act { width: 42px; height: 38px; border-color: var(--border); background: #fff; }
  table.list .act-col { width: auto; }
  table.list td.empty { grid-column: 1 / -1; }

  /* documents: number + amount / customer + status / date + branch / actions */
  #docTable tbody tr { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "doc amt" "cust status" "date branch" "acts acts"; }
  #docTable td:nth-child(1) { grid-area: doc; }
  #docTable td:nth-child(2) { grid-area: cust; }
  #docTable td:nth-child(3) { grid-area: date; font-size: 12.5px; color: var(--muted); }
  #docTable td:nth-child(4) { grid-area: branch; justify-self: end; }
  #docTable td:nth-child(5) { grid-area: amt; text-align: right; }
  #docTable td:nth-child(6) { grid-area: status; justify-self: end; }
  #docTable td:nth-child(7) { grid-area: acts; }

  /* team: name + status / mobile + role / last sign-in / actions */
  .team-list tbody tr { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "name status" "phone role" "last last" "acts acts"; }
  .team-list td:nth-child(1) { grid-area: name; }
  .team-list td:nth-child(2) { grid-area: phone; font-size: 13px; }
  .team-list td:nth-child(3) { grid-area: role; justify-self: end; }
  .team-list td:nth-child(4) { grid-area: last; font-size: 12px; color: var(--muted); }
  .team-list td:nth-child(4)::before { content: "Last sign-in: "; }
  .team-list td:nth-child(5) { grid-area: status; justify-self: end; }
  .team-list td:nth-child(6) { grid-area: acts; }
  #teamPanel .list-toolbar { flex-wrap: nowrap; }
  #teamPanel .list-toolbar .tabs { width: auto; }

  /* price list rows stack: description on top, prices + delete below */
  .edit-table thead { display: none; }
  .edit-table, .edit-table tbody { display: block; }
  .edit-table tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 42px; gap: 6px 8px; padding: 10px 0; border-bottom: 1px dashed #e6e9ef; align-items: end; }
  .edit-table td { padding: 0; }
  .edit-table td:first-child { grid-column: 1 / -1; }
  .edit-table td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 600; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .4px; }
  .edit-table td.center { grid-column: 1 / -1; }
}

/* laptops: keep the top bar on one line (status becomes a dot, the user chip an avatar) */
@media (min-width: 961px) and (max-width: 1600px) {
  .tb-brand small { display: none; }
  .user-txt, .caret { display: none; }
  .user-chip { padding: 2px; border-radius: 50%; }
  .db-pill { font-size: 0; padding: 0; margin: 0; width: 22px; height: 22px; justify-content: center; background: none !important; }
  .db-pill::before { width: 9px; height: 9px; }
}
@media (min-width: 961px) { .topbar { flex-wrap: nowrap; } .tb-nav button { white-space: nowrap; } }
@media (min-width: 961px) and (max-width: 1100px) {
  .lbl-new { display: none; }
  .topbar { gap: 12px; padding: 10px 14px; }
  .tb-nav button { padding: 8px 9px; }
  .tb-actions { gap: 6px; }
}

/* payment fields in the editor, QR preview in settings */
.pay-box { margin-top: 10px; padding: 10px 12px 4px; background: #f1faf5; border: 1px solid #cde9d8; border-radius: 8px; }
.pay-box .hint { color: #1f6e40; font-weight: 600; margin-bottom: 8px; }
.qr-preview { display: flex; align-items: center; gap: 14px; margin-top: 16px; padding: 12px 14px; border: 1px dashed var(--border); border-radius: 10px; background: #fff; }
.qr-preview .qr-prev-img { width: 96px; height: 96px; flex: none; border: 1px solid var(--border); border-radius: 6px; }
.qr-preview b { display: block; font-size: 14px; }
.qr-preview small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 3px; overflow-wrap: anywhere; }
.qr-preview a { color: var(--blue); }

/* editor: comparison options */
.comp-opts { margin-top: 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: #fafbfc; }
.comp-cols { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.chip-chk { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--border); background: #fff; border-radius: 16px; padding: 4px 10px 4px 7px; font-size: 12.5px; cursor: pointer; }
.chip-chk input { margin: 0; accent-color: var(--brand); }
.chip-chk.chosen { border-color: var(--brand); background: #fff1e6; font-weight: 600; }
.comp-quick { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.comp-rows summary { cursor: pointer; font-weight: 600; font-size: 13px; padding: 6px 0; }
.comp-count { color: var(--muted); font-weight: 400; margin-left: 4px; }
.comp-g { margin: 8px 0 4px; }
.comp-g .chk { margin: 2px 0; }
.comp-g .chk.r { margin-left: 22px; font-size: 12.5px; }
.comp-g .chk input { accent-color: var(--brand); }

/* settings: versions + comparison editor */
.ver-names { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 6px; }
.ver-pill { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 8px; background: #fff; overflow: hidden; }
.sect-body .ver-pill input { border: 0 !important; width: 104px; padding: 7px 8px !important; font-weight: 600; }
.ver-pill button { border: 0; border-left: 1px solid var(--border); background: #fafbfc; color: #9aa2b1; cursor: pointer; width: 30px; align-self: stretch; font-size: 16px; }
.ver-pill button:hover { color: var(--danger); background: #fff6f6; }
.cmp-wrap { margin-top: 8px; border: 1px solid var(--border); border-radius: 10px; max-height: 620px; overflow: auto; }
.cmp-edit { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.cmp-edit thead th { position: sticky; top: 0; z-index: 1; background: #1B2A4A; color: #fff; font-size: 10.5px; text-transform: uppercase; letter-spacing: .4px; padding: 7px 4px; font-weight: 600; min-width: 64px; }
.cmp-edit th.cf { text-align: left; padding-left: 10px; min-width: 240px; }
.cmp-edit td { padding: 2px 3px; border-top: 1px solid #eef0f4; }
.cmp-edit td.cf { padding-left: 6px; }
.sect-body .cmp-edit td input { padding: 5px 7px !important; font-size: 12.5px; border-radius: 6px; }
.sect-body .cmp-edit input.cv { text-align: center; font-weight: 700; padding: 5px 2px !important; }
.sect-body .cmp-edit input.cv.ok { color: #1f7a42; background: #f1faf5; }
.sect-body .cmp-edit input.cv.no { color: #c73b3b; background: #fff6f6; }
.sect-body .cmp-edit input.cv.add { color: #4a5366; background: #eef0f4; }
.cmp-edit tr.cg td { background: #fff6ee; padding: 7px 8px; border-top: 1px solid #f3dcc7; }
.cmp-edit tr.cg td > * { vertical-align: middle; }
.sect-body .cmp-edit input.cg-name { width: 300px; max-width: 60%; font-weight: 700; margin-right: 10px; }
.cmp-edit tr.cg .chk { display: inline-flex; margin: 0 10px 0 0; }
.cmp-edit tr.cadd td { padding: 2px 6px 8px; }
.cmp-edit td.cd { width: 40px; text-align: center; }
.cmp-edit .icon-act { width: 28px; height: 28px; }

/* a document's own comparison list */
.comp-custom { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 0 0 10px; margin-bottom: 8px; border-bottom: 1px dashed var(--border); }
.badge-custom { display: inline-flex; align-items: center; gap: 4px; background: #fff1e6; color: var(--brand-dark); border: 1px solid #f6c29d; border-radius: 14px; padding: 3px 10px; font-size: 12px; font-weight: 600; }
.cmp-dlg { width: min(1180px, calc(100vw - 24px)); max-height: calc(100vh - 32px); padding: 0; display: flex; flex-direction: column; }
.cmp-dlg:not([open]) { display: none; }
.cmp-dlg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 18px 20px 12px; border-bottom: 1px solid var(--border); }
.cmp-dlg-head h3 { margin: 0 0 3px; font-size: 17px; }
.cmp-dlg-head p { margin: 0; color: var(--muted); font-size: 13px; }
.cmp-dlg-body { padding: 14px 20px 18px; overflow: auto; }
.cmp-dlg-body .cmp-wrap { max-height: none; }
.cmp-dlg-body input:not([type=checkbox]) { border: 1px solid var(--border); border-radius: 6px; padding: 5px 7px; font-size: 12.5px; width: 100%; background: #fff; }
.cmp-dlg-body input.cv { text-align: center; font-weight: 700; padding: 5px 2px; }
.cmp-dlg-body input.cv.ok { color: #1f7a42; background: #f1faf5; }
.cmp-dlg-body input.cv.no { color: #c73b3b; background: #fff6f6; }
.cmp-dlg-body input.cv.add { color: #4a5366; background: #eef0f4; }
.cmp-dlg-body input.cg-name { width: 300px; max-width: 60%; font-weight: 700; margin-right: 10px; }
@media (max-width: 960px) { .cmp-dlg-head { flex-direction: column; } .cmp-dlg-head .btn { align-self: stretch; } }
