:root {
  --bg: #f5f4ef;
  --surface: #fffefb;
  --ink: #1d1f1e;
  --muted: #666a65;
  --line: #dcd9cf;
  --field: #ffffff;
  --accent: #14594a;
  --accent-ink: #ffffff;
  --accent-soft: #e3eee8;
  --danger: #a3321f;
  --danger-soft: #f8e6e1;
  --warn-soft: #f8eed2;
  --radius: 6px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131514;
    --surface: #1b1e1c;
    --ink: #e8eae5;
    --muted: #9a9f99;
    --line: #303532;
    --field: #141615;
    --accent: #72cdb3;
    --accent-ink: #0c1e19;
    --accent-soft: #1c2d27;
    --danger: #f0907d;
    --danger-soft: #36201c;
    --warn-soft: #342c16;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { color-scheme: light dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 28px; padding-bottom: 64px; }

a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

h1, h2 { margin: 0; }
h1 { font: 600 28px/1.2 var(--serif); letter-spacing: -0.01em; overflow-wrap: anywhere; }
h2 {
  font: 600 12px/1.3 var(--sans);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 14px;
}

.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.strong { font-weight: 600; }
.danger { color: var(--danger); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 56px; }
.brand { font: 600 19px/1 var(--serif); color: var(--ink); text-decoration: none; }
.topnav { display: flex; align-items: center; gap: 18px; }
.topnav form { margin: 0; }
.topnav a:not(.btn) { color: var(--ink); text-decoration: none; }
.topnav a:not(.btn):hover { text-decoration: underline; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: 500 14px/1 var(--sans);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { border-color: var(--accent); filter: brightness(1.1); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--surface); }
.btn-small { min-height: 32px; padding: 0 12px; }
.btn-block { display: flex; width: 100%; }
.link { padding: 0; border: 0; background: none; color: var(--muted); font: inherit; cursor: pointer; }
.link:hover { color: var(--ink); text-decoration: underline; }
.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: none;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { color: var(--danger); border-color: var(--line); }

/* Page furniture */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card + .card { margin-top: 16px; }
.card.empty { text-align: center; padding: 48px 20px; }
.card.empty h2 { font: 600 20px/1.3 var(--serif); letter-spacing: 0; text-transform: none; color: var(--ink); margin-bottom: 6px; }
.card.empty .actions { justify-content: center; margin-top: 18px; }
.narrow { max-width: 400px; margin: 48px auto 0; }
.narrow h1 { margin-bottom: 18px; font-size: 24px; }

.messages { list-style: none; margin: 0 0 20px; padding: 0; display: grid; gap: 8px; }
.message, .notice { margin: 0 0 16px; padding: 10px 14px; border-radius: var(--radius); background: var(--accent-soft); }
.message { margin: 0; }
.message-warning { background: var(--warn-soft); }
.message-error, .notice-error { background: var(--danger-soft); }

/* Fields */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); gap: 14px 16px; }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
.stack { display: grid; gap: 14px; align-content: start; }
.field { min-width: 0; }
.field label { display: block; margin-bottom: 4px; font-size: 13px; font-weight: 500; }
.field label::first-letter { text-transform: uppercase; }
.unit { color: var(--muted); font-weight: 400; }

input[type="text"], input[type="search"], input[type="password"], input[type="number"], input[type="date"], select, textarea {
  width: 100%;
  min-height: 38px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field);
  color: var(--ink);
  font: inherit;
}
textarea { resize: vertical; line-height: 1.4; }
input[type="number"] { font-variant-numeric: tabular-nums; text-align: right; }
input:hover, select:hover, textarea:hover { border-color: var(--muted); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; border-color: var(--accent); }
::placeholder { color: var(--muted); opacity: 0.75; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.hint, .error { margin: 4px 0 0; font-size: 13px; }
.hint { color: var(--muted); overflow-wrap: anywhere; }
.error { color: var(--danger); }

/* Editor and invoice page: content beside a sticky summary */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.editor-side { position: sticky; top: 16px; }
.side-actions { display: grid; gap: 8px; margin-top: 18px; }

/* Product rows */
.line { display: grid; grid-template-columns: minmax(0, 1fr) 130px 70px 120px 90px 36px; gap: 8px; align-items: start; margin-bottom: 8px; }
.line-head { margin-bottom: 4px; font-size: 13px; font-weight: 500; }
.line .field label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.line-error { grid-column: 1 / -1; }
.lines { margin-bottom: 12px; }

/* Summary */
.sum-lines { list-style: none; margin: 0 0 16px; padding: 0; }
.sum-lines li { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.sum-lines li > :first-child { min-width: 0; overflow-wrap: anywhere; }
.sum-lines li > :last-child { white-space: nowrap; }
.sum-lines .promo { color: var(--accent); }
.vat-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.vat-table th { font-weight: 500; color: var(--muted); }
.vat-table th, .vat-table td { padding: 4px 0 4px 8px; text-align: right; white-space: nowrap; }
.vat-table th:first-child, .vat-table td:first-child { padding-left: 0; text-align: left; }
.grand-total { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 14px 0 0; padding-top: 12px; border-top: 2px solid var(--ink); }
.grand-total strong { font-size: 22px; white-space: nowrap; }

/* Invoice list */
.search { display: flex; gap: 8px; flex: 0 1 380px; }
.invoice-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.invoice-table th, .invoice-table td { padding: 10px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.invoice-table th { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.invoice-table tbody tr:last-child td { border-bottom: 0; }
.invoice-table tbody tr:hover { background: var(--accent-soft); }
.invoice-table .num { text-align: right; white-space: nowrap; }
.cell-main a { font-weight: 600; overflow-wrap: anywhere; }
.cell-main .sub { display: block; color: var(--muted); font-size: 13px; }
.invoice-table .cell-actions { text-align: right; white-space: nowrap; }
.cell-actions a { margin-left: 12px; }
.list-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 20px; margin-top: 12px; font-size: 14px; }
.pager { display: flex; gap: 12px; }

/* Invoice page */
.pdf-frame { display: block; width: 100%; height: min(1100px, calc(100vh - 150px)); min-height: 480px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; overflow-wrap: anywhere; }
.record-links { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 16px; margin: 16px 0 0; padding-top: 14px; border-top: 1px solid var(--line); }

@media (max-width: 960px) {
  .editor { grid-template-columns: minmax(0, 1fr); }
  .editor-side { position: static; }
}

@media (max-width: 720px) {
  h1 { font-size: 24px; }
  .span-2 { grid-column: auto; }
  .topnav { gap: 12px; }
  .card { padding: 16px; }

  /* Each product becomes a small card with its own labels. */
  .line-head { display: none; }
  .line { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); position: relative; }
  .line .field label { position: static; width: auto; height: auto; clip-path: none; white-space: normal; }
  .line-desc { grid-column: 1 / -1; padding-right: 40px; }
  .line-asin { grid-column: 1 / -1; }
  .line-remove { position: absolute; top: 4px; right: 4px; }

  /* Each invoice becomes a card. */
  .invoice-table thead { display: none; }
  .invoice-table, .invoice-table tbody { display: block; border: 0; background: none; }
  .invoice-table tr { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 14px; margin-bottom: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
  .invoice-table td { padding: 0; border: 0; }
  .invoice-table td[data-label="Language"] { display: none; }
  .invoice-table td[data-label="Customer"] { grid-column: 1; grid-row: 2; }
  .invoice-table td[data-label="Total"] { grid-column: 2; grid-row: 1; }
  .invoice-table td[data-label="Date"] { grid-column: 2; grid-row: 2; color: var(--muted); }
  .invoice-table .cell-actions { grid-column: 1 / -1; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); text-align: left; }
  .cell-actions a { margin: 0 16px 0 0; }
  .pdf-frame { height: 70vh; }
}
