* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: #eee;
  color: #222;
}

body {
  padding: 0 24px;
}

@media (max-width: 900px) {
  body { padding: 0 8px; }
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #1f3a5f;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  flex-wrap: wrap;
  gap: 10px;
}
.toolbar h1 { margin: 0; font-size: 20px; letter-spacing: 1px; }
.toolbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.toolbar button, .file-label {
  background: #fff;
  color: #1f3a5f;
  border: none;
  padding: 8px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}
.toolbar button:hover, .file-label:hover { background: #e6edf5; }

.invoice {
.invoice {
  background:
    repeating-linear-gradient(
      to bottom,
      #fff 0,
      #fff calc(297mm - 1px),
      #c0c0c0 calc(297mm - 1px),
      #c0c0c0 297mm,
      #eee 297mm,
      #eee calc(297mm + 16px),
      #fff calc(297mm + 16px)
    );
  background-size: 100% calc(297mm + 16px);
  width: 210mm;
  min-height: 297mm;
  margin: 20px auto;
  padding: 20mm;
  box-shadow: 0 4px 14px rgba(0,0,0,0.15);
  font-size: 12px;
  line-height: 1.45;
  box-sizing: border-box;
}

.lines table tr,
.lines table thead,
.totals,
.notes,
.invoice-footer .seller-footer {
  break-inside: avoid;
  page-break-inside: avoid;
}
.lines table thead { display: table-header-group; }

[contenteditable="true"] {
  outline: none;
  border-radius: 2px;
  transition: background 0.15s;
}
[contenteditable="true"]:hover { background: #fffbe5; }
[contenteditable="true"]:focus { background: #fff3a8; }

.header-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 30px;
  margin-bottom: 30px;
}
.seller h2 {
  margin: 0 0 14px;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #1f3a5f;
  line-height: 1.1;
}
.seller .fskatt { margin-top: 8px; font-style: italic; }

.title-block { text-align: right; }
.big-title {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 4px;
  color: #1f3a5f;
  margin-bottom: 12px;
}
.meta { width: 100%; border-collapse: collapse; }
.meta th, .meta td {
  text-align: left;
  padding: 4px 6px;
  border-bottom: 1px solid #eee;
  font-weight: normal;
  font-size: 12px;
}
.meta th { color: #555; width: 45%; }

.customer {
  border: 1px solid #ddd;
  padding: 10px 14px;
  margin-bottom: 20px;
  background: #fafafa;
  border-radius: 3px;
}
.customer h3 { margin: 0 0 6px; font-size: 13px; color: #555; text-transform: uppercase; letter-spacing: 1px; }

.lines table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 14px;
}
.lines th {
  background: #1f3a5f;
  color: #fff;
  text-align: left;
  padding: 8px;
  font-size: 12px;
}
.lines td {
  border-bottom: 1px solid #e5e5e5;
  padding: 6px 8px;
  vertical-align: top;
}
.lines td[contenteditable="true"] { min-height: 18px; }
.col-qty, .col-price, .col-vat, .col-sum { width: 90px; text-align: right; }
.col-unit { width: 60px; }
.col-act { width: 30px; }
.lines td.col-qty, .lines td.col-price, .lines td.col-sum { text-align: right; }
.lines td.col-vat { text-align: right; }
.del-btn {
  background: #c0392b;
  color: #fff;
  border: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
}

.totals { display: flex; justify-content: flex-end; margin-bottom: 20px; }
.totals table { border-collapse: collapse; min-width: 280px; }
.totals th, .totals td {
  padding: 6px 10px;
  text-align: right;
  font-weight: normal;
}
.totals th { color: #444; }
.totals tr.grand th, .totals tr.grand td {
  border-top: 2px solid #1f3a5f;
  font-weight: 700;
  font-size: 14px;
  color: #1f3a5f;
  padding-top: 10px;
}

.notes { margin-bottom: 20px; }
.notes h3 { margin: 0 0 6px; font-size: 13px; color: #555; text-transform: uppercase; letter-spacing: 1px; }
.notes-area { min-height: 40px; border: 1px dashed #ddd; padding: 8px; border-radius: 3px; }

.invoice-footer {
  border-top: 1px solid #ddd;
  padding-top: 12px;
  margin-top: 30px;
  font-size: 11px;
  color: #555;
}
.seller-footer {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 12px;
}
.seller-col strong {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #1f3a5f;
  margin-bottom: 4px;
}
.seller-col .fskatt { font-style: italic; margin-top: 4px; }
.seller-footer-name { font-weight: 700; color: #1f3a5f; margin-bottom: 2px; }
.invoice-footer > [data-field="footer"] {
  text-align: center;
  border-top: 1px solid #eee;
  padding-top: 6px;
  font-size: 10px;
  color: #888;
}

@page { size: A4; margin: 15mm; }

@media print {
  body { background: #fff; padding: 0; }
  .no-print { display: none !important; }
  .invoice {
    box-shadow: none;
    margin: 0;
    width: auto;
    padding: 0;
    background: #fff;
    min-height: 0;
  }
  [contenteditable="true"]:hover, [contenteditable="true"]:focus { background: transparent; }
  tr, .totals, .notes, .invoice-footer .seller-footer { page-break-inside: avoid; }
  thead { display: table-header-group; }
  tfoot { display: table-footer-group; }
}
