:root {
  --bg: #0d1017;
  --panel: #151a24;
  --panel-2: #1b2130;
  --line: #2a3142;
  --text: #e8ebf2;
  --muted: #98a1b3;
  --pink: #E84393;
  --teal: #22D3C7;
  --amber: #F2B84B;
  --red: #ef5a5a;
  --green: #3ecf8e;
  --radius: 10px;
  --font-head: "Space Grotesk", "Inter", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font-body); }
a { color: var(--teal); }
h1, h2, h3, h4 { font-family: var(--font-head); font-weight: 600; margin: 0 0 .6em; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
code, .mono { font-family: var(--font-mono); font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* Layout */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { font-family: var(--font-head); font-size: 1.3rem; font-weight: 700; padding: 4px 10px 18px; }
.brand span { color: var(--pink); }
.brand small { display: block; font: 500 11px var(--font-mono); color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none; }
.nav a:hover { background: var(--panel-2); }
.nav a.active { background: rgba(232, 67, 147, .14); color: #fff; box-shadow: inset 3px 0 0 var(--pink); }
.nav .sep { margin: 14px 10px 6px; font: 600 11px var(--font-mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.side-foot { margin-top: auto; padding: 10px; border-top: 1px solid var(--line); font-size: 13px; }
.side-foot a { color: var(--muted); }
.main { padding: 24px 28px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { margin: 0; }
.page-head .spacer { flex: 1; }

/* Panels and cards */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.panel > h2:first-child, .panel > h3:first-child { margin-top: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card .k { font: 500 11px var(--font-mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.card .v { font: 600 1.5rem var(--font-head); margin-top: 4px; }
.card .s { font-size: 12px; color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 16px; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-all { grid-column: 1 / -1; }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .span-2, .span-3 { grid-column: auto; }
  .main { padding: 16px; }
}

/* Forms */
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 500; }
input, select, textarea, .rte-area {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 7px;
  padding: 7px 9px; font: inherit; font-size: 14px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus, .rte-area:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 2px rgba(34, 211, 199, .18); }
input[type="checkbox"] { width: auto; accent-color: var(--pink); }
input[type="color"] { padding: 2px; height: 36px; }
input:disabled, select:disabled, textarea:disabled { opacity: .6; }
input.bad { border-color: var(--red); }
textarea { resize: vertical; min-height: 70px; }
textarea.code { font-family: var(--font-mono); font-size: 12.5px; line-height: 1.5; white-space: pre; tab-size: 2; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); cursor: pointer; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar input[type="search"], .toolbar input.search { width: 260px; }
.toolbar select { width: auto; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel-2);
  color: var(--text); padding: 7px 13px; border-radius: 7px; font: 500 13px var(--font-body); cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #3a4357; background: #222a3b; }
.btn.primary { background: var(--pink); border-color: var(--pink); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.teal { background: transparent; border-color: var(--teal); color: var(--teal); }
.btn.danger { color: var(--red); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--panel-2); }
.btn.sm { padding: 4px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 3px 5px; border-radius: 5px; font-size: 14px; line-height: 1; }
.icon-btn:hover { color: var(--text); background: var(--panel-2); }
.icon-btn.on { color: var(--amber); }

/* Tables */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: left; font: 600 11px var(--font-mono); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: var(--panel-2); }
table.t .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; color: var(--muted); font-size: 13px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font: 600 11px var(--font-mono); letter-spacing: .03em; border: 1px solid currentColor; white-space: nowrap; }
.badge.Draft { color: var(--muted); }
.badge.Sent { color: var(--teal); }
.badge.Accepted { color: var(--green); }
.badge.Declined { color: var(--red); }
.badge.Expired { color: var(--amber); }
.badge.Superseded { color: #8a8fa0; text-decoration: line-through; }
.badge.admin { color: var(--pink); }

/* Quote editor */
.q-head { position: sticky; top: 0; z-index: 20; background: var(--bg); padding: 10px 0 12px; margin: -10px 0 8px; border-bottom: 1px solid var(--line); }
.q-ref { font: 700 1.5rem var(--font-head); }
.dirty-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--amber); display: inline-block; }
.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; font-size: 13px; }
.banner.info { border-color: rgba(34, 211, 199, .4); background: rgba(34, 211, 199, .08); }
.banner.warn { border-color: rgba(242, 184, 75, .45); background: rgba(242, 184, 75, .08); }
.banner.ok { border-color: rgba(62, 207, 142, .45); background: rgba(62, 207, 142, .08); }
.lines { width: 100%; border-collapse: collapse; }
.lines th { font: 600 10.5px var(--font-mono); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.lines th.num { text-align: right; }
.lines td { padding: 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.lines input, .lines textarea { padding: 5px 6px; font-size: 13px; }
.lines .c-handle { width: 22px; cursor: grab; color: var(--muted); text-align: center; padding-top: 9px; user-select: none; }
.lines .c-part { width: 130px; }
.lines .c-qty { width: 64px; }
.lines .c-money { width: 96px; }
.lines .c-mod { width: 96px; }
.lines .c-total { width: 104px; text-align: right; padding-top: 9px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lines .c-margin { width: 62px; text-align: right; padding-top: 9px; font-size: 12px; color: var(--muted); }
.lines .c-act { width: 128px; white-space: nowrap; text-align: right; }
.lines input.num { text-align: right; font-variant-numeric: tabular-nums; }
.lines tr.heading td { background: rgba(232, 67, 147, .06); }
.lines tr.heading input { font-weight: 600; font-family: var(--font-head); }
.lines tr.subtotal td { background: var(--panel-2); font-weight: 600; }
.lines tr.text td { background: rgba(34, 211, 199, .04); }
.lines tr.optional td { opacity: .75; }
.lines tr.drag-over td { border-top: 2px solid var(--pink); }
.lines tr.dragging { opacity: .4; }
.lines .details { margin-top: 4px; min-height: 40px; font-size: 12.5px; }
.lines .note { margin-top: 4px; min-height: 36px; font-size: 12.5px; border-color: rgba(242, 184, 75, .5); background: rgba(242, 184, 75, .05); }
.price-cell { position: relative; }
.price-cell .lock { position: absolute; left: -16px; top: 8px; font-size: 11px; color: var(--amber); cursor: pointer; }
.add-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.totals-box { margin-left: auto; width: 340px; max-width: 100%; margin-top: 16px; }
.totals-box div { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.totals-box div.grand { font: 700 1.15rem var(--font-head); border-bottom: 2px solid var(--pink); }
.totals-box div.internal { color: var(--muted); font-size: 13px; }

/* Rich text editor */
.rte { border: 1px solid var(--line); border-radius: 7px; background: var(--bg); }
.rte-bar { display: flex; gap: 2px; padding: 4px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.rte-bar button { background: none; border: 0; color: var(--muted); padding: 3px 8px; border-radius: 4px; cursor: pointer; font: 600 12px var(--font-body); }
.rte-bar button:hover { background: var(--panel-2); color: var(--text); }
.rte-area { border: 0; border-radius: 0 0 7px 7px; min-height: 70px; max-height: 420px; overflow: auto; }
.rte-area:empty::before { content: attr(data-placeholder); color: var(--muted); }
.rte-area p { margin: 0 0 .5em; }
.lines .rte-area { min-height: 44px; font-size: 13px; }

/* Template editor */
.tpl-layout { display: grid; grid-template-columns: minmax(380px, 1fr) minmax(420px, 1.1fr); gap: 16px; align-items: start; }
.tpl-layout textarea.code { min-height: 62vh; }
.tpl-preview { background: #fff; border-radius: var(--radius); overflow: hidden; height: calc(62vh + 92px); position: sticky; top: 12px; }
.tpl-preview iframe { width: 100%; height: 100%; border: 0; }
.tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.tabs button { background: none; border: 1px solid var(--line); color: var(--muted); padding: 5px 12px; border-radius: 6px; cursor: pointer; font: 500 13px var(--font-body); }
.tabs button.on { color: #fff; border-color: var(--pink); background: rgba(232, 67, 147, .14); }
.ref-list { font-family: var(--font-mono); font-size: 12px; columns: 2; column-gap: 24px; }
.ref-list div { break-inside: avoid; padding: 2px 0; }
.ref-list span { color: var(--muted); font-family: var(--font-body); }
@media (max-width: 1100px) { .tpl-layout { grid-template-columns: 1fr; } .tpl-preview { position: static; height: 70vh; } }

/* Modal */
.modal-back { position: fixed; inset: 0; background: rgba(3, 5, 10, .7); display: flex; align-items: flex-start; justify-content: center; z-index: 100; padding: 6vh 16px; overflow: auto; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; width: 560px; max-width: 100%; box-shadow: 0 20px 60px rgba(0, 0, 0, .5); }
.modal.wide { width: 920px; }
.modal.full { width: 1100px; }
.modal-h { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-h h3 { margin: 0; flex: 1; }
.modal-b { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.modal iframe.preview { width: 100%; height: 72vh; border: 0; background: #fff; border-radius: 8px; }

/* Autocomplete */
.ac { position: relative; }
.ac-list { position: absolute; z-index: 50; top: 100%; left: 0; right: 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; margin-top: 3px; max-height: 280px; overflow: auto; box-shadow: 0 10px 30px rgba(0, 0, 0, .4); }
.ac-list div { padding: 7px 10px; cursor: pointer; border-bottom: 1px solid var(--line); font-size: 13px; }
.ac-list div:hover, .ac-list div.on { background: rgba(34, 211, 199, .12); }

/* Toast */
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--panel-2); border: 1px solid var(--line); border-left: 4px solid var(--teal); padding: 10px 14px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .4); max-width: 380px; }
.toast.error { border-left-color: var(--red); }
.toast.ok { border-left-color: var(--green); }

/* Login */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: radial-gradient(800px 400px at 20% 0%, rgba(232, 67, 147, .15), transparent), radial-gradient(700px 400px at 100% 100%, rgba(34, 211, 199, .12), transparent), var(--bg); }
.auth { width: 380px; max-width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.auth .brand { padding: 0 0 6px; font-size: 1.6rem; }
.err { color: var(--red); font-size: 13px; min-height: 1em; }

.sig-img { max-height: 70px; background: #fff; border-radius: 6px; padding: 4px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.logo-preview { max-height: 70px; max-width: 240px; background: #fff; padding: 6px; border-radius: 6px; }
