/* Componentes — tema "Panel oscuro". Ver design-system/MASTER.md. Requiere tokens.css. */

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font-body);
    font-size: var(--fs-md);
    line-height: 1.5;
    color: var(--c-text);
    background: var(--c-bg);
    -webkit-font-smoothing: antialiased;
    touch-action: manipulation;
}
h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.02em;
    margin: 0 0 var(--sp-3);
}
h1 { font-size: 1.75rem; }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
p { margin: 0 0 var(--sp-4); max-width: 70ch; }
a { color: var(--c-link); text-underline-offset: 2px; }
a:hover { text-decoration: underline; }
img, svg { max-width: 100%; }
hr { border: 0; border-top: 1px solid var(--c-border); margin: var(--sp-5) 0; }
code { font-size: 0.9em; padding: 1px 6px; border-radius: var(--radius-sm); background: var(--c-surface-2); }
:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 2px; border-radius: 4px; }
.muted { color: var(--c-text-muted); }
.visually-hidden {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link { position: absolute; left: var(--sp-3); top: -100px; z-index: var(--z-modal); background: var(--c-primary); color: var(--c-primary-contrast); padding: var(--sp-2) var(--sp-4); border-radius: var(--radius); font-weight: 700; }
.skip-link:focus { top: var(--sp-3); }

.icon { width: 1.25em; height: 1.25em; flex: none; vertical-align: -0.2em; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Layout ---------- */
.container { width: 100%; max-width: 80rem; margin: 0 auto; padding: var(--sp-4); }
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.page-header h1 { margin: 0; }
.stack > * + * { margin-top: var(--sp-4); }
.row { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
.grid { display: grid; gap: var(--sp-4); grid-template-columns: 1fr; }

/* ---------- Logo ---------- */
.logo { display: inline-flex; align-items: center; gap: 10px; color: var(--c-text); text-decoration: none; }
.logo:hover { text-decoration: none; color: var(--c-text); }
.logo-mark { height: 2rem; width: auto; flex: none; }
.logo-word { font-family: var(--font-display); font-weight: 700; font-size: 1.375rem; letter-spacing: -0.02em; line-height: 1; }
.logo-lg .logo-mark { height: 3.5rem; }
.logo-lg .logo-word { font-size: 2.5rem; }

/* ---------- Cabecera y menú ---------- */
.navbar { position: sticky; top: 0; z-index: var(--z-nav); background: var(--c-header); border-bottom: 1px solid var(--c-border); }
.navbar-inner { max-width: 80rem; margin: 0 auto; padding: var(--sp-2) var(--sp-4); min-height: 4rem; display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: 10px; min-height: var(--tap); color: var(--c-text); text-decoration: none; }
.brand:hover { text-decoration: none; color: var(--c-text); }
.brand .logo-mark { height: 1.75rem; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 1.25rem; letter-spacing: -0.02em; overflow-wrap: anywhere; }
.nav-toggle { display: inline-flex; align-items: center; justify-content: center; min-width: var(--tap); min-height: var(--tap); background: transparent; color: var(--c-text-soft); border: 1px solid var(--c-border-strong); border-radius: var(--radius); cursor: pointer; }
.nav-toggle:hover { background: var(--c-surface-2); color: var(--c-text); }
.nav-menu { display: none; flex-basis: 100%; list-style: none; margin: 0; padding: var(--sp-1) 0 var(--sp-2); }
.nav-menu.is-open { display: block; }
.nav-menu a, .nav-menu button {
    display: flex; align-items: center; gap: var(--sp-2); width: 100%; min-height: var(--tap); padding: 0 var(--sp-3);
    font-family: var(--font-display); font-size: 0.9375rem; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap;
    color: var(--c-text-soft); text-decoration: none; background: none; border: 0; border-radius: var(--radius); cursor: pointer;
}
.nav-menu a:hover, .nav-menu button:hover { background: var(--c-surface-2); color: var(--c-text); text-decoration: none; }
.nav-menu a[aria-current="page"] { background: var(--c-primary); color: var(--c-primary-contrast); }
.nav-menu form { margin: 0; }

/* ---------- Botones ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
    min-height: var(--tap); padding: 0 var(--sp-4);
    font: inherit; font-size: var(--fs-sm); font-weight: 600; line-height: 1;
    border: 0; border-radius: var(--radius);
    cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: background-color 0.15s, opacity 0.15s, color 0.15s, box-shadow 0.15s;
}
.btn:hover { text-decoration: none; }
.btn-primary, .btn-cta { background: var(--c-primary); color: var(--c-primary-contrast); }
.btn-primary:hover, .btn-cta:hover { opacity: 0.9; color: var(--c-primary-contrast); }
.btn-secondary { background: var(--c-surface-2); color: var(--c-text); box-shadow: inset 0 0 0 1px var(--c-border-strong); }
.btn-secondary:hover { background: var(--c-border); color: var(--c-text); }
.btn-ghost { background: transparent; color: var(--c-text-soft); }
.btn-ghost:hover { background: var(--c-surface-2); color: var(--c-text); }
.btn-danger { background: var(--c-danger-solid); color: var(--c-danger-on); }
.btn-danger:hover { filter: brightness(1.1); color: var(--c-danger-on); }
.btn-sm { min-height: 2.5rem; padding: 0 var(--sp-3); }
.btn-block { display: flex; width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.btn[aria-busy="true"] { pointer-events: none; opacity: 0.6; }
.btn[aria-busy="true"]::before {
    content: ""; width: 1em; height: 1em; border-radius: 50%;
    border: 2px solid currentColor; border-right-color: transparent;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.btn-icon { padding: 0; min-width: var(--tap); }

/* ---------- Formularios ---------- */
.field { margin-bottom: var(--sp-4); }
.label { display: block; font-size: var(--fs-sm); font-weight: 500; color: var(--c-text-soft); margin-bottom: var(--sp-1); }
.label .req { color: var(--c-danger-text); }
.input, .select, .textarea {
    display: block; width: 100%; min-height: var(--tap);
    padding: var(--sp-2) var(--sp-3);
    font: inherit; font-size: 1rem; color: var(--c-text);
    background: var(--c-bg); border: 1px solid var(--c-border-strong); border-radius: var(--radius);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.textarea { min-height: 96px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--c-primary); box-shadow: 0 0 0 1px var(--c-primary); outline: none; }
.input::placeholder { color: var(--c-text-muted); }
.input[disabled], .select[disabled] { background: var(--c-surface-2); color: var(--c-text-muted); }
.hint { margin: var(--sp-1) 0 0; font-size: var(--fs-xs); color: var(--c-text-muted); }
.field-error { display: flex; gap: var(--sp-1); align-items: flex-start; margin: var(--sp-1) 0 0; font-size: var(--fs-xs); color: var(--c-danger-text); }
.has-error .input, .has-error .select, .has-error .textarea { border-color: var(--c-danger-solid); }
.check { display: flex; align-items: center; gap: var(--sp-3); min-height: var(--tap); cursor: pointer; color: var(--c-text-soft); }
.check input, input[type="checkbox"], input[type="radio"] { accent-color: var(--c-primary); }
.check input { width: 22px; height: 22px; flex: none; }
.form-actions { display: flex; flex-wrap: wrap; gap: var(--sp-3); margin-top: var(--sp-5); }
.form-actions .btn { flex: 1 1 140px; }

/* ---------- Tarjetas ---------- */
.card { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius-xl); box-shadow: var(--shadow); overflow: hidden; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--c-border); }
.card-header h2, .card-header h3 { margin: 0; }
.card-body { padding: var(--sp-4); }
.card-footer { padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--c-border); display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; }
a.card-link { display: block; color: inherit; text-decoration: none; transition: border-color 0.15s, filter 0.15s; }
a.card-link:hover { border-color: var(--c-primary); color: inherit; text-decoration: none; filter: brightness(1.08); }

/* ---------- Etiquetas de estado ---------- */
.badge { display: inline-flex; align-items: center; gap: var(--sp-1); padding: 2px 10px; min-height: 24px; border-radius: var(--radius-pill); font-size: var(--fs-xs); font-weight: 700; white-space: nowrap; }
.badge .icon { width: 1em; height: 1em; }
.badge-borrador, .badge-pendiente, .badge-finalizado { background: var(--c-surface-2); color: var(--c-text-soft); box-shadow: inset 0 0 0 1px var(--c-border-strong); }
.badge-inscripcion, .badge-info { background: var(--c-info-solid); color: var(--c-info-on); }
.badge-grupos, .badge-success { background: var(--c-success-solid); color: var(--c-success-on); }
.badge-eliminatoria, .badge-warning { background: var(--c-warning-solid); color: var(--c-warning-on); }
.badge-danger { background: var(--c-danger-solid); color: var(--c-danger-on); }

/* ---------- Avisos ---------- */
.alert { display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-lg); font-size: var(--fs-sm); }
.alert .icon { margin-top: 2px; }
.alert-body strong { display: block; }
.alert-info { color: var(--c-info-text); background: var(--c-info-bg); box-shadow: inset 0 0 0 1px var(--c-info-border); }
.alert-success { color: var(--c-success-text); background: var(--c-success-bg); box-shadow: inset 0 0 0 1px var(--c-success-border); }
.alert-warning { color: var(--c-warning-text); background: var(--c-warning-bg); box-shadow: inset 0 0 0 1px var(--c-warning-border); }
.alert-danger { color: var(--c-danger-text); background: var(--c-danger-bg); box-shadow: inset 0 0 0 1px var(--c-danger-border); }
.alert a { color: inherit; font-weight: 600; }
.alert .check { color: inherit; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--c-border); border-radius: var(--radius-lg); background: var(--c-surface); box-shadow: var(--shadow); -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table caption { text-align: left; padding: var(--sp-3) var(--sp-4); font-family: var(--font-display); font-weight: 700; font-size: var(--fs-lg); letter-spacing: -0.02em; }
.table th, .table td { padding: var(--sp-3); text-align: left; border-bottom: 1px solid var(--c-border); white-space: nowrap; }
.table th { background: var(--c-surface-2); color: var(--c-text-muted); font-weight: 600; font-size: var(--fs-xs); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table abbr { text-decoration: none; cursor: help; }
.table-standings td:first-child, .table-standings th:first-child { position: sticky; left: 0; background: inherit; }
.table-standings tbody td:first-child { background: var(--c-surface); }
.table-standings .pos { width: 2.5rem; font-family: var(--font-display); font-weight: 700; font-size: var(--fs-lg); text-align: center; }
.table-standings .team { white-space: normal; min-width: 11rem; font-weight: 600; }
.table-standings tr.qualified td { background: var(--c-success-bg); }
.table-standings tr.qualified td:first-child { box-shadow: inset 4px 0 0 var(--c-success-solid); }
.table-standings .pts { font-weight: 700; }
.table td.wrap { white-space: normal; min-width: 9rem; }

/* ---------- Partido ---------- */
.match { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius-lg); overflow: hidden; }
.match-meta { display: flex; justify-content: space-between; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); background: var(--c-surface-2); font-size: var(--fs-xs); font-weight: 600; color: var(--c-text-muted); }
.match-team { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3); min-height: 56px; }
.match-team + .match-team { border-top: 1px solid var(--c-border); }
.match-team-name { font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
.match-team.is-winner .match-team-name { font-weight: 700; }
.match-team.is-winner .match-team-name::after { content: " \2713"; color: var(--c-success-text); }
.match-score { display: flex; gap: var(--sp-1); font-family: var(--font-display); font-weight: 700; font-size: var(--fs-xl); font-variant-numeric: tabular-nums; }
.match-score span { min-width: 1.75rem; text-align: center; padding: 0 var(--sp-1); border-radius: var(--radius-sm); background: var(--c-surface-2); color: var(--c-text-soft); }
.match-team.is-winner .match-score span { background: var(--c-primary); color: var(--c-primary-contrast); }
.match-actions { padding: var(--sp-3); border-top: 1px solid var(--c-border); }
.score-input { width: 3.25rem; min-height: var(--tap); text-align: center; font-family: var(--font-display); font-size: var(--fs-xl); font-weight: 700; padding: 0; }

/* ---------- Cuadro ---------- */
.bracket-scroll { overflow-x: auto; padding-bottom: var(--sp-3); -webkit-overflow-scrolling: touch; }
.bracket { display: flex; gap: var(--sp-5); min-width: max-content; }
.bracket-round { display: flex; flex-direction: column; gap: var(--sp-3); width: 230px; }
.bracket-matches { flex: 1; display: flex; flex-direction: column; justify-content: space-around; gap: var(--sp-3); }
.bracket-cell { display: flex; flex-direction: column; justify-content: center; }
.bracket-round .match-team-name { font-size: var(--fs-sm); }
.bracket-round .match-team { min-height: 48px; padding: var(--sp-2) var(--sp-3); }
.bracket-scroll:focus-visible { outline-offset: 4px; }

/* ---------- Pestañas ---------- */
.tabs { display: flex; gap: var(--sp-1); margin-bottom: var(--sp-4); border-bottom: 1px solid var(--c-border); overflow-x: auto; }
.tab { display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 var(--sp-4); font-family: var(--font-display); font-size: 0.9375rem; font-weight: 600; color: var(--c-text-muted); text-decoration: none; border-bottom: 3px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--c-text); text-decoration: none; }
.tab[aria-current="page"] { color: var(--c-text); border-bottom-color: var(--c-primary); }

/* ---------- Pantallas sin sesión (ingreso, inicio) ---------- */
.guest { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-5); padding: var(--sp-5) var(--sp-4); }
.guest-head { display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); text-align: center; }
.guest-sub { margin: 0; font-size: var(--fs-sm); color: var(--c-text-muted); }
.guest-card { width: 100%; max-width: 24rem; }
.site-footer { text-align: center; padding: var(--sp-5) var(--sp-4); color: var(--c-text-muted); font-size: var(--fs-xs); }

/* ---------- Varios ---------- */
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--sp-3); }
.swatch { border: 1px solid var(--c-border-strong); border-radius: var(--radius-lg); overflow: hidden; font-size: var(--fs-xs); background: var(--c-surface); }
.swatch i { display: block; height: 48px; }
.swatch span { display: block; padding: var(--sp-1) var(--sp-2); }
.checks { list-style: none; padding: 0; }
.checks .ok { color: var(--c-success-text); }
.checks .fail { color: var(--c-danger-text); font-weight: 600; }
.debug { overflow: auto; padding: var(--sp-3); background: var(--c-surface-2); border-radius: var(--radius); font-size: 13px; }

/* ---------- Buscador de jugadores (inscripción de parejas) ---------- */
.picker { position: relative; }
.picker-search { position: relative; }
.picker-results { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: var(--z-dropdown); margin: 0; padding: var(--sp-1); list-style: none; max-height: 280px; overflow-y: auto; background: var(--c-surface); border: 1px solid var(--c-primary); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop); }
.picker-option { display: block; width: 100%; min-height: var(--tap); padding: var(--sp-2) var(--sp-3); text-align: left; font: inherit; color: var(--c-text); background: none; border: 0; border-radius: var(--radius); cursor: pointer; }
.picker-option:hover, .picker-option:focus-visible { background: var(--c-surface-2); }
.picker-empty { padding: var(--sp-3); color: var(--c-text-muted); font-size: var(--fs-sm); }
.picker-chosen { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); min-height: var(--tap); padding: var(--sp-1) var(--sp-3); background: var(--c-success-bg); border: 1px solid var(--c-success-border); border-radius: var(--radius); color: var(--c-success-text); font-weight: 600; }
.quick-add { margin-top: var(--sp-3); border: 1px dashed var(--c-border-strong); border-radius: var(--radius-lg); }
.quick-add summary { min-height: var(--tap); padding: var(--sp-3); font-weight: 600; color: var(--c-text-soft); cursor: pointer; }
.quick-add-body { padding: 0 var(--sp-3) var(--sp-3); }

/* ---------- Operación del torneo ---------- */
.member { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-2) 0; }
.member + .member { border-top: 1px solid var(--c-border); }
.member-name { display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-2); min-width: 0; }
.member-select { width: auto; min-width: 7.5rem; flex: none; }

.set-grid { display: grid; grid-template-columns: auto 1fr 1fr; gap: var(--sp-2) var(--sp-3); align-items: center; }
.set-grid .score-input { width: 100%; min-width: 3.25rem; }
.set-team { font-family: var(--font-display); font-size: var(--fs-md); text-align: center; overflow-wrap: anywhere; line-height: 1.2; }
.set-label { font-weight: 600; white-space: nowrap; }

a.match.card-link { display: block; color: inherit; text-decoration: none; transition: border-color 0.15s, filter 0.15s; }
a.match.card-link:hover { border-color: var(--c-primary); color: inherit; filter: brightness(1.08); }

/* El atributo hidden debe ganarle siempre a los display de los componentes (alert, card, etc.) */
[hidden] { display: none !important; }

/* ---------- Pantallas anchas ---------- */
@media (min-width: 768px) {
    h1 { font-size: 1.875rem; }
    .container { padding: var(--sp-5) var(--sp-4); }
    .navbar-inner { flex-wrap: nowrap; }
    .nav-toggle { display: none; }
    .nav-menu, .nav-menu.is-open { display: flex; align-items: center; flex-basis: auto; gap: var(--sp-1); padding: 0; }
    .nav-menu a, .nav-menu button { width: auto; min-height: 2.5rem; }
    .grid-2 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(3, 1fr); }
    .form-actions .btn { flex: 0 0 auto; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
.logo-net { stroke: var(--c-success-solid); }
