:root {
  --navy: #0B1D2D;
  --navy-2: #10283A;
  --navy-3: #163044;
  --panel: #12283B;
  --blue: #0080CF;
  --blue-deep: #0069A8;
  --charcoal: #323232;
  --gray: #A8A8A8;
  --muted: #8A9AAB;
  --white: #FFFFFF;
  --off: #E6ECF2;
  --grid: #24415C;
  --paid-bg: #1C4E3A;
  --paid-fg: #78E6AA;
  --partial-bg: #4E3E10;
  --partial-fg: #FFD678;
  --owed: #FF8C8C;
  --credit-bg: #103458;
  --credit-fg: #96D2FF;
  --danger: #CE2127;
  --font: "Roboto Condensed", "Barlow Condensed", "Archivo Narrow", "Arial Narrow", sans-serif;
  --header-h: 58px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--navy);
  color: var(--off);
  font-family: var(--font);
  font-weight: 400;
  -webkit-text-size-adjust: 100%;
}
body { min-height: 100dvh; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--navy);
  border-bottom: 1px solid var(--grid);
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px 8px;
  max-width: 100%;
}
.crest { height: 54px; width: auto; display: block; flex-shrink: 0; }
.titles { min-width: 0; flex: 1; }
.kicker {
  margin: 0;
  color: var(--blue);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.kicker::after {
  content: "";
  display: block;
  width: 88px;
  height: 2px;
  background: var(--blue);
  margin-top: 4px;
}
h1 {
  margin: 4px 0 0;
  font-size: clamp(18px, 3.4vw, 28px);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--white);
  line-height: 1.1;
}
.sub {
  margin: 3px 0 0;
  color: var(--gray);
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.summary-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  flex-shrink: 0;
}
.pill {
  background: var(--navy-2);
  border: 1px solid var(--grid);
  border-radius: 8px;
  padding: 6px 10px 5px;
  min-width: 108px;
  text-align: right;
}
.pill .lbl {
  display: block;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.pill .val {
  display: block;
  font-size: 16px;
  font-weight: 700;
  color: var(--white);
  font-variant-numeric: tabular-nums;
}
.pill.collected .val { color: var(--paid-fg); }
.pill.owed .val { color: var(--owed); }
.pill.credit .val { color: var(--credit-fg); }

.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  padding: 8px 16px 12px;
}
.toolbar p.hint {
  margin: 0;
  flex: 1;
  min-width: 200px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.35;
}
button, .btn {
  font-family: var(--font);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: 12px;
  border: 0;
  border-radius: 6px;
  padding: 9px 12px;
  cursor: pointer;
  background: var(--blue);
  color: var(--white);
}
button.secondary { background: var(--navy-3); color: var(--off); border: 1px solid var(--grid); }
button.danger { background: transparent; color: var(--owed); border: 1px solid #5a2a2a; }
button:hover { filter: brightness(1.08); }
button:disabled { opacity: 0.55; cursor: default; filter: none; }
button.icon {
  padding: 2px 8px;
  font-size: 16px;
  line-height: 1.2;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
}
button.icon:hover { color: var(--owed); border-color: #5a2a2a; }

.status-dot {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.status-dot.dirty { color: var(--partial-fg); }

.wrap {
  padding: 0 0 40px;
}
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-top: 1px solid var(--grid);
  border-bottom: 1px solid var(--grid);
}
table {
  border-collapse: collapse;
  min-width: 1680px;
  width: 100%;
  font-size: 13px;
}
thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--blue);
  color: var(--white);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 11px;
  line-height: 1.2;
  padding: 8px 6px;
  text-align: center;
  border-right: 1px solid rgba(255,255,255,0.18);
  white-space: pre-line;
  vertical-align: bottom;
}
thead th.left, td.left { text-align: left; }
thead th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
thead th.sticky-num, thead th.sticky-name {
  z-index: 6;
  left: 0;
}
thead th.sticky-name { left: 42px; }

tbody td, tfoot td {
  padding: 3px 5px;
  border-bottom: 1px solid var(--grid);
  border-right: 1px solid rgba(36,65,92,0.7);
  vertical-align: middle;
  background: var(--navy);
}
tbody tr:nth-child(even) td { background: var(--navy-2); }
tbody tr.parent td { background: #0E2436; }
tbody tr:hover td { background: var(--navy-3); }

td.sticky-num, th.sticky-num, td.sticky-name, th.sticky-name {
  position: sticky;
  z-index: 3;
}
td.sticky-num, th.sticky-num { left: 0; width: 42px; min-width: 42px; text-align: center; }
td.sticky-name, th.sticky-name { left: 42px; min-width: 168px; max-width: 220px; }
td.sticky-num, td.sticky-name { box-shadow: 4px 0 8px rgba(0,0,0,0.18); }
tbody tr:nth-child(even) td.sticky-num,
tbody tr:nth-child(even) td.sticky-name { background: var(--navy-2); }
tbody tr td.sticky-num, tbody tr td.sticky-name { background: var(--navy); }
tbody tr.parent td.sticky-num, tbody tr.parent td.sticky-name { background: #0E2436; }

.name-cell { display: flex; flex-direction: column; gap: 2px; }
.name-cell input[type="text"] {
  font-weight: 600;
  font-size: 13.5px;
  color: var(--white);
}
.role {
  display: flex;
  align-items: center;
  gap: 6px;
}
.role select {
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: transparent;
  color: var(--blue);
  border: 0;
  padding: 0;
}

input[type="text"], input[type="search"] {
  font-family: var(--font);
  font-size: 13px;
  color: var(--off);
  background: rgba(255,255,255,0.04);
  border: 1px solid transparent;
  border-radius: 3px;
  padding: 4px 5px;
  width: 100%;
  min-width: 0;
}
input[type="text"]:focus, input[type="search"]:focus, select:focus {
  outline: 2px solid var(--blue);
  outline-offset: 0;
  background: #0A1824;
}
input.money { text-align: right; font-variant-numeric: tabular-nums; }
input.note { min-width: 180px; font-size: 12px; color: var(--off); }
td.computed { text-align: right; font-variant-numeric: tabular-nums; padding-right: 8px; color: var(--off); }
td.total-col { font-weight: 700; color: var(--white); background-image: linear-gradient(90deg, transparent, rgba(0,128,207,0.12)); }

.badge {
  display: inline-block;
  min-width: 58px;
  text-align: center;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 4px;
  padding: 3px 6px;
}
.badge.yes { background: var(--paid-bg); color: var(--paid-fg); }
.badge.partial { background: var(--partial-bg); color: var(--partial-fg); }
.badge.empty { color: var(--muted); }

td.owed-pos { color: var(--owed); font-weight: 700; text-align: right; }
td.owed-zero { color: var(--paid-fg); font-weight: 600; text-align: right; }
td.owed-credit { color: var(--credit-fg); font-weight: 700; text-align: right; background: var(--credit-bg) !important; }

tfoot td {
  background: #005C94 !important;
  color: var(--white);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 8px 6px;
}
tfoot tr.math td {
  background: var(--navy-2) !important;
  color: var(--muted);
  font-weight: 400;
  font-size: 11px;
  line-height: 1.3;
  white-space: pre-line;
  text-align: center;
  vertical-align: top;
  padding: 8px 5px;
}
tfoot tr.credit-row td {
  background: var(--credit-bg) !important;
  color: var(--credit-fg);
  font-weight: 600;
}
tfoot input.money {
  background: rgba(0,0,0,0.2);
  color: var(--white);
  font-weight: 700;
}

.legend {
  padding: 16px 16px 8px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.45;
  max-width: 1100px;
}
.legend h2 {
  margin: 16px 0 6px;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--blue);
}
.legend p { margin: 0 0 8px; }
footer.brand {
  padding: 18px 16px 28px;
  color: var(--gray);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
footer.brand .rule {
  height: 1.5px;
  background: #3A5166;
  margin: 8px 0 12px;
}
footer.brand .tagline { letter-spacing: 0.28em; color: var(--off); }
footer.brand .tagline strong { color: var(--blue); letter-spacing: 0.2em; }

@media (max-width: 720px) {
  .header-inner { flex-wrap: wrap; }
  .summary-pills { width: 100%; justify-content: stretch; }
  .pill { flex: 1; min-width: 0; }
  .crest { height: 44px; }
  h1 { font-size: 18px; }
  .toolbar { padding-bottom: 10px; }
}
