:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e0e2e7;
  --text: #1c1f26;
  --muted: #6b7280;
  --primary: #2f6fed;
  --primary-dark: #1f4fbb;
  --success: #1c8a4b;
  --error: #c0392b;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--primary); text-decoration: none; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.user-chip { color: var(--muted); font-size: 0.9rem; }

/* --- Hamburger + side drawer (mobile nav) --- */
.drawer-toggle-checkbox { display: none; }

.hamburger-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text);
  border-radius: 8px;
}
.hamburger-btn:hover { background: var(--bg); }

.drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 20;
}

.side-drawer {
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 260px;
  max-width: 82%;
  background: var(--surface);
  box-shadow: 4px 0 16px rgba(0, 0, 0, 0.18);
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  z-index: 30;
  display: flex;
  flex-direction: column;
  padding: 14px;
  overflow-y: auto;
}

.drawer-toggle-checkbox:checked ~ .drawer-overlay { display: block; }
.drawer-toggle-checkbox:checked ~ .side-drawer { transform: translateX(0); }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.drawer-close {
  cursor: pointer;
  font-size: 1.2rem;
  color: var(--muted);
  padding: 4px 8px;
}

.side-drawer a {
  display: block;
  padding: 12px 10px;
  border-radius: 8px;
  color: var(--text);
  font-size: 0.98rem;
}
.side-drawer a:hover { background: var(--bg); }
.side-drawer a.active { color: var(--primary); font-weight: 600; background: var(--bg); }

.drawer-section-label {
  padding: 10px 10px 4px;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 700;
}

.drawer-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 0;
}

.drawer-expandable summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 10px;
  border-radius: 8px;
  color: var(--text);
  font-size: 0.98rem;
  cursor: pointer;
  list-style: none;
}
.drawer-expandable summary::-webkit-details-marker { display: none; }
.drawer-expandable summary:hover { background: var(--bg); }
.drawer-expandable summary .chevron { color: var(--muted); font-size: 0.8rem; transition: transform 0.15s ease; }
.drawer-expandable[open] summary .chevron { transform: rotate(180deg); }

.drawer-sublist { padding-left: 14px; }
.drawer-sublist .drawer-subitem {
  display: block;
  padding: 10px 10px;
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  border-left: 2px solid var(--border);
  margin-left: 4px;
}
.drawer-sublist .drawer-subitem:hover { background: var(--bg); }
.drawer-sublist .drawer-subitem.active { color: var(--primary); font-weight: 600; border-left-color: var(--primary); }
.drawer-sublist .drawer-subitem-empty { color: var(--muted); cursor: default; }
.drawer-sublist .drawer-subitem-empty:hover { background: none; }
.drawer-sublist .drawer-subitem-muted { color: var(--muted); font-size: 0.85rem; }

.drawer-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}

.flashes { margin-bottom: 16px; }
.flash {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 8px;
  font-size: 0.92rem;
}
.flash-success { background: #e5f6ec; color: var(--success); }
.flash-error { background: #fbe9e7; color: var(--error); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

h1 { font-size: 1.4rem; margin: 0 0 12px; }
h2 { font-size: 1.15rem; margin: 0 0 10px; }
h3 { font-size: 1rem; margin: 0 0 8px; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

label { display: block; font-size: 0.88rem; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=url], select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  margin-bottom: 14px;
  background: var(--surface);
  color: var(--text);
}

input[type=file] { margin-bottom: 14px; }

.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row > div { flex: 1; min-width: 140px; }

.btn {
  display: inline-block;
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  background: var(--primary);
  color: white;
  font-size: 0.95rem;
  cursor: pointer;
  text-align: center;
}
.btn:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-danger { background: var(--error); }
.btn-sm { padding: 6px 10px; font-size: 0.85rem; }

.btn-floating-save {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 40;
  padding: 14px 26px;
  border-radius: 999px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
.has-floating-save { padding-bottom: 84px; }

/* --- Custom modal (replaces native alert/confirm) --- */
.app-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.app-modal-overlay[hidden] { display: none; }

.app-modal {
  background: var(--surface);
  border-radius: 12px;
  padding: 20px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  animation: app-modal-in 0.15s ease-out;
}
@keyframes app-modal-in {
  from { transform: scale(0.96); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.app-modal-message {
  margin: 0 0 18px;
  font-size: 0.98rem;
  line-height: 1.4;
  color: var(--text);
}

.app-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.app-modal-actions .btn { flex: 0 0 auto; }
@media (max-width: 420px) {
  .app-modal-actions { flex-direction: column-reverse; }
  .app-modal-actions .btn { width: 100%; }
}

.team-list { list-style: none; padding: 0; margin: 0; }
.team-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-bottom: 1px solid var(--border);
}
.team-row:last-child { border-bottom: none; }
.shield {
  width: 32px; height: 32px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--bg);
  border: 1px solid var(--border);
}
.shield-sm { width: 20px; height: 20px; border-radius: 4px; flex-shrink: 0; }
.team-chip { display: inline-flex; align-items: center; gap: 6px; }
.team-name { flex: 1; font-weight: 500; }

.groups-board {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
@media (min-width: 700px) {
  .groups-board { grid-template-columns: repeat(2, 1fr); }
}

.group-column {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  min-height: 80px;
}
.group-column h3 { display: flex; justify-content: space-between; align-items: center; }

.drop-zone {
  min-height: 60px;
  border: 2px dashed transparent;
  border-radius: 8px;
  padding: 4px;
}
.drop-zone.drag-over { border-color: var(--primary); background: #eef3ff; }

.drag-card {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 6px;
  cursor: grab;
  touch-action: none;
}
.drag-card.sortable-ghost { opacity: 0.4; }
.drag-card .shield { width: 26px; height: 26px; }

.unassigned-pool {
  background: #fffbe8;
  border: 1px dashed #e0c65a;
}

table.standings {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
table.standings th, table.standings td {
  padding: 8px 6px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}
table.standings th:first-child, table.standings td.team-cell {
  text-align: left;
}
table.standings tr.qualifies { background: #e5f6ec; }
.team-cell { display: flex; align-items: center; gap: 8px; }

.match-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.match-row:last-child { border-bottom: none; }
.match-teams { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 200px; }
.match-score-form { display: flex; align-items: center; gap: 6px; }
.match-score-form input[type=number] {
  width: 50px;
  margin-bottom: 0;
  padding: 6px;
  text-align: center;
}

.match-datetime {
  font-size: 0.9rem;
  padding: 9px 12px;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  accent-color: var(--primary);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.match-datetime:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.15);
}
.match-datetime::-webkit-calendar-picker-indicator { cursor: pointer; }

@media (max-width: 480px) {
  .match-datetime { flex: 1 1 100%; width: 100%; }
}
.match-bye { color: var(--muted); font-style: italic; }
.match-tbd { color: var(--muted); }

.played-matches { margin: 10px 0 20px; }
.played-matches summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 8px 4px;
  list-style: none;
}
.played-matches summary::-webkit-details-marker { display: none; }
.played-matches summary::before { content: "▸ "; }
.played-matches[open] summary::before { content: "▾ "; }

.section-title {
  margin-top: 20px;
  font-size: 1.05rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

.phase-nav-buttons { display: flex; gap: 6px; }

.phase-carousel {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  gap: 12px;
  margin: 0 -16px;
  padding: 0 16px 8px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.phase-page {
  flex: 0 0 100%;
  scroll-snap-align: start;
  min-width: 0;
}

@media (min-width: 700px) {
  .phase-page { flex-basis: calc(50% - 6px); }
}

.phase-round-title { text-align: center; color: var(--muted); font-size: 0.9rem; margin-bottom: 10px; }

.bracket-match {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.9rem;
  margin-bottom: 10px;
}
.bracket-match .side { display: flex; justify-content: space-between; padding: 2px 0; }
.bracket-match .side.winner { font-weight: 700; }

.match-number { color: var(--muted); font-size: 0.75rem; margin-bottom: 4px; margin-right: 6px; }

.slot-dropzones { display: flex; align-items: center; gap: 8px; }
.slot-dropzones .slot-box { flex: 1; min-height: 44px; }
.slot-dropzones .vs-label { color: var(--muted); font-size: 0.8rem; }

.slot-resolved-names {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 4px;
}

.bracket-match-actions { margin-top: 6px; }
.btn-link-danger {
  background: none;
  border: none;
  padding: 0;
  color: var(--error);
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: underline;
}

.slots-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
}
.slot-box {
  min-height: 56px;
  border: 2px dashed var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
}
.slot-box.filled { border-style: solid; }
.slot-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.85rem;
  text-align: center;
  cursor: grab;
  width: 100%;
}

.wizard-steps { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; font-size: 0.85rem; color: var(--muted); }
.wizard-steps .done { color: var(--success); }

.empty-state { text-align: center; padding: 40px 16px; color: var(--muted); }

.tournament-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px;
  margin-bottom: 10px;
}
.tournament-card .dates { color: var(--muted); font-size: 0.85rem; }
