:root {
  --court: #0e4d64;
  --court-dark: #0a3a4c;
  --court-soft: #e7f0f3;
  --ball: #e4f24a;
  --ball-soft: #f6fbc6;
  --bg: #ffffff;
  --ink: #142a33;
  --muted: #5b6f77;
  --line: #dce6ea;
  --danger: #b3261e;
  --danger-soft: #fdecea;
  --ok: #1b7a44;
  --radius: 16px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }

.wrap { max-width: 560px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }

/* ----- Đầu trang ----- */
.top { background: var(--court); color: #fff; padding: 16px 0 14px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -0.01em; }
.brand p { margin: 0; font-size: 14px; opacity: 0.8; }
.ball {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 35% 35%, #f3fb8f, var(--ball) 60%, #c9d63a);
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0.06);
}
.who { margin-top: 12px; font-size: 15px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 24px; }
.who b { color: var(--ball); }
.who button {
  background: rgba(255, 255, 255, 0.14); border: 0; color: #fff;
  padding: 4px 12px; border-radius: 999px; font-size: 14px;
}

/* ----- Chọn ngày ----- */
.days {
  display: flex; gap: 8px; overflow-x: auto; padding: 14px 0 6px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.days::-webkit-scrollbar { display: none; }
.day {
  flex: none; border: 2px solid var(--line); background: #fff; border-radius: 14px;
  padding: 8px 12px; min-width: 76px; text-align: center; line-height: 1.2;
}
.day b { display: block; font-size: 16px; }
.day small { font-size: 13px; color: var(--muted); }
.day.on { border-color: var(--court); background: var(--court); color: #fff; }
.day.on small { color: var(--ball); }
.day.off small { color: var(--danger); }
.day.on.off small { color: #ffb4ab; }

/* ----- Thẻ buổi ----- */
.card {
  border: 1px solid var(--line); border-radius: var(--radius);
  margin: 12px 0 20px; overflow: hidden; background: #fff;
}
.card-head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 16px; background: var(--court-soft);
}
.card-head h2 { margin: 0; font-size: 22px; font-weight: 800; }
.card-head .meta { color: var(--muted); font-size: 15px; }
.count {
  flex: none; text-align: center; background: var(--court); color: #fff;
  border-radius: 14px; padding: 6px 12px; line-height: 1.1; min-width: 64px;
}
.count b { display: block; font-size: 26px; color: var(--ball); }
.count span { font-size: 12px; }

.status { padding: 10px 16px; font-size: 15px; font-weight: 600; border-bottom: 1px solid var(--line); }
.status.open { background: var(--ball-soft); color: #4d5200; }
.status.locked { background: #f1f3f4; color: var(--muted); }
.status.cancelled { background: var(--danger-soft); color: var(--danger); }

.money { padding: 14px 16px 4px; }
.money .big { font-size: 20px; font-weight: 800; }
.money .sub { font-size: 14px; color: var(--muted); }
.need { margin: 8px 16px 0; font-size: 14px; color: var(--danger); font-weight: 600; }

.grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 14px 16px 16px;
}
.member {
  position: relative; min-height: 58px; border-radius: 14px;
  border: 2px solid var(--line); background: #fff;
  font-size: 18px; font-weight: 600; text-align: left; padding: 10px 12px 10px 44px;
  transition: transform 0.08s ease;
}
.member:active { transform: scale(0.97); }
.member::before {
  content: ''; position: absolute; left: 12px; top: 50%; width: 22px; height: 22px;
  margin-top: -11px; border-radius: 50%; border: 2px solid var(--line); background: #fff;
}
.member.voted { background: var(--ball); border-color: #c4d12b; color: #1e2a00; }
.member.voted::before {
  border-color: var(--court); background: var(--court)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 12.5l4.2 4.2L19 7' fill='none' stroke='%23e4f24a' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")
    center / 16px no-repeat;
}
.member.me { box-shadow: 0 0 0 3px rgba(14, 77, 100, 0.25); }
.member .tag { display: block; font-size: 12px; font-weight: 500; opacity: 0.7; }
.member.pending { opacity: 0.6; }
.card.closed .member { cursor: default; }

.extra { padding: 0 16px 16px; font-size: 15px; }
.extra p { margin: 6px 0 0; }

.loading, .empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* ----- Hộp nhập mã ----- */
.modal {
  position: fixed; inset: 0; background: rgba(10, 30, 38, 0.55);
  display: flex; align-items: flex-end; justify-content: center; z-index: 20;
}
.modal[hidden] { display: none; }
.sheet {
  background: #fff; width: 100%; max-width: 480px; border-radius: 22px 22px 0 0;
  padding: 22px 20px calc(20px + env(safe-area-inset-bottom));
  animation: up 0.18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@media (min-width: 600px) {
  .modal { align-items: center; }
  .sheet { border-radius: 22px; }
}
.sheet h2 { margin: 0 0 4px; font-size: 22px; }
.sheet p { margin: 0 0 14px; }
.code-input {
  width: 100%; font-size: 34px; letter-spacing: 0.5em; text-align: center; font-weight: 700;
  padding: 12px 0 12px 0.5em; border: 2px solid var(--line); border-radius: 14px; outline: none;
}
.code-input:focus { border-color: var(--court); }
.error { color: var(--danger); font-weight: 600; margin: 10px 0 0 !important; }
.check { display: flex; align-items: center; gap: 8px; margin: 14px 0 4px; font-size: 15px; }
.check input { width: 20px; height: 20px; accent-color: var(--court); }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.btn { flex: 1; min-height: 52px; border-radius: 14px; border: 0; font-weight: 700; font-size: 17px; }
.btn.primary { background: var(--court); color: #fff; }
.btn.ghost { background: #eef2f3; }
.btn:disabled { opacity: 0.6; }

/* ----- Thanh mục ----- */
.tabs { display: flex; gap: 6px; margin-top: 14px; }
.tabs a {
  flex: 1; text-align: center; padding: 10px 6px; border-radius: 12px;
  color: #fff; text-decoration: none; font-weight: 600; font-size: 15px;
  background: rgba(255, 255, 255, 0.1);
}
.tabs a.on { background: var(--ball); color: var(--court-dark); }

.small { font-size: 14px; }
.section-title { font-size: 18px; margin: 26px 0 10px; }
.admin-note {
  margin: 14px 0 0; padding: 10px 14px; border-radius: 12px; font-size: 14px;
  background: var(--court-soft); color: var(--court); font-weight: 600;
}
.admin-tools { padding: 0 16px 16px; display: grid; gap: 10px; }

/* ----- Nút chung ----- */
.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; padding: 0 16px; }
.btn.small { min-height: 42px; font-size: 15px; border-radius: 12px; flex: none; }
.btn.full { width: 100%; margin-top: 10px; }
.btn.icon { flex: none; width: 48px; padding: 0; font-size: 22px; }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.admin-tools .btn.small { background: var(--court-soft); color: var(--court); }
.link { background: none; border: 0; color: var(--court); text-decoration: underline; font-size: 15px; padding: 6px 0; }

/* ----- Tin nhắn có nút sao chép ----- */
.copybox { border: 1px dashed #b9cbd2; border-radius: 14px; background: #f8fbfc; overflow: hidden; }
.copy-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 8px 8px 14px; border-bottom: 1px dashed #d3e0e5; font-size: 15px; }
.btn-copy { border: 0; background: var(--court); color: #fff; border-radius: 10px; padding: 8px 14px; font-weight: 700; font-size: 14px; }
.copybox pre {
  margin: 0; padding: 12px 14px; white-space: pre-wrap; word-break: break-word;
  font-family: inherit; font-size: 15px; line-height: 1.5;
  -webkit-user-select: text; user-select: text;
}

/* ----- Tổng kết tháng ----- */
.month-bar { display: flex; align-items: center; gap: 10px; margin: 16px 0 4px; }
.month-bar label { font-weight: 700; }
select, .input {
  font: inherit; font-size: 16px; width: 100%; min-height: 48px; padding: 10px 12px;
  border: 2px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink);
}
select:focus, .input:focus { outline: none; border-color: var(--court); }
textarea.input { resize: vertical; min-height: 80px; }
.month-bar select { flex: 1; font-weight: 700; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.stat { background: var(--court-soft); border-radius: 14px; padding: 12px 14px; }
.stat span { display: block; font-size: 13px; color: var(--muted); }
.stat b { font-size: 20px; font-weight: 800; }
.stat b.ok { color: var(--ok); }
.stat b.bad { color: var(--danger); }
.progress { position: relative; height: 30px; border-radius: 999px; background: #eef2f3; margin: 12px 0 18px; overflow: hidden; }
.progress div { height: 100%; background: linear-gradient(90deg, var(--court), #1a7a9c); border-radius: 999px; transition: width 0.3s; }
.progress span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; mix-blend-mode: difference; color: #fff; }

.table { width: 100%; border-collapse: collapse; font-size: 16px; }
.table th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 600; padding: 6px 6px; border-bottom: 2px solid var(--line); }
.table td { padding: 10px 6px; border-bottom: 1px solid var(--line); }
.table .num { text-align: right; white-space: nowrap; }
.table .paid { text-align: center; width: 72px; }
.table tfoot td { font-weight: 800; border-bottom: 0; }
.yes { color: var(--ok); font-weight: 700; font-size: 14px; }
.no { color: var(--muted); font-size: 14px; }
.paybox { display: inline-block; position: relative; width: 34px; height: 34px; }
.paybox input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.paybox span { position: absolute; inset: 0; border: 2px solid var(--line); border-radius: 10px; background: #fff; pointer-events: none; }
.paybox input:checked + span {
  background: var(--ok) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 12.5l4.2 4.2L19 7' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 20px no-repeat;
  border-color: var(--ok);
}
.paybox input:focus-visible + span { box-shadow: 0 0 0 3px rgba(14, 77, 100, 0.3); }

.sess-list { list-style: none; margin: 0 0 30px; padding: 0; }
.sess { padding: 12px 0; border-bottom: 1px solid var(--line); }
.sess-top { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; }
.sess-money { margin-left: auto; font-weight: 700; color: var(--court); font-size: 15px; }
.sess-names { font-size: 14px; color: var(--muted); margin-top: 2px; }
.sess.off { color: var(--muted); font-size: 15px; }
.sess.off span { color: var(--danger); }

/* ----- Quản trị ----- */
.panel { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 14px 0; background: #fff; }
.panel h2 { margin: 0 0 6px; font-size: 22px; }
.panel h3 { margin: 4px 0 10px; font-size: 18px; }
.panel h4 { margin: 16px 0 8px; font-size: 15px; }
.panel .input { margin-top: 6px; }
.panel label { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin-top: 10px; }
.panel label.check { display: flex; color: var(--ink); font-weight: 500; }
.panel summary { cursor: pointer; font-weight: 700; color: var(--court); padding: 4px 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row2 > label { margin-top: 10px; }
.admin-head { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; }
.badge { background: var(--ball); color: var(--court-dark); font-weight: 800; font-size: 13px; padding: 4px 10px; border-radius: 999px; }
.badge.small { font-size: 11px; padding: 2px 8px; vertical-align: middle; }
.subtabs { display: flex; gap: 6px; overflow-x: auto; margin: 12px 0 4px; padding-bottom: 4px; scrollbar-width: none; }
.subtabs::-webkit-scrollbar { display: none; }
.subtabs button { flex: none; border: 2px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 14px; font-weight: 600; font-size: 15px; }
.subtabs button.on { background: var(--court); border-color: var(--court); color: #fff; }

.day-pick { display: flex; gap: 8px; margin-top: 12px; }
.day-pick .input { text-align: center; font-weight: 700; }
.editor-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.editor-head h3 { margin: 0; }
.chip { flex: none; font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: #eef2f3; color: var(--muted); }
.chip.ok { background: var(--ball-soft); color: #4d5200; }
.chip.bad { background: var(--danger-soft); color: var(--danger); }
.money-line { margin: 8px 0 0; font-weight: 700; color: var(--court); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.pchip {
  border: 2px solid var(--line); background: #fff; border-radius: 999px;
  padding: 8px 14px; font-size: 15px; font-weight: 600; min-height: 42px;
}
.pchip.on { background: var(--ball); border-color: #c4d12b; }
.pchip.guest { display: inline-flex; align-items: center; gap: 6px; padding-right: 6px; }
.pchip.guest button { border: 0; background: rgba(0, 0, 0, 0.08); border-radius: 50%; width: 28px; height: 28px; font-size: 13px; }
.inline { display: flex; gap: 8px; margin-top: 10px; }
.inline .input { margin: 0; }
.inline .btn { flex: none; min-height: 48px; }
details.more { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 10px; }
.editor .copybox { margin-top: 14px; }

.member-row.inactive { background: #f6f7f8; }
.member-row .row2 > label:first-child { margin-top: 0; }
.member-row .row2 > label { margin-top: 0; }
.input.code { letter-spacing: 0.25em; font-weight: 700; }
.member-actions { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.member-actions .check { margin: 0 auto 0 0 !important; }

.price-row {
  display: grid; grid-template-columns: 1fr 1fr 44px; gap: 0 8px; align-items: end;
  padding: 4px 0 12px; margin-bottom: 4px; border-bottom: 1px solid var(--line);
}
.price-row label { margin-top: 6px !important; font-size: 13px !important; }
.price-row .input { margin-top: 4px; min-height: 44px; padding: 8px 10px; }
.price-row .btn.icon { grid-row: 1 / span 2; grid-column: 3; align-self: center; width: 44px; min-height: 44px; font-size: 16px; }
.price-row label:nth-of-type(3) { grid-column: 1; }
.price-row label:nth-of-type(4) { grid-column: 2; }

/* ----- Thông báo nhỏ ----- */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 12px 18px; border-radius: 12px; font-size: 15px; z-index: 30;
  max-width: calc(100% - 32px); text-align: center; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}
.toast.bad { background: var(--danger); }
