:root {
  color-scheme: dark;
  --bg: #080a0d;
  --panel: #10141a;
  --line: #252c35;
  --muted: #8f99a8;
  --text: #f4f5f7;
  --accent: #b8ff3d;
  --paper: #f7f5ee;
  --ink: #171a1d;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.topbar { position: sticky; z-index: 20; top: 0; min-height: 72px; padding: 12px clamp(18px, 3vw, 48px); display: flex; align-items: center; justify-content: space-between; gap: 18px; border-bottom: 1px solid var(--line); background: rgba(8,10,13,.9); backdrop-filter: blur(18px); }
.brand { display: inline-flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand__mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; color: #101405; background: var(--accent); font-size: 13px; font-weight: 900; }
.brand strong, .brand small { display: block; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.topbar__actions { display: flex; gap: 8px; }
.button { min-height: 42px; padding: 0 16px; border: 1px solid var(--line); border-radius: 10px; color: var(--text); background: transparent; font-weight: 750; }
.button--accent { border-color: var(--accent); color: #101405; background: var(--accent); }
.button:hover { transform: translateY(-1px); }

.workspace { width: min(1560px, 100%); margin: 0 auto; padding: clamp(18px, 3vw, 42px); display: grid; grid-template-columns: minmax(290px, 390px) minmax(600px, 1fr); gap: clamp(20px, 3vw, 44px); align-items: start; }
.panel { border: 1px solid var(--line); border-radius: 22px; background: var(--panel); }
.controls { position: sticky; top: 96px; max-height: calc(100vh - 118px); padding: 24px; overflow: auto; }
.eyebrow { color: var(--accent); font-size: 11px; font-weight: 900; letter-spacing: .16em; text-transform: uppercase; }
h1 { max-width: 9ch; margin: 10px 0 12px; font-size: clamp(32px, 4vw, 54px); line-height: .98; letter-spacing: -.055em; }
.lead { color: var(--muted); font-size: 14px; line-height: 1.6; }
.form-section { margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--line); }
.form-section h2 { margin: 0 0 13px; font-size: 13px; }
.form-grid { display: grid; gap: 11px; }
.form-grid--two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
label { color: var(--muted); font-size: 11px; font-weight: 700; }
input, textarea, select { width: 100%; margin-top: 7px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 9px; outline: none; color: var(--text); background: #0b0e12; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: #5b683d; box-shadow: 0 0 0 3px rgba(184,255,61,.08); }
.autosave { margin-top: 24px; color: var(--muted); font-size: 11px; }
.autosave span { display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 14px rgba(184,255,61,.6); }

.invoice-wrap { min-width: 0; }
.invoice { min-height: 940px; padding: clamp(38px, 6vw, 84px); border-radius: 2px; color: var(--ink); background: var(--paper); box-shadow: 0 30px 90px rgba(0,0,0,.28); }
.invoice__head { display: flex; justify-content: space-between; gap: 30px; padding-bottom: 42px; border-bottom: 2px solid var(--ink); }
.invoice__brand { margin-bottom: 12px; font-size: 28px; font-weight: 900; letter-spacing: -.04em; }
.muted { color: #6c7075; font-size: 12px; line-height: 1.6; }
.preline { white-space: pre-line; }
.invoice__meta { text-align: right; }
.invoice__meta span, .client-card span { display: block; color: #747a80; font-size: 10px; font-weight: 900; letter-spacing: .16em; }
.invoice__meta strong { display: block; margin: 6px 0; font-size: 26px; }
.invoice__meta small { color: #747a80; }
.client-card { margin: 34px 0; padding: 20px; border: 1px solid #d8d6ce; background: #efede5; }
.client-card strong { display: block; margin-top: 8px; font-size: 18px; }
.client-card p { margin: 7px 0 0; color: #666a6e; font-size: 12px; line-height: 1.5; }
.items-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.items-head h2 { font-size: 17px; }
.add-line { border: 0; color: #3a4b16; background: transparent; font-size: 12px; font-weight: 850; }
.items { margin-top: 13px; border-top: 1px solid #c9c7c0; }
.item-row { display: grid; grid-template-columns: minmax(160px, 1fr) 64px 104px 96px 28px; gap: 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid #dcdbd5; }
.item-row input { margin: 0; padding: 10px; border: 1px solid transparent; color: var(--ink); background: transparent; }
.item-row input:hover, .item-row input:focus { border-color: #cbc9c1; box-shadow: none; }
.item-qty, .item-price { text-align: right; }
.item-total { text-align: right; font-size: 13px; white-space: nowrap; }
.remove-item { width: 28px; height: 28px; border: 0; border-radius: 50%; color: #9a3f3f; background: transparent; font-size: 20px; }
.remove-item:hover { background: #f0dddd; }
.invoice__bottom { margin-top: 48px; display: grid; grid-template-columns: 1fr minmax(230px, 300px); gap: 46px; align-items: start; }
.note-label { color: #747a80; }
.note-label textarea { min-height: 106px; border-color: #d8d6ce; color: var(--ink); background: transparent; line-height: 1.5; }
.totals > div { display: flex; justify-content: space-between; gap: 20px; padding: 9px 0; color: #6f7377; font-size: 12px; }
.totals > div strong { color: var(--ink); }
.totals .totals__grand { margin-top: 9px; padding: 19px 0; border-top: 2px solid var(--ink); color: var(--ink); font-size: 15px; }
.totals__grand strong { font-size: 24px; }
.totals small { display: block; text-align: right; color: #747a80; }

@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; }
  .controls { position: static; max-height: none; }
  .invoice { min-height: auto; }
}

@media (max-width: 650px) {
  .topbar { align-items: flex-start; }
  .button--ghost { display: none; }
  .workspace { padding: 12px; }
  .controls { padding: 19px; }
  .invoice { padding: 28px 20px; }
  .invoice__head { flex-direction: column; }
  .invoice__meta { text-align: left; }
  .item-row { grid-template-columns: minmax(120px, 1fr) 45px 78px 75px 25px; gap: 2px; }
  .item-row input { padding: 8px 4px; font-size: 11px; }
  .item-total { font-size: 10px; }
  .invoice__bottom { grid-template-columns: 1fr; }
}

@media print {
  @page { size: A4; margin: 0; }
  body { background: white; }
  .topbar, .controls, .add-line, .remove-item { display: none !important; }
  .workspace { display: block; width: auto; padding: 0; }
  .invoice { width: 210mm; min-height: 297mm; padding: 18mm; box-shadow: none; }
  .item-row input, .note-label textarea { border-color: transparent; }
}
