:root {
  --bg: #0e0e0f;
  --surface: #17161a;
  --surface-2: #201f23;
  --border: #2c2a31;
  --text: #f4f3f6;
  --muted: #a3a0aa;
  --primary: #8c52ff;
  --primary-dim: #7440e0;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #ff6e84;
  --radius: 12px;
  --font: "Manrope", system-ui, sans-serif;
  --font-head: "Lexend", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.5; }
a { color: inherit; }
h1, h2, h3 { font-family: var(--font-head); margin: 0; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* Layout */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-head); font-weight: 700; text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--primary); display: grid; place-items: center; font-size: 15px; color: #fff; }
.nav { display: flex; gap: 6px; align-items: center; }
.nav a { text-decoration: none; padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; font-size: .9rem; }
.nav a:hover, .nav a.active { color: var(--text); background: var(--surface-2); }
.container { max-width: 1200px; margin: 0 auto; padding: 28px 24px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.torneo-card { display: flex; flex-direction: column; gap: 12px; text-decoration: none; transition: border-color .15s, transform .15s; }
.torneo-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.stats { display: flex; gap: 18px; }
.stat b { display: block; font-family: var(--font-head); font-size: 1.25rem; }
.stat span { color: var(--muted); font-size: .8rem; }

/* Forms */
label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 11px; font: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(140, 82, 255, .25); }
.form-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: end; }
.field { margin-bottom: 12px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: .9rem; font-weight: 500; margin: 0; }
.check input { width: auto; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: 8px; padding: 9px 16px; font: inherit; font-weight: 700; font-size: .9rem; cursor: pointer; text-decoration: none; background: var(--surface-2); color: var(--text); border-color: var(--border); white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dim); border-color: var(--primary-dim); }
.btn-danger { background: transparent; color: var(--danger); border-color: rgba(255, 110, 132, .4); }
.btn-danger:hover { border-color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--border); }
.btn-sm { padding: 5px 10px; font-size: .8rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge-en_curso, .badge-jugado { color: var(--ok); border-color: rgba(52, 211, 153, .35); }
.badge-borrador, .badge-pendiente { color: var(--warn); border-color: rgba(251, 191, 36, .35); }
.badge-finalizado { color: var(--muted); }
.badge-en_vivo { color: #fff; background: #e11d48; border-color: #e11d48; display: inline-flex; align-items: center; gap: 6px; }
.live-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulso 1.2s ease-in-out infinite; font-style: normal; }
.tab .live-dot { color: #f43f5e; margin-right: 4px; vertical-align: middle; }
@keyframes pulso { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } }
.badge-suspendido { color: var(--danger); border-color: rgba(255, 110, 132, .35); }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tab { background: none; border: none; color: var(--muted); font: inherit; font-weight: 700; padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab.active { color: var(--text); border-bottom-color: var(--primary); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: center; font-variant-numeric: tabular-nums; }
.team { display: flex; align-items: center; gap: 10px; }
.crest { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; background: var(--surface-2); display: grid; place-items: center; font-size: .7rem; font-weight: 800; color: var(--muted); flex-shrink: 0; border: 1px solid var(--border); }

img.crest { object-fit: contain; border-radius: 0; background: transparent; border: 0; }

/* Partidos */
.jornada { margin-bottom: 22px; }
.jornada-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.match { display: grid; grid-template-columns: 1fr auto 1fr auto; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; }
.match .home { justify-content: flex-end; text-align: right; }
.score { display: flex; align-items: center; gap: 6px; }
.score input { width: 52px; text-align: center; font-family: var(--font-head); font-weight: 700; font-size: 1.05rem; padding: 6px; }
.match-meta { grid-column: 1 / -1; display: flex; gap: 14px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); }
.match-actions { display: flex; gap: 4px; }
.match.saved { border-color: var(--ok); }

/* Imágenes */
.img-field { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.img-preview { width: 64px; height: 64px; border-radius: 10px; background: var(--surface-2); border: 1px dashed var(--border); display: grid; place-items: center; overflow: hidden; flex-shrink: 0; }
.img-preview.wide { width: 100%; height: auto; aspect-ratio: 4 / 1; }
.img-preview img { width: 100%; height: 100%; object-fit: contain; }
.img-preview span { color: var(--muted); font-size: .72rem; text-align: center; padding: 4px; }
.img-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.img-actions label.btn { margin: 0; color: var(--text); font-size: .8rem; }

/* Sponsors */
.sponsor-list { display: grid; gap: 12px; }
.sponsor { display: grid; grid-template-columns: 240px minmax(0, 1fr) auto; gap: 16px; align-items: center; padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.sponsor.off { opacity: .55; }
.sponsor-img { aspect-ratio: 4 / 1; background: var(--surface-2); border-radius: 8px; overflow: hidden; }
.sponsor-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sponsor-info { min-width: 0; }
.sponsor-info b { display: block; }
.sponsor-info a { color: var(--muted); font-size: .82rem; overflow-wrap: anywhere; }
.sponsor-actions { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

/* En vivo */
.btn-live { background: transparent; color: #fb7185; border-color: rgba(244, 63, 94, .45); }
.btn-live:hover { border-color: #f43f5e; }
.btn-warn { background: rgba(251, 191, 36, .12); color: var(--warn); border-color: rgba(251, 191, 36, .45); }
.match.is-live { border-color: rgba(244, 63, 94, .6); box-shadow: 0 0 0 1px rgba(244, 63, 94, .25) inset; }
.score.live { gap: 6px; }
.periodos { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.periodo-btn { background: var(--surface-2); color: var(--muted); border: 0; border-left: 1px solid var(--border); font: inherit; font-size: .76rem; font-weight: 700; padding: 4px 10px; cursor: pointer; }
.periodo-btn:first-child { border-left: 0; }
.periodo-btn:hover { color: var(--text); }
.periodo-btn.on { background: #e11d48; color: #fff; }
.periodo-btn:disabled { opacity: .6; }
.score.live b { font-family: var(--font-head); font-size: 1.6rem; min-width: 30px; text-align: center; font-variant-numeric: tabular-nums; }
.gol-btn { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 1.15rem; font-weight: 700; cursor: pointer; line-height: 1; }
.gol-btn.plus { background: rgba(140, 82, 255, .18); border-color: rgba(140, 82, 255, .5); }
.gol-btn:hover { border-color: var(--muted); }
.gol-btn:disabled { opacity: .5; }
.jornada.oculta .match { opacity: .6; }
#envivo .gol-btn { width: 44px; height: 44px; font-size: 1.4rem; }
#envivo .score.live b { font-size: 2rem; }

/* Sponsors: logos y espacios */
.sponsor.is-logo { grid-template-columns: 160px minmax(0, 1fr) auto; }
.sponsor.is-logo .sponsor-img { aspect-ratio: 5 / 2; background: #24222b; display: grid; place-items: center; padding: 10px; }
.sponsor.is-logo .sponsor-img img { width: auto; height: auto; max-width: 100%; max-height: 44px; object-fit: contain; filter: grayscale(1); }
.sponsor:not(.is-logo) .sponsor-img { aspect-ratio: 728 / 90; }
#sponsorsBanners .sponsor { grid-template-columns: 340px minmax(0, 1fr) auto; }
.slot-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; font-family: var(--font); font-weight: 700; }
.slot-title:first-child { margin-top: 0; }
.ad-slot-preview { border: 2px dashed rgba(140, 82, 255, .35); border-radius: 12px; padding: 14px; display: grid; justify-items: center; gap: 2px; text-align: center; }
.ad-slot-preview span { font-size: .7rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.ad-slot-preview b { color: var(--primary); font-family: var(--font-head); }
.ad-slot-preview small { color: var(--muted); }
[data-panel="sponsors"] .card + .card { margin-top: 16px; }
.empty { padding: 20px; }

/* Zonas y playoff */
.zonas-lista { display: flex; flex-wrap: wrap; gap: 8px; }
.zona-chip { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.zona-select { padding: 5px 8px; width: auto; }
tr.clasifica td:first-child { box-shadow: inset 3px 0 0 var(--primary); color: var(--primary); font-weight: 700; }
.clasifica-dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; background: var(--primary); vertical-align: middle; margin-right: 4px; }
.penales { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
.penales input { width: 44px; padding: 3px 6px; text-align: center; }
.match.tbd { opacity: .65; }
.campeon { display: flex; align-items: center; gap: 10px; padding: 14px 18px; margin-bottom: 18px; border-radius: 12px; background: linear-gradient(90deg, rgba(251, 191, 36, .18), transparent); border: 1px solid rgba(251, 191, 36, .45); font-size: 1.05rem; }
.sponsor.is-vertical { grid-template-columns: 90px minmax(0, 1fr) auto; }
#sponsorsBanners .sponsor.is-vertical { grid-template-columns: 90px minmax(0, 1fr) auto; }
.sponsor.is-vertical .sponsor-img { aspect-ratio: 1 / 2; }
.ad-slot-preview.vertical { max-width: 160px; aspect-ratio: 1 / 2; align-content: center; }

/* Armado manual del playoff */
.modal.modal-wide { max-width: 640px; max-height: 90vh; overflow-y: auto; }
.modal .field select#mNCruces { display: inline-block; margin-right: 8px; }
.cruces { display: grid; gap: 8px; margin: 6px 0 10px; }
.cruce { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto minmax(0, 1fr); gap: 8px; align-items: center; }
@media (max-width: 640px) {
  .cruce { grid-template-columns: 1fr; gap: 4px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
}

/* Copy box */
.copy { display: flex; gap: 8px; }
.copy input { font-family: ui-monospace, monospace; font-size: .82rem; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { width: 100%; max-width: 480px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; }
.modal h2 { margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* Toast */
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--surface-2); border: 1px solid var(--border); padding: 10px 18px; border-radius: 10px; font-weight: 600; opacity: 0; transition: .2s; z-index: 60; pointer-events: none; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { border-color: var(--danger); color: var(--danger); }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 380px; }
.login .brand { justify-content: center; margin-bottom: 22px; font-size: 1.2rem; }
.error-msg { color: var(--danger); font-size: .85rem; min-height: 1.2em; margin: 6px 0 0; }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }

.match { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto; }
.match .team span { min-width: 0; overflow-wrap: break-word; hyphens: auto; }
.nav-cuenta { display: none; }

@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .brand-text { display: none; }
  .nav-email { display: none; }
  .nav-cuenta { display: inline; }
  .container { padding: 20px 16px 48px; }
  .match { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 8px; padding: 12px; }
  .match .team { gap: 6px; font-size: .88rem; }
  .match .crest { width: 24px; height: 24px; }
  .score input { width: 42px; }
  .score.live { gap: 3px; }
  .gol-btn { width: 30px; height: 30px; }
  .score.live b { font-size: 1.3rem; min-width: 22px; }
  #envivo .gol-btn { width: 38px; height: 38px; }
  #envivo .score.live b { font-size: 1.5rem; }
  /* Partidos en celular: equipos arriba (uno a cada lado), marcador abajo a todo el ancho */
  .match { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); row-gap: 10px; }
  .match .team.home { grid-column: 1; grid-row: 1; justify-content: flex-end; text-align: left; flex-direction: row-reverse; }
  .match .team:not(.home) { grid-column: 2; grid-row: 1; justify-content: flex-start; text-align: right; flex-direction: row-reverse; }
  .match .team span { overflow-wrap: normal; }
  .match .score { grid-column: 1 / -1; grid-row: 2; justify-content: center; }
  .match .score.live { justify-content: space-between; }
  .match .match-actions { grid-row: 3; }
  .match .match-meta { grid-row: 4; }
  #envivo .match.is-live .score.live b { font-size: 2rem; }
  #envivo .match.is-live .gol-btn { width: 48px; height: 48px; font-size: 1.5rem; }
  .match-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .nav a { padding: 6px 8px; }
  .sponsor, .sponsor.is-logo, #sponsorsBanners .sponsor { grid-template-columns: 1fr; }
  .sponsor-actions { justify-content: flex-start; }
}
