:root {
  --navy: #162033;
  --navy-2: #243044;
  --gold: #c6a15a;
  --gold-ink: #7d5e2a;
  --bg: #eef1f4;
  --card: #ffffff;
  --ink: #1a2332;
  --muted: #5d6b7e;
  --line: #e1e6ee;
  --green: #1c7c4a;
  --green-bg: #e7f6ee;
  --red: #a33d36;
  --red-bg: #fdeceb;
  --blue: #245c9e;
  --blue-bg: #e8f0fa;
  --gold-bg: #fbf6ec;
  --shadow: 0 16px 40px rgba(22, 32, 51, 0.06);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--blue); }
h1, h2, h3 { font-family: Palatino, "Palatino Linotype", Georgia, serif; font-weight: 600; letter-spacing: -0.02em; margin: 0; }
h1 { font-size: 32px; }
h2 { font-size: 22px; }
p { margin: 0; }

.app { display: flex; min-height: 100vh; }
.side {
  width: 248px;
  flex: none;
  background: var(--navy);
  color: #e7edf5;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 18px 8px;
  color: white;
  text-decoration: none;
  font-family: Palatino, Georgia, serif;
  font-size: 28px;
}
.brand svg { display: block; }
.company-pick { padding: 8px 14px 12px; }
.company-pick select, .company-name {
  width: 100%;
  background: var(--navy-2);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 8px 10px;
}
.company-name { display: block; }
.nav { overflow: auto; padding: 6px 10px 16px; flex: 1; min-height: 0; }
.nav-group { margin: 14px 8px 6px; color: #93a0b5; font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; }
.nav a {
  display: block;
  color: #d5deea;
  text-decoration: none;
  border-radius: 8px;
  padding: 8px 10px;
  margin: 1px 0;
}
.nav a:hover { background: rgba(255, 255, 255, 0.05); }
.nav a.active { background: rgba(198, 161, 90, 0.18); color: #f3e6c8; }
.side-user { padding: 14px 16px 18px; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.side-user strong { display: block; }
.side-user span { color: #93a0b5; font-size: 13px; }
.side-user button { margin-top: 8px; background: transparent; color: #f3e6c8; border: 0; padding: 0; }

.main { flex: 1; min-width: 0; }
.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 28px;
  background: rgba(238, 241, 244, 0.92);
  position: sticky;
  top: 0;
  z-index: 5;
}
.menu {
  display: none;
  border: 1px solid var(--line);
  background: white;
  border-radius: 8px;
  padding: 6px 10px;
}
.content { padding: 8px 28px 64px; max-width: 1180px; }
.kicker { color: var(--gold-ink); font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; margin-bottom: 4px; }
.lede { color: var(--muted); margin: 6px 0 0; max-width: 62ch; }
.page-head, .split { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.page-head { margin-bottom: 18px; }
.actions, .row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.btn, .btn.secondary, .btn.danger, .btn.quiet {
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 8px 14px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--navy);
  color: white;
  min-height: 40px;
}
.btn.secondary { background: white; color: var(--ink); border-color: var(--line); }
.btn.danger { background: white; color: var(--red); border-color: #f0c9c6; }
.btn.quiet { background: transparent; color: var(--blue); padding-inline: 8px; }
.btn:disabled { opacity: 0.55; cursor: default; }
.icon {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  padding: 0 6px;
}

.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 18px 0; }
.card, .panel, .sheet, .login form, .modal {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.card { padding: 16px 16px 14px; }
.card span { color: var(--muted); font-size: 13px; }
.card strong { display: block; margin-top: 6px; font-size: 26px; font-variant-numeric: tabular-nums; font-family: Palatino, Georgia, serif; }
.card a { text-decoration: none; color: inherit; }
.panel { padding: 16px; margin-top: 14px; }
.panel h2 { margin-bottom: 10px; }
.grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; }
.stack { display: grid; gap: 14px; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
th, td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; }
tbody tr:hover { background: #f7f9fb; }
.table-wrap { overflow: auto; }

label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
input, select, textarea {
  width: 100%;
  border: 1px solid #d5dbe3;
  background: white;
  border-radius: 8px;
  padding: 9px 10px;
  min-height: 40px;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(36, 92, 158, 0.25); border-color: var(--blue); }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.fields .wide { grid-column: 1 / -1; }
.form-error, .banner.bad { color: var(--red); background: var(--red-bg); border-radius: 8px; padding: 8px 10px; }
.form-error[hidden] { display: none; }
.banner { margin-bottom: 12px; }
.totals { margin-left: auto; width: min(280px, 100%); display: grid; gap: 6px; }
.totals div { display: flex; justify-content: space-between; gap: 16px; }
.totals .grand { font-weight: 700; border-top: 1px solid var(--ink); padding-top: 6px; }

.pill {
  display: inline-flex;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  background: #eef1f4;
  color: var(--muted);
}
.pill.open, .pill.sent { background: var(--blue-bg); color: var(--blue); }
.pill.partial { background: var(--gold-bg); color: var(--gold-ink); }
.pill.paid, .pill.received { background: var(--green-bg); color: var(--green); }
.pill.void { background: var(--red-bg); color: var(--red); }
.overdue { color: var(--red); }

.sheet { padding: 28px; max-width: 860px; }
.sheet-top { display: flex; justify-content: space-between; gap: 20px; }
.sheet img.logo { max-width: 180px; max-height: 72px; object-fit: contain; }
.sheet .doc-title { text-align: right; }
.sheet .doc-title strong { font-family: Palatino, Georgia, serif; font-size: 28px; letter-spacing: 0.08em; }
.muted { color: var(--muted); }
.rule { height: 2px; background: var(--gold); border: 0; margin: 16px 0; }
.lines input { min-height: 36px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 12px; }
.filters button { background: white; border: 1px solid var(--line); border-radius: 999px; padding: 5px 10px; }
.filters button.on { background: var(--navy); color: white; border-color: var(--navy); }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; min-height: 0; }
.balance-ok { color: var(--green); }
.balance-bad { color: var(--red); }
.search { max-width: 260px; }

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 420px at 10% -10%, #e7d7b2, transparent 55%),
    var(--bg);
}
.login form { width: min(420px, 100%); padding: 28px; display: grid; gap: 12px; }
.login h1 { font-size: 34px; }
.mark { font-family: Palatino, Georgia, serif; font-size: 18px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--gold-ink); }

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(22, 32, 51, 0.46);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 20;
}
.modal-back[hidden] { display: none; }
.modal { width: min(460px, 100%); padding: 20px; display: grid; gap: 12px; }
#toast {
  position: fixed;
  bottom: 16px;
  right: 16px;
  background: var(--navy);
  color: white;
  padding: 12px 14px;
  border-radius: 10px;
  max-width: min(360px, calc(100% - 32px));
  z-index: 30;
  display: none;
}
#toast.show { display: block; }
#toast.bad { background: var(--red); }
.empty { color: var(--muted); padding: 12px 0; }
.report-total td { font-weight: 700; border-top: 1px solid var(--ink); }
.section-label td { padding-top: 16px; color: var(--muted); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }

@media (max-width: 980px) {
  .cards, .grid, .fields { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 15; transform: translateX(-105%); transition: transform 0.18s ease; }
  .side.open { transform: none; }
  .menu { display: inline-flex; }
  .content, .bar { padding-left: 16px; padding-right: 16px; }
}
@media print {
  .side, .bar, .actions, .noprint, #toast, #modal { display: none !important; }
  .main, .content { padding: 0; max-width: none; }
  .panel, .sheet, .card { box-shadow: none; }
}
