:root {
  color-scheme: light;
  font-family: Inter, "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #162641;
  background: #f1f6fc;
  --muted: #485c79;
  --accent: #1859d1;
  --accent-dark: #1347aa;
  --line: #dce6f2;
  --tint: #eaf2ff;
  --amber: #d69429;
  --amber-tint: #fff3dc;
  --amber-ink: #71430d;
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
h1, h2, h3, p, dl, dd { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
h2[id] { scroll-margin-top: 115px; }

.topbar { position: sticky; top: 0; z-index: 2; border-bottom: 1px solid var(--line); background: #fff; }
.topbar-inner, .workspace { width: min(100% - 56px, 1400px); margin-inline: auto; }
.topbar-inner {
  min-height: 70px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  column-gap: clamp(14px, 2vw, 30px);
}
.brand { display: inline-flex; align-items: center; width: 110px; min-height: 40px; }
.brand img { display: block; width: 100%; height: auto; }
.toolbar-actions, .workspace-title, .workspace-actions, .save-status { display: flex; align-items: center; }
.toolbar-actions { gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.workspace { min-width: 0; padding-bottom: 36px; }
.workspace-actions { flex-wrap: wrap; gap: 10px; }
.save-status { gap: 7px; color: var(--muted); font-size: 12px; }
.save-status i { width: 7px; height: 7px; border-radius: 50%; background: #12835f; flex: none; }
.save-status[data-error] i { background: #ad3a25; }
.section-icon, .company-mark { display: inline-grid; place-items: center; flex: none; }
.button { display: inline-flex; min-height: 38px; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: 8px; padding: 8px 12px; font-size: 12px; font-weight: 750; white-space: nowrap; text-decoration: none; }
.button-outline { background: #fff; color: #283e5d; border-color: var(--line); }
.button-outline:hover { background: #f2f7ff; border-color: #aac5eb; }
.button-primary { background: var(--accent); color: #fff; box-shadow: 0 3px 8px #1b5ed82c; }
.button-primary:hover { background: var(--accent-dark); }
.new-invoice { color: var(--accent-dark); }
.archive-status { grid-column: 1 / -1; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.archive-status:not(:empty) { padding-bottom: 10px; }
.workspace-title { justify-content: space-between; gap: 12px; padding-block: 29px 23px; }
.workspace-title h1 { font-size: clamp(30px, 3.1vw, 43px); letter-spacing: -.06em; line-height: 1.1; }
.workspace-title p { margin-top: 7px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.jump-preview { display: none; }
.layout { display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); gap: 20px; align-items: start; }
#editor, .item-list, fieldset { display: grid; gap: 15px; min-width: 0; }
.card { border: 1px solid var(--line); border-radius: 13px; background: #fff; box-shadow: 0 2px 4px #142d5308; }
.card { padding: 20px; display: grid; gap: 17px; }
.card-header { display: flex; align-items: center; gap: 11px; padding-bottom: 13px; border-bottom: 1px solid var(--line); }
.section-icon { width: 37px; height: 37px; border-radius: 10px; color: var(--accent); background: var(--tint); }
.card h2, .preview-header h2 { font-size: 16px; letter-spacing: -.022em; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
label { display: grid; align-content: start; gap: 6px; min-width: 0; font-size: 12px; font-weight: 650; color: #324967; }
input, select, textarea { width: 100%; min-width: 0; padding: 9px 10px; min-height: 40px; border: 1px solid #d6e1ef; border-radius: 7px; color: #203450; background: #f9fbfe; font-size: 13px; font-weight: 450; }
input::placeholder, textarea::placeholder { color: #60738d; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline-offset: 1px; }
textarea { resize: vertical; }
fieldset { margin: 0; padding: 0; border: 0; gap: 11px; }
legend { padding: 0; margin-bottom: 9px; color: var(--accent-dark); font-size: 12px; font-weight: 750; }
.contact-grid { gap: 18px; }
.logo-option { display: flex; align-items: center; gap: 9px; min-height: 34px; }
.logo-option input { width: 16px; height: 16px; min-height: 0; margin: 0; accent-color: var(--accent); }
.item-row { grid-template-columns: minmax(0, 1.35fr) minmax(0, .55fr) minmax(0, 1fr) auto; gap: 8px; align-items: end; padding: 10px; border: 1px solid var(--line); border-radius: 9px; }
.item-row legend { margin: 0; padding-inline: 4px; }
.remove-item { display: grid; place-items: center; width: 33px; height: 40px; border: 1px solid var(--line); border-radius: 7px; color: #6c4151; background: #fff; font-size: 21px; }
.remove-item:hover:enabled { background: #fff1f2; }
.remove-item:disabled { opacity: .42; cursor: default; }
.add-item { justify-self: start; color: var(--accent-dark); }
.adjustments { border-top: 1px solid var(--line); padding-top: 15px; }
.preview { position: sticky; top: 115px; min-width: 0; border: 1px solid #ceddf0; border-radius: 14px; background: #e5eefb; }
.preview-header { display: flex; justify-content: space-between; align-items: center; gap: 9px; padding: 12px 15px; border-bottom: 1px solid #ceddf0; }
.preview-header h2 { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.preview-header h2 .icon { color: var(--accent); }
.preview-format { padding: 4px 8px; border: 1px solid #c8d8ef; border-radius: 6px; color: #3b5579; background: #f7fbff; font-size: 10px; font-weight: 750; }
.preview-stage {
  padding: clamp(12px, 2.2vw, 34px);
  border-radius: 0 0 13px 13px;
  background: radial-gradient(circle, #bbd0eb 1px, transparent 1px) 0 0 / 13px 13px, #e5eefb;
}
.invoice {
  position: relative;
  color: #1d304e;
  background: #fff;
  max-width: 740px;
  margin-inline: auto;
  padding: clamp(16px, 2.7vw, 40px);
  min-height: 495px;
  border: 1px solid #dce6f3;
  border-radius: 2px;
  box-shadow: 0 9px 28px #18375926;
  overflow-wrap: anywhere;
}
.invoice::before { content: ""; position: absolute; inset: 0 0 auto; height: 4px; background: linear-gradient(90deg, #15346d 0 72%, #2473e8 72% 92%, var(--amber) 92%); }
.invoice-heading, .invoice-company { display: flex; align-items: center; gap: 10px; }
.invoice-heading { justify-content: space-between; padding-bottom: 19px; border-bottom: 1px solid var(--line); }
.invoice-company { min-width: 0; font-size: 13px; }
.invoice-logo { display: block; width: clamp(88px, 10vw, 138px); max-width: 100%; height: auto; }
.company-mark { min-width: 37px; height: 37px; padding-inline: 5px; border-radius: 9px; color: #fff; background: var(--accent); font-size: 13px; font-weight: 800; }
.invoice-title { text-align: right; min-width: 0; }
.invoice-title h2 { color: #163466; font-family: Georgia, serif; font-weight: 500; font-size: clamp(23px, 3vw, 39px); letter-spacing: -.055em; }
.invoice-title p, .invoice-parties p, .invoice-footer p { margin-top: 3px; color: #4d607a; font-size: 11px; line-height: 1.5; white-space: pre-wrap; }
.invoice-parties, .invoice-dates { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.invoice-parties { margin-block: 25px 19px; }
.invoice h3, .invoice-dates dt { margin-bottom: 4px; color: #496185; font-size: 9px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; }
.invoice-parties strong, .invoice-dates dd { font-size: 12px; font-weight: 700; }
.invoice-dates { padding: 11px 12px; margin-bottom: 17px; background: #eff5fd; border-radius: 6px; }
.invoice-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 11px; font-variant-numeric: tabular-nums; }
.invoice-table th { background: #15346d; color: #fff; font-size: 10px; }
.invoice-table th:first-child { width: 38%; border-radius: 5px 0 0 5px; }
.invoice-table th:nth-child(2) { width: 11%; }
.invoice-table th:last-child { border-radius: 0 5px 5px 0; }
.invoice-table th, .invoice-table td { padding: 9px 6px; text-align: right; vertical-align: top; }
.invoice-table th:first-child, .invoice-table td:first-child { text-align: left; padding-left: 9px; }
.invoice-table th:last-child, .invoice-table td:last-child { padding-right: 9px; }
.invoice-table td { border-bottom: 1px solid #e0e9f5; }
.invoice-table .empty-items { color: var(--muted); }
.invoice-totals { width: min(100%, 248px); margin: 13px 0 0 auto; font-size: 11px; }
.invoice-totals > div { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 5px 9px; }
.invoice-totals dd { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.invoice-totals .grand-total { margin-top: 6px; background: var(--amber-tint); border-top: 2px solid var(--amber); border-radius: 0; padding: 11px 10px; color: var(--amber-ink); font-weight: 800; }
.grand-total dd { font-size: 15px; font-weight: 800; }
.invoice-footer { display: grid; gap: 10px; }
.invoice-footer:has(> :not([hidden])) { margin-top: 17px; border-top: 1px solid var(--line); padding-top: 12px; }
.invoice-history { margin-top: 24px; }
.history-status { color: var(--muted); font-size: 13px; }
.history-status:empty { margin-top: -17px; }
.history-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.history-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, .8fr) auto; align-items: center; gap: 14px; padding: 12px; border: 1px solid var(--line); border-radius: 9px; }
.history-details { display: grid; gap: 4px; overflow-wrap: anywhere; font-size: 13px; }
.history-details span, .history-date { color: var(--muted); font-size: 12px; }
.history-total { font-variant-numeric: tabular-nums; }
.history-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.icon { display: inline-block; position: relative; width: 16px; height: 16px; flex: none; }
.icon-file { width: 12px; height: 15px; border: 1.5px solid currentColor; border-radius: 2px; }
.icon-file::after { content: ""; position: absolute; top: 5px; left: 2px; width: 5px; height: 1px; background: currentColor; box-shadow: 0 3px currentColor; }
.icon-download { border: 1.5px solid currentColor; border-width: 0 1.5px 1.5px; border-radius: 0 0 3px 3px; height: 7px; margin-top: 7px; }
.icon-download::before { content: ""; position: absolute; left: 6px; top: -7px; width: 1.5px; height: 9px; background: currentColor; }
.icon-download::after { content: ""; position: absolute; left: 4px; top: -3px; width: 6px; height: 6px; border: 1.5px solid currentColor; border-width: 0 1.5px 1.5px 0; transform: rotate(45deg); }
.icon-people::before { content: ""; position: absolute; top: 0; left: 5px; width: 6px; height: 6px; border: 1.5px solid currentColor; border-radius: 50%; }
.icon-people::after { content: ""; position: absolute; inset: 8px 1px 1px; border: 1.5px solid currentColor; border-radius: 7px 7px 2px 2px; }
.icon-list::before, .icon-list::after { content: ""; position: absolute; top: 3px; height: 2px; background: currentColor; border-radius: 4px; box-shadow: 0 4px currentColor, 0 8px currentColor; }
.icon-list::before { left: 1px; width: 2px; }
.icon-list::after { left: 5px; width: 10px; }
.icon-folder { height: 11px; margin-top: 3px; border: 1.5px solid currentColor; border-radius: 2px; }
.icon-folder::before { content: ""; position: absolute; top: -4px; left: -1.5px; width: 7px; height: 4px; border: 1.5px solid currentColor; border-bottom: 0; border-radius: 2px 2px 0 0; }
.icon-note { border: 1.5px solid currentColor; border-radius: 3px 3px 6px 3px; }
.icon-note::after { content: ""; position: absolute; top: 4px; left: 3px; width: 7px; height: 1px; background: currentColor; box-shadow: 0 3px currentColor; }
@media (max-width: 1170px) {
  .card { padding: 15px; }
  .layout { gap: 14px; }
}
@media (max-width: 800px) {
  .topbar { position: static; }
  .topbar-inner, .workspace { width: calc(100% - 36px); }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .preview { position: static; }
  .jump-preview { display: inline-flex; }
  .workspace-title { flex-wrap: wrap; }
  h2[id] { scroll-margin-top: 14px; }
}
@media (max-width: 560px) {
  .topbar-inner { grid-template-columns: minmax(0, 1fr); row-gap: 5px; padding-top: 6px; }
  .brand { width: 96px; }
  .toolbar-actions { justify-content: flex-start; padding-bottom: 8px; }
  .toolbar-actions .button { padding-inline: 8px; }
  .history-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .history-actions { grid-column: 1 / -1; }
}
@media (max-width: 440px) {
  .topbar-inner, .workspace { width: calc(100% - 28px); }
  .contact-grid { grid-template-columns: minmax(0, 1fr); }
  .item-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; }
  .item-description { grid-column: 1 / -1; }
  .invoice-table th, .invoice-table td { padding-inline: 3px; }
}
@page { size: A4; margin: 13mm; }
@media print {
  :root { background: #fff; }
  body { display: block; }
  .topbar, .workspace-title, #editor, .preview-header, .invoice-history { display: none !important; }
  .workspace, .layout, .preview, .preview-stage, .invoice { display: block; position: static; width: auto; max-width: none; margin: 0; padding: 0; border: 0; border-radius: 0; background: #fff; box-shadow: none; min-height: 0; }
  .invoice { position: relative; padding-top: 7mm; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .invoice-title h2 { font-size: 32px; }
  .invoice-logo { width: 35mm; }
  .invoice-heading, .invoice-parties, .invoice-dates, .invoice-table tr, .invoice-totals, .invoice-footer > div { break-inside: avoid; }
}
