/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue:    #1a3a6b;
  --gold:    #c9a84c;
  --gold-lt: #f0d585;
  --green:   #2e7d32;
  --red:     #c62828;
  --gray:    #f4f5f7;
  --border:  #c8cdd6;
  --text:    #1a1a2e;
  --muted:   #6b7280;
  --white:   #ffffff;
  --radius:  6px;
  --shadow:  0 2px 8px rgba(0,0,0,.12);

  /* Bracket geometry */
  --game-w:       158px;
  --game-h:       70px;    /* meta(26) + team(22) + team(22) */
  --meta-h:       26px;
  --team-h:       22px;
  --pair-gap:     0px;     /* gap within a pair (0 = games touch directly) */
  --between-pairs:28px;    /* gap between pairs in a round column */
  --round-gap:    18px;    /* horiz gap between round columns (= conn-w) */
  --conn-w:       18px;    /* connector width — MUST equal round-gap */
  --conn-color:   #6b8098; /* bracket line color */
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--gray);
  color: var(--text);
  min-height: 100vh;
}

/* ── Header ───────────────────────────────────────────────── */
header {
  background: var(--blue);
  color: var(--white);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.header-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: .4rem 1rem .3rem;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}
.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 32px;
}
header h1 {
  font-size: 1.05rem;
  font-weight: 700;
  white-space: nowrap;
  color: var(--gold);
}
#division-nav {
  display: flex;
  gap: .4rem;
  overflow-x: auto;
  padding-bottom: .25rem;
  scrollbar-width: none;
}
#division-nav::-webkit-scrollbar { display: none; }
.nav-btn {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.45);
  color: var(--white);
  padding: .35rem .75rem;
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
  font-size: .8rem;
  transition: background .15s, border-color .15s;
}
.nav-btn:hover  { background: rgba(255,255,255,.2); }
.nav-btn.active { background: var(--gold); border-color: var(--gold); color: var(--blue); font-weight: 700; }

/* Admin nav sits on white/gray background — needs dark text */
#admin-nav .nav-btn {
  background: var(--white);
  border-color: var(--border);
  color: var(--blue);
}
#admin-nav .nav-btn:hover  { background: var(--gray); }
#admin-nav .nav-btn.active { background: var(--gold); border-color: var(--gold); color: var(--blue); }
.admin-link {
  color: rgba(255,255,255,.6);
  text-decoration: none;
  font-size: .75rem;
  white-space: nowrap;
  padding: .25rem .5rem;
  border-radius: 4px;
}
.admin-link:hover  { color: var(--white); }
.results-link {
  color: rgba(255,255,255,.6);
  text-decoration: none;
  font-size: .75rem;
  white-space: nowrap;
  padding: .25rem .5rem;
  border-radius: 4px;
}
.results-link:hover { color: var(--white); }

/* ── Main content ─────────────────────────────────────────── */
main {
  max-width: 1600px;
  margin: 1.5rem auto;
  padding: 0 1rem 5rem;  /* extra bottom for sticky sponsor banner */
}
.loading {
  text-align: center;
  padding: 4rem;
  color: var(--muted);
  font-size: 1.1rem;
}

/* ── Division header ──────────────────────────────────────── */
.division-header { margin-bottom: 1rem; }
.division-header h2 {
  font-size: 1.4rem;
  color: var(--blue);
  font-weight: 800;
  letter-spacing: .01em;
}
.division-header p {
  color: var(--muted);
  font-size: .8rem;
  margin-top: .2rem;
}

/* ── Bracket scroll wrapper ───────────────────────────────── */
.bracket-scroll {
  overflow-x: auto;
  padding-bottom: .5rem;
}

/* ── Wrapper: grows to content width, scrolls as one unit ─── */
.bracket-wrapper {
  display: flex;
  flex-direction: column;
  width: max-content;
  min-width: 100%;
}

/* ─────────────────────────────────────────────────────────── */
/* ── Bracket body: [bracket-main] + [finals-col]             */
/* ─────────────────────────────────────────────────────────── */
.bracket-body {
  position: relative;   /* SVG connector overlay anchors here */
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: var(--round-gap);
  width: max-content;
  min-width: 100%;
}

/* ── bracket-main: Winners section + drop zone + Consol section */
.bracket-main {
  display: flex;
  flex-direction: column;
  flex: 1;
}

/* ── Each bracket section (winners / consolation) ─────────── */
.bracket-section {
  display: flex;
  flex-direction: column;
}

/* Section heading: "WINNERS BRACKET" / "CONSOLATION BRACKET" */
.section-label {
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  margin-bottom: .5rem;
  white-space: nowrap;
}

/* ── Rounds row: horizontal flow left → right ─────────────── */
.rounds-row {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: var(--round-gap);
}

/* ── Consolation rounds offset: indent to align C R2 with Winners R2 ─────── */
/* C R2 (first consol column) should start at the same x as W R2, not R1.   */
.consol-rounds-row {
  padding-left: calc(var(--game-w) + var(--round-gap));
}

/* ── Drop zone: divider between winners and consolation ─────── */
.drop-zone {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .9rem 0 .75rem;
}
.drop-rule {
  flex: 1;
  border-bottom: 1px dashed var(--border);
}
.drop-label {
  font-size: .68rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  letter-spacing: .04em;
}

/* ── Round column ─────────────────────────────────────────── */
.bracket-round {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--between-pairs);
  flex: 0 0 auto;
}
.round-lbl {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin-bottom: .1rem;
  white-space: nowrap;
}

/* ── Bracket pair / solo ──────────────────────────────────── */
/* All games render as bracket-solo for per-game vertical      */
/* positioning (positionGames in app.js). bracket-pair kept   */
/* for admin view compatibility but not used in public view.  */
.bracket-pair {
  display: flex;
  flex-direction: column;
  gap: 0;
  position: relative;
}
.bracket-solo { /* no extra styling needed */ }

/* ─────────────────────────────────────────────────────────── */
/* Connector lines are drawn by SVG in app.js (drawConnectors) */
/* using actual measured DOM positions for accuracy.           */
/* ─────────────────────────────────────────────────────────── */

/* ── Game slot ────────────────────────────────────────────── */
.bracket-game {
  position: relative;
  width: var(--game-w);
  height: var(--game-h);
  background: var(--white);
  border: 1.5px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
  flex-shrink: 0;
  transition: box-shadow .12s, border-color .12s;
  cursor: default;
  z-index: 1;  /* paint above the SVG connector layer */
}

/* Admin: clickable games get a blue left accent + pointer */
.bracket-game.admin-clickable {
  cursor: pointer;
  border-left: 3px solid var(--blue);
}
.bracket-game.admin-clickable:hover {
  box-shadow: 0 3px 12px rgba(26,58,107,.22);
  border-color: var(--blue);
}
.bracket-game.admin-clickable:active {
  box-shadow: 0 1px 4px rgba(26,58,107,.18);
}

/* Unplayed admin games: blue-tinted meta row so they stand out */
.bracket-game.needs-score .slot-meta {
  background: #dbeafe;
  border-bottom-color: #93c5fd;
}
.bracket-game.needs-score .sched-day,
.bracket-game.needs-score .sched-time {
  color: var(--blue);
  font-weight: 600;
}

/* Meta row (schedule + status badge) */
.slot-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--meta-h);
  padding: 2px 5px;
  background: var(--gray);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  gap: 3px;
}
/* Two-line schedule: day on top, time·location below */
.slot-sched {
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.sched-day {
  font-size: .57rem;
  color: var(--muted);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sched-time {
  font-size: .57rem;
  color: var(--muted);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Role badges in Users table */
.role-badge {
  display: inline-block;
  font-size: .65rem;
  font-weight: 700;
  padding: .1rem .38rem;
  border-radius: 3px;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.role-badge.role-admin  { background: var(--blue); color: #fff; }
.role-badge.role-editor { background: #6b8098;     color: #fff; }

/* Gym location map link — appears inside game cards and venue key */
.loc-link {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
}
.loc-link:hover { color: var(--blue); border-bottom-color: var(--blue); }

/* Sequential game label (G1, G2…) — shown inline after the day */
.game-lbl {
  font-size: .57rem;
  font-weight: 700;
  color: var(--blue);
  opacity: .75;
  letter-spacing: .02em;
}

/* Status badges */
.gbadge {
  font-size: .58rem;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 2px;
  margin-left: 3px;
  flex-shrink: 0;
  white-space: nowrap;
}
.gbadge.ot    { background: var(--red);   color: var(--white); }
.gbadge.live  { background: #fff3cd;      color: #856404; }
.gbadge.final { background: #d4edda;      color: var(--green); }
.gbadge.tap   { background: var(--blue);  color: var(--white); font-size: .57rem; padding: 1px 5px; letter-spacing: .02em; }

/* Team rows */
.slot-team {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--team-h);
  padding: 0 6px;
  border-bottom: 1px solid var(--border);
  gap: 4px;
  overflow: hidden;
}
.slot-team:last-child { border-bottom: none; }
.slot-team.winner {
  background: #e8f5e9;
}
.slot-team.winner .slot-name {
  font-weight: 800;
  color: var(--green);
}
.slot-team.winner .slot-score {
  color: var(--green);
  font-weight: 800;
}
.slot-team.loser {
  opacity: .45;
  text-decoration: line-through;
  text-decoration-color: #aaa;
}
.slot-name {
  font-size: .78rem;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.slot-name.tbd { color: var(--muted); font-style: italic; }
.slot-score {
  font-size: .88rem;
  font-weight: 700;
  min-width: 22px;
  text-align: right;
  color: var(--text);
  flex-shrink: 0;
}

/* Championship / 3rd place game special borders */
.champ-game { border-color: var(--gold); }
.champ-game .slot-meta { background: #fffbea; }
.third-game { border-color: #a1887f; }

/* ── Finals column (Championship + 3rd Place) ─────────────── */
.finals-col {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;  /* positionGames() sets margin-top to place games */
  align-self: stretch;
  padding-left: var(--round-gap);
  border-left: 2px solid var(--gold);
  flex-shrink: 0;
}
.finals-entry { display: flex; flex-direction: column; gap: 4px; }
.finals-lbl {
  font-size: .6rem;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--gold);
}

/* ── Venue key ────────────────────────────────────────────── */
.venue-key {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .35rem .6rem;
  margin-top: .6rem;
  padding-top: .65rem;
  border-top: 1px solid var(--border);
}
.venue-key-label {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  flex-shrink: 0;
}
.venue-item {
  display: inline-flex;
  align-items: center;
  gap: .2rem;
  font-size: .72rem;
  color: var(--muted);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .1rem .45rem;
}
.venue-item strong {
  color: var(--blue);
  font-weight: 700;
}

/* ── Legend ───────────────────────────────────────────────── */
.bracket-legend {
  display: flex;
  gap: 1rem;
  margin-top: 1.25rem;
  font-size: .72rem;
  color: var(--muted);
}
.li { display: flex; align-items: center; gap: .3rem; }
.ldot {
  width: 9px; height: 9px; border-radius: 50%;
}
.ldot.win { background: var(--green); }
.ldot.ot  { background: var(--red);   }
.ldot.lv  { background: #856404;      }

/* ── Modal overlay ────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
  width: 100%;
  max-width: 420px;
  overflow: hidden;
}

/* Mobile: full-screen modal for easier score entry */
@media (max-width: 500px) {
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    border-radius: var(--radius) var(--radius) 0 0;
    max-width: 100%;
    max-height: 90vh;
    overflow-y: auto;
  }
}
.modal-header {
  background: var(--blue);
  color: var(--white);
  padding: .9rem 1.2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h3 { font-size: 1rem; }
.modal-close {
  background: transparent;
  border: none;
  color: var(--white);
  font-size: 1.3rem;
  cursor: pointer;
  line-height: 1;
}
.modal-body { padding: 1.2rem; }
.modal-body label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  margin-bottom: .3rem;
  color: var(--muted);
}
.modal-body input[type=number],
.modal-body input[type=text],
.modal-body input[type=password],
.modal-body select {
  width: 100%;
  padding: .6rem .75rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;       /* larger for mobile readability */
  margin-bottom: .9rem;
  outline: none;
  transition: border-color .15s;
  min-height: 44px;      /* Apple HIG minimum touch target */
}

/* Score inputs extra-large for easy tapping */
#score-input-1, #score-input-2 {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  padding: .5rem;
  min-height: 56px;
}
.modal-body input:focus,
.modal-body select:focus { border-color: var(--blue); }
.score-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: .75rem;
  align-items: end;
  margin-bottom: .9rem;
}
.score-row .vs {
  text-align: center;
  font-weight: 700;
  color: var(--muted);
  padding-bottom: .5rem;
}
.checkbox-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .9rem;
}
.checkbox-row input { width: auto; margin: 0; }
.checkbox-row label { margin: 0; font-size: .875rem; color: var(--text); }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: .65rem 1.4rem;
  border: none;
  border-radius: 6px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;      /* touch-friendly */
  transition: opacity .15s;
}
.btn:hover { opacity: .85; }
.btn-primary   { background: var(--blue);  color: var(--white); }
.btn-success   { background: var(--green); color: var(--white); }
.btn-secondary { background: var(--gray);  color: var(--text); border: 1px solid var(--border); }
.btn-danger    { background: var(--red);   color: var(--white); }
.modal-footer {
  padding: .75rem 1.2rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
}
.error-msg {
  color: var(--red);
  font-size: .8rem;
  margin-top: -.6rem;
  margin-bottom: .6rem;
}

/* ── Admin login page ─────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--blue);
}
.login-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  width: 100%;
  max-width: 340px;
}
.login-card h2 {
  color: var(--blue);
  margin-bottom: 1.5rem;
  text-align: center;
}

/* ── Admin dashboard ──────────────────────────────────────── */
.admin-bar {
  background: var(--blue);
  color: var(--white);
  padding: .75rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  justify-content: space-between;
}
.admin-bar h2 { font-size: 1rem; color: var(--gold); }
.admin-bar .user-info { font-size: .8rem; opacity: .7; }
.admin-bar-actions { display: flex; gap: .5rem; }
.admin-note {
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: 6px;
  padding: .6rem .9rem;
  font-size: .8rem;
  color: #856404;
  margin-bottom: 1rem;
}

/* ── Stats cards ──────────────────────────────────────────── */
.stat-card {
  background: var(--white);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  min-width: 140px;
}
.stat-num {
  font-size: 2rem;
  font-weight: 800;
  color: var(--blue);
  line-height: 1;
}
.stat-lbl {
  font-size: .72rem;
  color: var(--muted);
  margin-top: .25rem;
}

/* ── Audit log ────────────────────────────────────────────── */
.audit-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .8rem;
}
.audit-table th {
  background: var(--gray);
  border-bottom: 2px solid var(--border);
  padding: .5rem .75rem;
  text-align: left;
  font-weight: 600;
  color: var(--muted);
}
.audit-table td {
  padding: .45rem .75rem;
  border-bottom: 1px solid var(--border);
}
.audit-table tr:hover td { background: #f9fafb; }

/* ── Admin form inputs (gyms / users views, outside modals) ─ */
.form-input {
  padding: .4rem .65rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: .85rem;
  outline: none;
  transition: border-color .15s;
  min-height: 36px;
  background: var(--white);
}
.form-input:focus { border-color: var(--blue); }

/* ── Admin hamburger menu (mobile) ───────────────────────── */
.admin-hamburger {
  display: none;
  background: transparent;
  border: 1px solid rgba(255,255,255,.4);
  color: var(--white);
  font-size: 1.3rem;
  line-height: 1;
  padding: .3rem .55rem;
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
}
.admin-hamburger:hover { background: rgba(255,255,255,.15); }

@media (max-width: 700px) {
  .admin-bar {
    flex-wrap: wrap;
    gap: .4rem .5rem;
  }
  .admin-bar > div:first-child {
    flex: 1;
    min-width: 0;
  }
  .admin-hamburger {
    display: block;
  }
  /* hide the inline button row on mobile */
  .admin-bar-actions {
    display: none;
    width: 100%;
    flex-direction: column;
    gap: .3rem;
    padding-top: .6rem;
    margin-top: .15rem;
    border-top: 1px solid rgba(255,255,255,.2);
  }
  .admin-bar-actions.mobile-open {
    display: flex;
  }
  /* make each nav button full-width and touch-friendly */
  .admin-bar-actions .btn {
    width: 100%;
    text-align: left;
    font-size: .9rem !important;
    padding: .65rem .9rem;
  }
}

/* ── Sponsor banner ───────────────────────────────────────── */
#sponsor-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #f0f4f8;
  border-top: 1px solid #d0d7de;
  padding: 6px 16px 5px;
  text-align: center;
  z-index: 9999;
  box-shadow: 0 -2px 8px rgba(0,0,0,.1);
}
#sb-link {
  text-decoration: none;
  color: #24292f;
  display: block;
}
.sb-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.sb-logo {
  height: 28px;
  width: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
}
.sb-name {
  font-size: 14px;
  color: #333;
}
.sb-menu {
  color: #777;
  font-size: 10px;
  letter-spacing: .5px;
  margin-top: 2px;
}
.sb-go {
  background: #7a8b2d;
  color: white;
  padding: 5px 14px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
  flex-shrink: 0;
}
#sb-link:hover .sb-go { background: #8fa033; }

@media (max-width: 400px) {
  .sb-logo { height: 22px; width: 22px; }
  .sb-name { font-size: 12px; }
  .sb-go { font-size: 11px; padding: 3px 10px; }
  .sb-menu { font-size: 9px; }
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 600px) {
  :root {
    --game-w:        142px;
    --game-h:        68px;
    --meta-h:        24px;
    --team-h:        22px;
    --pair-gap:      0px;
    --between-pairs: 22px;
    --round-gap:     14px;
    --conn-w:        14px;
  }
  .header-inner { gap: .5rem; }
  header h1 { font-size: .85rem; }
  main { padding: 0 .5rem 5rem; margin-top: .75rem; }

  .division-header p { font-size: .75rem; }

  /* Bracket: ensure horizontal scroll works smoothly on iOS */
  .bracket-scroll { -webkit-overflow-scrolling: touch; }

  /* Modal footer: stack buttons vertically on very small screens */
  .modal-footer { flex-direction: column-reverse; gap: .4rem; }
  .modal-footer .btn { width: 100%; }
}
