:root {
  --accent: #f0b400;
  --accent-dark: #c79400;
  --accent-soft: #fdf3d7;
  --ink: #1f2430;
  --ink-soft: #5b6472;
  --bg: #f4f5f7;
  --card: #ffffff;
  --line: #e3e6ea;
  --good: #1a7f4b;
  --bad: #c0392b;
  --warn: #a86f00;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 25, 35, .08), 0 4px 14px rgba(20, 25, 35, .05);
  font-size: 15px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

/* ---------- header ---------- */
.app-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 20px;
  background: var(--ink);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 40;
}

.logo {
  width: 40px;
  height: 40px;
  border-radius: 9px;
  background: var(--accent);
  color: #111;
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: .5px;
  font-size: 14px;
  flex: none;
}

.app-title { line-height: 1.15; }
.app-title b { font-size: 1.05rem; }
.app-title small { display: block; color: #cdd3dc; font-size: .72rem; }

nav.tabs { margin-left: auto; display: flex; gap: 6px; }
nav.tabs a {
  color: #cdd3dc;
  padding: 9px 14px;
  border-radius: 8px;
  font-size: .95rem;
  text-decoration: none;
}
nav.tabs a:hover { background: rgba(255,255,255,.08); color: #fff; }
nav.tabs a.active { background: var(--accent); color: #111; font-weight: 700; }

/* ---------- layout ---------- */
/* sized so every table fits a 1080p viewport (incl. 125% Windows scaling)
   without sideways scrolling */
main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 22px 20px 80px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 18px;
}

.card h2 { margin: 0 0 12px; font-size: 1.15rem; }
.card h3 { margin: 18px 0 8px; font-size: .95rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .4px; }

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.grow { flex: 1; }
.muted { color: var(--ink-soft); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- forms ---------- */
label.field { display: block; font-size: .8rem; color: var(--ink-soft); margin-bottom: 10px; }
label.field > span { display: block; margin-bottom: 4px; font-weight: 600; }

input, select, textarea {
  font: inherit;
  color: inherit;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
input[type="checkbox"] { width: auto; }
input.num { text-align: right; }
input:disabled, textarea:disabled { background: var(--bg); color: var(--ink-soft); }

button {
  font: inherit;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
  background: #e8eaee;
  color: var(--ink);
  font-weight: 600;
}
button:hover { filter: brightness(.97); }
button.primary { background: var(--accent); color: #111; }
button.primary:hover { background: var(--accent-dark); }
button.danger { background: #fbeae8; color: var(--bad); }
button.ghost { background: transparent; border: 1px solid var(--line); }
button:disabled { opacity: .5; cursor: default; }

/* ---------- tables ---------- */
table.grid { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.grid th, table.grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.grid th { font-size: .75rem; text-transform: uppercase; letter-spacing: .4px; color: var(--ink-soft); }
table.grid tr.click { cursor: pointer; }
table.grid tr.click:hover { background: var(--accent-soft); }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid input { padding: 5px 8px; }
table.grid.compact th, table.grid.compact td { padding: 6px 7px; }
table.grid.compact { font-size: .87rem; }
table.grid a { color: inherit; }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: .75rem; font-weight: 700; }
.badge.pending { background: var(--accent-soft); color: var(--warn); }
.badge.approved { background: #e2f4ea; color: var(--good); }
.badge.discarded { background: #f0f1f4; color: var(--ink-soft); text-decoration: line-through; }
.badge.tax { background: #e7edfb; color: #2b4ea2; }
.badge.proforma { background: #f3e9fb; color: #7a3ba2; }
.badge.open { background: #e2f4ea; color: var(--good); }
.badge.done { background: #f0f1f4; color: var(--ink-soft); }

/* ---------- misc ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--ink);
  color: #fff;
  padding: 11px 22px;
  border-radius: 24px;
  font-size: .9rem;
  opacity: 0;
  transition: all .25s;
  z-index: 100;
  max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.error { background: var(--bad); }

.empty { text-align: center; color: var(--ink-soft); padding: 40px 0; }
.spinner { text-align: center; color: var(--ink-soft); padding: 40px 0; }

.drop {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 44px 20px;
  text-align: center;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all .15s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }

/* ---------- invoice sheet (screen preview + print) ---------- */
.sheet-preview {
  max-width: 900px;
  margin: 0 auto 18px;
  box-shadow: var(--shadow);
}

.sheet {
  position: relative;
  background: #fff;
  color: #111;
  border: 1.5px solid #111;
  padding: 20px 22px;
  font-size: 12.5px;
  line-height: 1.35;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.sheet .watermark {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 90px;
  font-weight: 800;
  color: rgba(192, 57, 43, .15);
  transform: rotate(-24deg);
  pointer-events: none;
  z-index: 1;
}

.sheet-head {
  display: flex;
  gap: 14px;
  align-items: center;
  border-bottom: 1.5px solid #111;
  padding-bottom: 10px;
}
.sheet-logo {
  width: 58px;
  height: 58px;
  background: #f0b400;
  color: #111;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 21px;
  letter-spacing: 1px;
  flex: none;
}
.sheet-title { flex: 1; text-align: center; }
.sheet-title .doc-type { font-weight: 700; font-size: 14px; letter-spacing: .5px; }
.sheet-title .co-name { font-weight: 800; font-size: 18px; letter-spacing: .5px; }
.sheet-title .co-addr { font-size: 11.5px; }
.copies { font-size: 8.5px; border: 1px solid #111; }
.copies div { padding: 2px 6px; border-bottom: 1px solid #111; }
.copies div:last-child { border-bottom: none; }

.sheet-meta { display: flex; border: 1px solid #111; border-top: none; }
.sheet-meta .meta-left { width: 38%; padding: 8px 10px; border-right: 1px solid #111; }
.sheet-meta .meta-right { flex: 1; padding: 8px 10px; }
.meta-left div { display: flex; gap: 6px; margin-bottom: 2px; }
.meta-left span { width: 105px; color: #444; font-size: 11px; text-transform: uppercase; }
.meta-right span { color: #444; font-size: 11px; text-transform: uppercase; }
.buyer-label { font-weight: 700; font-size: 11px; text-transform: uppercase; text-decoration: underline; margin-bottom: 2px; }
.buyer-name { font-weight: 700; }
.buyer-addr { margin-bottom: 3px; }

table.sheet-items {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid #111;
  border-top: none;
}
.sheet-items th, .sheet-items td {
  border-left: 1px solid #111;
  padding: 3px 6px;
  vertical-align: top;
}
.sheet-items th:first-child, .sheet-items td:first-child { border-left: none; }
.sheet-items thead th { border-bottom: 1px solid #111; font-size: 10.5px; text-transform: uppercase; }
.sheet-items thead tr.sub th { border-bottom: 1.5px solid #111; font-size: 9.5px; padding: 1px 6px; }
.sheet-items .desc { width: 34%; }
.sheet-items td.c, .sheet-items th { text-align: center; }
.sheet-items td.n { text-align: right; font-variant-numeric: tabular-nums; }
.sheet-items td:nth-child(4) { text-align: left; }
.sheet-items tr.blank td { height: 20px; }
.sheet-items tr.pf td { border-top: 1px solid #111; font-weight: 600; }

.sheet-totals { display: flex; border: 1px solid #111; border-top: none; }
.words-block { flex: 1; padding: 8px 10px; border-right: 1px solid #111; }
.words-block > div { margin-bottom: 6px; }
.words-block span { display: block; color: #444; font-size: 10px; text-transform: uppercase; }
.totals-table { width: 265px; border-collapse: collapse; }
.totals-table td { padding: 4px 8px; border-bottom: 1px solid #111; }
.totals-table td.n { text-align: right; font-variant-numeric: tabular-nums; }
.totals-table tr.grand td { font-weight: 800; font-size: 14px; border-bottom: none; }

.sheet-sign {
  border: 1px solid #111;
  border-top: none;
  padding: 8px 12px;
  text-align: right;
}
.sheet-sign .sig-space { height: 52px; }

/* print area is only visible when printing */
#print-area { display: none; }

@media print {
  @page { size: A4; margin: 9mm; }
  body { background: #fff; }
  .app-header, main, .toast { display: none !important; }
  #print-area { display: block; }
  #print-area .sheet { border-width: 1.5px; }
  .sheet .watermark { color: rgba(192, 57, 43, .18); -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sheet-logo { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
