/* ─── RESET & BASE ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0a0e1a;
  --bg2:       #111827;
  --bg3:       #0d1520;
  --border:    #1e2a45;
  --border2:   #2a3a55;
  --text:      #e8f0fe;
  --text2:     #94a3b8;
  --text3:     #4a6080;
  --accent:    #2563eb;
  --accent2:   #60a5fa;
  --win:       #34d399;
  --win-bg:    #0f1f3d;
  --danger:    #ef4444;
  --gold:      #f59e0b;
  --radius:    8px;
  --radius-lg: 12px;
}

html { font-size: 16px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── LOADING ───────────────────────────────────────────────── */
.loading-screen {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 60vh; gap: 1rem;
  color: var(--text2);
}
.loader-icon { font-size: 3rem; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.error-screen {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 60vh; gap: 1rem;
  text-align: center; padding: 2rem;
}
.error-screen h2 { color: var(--danger); }
.error-screen code { background: var(--bg2); padding: 2px 6px; border-radius: 4px; font-size: 14px; }

/* ─── HEADER ────────────────────────────────────────────────── */
.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky; top: 0; z-index: 100;
}
.header-inner {
  max-width: 1400px; margin: 0 auto;
  padding: .75rem 1.5rem;
  display: flex; align-items: center; gap: 1.5rem;
  flex-wrap: wrap;
}
.header-logo {
  font-size: 1.1rem; font-weight: 700;
  color: var(--accent2); letter-spacing: .04em;
  white-space: nowrap;
}
.header-info {
  display: flex; align-items: center; gap: .75rem; flex: 1;
}
.header-info h1 { font-size: 1.2rem; font-weight: 700; }
.header-meta { font-size: 12px; color: var(--text3); white-space: nowrap; }
.sep { margin: 0 4px; }

.status-badge {
  font-size: 10px; font-weight: 700; letter-spacing: .1em;
  padding: 3px 10px; border-radius: 20px; text-transform: uppercase;
}
.status-badge.draft    { background: #1a1a2e; color: var(--text3); border: 1px solid var(--border); }
.status-badge.active   { background: #0f2a1a; color: var(--win); border: 1px solid #134d2a; }
.status-badge.finished { background: #1a1200; color: var(--gold); border: 1px solid #3a2800; }

/* ─── BRACKET LAYOUT ────────────────────────────────────────── */
.bracket-stage {
  padding: 1.5rem;
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
}

.bracket-wrap {
  display: flex;
  align-items: stretch;
  gap: 0;
  min-width: max-content;
  padding-bottom: 1rem;
}

/* Modo espejo: el wrap se convierte en contenedor centrador */
.bracket-wrap.mirror {
  min-width: 100%;
  justify-content: center;
}

.round-col {
  display: flex; flex-direction: column;
  min-width: 200px;
}

.round-label {
  font-size: 10px; font-weight: 700;
  letter-spacing: .15em; text-transform: uppercase;
  color: var(--text3); text-align: center;
  padding: .5rem 8px 1rem;
}

.matches-col {
  display: flex; flex-direction: column;
  flex: 1; justify-content: space-around;
}

/* ─── MATCH CARD ────────────────────────────────────────────── */
.match-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 8px;
  cursor: default;
  transition: border-color .15s;
}
.match-card.clickable { cursor: pointer; }
.match-card.clickable:hover { border-color: var(--accent); }
.match-card.clickable:hover .match-action { opacity: 1; }

.team-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; font-size: 13px; font-weight: 500;
  color: var(--text2);
  transition: background .12s;
}
.team-row:first-child { border-bottom: 1px solid var(--bg3); }

.team-row.winner { color: var(--text); background: var(--win-bg); }
.team-row.loser  { opacity: .4; }
.team-row.tbd    { color: var(--text3); font-style: italic; }

.team-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team-score {
  font-weight: 700; font-size: 14px;
  color: var(--text3); min-width: 20px; text-align: right;
}
.team-score.win { color: var(--win); }

.match-vs {
  font-size: 9px; color: var(--text3);
  text-align: center; padding: 1px 0;
  background: var(--bg3); letter-spacing: .1em;
}

.match-action {
  font-size: 10px; color: var(--accent2);
  text-align: center; padding: 4px;
  background: rgba(37,99,235,.08);
  opacity: 0; transition: opacity .15s;
}

/* ─── CONNECTOR SVG ─────────────────────────────────────────── */
.connector-col {
  display: flex; flex-direction: column;
  justify-content: space-around; align-self: stretch;
  padding: 8px 0; min-width: 24px;
}
.connector-col svg { overflow: visible; }

/* ─── CHAMPION BOX ──────────────────────────────────────────── */
.champion-col {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 1rem;
}
.champion-box {
  background: linear-gradient(135deg, var(--win-bg), var(--bg3));
  border: 1px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 1.5rem 2rem;
  text-align: center;
  min-width: 160px;
}
.champion-trophy { font-size: 2.5rem; margin-bottom: .5rem; }
.champion-label  { font-size: 10px; letter-spacing: .15em; color: var(--accent2); font-weight: 700; text-transform: uppercase; margin-bottom: .25rem; }
.champion-name   { font-size: 1.1rem; font-weight: 700; color: var(--text); }

/* ─── MODAL ─────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.modal.hidden { display: none; }
.modal-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.65);
}
.modal-box {
  position: relative; z-index: 1;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 100%; max-width: 420px;
  margin: 1rem;
}
.modal-box h3 { font-size: 1.1rem; margin-bottom: 1rem; }
.match-preview { font-size: 13px; color: var(--text2); margin-bottom: 1.5rem; }

.score-inputs {
  display: flex; align-items: center; gap: 1rem;
  margin-bottom: 1.5rem;
}
.score-field {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: .5rem;
}
.score-field label { font-size: 12px; color: var(--text2); }
.score-field input {
  width: 80px; text-align: center;
  font-size: 1.5rem; font-weight: 700;
  background: var(--bg3); border: 1px solid var(--border2);
  color: var(--text); border-radius: var(--radius);
  padding: .5rem;
}
.score-sep { font-size: 1.5rem; color: var(--text3); flex-shrink: 0; }

.modal-actions {
  display: flex; gap: .75rem; justify-content: flex-end;
}
.modal-note { font-size: 11px; color: var(--text3); margin-top: .75rem; text-align: center; }

/* ─── BUTTONS ───────────────────────────────────────────────── */
.btn-primary {
  background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius);
  padding: .5rem 1.25rem; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background .15s;
}
.btn-primary:hover { background: #1d4ed8; }

.btn-ghost {
  background: transparent; color: var(--text2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: .5rem 1.25rem; font-size: 14px;
  cursor: pointer; transition: background .15s;
}
.btn-ghost:hover { background: var(--bg3); }

.btn-danger {
  background: transparent; color: var(--danger);
  border: 1px solid #7f1d1d;
  border-radius: var(--radius);
  padding: .5rem 1.25rem; font-size: 14px;
  cursor: pointer; transition: background .15s;
}
.btn-danger:hover { background: #2d0a0a; }

/* ─── FOOTER ────────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border);
  padding: .75rem 1.5rem;
  font-size: 12px; color: var(--text3);
  display: flex; align-items: center; gap: .5rem;
}

/* ─── ADMIN PANEL ───────────────────────────────────────────── */
.admin-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
.admin-sidebar {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  padding: 1.5rem 0;
  position: sticky; top: 0; height: 100vh;
  overflow-y: auto;
}
.sidebar-logo {
  font-size: 1rem; font-weight: 700;
  color: var(--accent2);
  padding: 0 1.5rem 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}
.nav-item {
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem 1.5rem; font-size: 14px;
  color: var(--text2); cursor: pointer;
  transition: background .12s, color .12s;
  border: none; background: none; width: 100%; text-align: left;
}
.nav-item:hover, .nav-item.active {
  background: rgba(37,99,235,.1);
  color: var(--accent2);
}
.nav-icon { font-size: 16px; }

.admin-main { padding: 2rem; overflow-y: auto; }
.admin-main h2 { font-size: 1.3rem; font-weight: 700; margin-bottom: 1.5rem; }

.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.card h3 { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; color: var(--text2); }

.form-row { margin-bottom: 1rem; }
.form-row label { display: block; font-size: 12px; color: var(--text3); margin-bottom: .4rem; }
.form-row input,
.form-row select,
.form-row textarea {
  width: 100%; background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text); padding: .6rem .75rem;
  font-size: 14px; font-family: inherit;
  transition: border-color .15s;
}
.form-row input:focus, .form-row select:focus {
  outline: none; border-color: var(--accent);
}
.form-row select option { background: var(--bg2); }

.tournament-list { display: flex; flex-direction: column; gap: .75rem; }
.tournament-item {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  display: flex; align-items: center; gap: 1rem;
  cursor: pointer; transition: border-color .15s;
}
.tournament-item:hover { border-color: var(--accent); }
.t-info { flex: 1; }
.t-name { font-weight: 600; font-size: 15px; }
.t-meta { font-size: 12px; color: var(--text3); margin-top: 2px; }
.t-actions { display: flex; gap: .5rem; }

.players-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: .75rem;
  margin: 1rem 0;
}
.player-input {
  display: flex; align-items: center; gap: .5rem;
}
.player-num {
  font-size: 11px; color: var(--text3);
  min-width: 20px; text-align: right;
}
.player-input input {
  flex: 1; background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text); padding: .4rem .6rem;
  font-size: 13px;
}
.player-input input:focus { outline: none; border-color: var(--accent); }

.url-box {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  font-size: 13px; color: var(--accent2);
  display: flex; align-items: center; gap: .75rem;
  word-break: break-all;
}
.copy-btn {
  background: transparent; border: none;
  color: var(--text3); cursor: pointer; font-size: 16px;
  flex-shrink: 0;
}
.copy-btn:hover { color: var(--accent2); }

.tag-success { color: var(--win); font-size: 12px; }
.tag-error   { color: var(--danger); font-size: 12px; }

/* ─── LOGIN ─────────────────────────────────────────────────── */
.login-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
}
.login-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  width: 100%; max-width: 380px;
}
.login-box h1 { font-size: 1.5rem; margin-bottom: .25rem; }
.login-box p  { color: var(--text3); font-size: 13px; margin-bottom: 2rem; }

/* ─── RESPONSIVE ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .admin-layout { grid-template-columns: 1fr; }
  .admin-sidebar { height: auto; position: static; }
  .header-inner { gap: .75rem; }
}