:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #16a34a;
  --primary-dark: #15803d;
  --danger: #dc2626;
  --warn: #d97706;
  --topbar: #0f172a;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 12px rgba(15, 23, 42, .05);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }

/* ---------- Top bar ---------- */
.topbar { background: var(--topbar); color: #fff; position: sticky; top: 0; z-index: 20; }
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px 6px; max-width: 960px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 1.3rem; letter-spacing: .3px; }
.brand b { color: #4ade80; }
.brand-ball { font-size: 1.4rem; }
.tabs {
  display: flex; gap: 4px; max-width: 960px; margin: 0 auto; padding: 0 12px;
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  background: none; border: none; color: #cbd5e1; padding: 10px 12px;
  border-bottom: 3px solid transparent; white-space: nowrap; font-weight: 500;
}
.tabs button.active { color: #fff; border-bottom-color: #4ade80; }

/* ---------- Layout ---------- */
main { max-width: 960px; margin: 0 auto; padding: 16px; }
.tab > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
h2 { margin: 0; font-size: 1.15rem; }
h3 { margin: 0 0 8px; font-size: 1rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.card + .card { margin-top: 12px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* ---------- Buttons & inputs ---------- */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 8px 14px; border-radius: 10px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { background: #f8fafc; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-ghost { background: transparent; border-color: rgba(255,255,255,.25); color: #fff; }
.btn-ghost:hover { background: rgba(255,255,255,.1); }
.btn-sm { padding: 4px 10px; font-size: .85rem; border-radius: 8px; }
.btn-icon { padding: 4px 8px; }

input[type=text], input[type=number], input[type=date], input[type=password], select, textarea {
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fff;
  color: var(--text); min-width: 0; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bbf7d0; border-color: var(--primary); }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
label.field > input, label.field > select { font-size: 1rem; color: var(--text); }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.check input { width: 18px; height: 18px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: .93rem; }
th, td { padding: 8px 8px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .4px; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable.on { color: var(--primary-dark); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.inactive td { color: var(--muted); }
.pos { color: var(--primary-dark); font-weight: 600; }
.neg { color: var(--danger); font-weight: 600; }
tfoot td { font-weight: 600; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge-temporada { background: #dcfce7; color: #166534; }
.badge-media { background: #dbeafe; color: #1e40af; }
.badge-partido { background: #fef3c7; color: #92400e; }
.badge-gray { background: #e2e8f0; color: #334155; }

/* ---------- Match list ---------- */
.match-card {
  display: flex; align-items: center; gap: 12px; cursor: pointer;
}
.match-card:hover { box-shadow: 0 2px 8px rgba(15,23,42,.12); }
.match-date { flex: 1; }
.match-date b { display: block; }
.score {
  display: flex; align-items: center; gap: 8px; font-size: 1.3rem; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.score .team-dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; border: 1px solid #94a3b8; }
.team-dot.negro { background: #111; }
.team-dot.blanco { background: #fff; }
.score-sep { color: var(--muted); font-weight: 400; }
.match-pending { color: var(--muted); font-weight: 500; font-size: .95rem; }

/* ---------- Match editor ---------- */
.roster { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; }
.roster-item {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  border: 1px solid var(--line); border-radius: 10px; padding: 6px 6px 6px 10px;
}
.roster-item.in-negro { border-color: #111; background: #f5f5f5; }
.roster-item.in-blanco { border-color: #94a3b8; background: #fff; }
.roster-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: none; background: #fff; padding: 4px 9px; font-size: .8rem; font-weight: 600; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on-none { background: #e2e8f0; color: var(--text); }
.seg button.on-negro { background: #111; color: #fff; }
.seg button.on-blanco { background: #fff; color: #111; box-shadow: inset 0 0 0 2px #111; }

.counters { display: flex; gap: 10px; flex-wrap: wrap; }
.counter { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.counter.over { color: var(--warn); }

.scoreboard {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; text-align: center;
}
.scoreboard .big { font-size: 2.4rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.scoreboard .team-name { font-weight: 600; text-transform: uppercase; letter-spacing: 1px; font-size: .8rem; color: var(--muted); }
.scoreboard .dash { font-size: 1.6rem; color: var(--muted); }
.extra { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: .8rem; color: var(--muted); margin-top: 6px; }
.extra input { width: 56px; padding: 3px 6px; text-align: center; }

.pitch-wrap { display: flex; justify-content: center; }
.pitch {
  position: relative; width: 100%; max-width: 440px; aspect-ratio: 2 / 3;
  background: repeating-linear-gradient(180deg, #2f9e44 0 12.5%, #37a94c 12.5% 25%);
  border: 3px solid #e6f4ea; border-radius: 6px; overflow: hidden; touch-action: none; user-select: none;
}
.pitch .line { position: absolute; border: 2px solid rgba(255,255,255,.85); }
.pitch .mid { left: 0; right: 0; top: 50%; border-width: 1px 0 0; }
.pitch .circle { left: 50%; top: 50%; width: 22%; aspect-ratio: 1; transform: translate(-50%, -50%); border-radius: 50%; }
.pitch .area { left: 22%; width: 56%; height: 16%; }
.pitch .area.top { top: -2px; border-top: none; }
.pitch .area.bottom { bottom: -2px; border-bottom: none; }
.pitch .goal { left: 40%; width: 20%; height: 3.5%; background: rgba(255,255,255,.35); }
.pitch .goal.top { top: -2px; } .pitch .goal.bottom { bottom: -2px; }
.pitch .half-label {
  position: absolute; left: 8px; font-size: .7rem; font-weight: 700; letter-spacing: 1px; text-transform: uppercase;
  color: rgba(255,255,255,.75);
}
.pitch .half-label.top { top: 6px; } .pitch .half-label.bottom { bottom: 6px; }

.chip {
  position: absolute; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center;
  gap: 2px; cursor: grab; width: 64px; text-align: center;
}
.chip.dragging { cursor: grabbing; z-index: 5; }
.chip .dot {
  width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .8rem; box-shadow: 0 2px 4px rgba(0,0,0,.35); border: 2px solid #fff;
}
.chip.negro .dot { background: #111; color: #fff; }
.chip.blanco .dot { background: #fff; color: #111; border-color: #111; }
.chip .label {
  font-size: .68rem; font-weight: 600; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.7);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 64px;
}
.chip .g { position: absolute; top: -4px; right: 6px; background: #facc15; color: #111; border-radius: 999px; font-size: .65rem; font-weight: 800; padding: 0 5px; line-height: 16px; }
.pitch.readonly .chip { cursor: default; }

.goals-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .goals-grid { grid-template-columns: 1fr; } }
.goals-team h3 { display: flex; align-items: center; gap: 8px; }
.goal-row { display: flex; align-items: center; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--line); }
.goal-row:last-child { border-bottom: none; }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper button { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line); background: #fff; font-weight: 700; }
.stepper span { min-width: 24px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Stats ---------- */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.stat-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; text-align: center; }
.stat-card .v { font-size: 1.7rem; font-weight: 800; line-height: 1.1; }
.stat-card .l { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-top: 4px; }
.stat-card.negro { background: #111; color: #fff; }
.stat-card.negro .l { color: #cbd5e1; }
.stat-card.blanco { border: 2px solid #111; }

/* ---------- Modal & toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-card { background: #fff; border-radius: 14px; padding: 18px; width: 100%; max-width: 420px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal-card h2 { margin-bottom: 12px; }
.modal-card .form-grid { grid-template-columns: 1fr; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.error { color: var(--danger); font-size: .85rem; margin-top: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: .9rem;
  box-shadow: 0 4px 16px rgba(0,0,0,.3); z-index: 60; max-width: 90vw;
}
.toast.err { background: var(--danger); }

.sticky-actions {
  position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%);
  padding: 12px 0 4px; display: flex; gap: 8px; justify-content: flex-end;
}
