:root {
    --primary: #3659B8;
    --primary-dark: #29458F;
    --primary-light: #748CC9;
    --secondary: #C34B42;
    --bg: #f5f7fb;
    --surface: #ffffff;
    --text: #1f2937;
    --text-muted: #6b7280;
    --border: #d1d5db;
    --error: #b91c1c;
    --error-bg: #fef2f2;
    --success: #15803d;
    --success-bg: #f0fdf4;
    --info: #4266B2;
    --info-bg: #eef3fa;
    --warning: #a16207;
    --warning-bg: #fefce8;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--primary);
    color: #fff;
    border-bottom: 2px solid var(--secondary);
    padding: 1rem 1.5rem;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 0.75rem;
    align-items: center;
    box-shadow: var(--shadow);
}

.topbar .brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.35rem;
    color: #fff;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.topbar .brand:hover { text-decoration: none; color: #fff; }

.topbar nav { display: flex; align-items: center; }
.topbar nav a { color: #f5f7ff; font-size: 1.15rem; font-weight: 700; padding: 0.35rem 0.75rem; text-align: center; white-space: nowrap; }
.topbar .primary-nav { justify-content: center; min-width: 0; }
.topbar .account-nav { justify-content: flex-end; }
.topbar .primary-nav > a + a,
.topbar .account-nav > :not(:first-child) { border-left: 1px solid rgba(255,255,255,0.55); }
.topbar nav a:hover { color: #fff; }
@media (max-width: 1200px) {
    .topbar { display: flex; flex-direction: column; gap: 0.75rem; }
    .topbar nav { flex-wrap: wrap; justify-content: center; }
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem;
}

.page-title {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--primary-dark);
    border-left: 3px solid var(--secondary);
    padding-left: 0.65rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
}

.card h3 { margin-bottom: 0.5rem; }

.form-group { margin-bottom: 1rem; }

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.35rem;
    font-size: 0.9rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: inherit;
    background: #fff;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: 2px solid var(--primary-light);
    outline-offset: 1px;
    border-color: var(--primary-light);
}

.form-group .hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }

.btn {
    display: inline-block;
    padding: 0.5rem 1.1rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    background: var(--primary);
    color: #fff;
    transition: background 0.15s ease;
}

.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary { background: #fff; color: var(--primary-dark); border-color: var(--primary); }
.btn-secondary:hover { background: #eef3ff; }

.btn-danger { background: var(--secondary); }
.btn-danger:hover { background: #a83c34; }

.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.82rem; }

.alert {
    padding: 0.7rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
    border: 1px solid transparent;
}

.alert-error { background: var(--error-bg); color: var(--error); border-color: #fecaca; }
.alert-success { background: var(--success-bg); color: var(--success); border-color: #bbf7d0; }
.alert-info { background: var(--info-bg); color: var(--info); border-color: #bfdbfe; }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: #fde68a; }

.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-green { background: var(--success-bg); color: var(--success); }
.badge-red { background: var(--error-bg); color: var(--error); }
.badge-yellow { background: var(--warning-bg); color: var(--warning); }
.badge-blue { background: var(--info-bg); color: var(--info); }
.badge-gray { background: #f3f4f6; color: #374151; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.partida-list { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: 1fr; }
.partida-list > .card { display: flex; flex-direction: column; }
.partida-list > .card > .flex:last-child { margin-top: auto; }
.game-detail-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); }
.grid-3 { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

@media (max-width: 768px) {
    .partida-list { grid-template-columns: minmax(0, 1fr); }
    .game-detail-grid { grid-template-columns: 1fr; }
}

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table th, table td { padding: 0.55rem 0.7rem; text-align: left; border-bottom: 1px solid var(--border); }
table th { background: #f9fafb; font-weight: 600; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); }

.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow);
}

.auth-card h1 { font-size: 1.4rem; margin-bottom: 0.35rem; color: var(--primary-dark); }
.auth-card .subtitle { color: var(--text-muted); margin-bottom: 1.5rem; font-size: 0.9rem; }
.auth-card .footer-link { margin-top: 1.25rem; font-size: 0.88rem; text-align: center; }

.role-cards { display: grid; gap: 0.6rem; margin-bottom: 1rem; }
.role-card {
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    cursor: pointer;
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.role-card:hover { border-color: var(--primary-light); }
.role-card.selected { border-color: var(--primary); background: #eef3ff; }
.role-card input { margin-top: 0.25rem; }
.role-card .role-name { font-weight: 700; font-size: 0.95rem; }
.role-card .role-desc { font-size: 0.82rem; color: var(--text-muted); }

.request-notice { margin: 0 0 1.25rem; }

.request-dialog {
    width: min(520px, calc(100vw - 2rem));
    max-width: none;
    max-height: calc(100vh - 2rem);
    margin: auto;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    box-shadow: 0 18px 50px rgba(15, 23, 42, 0.24);
}

.request-dialog::backdrop { background: rgba(15, 23, 42, 0.52); }
.request-dialog[open] { animation: dialog-enter 0.18s ease-out; }

.request-dialog-content { padding: 2.25rem; }
.request-dialog h2 { color: var(--primary-dark); font-size: 1.4rem; margin-bottom: 0.65rem; }
.request-dialog-content > p { color: var(--text-muted); margin-bottom: 1.5rem; }
.request-dialog .btn { min-width: 130px; }

@keyframes dialog-enter {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
    .request-dialog[open] { animation: none; }
}

.occupancy-bar {
    height: 6px;
    background: #e5e7eb;
    border-radius: 999px;
    overflow: hidden;
    margin: 0.4rem 0;
}

.occupancy-bar > div { height: 100%; background: var(--primary); }
.occupancy-bar.full > div { background: var(--error); }

.tabs { display: flex; gap: 0.4rem; border-bottom: 2px solid var(--border); margin-bottom: 1.25rem; flex-wrap: wrap; }
.tabs a {
    padding: 0.5rem 0.9rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}
.tabs a:hover { color: var(--primary-dark); text-decoration: none; }
.tabs a.active { color: var(--primary-dark); border-bottom-color: var(--primary); }

.meta-row { display: flex; gap: 1.25rem; flex-wrap: wrap; font-size: 0.85rem; color: var(--text-muted); }
.meta-row strong { color: var(--text); }

.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--text-muted); }

.spinner {
    border: 3px solid #e5e7eb;
    border-top-color: var(--primary);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    animation: spin 0.8s linear infinite;
    margin: 1rem auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.85rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; gap: 0.75rem; align-items: center; }
.flex-between { display: flex; gap: 0.75rem; align-items: center; justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }

.game-card img {
    width: 100%;
    height: 160px;
    object-fit: cover;
    border-radius: var(--radius);
    background: #e5e7eb;
    margin-bottom: 0.6rem;
}

.code-box {
    background: #f9fafb;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 0.6rem;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.82rem;
    word-break: break-all;
    margin: 0.5rem 0;
}

/* --- Evento Especial "Sevilla Essten" --- */

/* Tarjetas de juego del evento: 2 por fila (1 en pantallas estrechas) */
.grid-evento { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 700px) {
    .grid-evento { grid-template-columns: minmax(0, 1fr); }
}

/* Todas las tarjetas de la fila igualan su altura y los botones quedan abajo.
   El padding-top garantiza una separación mínima respecto a la ficha del juego:
   margin-top: auto absorbe el espacio libre y, sin esto, se queda en 0. */
.grid-evento > .card { display: flex; flex-direction: column; }
.grid-evento > .card > .flex:last-child { margin-top: auto; padding-top: 1.25rem; }

.evento-intro { background: linear-gradient(135deg, #3659B8 0%, #29458F 100%); color: #fff; }
.evento-intro h3, .evento-intro .page-title { color: #fff; }
.evento-intro .text-muted { color: rgba(255,255,255,0.85); }

/* Ficha del juego: los datos cortos a la izquierda y la dependencia del idioma
   (que suele ser texto largo) a la derecha, aprovechando el ancho de la tarjeta
   sin descuadrarla. Con auto-fit, si no hay dependencia los datos ocupan todo. */
.juego-ficha {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 0.5rem 1rem;
    align-items: start;
}
.juego-datos { display: grid; gap: 0.2rem; font-size: 0.85rem; color: var(--text-muted); }
.juego-datos strong { color: var(--text); }
.juego-dependencia .etiqueta {
    display: block;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    margin-bottom: 0.15rem;
}
.juego-dependencia p { margin: 0; font-size: 0.85rem; }

.slot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0.6rem; }
.slot-btn {
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 0.6rem 0.75rem;
    background: #fff;
    cursor: pointer;
    text-align: left;
    font: inherit;
    color: var(--text);
    transition: border-color 0.15s ease, background 0.15s ease;
}
.slot-btn:hover:not(:disabled) { border-color: var(--primary-light); background: #eef3ff; }
.slot-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.slot-btn .slot-hora { font-weight: 700; display: block; }
.slot-btn .slot-meta { font-size: 0.8rem; color: var(--text-muted); }
.slot-btn.no-disponible .slot-meta { color: var(--error); }

.lote { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; background: var(--surface); box-shadow: var(--shadow); }
.total-box { display: flex; justify-content: space-between; align-items: baseline; border-top: 1px dashed var(--border); margin-top: 0.75rem; padding-top: 0.75rem; font-weight: 700; font-size: 1.05rem; }
.total-box .importe { color: var(--primary-dark); font-size: 1.25rem; }

.modal-normas {
    max-height: 38vh;
    overflow-y: auto;
    white-space: pre-wrap;
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.9rem;
    font-size: 0.85rem;
    line-height: 1.45;
}

.check-acepto { display: flex; gap: 0.6rem; align-items: flex-start; margin-top: 1rem; font-size: 0.9rem; }
.check-acepto input { width: auto; margin-top: 0.2rem; flex: none; }

.dato-pago { background: var(--info-bg); border: 1px solid #bfdbfe; border-radius: var(--radius); padding: 1rem; margin: 0.75rem 0; }
.dato-pago .etiqueta { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }

.lista-reservas { list-style: none; }
.lista-reservas li { display: flex; gap: 0.75rem; justify-content: space-between; align-items: center; flex-wrap: wrap; padding: 0.55rem 0; border-bottom: 1px solid var(--border); }
.lista-reservas li:last-child { border-bottom: none; }

/* Interruptor (toggle) del panel de administración */
.switch { display: inline-flex; align-items: center; gap: 0.6rem; cursor: pointer; font-weight: 600; font-size: 0.9rem; }
.switch input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 46px;
    height: 26px;
    border-radius: 999px;
    background: #cbd5e1;
    position: relative;
    transition: background 0.15s ease;
    cursor: pointer;
    flex: none;
    margin: 0;
}
.switch input[type="checkbox"]::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.3);
    transition: transform 0.15s ease;
}
.switch input[type="checkbox"]:checked { background: var(--primary); }
.switch input[type="checkbox"]:checked::after { transform: translateX(20px); }

.tabla-acciones { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.table-scroll { overflow-x: auto; }

/* Inputs sueltos (fuera de .form-group) */
.input {
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: inherit;
    background: #fff;
    color: var(--text);
}
.input:focus { outline: 2px solid var(--primary-light); outline-offset: 1px; border-color: var(--primary-light); }

.bloque-fila { align-items: flex-end; }
.bloque-fila .input { flex: 1 1 140px; min-width: 0; }
.bloque-fila .input[type="time"] { flex: 0 0 130px; }

.filtro-barra { align-items: flex-end; }
.filtro-barra .input, .filtro-barra select { flex: 1 1 160px; min-width: 0; }
.filtro-barra .input[type="search"] { flex: 2 1 240px; }