:root { --bg: #f4f5f8; --card: #fff; --ink: #1c2430; --muted: #6b7684; --line: #e2e6ec; --brand: #5b3cc4; --brand-2: #0e9f8a; --accent: #efeafd; --err: #b3261e; }
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; }
h2, h3 { margin: 0 0 .5em; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
[hidden] { display: none !important; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 12px 24px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { display: flex; gap: 10px; align-items: center; }
.brand-name { font-weight: 800; font-size: 17px; }
.brand-sub { color: var(--muted); font-size: 13px; }
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sel { font-size: 13px; color: var(--muted); display: flex; flex-direction: row; gap: 6px; align-items: center; }

.btn { border: 1px solid var(--brand); background: #fff; color: var(--brand); padding: 8px 14px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--accent); }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: #4a2fa6; }
.btn.ghost { border-color: var(--line); color: var(--ink); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.pill { background: var(--accent); color: var(--brand); border-radius: 10px; padding: 0 7px; font-size: 12px; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: var(--brand); }

.layout { display: grid; grid-template-columns: 420px 1fr; gap: 20px; max-width: 1320px; margin: 0 auto; padding: 20px 24px; align-items: start; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; }
.catalog { position: sticky; top: 76px; max-height: calc(100vh - 96px); display: flex; flex-direction: column; overflow: hidden; }
.cat-head { padding: 18px 18px 10px; border-bottom: 1px solid var(--line); }
.cat-head input { width: 100%; margin: 4px 0 10px; }
.cats { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 16px; padding: 4px 11px; font: inherit; font-size: 13px; cursor: pointer; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.items { overflow: auto; padding: 6px 10px 14px; }
.cat-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 12px 8px 4px; }
.item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px; border-radius: 9px; }
.item:hover { background: var(--bg); }
.item.added .iname { color: var(--brand); }
.add { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--brand); background: #fff; color: var(--brand); font-size: 18px; cursor: pointer; flex: none; }
.add:hover, .item.added .add { background: var(--brand); color: #fff; }

.offer { padding: 20px 22px; }
.offer-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.offer-buttons { display: flex; gap: 8px; }
.client { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 8px 0 16px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.wide { grid-column: 1 / -1; }
.lines { width: 100%; border-collapse: collapse; }
.lines th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px; border-bottom: 1px solid var(--line); }
.lines td { padding: 7px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.lines input { width: 92px; padding: 5px 7px; }
.lines .r { text-align: right; white-space: nowrap; font-weight: 600; }
.del { border: 0; background: none; color: var(--muted); font-size: 20px; cursor: pointer; line-height: 1; }
.del:hover { color: var(--err); }
.empty { color: var(--muted); padding: 26px; text-align: center; border: 1px dashed var(--line); border-radius: 10px; }
.totals { display: grid; grid-template-columns: 140px 1fr; gap: 10px 16px; margin-top: 18px; }
.totals label:first-child input { width: 100%; }
#sum { grid-column: 1 / -1; justify-self: end; min-width: 320px; border-collapse: collapse; }
#sum td { padding: 4px 0; }
#sum td:last-child { text-align: right; padding-left: 30px; white-space: nowrap; }
#sum .total td { font-size: 22px; font-weight: 800; color: var(--brand); border-top: 2px solid var(--line); padding-top: 8px; }
.actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 4px 0 26px; }
.foot a { color: var(--brand); }

dialog { border: 0; border-radius: 14px; padding: 24px; width: min(640px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.logo-preview { margin-top: 10px; display: flex; gap: 12px; align-items: center; }
.logo-preview img { max-height: 54px; max-width: 200px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.saved-row { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }

.toast { position: fixed; right: 22px; bottom: 22px; padding: 13px 18px; border-radius: 10px; background: var(--brand-2); color: #fff; box-shadow: 0 8px 24px rgba(0,0,0,.18); z-index: 20; max-width: 420px; }
.toast.err { background: var(--err); }

.print { display: none; }
@media print {
  @page { size: A4; margin: 14mm; }
  .no-print { display: none !important; }
  body { background: #fff; }
  .print { display: block; font-size: 12px; color: #111; }
  .p-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 3px solid var(--brand); padding-bottom: 10px; margin-bottom: 16px; }
  .p-brand { display: flex; gap: 12px; align-items: center; }
  .p-brand img { max-height: 56px; max-width: 160px; }
  .p-company { font-size: 18px; font-weight: 800; color: var(--brand); }
  .p-contacts { color: #555; }
  .p-meta { text-align: right; color: #444; }
  .p-to { margin: 0 0 6px; }
  .print h1 { font-size: 19px; margin: 6px 0 14px; }
  .p-table { width: 100%; border-collapse: collapse; }
  .p-table th { background: var(--brand); color: #fff; text-align: left; padding: 6px 8px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .p-table td { padding: 6px 8px; border-bottom: 1px solid #ddd; }
  .p-table td:nth-child(n+3), .p-table th:nth-child(n+3) { text-align: right; white-space: nowrap; }
  .p-table tr { break-inside: avoid; }
  .p-sum { margin: 12px 0 0 auto; border-collapse: collapse; min-width: 300px; }
  .p-sum td { padding: 4px 8px; }
  .p-sum td:last-child { text-align: right; white-space: nowrap; }
  .p-total td { font-size: 16px; font-weight: 800; color: var(--brand); border-top: 2px solid var(--brand); }
  .p-comment { margin-top: 18px; padding: 10px 12px; background: #f6f4fd; border-radius: 6px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .p-sign { margin-top: 34px; }
  .p-req { margin-top: 20px; color: #666; font-size: 10.5px; }
}

@media (max-width: 920px) {
  .layout { grid-template-columns: 1fr; padding: 12px; }
  .catalog { position: static; max-height: 60vh; }
  .client, .grid2, .totals { grid-template-columns: 1fr; }
  #sum { min-width: 0; width: 100%; }
}
