:root {
  --page: #f4f5f7;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #18202b;
  --muted: #667085;
  --line: #dfe3e8;
  --brand: #be3a2d;
  --brand-dark: #94291f;
  --brand-soft: #fff1ef;
  --ok: #137a4b;
  --ok-soft: #eaf8f1;
  --warning: #9a6500;
  --warning-soft: #fff7df;
  --error: #b42318;
  --error-soft: #fff0ef;
  --shadow: 0 16px 45px rgba(16, 24, 40, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--page);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 48px 0 64px;
}

.hero {
  padding: 42px;
  border-radius: 24px;
  background: linear-gradient(135deg, #271b1a 0%, #662d27 65%, #92382e 100%);
  color: white;
  box-shadow: var(--shadow);
}

.hero__eyebrow {
  display: inline-flex;
  padding: 5px 10px;
  border: 1px solid rgba(255,255,255,.24);
  border-radius: 999px;
  color: rgba(255,255,255,.84);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 14px 0 10px;
  max-width: 760px;
  font-size: clamp(2rem, 5vw, 3.5rem);
  line-height: 1.05;
  letter-spacing: -.035em;
}

.hero__lead {
  max-width: 760px;
  margin: 0;
  color: rgba(255,255,255,.83);
  font-size: 1.08rem;
}

.privacy-pill {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  margin-top: 22px;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255,255,255,.12);
  color: rgba(255,255,255,.92);
  font-size: .9rem;
}

.upload-card,
.results,
.info-grid article {
  background: var(--surface);
  border: 1px solid rgba(16, 24, 40, 0.07);
  box-shadow: var(--shadow);
}

.upload-card {
  margin-top: 24px;
  padding: 28px;
  border-radius: var(--radius);
}

.upload-card__intro h2,
.info-grid h2 { margin: 0 0 5px; }
.upload-card__intro p,
.info-grid p { margin: 0; color: var(--muted); }

.drop-zone {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 20px;
  align-items: center;
  margin-top: 20px;
  padding: 24px;
  border: 2px dashed #c9ced6;
  border-radius: 16px;
  background: var(--surface-soft);
  transition: .18s ease;
}

.drop-zone:hover,
.drop-zone:focus-visible,
.drop-zone.is-dragover {
  border-color: var(--brand);
  background: var(--brand-soft);
  outline: none;
}

.drop-zone__icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--brand);
  font-weight: 900;
  letter-spacing: -.03em;
}

.drop-zone__title { margin: 0; font-weight: 800; font-size: 1.04rem; }
.drop-zone__help { margin: 2px 0 0; color: var(--muted); font-size: .93rem; }

.button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 42px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-weight: 800;
  transition: .16s ease;
}

.button:hover { transform: translateY(-1px); }
.button:focus-visible, .tab:focus-visible, .filter-chip:focus-visible {
  outline: 3px solid rgba(190,58,45,.22);
  outline-offset: 2px;
}
.button--primary { background: var(--brand); color: white; }
.button--primary:hover { background: var(--brand-dark); }
.button--ghost { background: white; border-color: var(--line); color: var(--ink); }
.button--ghost:hover { border-color: #aab1bb; }

.upload-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.message {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.message--error { background: var(--error-soft); border-color: #f5b7b1; color: var(--error); }
.message--success { background: var(--ok-soft); border-color: #a9dec5; color: var(--ok); }

.results {
  margin-top: 24px;
  border-radius: var(--radius);
  overflow: hidden;
}

.result-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 24px 28px;
  border-bottom: 1px solid var(--line);
}
.result-toolbar__label { margin: 0; color: var(--muted); font-size: .82rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.result-toolbar h2 { margin: 2px 0; font-size: 1.2rem; word-break: break-word; }
.result-toolbar__meta { margin: 0; color: var(--muted); font-size: .9rem; }
.result-toolbar__actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
  overflow-x: auto;
}

.tab {
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  padding: 15px 14px 12px;
  color: var(--muted);
  font-weight: 800;
  white-space: nowrap;
}
.tab.is-active { color: var(--brand); border-bottom-color: var(--brand); }
.tab__badge {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  margin-left: 4px;
  padding: 0 6px;
  border-radius: 999px;
  background: #e8eaee;
  color: var(--ink);
  font-size: .74rem;
}

.tab-panel { padding: 28px; }
.invoice-switcher {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--surface-soft);
}
.invoice-switcher label { font-weight: 800; }
.invoice-switcher select { min-width: 240px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: white; }

.invoice-paper {
  max-width: 980px;
  margin: 0 auto;
  padding: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: 0 8px 25px rgba(16, 24, 40, .07);
}

.invoice-head {
  display: flex;
  justify-content: space-between;
  gap: 28px;
  padding-bottom: 24px;
  border-bottom: 3px solid var(--ink);
}
.invoice-title { margin: 0; font-size: 2rem; letter-spacing: -.035em; }
.invoice-subtitle { margin: 4px 0 0; color: var(--muted); }
.invoice-doc-meta { display: grid; grid-template-columns: auto auto; gap: 5px 18px; text-align: right; }
.invoice-doc-meta dt { color: var(--muted); }
.invoice-doc-meta dd { margin: 0; font-weight: 800; }

.party-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin: 26px 0;
}
.party-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-soft);
}
.party-card__label { margin: 0 0 10px; color: var(--brand); text-transform: uppercase; letter-spacing: .06em; font-size: .76rem; font-weight: 900; }
.party-card h3 { margin: 0 0 5px; }
.party-card p { margin: 2px 0; color: #3b4350; }

.invoice-section { margin-top: 28px; }
.invoice-section h3 { margin: 0 0 10px; font-size: 1.02rem; }
.table-wrap { overflow-x: auto; }
.invoice-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.invoice-table th { padding: 10px 8px; border-bottom: 2px solid var(--ink); text-align: left; color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; }
.invoice-table td { padding: 11px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.invoice-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.line-description { min-width: 260px; }
.line-extra { margin-top: 4px; color: var(--muted); font-size: .8rem; }

.totals-layout { display: grid; grid-template-columns: 1fr minmax(300px, 390px); gap: 28px; align-items: start; }
.notes-box { min-height: 120px; padding: 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-soft); }
.notes-box p { margin: 0 0 8px; }
.totals-box { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.total-row { display: flex; justify-content: space-between; gap: 20px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.total-row:last-child { border-bottom: 0; }
.total-row strong:last-child { font-variant-numeric: tabular-nums; }
.total-row--grand { padding: 15px 14px; background: var(--ink); color: white; font-size: 1.05rem; }
.total-row--muted { color: var(--muted); }

.payment-card { padding: 16px; border: 1px solid var(--line); border-radius: 10px; }
.payment-card + .payment-card { margin-top: 10px; }
.payment-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 18px; }
.payment-grid div span { display: block; color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; }
.payment-grid div strong { display: block; margin-top: 2px; }

.empty-value { color: #98a2b3; font-style: italic; }

.check-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.summary-card { padding: 16px; border: 1px solid var(--line); border-radius: 12px; }
.summary-card span { display: block; color: var(--muted); font-size: .8rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.summary-card strong { display: block; margin-top: 4px; font-size: 1.65rem; }
.summary-card--error { background: var(--error-soft); }
.summary-card--warning { background: var(--warning-soft); }
.summary-card--ok { background: var(--ok-soft); }

.check-filter { display: flex; gap: 8px; flex-wrap: wrap; margin: 18px 0; }
.filter-chip { border: 1px solid var(--line); border-radius: 999px; padding: 7px 12px; background: white; color: var(--muted); font-weight: 800; }
.filter-chip.is-active { border-color: var(--ink); color: var(--ink); background: var(--surface-soft); }

.check-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.check-item + .check-item { margin-top: 10px; }
.check-item__icon { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; font-weight: 900; }
.check-item--error .check-item__icon { background: var(--error-soft); color: var(--error); }
.check-item--warning .check-item__icon { background: var(--warning-soft); color: var(--warning); }
.check-item--ok .check-item__icon { background: var(--ok-soft); color: var(--ok); }
.check-item h3 { margin: 0; font-size: .98rem; }
.check-item p { margin: 3px 0 0; color: var(--muted); }
.check-item code { font-size: .84em; }

.validation-note { margin-top: 20px; padding: 14px 16px; border-left: 4px solid var(--warning); background: var(--warning-soft); }

.xml-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.xml-toolbar label { font-weight: 800; }
.xml-toolbar input { flex: 1; max-width: 520px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; }
.xml-search-count { color: var(--muted); font-size: .88rem; }
.xml-raw { max-height: 650px; margin: 0; padding: 20px; overflow: auto; border-radius: 10px; background: #151a22; color: #e5e7eb; font: 13px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
.xml-raw mark { background: #ffdb70; color: #151a22; }

.info-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 24px;
}
.info-grid article { padding: 22px; border-radius: 14px; }
.info-grid h2 { font-size: 1rem; }

@media (max-width: 820px) {
  .app-shell { width: min(100% - 20px, 1180px); padding-top: 20px; }
  .hero { padding: 28px 22px; }
  .upload-card, .tab-panel { padding: 20px; }
  .drop-zone { grid-template-columns: 1fr; text-align: center; justify-items: center; }
  .result-toolbar { align-items: flex-start; flex-direction: column; padding: 20px; }
  .result-toolbar__actions { justify-content: flex-start; }
  .invoice-paper { padding: 24px 18px; }
  .invoice-head { flex-direction: column; }
  .invoice-doc-meta { text-align: left; }
  .party-grid, .totals-layout, .info-grid { grid-template-columns: 1fr; }
  .payment-grid { grid-template-columns: 1fr 1fr; }
  .check-summary { grid-template-columns: 1fr; }
  .xml-toolbar { align-items: stretch; flex-direction: column; }
}

@media (max-width: 520px) {
  .privacy-pill { align-items: flex-start; border-radius: 12px; }
  .upload-actions, .result-toolbar__actions { flex-direction: column; width: 100%; }
  .button { width: 100%; }
  .invoice-switcher { align-items: stretch; flex-direction: column; }
  .invoice-switcher select { min-width: 0; width: 100%; }
  .payment-grid { grid-template-columns: 1fr; }
}

@media print {
  body { background: white; }
  .hero, .upload-card, .result-toolbar, .tabs, .invoice-switcher, .info-grid, #checksPanel, #xmlPanel { display: none !important; }
  .app-shell, .results, .tab-panel { width: 100%; margin: 0; padding: 0; border: 0; box-shadow: none; }
  #results, #previewPanel { display: block !important; }
  .invoice-paper { max-width: none; padding: 0; border: 0; box-shadow: none; }
  @page { size: A4; margin: 14mm; }
}
