:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --text: #172033;
  --muted: #667085;
  --line: #d7dde8;
  --accent: #0b7fab;
  --accent-2: #0f9f7a;
  --danger: #c93c4a;
  --warn: #b7791f;
  --shadow: 0 10px 30px rgba(18, 31, 53, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); min-height: 100vh; }
button, input, textarea, select { font: inherit; }
button { border: 0; cursor: pointer; }
p { color: var(--muted); line-height: 1.5; }
h1, h2, h3 { margin: 0; }
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
input, textarea, select {
  width: 100%;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 11px;
  outline: none;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(11,127,171,.12); }

/* Układ z bocznym panelem (jak AMMS) */
.app-shell { display: grid; grid-template-columns: 270px 1fr; min-height: 100vh; }
.sidebar { background: #172033; color: #fff; padding: 22px; position: sticky; top: 0; height: 100vh; }
.sidebar p, .sidebar .muted { color: #aeb8ca; }
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.brand-logo { width: 124px; height: 78px; object-fit: contain; background: transparent; }
.brand-sub { color: #aeb8ca; font-size: 12px; line-height: 1.4; margin: 8px 0 18px; }
.nav { display: grid; gap: 6px; }
.nav button { display: flex; align-items: center; gap: 11px; text-align: left; background: transparent; color: #c4ccda; padding: 11px 12px; border-radius: 8px; font-weight: 600; transition: background .12s, color .12s; }
.nav button.active, .nav button:hover { color: #fff; background: rgba(255,255,255,.12); }
.nav button.active { box-shadow: inset 3px 0 0 var(--accent-2); }
.nav-ico { width: 19px; height: 19px; flex: none; opacity: .9; }
.nav-logout { display: block; width: 100%; margin-top: 18px; padding: 10px 12px; text-align: left;
  background: rgba(255,255,255,.06); color: #c4ccda; border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px; font-weight: 600; }
.nav-logout:hover { background: rgba(201,60,74,.22); color: #fff; border-color: rgba(201,60,74,.5); }
.sidebar-credit { margin-top: 22px; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.1); color: #8b95a7; font-size: 12px; }

.content { padding: 26px 28px 40px; max-width: 1280px; width: 100%; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.topbar h2 { font-size: 28px; }
.topbar p { margin: 6px 0 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }

.btn { background: var(--accent); color: #fff; padding: 9px 14px; border-radius: 8px; font-weight: 700; border: 1px solid transparent; }
.btn:hover { filter: brightness(1.05); }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn.danger { background: #fff3f4; color: var(--danger); border-color: #f0b9bf; }
.btn.ok { background: #eefbf6; color: #08765a; border-color: #b9e8d9; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card h3 { font-size: 17px; margin-bottom: 4px; }
.grid { display: grid; gap: 14px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.muted { color: var(--muted); }
.spacer { flex: 1; }

.table-wrap { overflow-x: auto; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); }
tr:hover td { background: #fbfcfe; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 800; border: 1px solid var(--line); background: #f5f7fb; color: var(--text); }
.badge.green { background: #ecfdf4; color: #087246; border-color: #a8dfc2; }
.badge.orange { background: #fff4ec; color: #9a4a11; border-color: #f3c4a4; }

/* Pozycje na fakturze (edytor) */
.items-table input, .items-table select { padding: 8px 9px; }
.items-table td { padding: 6px 8px; }
.line-del { background: #fff3f4; color: var(--danger); border: 1px solid #f0b9bf; border-radius: 8px; padding: 6px 9px; font-weight: 800; }

.catalog-pick { display: flex; gap: 10px; align-items: stretch; margin-bottom: 12px; }
.catalog-pick select { flex: 1; }
.catalog-pick .btn { white-space: nowrap; align-self: center; }

.vat-legend { margin-top: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.vat-legend summary { cursor: pointer; padding: 10px 12px; font-weight: 700; font-size: 13px; color: var(--accent); }
.vat-legend-body { padding: 4px 14px 14px; }
.vat-legend-row { display: grid; grid-template-columns: 56px 1fr; gap: 10px; align-items: start; padding: 6px 0; font-size: 13px; border-top: 1px dashed var(--line); }
.vat-legend-row .badge { justify-self: start; }

.totals-box { margin-top: 12px; margin-left: auto; max-width: 360px; }
.totals-box .row { display: flex; justify-content: space-between; padding: 6px 0; }
.totals-box .row.grand { border-top: 2px solid var(--text); margin-top: 6px; padding-top: 10px; font-size: 20px; font-weight: 800; }
.totals-box .row.grand span:last-child { color: var(--accent); }

.error { background: #fff0f1; color: #9f2a35; border: 1px solid #f1b8bf; border-radius: 8px; padding: 11px 13px; margin-bottom: 14px; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* ---------------- Wydruk faktury ---------------- */
.invoice-actions { display: flex; gap: 10px; margin-bottom: 16px; }
.invoice-sheet {
  background: #fff; color: #111; border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); padding: 40px 44px; max-width: 900px; margin: 0 auto;
}
.inv-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; border-bottom: 3px solid var(--accent); padding-bottom: 18px; }
.inv-head img { width: 150px; height: 92px; object-fit: contain; }
.inv-head .seller-name { font-size: 15px; font-weight: 800; max-width: 360px; }
.inv-head .seller-meta { font-size: 12.5px; color: #444; line-height: 1.6; margin-top: 4px; }
.inv-title { text-align: right; }
.inv-title h1 { font-size: 26px; letter-spacing: .5px; }
.inv-title .num { font-size: 15px; font-weight: 700; color: var(--accent); margin-top: 2px; }
.inv-title .dates { font-size: 12.5px; color: #444; margin-top: 8px; line-height: 1.7; }

.parties { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; margin: 22px 0; }
.party { border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; background: var(--surface-2); }
.party h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 8px; }
.party .pname { font-weight: 800; font-size: 14px; }
.party .pmeta { font-size: 13px; color: #333; line-height: 1.6; margin-top: 3px; }

table.inv-items { border: 1px solid var(--line); }
table.inv-items th { background: #172033; color: #fff; font-size: 11px; }
table.inv-items td, table.inv-items th { padding: 9px 11px; border-bottom: 1px solid var(--line); }
table.inv-items tfoot td { font-weight: 800; background: var(--surface-2); }

.inv-summary { display: flex; justify-content: space-between; gap: 24px; margin-top: 20px; align-items: flex-start; }
.inv-pay { font-size: 13px; line-height: 1.8; max-width: 380px; }
.inv-pay b { color: #111; }
.inv-grand { min-width: 280px; }
.inv-grand .row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 13.5px; }
.inv-grand .row.big { border-top: 2px solid #111; margin-top: 6px; padding-top: 10px; font-size: 19px; font-weight: 800; }
.inv-words { margin-top: 14px; font-size: 13px; }
.inv-words b { color: #111; }
.inv-notes { margin-top: 18px; font-size: 13px; white-space: pre-wrap; }
.inv-issuer { margin-top: 40px; padding-top: 14px; border-top: 1px solid var(--line); }
.inv-issuer .issuer-name { font-size: 14px; font-weight: 800; color: #111; }
.inv-issuer .issuer-role { font-size: 12px; color: var(--muted); margin-top: 2px; }
.inv-issuer .issuer-note { font-size: 11.5px; color: var(--muted); font-style: italic; margin-top: 10px; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .cols-2, .cols-3, .form-row, .form-row.three, .parties { grid-template-columns: 1fr; }
}

/* Druk / zapis do PDF — pokazujemy tylko arkusz faktury */
@media print {
  body { background: #fff; }
  .sidebar, .topbar, .invoice-actions, .no-print { display: none !important; }
  .app-shell { display: block; }
  .content { padding: 0; max-width: none; }
  .invoice-sheet { border: 0; box-shadow: none; border-radius: 0; padding: 0; max-width: none; }
  @page { size: A4; margin: 16mm; }
}
