:root {
  --navy: #16398f;
  --navy-deep: #102a6b;
  --blue: #1e56c9;
  --red: #e11d2a;
  --red-dark: #c4121e;
  --ink: #121826;
  --muted: #5c6675;
  --page: #eef1f5;
  --paper: #ffffff;
  --line: #d4dbe4;
  --line-strong: #b7c1ce;
  --ok: #18794e;
  --warn: #c4121e;
  --draft: #9a6b12;
  --sent: #1e56c9;
  --shadow: 0 1px 0 rgba(18, 24, 38, 0.04), 0 10px 28px rgba(18, 24, 38, 0.06);
  --radius: 2px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  display: grid;
  grid-template-columns: 232px 1fr;
  font: 15px/1.5 Inter, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--page);
}

a { color: var(--blue); }
a:hover { color: var(--red); }

.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 16px;
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-deep) 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  color: inherit;
  text-decoration: none;
  padding: 4px 8px;
}

.brand strong {
  display: block;
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand small {
  display: block;
  opacity: 0.72;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.64rem;
  font-weight: 600;
}

.mark {
  width: 32px;
  height: 32px;
  background: var(--red);
  border-radius: var(--radius);
  flex: 0 0 auto;
  position: relative;
}
.mark::before,
.mark::after {
  content: "";
  position: absolute;
  background: #fff;
}
.mark::before {
  width: 4px;
  height: 16px;
  left: 9px;
  top: 8px;
}
.mark::after {
  width: 10px;
  height: 4px;
  left: 9px;
  top: 8px;
}

.rail nav { display: flex; flex-direction: column; gap: 2px; }

.rail nav a {
  color: rgba(255, 255, 255, 0.88);
  text-decoration: none;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-weight: 500;
  border-left: 3px solid transparent;
}

.rail nav a.on,
.rail nav a:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.rail nav a.on {
  border-left-color: var(--red);
  background: rgba(255, 255, 255, 0.14);
}

.rail-note {
  margin-top: auto;
  font-size: 0.75rem;
  line-height: 1.4;
  opacity: 0.62;
}

.rail-note code {
  color: #ffd0d3;
}

.shell {
  min-width: 0;
  padding: 32px 36px 56px;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 22px;
}

h1 {
  margin: 0;
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

h2 {
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 700;
}

.sub, .muted { color: var(--muted); }

.top-actions, .row-actions, .status-actions, .filters, .inline-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.btn {
  appearance: none;
  border: 0;
  background: var(--red);
  color: #fff;
  font: inherit;
  font-weight: 700;
  padding: 9px 16px;
  border-radius: var(--radius);
  text-decoration: none;
  cursor: pointer;
}

.btn:hover { background: var(--red-dark); color: #fff; }

.btn.ghost {
  background: transparent;
  color: var(--navy);
  border: 1px solid var(--line-strong);
}

.btn.ghost:hover {
  border-color: var(--navy);
  background: #fff;
  color: var(--navy);
}

.btn.danger { background: var(--warn); }
.btn.danger.ghost { background: transparent; color: var(--warn); border-color: #f0b4b8; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.small {
  padding: 5px 11px;
  font-size: 0.85rem;
}

.flash {
  margin: 0 0 16px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: #e6f5ec;
  border: 1px solid #c6e6d3;
}

.flash.error { background: #fde8ea; border-color: #f5c2c6; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.stats article, .panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stats article { padding: 18px 18px 16px; }
.stats span, .meta-grid .muted {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.stats strong {
  display: block;
  margin: 8px 0 4px;
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.stats em {
  font-style: normal;
  color: var(--muted);
  font-size: 0.88rem;
}

.stats.five-up { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.stats.six-up { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stats article.lead { border-top: 3px solid var(--navy); }
.stats article.gain { border-top: 3px solid #1e8e4e; }
.stats article.loss { border-top: 3px solid #b42318; }
.stats article.gain strong { color: #1e8e4e; }
.stats article.loss strong { color: #b42318; }
td.num.pos { color: #1e8e4e; font-weight: 600; }
td.num.neg { color: #b42318; font-weight: 600; }

.month-nav { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.month-nav .month-pick select { width: auto; min-width: 170px; }

.panel { padding: 20px; }
.panel.narrow { max-width: 720px; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 11px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.dim { opacity: 0.62; }

.pill {
  display: inline-block;
  padding: 2px 7px;
  border-radius: var(--radius);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: #e8edf4;
  color: var(--navy);
}

.pill.active, .pill.paid { background: #d9f3e4; color: var(--ok); }
.pill.inactive, .pill.void { background: #e8edf4; color: var(--muted); }
.pill.draft { background: #f8ebd0; color: var(--draft); }
.pill.sent { background: #dce7fb; color: var(--sent); }
.pill.GGR { background: #dce7fb; color: var(--sent); }
.pill.PPH { background: #fde2e4; color: var(--red-dark); }
.pill.HOUSE { background: #ece6d4; color: #6b5420; }
.pill.overdue { background: #fde2e4; color: var(--warn); }

.filters {
  margin-bottom: 16px;
}

input, select, textarea, button {
  font: inherit;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 0;
  padding: 8px 10px;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(30, 86, 201, 0.28);
  outline-offset: 0;
  border-color: var(--blue);
}

.amount {
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: #fff;
}
.amount .affix {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  min-width: 1.7rem;
  padding: 0 8px;
  color: var(--muted);
  font-weight: 700;
  background: #f3f5f8;
  white-space: nowrap;
}
.amount.money .affix { border-right: 1px solid var(--line); }
.amount.percent .affix { border-left: 1px solid var(--line); }
.amount input {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  border: 0;
  background: transparent;
  border-radius: 0;
}
.amount input:focus { outline: none; border: 0; }
.amount:focus-within {
  outline: 2px solid rgba(30, 86, 201, 0.28);
  outline-offset: 0;
  border-color: var(--blue);
}

.filters input, .filters select, .inline-form select {
  width: auto;
  min-width: 220px;
}

.bulk-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 0 0 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.bulk-bar .check { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.bulk-bar .check input { width: auto; }
.bulk-bar .bulk-pdf { display: inline-flex; gap: 8px; margin-left: auto; min-width: 0; }
.bulk-bar .bulk-pdf input { width: 380px; max-width: 100%; }
input.mono { font-family: Consolas, "Courier New", monospace; }
.check-inline { display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; font-weight: 400; white-space: nowrap; }
.check-inline input { width: auto; }
.check-col { width: 28px; }
.check-col input { width: auto; }

.ggr-amount { font-variant-numeric: tabular-nums; }
.ggr-amount.warn { color: #b42318; font-weight: 600; }
.balance-input { margin-top: 0; }
.subhead {
  margin: 22px 0 6px;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.casino-summary .total-row td { font-weight: 700; }
.ggr-input {
  display: block;
  margin: 6px 0 0 auto;
  width: 7.5rem;
  min-width: 0;
  padding: 5px 8px;
  font-size: 0.85rem;
  text-align: right;
}

.casino-lines { margin-top: 6px; }
.casino-lines .muted {
  font-size: 0.78rem;
  line-height: 1.35;
}

.nowrap { white-space: nowrap; }
.inline-delete {
  display: inline;
  margin: 0;
}

.confirm-dialog {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: 420px;
  width: calc(100% - 32px);
}
.confirm-dialog::backdrop {
  background: rgba(18, 24, 38, 0.48);
}
.confirm-card {
  margin: 0;
  padding: 22px 20px 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.confirm-card p {
  margin: 0 0 18px;
  font-size: 1.05rem;
  font-weight: 500;
  line-height: 1.4;
}
.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.bulk-panel { padding: 0; overflow: hidden; }
.bulk-scroll { overflow: auto; max-height: calc(100vh - 260px); }
.bulk-table { min-width: 1480px; }
.bulk-table th, .bulk-table td { vertical-align: middle; }
.bulk-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--paper);
}
.bulk-table th.sticky,
.bulk-table td.customer-cell {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 180px;
  background: var(--paper);
  box-shadow: 8px 0 10px -10px rgba(18, 24, 38, 0.22);
}
.bulk-table thead th.sticky { z-index: 3; }
.bulk-table input:not([type="checkbox"]),
.bulk-table select {
  min-width: 0;
  width: 7.5rem;
  padding: 6px 8px;
}
.bulk-table .amount {
  width: 8.2rem;
}
.bulk-table .amount input { width: 100%; padding: 6px 8px; }
.bulk-product {
  display: grid;
  gap: 6px;
  justify-items: start;
}
.bulk-product .amount { width: 7.4rem; }
.bulk-bar {
  position: sticky;
  bottom: 0;
  z-index: 4;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding: 12px 0 4px;
  background: linear-gradient(transparent, var(--page) 28%);
}

.filter-summary { margin: 0; color: var(--muted); }

.stack { display: grid; gap: 14px; }
.split {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(280px, 0.9fr);
  gap: 18px;
  align-items: start;
}

label { display: grid; gap: 6px; font-weight: 600; }
[hidden] { display: none !important; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.three { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.four { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.five { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.product {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}
.product h3 {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 700;
}
.check-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}
.check-line input { width: auto; }
.type-pick {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.type-pick legend {
  grid-column: 1 / -1;
  padding: 0 6px;
  font-weight: 700;
}
.choice {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}
.choice:has(input:checked) {
  border-color: var(--blue);
  background: #eef3fc;
}
.choice input { width: auto; }
.choice small { font-weight: 400; color: var(--muted); }
.row-actions { margin-top: 8px; }
.danger-form { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.empty { padding: 28px 8px; color: var(--muted); }
.meta-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.item-form {
  display: grid;
  grid-template-columns: 2fr 80px 150px auto;
  gap: 8px;
  margin: 14px 0;
}

.totals {
  display: block;
  margin: 18px 0 0 auto;
  width: min(320px, 100%);
  padding: 12px 16px 14px;
  background: #f7f8fb;
  border: 1px solid var(--line);
}

.totals div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding: 6px 0;
}
.totals dt { color: var(--muted); white-space: nowrap; }
.totals dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

.totals .grand {
  border-top: 2px solid var(--navy);
  margin-top: 6px;
  padding-top: 10px;
}
.totals .grand dt { color: var(--navy); font-weight: 700; font-size: 1.05rem; }
.totals .grand dd { font-size: 1.3rem; font-weight: 800; }
.totals .remit-note { display: block; padding: 6px 0 0; color: var(--muted); font-size: 0.9rem; text-align: right; }

.linkish {
  border: 0;
  background: none;
  color: var(--warn);
  cursor: pointer;
  font: inherit;
  padding: 0;
}
.linkish.edit { color: var(--blue); }

/* Copy-to-clipboard icon next to email addresses */
.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  vertical-align: middle;
  margin-left: 4px;
  padding: 2px 4px;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.75rem;
  line-height: 1;
}
.copy-btn:hover { color: var(--blue); background: #eef2ff; }
.copy-btn.copied { color: #1e8e4e; }
.copy-btn .copy-label:empty { display: none; }
.email-line { white-space: nowrap; }
.label-row { display: inline-flex; align-items: center; gap: 2px; }
.linkish:hover { text-decoration: underline; }

.row-actions { white-space: nowrap; }
.row-actions form { display: inline; }
.row-actions > * + * { margin-left: 12px; }
.item-edit td { background: #f7f8fb; vertical-align: middle; }
.item-edit input { padding: 6px 8px; }
.item-edit .qty-input { width: 72px; text-align: right; }
.item-edit .amount { width: 130px; margin-left: auto; }

.login-body {
  display: grid;
  place-items: center;
  grid-template-columns: 1fr;
  min-height: 100vh;
  background: var(--navy-deep);
}
.login-card {
  width: min(400px, calc(100vw - 32px));
  padding: 28px;
}
.login-card .brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login-card h1 { margin: 0 0 6px; }
.rail-logout { margin-top: auto; padding: 16px; }
.rail-logout .btn,
.rail-logout .btn.ghost {
  background: #fff;
  color: var(--blue);
  border: 1px solid #fff;
}
.rail-logout .btn:hover,
.rail-logout .btn.ghost:hover {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

@media (max-width: 1280px) {
  .four, .five { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 980px) {
  body { grid-template-columns: 1fr; }
  .rail { position: relative; height: auto; }
  .stats, .stats.five-up, .stats.six-up, .split, .two, .three, .four, .five, .item-form, .meta-grid, .type-pick { grid-template-columns: 1fr; }
  .shell { padding: 24px; }
}
