:root {
  --bg: #f5f7f2;
  --surface: #ffffff;
  --surface-soft: #eef4ef;
  --ink: #17211d;
  --muted: #63736b;
  --line: #d8e1da;
  --green: #0f6b4f;
  --green-strong: #0a563f;
  --teal: #236c73;
  --red: #b64036;
  --amber: #d39a2d;
  --shadow: 0 10px 28px rgba(21, 35, 28, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px clamp(16px, 3vw, 34px);
  background: rgba(245, 247, 242, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--green);
  color: #ffffff;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
  white-space: nowrap;
}

.brand strong {
  max-width: min(48vw, 520px);
  overflow: hidden;
  font-size: 1rem;
  text-overflow: ellipsis;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-pill,
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill.is-online {
  border-color: rgba(15, 107, 79, 0.26);
  color: var(--green);
}

.status-pill.is-offline,
.badge.is-danger {
  border-color: rgba(182, 64, 54, 0.28);
  color: var(--red);
}

.badge.is-good {
  border-color: rgba(15, 107, 79, 0.26);
  color: var(--green);
}

.badge.is-warn {
  border-color: rgba(211, 154, 45, 0.36);
  color: #8a5b00;
}

.view-switch,
.admin-tabs,
.mini-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.switch-button,
.tab-button {
  min-height: 34px;
  padding: 7px 12px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.switch-button.is-active,
.tab-button.is-active {
  background: var(--green);
  color: #ffffff;
}

.main-content {
  width: min(1320px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.overview-band {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: end;
  margin-bottom: 18px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(135deg, #ffffff 0%, #edf5ee 100%);
  box-shadow: var(--shadow);
}

.overview-band h1,
.overview-band h2,
.panel h2,
.panel h3 {
  margin: 0;
  line-height: 1.1;
}

.overview-band h1 {
  font-size: clamp(1.7rem, 3.2vw, 3rem);
  overflow-wrap: anywhere;
}

.overview-band p,
.empty-state,
.field-hint,
.system-note {
  color: var(--muted);
}

.overview-band p {
  max-width: 720px;
  margin: 8px 0 0;
}

.quick-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  gap: 8px;
}

.stat-box {
  min-width: 92px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.stat-box strong,
.stat-box span {
  display: block;
}

.stat-box strong {
  font-size: 1.45rem;
}

.stat-box span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(320px, 0.9fr);
  gap: 18px;
  min-width: 0;
}

.stack {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  min-width: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2,
.panel-header h3 {
  font-size: 1rem;
}

.panel-body {
  padding: 18px;
  min-width: 0;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}

th,
td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

td.number,
th.number {
  text-align: right;
}

tr:last-child td {
  border-bottom: 0;
}

.team-cell,
.player-chip,
.team-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.team-cell strong,
.team-title strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar {
  display: grid;
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 900;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.team-avatar-stack {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 3px;
}

.team-avatar-stack .avatar {
  flex-basis: 32px;
  width: 32px;
  height: 32px;
  border: 2px solid #ffffff;
  box-shadow: 0 2px 8px rgba(21, 35, 28, 0.12);
}

.team-avatar-stack .avatar + .avatar {
  margin-left: 0;
}

.standings-grid {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.standings-grid > section {
  min-width: 0;
}

.group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.group-title h3 {
  font-size: 1rem;
}

.match-list,
.team-list,
.bracket-list,
.admin-list {
  display: grid;
  gap: 10px;
}

.match-row,
.team-row,
.bracket-row,
.admin-row {
  display: grid;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.match-row:last-child,
.team-row:last-child,
.bracket-row:last-child,
.admin-row:last-child {
  border-bottom: 0;
}

.match-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 14px;
  align-items: center;
}

.match-team {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.match-team.is-right {
  justify-items: end;
  text-align: right;
}

.match-team-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.match-team.is-right .match-team-title {
  flex-direction: row-reverse;
}

.match-team-title strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.versus {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.round-section {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.bye-list {
  display: grid;
  gap: 8px;
  padding-top: 4px;
}

.bye-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, clamp(360px, 42%, 430px));
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.bye-row .match-team {
  grid-column: 2;
  justify-self: stretch;
  width: 100%;
  justify-items: stretch;
}

.bye-row > .badge {
  justify-self: start;
}

.bye-row .match-team-title {
  width: 100%;
  justify-content: flex-end;
}

.bye-row .team-players.is-compact {
  display: grid;
  grid-template-columns: 1fr;
}

.bye-row .player-chip {
  width: 100%;
}

.team-players {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.team-players.is-compact {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.team-players.is-compact {
  width: 100%;
}

.team-players.is-compact .player-chip {
  flex: 1 1 180px;
}

.match-team.is-right .team-players.is-compact {
  justify-content: flex-end;
}

.player-chip {
  min-width: 0;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.player-chip .avatar {
  flex-basis: 34px;
  width: 34px;
  height: 34px;
}

.player-chip span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.game-pill {
  min-width: 58px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-align: center;
}

.game-pill.is-a,
.winner-text {
  color: var(--green);
}

.game-pill.is-b {
  color: var(--teal);
}

.bracket-row {
  padding: 14px 0;
}

.bracket-row h4,
.match-row h4 {
  margin: 0;
  font-size: 0.84rem;
  color: var(--muted);
  text-transform: uppercase;
}

.champion-box {
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 1px solid rgba(15, 107, 79, 0.25);
  border-radius: 8px;
  background: #eef7f1;
}

.champion-box span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.champion-box strong {
  font-size: 1.35rem;
}

.action-row,
.form-actions,
.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: var(--green);
  color: #ffffff;
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
}

.button:hover,
.switch-button:hover,
.tab-button:hover {
  filter: brightness(0.97);
}

.button.secondary {
  border-color: var(--line);
  background: #ffffff;
  color: var(--ink);
}

.button.warn {
  background: var(--amber);
  color: #201607;
}

.button.danger {
  background: var(--red);
}

.icon-button {
  width: 38px;
  padding: 0;
}

.admin-shell {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.admin-tabs {
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
}

.public-tabs {
  width: fit-content;
  max-width: 100%;
  margin: 0 0 16px;
  overflow-x: auto;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(190px, 1fr));
  gap: 14px;
}

.field {
  display: grid;
  gap: 7px;
}

.field label,
.field > span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.field input,
.field select,
.field textarea,
.score-input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  padding: 8px 10px;
  outline: none;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.score-input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(15, 107, 79, 0.12);
}

.field textarea {
  min-height: 170px;
  resize: vertical;
}

.field.full {
  grid-column: 1 / -1;
}

.field-hint,
.system-note {
  margin: 0;
  font-size: 0.86rem;
}

.login-wrap {
  display: grid;
  min-height: calc(100vh - 180px);
  place-items: center;
}

.login-panel {
  width: min(440px, 100%);
}

.login-panel .form-grid {
  grid-template-columns: minmax(0, 1fr);
}

.login-panel .field.full {
  grid-column: auto;
}

.login-panel .button {
  width: 100%;
}

.team-editor,
.match-editor {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.team-editor:last-child,
.match-editor:last-child {
  border-bottom: 0;
}

.team-editor-head {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 180px auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.players-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(240px, 1fr));
  gap: 12px;
}

.player-editor {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.player-editor .avatar {
  width: 48px;
  height: 48px;
}

.player-fields {
  display: grid;
  gap: 8px;
}

.file-control {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.file-control input[type="file"] {
  max-width: 230px;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(126px, 1fr));
  gap: 10px;
}

.score-box {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 6px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.score-box span {
  color: var(--muted);
  font-weight: 900;
}

.score-input {
  min-width: 0;
  padding: 7px;
  text-align: center;
}

.qualifier-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.qualifier-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.qualifier-list li:last-child {
  border-bottom: 0;
}

.empty-state {
  margin: 0;
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  text-align: center;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: min(380px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #17211d;
  color: #ffffff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 150ms ease, transform 150ms ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 920px) {
  .topbar,
  .overview-band,
  .dashboard-grid,
  .team-editor-head {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .topbar-actions {
    justify-content: space-between;
  }

  .dashboard-grid {
    display: grid;
  }

  .form-grid,
  .players-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .main-content {
    width: min(100% - 20px, 1320px);
    padding-top: 14px;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 8px;
  }

  .status-pill {
    justify-self: start;
  }

  .topbar-actions,
  .view-switch,
  .public-tabs,
  .quick-stats {
    width: 100%;
  }

  .view-switch,
  .public-tabs {
    display: flex;
    min-width: 0;
    overflow: hidden;
  }

  .admin-shell > .action-row {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
    min-width: 0;
  }

  .admin-tabs {
    width: 100%;
    min-width: 0;
    flex-wrap: wrap;
    overflow: visible;
  }

  .admin-tabs .tab-button {
    flex: 1 1 110px;
    min-width: 0;
  }

  .view-switch .switch-button,
  .public-tabs .tab-button,
  .quick-stats .stat-box {
    flex: 1 1 0;
  }

  .view-switch .switch-button,
  .public-tabs .tab-button {
    min-width: 0;
    padding-right: 8px;
    padding-left: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .quick-stats {
    grid-template-columns: 1fr;
  }

  .overview-band .action-row {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .overview-band .button,
  .overview-band .badge {
    width: 100%;
  }

  .overview-band .badge {
    white-space: normal;
  }

  .overview-band,
  .panel-body {
    padding: 14px;
  }

  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .match-main {
    grid-template-columns: 1fr;
  }

  .match-team.is-right {
    justify-items: start;
    text-align: left;
  }

  .match-team.is-right .match-team-title {
    flex-direction: row;
  }

  .match-team.is-right .team-players.is-compact {
    justify-content: flex-start;
  }

  .versus {
    text-align: left;
  }

  .brand strong {
    max-width: 58vw;
  }

  .team-players {
    grid-template-columns: 1fr;
  }

  .team-players.is-compact .player-chip {
    flex-basis: 100%;
  }

  .bye-row {
    align-items: flex-start;
    grid-template-columns: 1fr;
  }

  .bye-row .match-team {
    grid-column: auto;
    justify-items: start;
  }

  .bye-row .match-team-title {
    justify-content: flex-start;
  }
}
