:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #667085;
  --line: #d7dce5;
  --panel: #ffffff;
  --soft: #f5f7fb;
  --brand: #12395b;
  --teal: #0f766e;
  --green: #15803d;
  --amber: #b45309;
  --red: #b91c1c;
  --blue: #2563eb;
  --shadow: 0 10px 28px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Aptos, Segoe UI, Arial, sans-serif;
  color: var(--ink);
  background: #eef2f7;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 28px;
  color: #fff;
  background: var(--brand);
  box-shadow: var(--shadow);
}

.app-header h1,
.app-header p {
  margin: 0;
}

.app-header h1 {
  font-size: 24px;
}

.app-header p {
  margin-top: 4px;
  color: #cfe0f2;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 12px;
  color: #fff;
  background: var(--teal);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

main {
  display: grid;
  gap: 18px;
  max-width: min(1500px, 100%);
  min-width: 0;
  margin: 0 auto;
  padding: 18px;
}

.identity-band,
.status-band,
.groups-section,
.bracket-section,
.report-section {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
}

.identity-band {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) minmax(170px, 0.8fr) minmax(220px, 1.4fr);
  gap: 14px;
  padding: 16px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  min-height: 38px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--ink);
  background: #fff;
  font: inherit;
}

select.invalid,
input.invalid {
  border-color: var(--red);
  outline: 2px solid rgba(185, 28, 28, 0.12);
}

.status-band {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  overflow: hidden;
  background: var(--line);
}

.status-band > div {
  display: grid;
  gap: 4px;
  padding: 14px 16px;
  background: #fff;
}

.kpi-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.status-band strong {
  font-size: 20px;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.section-title h2,
.section-title p {
  margin: 0;
}

.section-title h2 {
  font-size: 18px;
}

.section-title p {
  min-width: 0;
  color: var(--muted);
  font-size: 14px;
  overflow-wrap: anywhere;
  text-align: right;
}

.groups-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(220px, 1fr));
  gap: 12px;
  padding: 16px;
}

.group-card,
.match-card,
.summary-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.group-card {
  overflow: hidden;
}

.group-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  color: #fff;
  background: var(--teal);
}

.group-card h3 {
  flex: 0 0 auto;
  margin: 0;
  font-size: 15px;
}

.group-card .teams {
  min-width: 0;
  color: #e7fffb;
  font-size: 12px;
  line-height: 1.25;
  overflow-wrap: anywhere;
  text-align: right;
}

.group-controls {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.bracket-grid {
  display: flex;
  gap: 12px;
  align-items: start;
  overflow-x: auto;
  padding: 16px;
}

.round-column {
  display: grid;
  flex: 0 0 210px;
  gap: 10px;
  min-width: 210px;
}

.round-column h3 {
  margin: 0;
  padding: 10px;
  border-radius: 6px;
  color: #fff;
  background: var(--brand);
  font-size: 14px;
}

.match-card {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.match-card[data-ready="false"] {
  background: var(--soft);
}

.match-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.teams-line {
  display: grid;
  gap: 4px;
  min-height: 42px;
  font-size: 13px;
}

.teams-line > span {
  display: block;
  padding: 5px 7px;
  border-radius: 5px;
  background: #eef6ff;
}

.team-with-flag {
  display: inline-grid;
  grid-template-columns: 32px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  max-width: 100%;
}

.team-with-flag img {
  display: block;
  width: 32px;
  height: 32px;
  object-fit: cover;
  border: 1px solid rgba(23, 32, 51, 0.12);
  border-radius: 3px;
  background: #fff;
}

.team-with-flag span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.teams-line > span {
  min-height: 44px;
}

.matchup-cell {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.versus {
  color: var(--muted);
  font-weight: 700;
}

.report {
  display: grid;
  gap: 16px;
  overflow-x: auto;
  padding: 16px;
}

.report-header {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.summary-card {
  padding: 12px;
}

.summary-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.summary-card strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.summary-card .team-with-flag,
.report-table .team-with-flag,
.teams-line .team-with-flag {
  display: inline-grid;
  grid-template-columns: 32px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  max-width: 100%;
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
  text-transform: none;
}

.summary-card .team-with-flag span,
.report-table .team-with-flag span,
.teams-line .team-with-flag span {
  display: inline;
  margin: 0;
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
  line-height: 1.2;
  text-transform: none;
}

.report-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 13px;
}

.report-table th,
.report-table td {
  border: 1px solid var(--line);
  padding: 7px 8px;
  text-align: left;
}

.report-table th {
  color: #fff;
  background: var(--teal);
}

.tag-ok {
  color: var(--green);
}

.tag-warn {
  color: var(--amber);
}

.tag-error {
  color: var(--red);
}

@media (max-width: 1100px) {
  .app-header,
  .section-title {
    align-items: stretch;
    flex-direction: column;
  }

  .identity-band,
  .status-band,
  .groups-grid,
  .report-header {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 720px) {
  main {
    padding: 10px;
  }

  .app-header {
    padding: 14px;
  }

  .identity-band,
  .status-band,
  .groups-grid,
  .report-header {
    grid-template-columns: 1fr;
  }
}

@media print {
  body {
    background: #fff;
  }

  .app-header,
  .identity-band,
  .groups-section,
  .header-actions {
    display: none;
  }

  main {
    max-width: none;
    padding: 0;
  }

  .bracket-section,
  .report-section,
  .status-band {
    border: 0;
  }

  .bracket-grid {
    grid-template-columns: repeat(6, 1fr);
    overflow: visible;
    padding: 8px 0;
  }

  .round-column h3 {
    position: static;
  }
}
