:root {
  --bg: #f3f0ea;
  --paper: #ffffff;
  --ink: #161616;
  --muted: #6d6a64;
  --line: #ddd8ce;
  --sidebar: #141414;
  --sidebar-text: #f4f1ea;
  --accent: #b0894d;
  --danger: #9b2c2c;
  --shadow: 0 18px 50px rgba(20, 20, 20, 0.08);
  font-family: "Avenir Next", "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { color: var(--ink); background: var(--bg); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2 { margin: 0; font-weight: 600; letter-spacing: -0.03em; }
p { margin: 0; }

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at top, rgba(176, 137, 77, 0.16), transparent 28%),
    #111;
  color: #f7f4ee;
}
.auth-card {
  width: min(440px, calc(100vw - 32px));
  background: #1b1b1b;
  border: 1px solid #2a2a2a;
  padding: 36px 32px;
  box-shadow: 0 24px 80px rgba(0,0,0,.35);
}
.auth-kicker {
  text-transform: uppercase;
  letter-spacing: 0.22em;
  font-size: 11px;
  color: var(--accent);
  margin-bottom: 10px;
}
.auth-lead { color: #bdb7ad; margin: 10px 0 24px; line-height: 1.45; }
.auth-lead strong { color: #f7f4ee; font-weight: 600; }
.auth-alt { margin-top: 18px; font-size: 13px; }
.auth-alt a { color: var(--accent); }
.auth-form button {
  background: #f4f1ea;
  color: #111;
  font-weight: 600;
  padding: 12px;
  border: 0;
  border-radius: 8px;
}
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.auth-form label { color: #cfc9bf; }
input, select, textarea {
  border: 1px solid var(--line);
  background: #fff;
  padding: 10px 12px;
  border-radius: 8px;
}
.auth-form input {
  background: #111;
  border-color: #333;
  color: #fff;
}
.form-error { color: #e8b4b4; font-size: 13px; }
.app-body .form-error { color: var(--danger); }

.app-body { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--accent); color: #111; font-weight: 700;
}
.brand small { display: block; color: #a8a49c; font-size: 12px; }
.company-switch { color: #bdb7ad; }
.company-switch select {
  margin-top: 6px;
  background: #1d1d1d;
  color: #fff;
  border-color: #333;
  width: 100%;
  font-size: 13px;
}
nav { display: grid; gap: 6px; }
.nav-btn, .logout, .ghost, .primary {
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  text-align: left;
}
.nav-btn { background: transparent; color: #d7d2c8; }
.nav-btn.is-active, .nav-btn:hover { background: #222; color: #fff; }
.logout {
  margin-top: auto;
  background: transparent;
  color: #a8a49c;
  border: 1px solid #333;
}
.main { padding: 32px 36px 48px; overflow: auto; }
.view-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 22px;
}
.view-header p { color: var(--muted); margin-top: 6px; }
.header-actions { display: flex; gap: 8px; }
.primary { background: var(--ink); color: #fff; }
.ghost { background: transparent; border: 1px solid var(--line); }
.compact { padding: 8px 10px; white-space: nowrap; }
.search { width: 100%; margin-bottom: 16px; }
.table-wrap {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: auto;
  box-shadow: var(--shadow);
}
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); font-size: 14px; }
.data-table th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .empty { color: var(--muted); text-align: center; padding: 36px; }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; }
.linkish { background: none; border: 0; padding: 0; color: #3d3d3d; text-decoration: underline; text-underline-offset: 3px; }

.editor-grid {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  gap: 24px;
  align-items: start;
}
.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.split { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; }
.split label { min-width: 0; }
.lines-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); }
.line-row { display: grid; grid-template-columns: 1fr 110px 32px; gap: 8px; margin-bottom: 8px; }
.preview-pane { overflow: auto; padding-bottom: 24px; }
.paper-stage {
  transform-origin: top center;
  display: flex;
  justify-content: center;
  min-height: 980px;
}
.paper {
  width: 210mm;
  min-height: 297mm;
  background: #fff;
  color: #000;
  box-shadow: var(--shadow);
  padding: 20mm 15mm 18mm;
  font-family: Helvetica, Arial, sans-serif;
  font-size: 12pt;
  line-height: 1.15;
  position: relative;
  transform: scale(0.78);
  transform-origin: top center;
}
.inv-top { display: flex; justify-content: space-between; align-items: flex-start; }
.inv-logo { width: 44mm; height: 26mm; object-fit: contain; object-position: right top; }
.inv-title { font-weight: 700; margin-bottom: 18pt; }
.inv-issuer { margin: 0; }
.inv-client { text-align: left; margin: 28pt 0 0 auto; width: 48%; }
.inv-meta { margin-top: 36pt; }
.inv-meta p { margin: 10pt 0; }
.inv-table { width: 100%; border-collapse: collapse; margin: 10pt 0 16pt; }
.inv-table th, .inv-table td { border: 0.35pt solid #a6a6a6; padding: 7pt 6pt; }
.inv-table th { text-align: left; }
.inv-table td:last-child, .inv-table th:last-child { text-align: right; white-space: nowrap; }
.inv-total { font-weight: 700; margin: 12pt 0 22pt; }
.inv-footer { position: absolute; left: 15mm; bottom: 18mm; }
.inv-footer strong { display: block; }
.inv-footer .underline { text-decoration: underline; }

.company-cards { display: grid; gap: 18px; }
.company-card { display: grid; grid-template-columns: 140px 1fr; gap: 18px; align-items: start; }
.logo-box {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  min-height: 110px;
  display: grid;
  place-items: center;
  padding: 10px;
}
.logo-box img { max-width: 100%; max-height: 90px; object-fit: contain; }
.dialog { border: 0; border-radius: 16px; padding: 24px; width: min(460px, 92vw); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(20,20,20,.45); }

@media (max-width: 1100px) {
  .app-body { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .logout { margin-top: 0; }
  .editor-grid { grid-template-columns: 1fr; }
  .paper { transform: scale(0.72); transform-origin: top left; }
}
