@import url("https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap");

:root {
    --primary-color: #075ADF;
    --primary-dark: #0300A3;
    --text-white: #fff;
    --text-dark: #333;
    --border-color: #3f464e;
    --signal-color: white;
    --border-radius: 8px;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    --success-color: #28a745;
    --warning-color: #ffc107;
    --error-color: #dc3545;
    --info-color: #17a2b8;
}

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

html, body {
    font-family: "Roboto", sans-serif;
    line-height: 1.6;
    color: var(--text-dark);
}

/* ===== ACCESSIBILITY STYLES ===== */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.form-help {
    font-size: 0.875rem;
    color: #666;
    margin-top: 5px;
}

.team-label {
    display: block;
    font-weight: 500;
    margin-bottom: 5px;
    color: var(--text-dark);
}

/* ===== LOADING INDICATOR ===== */
.loading-indicator {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 10px 15px;
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 1000;
    font-size: 14px;
}

.loading-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top: 2px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.hidden {
    display: none !important;
}

/* ===== TOAST NOTIFICATIONS ===== */
.toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1001;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 12px 20px;
    border-radius: var(--border-radius);
    font-size: 14px;
    max-width: 300px;
    text-align: center;
    box-shadow: var(--shadow);
    animation: toastSlideIn 0.3s ease-out;
}

.toast-success {
    background: var(--success-color);
}

.toast-warning {
    background: var(--warning-color);
    color: var(--text-dark);
}

.toast-error {
    background: var(--error-color);
}

.toast-info {
    background: var(--info-color);
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== CONNECTION STATUS ===== */
.connection-status {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 12px;
    border-radius: var(--border-radius);
    font-size: 12px;
    z-index: 1000;
}

/* ===== PÁGINA PRINCIPAL (INDEX) ===== */
.main-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    padding: 15px;
}

.logo-main {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    object-fit: cover;
}

.teams-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 15px;
    width: 100%;
    max-width: 1000px;
}

.team-card {
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.95);
    border-radius: var(--border-radius);
    padding: 15px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.team-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}

.team-name {
    font-size: 1em;
    font-weight: 500;
    color: var(--text-white);
    text-align: center;
}

.team-buttons {
    display: flex;
    gap: 8px;
    width: 100%;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: var(--border-radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
    text-align: center;
    flex: 1;
}

.btn:focus {
    outline: 2px solid var(--signal-color);
    outline-offset: 2px;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary-color);
    color: var(--text-white);
}

.btn-marcador {
    background: white;
    color: var(--primary-color);
    border: 2px solid white;
}

.btn-marcador:hover {
    background: rgba(255, 255, 255, 0.9);
    color: var(--primary-dark);
}

.btn-secondary {
    background: var(--border-color);
    color: var(--text-white);
}

.btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
}

.btn-secondary:hover:not(:disabled) {
    background: #2c3138;
}

.btn-admin {
    background: var(--success-color);
    color: white;
    margin-top: 20px;
    padding: 12px 24px;
    font-size: 16px;
    width: auto;
    max-width: 300px;
    min-width: 200px;
}

.btn-admin:hover:not(:disabled) {
    background: #218838;
}

/* ===== PÁGINA DE CONTROL ===== */
.control-page {
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    padding: 10px;
    display: flex;
    flex-direction: column;
}

.control-header {
    text-align: center;
    margin-bottom: 15px;
    flex-shrink: 0;
}

.logo-control {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    margin-bottom: 8px;
    object-fit: cover;
}

.page-title {
    color: var(--text-white);
    font-size: 1.3em;
    font-weight: 500;
    margin-bottom: 5px;
}

.team-subtitle {
    color: var(--text-white);
    font-size: 1em;
    opacity: 0.9;
}

.control-container {
    flex: 1;
    display: flex;
    gap: 15px;
    justify-content: center;
    max-width: 700px;
    margin: 0 auto;
}

.team-control {
    background: rgba(255, 255, 255, 0.95);
    border-radius: var(--border-radius);
    padding: 15px;
    box-shadow: var(--shadow);
    flex: 1;
    min-width: 0;
}

.team-name-input {
    width: 100%;
    padding: 8px;
    border: 2px solid #ddd;
    border-radius: var(--border-radius);
    font-size: 14px;
    margin-bottom: 15px;
    text-align: center;
    font-weight: 500;
    transition: border-color 0.2s ease;
}

.team-name-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(7, 90, 223, 0.2);
}

.score-section {
    text-align: center;
    margin-bottom: 15px;
}

.score-label {
    font-size: 0.9em;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-dark);
}

.score-display {
    font-size: 2em;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 10px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.sets-display {
    font-size: 1.5em;
}

.control-buttons {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 10px;
}

.control-btn {
    width: 35px;
    height: 35px;
    border: none;
    border-radius: 50%;
    font-size: 1.2em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
}

.control-btn:focus {
    outline: 2px solid var(--signal-color);
    outline-offset: 2px;
}

.control-btn.plus {
    background: var(--success-color);
    color: white;
}

.control-btn.minus {
    background: var(--error-color);
    color: white;
}

.control-btn:hover:not(:disabled) {
    transform: scale(1.1);
}

.reset-btn {
    background: var(--border-color);
    color: white;
    padding: 6px 12px;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 12px;
    transition: all 0.3s ease;
}

.reset-btn:hover:not(:disabled) {
    background: #2c3138;
}

.reset-btn:focus {
    outline: 2px solid var(--signal-color);
    outline-offset: 2px;
}

.control-footer {
    margin-top: 15px;
    text-align: center;
    flex-shrink: 0;
}

.control-footer .btn {
    margin: 0 5px;
    padding: 8px 16px;
    font-size: 14px;
}

/* ===== PÁGINA DE MARCADOR ===== */
.scoreboard-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: transparent;
}

.scoreboard-container {
    background-image: url('fondoazul.jpg');
    background-size: cover;
    background-position: center;
    border-radius: 10px;
    padding: 5px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    position: relative;
}

.scoreboard-grid {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: auto 1fr auto auto auto;
    grid-template-rows: auto auto auto auto;
    gap: 1px 6px;
    align-items: center;
    width: 100%;
}

.scoreboard-logo {
    grid-row: 1/5;
    grid-column: 1/2;
    display: flex;
    align-items: center;
}

.scoreboard-logo img {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    object-fit: cover;
    transition: transform 0.2s ease;
}

.scoreboard-logo img:hover {
    transform: scale(1.1);
}

.scoreboard-header {
    text-align: center;
    color: var(--text-white);
    font-size: 0.7em;
    font-weight: 500;
}

.header-sets { 
    grid-row: 2/4; 
    grid-column: 4/5;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-points { 
    grid-row: 2/4; 
    grid-column: 5/6;
    display: flex;
    align-items: center;
    justify-content: center;
}

.team-name-display {
    grid-column: 2/4;
    color: var(--text-white);
    font-size: 1em;
    font-weight: 500;
    padding: 1px 6px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    position: relative;
}

.team1-name { 
    grid-row: 2/3; 
}

.team2-name { 
    grid-row: 3/4; 
}

.service-indicator {
    width: 8px;
    height: 8px;
    background: var(--signal-color);
    border-radius: 50%;
    margin-left: 4px;
    opacity: 0;
    transition: opacity 0.3s ease;
    box-shadow: 0 0 3px rgba(255, 255, 255, 0.6);
}

.service-indicator.active {
    opacity: 1;
}

.score-value {
    text-align: center;
    color: var(--text-white);
    font-size: 1.3em;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.2);
    padding: 1px 4px;
    border-radius: var(--border-radius);
    min-width: 40px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.sets-value {
    border-left: 2px solid rgba(255, 255, 255, 0.3);
    font-size: 1.1em;
}

.team1-sets { 
    grid-row: 2/3; 
    grid-column: 4/5; 
}

.team1-points { 
    grid-row: 2/3; 
    grid-column: 5/6; 
}

.team2-sets { 
    grid-row: 3/4; 
    grid-column: 4/5; 
}

.team2-points { 
    grid-row: 3/4; 
    grid-column: 5/6; 
}

/* ===== PÁGINA DE ADMINISTRACIÓN ===== */
.admin-page {
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    padding: 20px;
}

.admin-header {
    text-align: center;
    margin-bottom: 30px;
    color: var(--text-white);
}

.admin-container {
    max-width: 800px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.95);
    border-radius: var(--border-radius);
    padding: 25px;
    box-shadow: var(--shadow);
}

.admin-section {
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;
}

.admin-section:last-child {
    border-bottom: none;
}

.admin-section h3 {
    margin-bottom: 15px;
    color: var(--text-dark);
}

.team-edit-grid {
    display: grid;
    grid-template-columns: 120px 1fr auto;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
    padding: 8px;
    border-radius: var(--border-radius);
    transition: background-color 0.2s ease;
}

.team-edit-grid:hover {
    background-color: rgba(0, 0, 0, 0.02);
}

.team-id {
    font-weight: bold;
    color: var(--border-color);
    font-family: monospace;
}

.team-name-edit {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    font-size: 14px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.team-name-edit:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(7, 90, 223, 0.2);
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-danger {
    background: var(--error-color);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #c82333;
}

.new-team-form {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.new-team-form input {
    flex: 1;
    min-width: 150px;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    transition: border-color 0.2s ease;
}

.new-team-form input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(7, 90, 223, 0.2);
}

.global-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* ===== RESPONSIVE DESIGN ===== */

/* Pantallas muy pequeñas (streaming overlays, móviles en portrait) */
@media (max-width: 480px) or (max-height: 480px) {
    .scoreboard-page {
        padding: 0;
        align-items: flex-start;
        justify-content: flex-start;
        min-height: auto;
    }
    
    .scoreboard-container {
        width: 100vw;
        max-width: none;
        border-radius: 0;
        padding: 1vw;
        margin: 0;
        box-shadow: none;
    }
    
    .scoreboard-grid {
        gap: 0.2vw 1vw;
        font-size: 4vw;
    }
    
    .scoreboard-logo img {
        width: 8vw;
        height: 8vw;
    }
    
    .scoreboard-header {
        font-size: 2.5vw;
    }
    
    .team-name-display {
        font-size: 3.5vw;
        padding: 0.3vw 1vw;
    }
    
    .score-value {
        font-size: 4.5vw;
        padding: 0.3vw 0.8vw;
        min-width: 8vw;
    }
    
    .sets-value {
        font-size: 3.8vw;
    }
    
    .service-indicator {
        width: 2.5vw;
        height: 2.5vw;
        margin-left: 1vw;
    }
}

/* Pantallas medianas (tablets, streaming en landscape) */
@media (min-width: 481px) and (max-width: 768px) {
    .teams-grid {
        grid-template-columns: 1fr;
    }
    
    .control-container {
        flex-direction: column;
        gap: 10px;
    }
    
    .scoreboard-page {
        padding: 10px;
        align-items: flex-start;
        justify-content: flex-start;
    }
    
    .scoreboard-container {
        width: 95vw;
        max-width: 500px;
        padding: 0.5vw;
    }
    
    .scoreboard-grid {
        gap: 0.3vw 1.2vw;
        font-size: 2.5vw;
    }
    
    .scoreboard-logo img {
        width: 6vw;
        height: 6vw;
        max-width: 40px;
        max-height: 40px;
    }
    
    .team-name-display {
        font-size: 2.8vw;
        padding: 0.4vw 1.2vw;
    }
    
    .score-value {
        font-size: 3.2vw;
        padding: 0.4vw 1vw;
        min-width: 6vw;
    }
    
    .sets-value {
        font-size: 2.8vw;
    }
    
    .service-indicator {
        width: 1.8vw;
        height: 1.8vw;
        margin-left: 0.8vw;
    }
    
    .admin-container {
        padding: 15px;
    }
    
    .team-edit-grid {
        grid-template-columns: 1fr;
        gap: 5px;
        text-align: center;
    }
    
    .new-team-form {
        flex-direction: column;
        align-items: stretch;
    }
}

/* Pantallas grandes (desktop) - mantener centrado */
@media (min-width: 769px) {
    .scoreboard-page {
        padding: 20px;
        align-items: center;
        justify-content: center;
    }
    
    .scoreboard-container {
        width: auto;
        max-width: 600px;
        min-width: 450px;
        padding: 3px;
    }
    
    .scoreboard-grid {
        gap: 1px 6px;
    }
    
    .scoreboard-logo img {
        width: 35px;
        height: 35px;
    }
    
    .scoreboard-header {
        font-size: 0.7em;
    }
    
    .team-name-display {
        font-size: 1em;
        padding: 1px 6px;
    }
    
    .score-value {
        font-size: 1.3em;
        padding: 1px 4px;
        min-width: 40px;
    }
    
    .sets-value {
        font-size: 1.1em;
    }
    
    .service-indicator {
        width: 8px;
        height: 8px;
        margin-left: 4px;
    }
}

@media (max-width: 480px) {
    .control-page {
        padding: 5px;
    }
    
    .team-control {
        padding: 10px;
    }
    
    .score-display {
        font-size: 1.8em;
    }
    
    .control-btn {
        width: 30px;
        height: 30px;
        font-size: 1em;
    }
}

/* ===== MODO LANDSCAPE EN MÓVIL ===== */
@media (max-height: 500px) and (orientation: landscape) {
    .control-page {
        padding: 5px;
    }
    
    .control-header {
        margin-bottom: 8px;
    }
    
    .logo-control {
        width: 35px;
        height: 35px;
    }
    
    .page-title {
        font-size: 1.1em;
    }
    
    .team-control {
        padding: 10px;
    }
    
    .score-section {
        margin-bottom: 10px;
    }
    
    .score-display {
        font-size: 1.5em;
        margin-bottom: 5px;
    }
    
    .control-footer {
        margin-top: 8px;
    }
}

/* ===== ANIMACIONES ===== */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.score-display.updated,
.score-value.updated,
.team-name-display.updated {
    animation: pulse 0.6s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.team-card,
.team-control,
.admin-section {
    animation: fadeIn 0.3s ease-in-out;
}

/* ===== HIGH CONTRAST MODE ===== */
@media (prefers-contrast: high) {
    :root {
        --primary-color: #000;
        --primary-dark: #000;
        --text-white: #fff;
        --text-dark: #000;
        --border-color: #000;
    }
    
    .btn {
        border: 2px solid currentColor;
    }
    
    .team-card {
        border: 3px solid white;
    }
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .loading-spinner {
        animation: none;
        border: 2px solid white;
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    .loading-indicator,
    .toast-container,
    .connection-status,
    .btn,
    .control-buttons {
        display: none !important;
    }
    
    .scoreboard-container {
        background: white !important;
        box-shadow: none !important;
        border: 2px solid black;
    }
    
    .team-name-display,
    .score-value,
    .scoreboard-header {
        color: black !important;
        background: white !important;
    }
}

/* ===== UTILIDADES ===== */
.text-center { text-align: center; }
.mb-20 { margin-bottom: 20px; }
.mt-20 { margin-top: 20px; }

/* Focus styles for better keyboard navigation */
button:focus,
input:focus,
a:focus {
    outline: 2px solid var(--signal-color);
    outline-offset: 2px;
}

/* Improved contrast for better readability */
.score-display,
.score-value {
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

/* Better visual hierarchy */
h1, h2, h3 {
    margin-bottom: 0.5em;
}

/* Smooth state transitions */
.btn,
.team-card,
.score-display,
input {
    transition: all 0.2s ease;
}