:root {
  --ink: #14201c;
  --muted: #5a6b63;
  --paper: #f3f6f4;
  --card: #ffffff;
  --line: #d5e0da;
  --leaf: #1f6b4a;
  --leaf-deep: #0f3d2c;
  --leaf-soft: #e6f2eb;
  --danger: #b42318;
  --warn: #9a6700;
  --shadow: 0 10px 30px rgba(20, 32, 28, 0.06);
  --radius: 12px;
  --font: "Manrope", "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Sans", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 100% -10%, #cfe0d6 0%, transparent 55%),
    radial-gradient(700px 360px at -10% 0%, #f1e7c8 0%, transparent 50%),
    var(--paper);
}

a { color: var(--leaf); }
button, input, select, textarea { font: inherit; }

.app-shell { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(10px);
  background: rgba(243, 246, 244, 0.88);
  border-bottom: 1px solid var(--line);
}
.topbar-inner, .wrap {
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
}
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 0.85rem 0;
}
.brand {
  display: flex; align-items: baseline; gap: 0.55rem;
  text-decoration: none; color: inherit; font-weight: 700; font-size: 1.35rem;
}
.brand span { color: var(--muted); font-weight: 500; font-size: 0.85rem; }
.nav-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.btn {
  appearance: none; border: 1px solid var(--line); background: #fff;
  color: var(--ink); border-radius: 10px; padding: 0.55rem 0.9rem;
  cursor: pointer; font-weight: 600; transition: 0.15s ease;
}
.btn:hover { border-color: #b7c9bf; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--leaf); border-color: var(--leaf); color: #fff; }
.btn-primary:hover { background: var(--leaf-deep); border-color: var(--leaf-deep); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); border-color: #f0c4c0; background: #fff7f6; }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.9rem; border-radius: 8px; }

.page { padding: 1.25rem 0 3rem; }
.page-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap;
}
.page-head h1 { margin: 0; font-size: 1.7rem; letter-spacing: -0.02em; }
.page-head p { margin: 0.25rem 0 0; color: var(--muted); }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1rem;
}
.card-h {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.75rem 1rem; background: #eef4f0; border-bottom: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0; font-weight: 700;
}
.card-b { padding: 1rem; }
.grid { display: grid; gap: 0.85rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }

@media (max-width: 860px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .span-2, .span-3, .span-4 { grid-column: auto; }
}

.field { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }
.field label { font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.field .hint { font-size: 0.75rem; color: var(--muted); font-weight: 400; }
.row-inline { display: flex; gap: 0.5rem; align-items: end; }
.row-inline > .field { flex: 1; }

input[type="text"], input[type="number"], input[type="date"], input[type="email"],
input[type="tel"], select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px;
  padding: 0.55rem 0.7rem; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(31, 107, 74, 0.25); border-color: var(--leaf);
}
textarea { min-height: 72px; resize: vertical; }
.checkbox, .radio {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-size: 0.92rem; color: var(--ink); cursor: pointer; user-select: none;
}
.checks { display: flex; flex-wrap: wrap; gap: 0.85rem 1.25rem; align-items: center; }

.table-wrap { overflow-x: auto; }
table.items { width: 100%; border-collapse: collapse; min-width: 760px; }
table.items th, table.items td {
  border: 1px solid var(--line); padding: 0.4rem; vertical-align: top;
}
table.items th {
  background: #f7faf8; font-size: 0.78rem; text-align: left; color: var(--muted);
}
table.items input, table.items select, table.items textarea {
  border: 0; border-radius: 6px; padding: 0.4rem; background: transparent;
}
table.items textarea { min-height: 54px; }
table.items .num { width: 88px; }
table.items .unit { width: 70px; }
table.items .vat { width: 96px; }
table.items .sum { width: 110px; background: #f7faf8; font-weight: 600; }
table.items .del { width: 40px; text-align: center; }

.totals {
  display: flex; justify-content: flex-end; margin-top: 0.85rem;
}
.totals-box {
  min-width: 280px; background: var(--leaf-soft); border: 1px solid #c7ddd1;
  border-radius: 10px; padding: 0.75rem 1rem;
}
.totals-box .line {
  display: flex; justify-content: space-between; gap: 1rem; margin: 0.25rem 0;
}
.totals-box .line.strong { font-weight: 700; font-size: 1.05rem; margin-top: 0.4rem; }

.list { display: grid; gap: 0.65rem; }
.list-item {
  display: grid; grid-template-columns: 1fr auto; gap: 0.75rem; align-items: center;
  padding: 0.9rem 1rem; border: 1px solid var(--line); border-radius: 12px; background: #fff;
}
.list-item h3 { margin: 0 0 0.2rem; font-size: 1.05rem; }
.list-item p { margin: 0; color: var(--muted); font-size: 0.9rem; }
.list-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; justify-content: end; }
.empty {
  padding: 2rem 1rem; text-align: center; color: var(--muted);
  border: 1px dashed var(--line); border-radius: 12px; background: rgba(255,255,255,0.6);
}

.toast {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 50;
  background: var(--leaf-deep); color: #fff; padding: 0.75rem 1rem;
  border-radius: 10px; box-shadow: var(--shadow); max-width: min(360px, calc(100% - 2rem));
  opacity: 0; transform: translateY(8px); pointer-events: none; transition: 0.2s ease;
}
.toast.show { opacity: 1; transform: none; }
.toast.err { background: #7a1f18; }
.bik-ok { color: var(--leaf); font-size: 0.8rem; font-weight: 600; }
.bik-err { color: var(--danger); font-size: 0.8rem; font-weight: 600; }

.sticky-actions {
  position: sticky; bottom: 0; z-index: 10;
  display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: flex-end;
  padding: 0.85rem 0; margin-top: 0.5rem;
  background: linear-gradient(180deg, transparent, var(--paper) 30%);
}

/* Print documents */
.print-root { display: none; }
@media print {
  body { background: #fff; }
  .app-shell, .toast { display: none !important; }
  .print-root { display: block !important; }
  .print-sheet {
    color: #000; font-family: "Times New Roman", Times, serif;
    font-size: 11pt; line-height: 1.25;
  }
  .print-sheet h1, .print-sheet h2 { font-family: Arial, sans-serif; }
  .no-print { display: none !important; }
  @page { margin: 12mm; }
}

.print-sheet .doc-title { text-align: center; font-size: 16pt; margin: 0 0 10px; }
.print-sheet .muted { color: #333; font-size: 10pt; }
.print-sheet table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.print-sheet table.bordered th, .print-sheet table.bordered td {
  border: 1px solid #000; padding: 4px 6px; vertical-align: top;
}
.print-sheet table.bordered th { background: #f2f2f2; font-size: 9pt; }
.print-sheet .right { text-align: right; }
.print-sheet .center { text-align: center; }
.print-sheet .sign-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 28px;
}
.print-sheet .sign-line { border-bottom: 1px solid #000; height: 28px; margin-top: 18px; }
.print-sheet .bank-box { border: 1px solid #000; margin-bottom: 10px; }
.print-sheet .bank-box td { border: 1px solid #000; padding: 4px 6px; vertical-align: top; }
.print-sheet .qr-wrap { float: right; margin: 0 0 8px 12px; }
.print-sheet .clear { clear: both; }
}