:root {
  --bg: #0e0e10;
  --panel: #18181b;
  --panel-2: #212124;
  --border: #2e2e33;
  --text: #f2f2f2;
  --text-dim: #a3a3a8;
  --accent: #f7941d;
  --accent-dark: #c9740a;
  --danger: #e5484d;
  --success: #3dd68c;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
  padding: 0 6px;
}
.sidebar .brand img { width: 34px; height: 34px; object-fit: contain; }
.sidebar .brand span { font-weight: 700; font-size: 14px; line-height: 1.2; }

.sidebar nav a {
  display: block;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 2px;
}
.sidebar nav a:hover { background: var(--panel-2); text-decoration: none; color: var(--text); }
.sidebar nav a.active { background: var(--accent); color: #1a1a1a; font-weight: 600; }

.main {
  flex: 1;
  padding: 28px 32px;
  max-width: 1100px;
}

h1 { font-size: 22px; margin: 0 0 18px; }
h2 { font-size: 16px; margin: 28px 0 10px; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

.cards { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  min-width: 160px;
}
.card .label { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.card .value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.card .value.accent { color: var(--accent); }
.card .value.danger { color: var(--danger); }

table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--text-dim); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }
tr.clickable:hover { background: var(--panel-2); cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.btn {
  display: inline-block;
  background: var(--accent);
  color: #1a1a1a;
  border: none;
  padding: 9px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.btn:hover { background: var(--accent-dark); }
.btn.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: #29292e; }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn.small { padding: 5px 10px; font-size: 12px; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 10px; flex-wrap: wrap; }

.status-pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.status-draft { background: #3a3a3f; color: #cfcfd4; }
.status-sent { background: #2b4a63; color: #8fc4ec; }
.status-accepted, .status-paid { background: #16382a; color: var(--success); }
.status-declined { background: #3a1e20; color: var(--danger); }
.status-partially_paid { background: #4a3a16; color: #f2c94c; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; max-width: 640px; }
.form-grid.full { grid-template-columns: 1fr; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.span2 { grid-column: span 2; }
.field label { font-size: 12px; color: var(--text-dim); }
input, select, textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 7px;
  font-size: 14px;
  font-family: inherit;
}
textarea { resize: vertical; min-height: 60px; }

.lines-table input { width: 100%; }
.lines-table td { vertical-align: middle; }
.remove-line { color: var(--danger); cursor: pointer; font-weight: 700; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; width: 480px; max-width: 92vw; max-height: 88vh; overflow: auto;
}
.modal h3 { margin-top: 0; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.empty { color: var(--text-dim); font-size: 14px; padding: 20px; text-align: center; }
.error { color: var(--danger); font-size: 13px; margin-top: 6px; }

/* ---------- Printable document view ---------- */
.doc-actions { margin-bottom: 18px; display: flex; gap: 10px; flex-wrap: wrap; }

.doc-page {
  background: #fff;
  color: #111;
  width: 210mm;
  min-height: 200mm;
  margin: 0 auto;
  padding: 14mm;
  border: 3px solid #111;
  font-family: Calibri, "Segoe UI", Arial, sans-serif;
  font-size: 13px;
}
.doc-page table { background: transparent; }
.doc-page td, .doc-page th { border-bottom: none; }
.doc-title { background: #d9d9d9; font-weight: 700; padding: 6px 8px; margin-bottom: 16px; font-size: 14px; }
.doc-meta-table { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
.doc-meta-table td { padding: 1px 0; vertical-align: top; line-height: 1.5; }
.doc-meta-table .lbl { font-weight: 700; width: 80px; }
.doc-meta-table .val { width: auto; }
.doc-meta-table .lbl2 { font-weight: 700; width: 70px; padding-left: 30px; }
.doc-meta-table .val2 { width: 90px; }
.doc-attn { margin-bottom: 14px; }
.doc-table { width: 100%; border-collapse: collapse; margin-bottom: 4px; }
.doc-table thead th { background: #d9d9d9; text-align: left; padding: 5px 8px; font-size: 12px; text-transform: uppercase; }
.doc-table thead th.num { text-align: right; }
.doc-table td { padding: 3px 8px; vertical-align: top; }
.doc-table td.num { text-align: right; white-space: nowrap; }
.doc-event-title { font-weight: 700; padding-top: 10px; }
.doc-event-meta { padding-bottom: 6px; }
.doc-total-row td { border-top: 2px solid #111; font-weight: 700; padding-top: 6px; }
.doc-footer { display: flex; justify-content: space-between; margin-top: 24px; }
.doc-footer .block-label { background: #d9d9d9; display: inline-block; padding: 2px 8px; font-weight: 700; margin-bottom: 4px; }
.doc-logo { width: 220px; }
.doc-statement-table th, .doc-statement-table td { font-size: 12px; }

@media print {
  body * { visibility: hidden; }
  .doc-page, .doc-page * { visibility: visible; }
  .doc-page { position: absolute; top: 0; left: 0; margin: 0; border: 3px solid #111; box-shadow: none; }
  .doc-actions, .sidebar { display: none !important; }
}
