:root {
  --bg: #f4f7f5;
  --surface: #ffffff;
  --surface-soft: #eef4f1;
  --text: #15231d;
  --muted: #66756e;
  --line: #d8e2dd;
  --brand: #126b4f;
  --brand-strong: #0b4938;
  --accent: #f4b942;
  --danger: #b3261e;
  --ok: #16784f;
  --shadow: 0 10px 24px rgba(18, 35, 29, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.45;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
  max-width: 100%;
}

button,
.button {
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: white;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0.7rem 1rem;
  font-weight: 700;
}

button.secondary,
.button.secondary {
  background: var(--surface-soft);
  color: var(--brand-strong);
}

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

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

.topbar {
  background: var(--brand-strong);
  color: white;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0.9rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  justify-content: space-between;
  flex-wrap: wrap;
}

.brand {
  font-weight: 900;
  font-size: 1.05rem;
}

.nav {
  display: flex;
  gap: 0.45rem;
  overflow-x: auto;
  padding-bottom: 0.1rem;
}

.nav a,
.nav button {
  background: rgba(255, 255, 255, 0.12);
  color: white;
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  min-height: auto;
  white-space: nowrap;
}

.hero {
  background: linear-gradient(135deg, #0b4938, #147255 62%, #f4b942);
  color: white;
  padding: 2rem 1rem 1.4rem;
}

.hero-inner,
.page {
  max-width: 1180px;
  margin: 0 auto;
}

.hero h1 {
  margin: 0 0 0.6rem;
  font-size: clamp(2rem, 6vw, 4.4rem);
  line-height: 1;
  letter-spacing: 0;
}

.hero p {
  margin: 0;
  color: rgba(255, 255, 255, 0.88);
  max-width: 720px;
}

.page {
  padding: 1rem;
  width: 100%;
}

.quick-actions,
.grid,
.cards,
.stats {
  display: grid;
  gap: 0.85rem;
}

.quick-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 1rem 0;
}

.quick-actions .button {
  min-height: 64px;
  font-size: 1.05rem;
}

.grid {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.stats {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

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

.card {
  padding: 0.9rem;
}

.list-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.compact-list {
  gap: 0.55rem;
}

.admin-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.admin-toolbar > div {
  min-width: 0;
}

.admin-toolbar h2,
.admin-toolbar p {
  margin: 0;
}

.toolbar-actions {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.toolbar-actions button {
  flex: 0 1 auto;
}

.pair-list {
  display: grid;
  gap: 0.75rem;
}

.group-list {
  display: grid;
  gap: 0.75rem;
}

.round-list {
  display: grid;
  gap: 0.75rem;
}

.category-list {
  display: grid;
  gap: 0.75rem;
}

.category-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 0.95rem;
}

.category-card-main {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  align-items: center;
  flex-wrap: wrap;
}

.category-card strong {
  font-size: 1.05rem;
}

.category-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.45rem;
}

.pair-category {
  margin-top: 1rem;
}

.group-category {
  margin-top: 1rem;
}

.round-category {
  margin-top: 1rem;
}

.match-category {
  margin-top: 1.2rem;
}

.pair-category:first-of-type {
  margin-top: 0;
}

.group-category:first-of-type {
  margin-top: 0;
}

.round-category:first-of-type {
  margin-top: 0;
}

.match-category:first-of-type {
  margin-top: 0;
}

.pair-category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 0 0.55rem;
  border-bottom: 2px solid var(--brand);
  margin-bottom: 0.75rem;
}

.group-category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 0 0.55rem;
  border-bottom: 2px solid var(--brand);
  margin-bottom: 0.75rem;
}

.round-category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 0 0.55rem;
  border-bottom: 2px solid var(--brand);
  margin-bottom: 0.75rem;
}

.match-category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 0 0.55rem;
  border-bottom: 2px solid var(--brand);
  margin-bottom: 0.85rem;
}

.pair-category-header h3 {
  margin: 0;
  font-size: 1.12rem;
}

.group-category-header h3 {
  margin: 0;
  font-size: 1.12rem;
}

.round-category-header h3 {
  margin: 0;
  font-size: 1.12rem;
}

.match-category-header h3 {
  margin: 0;
  font-size: 1.12rem;
}

.match-group {
  margin: 0 0 1rem;
}

.phase-category {
  margin-top: 1.2rem;
}

.phase-category:first-of-type {
  margin-top: 0;
}

.match-group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin: 0 0 0.65rem;
}

.match-group-header h4 {
  margin: 0;
  font-size: 1rem;
}

.pair-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 0.95rem;
}

.group-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 0.95rem;
}

.round-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 0.95rem;
}

.pair-card-main {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  align-items: center;
  flex-wrap: wrap;
}

.pair-card-main > div {
  min-width: 0;
}

.group-card-main {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  align-items: center;
  flex-wrap: wrap;
}

.group-card-main > div {
  min-width: 0;
}

.round-card-main {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  align-items: center;
  flex-wrap: wrap;
}

.round-card-main > div {
  min-width: 0;
}

.pair-card strong {
  font-size: 1.03rem;
}

.group-card strong {
  font-size: 1.03rem;
}

.round-card strong {
  font-size: 1.03rem;
}

.pair-meta,
.pair-detail {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.45rem;
}

.group-meta,
.group-detail {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.45rem;
}

.round-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.45rem;
}

.pair-detail {
  color: var(--muted);
  border-top: 1px solid var(--line);
  padding-top: 0.65rem;
}

.group-detail {
  color: var(--muted);
  border-top: 1px solid var(--line);
  padding-top: 0.65rem;
}

.group-assign-form {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.85rem;
  margin-bottom: 1rem;
  background: var(--surface-soft);
}

.assigned-list {
  display: grid;
  gap: 0.6rem;
}

.assigned-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.8rem;
  background: var(--surface);
}

.assigned-edit-form {
  display: grid;
  gap: 0.75rem;
}

.assigned-edit-header,
.assigned-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.assign-pair-form {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
}

.assign-pair-form > div {
  flex: 1;
  min-width: 0;
}

.assign-pair-form button {
  flex-shrink: 0;
  width: auto;
}

.assigned-edit-fields {
  grid-template-columns: minmax(120px, 180px) minmax(0, 1fr);
}

.assigned-edit-fields textarea {
  min-height: 58px;
}

.group-standings-panel {
  margin-bottom: 1rem;
}

.standings-category {
  margin-top: 1rem;
}

.standings-category:first-of-type {
  margin-top: 0;
}

.standings-grid {
  display: grid;
  gap: 0.85rem;
}

.standings-card {
  min-width: 0;
  overflow: hidden;
  padding: 1rem;
}

.standings-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.55rem;
}

.standings-card-header h4 {
  margin: 0;
  font-size: 1rem;
}

.compact-title {
  margin: 0.9rem 0 0.55rem;
}

.panel,
.form-panel {
  padding: 1rem;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 1.3rem 0 0.75rem;
}

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

.muted {
  color: var(--muted);
}

.match-card {
  padding: 0.95rem;
  display: grid;
  gap: 0.65rem;
  border-left: 7px solid var(--line);
  min-width: 0;
}

.match-card.is-pending-result {
  background: #fff1dc;
  border-color: #e58a1f;
  box-shadow: 0 10px 24px rgba(180, 91, 12, 0.13);
}

.match-card.is-finished {
  background: #e7f6ec;
  border-color: #188455;
  box-shadow: 0 10px 24px rgba(22, 120, 79, 0.13);
}

.match-card.is-pending-result .match-status-pill {
  background: #b85e00;
  color: #ffffff;
}

.match-card.is-finished .match-status-pill {
  background: #126b4f;
  color: #ffffff;
}

.match-top,
.match-meta,
.row-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.match-title {
  font-size: 1.05rem;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.25rem 0.55rem;
  background: var(--surface-soft);
  color: var(--brand-strong);
  font-size: 0.83rem;
  font-weight: 800;
}

.pill.jugado {
  background: #dff4eb;
  color: var(--ok);
}

.filters,
.form-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr));
  align-items: end;
}

label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.9rem;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.7rem;
  background: white;
  color: var(--text);
}

textarea {
  min-height: 76px;
}

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

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

.standings-board {
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  margin-top: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #f7fbf9 100%);
}

.standings-table {
  min-width: 580px;
  border-collapse: separate;
  border-spacing: 0;
}

.standings-table th,
.standings-table td {
  text-align: center;
  padding: 0.72rem 0.62rem;
}

.standings-table th:nth-child(2),
.standings-table td:nth-child(2) {
  text-align: left;
}

.standings-table th {
  background: var(--surface-soft);
  color: var(--brand-strong);
}

.standings-table tbody tr:first-child {
  background: #e7f6ec;
}

.standings-table tbody tr:hover {
  background: #f5faf7;
}

.rank-badge {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--brand-strong);
  font-weight: 900;
}

.standings-table tbody tr:first-child .rank-badge {
  background: var(--brand);
  color: white;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 0.65rem;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.85rem;
}

.tabs {
  display: flex;
  gap: 0.45rem;
  max-width: 100%;
  overflow-x: auto;
  margin-bottom: 1rem;
  padding-bottom: 0.15rem;
  scrollbar-width: thin;
}

.tabs button {
  background: var(--surface);
  color: var(--brand-strong);
  border: 1px solid var(--line);
  white-space: nowrap;
}

.tabs button.active {
  background: var(--brand);
  color: white;
}

.hidden {
  display: none !important;
}

.message {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 200;
  max-width: min(420px, calc(100vw - 2rem));
  border-radius: 8px;
  padding: 0.75rem;
  margin: 0.75rem 0;
  background: #dff4eb;
  color: var(--ok);
  font-weight: 700;
}

.message.error {
  background: #fde8e7;
  color: var(--danger);
}

.login-box {
  max-width: 420px;
  margin: 8vh auto;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(7, 18, 14, 0.58);
  backdrop-filter: blur(3px);
  overflow-y: auto;
}

.modal-card {
  width: min(560px, 100%);
  max-height: calc(100dvh - 2rem);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 22px 70px rgba(7, 18, 14, 0.32);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.95rem;
  padding: 1rem;
  overflow: hidden;
  min-width: 0;
}

.modal-wide {
  width: min(760px, 100%);
  grid-template-columns: 1fr;
}

.modal-icon {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #fde8e7;
  color: var(--danger);
  font-weight: 900;
  font-size: 1.35rem;
}

.modal-body-full {
  width: 100%;
}

.modal-body {
  max-height: calc(100dvh - 4rem);
  min-height: 0;
  min-width: 0;
  overflow: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1rem;
  min-width: 0;
}

.modal-header > div {
  min-width: 0;
}

.modal-body h2 {
  margin: 0 0 0.45rem;
  font-size: 1.25rem;
  overflow-wrap: anywhere;
}

.modal-body p {
  margin: 0;
  color: var(--muted);
}

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

.modal-form {
  align-items: start;
}

.form-span {
  grid-column: 1 / -1;
}

.modal-list {
  margin: 0.85rem 0 0;
  padding: 0.8rem 0.8rem 0.8rem 1.65rem;
  border: 1px solid #f4c7c3;
  border-radius: 8px;
  background: #fff7f6;
  color: var(--text);
}

.modal-list li + li {
  margin-top: 0.35rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.55rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.modal-actions button {
  min-width: 126px;
}

@media (max-width: 640px) {
  .page {
    padding: 0.75rem;
  }

  .section-title {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.45rem;
  }

  .section-title h1 {
    font-size: 1.65rem;
    line-height: 1.15;
    margin: 0;
  }

  .admin-toolbar,
  .category-card-main,
  .pair-card-main,
  .group-card-main,
  .round-card-main,
  .assigned-edit-header,
  .match-group-header,
  .pair-category-header,
  .group-category-header,
  .round-category-header,
  .match-category-header,
  .standings-card-header {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-actions,
  .row-actions,
  .modal-actions {
    width: 100%;
  }

  .toolbar-actions button,
  .row-actions button,
  .modal-actions button,
  .toolbar-actions .button,
  .row-actions .button,
  .modal-actions .button {
    flex: 1 1 140px;
  }

  .form-grid,
  .filters,
  .assigned-edit-fields {
    grid-template-columns: 1fr;
  }

  .modal-backdrop {
    align-items: start;
    padding: 0.5rem;
  }

  .modal-card {
    width: 100%;
    max-height: calc(100dvh - 1rem);
    padding: 0.75rem;
  }

  .modal-card:not(.modal-wide) {
    grid-template-columns: 1fr;
  }

  .modal-body {
    max-height: calc(100dvh - 2.5rem);
    overscroll-behavior: contain;
  }

  .modal-header {
    gap: 0.75rem;
    margin-bottom: 0.75rem;
  }

  .group-assign-form,
  .assigned-card,
  .pair-card,
  .group-card,
  .round-card,
  .match-card,
  .category-card,
  .panel,
  .form-panel {
    padding: 0.75rem;
  }

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

  .standings-table {
    min-width: 520px;
  }
}

@media (min-width: 780px) {
  .quick-actions {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .hero {
    padding: 3.5rem 1rem 2rem;
  }
}

@media (min-width: 860px) {
  .pair-list,
  .group-list,
  .round-list,
  .standings-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Score input boxes */
.resultado-input {
  grid-column: 1 / -1;
}

.resultado-input label {
  display: block;
  font-weight: bold;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.score-boxes {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.score-box {
  width: 50px;
  height: 50px;
  font-size: 1.25rem;
  font-weight: bold;
  text-align: center;
  border: 2px solid var(--line);
  border-radius: 6px;
  padding: 0.25rem;
  color: var(--text);
  background: var(--surface);
}

.score-box:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(18, 107, 79, 0.1);
}

.score-dash {
  font-weight: bold;
  color: var(--text);
  margin: 0 0.25rem;
}

.score-sep {
  font-weight: bold;
  color: var(--muted);
  margin: 0 0.5rem;
  font-size: 1.1rem;
}
