:root {
    --bg: #f0f2f5;
    --text: #1e293b;
    --primary: #00347a;
    --primary-hover: #002860;
    --card-bg: #ffffff;
    --border: #d9dadd;
    --danger: #ef4444;
    --naranja-brand: #fb6b25;
    --morado-brand: #3a3171;
    --verde-brand: #2f982a;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; }
body { min-height: 100dvh; background: var(--bg); color: var(--text); -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

/* RESPONSIVE LAYOUT */
.desktop-only { display: none !important; }
.mobile-only { display: none !important; }

@media (min-width: 769px) {
    .desktop-only { display: flex !important; }
    .mobile-only { display: none !important; }
}
@media (max-width: 768px) {
    .desktop-only { display: none !important; }
    .mobile-only { display: flex !important; }
}

/* FIXED BARS PADDING */
.has-fixed-bars {
    padding-top: 70px;
    padding-bottom: 70px;
}
@media (min-width: 769px) {
    .has-fixed-bars {
        padding-bottom: 20px; /* No mobile footer */
    }
}

/* HEADER */
.app-header { background: var(--primary); color: #fff; padding: calc(15px + env(safe-area-inset-top)) 20px 15px 20px; display: flex; justify-content: space-between; align-items: center; }
.fixed-header { position: fixed; top: 0; left: 0; width: 100%; z-index: 1000; box-shadow: 0 2px 10px rgba(0,0,0,0.2); }
.header-logo { font-weight: 900; font-size: 1.2rem; letter-spacing: 1px; color: #fff; display: flex; align-items: center; }
.header-logo img { height: 26px; max-height: 26px; width: auto; max-width: 130px; object-fit: contain; display: block; }
.header-user { display: flex; align-items: center; gap: 15px; }

.nav-btn {
    background: transparent; color: rgba(255,255,255,0.7); border: none; font-size: 1rem; cursor: pointer; display: flex; align-items: center; gap: 5px; padding: 5px 10px; border-radius: 5px; transition: all 0.2s;
    -webkit-appearance: none; appearance: none;
}
.nav-btn:hover { color: #fff; background: rgba(255,255,255,0.1); }
.nav-btn.active { color: #fff; font-weight: bold; background: rgba(255,255,255,0.2); }

/* FOOTER AIRBNB STYLE */
.app-footer {
    position: fixed; bottom: 0; left: 0; width: 100%; background: #ffffff; border-top: 1px solid var(--border); display: flex; justify-content: space-around; padding: 10px 0 calc(5px + env(safe-area-inset-bottom)); z-index: 1000; box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
}
.nav-item {
    display: flex; flex-direction: column; align-items: center; color: #64748b; cursor: pointer; transition: all 0.2s; font-size: 0.75rem; gap: 4px;
    background: transparent; border: none; outline: none; font-family: inherit;
    -webkit-appearance: none; appearance: none; box-shadow: none; -webkit-tap-highlight-color: transparent;
}
.nav-item i { font-size: 1.4rem; }
.nav-item.active { color: var(--naranja-brand); }

.btn-icon { background: rgba(255,255,255,0.1); border: none; color: #fff; width: 35px; height: 35px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.btn-install { background: var(--verde-brand); color: #fff; border: none; padding: 8px 12px; border-radius: 8px; font-weight: bold; cursor: pointer; display: none; margin-right: 10px; font-size: 0.9rem; }

/* INSTALL MODAL iOS */
.ios-install-modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8); z-index: 2000;
    display: none; justify-content: center; align-items: center; padding: 20px;
}
.ios-install-modal.active { display: flex; }
.ios-install-card {
    background: #fff; color: #1e293b; border-radius: 12px; padding: 25px; text-align: center; max-width: 320px;
}
.ios-install-card img { width: 60px; height: 60px; margin-bottom: 15px; }
.btn-close-modal { background: #e2e8f0; border: none; padding: 10px 20px; border-radius: 8px; font-weight: bold; margin-top: 20px; cursor: pointer; width: 100%; }

/* LAYOUT */
.app-container { padding: 20px; max-width: 800px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* LOGIN */
.login-card { background: var(--card-bg); padding: 30px 20px; border-radius: 12px; border: 1px solid var(--border); margin-top: 40px; text-align: center; }
.login-card h2 { margin-bottom: 20px; color: var(--primary); }
.form-group { margin-bottom: 15px; text-align: left; }
.form-group label { display: block; margin-bottom: 5px; font-size: 0.9rem; font-weight: 600; color: #64748b; }
.form-group input { width: 100%; padding: 12px; border: 2px solid var(--border); border-radius: 8px; font-size: 1rem; outline: none; }
.form-group input:focus { border-color: var(--primary); }
.btn-primary { width: 100%; background: var(--primary); color: #fff; border: none; padding: 15px; border-radius: 8px; font-size: 1rem; font-weight: 700; cursor: pointer; }
.error-msg { color: var(--danger); font-size: 0.9rem; margin-top: 10px; font-weight: 600; }

/* CANCHAS */
.view-title { font-size: 1.3rem; margin-bottom: 20px; text-align: center; font-weight: 800; color: var(--primary); }
.canchas-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 15px; }
.cancha-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; cursor: pointer; box-shadow: 0 4px 6px rgba(0,0,0,0.05); }
.cancha-card img { width: 100%; height: 150px; object-fit: cover; display: block; }
.cancha-card h3 { padding: 15px; text-align: center; font-size: 1.1rem; color: var(--primary); }

/* PARTIDOS */
.view-header { display: flex; align-items: center; margin-bottom: 20px; gap: 15px; }
.view-header h2 { margin: 0; font-size: 1.1rem; flex: 1; color: var(--primary); }
.btn-back { background: #e2e8f0; color: var(--text); border: none; padding: 10px 15px; border-radius: 8px; font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 5px; }

.partido-item {
    background: #fff;
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 15px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
    cursor: pointer;
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border);
}
.partido-item:hover { background-color: #f8fafc; }
.partido-finalizado { opacity: 0.95; }

.match-meta {
    font-size: 0.8rem;
    color: #64748b;
    font-weight: 800;
    margin-bottom: 12px;
    border-bottom: 1px dashed #e2e8f0;
    padding-bottom: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.match-body-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto auto;
    align-items: center;
    column-gap: 15px;
}

.vnl-team-info { display: flex; align-items: center; gap: 10px; }
.vnl-team-info.top { grid-column: 1; grid-row: 1; }
.vnl-team-info.bottom { grid-column: 1; grid-row: 3; }
.vnl-logo { width: 35px; height: 35px; object-fit: contain; border-radius: 4px; background: #f8fafc; padding: 2px; }
.vnl-name { font-weight: 800; color: #1e293b; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }

.vnl-divider { grid-column: 1 / 3; grid-row: 2; height: 1px; background: #e2e8f0; margin: 10px 0; }

.vnl-scores { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.vnl-scores.top { grid-column: 2; grid-row: 1; }
.vnl-scores.bottom { grid-column: 2; grid-row: 3; }

.vnl-sets-won { font-weight: 900; font-size: 1.4rem; color: #0c417e; min-width: 25px; text-align: center; margin-right: 5px; }
.vnl-set-score { font-weight: 800; font-size: 0.9rem; min-width: 20px; text-align: center; }
.vnl-set-score.won { color: #000; }
.vnl-set-score.lost { color: #94a3b8; }
.vnl-set-score.empty { color: transparent; }

.vnl-time-container {
    grid-column: 2;
    grid-row: 1 / 4;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: right;
}
.st-label { font-size: 0.75rem; color: #64748b; font-weight: 700; margin-bottom: 2px; }
.st-value { font-size: 1.2rem; font-weight: 900; color: #1e293b; }

.badge-final-small {
    background: var(--success);
    color: white;
    font-size: 0.65rem;
    font-weight: 900;
    padding: 2px 6px;
    border-radius: 4px;
    letter-spacing: 0.5px;
}

.partido-finalizado {
    opacity: 0.7;
    background: #f8fafc;
    cursor: default;
    border-color: #e2e8f0;
}
.partido-finalizado .partido-info {
    color: #94a3b8;
}
.final-score-badge {
    text-align: center;
    background: #e2e8f0;
    padding: 5px 10px;
    border-radius: 6px;
    font-weight: 800;
    font-size: 1rem;
    margin-top: 10px;
    color: var(--primary);
}

/* PIZARRA */
.scoreboard { display: flex; flex-direction: column; gap: 20px; background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
@media (min-width: 600px) { .scoreboard { flex-direction: row; align-items: stretch; } }
.team-panel { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 15px; background: var(--bg); padding: 20px; border-radius: 12px; border: 1px solid var(--border); }
.team-panel h3 { font-size: 1.2rem; text-align: center; margin: 0; color: var(--primary); }

.score-display { font-size: 4rem; font-weight: 900; min-width: 60px; text-align: center; line-height: 1; color: var(--text); margin: 0; }

.score-row { display: flex; flex-direction: row; flex-wrap: nowrap; align-items: center; justify-content: center; gap: 10px; width: 100%; }
.score-buttons-col { display: flex; flex-direction: column; gap: 5px; }

/* NUEVO DISEÑO PIZARRA MOBILE-FIRST */
.team-card {
    background: #ffffff;
    border-radius: 16px;
    padding: 20px 15px;
    margin-bottom: 0px;
    border: 2px solid #0c417e;
    box-shadow: 0 8px 16px rgba(0,0,0,0.06);
    text-align: center;
}
.team-name {
    color: #0c417e;
    font-size: 1.4rem;
    font-weight: 900;
    text-transform: uppercase;
    margin: 0 0 15px 0;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}
.score-grid {
    display: grid;
    grid-template-columns: 1fr 1.2fr 1fr;
    gap: 10px;
    align-items: center;
}
.btn-big {
    border-radius: 12px;
    height: 100px;
    border: none;
    font-size: 2.2rem;
    font-weight: 800;
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    transition: transform 0.1s;
}
.btn-big:active { transform: scale(0.95); }
.btn-big.minus { background: #60a5fa; }
.btn-big.plus { background: #f97316; }

.score-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.score-number {
    font-size: 4.5rem;
    font-weight: 900;
    line-height: 1;
    color: #f97316;
}
.score-label {
    font-size: 0.9rem;
    font-weight: 900;
    color: #0c417e;
    margin-top: 5px;
    letter-spacing: 1px;
}

.set-selector-new {
    display: flex;
    background: #e2e8f0;
    padding: 5px;
    border-radius: 8px;
    margin: 20px auto;
    justify-content: space-between;
    align-items: center;
    gap: 5px;
    width: max-content;
}
.set-btn {
    padding: 10px 15px;
    font-weight: 800;
    border-radius: 6px;
    cursor: pointer;
    color: #64748b;
    background: transparent;
    transition: all 0.2s;
    font-size: 0.95rem;
}
.set-btn.active {
    background: #fff;
    color: #0c417e;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.btn-fin {
    border-radius: 6px;
    border: none;
    background: #f97316;
    color: #fff;
    padding: 10px 15px;
    font-weight: 900;
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 4px rgba(249, 115, 22, 0.4);
    transition: all 0.2s;
    margin-left: 5px;
}
.btn-fin:disabled {
    background: #cbd5e1;
    color: #94a3b8;
    cursor: not-allowed;
    box-shadow: none;
}

@media (max-width: 400px) {
    .team-card { padding: 15px 10px; }
    .score-grid { gap: 5px; }
    .btn-big { height: 75px; font-size: 1.8rem; }
    .score-number { font-size: 3.2rem; }
    .team-name { font-size: 1.1rem; margin-bottom: 10px; }
    .score-label { font-size: 0.75rem; }
}

/* RANKING */
.ranking-filters { display: flex; gap: 10px; margin-bottom: 15px; }
.ranking-select { flex: 1; padding: 10px; border-radius: 8px; border: 1px solid var(--border); font-size: 1rem; color: var(--text); background: var(--card-bg); outline: none; }
.ranking-select:focus { border-color: var(--primary); }
.ranking-table-container { width: 100%; overflow-x: auto; background: var(--card-bg); border-radius: 12px; border: 1px solid var(--border); box-shadow: 0 4px 6px rgba(0,0,0,0.02); }
.ranking-table { width: 100%; border-collapse: collapse; min-width: 500px; }
.ranking-table th { background: #f8fafc; padding: 12px 5px; color: #64748b; font-size: 0.8rem; text-transform: uppercase; border-bottom: 2px solid var(--border); }
.ranking-table td { padding: 10px 5px; font-size: 0.9rem; }
.col-equipo { text-align: left !important; padding-left: 10px !important; }
