/* ======================================================================
   v3: nuevas funciones (Mi equipo, agenda, probabilidades, actas, PWA…)
   ====================================================================== */
.left { text-align: left !important; }
.center { text-align: center; }
.muted { opacity: .7; }
.small { font-size: .82rem; }
.nowrap { white-space: nowrap; }
.inline { display: inline-flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }
.header-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.header-btns select { max-width: 270px; }
.btn-ghost { background: transparent; color: #3498db; border: 1px solid #3498db; }
.btn-ghost:hover { background: rgba(52,152,219,.12); }
.btn-ghost.fav-on, button.fav-on { background: #f1c40f; color: #333; border-color: #f1c40f; }
.small-btn { padding: 4px 10px; font-size: .8rem; }
.btn-link { color: #3498db; text-decoration: none; font-weight: 600; font-size: .9rem; white-space: nowrap; }
.btn-link:hover { text-decoration: underline; }
a { color: #3498db; }
.team-bar { background: var(--bg-color); padding: 10px; border-radius: 6px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 18px; }
.section-head h3 { margin: 6px 0; }
.chart-title { text-align: center; margin-top: 0; font-size: 1.05rem; }
.chart-wrap { position: relative; height: 340px; width: 100%; }
.small-chart { height: 180px; }
.chart-box { margin-top: 15px; }

/* Pestañas: una sola fila desplazable */
.tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; -webkit-overflow-scrolling: touch; }
.tab-btn { white-space: nowrap; font-size: .9rem; background: transparent; }
.tab-btn:hover { background: var(--hover-bg); }

/* Escudos */
.crest { width: 20px; height: 20px; object-fit: contain; vertical-align: middle; margin-right: 6px; flex-shrink: 0; }
.crest.big { width: 38px; height: 38px; margin: 0 0 4px 0; }
.crest.huge { width: 64px; height: 64px; margin-right: 12px; }
.team-cell { white-space: nowrap; }
.sim-team { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }

/* Filas destacadas */
tr.my-team td { background: rgba(241,196,15,.18); }
tr.my-team td:first-child { box-shadow: inset 4px 0 0 #f1c40f; }
tr.zone-top td:first-child { box-shadow: inset 4px 0 0 #3498db; }
tr.zone-bottom td:first-child { box-shadow: inset 4px 0 0 #e74c3c; }
.pred-badge { background: #3498db; }
.pred-score.edited { color: #e67e22; }
.prob-row { display: flex; justify-content: center; gap: 3px; min-width: 140px; }

/* Avisos y notas */
.note { padding: 8px 12px; border-radius: 4px; margin-bottom: 12px; font-size: .88rem; background: var(--hover-bg); border-left: 4px solid #3498db; }
.note.ok { border-left-color: #27ae60; }
.note.warn { border-left-color: #f39c12; }
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 10000; display: flex; flex-direction: column; gap: 8px; max-width: 90vw; }
.toast { background: #2c3e50; color: #fff; padding: 10px 14px; border-radius: 6px; box-shadow: 0 4px 12px rgba(0,0,0,.3); font-size: .9rem; transition: opacity .5s; }
.toast.error { background: #c0392b; }
.toast.hide { opacity: 0; }

/* Tarjetas de partido (agenda, mi equipo, mi club) */
.match-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.match-card { border: 1px solid var(--border-color); border-radius: 8px; padding: 10px; background: var(--card-bg); }
.match-card.my-team { border-color: #f1c40f; box-shadow: 0 0 0 1px #f1c40f inset; }
.mc-head { font-size: .8rem; opacity: .75; margin-bottom: 6px; text-transform: capitalize; }
.mc-body { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.mc-team { display: flex; flex-direction: column; align-items: center; text-align: center; font-weight: 600; font-size: .85rem; }
.mc-center { text-align: center; min-width: 130px; }
.mc-score { font-size: 1.5rem; font-weight: 800; }
.mc-pred { font-size: 1.3rem; font-weight: 700; color: #3498db; }
.mc-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 6px; font-size: .8rem; }
.mc-foot a { color: inherit; opacity: .8; text-decoration: none; }
.mc-foot a:hover { text-decoration: underline; }
.club-card .club-row { margin: 4px 0; }

/* Mi equipo */
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; align-items: start; }
.dash-card { border: 1px solid var(--border-color); border-radius: 8px; padding: 14px; background: var(--bg-color); min-width: 0; }
.dash-card h4 { margin: 0 0 8px; }
.dash-card .match-card { margin-bottom: 8px; }
.dash-team { display: flex; align-items: center; }
.dash-team h3 { margin: 0; }
.dash-kpis { display: flex; flex-wrap: wrap; gap: 16px; margin: 12px 0; }
.dash-kpis > div, .stat-card { display: flex; flex-direction: column; }
.kpi { font-size: 1.6rem; font-weight: 800; line-height: 1.1; }
.kpi-l { font-size: .75rem; opacity: .7; text-transform: uppercase; letter-spacing: .03em; }
.small-kpis .kpi { font-size: 1.2rem; }
.dash-facts { padding-left: 18px; margin: 10px 0 0; font-size: .9rem; line-height: 1.6; }
.dash-form { margin: 6px 0; }

/* Estadísticas */
.stat-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 10px; }
.stat-card { border: 1px solid var(--border-color); border-radius: 8px; padding: 10px; background: var(--bg-color); gap: 4px; font-size: .88rem; }
.stat-card.wide { grid-column: span 2; }
table.narrow { min-width: 0; }

/* Mapa de calor Monte Carlo */
.heat-table td { font-variant-numeric: tabular-nums; }
#mc_heat { min-width: 0; font-size: .78rem; }
#mc_heat td, #mc_heat th { padding: 5px 4px; min-width: 26px; }

/* Acta */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 9000; display: flex; align-items: flex-start; justify-content: center; padding: 30px 10px; overflow-y: auto; }
.modal[hidden] { display: none; }
.modal-box { background: var(--card-bg); color: var(--text-color); border-radius: 10px; padding: 20px; max-width: 820px; width: 100%; position: relative; }
.modal-close { position: absolute; top: 10px; right: 10px; background: transparent; color: var(--text-color); font-size: 1.2rem; }
.acta-score { margin: 8px 0; }
.acta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 12px; }
.acta-side h4 { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; }
.events, .players { list-style: none; padding: 0; margin: 6px 0; font-size: .88rem; }
.events li { padding: 3px 0; border-bottom: 1px dashed var(--border-color); }
.minute { display: inline-block; min-width: 32px; opacity: .7; font-variant-numeric: tabular-nums; }

/* Imagen para compartir */
.share-title { display: none; font-weight: 800; font-size: 1.05rem; margin-bottom: 8px; }
.share-area.sharing { padding: 14px; background: var(--card-bg); }
.share-area.sharing .share-title { display: block; }
.share-area.sharing .table-container { max-height: none !important; overflow: visible; }
.share-area.sharing .share-title::after { content: " · Liga Predictor"; font-weight: 400; opacity: .6; font-size: .85rem; }

@media (max-width: 900px) {
    .dash-grid { grid-template-columns: 1fr; }
    .stat-cards { grid-template-columns: 1fr 1fr; }
    .acta-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    body { padding: 0; }
    .container { padding: 12px; border-radius: 0; box-shadow: none; }
    .tabs { flex-direction: row; border-bottom: 2px solid var(--border-color); }
    .tab-btn { margin-bottom: 0; border: none; border-radius: 5px 5px 0 0; padding: 10px 12px; }
    .tab-btn.active { margin-bottom: -2px; border-bottom: 2px solid #3498db; }
    .header-btns select { max-width: none; flex: 1 1 100%; }
    .header-btns button { flex: 1; }
    table { font-size: .8rem; }
    th, td { padding: 6px 4px; }
    .match-cards { grid-template-columns: 1fr; }
    .stat-card.wide { grid-column: 1 / -1; }
    .kpi { font-size: 1.3rem; }
}

/* Tarjetas en columnas estrechas */
.mc-body { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
.mc-team span { overflow-wrap: break-word; hyphens: auto; }
.mc-center { min-width: 0; }
.match-card .prob-row { min-width: 0; }
.match-card .prob-box { padding: 3px 4px; font-size: .72rem; }

/* ===== Menú de ajustes (v3.1) ===== */
.settings-wrap { position: relative; }
.settings-panel {
    position: absolute; right: 0; top: calc(100% + 8px); z-index: 8000;
    width: 340px; max-width: calc(100vw - 24px);
    background: var(--card-bg); color: var(--text-color);
    border: 1px solid var(--border-color); border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,.25); padding: 14px;
    max-height: calc(100vh - 100px); overflow-y: auto;
}
.settings-panel[hidden] { display: none; }
.settings-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; font-size: 1.05rem; }
.settings-head .modal-close { position: static; padding: 4px 8px; }
.set-group { border-top: 1px solid var(--border-color); padding: 10px 0 6px; }
.set-title { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; opacity: .6; margin-bottom: 6px; }
.set-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 5px 0; font-size: .9rem; cursor: pointer; }
.set-row select { padding: 6px; max-width: 180px; }
.set-hint { font-size: .75rem; opacity: .65; margin: 0 0 6px; }
.set-hint:empty { display: none; }
.set-btn { width: 100%; margin: 4px 0 2px; }
.set-version { border-top: 1px solid var(--border-color); padding-top: 10px; font-size: .8rem; opacity: .7; text-align: center; }

/* Interruptor */
input.switch { appearance: none; -webkit-appearance: none; width: 40px; height: 22px; border-radius: 11px; padding: 0;
    background: #bbb; position: relative; cursor: pointer; transition: background .2s; border: none; flex-shrink: 0; }
input.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
    background: #fff; transition: left .2s; }
input.switch:checked { background: #27ae60; }
input.switch:checked::after { left: 21px; }

@media (max-width: 768px) {
    .settings-panel { position: fixed; left: 12px; right: 12px; top: 60px; width: auto; max-height: calc(100vh - 80px); overflow-y: auto; }
}

/* ===== v3.2: más ancho y tarjetas tipo marcador ===== */
.container { max-width: 1500px; }
.match-cards { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.dash-grid { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

.match-card { display: flex; flex-direction: column; gap: 6px; padding: 12px 14px; }
.match-card .mc-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 0; text-transform: none; }
.mc-tag { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 2px 8px; border-radius: 10px; background: var(--hover-bg); opacity: 1; }
.mc-tag.pred { background: rgba(52,152,219,.15); color: #3498db; }
.mc-row { display: flex; align-items: center; gap: 10px; min-height: 34px; }
.mc-row .crest.mid { width: 28px; height: 28px; margin: 0; }
.mc-name { flex: 1; min-width: 0; font-weight: 600; font-size: .92rem; line-height: 1.25; overflow-wrap: break-word; }
.mc-row.mine .mc-name { color: #b7950b; }
body.dark-mode .mc-row.mine .mc-name { color: #f1c40f; }
.mc-goals { font-size: 1.35rem; font-weight: 800; min-width: 28px; text-align: right; font-variant-numeric: tabular-nums; }
.mc-goals.pred { color: #3498db; font-style: italic; }
.mc-row.win .mc-goals { color: #27ae60; }
.mc-row.loss .mc-name { opacity: .7; }

.pbar { display: flex; height: 22px; border-radius: 6px; overflow: hidden; font-size: .72rem; font-weight: 700; margin-top: 4px; }
.pbar-seg { display: flex; align-items: center; justify-content: center; white-space: nowrap; overflow: hidden; color: #222; min-width: 0; padding: 0 4px; }
.pbar-seg.p1 { background: rgba(39,174,96,.55); }
.pbar-seg.px { background: rgba(241,196,15,.55); }
.pbar-seg.p2 { background: rgba(231,76,60,.55); }
.pbar-seg.top { filter: saturate(1.6) brightness(.95); box-shadow: inset 0 0 0 2px rgba(0,0,0,.35); }
body.dark-mode .pbar-seg { color: #fff; }
.mc-meta { font-size: .75rem; opacity: .7; }
.match-card .mc-foot { margin-top: auto; padding-top: 4px; border-top: 1px dashed var(--border-color); }
.mc-foot a { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Tablas: los nombres largos no rompen la fila en pantallas anchas */
td.team-cell { max-width: 420px; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 768px) {
    td.team-cell { max-width: 220px; }
}
/* Móviles pequeños: una columna (sin min(), que html2canvas no entiende) */
@media (max-width: 420px) {
    .match-cards, .dash-grid { grid-template-columns: 1fr; }
}

/* ===== v3.2.3: barra de pestañas sin barras de desplazamiento ===== */
/* La pestaña activa usaba margin-bottom:-2px para pisar la línea: eso hacía la barra 2 px más
   alta que su caja y el navegador mostraba una barra de scroll vertical. Ahora la línea se dibuja
   con una sombra interior y la pestaña activa no se sale. */
.tabs { position: relative; border-bottom: none; box-shadow: inset 0 -2px 0 var(--border-color);
        overflow-x: auto; overflow-y: hidden; scrollbar-width: none; -ms-overflow-style: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab-btn, .tab-btn.active { margin-bottom: 0; border: none; border-bottom: 2px solid transparent; border-radius: 5px 5px 0 0; }
.tab-btn.active { border-bottom-color: #3498db; background: transparent; }
/* En pantallas estrechas se sigue pudiendo deslizar: un degradado indica que hay más pestañas */
.tabs.more-right { -webkit-mask-image: linear-gradient(to right, #000 85%, transparent); mask-image: linear-gradient(to right, #000 85%, transparent); }
.tabs.more-left { -webkit-mask-image: linear-gradient(to left, #000 85%, transparent); mask-image: linear-gradient(to left, #000 85%, transparent); }
.tabs.more-left.more-right { -webkit-mask-image: linear-gradient(to right, transparent, #000 15%, #000 85%, transparent); mask-image: linear-gradient(to right, transparent, #000 15%, #000 85%, transparent); }
@media (max-width: 768px) {
    .tabs { border-bottom: none; }
    .tab-btn, .tab-btn.active { margin-bottom: 0; border: none; border-bottom: 2px solid transparent; }
    .tab-btn.active { border-bottom-color: #3498db; }
}

/* ===== v3.2.4: revisión para móvil ===== */
/* Campos con etiqueta: Mis ligas y Mi equipo */
.field-block { margin-bottom: 12px; }
.field-block.team-bar { padding: 10px 12px; }
.field-label { display: block; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; opacity: .75; margin-bottom: 4px; }
.field-row { display: flex; gap: 8px; align-items: stretch; }
.field-row select { flex: 1; min-width: 0; }
.icon-btn { flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-width: 44px; padding: 8px 14px; white-space: nowrap; }

/* Nada puede ser más ancho que la pantalla (los <select> con textos largos se estiraban) */
select, input, button { max-width: 100%; }
select { min-width: 0; text-overflow: ellipsis; }
.charts-grid > *, .dash-grid > *, .match-cards > *, .stat-cards > * { min-width: 0; }
.section-head { flex-wrap: wrap; }

@media (max-width: 768px) {
    /* Botones de icono: grandes para el dedo y sin texto */
    .field-row .btn-text { display: none; }
    .icon-btn { min-height: 44px; padding: 0 14px; font-size: 1.1rem; }
    /* Los controles de cada pestaña fluyen en filas en vez de apilarse a todo el ancho */
    .controls { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; }
    .controls > select, .controls > input[type="text"] { flex: 1 1 100%; }
    .controls > .spacer { display: none; }
    .controls > .btn-group { width: 100%; }
    .controls > .inline { flex-wrap: wrap; }
    .charts-grid { gap: 12px; }
    .section-head h3 { font-size: 1.05rem; }
}

/* ===== v3.2.4: tablas en el móvil =====
   En pantallas estrechas se ocultan las columnas secundarias para que las importantes quepan sin
   desplazarse de lado. Los nombres largos se recortan con "…" (el nombre completo sigue en el
   resto de pantallas). La tabla de estadísticas por equipo y el mapa de calor se siguen
   desplazando de lado porque necesitan todas sus columnas. */
@media (max-width: 768px) {
    #standings_table, #team_matches_table, #pred_standings_table, #mc_table,
    #form_table, #bt_table, #scorers_table { min-width: 0; }
    #standings_table td.team-cell, #team_matches_table td.team-cell, #pred_standings_table td.team-cell,
    #mc_table td.team-cell, #form_table td.team-cell, #scorers_table td.left {
        max-width: 0; width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    /* Clasificación: #, Equipo, PJ, DG, Pts y las 3 últimas de la racha */
    #standings_table th:nth-child(n+4):nth-child(-n+8), #standings_table td:nth-child(n+4):nth-child(-n+8) { display: none; }
    #standings_table .form-badge:nth-child(-n+2) { display: none; }
    /* Partidos del equipo: sin posición ni % */
    #team_matches_table th:nth-child(5), #team_matches_table td:nth-child(5),
    #team_matches_table th:nth-child(7), #team_matches_table td:nth-child(7) { display: none; }
    /* Clasificación simulada: #, Equipo, simulados y total */
    #pred_standings_table th:nth-child(3), #pred_standings_table td:nth-child(3),
    #pred_standings_table th:nth-child(4), #pred_standings_table td:nth-child(4) { display: none; }
    /* Probabilidades: sin el rango ni los puntos actuales */
    #mc_table th:nth-child(4), #mc_table td:nth-child(4) { display: none; }
    #mc_table td small { display: none; }
    /* Últimas 5 jornadas: sin GF y GC */
    #form_table th:nth-child(5), #form_table td:nth-child(5),
    #form_table th:nth-child(6), #form_table td:nth-child(6) { display: none; }
    /* Fiabilidad: modelo, acierto y Brier */
    #bt_table th:nth-child(2), #bt_table td:nth-child(2), #bt_table th:nth-child(4), #bt_table td:nth-child(4),
    #bt_table th:nth-child(6), #bt_table td:nth-child(6), #bt_table th:nth-child(7), #bt_table td:nth-child(7) { display: none; }
    /* Goleadores: sin PJ ni goles por partido */
    #scorers_table th:nth-child(4), #scorers_table td:nth-child(4),
    #scorers_table th:nth-child(6), #scorers_table td:nth-child(6) { display: none; }
    #scorers_table td.team-cell { max-width: 110px; overflow: hidden; text-overflow: ellipsis; }

    /* Simulador: cada partido como una tarjeta con los botones +/− a la vista */
    #pred_matches_table { min-width: 0; }
    #pred_matches_table thead { display: none; }
    #pred_matches_table, #pred_matches_table tbody { display: block; }
    #pred_matches_table tr { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; gap: 6px 8px;
        grid-template-areas: "j l rl" "j v rv" "p p p" "s s s"; padding: 10px 8px; border-bottom: 1px solid var(--border-color); }
    #pred_matches_table td { border: none; padding: 0; text-align: left; min-width: 0; }
    #pred_matches_table .prob-row { min-width: 0; }
    #pred_matches_table td:nth-child(1) { grid-area: j; text-align: center; padding-top: 4px; }
    #pred_matches_table td:nth-child(2) { grid-area: l; align-self: center; }
    #pred_matches_table td:nth-child(3) { grid-area: rl; align-self: center; }
    #pred_matches_table td:nth-child(4) { grid-area: v; align-self: center; }
    #pred_matches_table td:nth-child(5) { grid-area: rv; align-self: center; }
    #pred_matches_table td:nth-child(6) { grid-area: p; }
    #pred_matches_table td:nth-child(7) { grid-area: s; text-align: center; }
    #pred_matches_table td[colspan] { grid-column: 1 / -1; text-align: center; }
    #pred_matches_table .sim-team { flex-wrap: nowrap; }
    #pred_matches_table .sim-team b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    #pred_matches_table .form-fixed .form-badge { width: 18px; height: 18px; font-size: .65rem; }
    #pred_matches_table .pred-controls button { padding: 6px 14px; }
    #pred_matches_table .pred-score { min-width: 28px; margin: 0 6px; }
    .table-container[style*="max-height"] { max-height: none !important; }
}

/* ===== v3.2.6: racha del simulador en columnas propias y alineada ===== */
.form-fixed { display: inline-flex; gap: 3px; flex-wrap: nowrap; }
.form-badge.form-empty { background: transparent; box-shadow: inset 0 0 0 1px var(--border-color); }
#pred_matches_table th.th-form, #pred_matches_table td.td-form { width: 1%; white-space: nowrap; text-align: center; padding-left: 4px; padding-right: 4px; }
#pred_matches_table .sim-team { display: flex; align-items: center; gap: 6px; }
