:root {
  --paper: #f3efe6;
  --paper-2: #fffdf8;
  --ink: #1c2b24;
  --muted: #5e6d64;
  --line: #e3d9c8;
  --green: #1e6b43;
  --green-dark: #143d28;
  --green-soft: #e5f2ea;
  --gold: #c9842a;
  --gold-soft: #f8ecd9;
  --rust: #8d4a3a;
  --rust-soft: #f6e6e1;
  --shadow: 0 10px 30px rgba(28, 43, 36, 0.06);
  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  --sans: "Segoe UI", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.45 var(--sans);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.02em; margin: 0; }
p { margin: 0; }

#app { display: flex; min-height: 100%; }

#nav {
  width: 248px;
  flex: none;
  background: var(--green-dark);
  color: #f6f1e6;
  padding: 22px 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 0 8px; }
.mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--gold); color: var(--green-dark);
  display: grid; place-items: center; font-family: var(--serif); font-weight: 700;
}
.brand strong { display: block; font-family: var(--serif); font-size: 22px; line-height: 1; }
.brand span { color: #d7c7a4; font-size: 12px; }
.nav-scroll { overflow: auto; flex: 1; display: flex; flex-direction: column; gap: 4px; padding-right: 4px; }
.nav-label { margin: 12px 8px 4px; font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: #b7c4b4; }
.nav-btn, .season-link {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; text-align: left; border: 0; background: transparent; color: inherit;
  border-radius: 10px; padding: 8px 10px;
}
.nav-btn:hover, .season-link:hover { background: rgba(255,255,255,0.06); }
.nav-btn.active, .season-link.active { background: rgba(255,255,255,0.12); }
.season-link small { color: #d7c7a4; }
.season-link .dot { width: 7px; height: 7px; border-radius: 99px; background: var(--gold); flex: none; }
.nav-foot { padding: 8px; color: #d7c7a4; font-size: 12px; }

#stage { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
.history-nav {
  position: sticky; top: 0; z-index: 8; display: flex; gap: 6px;
  padding: 10px 32px 8px; background: var(--paper);
}
.history-btn {
  width: 34px; height: 30px; border-radius: 8px; border: 1px solid var(--line);
  background: white; color: var(--ink); padding: 0;
}
.history-btn:disabled { opacity: 0.35; cursor: default; }
#main { flex: 1; min-width: 0; padding: 8px 32px 64px; }
.loading { color: var(--muted); padding: 40px 0; }

.top { display: flex; justify-content: space-between; gap: 16px; align-items: flex-end; margin-bottom: 18px; }
.kicker { color: var(--gold); font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; margin-bottom: 4px; }
.lede { color: var(--muted); max-width: 46rem; margin-top: 6px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.btn, .btn-gold, .btn-quiet, .btn-danger {
  border-radius: 999px; border: 1px solid transparent; padding: 8px 14px; background: var(--green); color: white;
}
.btn:hover { background: #185838; }
.btn-gold { background: var(--gold); color: #2a2116; }
.btn-gold:hover { background: #b67522; }
.btn-quiet { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-quiet:hover { background: white; }
.btn-danger { background: transparent; color: var(--rust); border-color: #e4c7bf; }
.btn[disabled] { opacity: 0.55; cursor: wait; }

.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 16px 0; }
.card, .panel {
  background: var(--paper-2); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
}
.card { padding: 14px 16px; }
.card span { display: block; color: var(--muted); font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
.card strong { display: block; margin-top: 4px; font-family: var(--serif); font-size: 28px; font-variant-numeric: tabular-nums; }
.card em { font-style: normal; color: var(--muted); font-size: 13px; }

.panel { padding: 16px 18px; margin-top: 14px; }
.panel h2 { font-size: 22px; margin-bottom: 8px; }
.split { display: grid; grid-template-columns: 1.2fr 0.8fr; gap: 14px; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { text-align: left; font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
th, td { padding: 8px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.name { font-weight: 650; }
.right { text-align: right; }
.muted { color: var(--muted); }
.tag {
  display: inline-block; border-radius: 999px; padding: 1px 8px; font-size: 12px;
  background: var(--green-soft); color: var(--green-dark);
}
.tag.new { background: var(--gold-soft); color: #6d4a16; }
.tag.warn { background: var(--rust-soft); color: var(--rust); }
.tag.drop { background: #e7eef8; color: #23405f; }
.tag-btn { border: 0; cursor: pointer; font: inherit; line-height: inherit; }
.tag-btn:hover { filter: brightness(0.96); }
.drop-band td { vertical-align: top; background: #fbfaf6; }
.drop-stack { display: flex; flex-direction: column; align-items: stretch; gap: 8px; min-width: 156px; text-align: left; }
.drop-card {
  display: flex; flex-direction: column; align-items: stretch; gap: 6px;
  background: white; border: 1px solid var(--line); border-radius: 12px; padding: 8px;
}
.drop-card-name { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: space-between; }
.drop-card-name .who { font-weight: 700; color: var(--ink); }
.drop-card .fee-edit input { width: 72px; }
.drop-sum { color: var(--muted); font-size: 12px; }
.drop-add { display: flex; gap: 4px; align-items: center; }
.drop-add input { min-width: 0; }
.dialog { position: relative; }
.dialog-x {
  position: absolute; top: 12px; right: 12px; width: 32px; height: 32px; border-radius: 999px;
  border: 1px solid var(--line); background: white; color: var(--ink); font-size: 18px; line-height: 1;
}
.dialog h2 { padding-right: 40px; }
.drop-line { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0; min-width: 280px; }
.drop-line input { width: auto; }
.drop-night-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 4px; }
.drop-paid-sum { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.add-bar { margin: 4px 0 12px; }
.night-pick { background: transparent; border: 0; padding: 0; color: inherit; font-weight: 650; }
th.night-on, td.night-on { background: #e7f2ea; }
.batch-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.batch-row select, .batch-row input { width: auto; min-width: 120px; }
.dialog.wide { width: min(920px, 100%); }

.tabs { display: flex; gap: 6px; margin: 8px 0 14px; flex-wrap: wrap; }
.tabs button { background: transparent; border: 0; border-bottom: 2px solid transparent; border-radius: 0; padding: 8px 10px; color: var(--muted); }
.tabs button.active { color: var(--green-dark); border-color: var(--gold); }

.banner {
  background: var(--gold-soft); border: 1px solid #edd3a8; color: #5c4318;
  border-radius: 12px; padding: 10px 12px; margin-bottom: 12px;
}
.banner.green { background: var(--green-soft); border-color: #c9e4d4; color: var(--green-dark); }

.grid-wrap { overflow: auto; overflow-anchor: none; border: 1px solid var(--line); border-radius: 16px; background: var(--paper-2); }
.nowrap { white-space: nowrap; }
.night-meters { display: flex; justify-content: center; gap: 8px; margin-top: 6px; }
.court-hours {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  margin-top: 0; font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted); font-weight: 650;
}
.court-hours input {
  width: 72px; padding: 3px 6px; text-align: center; text-transform: none;
  letter-spacing: 0; font-size: 14px; font-weight: 650; color: var(--ink);
}
.night-date { margin-top: 6px; }
.night-date input { width: 138px; }
.rate-cell, .player-rates { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.rate-mini { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; justify-content: center; font-size: 10px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.rate-mini input, .rate-cell input { width: 64px; padding: 2px 4px; text-align: center; text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--ink); }
.grid-wrap:has(> table.att) { max-height: calc(100vh - 230px); min-height: 280px; }
.grid-wrap:has(.cell-stack.tip-open) { overflow: visible; }
.att { min-width: 980px; border-collapse: separate; border-spacing: 0; }
.att th, .att td { text-align: center; }
.att thead th {
  position: sticky; top: 0; z-index: 4; background: #fffdf8;
  box-shadow: inset 0 -1px 0 var(--line);
}
.att th.pin-start, .att td.pin-start, .att th:first-child, .att td:first-child {
  text-align: left; position: sticky; left: 0; z-index: 3; background: #fffdf8;
  box-shadow: 8px 0 8px -8px rgba(28, 43, 36, 0.28);
}
.att thead th.pin-start, .att thead th:first-child {
  z-index: 6; top: 0; left: 0;
  box-shadow: inset 0 -1px 0 var(--line), 8px 0 8px -8px rgba(28, 43, 36, 0.28);
}
.att th.pin-end, .att td.pin-end {
  position: sticky; z-index: 3; background: #fffdf8;
}
.att thead th.pin-end { z-index: 5; top: 0; }
.att .pin-end-edge { box-shadow: -8px 0 8px -8px rgba(28, 43, 36, 0.28); }
.att thead th.pin-end-edge { box-shadow: inset 0 -1px 0 var(--line), -8px 0 8px -8px rgba(28, 43, 36, 0.28); }
.att thead th.night-on { background: #e7f2ea; }
.drop-band td.pin-start, .drop-band td:first-child, .drop-band td.pin-end { background: #fbfaf6; }
.att thead .night-pick {
  font-size: 14px; font-weight: 700; letter-spacing: 0; text-transform: none;
  color: var(--ink); white-space: nowrap; line-height: 1.25;
}
.data-path {
  margin-top: 8px; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 14px; background: white; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; word-break: break-all;
}
.cell {
  min-width: 64px; border-radius: 8px; border: 1px solid transparent; padding: 6px 4px; background: #f7f3ea;
}
.cell.yes { background: var(--green-soft); color: var(--green-dark); }
.cell.no { background: #f3f0ea; color: var(--muted); }
.cell.partial { background: var(--gold-soft); color: #6d4a16; }
.cell.full { background: var(--rust-soft); color: var(--rust); }
.cell:hover { border-color: var(--green); }
.cell .refund-amt { display: block; font-size: 11px; font-variant-numeric: tabular-nums; }
.cell-stack { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.refund-edit { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.refund-edit input { width: 76px; padding: 3px 6px; font-size: 12px; text-align: right; }
.badge {
  display: inline-block; font-size: 10px; letter-spacing: 0.04em; text-transform: uppercase;
  background: var(--gold-soft); color: #6d4a16; border-radius: 999px; padding: 1px 6px;
}
.manual-money, .calc-amt { display: inline-flex; flex-direction: column; align-items: flex-end; gap: 3px; min-width: 96px; }
.lock-icon { display: inline-block; vertical-align: -2px; margin-left: 8px; color: var(--gold); }
.season-link .lock-icon { width: 14px; height: 14px; margin-left: 6px; color: #f6f1e6; flex: none; }
.buyin-preview { width: 100%; height: auto; border-radius: 12px; border: 1px solid var(--line); background: white; }
input:disabled, select:disabled, textarea:disabled, button:disabled { opacity: 0.55; }
.manual-money input {
  width: 96px; text-align: right; background: #fffdf8; border-color: #e0c48a;
  -webkit-app-region: no-drag; app-region: no-drag; user-select: text;
}
.tiny { padding: 4px 8px; font-size: 12px; }
.night-rules { margin-top: 16px; margin-bottom: 16px; }
.cell-stack { position: relative; }
.tip {
  display: none; position: absolute; z-index: 6; left: 0; top: calc(100% + 4px); width: 240px;
  background: #143d28; color: #f7f3ea; border-radius: 10px; padding: 8px 10px; font-size: 12px; text-align: left;
  box-shadow: 0 12px 30px rgba(20, 40, 30, 0.2);
}
.tip span { display: block; margin: 3px 0; }
.cell-stack:hover .tip, .cell-stack.tip-open .tip { display: block; }
details.night-card { border: 1px solid var(--line); border-radius: 14px; background: white; margin: 8px 0; padding: 8px 12px; }
details.night-card summary { cursor: pointer; font-weight: 650; }
.night-body { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 10px; }
.night-body span, .night-body small { display: block; color: var(--muted); font-size: 12px; }
.night-body strong { font-size: 18px; }
.refund-list { margin: 8px 0 0; padding-left: 18px; }
.pay-board { display: grid; grid-template-columns: repeat(3, minmax(220px, 1fr)); gap: 8px; margin-top: 10px; }
.pay-row {
  display: flex; align-items: center; justify-content: flex-start; gap: 10px;
  margin: 0; padding: 8px 12px; border: 1px solid var(--line); border-radius: 12px;
  background: white; cursor: pointer; min-height: 44px;
}
.pay-row .pay-name { font-weight: 650; }
.pay-row .pay-amt { color: var(--muted); font-variant-numeric: tabular-nums; }
.pay-row.is-paid { background: var(--green-soft); border-color: #c9e4d4; }
.pay-row.is-paid .pay-name { color: var(--green-dark); }
.pay-summary { display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: center; }
.roster-tools { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.roster-tools button { padding: 2px 6px; }
.drag-handle { cursor: grab; padding: 2px 6px; border: 1px solid var(--line); border-radius: 8px; background: white; user-select: none; }
tr.dragging { opacity: 0.55; }
.fee-edit { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.fee-edit input { width: 72px; padding: 3px 6px; text-align: right; }
.chart-block { margin: 8px 0 14px; }
.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; margin: 0 0 6px; color: var(--muted); font-size: 13px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 18px; height: 3px; border-radius: 99px; display: inline-block; }
.swatch.rate { background: var(--green); }
.swatch.cost { background: var(--gold); }
.cost-chart { width: 100%; height: auto; display: block; background: white; border: 1px solid var(--line); border-radius: 12px; }
tr.totals td { font-weight: 700; border-top: 1px solid var(--line); }
button.is-default { box-shadow: 0 0 0 3px rgba(30, 107, 67, 0.28); }
@media (max-width: 980px) { .pay-board { grid-template-columns: 1fr; } }
.wizard-steps { display: flex; gap: 12px; color: var(--muted); font-size: 13px; margin-top: 6px; }
.wizard-steps .on { color: var(--green-dark); font-weight: 700; }
button.linkish { background: none; border: 0; padding: 0; color: var(--green-dark); font-weight: 650; text-align: left; }
.reminder { color: #6d4a16; font-size: 12px; margin-top: 4px; max-width: 160px; }
.night-rules { margin-top: 16px; margin-bottom: 16px; }
.night-rules td .check { margin-top: 6px; font-size: 12px; }
.span { grid-column: 1 / -1; }

.status-menu {
  position: fixed; z-index: 40; background: var(--paper-2); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: 0 16px 40px rgba(20, 40, 30, 0.18); padding: 6px; min-width: 240px;
}
.status-menu button { display: block; width: 100%; text-align: left; background: transparent; border: 0; border-radius: 8px; padding: 8px 10px; }
.status-menu button:hover { background: var(--green-soft); }

.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.field.wide { grid-column: 1 / -1; }
input, select, textarea {
  background: white; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; width: 100%;
  -webkit-app-region: no-drag; app-region: no-drag; user-select: text;
}
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; padding: 0; flex: 0 0 auto; }
textarea { min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #cfe3d6; border-color: var(--green); }
.check { display: flex; gap: 8px; align-items: center; color: var(--ink); }

.help { color: var(--muted); font-size: 14px; }
.help li { margin: 6px 0; }
.steps { margin: 8px 0 0; padding-left: 18px; }
.steps li { margin: 6px 0; }

#toast {
  position: fixed; bottom: 18px; right: 18px; max-width: 360px; z-index: 50;
  background: var(--green-dark); color: white; padding: 12px 14px; border-radius: 12px;
  box-shadow: var(--shadow);
}
#toast.bad { background: var(--rust); }
#modal {
  position: fixed; inset: 0; background: rgba(20, 35, 28, 0.45); z-index: 45;
  display: grid; place-items: center; padding: 20px;
}
#modal[hidden], #toast[hidden] { display: none; }
.dialog {
  width: min(640px, 100%); background: var(--paper); border-radius: 18px; padding: 18px;
  border: 1px solid var(--line); max-height: min(80vh, 760px); overflow: auto;
}
.dialog pre {
  white-space: pre-wrap; background: white; border-radius: 12px; padding: 12px; border: 1px solid var(--line);
  font: 13px/1.45 ui-monospace, "Cascadia Mono", Consolas, monospace;
}
.warn-list { max-height: 280px; overflow: auto; margin: 8px 0 0; padding-left: 18px; }
.warn-list li { margin: 4px 0; }

.empty { padding: 28px; text-align: left; }
.empty h1 { font-size: 40px; margin-bottom: 8px; }

@media (max-width: 980px) {
  #app { flex-direction: column; }
  #nav { width: 100%; height: auto; position: sticky; z-index: 5; padding: 12px; }
  .nav-scroll { flex-direction: row; overflow: auto; gap: 6px; }
  .nav-label, .nav-foot { display: none; }
  .season-link, .nav-btn { width: auto; white-space: nowrap; }
  #main { padding: 18px 14px 48px; }
  .cards, .split, .fields { grid-template-columns: 1fr 1fr; }
  .top { flex-direction: column; align-items: flex-start; }
}
@media (max-width: 640px) {
  .cards, .split, .fields { grid-template-columns: 1fr; }
  .card strong { font-size: 24px; }
}

.swipe-note { display: none; }
.gate {
  max-width: 440px;
  margin: 6vh auto 0;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.gate h1 { font-size: 36px; }
.gate .field { margin-top: 4px; }
.form-error { color: var(--rust); min-height: 1.2em; margin: 0; }
.backup-list { list-style: none; padding: 0; margin: 8px 0 0; }
.backup-list li {
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center;
  justify-content: space-between;
  padding: 10px 0; border-top: 1px solid var(--line);
}

@media (max-width: 720px) {
  .history-nav { padding: 8px 12px 6px; }
  #main { padding: 4px 12px 80px; }
  h1 { font-size: 28px; }
  .empty h1 { font-size: 30px; }
  .lede { font-size: 15px; }
  .night-body { grid-template-columns: 1fr 1fr; }
  .btn, .btn-gold, .btn-quiet { min-height: 44px; }
  input, select, textarea { font-size: 16px; }
  #toast { left: 12px; right: 12px; bottom: 12px; max-width: none; }
  .dialog { width: 100%; padding: 14px; border-radius: 14px; }
  #nav { padding: 10px 8px 8px; gap: 8px; }
  .brand { padding: 0 4px; }
  .brand strong { font-size: 18px; }
  .nav-scroll { -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
  .nav-btn, .season-link { min-height: 40px; }
  .tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .tabs button { flex: none; }
  .grid-wrap { -webkit-overflow-scrolling: touch; }
  .swipe-note { display: block; color: var(--muted); font-size: 13px; margin: 0 0 8px; }
  .gate { margin-top: 12px; padding: 16px; }
  .gate h1 { font-size: 30px; }
  .pay-row { min-height: 48px; }
  .top .row, .row { gap: 8px; }
  #stage { min-height: 0; }
  body { padding-bottom: env(safe-area-inset-bottom); }
}
