:root {
  --blue:       #0f2d5e;
  --blue-light: #1a4a8a;
  --gold:        #c9a227;
  --bg:          #f0f4f8;
  --white:       #ffffff;
  --text:        #1a1a1a;
  --muted:       #6b7280;
  --border:      #d1d5db;
  --radius:      8px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Libre Baskerville', Georgia, serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 16px;
  line-height: 1.5;
}

/* ── Nav ─────────────────────────────────────────── */
nav {
  background: var(--blue);
  color: white;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
}

.nav-logo img  { height: 44px; width: auto; display: block; background: white; border-radius: 6px; padding: 3px 6px; }
.nav-logo span { font-size: 1.5rem; font-weight: 700; color: var(--gold); }

.nav-title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  opacity: 0.9;
}

.nav-links {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.nav-links a {
  color: white;
  text-decoration: none;
  font-size: 0.875rem;
  opacity: 0.85;
}

.nav-links a:hover { opacity: 1; text-decoration: underline; }

.nav-user {
  font-size: 0.8125rem;
  opacity: 0.8;
}

/* ── Main ────────────────────────────────────────── */
main {
  flex: 1;
  padding: 2rem 1.5rem;
  max-width: 1500px;
  margin: 0 auto;
  width: 100%;
}

/* ── Cards ───────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 1.75rem;
}

.card-sm  { max-width: 440px; margin: 3rem auto 0; }
.card-md  { max-width: 680px; margin: 0 auto; }

/* ── Page header ─────────────────────────────────── */
.page-header { margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.5rem; font-weight: 700; color: var(--blue); }
.page-header p  { color: var(--muted); margin-top: 0.25rem; font-size: 0.875rem; }

/* ── Forms ───────────────────────────────────────── */
.form-group   { margin-bottom: 1.125rem; }
.form-row     { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.form-section { margin-bottom: 1.5rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--border); }
.form-section:last-of-type { border-bottom: none; }
.form-section-title { font-size: 0.8125rem; font-weight: 600; text-transform: uppercase;
                      letter-spacing: 0.05em; color: var(--muted); margin-bottom: 0.75rem; }

label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  margin-bottom: 0.3rem;
  color: var(--text);
}

input[type="email"],
input[type="text"],
input[type="number"],
input[type="datetime-local"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.875rem;
  color: var(--text);
  background: white;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(15,45,94,0.12);
}

/* ── Buttons ─────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.5rem 1.25rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: opacity 0.12s, background 0.12s;
  white-space: nowrap;
}

.btn:hover { opacity: 0.88; }

.btn-primary   { background: var(--blue); color: white; }
.btn-secondary { background: white; color: var(--blue); border-color: var(--blue); }
.btn-danger    { background: #dc2626; color: white; }
.btn-ghost     { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-sm        { padding: 0.25rem 0.75rem; font-size: 0.8125rem; }
.btn-block     { width: 100%; }

/* ── Flash messages ──────────────────────────────── */
.flash {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1.25rem;
  font-size: 0.875rem;
  line-height: 1.4;
}

.flash-success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.flash-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.flash-info    { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

/* ── Tables ──────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }

table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }

th {
  text-align: left;
  padding: 0.5rem 0.875rem;
  background: var(--bg);
  border-bottom: 2px solid var(--border);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

td { padding: 0.625rem 0.875rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(0,0,0,0.015); }

/* ── Badges ──────────────────────────────────────── */
.badge {
  display: inline-flex;
  padding: 0.15rem 0.5rem;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.badge-pending  { background: #fef3c7; color: #92400e; }
.badge-approved { background: #d1fae5; color: #065f46; }
.badge-rejected { background: #fee2e2; color: #991b1b; }
.badge-info     { background: #dbeafe; color: #1e40af; }

/* ── Bracket ─────────────────────────────────────── */
.bracket {
  display: flex;
  align-items: stretch;
  gap: 0;
  overflow-x: auto;
  padding-bottom: 1rem;
  min-height: 300px;
}

.bracket-round {
  display: flex;
  flex-direction: column;
  min-width: 210px;
  scroll-margin-top: 48px;
}

.bracket-round-nav { display: none; }

.bracket-round-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 0 1rem 0.5rem;
  text-align: center;
}

.bracket-matches {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.bracket-match-wrapper {
  display: flex;
  flex: 1;
  align-items: center;
  position: relative;
}

/* Outgoing connector: top match of pair — horizontal right + vertical down */
.bracket-round:not(:last-child) .bracket-match-wrapper:nth-child(odd)::after {
  content: '';
  position: absolute;
  right: 0;
  top: 50%;
  width: 1rem;
  height: 50%;
  border-top: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

/* Outgoing connector: bottom match of pair — vertical up + horizontal right */
.bracket-round:not(:last-child) .bracket-match-wrapper:nth-child(even)::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  width: 1rem;
  height: 50%;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

/* Incoming connector: horizontal line from column edge to card */
.bracket-round:not(:first-child) .bracket-match-wrapper::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  width: 1rem;
  height: 1px;
  background: var(--border);
}

.match-card {
  flex: 1;
  margin: 0.35rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: white;
  overflow: hidden;
  font-size: 0.8125rem;
}

.match-card-team {
  padding: 0.4rem 0.625rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.match-card-team:last-child { border-bottom: none; }
.match-card-team.winner { font-weight: 600; background: #eff6ff; color: var(--blue); }
.match-card--highlighted { border-color: #16a34a; box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.2); }
.match-card-team.bye { color: var(--muted); font-style: italic; }
.match-card-team.tbd { color: var(--muted); }

.match-score {
  font-size: 0.7rem;
  color: var(--muted);
  padding: 0.25rem 0.625rem;
  background: var(--bg);
  border-top: 1px solid var(--border);
  text-align: center;
}

.match-pending-badge {
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  background: #fef3c7;
  color: #92400e;
  border-top: 1px solid var(--border);
  text-align: center;
}

/* ── Admin layout ────────────────────────────────── */
.admin-nav {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0;
}

.admin-nav a {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.65);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}

.admin-nav a:hover { color: white; }
.admin-nav a.active { color: white; border-bottom-color: white; }

/* ── Utilities ───────────────────────────────────── */
.text-muted   { color: var(--muted); }
.text-sm      { font-size: 0.875rem; }
.text-center  { text-align: center; }
.text-right   { text-align: right; }
.mt-1  { margin-top: 0.25rem; }
.mt-2  { margin-top: 0.5rem; }
.mt-3  { margin-top: 0.75rem; }
.mt-4  { margin-top: 1rem; }
.mt-6  { margin-top: 1.5rem; }
.mb-4  { margin-bottom: 1rem; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.flex  { display: flex; }
.divider-or {
  display: flex; align-items: center; gap: 0.75rem;
  color: var(--muted); font-size: 0.875rem; margin: 1rem 0;
}
.divider-or::before,
.divider-or::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.badge-admin { background: #ede9fe; color: #5b21b6; }
.flex-center { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.divider { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

/* ── Coming soon / empty states ─────────────────── */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--muted);
}

.empty-state h2 { font-size: 1.25rem; color: var(--text); margin-bottom: 0.5rem; }
.empty-state p  { font-size: 0.875rem; }

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 640px) {
  main { padding: 1rem 0.75rem; }
  .form-row { grid-template-columns: 1fr; }
  .card-sm { margin-top: 1.5rem; }
  nav { gap: 0.75rem; }
  .nav-title { display: none; }
  .page-header h1 { font-size: 1.25rem; }
  .btn { min-height: 44px; }
}

@media (max-width: 768px) {
  .bracket-round-nav {
    display: flex;
    gap: 0.5rem;
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg);
    padding: 0.5rem 0.75rem;
    overflow-x: auto;
    border-bottom: 1px solid var(--border);
    -webkit-overflow-scrolling: touch;
  }
  .bracket-round-nav a {
    white-space: nowrap;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    background: white;
    border: 1px solid var(--border);
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--blue);
    text-decoration: none;
  }
  .bracket-round-nav a:hover { background: var(--blue); color: white; }

  .bracket {
    flex-direction: column;
    overflow-x: visible;
    gap: 1.5rem;
    padding-bottom: 0;
  }
  .bracket-round {
    min-width: unset;
    width: 100%;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
  }
  .bracket-round-label {
    font-size: 0.875rem;
    text-align: left;
    padding: 0 0.5rem 0.5rem;
  }
  .bracket-match-wrapper::before,
  .bracket-match-wrapper::after { display: none; }
  .bracket-match-wrapper { flex: unset; }

  .match-card { font-size: 0.9375rem; margin: 0.35rem 0.5rem; }
  .match-card-team { padding: 0.6rem 0.75rem; min-height: 44px; }
  .match-score, .match-pending-badge { font-size: 0.8125rem; }
}

@media (min-width: 769px) {
  /* Break out of main's max-width so all rounds have room.
     2rem padding keeps round 1 and the final off the viewport edge. */
  .bracket {
    width: 100vw;
    position: relative;
    left: 50%;
    transform: translateX(-50%);
    padding-left: 2rem;
    padding-right: 2rem;
    box-sizing: border-box;
    justify-content: center;
  }

  .bracket-round { min-width: 200px; }

  /* Slightly tighter cards */
  .match-card { font-size: 0.75rem; }
  .match-card-team { padding: 0.35rem 0.5rem; }
}

/* Competition sub-nav */
.competition-subnav {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 0 16px;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.competition-subnav-back {
  font-size: 0.875rem;
  color: #6b7280;
  text-decoration: none;
  white-space: nowrap;
}
.competition-subnav-back:hover { color: #0f2d5e; }
.competition-subnav-title {
  font-weight: 600;
  flex: 1;
}
.competition-subnav-tabs {
  display: flex;
  gap: 0;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  overflow: hidden;
}
.competition-subnav-tab {
  padding: 5px 14px;
  font-size: 0.875rem;
  text-decoration: none;
  color: #fff;
  background: #0f2d5e;
  border-right: 1px solid rgba(255,255,255,0.2);
}
.competition-subnav-tab:last-child { border-right: none; }
.competition-subnav-tab:hover { background: #1a3f7a; }
.competition-subnav-tab.active {
  background: #fff;
  color: #0f2d5e;
}
