/* ================================================================
   Invoice Studio — app UI
   ================================================================ */
@font-face { font-family: 'Montserrat'; src: url('../fonts/Montserrat-VF.woff') format('woff'); font-weight: 100 900; font-style: normal; font-display: swap; }
@font-face { font-family: 'Montserrat'; src: url('../fonts/Montserrat-Italic-VF.woff') format('woff'); font-weight: 100 900; font-style: italic; font-display: swap; }

:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --ink: #15171c;
  --ink-2: #3d424c;
  --muted: #747a85;
  --line: #e7e4dd;
  --line-2: #d9d5cc;
  --side: #121418;
  --side-2: #1b1e24;
  --side-ink: #c9ccd2;
  --ok: #17845a;   --ok-bg: #e5f4ec;
  --warn: #b46a00; --warn-bg: #fdf1dc;
  --bad: #c2372f;  --bad-bg: #fbe8e6;
  --info: #2b5fb3; --info-bg: #e7eefb;
  --accent: #1d2430; --accent-soft: #eef0f3; --on-accent: #fff;
  --r: 14px; --r-sm: 9px;
  --shadow: 0 1px 2px rgba(20, 22, 28, .04), 0 6px 24px -12px rgba(20, 22, 28, .12);
  --shadow-lg: 0 24px 60px -20px rgba(15, 18, 25, .35);
  --sb-w: 264px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.5 'Montserrat', system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased; font-feature-settings: 'lnum' 1;
}
a { color: inherit; }
img { max-width: 100%; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; background: rgba(0,0,0,.05); padding: 1px 5px; border-radius: 5px; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 26px; font-weight: 700; line-height: 1.2; }
h2 { font-size: 15px; font-weight: 700; }
h3 { font-size: 17px; font-weight: 700; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.strong { font-weight: 700; }
.num { font-variant-numeric: tabular-nums; }
.eyebrow { font-size: 11.5px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.label { font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.hint { display: block; font-size: 12px; color: var(--muted); margin-top: 6px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
.i { flex: none; }

/* ---------------- shell ---------------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sb-w); z-index: 40;
  background: var(--side); color: var(--side-ink);
  display: flex; flex-direction: column; padding: 18px 14px;
  border-right: 1px solid rgba(255,255,255,.04);
}
.sb-brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 22px; text-decoration: none; color: #fff; font-weight: 700; font-size: 15.5px; letter-spacing: -.01em; }
.sb-mark { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: linear-gradient(135deg, #2a2f38, #0c0e11); box-shadow: inset 0 0 0 1px rgba(255,255,255,.08); color: #f4d48a; }
.sb-nav { flex: 1; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.sb-label { margin: 18px 10px 8px; font-size: 10.5px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: #6c727d; }
.sb-link { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 10px; text-decoration: none; color: var(--side-ink); font-weight: 500; transition: background .15s, color .15s; }
.sb-link:hover { background: var(--side-2); color: #fff; }
.sb-link.is-active { background: var(--side-2); color: #fff; box-shadow: inset 0 0 0 1px rgba(255,255,255,.05); }
.sb-logo { width: 30px; height: 30px; border-radius: 8px; background: #fff; display: grid; place-items: center; overflow: hidden; flex: none; box-shadow: 0 0 0 2px transparent; transition: box-shadow .2s; }
.sb-logo img { width: 100%; height: 100%; object-fit: contain; }
.sb-brandlink span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-brandgroup.is-open .sb-logo { box-shadow: 0 0 0 2px var(--b); }
.sb-brandgroup.is-open .sb-brandlink { color: #fff; }
.sb-sub { display: none; flex-direction: column; margin: 2px 0 8px 25px; padding-left: 16px; border-left: 1px solid #2a2e36; }
.sb-brandgroup.is-open .sb-sub { display: flex; }
.sb-sub a { display: flex; align-items: center; gap: 9px; padding: 7px 10px; font-size: 13px; color: #9aa0aa; text-decoration: none; border-radius: 8px; }
.sb-sub a:hover { color: #fff; background: var(--side-2); }
.sb-sub a.is-active { color: #fff; background: var(--side-2); }
.sb-sub a.is-active::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--b); margin: 0 -2px 0 -19px; position: relative; left: -10px; }
.sb-logout { margin-top: 10px; color: #8d929b; }
.sb-backdrop { display: none; }

.main { flex: 1; min-width: 0; margin-left: var(--sb-w); display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: 64px; display: flex; align-items: center; gap: 14px;
  padding: 0 28px; background: rgba(244, 243, 239, .86); backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.crumbs { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; }
.crumbs a { text-decoration: none; }
.crumbs a:hover { color: var(--ink); }
.crumbs b { color: var(--ink); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.banner { margin: 16px 28px 0; padding: 10px 14px; border-radius: 10px; background: var(--warn-bg); color: #7a4a00; font-size: 13px; border: 1px solid #f4dcae; }
.content { padding: 28px; max-width: 1480px; width: 100%; }

/* ---------------- buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px;
  border-radius: 10px; border: 1px solid transparent; font: inherit; font-weight: 600; font-size: 13.5px;
  cursor: pointer; text-decoration: none; white-space: nowrap; transition: transform .12s var(--ease), background .15s, box-shadow .15s, border-color .15s, filter .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: #000; }
.btn-brand { background: var(--accent); color: var(--on-accent); box-shadow: 0 6px 16px -8px var(--accent); }
.btn-brand:hover { filter: brightness(1.06) saturate(1.05); }
.btn-ghost { background: var(--surface); border-color: var(--line-2); color: var(--ink); }
.btn-ghost:hover { border-color: #bdb8ad; background: #fff; }
.btn-ghost.on-dark { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.18); color: #fff; }
.btn-danger { background: var(--bad); color: #fff; }
.btn-dashed { background: transparent; border: 1.5px dashed var(--line-2); color: var(--ink-2); height: 46px; }
.btn-dashed:hover { border-color: var(--accent); color: var(--ink); background: var(--accent-soft); }
.btn-block { width: 100%; }
.btn.is-loading { position: relative; color: transparent !important; }
.btn.is-loading::after { content: ''; position: absolute; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--on-accent); border-right-color: transparent; animation: spin .7s linear infinite; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; border: 1px solid transparent;
  background: transparent; color: var(--ink-2); cursor: pointer; text-decoration: none;
}
.icon-btn:hover { background: rgba(0,0,0,.05); color: var(--ink); }
.icon-btn.sm { width: 32px; height: 32px; border-radius: 8px; }
.icon-btn.danger:hover { background: var(--bad-bg); color: var(--bad); }
.icon-btn:disabled { opacity: .3; cursor: default; background: transparent; }
.icon-btn.on-dark { color: #fff; }
.icon-btn.on-dark:hover { background: rgba(255,255,255,.12); }
.link-btn { border: 0; background: none; padding: 0; font: inherit; font-size: 12.5px; font-weight: 600; color: var(--ink-2); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.link-btn:hover { color: var(--ink); }
.chip { height: 28px; padding: 0 11px; border-radius: 99px; border: 1px solid var(--line-2); background: var(--surface); font: inherit; font-size: 12px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.chip:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.chip-plain { border-style: dashed; }

/* ---------------- badges ---------------- */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 99px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-paid { background: var(--ok-bg); color: var(--ok); }
.badge-partial { background: var(--warn-bg); color: var(--warn); }
.badge-unpaid { background: var(--bad-bg); color: var(--bad); }

/* ---------------- cards & forms ---------------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 22px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.grid { display: grid; gap: 14px 16px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; position: relative; }
.field > span, .label-like { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field em { color: var(--bad); font-style: normal; }
.field .opt { font-style: normal; font-weight: 500; color: var(--muted); font-size: 11.5px; }
input, select, textarea {
  font: inherit; font-size: 14px; color: var(--ink); width: 100%;
  height: 42px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: var(--r-sm); background: var(--surface-2);
  transition: border-color .15s, box-shadow .15s, background .15s; outline: none;
}
textarea { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.55; }
select { appearance: none; -webkit-appearance: none; padding-right: 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='%23747a85' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; }
input:hover, select:hover, textarea:hover { border-color: #c4bfb4; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3.5px color-mix(in srgb, var(--accent) 18%, transparent); }
input:disabled { opacity: .5; cursor: not-allowed; }
input[type=date] { padding-right: 8px; }
input[type=checkbox] { width: auto; height: auto; }
::placeholder { color: #a7aab1; }
.input-affix { position: relative; display: flex; align-items: center; }
.input-affix > i { position: absolute; left: 12px; font-style: normal; color: var(--muted); font-weight: 600; pointer-events: none; }
.input-affix > input { padding-left: 28px; }
.input-group { display: flex; }
.input-group > input { border-radius: var(--r-sm) 0 0 var(--r-sm); }
.input-group > select { width: 64px; flex: none; border-radius: 0 var(--r-sm) var(--r-sm) 0; margin-left: -1px; background-color: #fff; }
.input-group > .addon { display: grid; place-items: center; width: 44px; flex: none; border: 1px solid var(--line-2); border-left: 0; border-radius: 0 var(--r-sm) var(--r-sm) 0; background: #f0eee9; color: var(--muted); font-weight: 600; }
.err { color: var(--bad); font-size: 12px; font-weight: 500; min-height: 0; }
.err:empty { display: none; }
.err.block { display: block; margin-bottom: 10px; }
.err.block:empty { display: none; }
.field.has-err input, .field.has-err select, .field.has-err textarea { border-color: var(--bad); background: #fff8f7; }
.form-error { margin-bottom: 16px; padding: 12px 14px; border-radius: 10px; background: var(--bad-bg); color: var(--bad); font-weight: 600; font-size: 13px; border: 1px solid #f3cbc6; }
.alert { padding: 12px 14px; border-radius: 10px; font-size: 13px; font-weight: 600; margin-bottom: 16px; }
.alert-error { background: var(--bad-bg); color: var(--bad); }
.alert-ok { background: var(--ok-bg); color: var(--ok); }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--ink-2); user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 38px; height: 22px; border-radius: 99px; background: #d6d2c9; position: relative; flex: none; transition: background .2s; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .2s var(--ease); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.inline-select { display: flex; align-items: center; gap: 8px; }
.inline-select select { width: auto; height: 34px; font-size: 13px; }
.quick-terms { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 14px; }
.quick-terms.tight { margin-top: 2px; }

/* ---------------- page heads ---------------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.page-head .muted { margin-top: 6px; max-width: 620px; }
.brand-head { justify-content: flex-start; align-items: center; }
.bh-logo { width: 72px; height: 72px; border-radius: 18px; background: #fff; border: 1px solid var(--line); display: grid; place-items: center; overflow: hidden; flex: none; box-shadow: var(--shadow); }
.bh-logo img { width: 84%; height: 84%; object-fit: contain; }

/* ---------------- dashboard ---------------- */
.brand-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 22px; }
.brand-card { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; transition: transform .25s var(--ease), box-shadow .25s; }
.brand-card:hover { transform: translateY(-3px); box-shadow: 0 2px 4px rgba(0,0,0,.03), 0 28px 50px -24px rgba(20,22,28,.28); }
.brand-card-top {
  position: relative; display: grid; place-items: center; height: 196px; text-decoration: none;
  background:
    radial-gradient(120% 90% at 100% 0%, var(--b-soft) 0%, transparent 60%),
    linear-gradient(180deg, #fff, #fbfaf7);
  border-bottom: 1px solid var(--line);
}
.bc-stripe { position: absolute; left: 0; top: 30px; width: 10px; height: 64px; background: var(--b); border-radius: 0 4px 4px 0; }
.bc-logo { width: 150px; height: 150px; object-fit: contain; transition: transform .35s var(--ease); }
.brand-card:hover .bc-logo { transform: scale(1.04); }
.bc-next { position: absolute; right: 0; top: 26px; padding: 8px 16px 8px 18px; border-radius: 99px 0 0 99px; background: var(--b); color: var(--b-on); font-weight: 800; font-size: 12.5px; letter-spacing: .04em; }
.brand-card-body { padding: 22px 24px 24px; display: flex; flex-direction: column; flex: 1; }
.brand-card-body h2 { font-size: 21px; }
.brand-card-body > .muted { margin-top: 4px; }
.bc-stats { display: grid; grid-template-columns: repeat(3, 1fr); margin: 20px 0 16px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.bc-stats > div { padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; background: var(--surface-2); }
.bc-stats > div + div { border-left: 1px solid var(--line); }
.bc-stats span { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
.bc-stats b { font-size: 18px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bc-bar { height: 6px; border-radius: 99px; background: #ece9e2; display: flex; overflow: hidden; }
.bc-bar i { display: block; height: 100%; }
.s-paid { background: var(--ok); } .s-partial { background: #e2a33a; } .s-unpaid { background: #dc6b63; }
.bc-legend { display: flex; gap: 14px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.bc-legend i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.bc-recent { margin-top: 18px; display: flex; flex-direction: column; gap: 4px; }
.bc-recent .label { margin-bottom: 4px; }
.bc-row { display: grid; grid-template-columns: 62px 1fr auto auto; align-items: center; gap: 10px; padding: 8px 10px; margin: 0 -10px; border-radius: 9px; text-decoration: none; font-size: 13px; }
.bc-row:hover { background: var(--surface-2); }
.bc-row .amt { font-weight: 600; font-variant-numeric: tabular-nums; }
.bc-actions { display: flex; gap: 10px; margin-top: auto; padding-top: 20px; }
.bc-actions .btn { flex: 1; height: 44px; }
.brand-card .btn-brand { background: var(--b); color: var(--b-on); box-shadow: 0 8px 18px -10px var(--b); }

/* ---------------- history ---------------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { display: flex; align-items: center; gap: 14px; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); min-width: 0; }
.stat p { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat b { font-size: 20px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat > div { min-width: 0; }
.stat-ico { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.stat-ico.ok { background: var(--ok-bg); color: var(--ok); }
.stat-ico.warn { background: var(--warn-bg); color: var(--warn); }
.list-card { padding: 0; overflow: visible; }
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.search { position: relative; flex: 1 1 260px; display: flex; align-items: center; }
.search svg { position: absolute; left: 12px; color: var(--muted); }
.search input { padding-left: 38px; }
.seg { display: inline-flex; padding: 3px; background: #efede8; border-radius: 11px; gap: 2px; }
.seg button { border: 0; background: transparent; font: inherit; font-size: 12.5px; font-weight: 600; color: var(--muted); height: 34px; padding: 0 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.seg button i { font-style: normal; font-size: 11px; margin-left: 4px; padding: 1px 6px; border-radius: 99px; background: rgba(0,0,0,.06); }
.seg button.is-active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.filter-more { display: flex; gap: 8px; flex-wrap: wrap; }
.mini { display: flex; flex-direction: column; gap: 2px; }
.mini span { font-size: 10.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.mini input, .mini select { height: 36px; font-size: 13px; width: auto; min-width: 130px; }
.table-wrap { overflow-x: auto; }
.tbl-list { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl-list th { text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
.tbl-list td { padding: 13px 18px; border-bottom: 1px solid #f0ede7; vertical-align: middle; }
.tbl-list tbody tr { transition: background .12s; }
.tbl-list tbody tr:hover { background: #fcfbf8; }
.tbl-list .r { text-align: right; }
.tbl-list .cust b { display: block; font-weight: 600; }
.tbl-list .cust span { display: block; }
.tbl-list td a.strong { text-decoration: none; }
.tbl-list td a.strong:hover { text-decoration: underline; }
.tbl-list .due { color: var(--bad); font-weight: 600; }
.tbl-list .actions { white-space: nowrap; }
.tbl-list .actions > * { vertical-align: middle; }
.menu-wrap { position: relative; display: inline-block; }
.menu { position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; min-width: 180px; padding: 6px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); text-align: left; }
.menu button, .menu a { display: block; width: 100%; padding: 9px 12px; border: 0; background: none; font: inherit; font-size: 13px; font-weight: 500; text-align: left; border-radius: 8px; cursor: pointer; text-decoration: none; color: var(--ink); }
.menu button:hover, .menu a:hover { background: var(--surface-2); }
.menu .danger { color: var(--bad); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 0; }
.empty-row, .loading-row { text-align: center; padding: 48px 18px !important; }
.empty { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty .btn { margin-top: 8px; }
.list-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; flex-wrap: wrap; }
.pager { display: flex; gap: 4px; align-items: center; }
.pager button { min-width: 34px; height: 34px; border: 1px solid var(--line); background: #fff; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; }
.pager button.is-active { background: var(--ink); color: #fff; border-color: var(--ink); }
.pager button:disabled { opacity: .4; cursor: default; }
.pager span { padding: 0 4px; color: var(--muted); }

/* ---------------- editor ---------------- */
.page-editor .content { max-width: none; padding-right: 0; padding-top: 0; padding-bottom: 0; }
.editor { display: grid; grid-template-columns: minmax(440px, 1fr) minmax(420px, 1.05fr); gap: 0; align-items: start; }
.ed-form { padding: 28px 28px 40px 0; min-width: 0; }
.ed-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.ed-title h1 small { font-size: 13px; font-weight: 500; }
.ed-preview { position: sticky; top: 64px; height: calc(100vh - 64px); display: flex; flex-direction: column; background: #e6e4de; border-left: 1px solid var(--line); }
.pv-bar { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px 10px 20px; border-bottom: 1px solid #d9d6cf; background: rgba(255,255,255,.4); }
.pv-title { font-size: 12.5px; font-weight: 600; color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.pv-title .dot { width: 8px; height: 8px; border-radius: 50%; background: #2fbf71; box-shadow: 0 0 0 3px rgba(47,191,113,.2); }
.pv-actions { display: flex; gap: 2px; }
.pv-stage { flex: 1; overflow: auto; padding: 22px 16px 40px; }
.pv-paper { margin: 0 auto; position: relative; box-shadow: 0 18px 50px -18px rgba(20,22,28,.35), 0 0 0 1px rgba(0,0,0,.04); background: #fff; overflow: hidden; }
.pv-paper iframe { position: absolute; left: 0; top: 0; border: 0; transform-origin: 0 0; background: #fff; width: 794px; height: 1123px; }

.items { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
.item { border: 1px solid var(--line); border-radius: 12px; padding: 14px; background: var(--surface-2); position: relative; }
.item:focus-within { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); background: #fff; }
.item-top { display: flex; align-items: flex-start; gap: 10px; }
.item-no { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; background: var(--accent-soft); color: var(--ink); font-weight: 700; font-size: 12px; margin-top: 8px; flex: none; }
.item-top .grow { flex: 1; }
.item-top input { font-weight: 600; }
.item-tools { display: flex; gap: 0; margin-top: 4px; }
.item .sub { margin: 8px 0 0 36px; }
.item .sub input { height: 36px; font-size: 13px; }
.item-grid { display: grid; grid-template-columns: 1.25fr .75fr 1fr; gap: 10px; margin: 10px 0 0 36px; align-items: end; }
.item-grid .item-amount { grid-column: 3; }
.item-grid .field > span { font-size: 11.5px; color: var(--muted); }
.item-grid input, .item-grid select { height: 38px; font-size: 13.5px; background: #fff; }
.item-grid .custom-label { grid-column: 2; }
.item-amount { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; padding-bottom: 6px; }
.item-amount span { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.item-amount b { font-size: 15px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.override-box { margin-top: 10px; max-width: 260px; }

.totals-card { margin-top: 20px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); padding: 6px 16px; }
.totals-card > div { display: flex; justify-content: space-between; padding: 8px 0; font-size: 13.5px; color: var(--ink-2); }
.totals-card > div + div { border-top: 1px dashed var(--line); }
.totals-card b { font-variant-numeric: tabular-nums; color: var(--ink); }
.totals-card .grand { font-size: 16px; font-weight: 700; color: var(--ink); }
.totals-card .grand b { font-size: 18px; }
.totals-card .bal b { color: var(--bad); }

.ed-footer { position: sticky; bottom: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 20px; padding: 14px 18px; background: rgba(255,255,255,.92); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border: 1px solid var(--line); border-radius: var(--r); box-shadow: 0 -8px 30px -18px rgba(20,22,28,.25); flex-wrap: wrap; }
.ed-footer-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.ed-tabs { display: none; }

.ac-wrap { position: relative; }
.ac-list { position: absolute; top: 72px; left: 0; right: 0; z-index: 25; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px; max-height: 300px; overflow: auto; }
.ac-list button { display: flex; flex-direction: column; align-items: flex-start; width: 100%; padding: 9px 12px; border: 0; background: none; border-radius: 8px; cursor: pointer; font: inherit; text-align: left; }
.ac-list button:hover { background: var(--surface-2); }
.ac-list span { font-size: 12px; color: var(--muted); }

/* full preview */
.modal { position: fixed; inset: 0; z-index: 100; background: rgba(14,16,20,.55); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 20px; animation: fade .18s ease; }
.modal-card { background: #fff; border-radius: 18px; padding: 24px; width: 100%; max-width: 520px; box-shadow: var(--shadow-lg); animation: pop .22s var(--ease); }
.modal-sm { max-width: 440px; }
.modal-card h3 { margin-bottom: 6px; }
.modal-card .field { margin-top: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; flex-wrap: wrap; }
.modal-full { display: flex; flex-direction: column; padding: 0; place-items: stretch; background: rgba(14,16,20,.88); }
.fp-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 18px; color: #fff; border-bottom: 1px solid rgba(255,255,255,.1); flex-wrap: wrap; }
.fp-bar > div { display: flex; gap: 8px; align-items: center; }
.fp-stage { flex: 1; overflow: auto; padding: 28px 16px 60px; }
.fp-paper { margin: 0 auto; overflow: hidden; background: #fff; box-shadow: 0 30px 80px -20px rgba(0,0,0,.6); }

.pdf-busy { position: fixed; inset: 0; z-index: 120; display: grid; place-content: center; justify-items: center; gap: 14px; background: rgba(244,243,239,.75); backdrop-filter: blur(4px); font-weight: 600; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(0,0,0,.1); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.spinner.sm { width: 22px; height: 22px; margin: 0 auto; border-width: 2.5px; }

/* toasts */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
.toast { max-width: 380px; padding: 12px 16px; border-radius: 12px; background: var(--ink); color: #fff; font-size: 13px; font-weight: 600; box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(8px); transition: opacity .25s, transform .25s var(--ease); pointer-events: auto; }
.toast.in { opacity: 1; transform: none; }
.toast-error { background: var(--bad); }
.toast-info { background: var(--info); }
.toast-ok::before { content: '✓  '; color: #7be0a8; }

/* settings */
.settings-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; align-items: start; }
.settings-grid .card + .card { margin-top: 0; }
.settings-grid > .card:first-of-type { grid-row: span 2; }
.settings-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 10px; }
.fixed-info { display: flex; gap: 16px; align-items: center; }
.fixed-info img { width: 96px; height: 96px; padding: 10px; object-fit: contain; border: 1px solid var(--line); border-radius: 14px; background: #fff; flex: none; }
.fixed-info dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; }
.fixed-info dt { color: var(--muted); font-weight: 600; }
.fixed-info dd { margin: 0; font-weight: 600; display: flex; align-items: center; gap: 8px; word-break: break-all; }
.swatch { width: 14px; height: 14px; border-radius: 4px; display: inline-block; box-shadow: inset 0 0 0 1px rgba(0,0,0,.1); }

/* login */
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(90% 60% at 50% 0%, #fff 0%, var(--bg) 60%); }
.auth-card { width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--line); border-radius: 20px; padding: 32px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; gap: 14px; }
.auth-card h1 { font-size: 22px; }
.auth-mark { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: linear-gradient(135deg, #2a2f38, #0c0e11); color: #f4d48a; }
.auth-card .btn { height: 46px; margin-top: 4px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

.only-mobile, .only-narrow { display: none !important; }

/* ---------------- responsive ---------------- */
@media (max-width: 1180px) {
  .editor { grid-template-columns: 1fr; }
  .ed-form { padding: 20px 28px 40px 0; }
  .ed-tabs.only-narrow { display: flex !important; position: sticky; top: 64px; z-index: 12; margin: 0 28px 0 0; padding: 12px 0 0; background: var(--bg); gap: 4px; }
  .ed-tabs button { flex: 1; height: 40px; border: 1px solid var(--line-2); background: #fff; font: inherit; font-weight: 600; border-radius: 10px; cursor: pointer; }
  .ed-tabs button.is-active { background: var(--ink); color: #fff; border-color: var(--ink); }
  .editor .ed-preview { display: none; position: static; height: auto; min-height: calc(100vh - 130px); margin: 12px 28px 28px 0; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
  .editor[data-view="preview"] .ed-form { display: none; }
  .editor[data-view="preview"] .ed-preview { display: flex; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-grid { grid-template-columns: 1fr; }
  .settings-grid > .card:first-of-type { grid-row: auto; }
}
@media (max-width: 900px) {
  :root { --sb-w: 280px; }
  .sidebar { transform: translateX(-100%); transition: transform .28s var(--ease); box-shadow: var(--shadow-lg); }
  body.sb-open .sidebar { transform: none; }
  body.sb-open .sb-backdrop { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(0,0,0,.4); }
  .main { margin-left: 0; }
  .only-mobile { display: inline-grid !important; }
  .topbar { padding: 0 14px; gap: 8px; }
  .banner { margin: 12px 14px 0; }
  .content { padding: 18px 14px; }
  .page-editor .content { padding: 0 14px; }
  .ed-form { padding: 16px 0 32px; }
  .ed-tabs.only-narrow { margin: 0; }
  .editor .ed-preview { margin: 12px 0 20px; }
  .hide-sm { display: none !important; }
}
@media (max-width: 640px) {
  h1 { font-size: 22px; }
  .card { padding: 16px; border-radius: 12px; }
  .g-2, .g-3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .brand-grid { grid-template-columns: 1fr; }
  .bc-stats b { font-size: 15px; }
  .brand-card-top { height: 170px; }
  .bc-logo { width: 130px; height: 130px; }
  .bc-row { grid-template-columns: 54px 1fr auto; }
  .bc-row .badge { display: none; }
  .stat { padding: 14px; gap: 10px; }
  .stat b { font-size: 16px; }
  .stat-ico { width: 34px; height: 34px; }
  .filters { padding: 14px; }
  .seg { width: 100%; overflow-x: auto; }
  .seg button { flex: 1; padding: 0 8px; }
  .filter-more { width: 100%; }
  .mini { flex: 1; }
  .mini input, .mini select { min-width: 0; width: 100%; }
  .tbl-list thead { display: none; }
  .tbl-list, .tbl-list tbody, .tbl-list tr, .tbl-list td { display: block; }
  .tbl-list tr { padding: 12px 14px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; }
  .tbl-list td { padding: 2px 0; border: 0; text-align: left !important; }
  .tbl-list td[data-l]::before { content: attr(data-l); display: block; font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
  .tbl-list td.actions { grid-column: 1 / -1; display: flex; gap: 6px; justify-content: flex-end; border-top: 1px dashed var(--line); padding-top: 8px; margin-top: 4px; }
  .tbl-list td.cust { grid-column: 1 / -1; }
  .item-grid { grid-template-columns: 1fr 1fr; margin-left: 0; }
  .item-grid .custom-label { grid-column: auto; }
  .item .sub { margin-left: 0; }
  .item-grid .item-amount { grid-column: 1 / -1; flex-direction: row; justify-content: space-between; align-items: center; padding: 4px 0 0; }
  .item-tools { flex-wrap: nowrap; }
  .item-top .item-tools .icon-btn[data-item="dup"] { display: none; }
  .ed-footer { padding: 12px; }
  .ed-footer-actions { width: 100%; }
  .ed-footer-actions .btn { flex: 1; }
  .topbar-actions .btn { padding: 0 12px; height: 38px; }
  .hide-xs { display: none; }
  .crumbs a, .crumbs span { display: none; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .brand-head { flex-direction: row; }
  .bh-logo { width: 56px; height: 56px; border-radius: 14px; }
  .fixed-info { flex-direction: column; align-items: flex-start; }
  .toasts { left: 14px; right: 14px; bottom: 14px; align-items: stretch; }
  .toast { max-width: none; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
