:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --line: #e3e2dc;
  --accent: #2463eb;
  --accent-soft: #e8efff;
  --ok: #1d7a46;
  --danger: #c4312b;
  --danger-soft: #fdecea;
  --warn-soft: #fff6e0;
  --selected: #fff1b8;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  color: var(--text);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 24px 0 8px; }
a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pad { padding: 16px; }
.right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
[hidden] { display: none !important; }

.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  background: var(--surface); border-bottom: 1px solid var(--line); padding: 10px 16px;
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; color: var(--text); }
#nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
#nav a { padding: 6px 10px; border-radius: 8px; color: var(--muted); }
#nav a.active { background: var(--accent-soft); color: var(--accent); }
.me { display: flex; gap: 10px; align-items: center; color: var(--muted); font-size: 14px; }
.guide-link { display: inline-flex; align-items: center; gap: 4px; }
.guide-link::before { content: ""; width: 14px; height: 14px; background: currentColor; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 1v9m0 0L4.5 6.5M8 10l3.5-3.5M2 12v2h12v-2' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 1v9m0 0L4.5 6.5M8 10l3.5-3.5M2 12v2h12v-2' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat; }

main { max-width: 1280px; margin: 0 auto; padding: 16px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

button, .btn {
  font: inherit; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
button:hover:not(:disabled) { border-color: #c9c8c0; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
input, select { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; min-width: 0; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.form-row > label { flex: 1 1 140px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.club-card { display: block; color: var(--text); }
.club-card:hover { border-color: var(--accent); }
.club-card .title { font-weight: 600; font-size: 16px; margin-bottom: 6px; }

.month-switch { display: inline-flex; align-items: center; gap: 4px; }
.month-switch .label { min-width: 130px; text-align: center; font-weight: 600; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--line); color: var(--muted); }
.badge.locked { background: #ececec; color: #444; }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.good { background: #e6f4ec; color: var(--ok); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-weight: 500; color: var(--muted); font-size: 13px; white-space: nowrap; background: var(--surface); }
tbody tr:hover td { background: #fafaf7; }
tr.clickable { cursor: pointer; }
tfoot td { font-weight: 600; border-bottom: 0; }
tfoot .sub { font-weight: 400; }
.grand-total { text-align: right; font-size: 17px; font-weight: 700; padding: 12px 4px; }

.grid th.sticky, .grid td.sticky { position: sticky; left: 0; z-index: 2; background: var(--surface); box-shadow: 1px 0 0 var(--line); }
.grid .student { min-width: 160px; max-width: 220px; }
.grid .student button { text-align: left; padding: 0; border: 0; background: none; color: var(--text); display: block; }
.grid .student .sub { font-size: 12px; color: var(--muted); }
.grid th.date { text-align: center; min-width: 58px; }
.grid th.date button { border: 0; background: none; padding: 2px 4px; color: inherit; font-size: 13px; }
.grid td.cell { text-align: center; padding: 0; min-width: 58px; }
.cell-inner { position: relative; height: 44px; display: flex; align-items: center; justify-content: center; }
.cell-toggle { width: 100%; height: 100%; border: 0; background: none; border-radius: 0; justify-content: center; font-size: 18px; color: var(--text); padding: 0; }
.cell-toggle:disabled { opacity: 1; cursor: default; }
.receipt-dot {
  position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; padding: 0; border: 0; border-radius: 50%;
  background: radial-gradient(circle, var(--accent) 0 5px, #fff 5px 6px, var(--accent) 6px 7px, transparent 7px);
}
td.cell.no_receipt .cell-inner, td.cell.extra_receipt .cell-inner { background: var(--danger-soft); box-shadow: inset 0 0 0 2px #e79a96; border-radius: 6px; margin: 3px; height: 38px; }
td.cell.selected .cell-inner { background: var(--selected); box-shadow: inset 0 0 0 2px #e0b800; }
td.cell.highlight .cell-inner { box-shadow: inset 0 0 0 2px var(--accent); border-radius: 6px; }
tr.left td.sticky .name { color: var(--muted); }

.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-top: 8px; }
.legend .sw { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; margin-right: 4px; }

.banner { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.banner.info { background: var(--accent-soft); }
.banner.warn { background: var(--warn-soft); }
.banner.locked { background: #efefec; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat .v { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat.bad .v { color: var(--danger); }

.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 20, 18, .35); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 12px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 520px; padding: 18px; box-shadow: 0 12px 40px rgba(0,0,0,.18); }
.modal.wide { max-width: 860px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.receipt-view img { max-width: 100%; max-height: 70vh; object-fit: contain; border-radius: 8px; border: 1px solid var(--line); }
.receipt-view iframe { width: 100%; height: 60vh; border: 1px solid var(--line); border-radius: 8px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 60; max-width: 90vw; }
#toast.show { opacity: 1; }
#toast.error { background: var(--danger); }

.login { max-width: 360px; margin: 10vh auto; }
.login form { display: flex; flex-direction: column; gap: 12px; }
.error { color: var(--danger); font-size: 14px; }

@media (max-width: 640px) {
  main { padding: 10px; }
  .topbar { padding: 8px 10px; gap: 8px; }
  .me #me-name { display: none; }
  .grid .student { min-width: 120px; }
  th, td { padding: 6px 8px; }
  .hide-sm { display: none; }
}
