:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --border: #e1e6ee;
  --text: #1a2233;
  --text-muted: #63708a;
  --primary: #1f7a5c;
  --primary-hover: #17624a;
  --accent: #2f6fed;
  --warn-bg: #fff6e0;
  --warn-border: #f0cf70;
  --warn-text: #7a5b06;
  --error-bg: #fdeaea;
  --error-border: #f2a7a7;
  --error-text: #a12626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 30, 50, 0.08), 0 1px 2px rgba(20, 30, 50, 0.06);
}

* { box-sizing: border-box; }

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

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header h1 {
  margin: 0 0 0.75rem;
  font-size: 1.4rem;
}

.tabs {
  display: flex;
  gap: 0.25rem;
}

.tab-btn {
  border: none;
  background: transparent;
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.25rem;
}

.panel-controls label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}

.panel-controls input,
.panel-controls select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  font-size: 0.95rem;
  min-width: 5rem;
  background: var(--surface);
  color: var(--text);
}

.btn {
  border: none;
  border-radius: 6px;
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: #eef1f6; color: var(--text); }
.btn-secondary:hover { background: #e3e8f0; }
.btn-small { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.meta-text { font-size: 0.8rem; color: var(--text-muted); margin-left: auto; }
.summary-text { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 1rem; }

.warnings {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.warning-item {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
}

.error-box {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error-text);
  border-radius: 6px;
  padding: 0.6rem 0.85rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.loading { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1rem; }

.teams-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.9rem;
}

.team-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.9rem 1rem;
}

.team-card h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.team-card .avg-badge {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary);
  background: #e6f4ee;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
}

.team-card ul {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.9rem;
}

.team-card li {
  display: flex;
  justify-content: space-between;
  padding: 0.2rem 0;
  border-bottom: 1px dashed var(--border);
}

.team-card li:last-child { border-bottom: none; }
.team-card .niveau { color: var(--text-muted); }

.team-card h3 { flex-wrap: wrap; gap: 0.4rem; }

.member-edit-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.member-edit-row .member-name {
  flex: 1;
  min-width: 70px;
}

.niveau-input {
  width: 3.2rem;
}

.move-select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 0.3rem;
  font-size: 0.78rem;
  background: var(--surface);
  color: var(--text);
  max-width: 8.5rem;
}

.add-person-form {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
}

.add-person-name {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.45rem;
  font-size: 0.85rem;
  background: var(--surface);
  color: var(--text);
}

#add-team-btn {
  margin-top: 1rem;
}

.empty-hint {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  color: var(--text-muted);
  text-align: center;
}

/* --- Turnier --- */

.round-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  margin-bottom: 0.9rem;
}

.round-block h4 {
  margin: 0 0 0.6rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.match-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0;
  flex-wrap: wrap;
}

.match-row + .match-row { border-top: 1px solid var(--border); }

.field-tag {
  font-size: 0.7rem;
  font-weight: 700;
  color: white;
  background: var(--accent);
  border-radius: 4px;
  padding: 0.15rem 0.4rem;
  min-width: 4.2rem;
  text-align: center;
}

.field-tag[data-field="2"] { background: #8a4fd6; }

.group-tag {
  font-size: 0.7rem;
  color: var(--text-muted);
  background: #eef1f6;
  border-radius: 4px;
  padding: 0.15rem 0.4rem;
}

.match-teams {
  flex: 1;
  min-width: 180px;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.92rem;
}

.match-teams .vs { color: var(--text-muted); font-size: 0.8rem; }
.team-name.tbd { color: var(--text-muted); font-style: italic; }

.score-input {
  width: 3rem;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem;
}

.match-winner {
  font-size: 0.75rem;
  color: var(--primary);
  font-weight: 600;
  min-width: 5rem;
}

.standings-wrap {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

table.standings {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 0.85rem;
}

table.standings caption {
  text-align: left;
  font-weight: 700;
  padding: 0.6rem 0.8rem;
  background: #eef1f6;
  caption-side: top;
}

table.standings th,
table.standings td {
  padding: 0.4rem 0.6rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

table.standings th:first-child,
table.standings td:first-child {
  text-align: left;
}

table.standings tbody tr:last-child td { border-bottom: none; }
table.standings tbody tr.qualified { background: #e6f4ee; }

.section-title {
  font-size: 1.05rem;
  margin: 1.5rem 0 0.75rem;
}

.bracket {
  display: flex;
  gap: 2rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
}

.bracket-round {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  gap: 1rem;
  min-width: 220px;
}

.bracket-round h5 {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.bracket-match {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  box-shadow: var(--shadow);
}

.bracket-match .match-teams { margin-bottom: 0.3rem; }

.champion-box {
  background: linear-gradient(135deg, #1f7a5c, #2f6fed);
  color: white;
  border-radius: var(--radius);
  padding: 1.2rem;
  text-align: center;
  font-size: 1.2rem;
  font-weight: 700;
  margin-top: 1rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10141c;
    --surface: #1a2030;
    --border: #2b3346;
    --text: #e7ebf3;
    --text-muted: #96a1b8;
    --primary: #35b787;
    --primary-hover: #2c9a72;
    --warn-bg: #3a2f0f;
    --warn-border: #6b551b;
    --warn-text: #f0d27a;
    --error-bg: #3a1414;
    --error-border: #6b2424;
    --error-text: #f29b9b;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }

  .btn-secondary { background: #262f45; color: var(--text); }
  .btn-secondary:hover { background: #303c58; }
  .team-card .avg-badge { background: #163a2c; }
  .group-tag { background: #262f45; }
  table.standings caption { background: #262f45; }
  table.standings tbody tr.qualified { background: #163a2c; }
}
