:root {
  --ink: #141311;
  --paper: #efe9dc;
  --sheet: #fffdf8;
  --gold: #c5a46b;
  --gold-deep: #9a7a3e;
  --line: #ddd4c4;
  --muted: #6d675c;
  --draft: #7c7568;
  --sent: #35506a;
  --paid: #3c5a43;
  --danger: #8b3a2a;
  --shadow: 0 10px 30px rgba(20, 19, 17, 0.07);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Avenir Next", "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  letter-spacing: 0.01em;
}

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

.topbar {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 28px;
  height: 64px;
  background: var(--ink);
  color: #fff;
}
.brand { text-decoration: none; color: #fff; display: flex; align-items: baseline; gap: 10px; }
.brand-mark { font-weight: 700; font-size: 22px; letter-spacing: -0.04em; }
.brand-app { color: var(--gold); font-size: 12px; text-transform: uppercase; letter-spacing: 0.16em; }
.nav { display: flex; gap: 6px; flex: 1; }
.nav a {
  color: rgba(255,255,255,.72);
  text-decoration: none;
  font-size: 14px;
  padding: 8px 12px;
  border-bottom: 2px solid transparent;
}
.nav a.is-active, .nav a:hover { color: #fff; border-bottom-color: var(--gold); }
.topbar-user { font-size: 13px; color: rgba(255,255,255,.7); display: flex; gap: 14px; align-items: center; }
.topbar-user a { color: var(--gold); text-decoration: none; }

.wrap { width: min(1180px, calc(100% - 40px)); margin: 28px auto 60px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; }
.page-head h1 { margin: 0; font-size: 28px; letter-spacing: -0.03em; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

.flash { padding: 12px 16px; border-radius: 2px; margin-bottom: 18px; font-size: 14px; }
.flash-success { background: #e4eee4; color: #24402c; }
.flash-error { background: #f3e1db; color: var(--danger); }
.flash-info { background: #ece6d8; color: var(--ink); }

.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.card {
  background: var(--sheet);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 20px 20px 16px;
  position: relative;
}
.card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--gold);
}
.card h2 { margin: 0 0 4px; font-size: 20px; }
.card .meta { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.period-box {
  background: #f6f1e6;
  padding: 10px 12px;
  margin: 12px 0;
  font-size: 13px;
}
.period-box strong { display: block; font-size: 14px; margin-top: 2px; }
.period-box .next { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.warn { color: var(--danger); font-size: 12px; margin-top: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; cursor: pointer; text-decoration: none;
  padding: 10px 16px; font-size: 14px; font-weight: 600;
  background: var(--ink); color: #fff;
}
.btn:hover { background: #2a2824; }
.btn-gold { background: var(--gold-deep); color: #fff; }
.btn-gold:hover { background: #7f632f; }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--ink); }
.btn-ghost:hover { background: var(--ink); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.btn-small { padding: 7px 11px; font-size: 12px; }

.badge {
  display: inline-block; font-size: 11px; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase;
  padding: 3px 8px;
}
.badge-draft { background: #ece7dc; color: var(--draft); }
.badge-sent { background: #dce6ef; color: var(--sent); }
.badge-paid { background: #dce8de; color: var(--paid); }

.table-wrap { background: var(--sheet); border: 1px solid var(--line); overflow: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
table.data tr:last-child td { border-bottom: 0; }
table.data a { font-weight: 600; text-decoration: none; }
table.data a:hover { color: var(--gold-deep); }

.filters { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filters a {
  text-decoration: none; font-size: 13px; padding: 6px 10px;
  border: 1px solid var(--line); background: var(--sheet); color: var(--muted);
}
.filters a.is-active { background: var(--ink); color: #fff; border-color: var(--ink); }

.form-card { background: var(--sheet); border: 1px solid var(--line); padding: 24px; max-width: 720px; }
label { display: block; font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin: 0 0 6px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); background: #fff; font-size: 15px; color: var(--ink);
}
textarea { min-height: 120px; resize: vertical; }
.field { margin-bottom: 16px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.qty-input { font-size: 28px !important; font-weight: 700; letter-spacing: -0.03em; }
.preview-line { background: #f6f1e6; padding: 12px 14px; font-size: 14px; margin: 8px 0 16px; }
.total-preview { font-size: 22px; font-weight: 700; }

.login-body { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.login-panel {
  background: var(--ink); color: #fff;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 48px;
}
.login-panel h1 { font-size: 42px; margin: 0; letter-spacing: -0.04em; }
.login-panel .gold { color: var(--gold); }
.login-form-wrap { display: flex; align-items: center; justify-content: center; padding: 40px; }
.login-form { width: min(380px, 100%); }
.login-form h2 { margin: 0 0 8px; font-size: 26px; }
.login-form p { color: var(--muted); margin: 0 0 22px; }

.two-col { display: grid; grid-template-columns: 1fr 1.1fr; gap: 24px; align-items: start; }
.side-actions { background: var(--sheet); border: 1px solid var(--line); padding: 18px; }
.side-actions h3 { margin: 0 0 12px; font-size: 15px; }
.stack { display: flex; flex-direction: column; gap: 8px; }

.invoice-stage {
  background: #d9d1c1;
  padding: 24px;
  overflow: auto;
  display: flex;
  justify-content: center;
}

/* Invoice sheet */
.inv {
  width: 210mm;
  min-height: 297mm;
  background: #fff;
  color: #111;
  font-family: Helvetica, Arial, sans-serif;
  position: relative;
  box-shadow: 0 12px 40px rgba(0,0,0,.12);
}
.inv-head {
  background: #111;
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 18px 18mm 14px;
}
.inv-title { font-size: 34px; font-weight: 700; letter-spacing: -0.03em; }
.inv-sender { text-align: right; font-size: 11px; line-height: 1.45; }
.inv-co { color: #c5a46b; font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.inv-gold { height: 3px; background: #c5a46b; }
.inv-gold-mid { margin: 0 18mm; }
.inv-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; padding: 16px 18mm 8px; }
.inv-meta h2 {
  font-size: 13px; margin: 0 0 8px; padding-bottom: 6px;
  border-bottom: 1.5px solid #c5a46b;
}
.inv-meta p { margin: 0; font-size: 12.5px; line-height: 1.45; }
.inv-meta dl { margin: 0; }
.inv-meta dl > div { display: grid; grid-template-columns: 120px 1fr; gap: 8px; font-size: 12.5px; padding: 2px 0; }
.inv-meta dt { color: #6d675c; }
.inv-meta dd { margin: 0; font-weight: 700; }
.inv-table { width: calc(100% - 36mm); margin: 18px 18mm 0; border-collapse: collapse; }
.inv-table th {
  background: #111; color: #fff; font-size: 11px; font-weight: 700;
  padding: 8px 8px; text-align: left;
}
.inv-table th:nth-child(n+2), .inv-table td:nth-child(n+2) { text-align: right; }
.inv-table td { background: #f7f2e9; padding: 12px 8px; font-size: 12px; vertical-align: top; }
.inv-sum { width: 88mm; margin: 14px 18mm 0 auto; }
.inv-sum-rows { background: #f7f2e9; padding: 8px 12px; }
.inv-sum-rows div, .inv-balance { display: flex; justify-content: space-between; font-size: 12px; padding: 3px 0; }
.inv-balance { background: #111; color: #fff; padding: 8px 12px; font-size: 14px; }
.inv-note { font-size: 10px; color: #6d675c; font-style: italic; margin: 8px 0 0; }
.inv-thanks { text-align: center; font-style: italic; margin: 36px 18mm 10px; font-size: 13px; }
.inv-pay { padding: 12px 18mm 0; }
.inv-pay h2 { font-size: 13px; margin: 0 0 10px; }
.inv-pay-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; font-size: 11.5px; }
.inv-pay-grid div > div { display: grid; grid-template-columns: 92px 1fr; padding: 2px 0; }
.inv-pay-grid span { color: #6d675c; }
.inv-foot { text-align: center; padding: 28px 0 18px; border-top: 4px solid #111; margin-top: 22px; }
.inv-logo { font-weight: 800; font-size: 26px; letter-spacing: -0.04em; }
.inv-logo-sub { font-size: 9px; letter-spacing: 0.22em; margin-top: 2px; }

.muted { color: var(--muted); }
.empty { padding: 28px; text-align: center; color: var(--muted); background: var(--sheet); border: 1px dashed var(--line); }

@media (max-width: 960px) {
  .grid-3, .two-col, .login-body, .field-row { grid-template-columns: 1fr; }
  .login-panel { min-height: 220px; }
  .topbar { flex-wrap: wrap; height: auto; padding: 12px 16px; }
  .nav { order: 3; width: 100%; }
}

@media print {
  .topbar, .side-actions, .flash, .page-head, .wrap > .two-col > :first-child { display: none !important; }
  body, .wrap, .invoice-stage { background: #fff; padding: 0; margin: 0; width: auto; }
  .inv { box-shadow: none; }
}
