:root {
  --ink-900: #14161c;
  --ink-800: #1d2029;
  --ink-700: #2a2e3a;
  --gold: #f0b400;
  --gold-deep: #dc8f00;
  --gold-soft: #fff6d6;
  --gold-grad: linear-gradient(90deg, #e39a00 0%, #f3c400 55%, #fbe000 100%);
  --text: #1c1f27;
  --muted: #667085;
  --line: #e4e6eb;
  --surface: #f6f7f9;
  --bg: #e9ebef;
  --danger: #d64545;
  --ok: #1f9d55;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  font-size: 14.5px; line-height: 1.5;
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}

/* ---------- Toolbar & action bar (screen only) ---------- */
.toolbar { background: var(--ink-900); border-bottom: 2px solid var(--gold); position: sticky; top: 0; z-index: 10; }
.toolbar-inner { max-width: 1000px; margin: 0 auto; padding: 10px 20px; display: flex; justify-content: space-between; align-items: center; }
.toolbar-title { color: #fff; font-weight: 600; letter-spacing: .06em; font-size: 13px; text-transform: uppercase; }
.lang-switch { display: flex; gap: 4px; }
.lang-switch button { padding: 4px 12px; border: 1px solid var(--ink-700); background: transparent; color: #c9ccd4; cursor: pointer; border-radius: 6px; font-size: 12px; font-weight: 600; }
.lang-switch button.active { background: var(--gold-grad); color: var(--ink-900); border-color: transparent; }

.actions { position: sticky; bottom: 0; background: rgba(20,22,28,.96); backdrop-filter: blur(6px); border-top: 2px solid var(--gold); z-index: 10; }
.actions-inner { max-width: 1000px; margin: 0 auto; padding: 10px 20px; display: flex; justify-content: flex-end; align-items: center; gap: 10px; flex-wrap: wrap; }
.status { margin: 0 auto 0 0; color: var(--gold); font-size: 13px; min-height: 1.2em; }

button { font: inherit; }
button.gold, button.ghost { padding: 9px 18px; border-radius: 8px; cursor: pointer; font-size: 13.5px; font-weight: 600; transition: transform .1s, filter .15s, background .15s; }
button.gold { background: var(--gold-grad); color: var(--ink-900); border: 0; }
button.gold:hover { filter: brightness(1.06); }
button.ghost { background: transparent; color: var(--ink-700); border: 1px solid #cfd3da; }
button.ghost:hover { background: #fff; border-color: var(--gold-deep); }
.actions button.ghost { color: #e5e7ec; border-color: var(--ink-700); }
.actions button.ghost:hover { background: var(--ink-800); border-color: var(--gold); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---------- Page ---------- */
.page { max-width: 1000px; margin: 28px auto 32px; background: #fff; border-radius: 14px; overflow: hidden; box-shadow: 0 10px 40px rgba(20,22,28,.14); }

.brand { background: radial-gradient(120% 160% at 0% 0%, var(--ink-700) 0%, var(--ink-900) 60%); display: flex; justify-content: space-between; align-items: center; padding: 22px 44px; gap: 20px; }
.brand-logo { height: 104px; width: auto; display: block; }
.brand-doc { text-align: right; }
.brand-doc h2 { margin: 0; font-size: 40px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; background: var(--gold-grad); -webkit-background-clip: text; background-clip: text; color: transparent; line-height: 1.1; }
.brand-no { color: #c9ccd4; font-size: 15px; margin-top: 4px; letter-spacing: .04em; }
.gold-bar { height: 5px; background: var(--gold-grad); }

.body { padding: 30px 44px 30px; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; }
.card-label { margin: 0 0 10px; font-size: 11.5px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--gold-deep); }
.k { color: var(--muted); }
.multiline { white-space: pre-wrap; }

.top { display: grid; grid-template-columns: 1.15fr 1fr; gap: 18px; align-items: stretch; }
.seller-name { font-size: 19px; font-weight: 700; margin-bottom: 4px; }
.id-rows { margin-top: 10px; padding-top: 10px; border-top: 1px dashed #d3d6dd; }

.meta { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; align-items: center; align-content: start; background: #fff; border-left: 4px solid var(--gold); }
.meta label { font-weight: 600; color: var(--muted); font-size: 13px; }
.meta .due { grid-column: 1 / -1; margin-top: 6px; padding: 8px 12px; background: var(--ink-900); color: #fff; border-radius: 8px; display: flex; justify-content: space-between; }
.meta .due strong { color: var(--gold); }
.meta input[type="date"] { min-width: 140px; }

.billed { margin-top: 18px; background: #fff; }

/* ---------- Editable fields ---------- */
input, select { font: inherit; padding: 4px 8px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: inherit; min-width: 0; }
input:hover, select:hover { border-color: var(--line); background: #fff; }
input:focus, select:focus, [contenteditable]:focus { outline: 2px solid var(--gold); outline-offset: 1px; background: #fffdf3; }
[contenteditable] { border-radius: 4px; }
[contenteditable]:hover { background: #fffbe8; }

.customer-vat, .type-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.customer-vat label, .type-row label { font-weight: 600; color: var(--muted); font-size: 13px; }
.customer-vat input.warn { border-color: var(--danger); background: #fff3f3; }

/* ---------- Items table ---------- */
.table-wrap { margin-top: 24px; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th { background: var(--ink-900); color: var(--gold); text-align: left; padding: 12px 12px; font-size: 11.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
td { padding: 6px 12px; border-top: 1px solid var(--line); vertical-align: middle; }
tbody tr:nth-child(even) td { background: var(--surface); }
th.num, td.num { text-align: right; }
td input.desc { width: 100%; }
td input.qty { width: 70px; text-align: right; }
td input.price { width: 110px; text-align: right; }
td select.unit { width: 100px; }
td select.rate { width: 72px; text-align: right; }
td.line-net { text-align: right; white-space: nowrap; font-weight: 600; font-variant-numeric: tabular-nums; }
td button.remove { padding: 3px 10px; font-size: 12px; background: #fff; color: var(--danger); border: 1px solid #f0c8c8; border-radius: 6px; cursor: pointer; }
td button.remove:hover { background: #fff3f3; }

.buttons-inline { display: flex; gap: 10px; margin-top: 12px; }

/* ---------- Totals ---------- */
.totals { margin: 22px 0 0 auto; width: 380px; max-width: 100%; }
.discount-row { display: flex; justify-content: flex-end; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.discount-row input { width: 70px; text-align: right; border-color: var(--line); background: #fff; }
.t-row { display: flex; justify-content: space-between; gap: 16px; padding: 5px 12px; font-variant-numeric: tabular-nums; }
.t-row.sub { color: var(--muted); font-size: 13px; }
.t-row.grand { margin-top: 10px; padding: 14px 16px; border-radius: var(--radius); background: var(--ink-900); color: #fff; font-size: 18px; font-weight: 700; border-bottom: 4px solid var(--gold); }
.t-row.grand span:last-child { color: var(--gold); font-size: 22px; }

.note { margin-top: 18px; }
.note #note:empty { display: none; }
.note #note { padding: 10px 14px; border-left: 4px solid var(--gold); background: var(--gold-soft); border-radius: 0 8px 8px 0; font-weight: 500; }

/* ---------- Lower section ---------- */
.lower { display: grid; grid-template-columns: 1fr 1.3fr; gap: 24px; margin-top: 30px; align-items: start; }
.bank { background: #fff; border-left: 4px solid var(--gold); }
.bank > div { margin-bottom: 2px; }
.conditions { color: var(--muted); font-size: 12.5px; }
.conditions ol { margin: 0; padding-left: 20px; }
.conditions li { margin-bottom: 3px; }

.thanks { margin-top: 28px; text-align: center; font-weight: 600; color: var(--ink-700); letter-spacing: .02em; }

.foot { background: var(--ink-900); color: #c9ccd4; font-size: 12.5px; text-align: center; padding: 14px 24px; border-top: 4px solid var(--gold); display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 10px; }
.foot .dot { color: var(--gold); }

/* ---------- Responsive ---------- */
@media screen and (max-width: 760px) {
  .page { margin: 0; border-radius: 0; }
  .brand { padding: 18px 20px; flex-direction: column; align-items: flex-start; }
  .brand-doc { text-align: left; }
  .brand-doc h2 { font-size: 30px; }
  .body { padding: 20px 16px; }
  .top, .lower { grid-template-columns: 1fr; }
  .actions-inner { padding: 10px 12px; }
  .actions-inner button { flex: 1 1 40%; }
}

/* ---------- Print ---------- */
@page { size: A4; margin: 0; }
@media print {
  body { background: #fff; font-size: 11.5px; line-height: 1.4; }
  .no-print { display: none !important; }
  .page { margin: 0; max-width: none; border-radius: 0; box-shadow: none; display: flex; flex-direction: column; min-height: 296mm; }
  .body { flex: 1; }
  .foot { margin-top: auto; }
  .brand { padding: 14px 32px; }
  .brand-logo { height: 76px; }
  .brand-doc { text-align: right; }
  /* gradient-clipped text prints with box artefacts, so use a solid gold */
  .brand-doc h2 { background: none; -webkit-background-clip: border-box; background-clip: border-box; color: var(--gold); font-size: 30px; }
  .body { padding: 18px 32px 14px; }
  .top { grid-template-columns: 1.15fr 1fr; gap: 14px; }
  .lower { grid-template-columns: 1fr 1.3fr; gap: 16px; margin-top: 18px; }
  .card { padding: 10px 14px; }
  .billed { margin-top: 12px; }
  .table-wrap { margin-top: 16px; overflow: visible; }
  .totals { margin-top: 14px; }
  .t-row.grand { padding: 10px 14px; }
  .thanks { margin-top: 10px; }
  .conditions { font-size: 11px; line-height: 1.35; }
  .conditions li { margin-bottom: 2px; }
  .brand-logo { height: 64px; }
  .brand { padding: 10px 32px; }
  .body { padding: 14px 32px 10px; }
  .lower { margin-top: 12px; }
  .totals { margin-top: 10px; }
  .table-wrap { margin-top: 12px; }
  .billed { margin-top: 10px; }
  .foot { padding: 10px 24px; font-size: 11.5px; }
  input, select { border: 0 !important; appearance: none; -webkit-appearance: none; padding: 0; background: transparent !important; }
  td input.qty, td input.price { width: auto; }
  td select.unit, td select.rate { width: auto; }
  [contenteditable], [contenteditable]:hover { background: none !important; outline: none !important; }
  input[type="date"]::-webkit-calendar-picker-indicator { display: none; }
  .customer-vat input.warn { background: none; }
  .customer-vat input:placeholder-shown { display: none; }
  .discount-row { display: none; }
  tr, .card, .totals, .conditions { break-inside: avoid; }
}

/* ---------- Invoice list ---------- */
.list-page { max-width: 1000px; margin: 24px auto; padding: 0 20px; }
.list-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.list-head h1 { margin: 0; font-size: 22px; }
.btn-gold { padding: 9px 18px; border-radius: 8px; font-size: 13.5px; font-weight: 600; background: var(--gold-grad); color: var(--ink-900); text-decoration: none; }
.btn-gold:hover { filter: brightness(1.06); }
.list-search { width: 100%; box-sizing: border-box; margin-bottom: 14px; padding: 10px 12px; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.list-page .table-wrap { margin-top: 0; background: #fff; }
.list-table { width: 100%; border-collapse: collapse; }
.list-table td.num, .list-table th.num { text-align: right; white-space: nowrap; }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions a.open { color: var(--ink-700); font-weight: 600; font-size: 13px; margin-right: 10px; text-decoration: underline; cursor: pointer; }
.row-actions a.open:hover { color: var(--gold-deep); }
.list-empty { margin: 0; padding: 28px; text-align: center; color: var(--muted); }
.actions a.back { color: #e5e7ec; border: 1px solid var(--ink-700); padding: 9px 18px; border-radius: 8px; font-size: 13.5px; font-weight: 600; text-decoration: none; }
.actions a.back:hover { background: var(--ink-800); border-color: var(--gold); }
@media screen and (max-width: 760px) { .list-table th:nth-child(2), .list-table td:nth-child(2) { display: none; } }
