/* ============ BasketStats - estilo minimalista ============ */
:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --line: #e5e3de;
  --accent: #e8590c;
  --accent-soft: #fdeee3;
  --green: #2f9e44;
  --red: #d6336c;
  --blue: #1971c2;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.07);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}
button { font-family: inherit; cursor: pointer; }
a { color: inherit; }

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
}
.brand { font-weight: 800; font-size: 1.05rem; text-decoration: none; white-space: nowrap; }
.topnav { display: flex; gap: 4px; flex: 1; }
.topnav a {
  text-decoration: none; font-size: .9rem; font-weight: 600; color: var(--muted);
  padding: 6px 12px; border-radius: 999px;
}
.topnav a.active { background: var(--accent-soft); color: var(--accent); }
.sync-btn {
  display: flex; align-items: center; gap: 6px;
  background: none; border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; font-size: .8rem; font-weight: 600; color: var(--muted);
}
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: #adb5bd; }
.sync-dot.online { background: var(--green); }
.sync-dot.pending { background: var(--accent); }
.sync-dot.syncing { background: var(--blue); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------- Layout ---------- */
.container { max-width: 960px; margin: 0 auto; padding: 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 1.3rem; }
.page-head .sub { color: var(--muted); font-size: .85rem; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px;
}
.card h2 { font-size: 1rem; margin-bottom: 12px; }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; font-size: .95rem; }
.empty .big { font-size: 2rem; display: block; margin-bottom: 8px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 10px; font-weight: 700; font-size: .9rem;
  padding: 10px 16px; background: var(--accent); color: #fff;
  transition: filter .1s;
}
.btn:active { filter: brightness(.9); }
.btn.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: var(--red); }
.btn.green { background: var(--green); }
.btn.small { padding: 6px 12px; font-size: .8rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Listas ---------- */
.list-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px;
  text-decoration: none; box-shadow: var(--shadow);
}
.list-item:active { background: var(--accent-soft); }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 700; }
.list-item .meta { color: var(--muted); font-size: .82rem; margin-top: 2px; }
.chev { color: var(--muted); }

.badge {
  font-size: .7rem; font-weight: 700; padding: 3px 10px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: .04em;
}
.badge.live { background: #ffe3e3; color: #c92a2a; }
.badge.finished { background: #e6f4ea; color: var(--green); }
.badge.scheduled { background: #e7f0fa; color: var(--blue); }

/* ---------- Formularios ---------- */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field input, .field select {
  width: 100%; padding: 11px 12px; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text);
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); border-color: transparent; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15,15,15,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--surface); width: 100%; max-width: 480px;
  border-radius: 18px 18px 0 0; padding: 20px;
  max-height: 85vh; overflow-y: auto;
  animation: slideUp .18s ease-out;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: .5; } }
.modal h3 { font-size: 1.05rem; margin-bottom: 14px; }
.modal .modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal .modal-actions .btn { flex: 1; }

/* Selector de jugadores (grid de dorsales) */
.player-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 10px; }
.player-cell {
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  padding: 10px 4px; text-align: center;
}
.player-cell:active { background: var(--accent-soft); border-color: var(--accent); }
.player-cell .num { font-size: 1.4rem; font-weight: 800; }
.player-cell .pname { font-size: .68rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-cell.team-only { grid-column: 1 / -1; padding: 12px; font-weight: 700; color: var(--muted); }

/* ---------- Partido en vivo ---------- */
.scoreboard {
  background: #21252b; color: #fff; border-radius: var(--radius);
  padding: 18px 12px 14px; margin-bottom: 12px; text-align: center;
}
.scoreboard .teams { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; }
.scoreboard .tname { font-size: .85rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scoreboard .score { font-size: 3rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.scoreboard .vs { color: #868e96; font-size: .8rem; }
.scoreboard .fouls { font-size: .72rem; color: #ced4da; margin-top: 6px; }
.scoreboard .period-bar { display: flex; justify-content: center; gap: 6px; margin-top: 12px; align-items: center; flex-wrap: wrap; }
.period-pill {
  border: 1px solid #495057; background: none; color: #adb5bd;
  border-radius: 999px; padding: 4px 12px; font-size: .75rem; font-weight: 700;
}
.period-pill.current { background: var(--accent); border-color: var(--accent); color: #fff; }

.qtable { width: 100%; border-collapse: collapse; font-size: .82rem; margin-top: 4px; }
.qtable th, .qtable td { padding: 6px 8px; text-align: center; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.qtable th:first-child, .qtable td:first-child { text-align: left; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qtable .tot { font-weight: 800; }

.action-panels { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; box-shadow: var(--shadow);
}
.panel .panel-title { font-weight: 800; font-size: .85rem; text-align: center; margin-bottom: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.sbtn {
  border: none; border-radius: 10px; font-weight: 800; font-size: 1.05rem; padding: 14px 4px; color: #fff;
}
.sbtn.plus { background: var(--green); }
.sbtn.minus { background: #adb5bd; font-size: .9rem; padding: 10px 4px; }
.sbtn:active { filter: brightness(.85); }
.stat-buttons { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat-btn {
  border: 1px solid var(--line); background: var(--bg); border-radius: 10px;
  padding: 10px 4px; font-weight: 700; font-size: .8rem; color: var(--text);
}
.stat-btn:active { background: var(--accent-soft); }
.stat-btn.foul { background: #fff5f5; border-color: #ffc9c9; color: #c92a2a; }

.game-actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.game-actions .btn { flex: 1; min-width: 140px; }

.event-log { max-height: 260px; overflow-y: auto; }
.event-row { display: flex; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--line); font-size: .82rem; align-items: center; }
.event-row .etime { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.event-row .grow { flex: 1; }
.event-row .undo { background: none; border: none; color: var(--red); font-weight: 700; font-size: .75rem; }

/* ---------- Estadisticas ---------- */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(105px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 10px; text-align: center; box-shadow: var(--shadow);
}
.stat-card .val { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-card .lbl { font-size: .7rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin-top: 2px; }
.stat-card.accent .val { color: var(--accent); }

.table-wrap { overflow-x: auto; }
.stats-table { width: 100%; border-collapse: collapse; font-size: .85rem; white-space: nowrap; }
.stats-table th, .stats-table td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: center; font-variant-numeric: tabular-nums; }
.stats-table th { font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.stats-table th:first-child, .stats-table td:first-child { text-align: left; }
.stats-table tr.clickable { cursor: pointer; }
.stats-table tr.clickable:active { background: var(--accent-soft); }

.back-link { display: inline-block; color: var(--muted); text-decoration: none; font-size: .85rem; font-weight: 600; margin-bottom: 10px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #21252b; color: #fff; padding: 10px 20px; border-radius: 999px;
  font-size: .85rem; font-weight: 600; z-index: 200; box-shadow: 0 4px 14px rgba(0,0,0,.25);
  max-width: 90vw; text-align: center;
}

/* ---------- Responsive ---------- */
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 18px; }
  .scoreboard .score { font-size: 4rem; }
}
@media (max-width: 420px) {
  .topnav a { padding: 6px 9px; font-size: .82rem; }
  .action-panels { gap: 8px; }
  .stat-buttons { grid-template-columns: 1fr 1fr; }
}
