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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    margin: 0; padding: 0;
    background-color: #f0f2f5; color: #333;
    transition: background-color 0.3s, color 0.3s;
}

.navbar {
    background-color: #1a1a24; color: white; display: flex; align-items: center; justify-content: space-between;
    padding: 12px 24px; box-shadow: 0 2px 10px rgba(0,0,0,0.15); position: relative; z-index: 1000;
}
.navbar-left { display: flex; align-items: center; }
.burger-btn {
    background: none; border: none; color: white; font-size: 24px; cursor: pointer; margin-right: 20px; transition: transform 0.2s;
}
.burger-btn:hover { transform: scale(1.1); }
.navbar h1 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: 0.5px; }
.theme-toggle-container { display: flex; align-items: center; gap: 10px; font-size: 16px; }

.sidebar {
    height: 100%; width: 260px; position: fixed; top: 0; left: -260px;
    background-color: #1f1f2e; overflow-x: hidden; transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding-top: 70px; z-index: 999; box-shadow: 4px 0 15px rgba(0,0,0,0.2);
}
.sidebar.active { left: 0; }
.sidebar a, li {
    padding: 15px 30px; text-decoration: none; font-size: 16px; color: #a0a0b5; display: block; transition: all 0.2s; border-left: 4px solid transparent;
}
.sidebar a:hover, .sidebar a.current { color: #ffffff; background-color: #2a2a3d; border-left-color: #b71c1c; }

.app-container { max-width: 100%; margin: 0 auto; padding: 20px 40px; }

.toolbar {
    background-color: #ffffff; padding: 15px 24px; display: flex; justify-content: space-between; align-items: center;
    border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); margin-bottom: 30px; transition: background-color 0.3s, border-color 0.3s;
}
.toolbar-group { display: flex; align-items: center; gap: 15px; }
.toolbar select {
    padding: 10px 16px; font-size: 14px; font-weight: 500; border: 1px solid #e0e0e0; border-radius: 8px; outline: none;
    font-family: inherit; background-color: #f8f9fa; cursor: pointer; transition: all 0.3s;
}

.switch-container { font-size: 14px; font-weight: 600; color: #4a5568; }
.switch { position: relative; display: inline-block; width: 48px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: #cbd5e0; transition: .3s; border-radius: 24px;
}
.slider:before {
    position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px;
    background-color: white; transition: .3s; border-radius: 50%; box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
input:checked + .slider { background-color: #2f855a; }
#themeToggle:checked + .slider { background-color: #880a14; }
input:checked + .slider:before { transform: translateX(24px); }

.group-section { display: flex; flex-wrap: wrap; gap: 24px; margin-bottom: 40px; }
.stats-section { display: flex; flex-direction: column; align-items: center; gap: 30px; margin-bottom: 40px; }

.table-container {
    flex: 1; min-width: 450px; background: #ffffff; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.05); overflow: hidden;
    border: 1px solid #f0f0f0; transition: background-color 0.3s, border-color 0.3s;
}
.stats-table-container {
    width: 100%; max-width: 600px; background: #ffffff; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.05); overflow: hidden;
    border: 1px solid #f0f0f0; transition: background-color 0.3s, border-color 0.3s;
}
.stats-table-container.large-stats { max-width: 900px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 12px 10px; text-align: center; border-bottom: 1px solid #ececec; transition: border-color 0.3s; }
.main-match-row:nth-child(odd) { background-color: #fafafa; }
tbody tr:hover { background-color: rgba(0,0,0,0.02); }
th { background-color: #b71c1c; color: white; font-weight: 600; border-bottom: none; letter-spacing: 0.3px; }
th:not(:last-child), td:not(:last-child) { border-right: 1px solid #ececec; }
th:not(:last-child) { border-right: 1px solid #d32f2f; }

.card-header-icon { font-size: 12px; vertical-align: middle; }
.flag-icon img { width: 20px; height: 15px; border-radius: 2px; vertical-align: middle; box-shadow: 0 1px 2px rgba(0,0,0,0.2); }

.standings-table td:first-child { font-weight: 700; color: #555; }
.standings-table tr:nth-child(1) td:first-child,
.standings-table tr:nth-child(2) td:first-child { border-left: 4px solid #38a169; }
.standings-table tr:nth-child(3) td:first-child { border-left: 4px solid #d69e2e; }

.best-thirds-table tbody tr:nth-child(-n+8) td:first-child { border-left: 4px solid #38a169; font-weight: 700; }

.score-input {
    width: 30px; height: 26px; text-align: center; border: 1px solid #cbd5e0;
    border-radius: 4px; background-color: #fff; color: inherit; font-weight: 600; font-size: 13px;
}
.score-input[readonly] { cursor: default; outline: none; }
.hidden { display: none !important; }

/* Vistas y Botones */
body.view-mode .score-input { border: 1px solid transparent; background-color: transparent; pointer-events: none; }
body.view-mode .whistle-btn, body.view-mode .control-btn, body.view-mode .timer-control-btn { display: none !important; }
body:not(.view-mode) .view-details-btn { display: none !important; }

.view-details-btn {
    background-color: #cbd5e0; color: #2d3748; border: none; border-radius: 4px;
    padding: 6px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; transition: background 0.2s;
}
.view-details-btn:hover { background-color: #a0aec0; }
.whistle-btn {
    background-color: #eab308; color: #111; border: none; border-radius: 50%;
    width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 2px 4px rgba(0,0,0,0.2); transition: transform 0.2s;
}
.whistle-btn:hover { transform: scale(1.1); background-color: #facc15; }

.match-details-row { background-color: #f8f9fa; }
.match-timer-bar { display: flex; justify-content: center; align-items: center; gap: 15px; padding: 10px; border-bottom: 1px dashed #cbd5e0; }
.timer-display { font-family: monospace; font-size: 26px; font-weight: bold; color: #eab308; letter-spacing: 1px; }
.timer-control-btn { background-color: transparent; border: 2px solid #eab308; color: #eab308; border-radius: 50%; width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.2s; }
.timer-control-btn:hover { background-color: #eab308; color: #111; }
.match-actions-container { display: flex; justify-content: space-around; padding: 15px; gap: 20px; }
.team-action-panel { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 10px; border-radius: 8px; background: white; border: 1px solid #e2e8f0; }
.cards-control { display: flex; align-items: center; gap: 8px; margin: 4px 0; font-size: 13px; font-weight: bold; }
.control-btn { background: #e2e8f0; border: none; border-radius: 4px; width: 22px; height: 22px; cursor: pointer; font-weight: bold; display: flex; align-items: center; justify-content: center; }
.control-btn:hover { background: #cbd5e0; }
.events-list { width: 100%; text-align: center; margin-bottom: 10px; font-size: 12px; font-weight: 600; color: #4a5568; }
.event-item { padding: 4px 0; border-bottom: 1px solid #edf2f7; }
.event-item:last-child { border-bottom: none; }

/* Modal */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 2000; backdrop-filter: blur(3px);
}
.modal-content { background: white; padding: 20px 30px; border-radius: 12px; width: 300px; box-shadow: 0 10px 25px rgba(0,0,0,0.2); }
.modal-input { width: 100%; padding: 8px 12px; margin: 5px 0 15px; border: 1px solid #cbd5e0; border-radius: 6px; font-family: inherit; font-size: 14px; }
.modal-btn { padding: 8px 16px; border: none; border-radius: 6px; font-weight: bold; cursor: pointer; }
.save-btn { background: #2f855a; color: white; }
.cancel-btn { background: #e2e8f0; color: #4a5568; }

/* BRACKET */
.bracket-scroll-container { width: 100%; overflow-x: auto; padding-bottom: 20px; }
.bracket-header { display: flex; background-color: #b71c1c; color: white; font-weight: bold; font-size: 11px; text-align: center; border-radius: 8px 8px 0 0; min-width: 950px; width: 100%; }
.bracket-header div { flex: 1; padding: 10px 4px; text-transform: uppercase; border-right: 1px solid rgba(255,255,255,0.2); }
.bracket-header div:last-child { border-right: none; }
.bracket-header div:nth-child(5) { flex: 1.2; }
.bracket-container { display: flex; justify-content: space-between; min-width: 950px; width: 100%; background-color: #fdfdfd; padding: 25px 8px; border-radius: 0 0 8px 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.05); border: 1px solid #ececec; border-top: none; transition: background-color 0.3s, border-color 0.3s; }
.bracket-col { display: flex; flex-direction: column; justify-content: space-around; flex: 1; padding: 0 5px; position: relative; }
.match-card { background: white; border-radius: 6px; box-shadow: 0 2px 5px rgba(0,0,0,0.06); margin: 8px 0; padding: 6px; position: relative; z-index: 2; border: 1px solid #f0f0f0; transition: background-color 0.3s, border-color 0.3s; }
.match-row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; font-size: 13px; font-weight: 500; transition: border-color 0.3s; }
.match-row:first-child { border-bottom: 1px solid #f0f0f0; }
.team-name { flex: 1; padding-right: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 5px;}
.team-name.right-align { justify-content: flex-end; }
.bracket-col.center-col { flex: 1.2; justify-content: center; gap: 20px; align-items: center; }
.champion-box { background-color: #f8f9fa; color: #333; text-align: center; padding: 12px; border-radius: 8px; width: 180px; font-weight: bold; box-shadow: 0 2px 8px rgba(0,0,0,0.05); border: 1px solid #e0e0e0; transition: background-color 0.3s, border-color 0.3s; }
.champion-box svg { margin-top: 5px; }
.center-label { text-align: center; font-size: 11px; font-weight: bold; color: #718096; margin-bottom: -5px; margin-top: 10px; text-transform: uppercase; }
#champion-name { display: flex; align-items: center; justify-content: center; gap: 5px; }

/* MODO OSCURO */
body.dark-mode { background-color: #121212; color: #e0e0e0; }
body.dark-mode .toolbar, body.dark-mode .table-container, body.dark-mode .stats-table-container,
body.dark-mode .match-card, body.dark-mode .champion-box,
body.dark-mode .modal-content, body.dark-mode .team-action-panel { background-color: #1e1e24; border-color: #2c2c35; }
body.dark-mode .bracket-container { background-color: #16161c; border-color: #2c2c35; }
body.dark-mode th:not(:last-child), body.dark-mode td:not(:last-child) { border-right-color: #2c2c35; }
body.dark-mode th:not(:last-child) { border-right-color: #8f1212; }
body.dark-mode td { border-bottom-color: #2c2c35; }
body.dark-mode .main-match-row:nth-child(odd) { background-color: #25252d; }
body.dark-mode tbody tr:hover { background-color: #2a2a35; }
body.dark-mode .match-row:first-child { border-bottom-color: #2c2c35; }
body.dark-mode .toolbar select, body.dark-mode .modal-input { background-color: #2a2a35; color: #e0e0e0; border-color: #444; }
body.dark-mode .score-input { background-color: #2a2a35; color: #e0e0e0; border-color: #555; }
body.dark-mode .champion-box { color: #e0e0e0; }
body.dark-mode .standings-table td:first-child { color: #aaa; }
body.dark-mode .switch-container { color: #e0e0e0; }
body.dark-mode .match-details-row { background-color: #16161c; }
body.dark-mode .match-timer-bar { background-color: rgba(0,0,0,0.2); border-bottom-color: #444; }
body.dark-mode .control-btn { background: #2c2c35; color: white; }
body.dark-mode .control-btn:hover { background: #3f3f4e; }
body.dark-mode .events-list { color: #a0aec0; }
body.dark-mode .event-item { border-bottom-color: #2c2c35; }
body.dark-mode .cancel-btn { background: #2c2c35; color: white; }
body.dark-mode .view-details-btn { background: #2c2c35; color: #e0e0e0; }
body.dark-mode .view-details-btn:hover { background: #3f3f4e; }

@media (max-width: 768px) {
    .app-container { padding: 10px; }
    .table-container, .stats-table-container { min-width: 100%; overflow-x: auto; }
    .toolbar { flex-direction: column; align-items: stretch; gap: 15px; }
    .toolbar-group { flex-direction: column; align-items: stretch; }
    .switch-container { flex-direction: row; justify-content: flex-end; }
}

.paused-timer {
    color: #f56565 !important;
    animation: blink 1.5s linear infinite;
}

@keyframes blink {
    50% { opacity: 0.3;}
}