/* ========== PozoPadel Styles ========== */

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --accent: #16a34a;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg: #f8fafc;
    --surface: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 0.75rem;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
}

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
}

/* ========== App Layout ========== */

.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-header {
    background: var(--primary);
    color: white;
    padding: 0.75rem 1rem;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.app-title {
    font-size: 1.25rem;
    margin: 0;
    white-space: nowrap;
    border: none;
    outline: none;
}

.title-icon {
    height: 1.2em;
    width: auto;
    vertical-align: middle;
    margin-right: 0.1em;
}

.btn-icon {
    height: 1em;
    width: auto;
    vertical-align: middle;
    margin-right: 0.15em;
}

.nav-links {
    display: flex;
    gap: 0.25rem;
}

.nav-links .nav-link {
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    transition: background 0.2s;
}

.nav-links .nav-link:hover,
.nav-links .nav-link.active {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ========== Language Picker ========== */

.language-picker {
    position: relative;
}

.lang-toggle {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 0.3rem 0.6rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    transition: background 0.2s;
}

.lang-toggle:hover {
    background: rgba(255, 255, 255, 0.25);
}

.lang-code {
    font-weight: 600;
}

.lang-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    z-index: 200;
    min-width: 120px;
}

.lang-backdrop {
    position: fixed;
    inset: 0;
    z-index: 199;
}

.lang-option {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: none;
    background: none;
    color: var(--text);
    font-size: 0.875rem;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
}

.lang-option:hover {
    background: var(--bg);
}

.lang-option.active {
    background: var(--primary);
    color: white;
    font-weight: 600;
}

.app-main {
    flex: 1;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    padding: 1rem;
}

/* ========== Buttons ========== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

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

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

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

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

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

.btn-large {
    padding: 0.85rem 2rem;
    font-size: 1.1rem;
}

.btn-start {
    background: var(--accent);
    color: white;
}

.btn-pause {
    background: var(--warning);
    color: white;
}

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

/* ========== Setup Page ========== */

.setup-page h1 {
    margin: 0 0 0.25rem;
}

.subtitle {
    color: var(--text-muted);
    margin: 0 0 1.5rem;
}

.mode-buttons {
    display: flex;
    gap: 0.75rem;
}

.player-setup,
.team-setup {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1.5rem;
}

.player-setup h2,
.team-setup h2,
.config-section h2,
.schedule-preview h2 {
    font-size: 1.1rem;
    margin: 0 0 0.75rem;
    color: var(--text);
}

.player-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
}

.player-input label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.player-input input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

.player-input input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.config-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1.5rem;
}

.config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.75rem;
}

.config-item label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.config-item input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
}

.config-item input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Number Stepper */

.number-stepper {
    display: flex;
    align-items: center;
    gap: 0;
}

.number-stepper input[type="number"] {
    -moz-appearance: textfield;
    text-align: center;
    border-radius: 0;
    border-left: none;
    border-right: none;
    min-width: 0;
    flex: 1;
}

.number-stepper input[type="number"]::-webkit-inner-spin-button,
.number-stepper input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.stepper-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 100%;
    min-height: 2.25rem;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

.stepper-decrement {
    border-radius: var(--radius) 0 0 var(--radius);
}

.stepper-increment {
    border-radius: 0 var(--radius) var(--radius) 0;
}

.stepper-btn:hover:not(:disabled) {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.stepper-btn:active:not(:disabled) {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

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

/* Stepper in config items */
.config-item .number-stepper input {
    width: 100%;
    padding: 0.5rem 0.25rem;
    border: 1px solid var(--border);
    border-left: none;
    border-right: none;
    border-radius: 0;
    font-size: 0.95rem;
}

.config-item .number-stepper input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Stepper in score groups */
.score-group .number-stepper input {
    width: 50px;
    text-align: center;
    padding: 0.4rem 0.1rem;
    border: 1px solid var(--border);
    border-left: none;
    border-right: none;
    border-radius: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.score-group .number-stepper input:focus {
    outline: none;
    border-color: var(--primary);
}

.score-group .stepper-btn {
    width: 1.75rem;
    min-height: 2rem;
    font-size: 1rem;
}

.duration-summary {
    margin-top: 0.75rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.error-message {
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
}

.action-buttons {
    text-align: center;
    margin: 1.5rem 0;
}

/* ========== Schedule Preview ========== */

.schedule-preview {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-top: 1.5rem;
}

.preview-round {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.preview-round:last-child {
    border-bottom: none;
}

.preview-match {
    font-size: 0.9rem;
    color: var(--text-muted);
    padding: 0.15rem 0 0.15rem 1rem;
}

/* ========== Session Page ========== */

.session-header {
    margin-bottom: 1rem;
}

.round-info {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.progress-bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.3s;
}

/* ========== Timer ========== */

.game-timer {
    text-align: center;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}

.round-timer {
    border-color: var(--primary);
}

.break-timer {
    border-color: var(--accent);
}

.game-timer.warning {
    border-color: var(--warning);
    animation: pulse 1s infinite;
}

.game-timer.expired {
    border-color: var(--danger);
    background: #fef2f2;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.timer-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.timer-display {
    font-size: 3rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}

.timer-controls {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 0.75rem;
}

/* ========== Court Display ========== */

.courts-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.court-display {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow);
}

.court-display h3 {
    margin: 0 0 0.75rem;
    font-size: 1rem;
    color: var(--text-muted);
}

.court-matchup {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.team {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    flex: 1;
}

.player-name {
    font-weight: 500;
    font-size: 0.95rem;
}

.vs-badge {
    font-weight: 700;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 0.25rem 0.5rem;
    background: var(--bg);
    border-radius: var(--radius);
}

.score-input {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.score-group {
    text-align: center;
}

.score-group label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.score-group input {
    width: 60px;
    text-align: center;
    padding: 0.4rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1.25rem;
    font-weight: 600;
}

.score-group input:focus {
    outline: none;
    border-color: var(--primary);
}

.score-separator {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--text-muted);
}

.score-final {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.score-final .score {
    font-size: 1.5rem;
    font-weight: 700;
}

.score-final .winning {
    color: var(--accent);
}

/* ========== Session Controls ========== */

.session-controls {
    text-align: center;
    margin: 1rem 0;
}

.break-message {
    text-align: center;
    padding: 1rem;
}

.break-message h2 {
    margin: 0 0 0.5rem;
}

.break-message p {
    color: var(--text-muted);
    margin: 0 0 1rem;
}

.no-session,
.session-finished {
    text-align: center;
    padding: 3rem 1rem;
}

/* ========== Leaderboard ========== */

.leaderboard {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin: 1rem 0;
}

.leaderboard h2 {
    margin: 0 0 0.75rem;
    font-size: 1.1rem;
}

.leaderboard table {
    width: 100%;
    border-collapse: collapse;
}

.leaderboard th {
    text-align: left;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.4rem 0.75rem;
    border-bottom: 2px solid var(--border);
}

.leaderboard td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
}

.leaderboard tr:last-child td {
    border-bottom: none;
}

.leaderboard .rank {
    width: 2rem;
    font-weight: 600;
}

.leaderboard .points {
    font-weight: 700;
    text-align: right;
}

.leaderboard .top-1 td { background: #fef9c3; }
.leaderboard .top-2 td { background: #f0f0f0; }
.leaderboard .top-3 td { background: #fff7ed; }

/* ========== Results Page ========== */

.results-page h1 {
    text-align: center;
    margin: 0 0 1rem;
}

.round-history {
    margin: 1.5rem 0;
}

.round-history h2 {
    font-size: 1.1rem;
    margin: 0 0 0.75rem;
}

.history-round {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
}

.history-round h3 {
    margin: 0 0 0.5rem;
    font-size: 0.95rem;
}

.history-match {
    font-size: 0.9rem;
    padding: 0.25rem 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.court-label {
    font-weight: 600;
    color: var(--text-muted);
    min-width: 4rem;
}

.match-score {
    font-weight: 700;
    padding: 0.1rem 0.5rem;
    background: var(--bg);
    border-radius: 4px;
}

.winner {
    color: var(--accent);
    font-weight: 600;
}

/* ========== Error UI Override ========== */

#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZ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4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

.blazor-error-boundary::after {
    content: "An error has occurred."
}

/* ========== Loading ========== */

.loading-progress {
    position: relative;
    display: block;
    width: 8rem;
    height: 8rem;
    margin: 20vh auto 1rem auto;
}

.loading-progress circle {
    fill: none;
    stroke: #e0e0e0;
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--primary);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}

.loading-progress-text:after {
    content: var(--blazor-load-percentage-text, "Loading");
}

/* ========== Rules Page ========== */

.rules-page section {
    margin-bottom: 2rem;
}

.rules-page h2 {
    margin-top: 1.5rem;
}

.rules-page h3 {
    margin-top: 1.25rem;
}

.rules-page table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0;
}

.rules-page th,
.rules-page td {
    border: 1px solid var(--border);
    padding: 0.5rem 0.75rem;
    text-align: left;
}

.rules-page th {
    background: var(--surface);
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ========== PWA Update Toast ========== */

.sw-update-toast {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--text);
    color: white;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
    z-index: 2000;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.sw-update-toast.visible {
    transform: translateY(0);
}

.sw-update-toast span {
    flex: 1;
}

.sw-update-btn {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    padding: 0.4rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.sw-update-btn:hover {
    background: var(--primary-dark);
}

.sw-dismiss-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    font-size: 1rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
}

.sw-dismiss-btn:hover {
    color: white;
}

/* ========== Responsive ========== */

@media (max-width: 480px) {
    .app-title {
        font-size: 1rem;
    }

    .nav-links .nav-link {
        padding: 0.3rem 0.5rem;
        font-size: 0.8rem;
    }

    .lang-toggle {
        padding: 0.25rem 0.4rem;
        font-size: 0.75rem;
    }

    .timer-display {
        font-size: 2.5rem;
    }

    .player-grid {
        grid-template-columns: 1fr 1fr;
    }

    .courts-container {
        grid-template-columns: 1fr;
    }
}
