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

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    height: 100vh;
    padding: 20px;
    overflow: hidden;
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }
}

.container {
    max-width: 100%;
    width: 100%;
    height: calc(100vh - 40px);
    margin: 0 auto;
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

@media (max-width: 768px) {
    .container {
        border-radius: 10px;
    }
}

header {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: white;
    padding: 12px 20px;
    text-align: center;
}

header h1 {
    margin-bottom: 10px;
    font-size: 1.8em;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.tournament-info {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 10px;
}

.tournament-info input {
    padding: 6px 10px;
    border: none;
    border-radius: 5px;
    font-size: 13px;
    min-width: 150px;
}

.controls {
    display: flex;
    gap: 8px;
    padding: 8px;
    background: #f8f9fa;
    justify-content: center;
    flex-wrap: wrap;
}

.btn-primary, .btn-success, .btn-danger, .btn-info, .btn-secondary, .btn-blue, .btn-red {
    padding: 8px 16px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 13px;
    font-weight: bold;
    transition: all 0.3s;
    color: white;
}

.btn-primary {
    background: #007bff;
}

.btn-primary:hover {
    background: #0056b3;
}

.btn-success {
    background: #28a745;
}

.btn-success:hover {
    background: #218838;
}

.btn-danger {
    background: #dc3545;
}

.btn-danger:hover {
    background: #c82333;
}

.btn-info {
    background: #17a2b8;
}

.btn-info:hover {
    background: #138496;
}

.btn-secondary {
    background: #6c757d;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-blue {
    background: #0066cc;
    flex: 1;
}

.btn-red {
    background: #cc0000;
    flex: 1;
}

.main-content {
    display: flex;
    gap: 15px;
    padding: 10px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.competitors-panel {
    width: 280px;
    background: #f8f9fa;
    padding: 15px;
    border-radius: 10px;
    overflow-y: auto;
    flex-shrink: 0;
}

.competitors-panel h2 {
    margin-bottom: 15px;
    color: #1e3c72;
}

.competitors-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.competitor-item {
    background: white;
    padding: 12px;
    border-radius: 8px;
    border-left: 4px solid #007bff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    position: relative;
}

.competitor-item .name {
    font-weight: bold;
    color: #1e3c72;
    margin-bottom: 5px;
}

.competitor-item .details {
    font-size: 12px;
    color: #666;
}

.competitor-item .rank {
    position: absolute;
    top: 10px;
    right: 10px;
    background: #ffc107;
    color: #000;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: bold;
}

.competitor-item .remove {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 3px;
    padding: 3px 8px;
    cursor: pointer;
    font-size: 11px;
}

.bracket-container {
    flex: 1;
    overflow: hidden;
    padding: 0;
    background: #fafafa;
    border-radius: 10px;
    position: relative;
    cursor: grab;
}

.bracket-container:active {
    cursor: grabbing;
}

.bracket-message {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #999;
    font-size: 18px;
}

.bracket-main-container {
    width: fit-content;
    height: fit-content;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transform-origin: center center;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    will-change: transform;
}

.bracket {
    display: flex;
    gap: 0;
    position: relative;
    align-items: center;
}

.bracket-left {
    flex-direction: row;
}

.bracket-right {
    flex-direction: row-reverse;
}

.bracket-round {
    display: flex;
    flex-direction: column;
    position: relative;
}

.bracket-final-container {
    min-width: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 20px;
}

.round-title {
    text-align: center;
    font-weight: bold;
    color: #000;
    margin-bottom: 15px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    position: sticky;
    top: 0;
    background: white;
    padding: 8px 0;
    z-index: 5;
}

.match {
    background: white;
    border: 1px solid #999;
    border-radius: 3px;
    margin: 3px 0;
    min-width: 180px;
    max-width: 180px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    z-index: 10;
}

.match:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    transform: scale(1.01);
    border-color: #000;
}

.match-number {
    position: absolute;
    top: 3px;
    right: 3px;
    background: #999;
    color: white;
    padding: 3px 7px;
    border-radius: 12px;
    font-size: 9px;
    font-weight: bold;
    z-index: 20;
}

.competitor {
    padding: 6px 9px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #ddd;
    transition: background 0.2s;
    min-height: 26px;
}

.competitor:last-child {
    border-bottom: 0;
}

.competitor.blue {
    background: #fff;
}

.competitor.red {
    background: #fff3f3;
}

.competitor.winner {
    background: #d4edda;
    font-weight: bold;
}

.competitor.loser {
    opacity: 0.5;
}

.competitor-name {
    font-size: 11px;
    flex: 1;
    line-height: 1.3;
    font-weight: 600;
    color: #000;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.competitor-name .country {
    font-size: 9px;
    color: #666;
    display: inline;
    margin-left: 4px;
    font-weight: normal;
}

.competitor-name .rank-badge {
    background: #ffa500;
    color: white;
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 9px;
    margin-left: 4px;
    font-weight: bold;
}

.competitor-score {
    font-weight: bold;
    font-size: 14px;
    color: #1e3c72;
    min-width: 20px;
    text-align: center;
}

.match.completed {
    border-color: #28a745;
    background: #f8fff9;
}

.match.bye {
    opacity: 0.5;
    cursor: default;
}

.match.bye:hover {
    transform: none;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.6);
    animation: fadeIn 0.3s;
}

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

.modal-content {
    background-color: #fefefe;
    margin: 5% auto;
    padding: 30px;
    border: 1px solid #888;
    border-radius: 15px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    animation: slideIn 0.3s;
}

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

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s;
}

.close:hover,
.close:focus {
    color: #000;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: #333;
}

.form-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
}

.form-buttons {
    display: flex;
    gap: 10px;
    margin-top: 25px;
}

.form-buttons button {
    flex: 1;
}

#matchInfo {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.match-actions {
    display: flex;
    gap: 15px;
}

/* Responsive */
/* Responsive Design - JavaScript controla el scale dinámicamente */

@media (max-width: 1400px) {
    .main-content {
        flex-direction: column;
    }
    
    .competitors-panel {
        width: 100%;
        max-height: 180px;
        margin-bottom: 10px;
    }
    
    .bracket-container {
        width: 100%;
        flex: 1;
    }
}

@media (max-width: 992px) {
    header h1 {
        font-size: 2em;
    }
    
    body {
        padding: 10px;
    }
    
    .container {
        height: calc(100vh - 20px);
    }
}

@media (max-width: 768px) {
    .tournament-info {
        flex-direction: column;
    }
    
    .tournament-info input {
        min-width: 100%;
        width: 100%;
    }
    
    .controls {
        flex-direction: column;
        gap: 8px;
    }
    
    .controls button {
        width: 100%;
    }
    
    header h1 {
        font-size: 1.5em;
    }
    
    .main-content {
        padding: 10px;
    }
    
    header {
        padding: 20px;
    }
}

@media (max-width: 576px) {
    .bracket-container {
        min-height: 400px;
        padding: 5px;
    }
    
    header {
        padding: 15px;
    }
    
    header h1 {
        font-size: 1.2em;
    }
    
    .controls {
        padding: 10px;
        gap: 8px;
    }
    
    .btn-primary, .btn-success, .btn-danger, .btn-info, .btn-secondary {
        padding: 10px 15px;
        font-size: 13px;
    }
}

@media print {
    .controls, .competitors-panel, .modal {
        display: none !important;
    }
    
    .bracket-container {
        overflow: visible;
    }
    
    body {
        background: white;
    }
    
    .container {
        box-shadow: none;
    }
}

/* Conexiones entre matches */
.bracket-round {
    position: relative;
}

.match-connector {
    position: absolute;
    background: #666;
    z-index: 1;
}

.connector-horizontal {
    height: 2px;
    background: #666;
}

.connector-vertical {
    width: 2px;
    background: #666;
}

.connector-line {
    position: absolute;
    background: #666;
    z-index: 1;
}
