* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html.menu-visible .controls {
    max-height: 200px;
    opacity: 1;
}

.controls.hidden {
    max-height: 0;
    opacity: 0;
    margin: 0;
    padding: 0;
}

.controls {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    transition: opacity 0.5s ease, max-height 0.5s ease;
    overflow: hidden;
    opacity: 1;
    margin-bottom: 15px;
}

body {
    font-family: 'Montserrat', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-weight: 700;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    margin: 0;
    padding: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    overflow-x: hidden; /* ДОБАВИТЬ: Запрещаем горизонтальную прокрутку */
}

* {
    box-sizing: border-box; /* ДОБАВИТЬ: Правильный расчет ширины */
}


.container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    border-radius: 15px;
    padding: 10px;
    overflow-x: hidden;
    width: 100%;
}

header {
    text-align: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 3px solid #e20713;
}

h1 {
    color: #333;
    font-size: 2.5em;
    font-weight: 700;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
}

.btn:hover {
    transform: translateY(-2px);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5568d3;
}

.btn-success {
    background: #48bb78;
    color: white;
}

.btn-success:hover {
    background: #38a169;
}

.btn-danger {
    background: #e20713;
    color: white;
}

.btn-danger:hover {
    background: #c00610;
}

.btn-secondary {
    background: #718096;
    color: white;
    margin-bottom: 10px;
}

.btn-secondary:hover {
    background: #4a5568;
}


.status-message {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    border-radius: 8px;
    display: none;
    font-weight: 500;
    z-index: 1000;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        bottom: -50px;
        opacity: 0;
    }
    to {
        bottom: 20px;
        opacity: 1;
    }
}

.status-message.success {
    background: #c6f6d5;
    color: #22543d;
    border: 1px solid #9ae6b4;
    display: block;
}

.status-message.error {
    background: #fed7d7;
    color: #742a2a;
    border: 1px solid #fc8181;
    display: block;
}

/* Модальное окно */
.modal {
    display: none;
    position: fixed;
    z-index: 10001;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal.show {
    display: flex;
    /* align-items: center; */
    justify-content: center;
}

.modal-content {
    background-color: white;
    border-radius: 15px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    height: fit-content;
    display: flex;
    flex-direction: column;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 20px 25px;
    border-bottom: 2px solid #e20713;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    color: #333;
    font-size: 1.5em;
}

.close-modal {
    font-size: 32px;
    font-weight: 700;
    color: #999;
    cursor: pointer;
    transition: color 0.2s ease;
    line-height: 1;
}

.close-modal:hover {
    color: #e20713;
}

.modal-body {
    padding: 20px 25px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 15px 25px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.team-search-container {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.team-search-input {
    flex: 1;
    padding: 12px 15px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 16px;
    font-family: 'Montserrat', sans-serif;
    font-weight: 700;
    transition: border-color 0.2s ease;
}

.team-search-input:focus {
    outline: none;
    border-color: #e20713;
}

.bulk-import-container {
    margin-bottom: 20px;
    padding: 15px;
    background-color: #f7fafc;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
}

.bulk-import-textarea {
    width: 100%;
    min-height: 200px;
    padding: 12px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    font-family: 'Montserrat', sans-serif;
    font-weight: 600;
    resize: vertical;
    margin-bottom: 10px;
    line-height: 1.6;
}

.bulk-import-textarea:focus {
    outline: none;
    border-color: #e20713;
}

.bulk-import-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.bulk-import-toggle {
    margin-bottom: 15px;
    text-align: center;
}

.bulk-import-stats {
    margin-top: 10px;
    padding: 10px;
    background-color: #e6fffa;
    border-left: 4px solid #38b2ac;
    border-radius: 4px;
    font-size: 14px;
    color: #234e52;
}

.bulk-import-stats.error {
    background-color: #fff5f5;
    border-left-color: #e53e3e;
    color: #742a2a;
}


.teams-list-container {
    overflow-y: auto;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px;
    height: 75%;
}

.team-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid #e2e8f0;
    transition: background-color 0.2s ease;
}

.team-list-item:last-child {
    border-bottom: none;
}

.team-list-item:hover {
    background-color: #f7fafc;
}

.team-list-item-name {
    font-size: 16px;
    font-weight: 700;
    color: #2d3748;
    flex: 1;
}

.team-list-item-name input {
    width: 100%;
    border: none;
    background: transparent;
    font-size: 16px;
    font-weight: 700;
    font-family: 'Montserrat', sans-serif;
    color: #2d3748;
    padding: 4px;
}

.team-list-item-name input:focus {
    outline: none;
    background-color: #f0f8ff;
    border-radius: 4px;
}

.team-list-item-actions {
    display: flex;
    gap: 8px;
}

.team-list-item-actions button {
    background: #e20713;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.team-list-item-actions button:hover {
    background: #c00610;
    transform: scale(1.05);
}

.empty-teams-list {
    text-align: center;
    padding: 40px 20px;
    color: #a0aec0;
    font-style: italic;
}

/* Скрытие на мобильных */
.desktop-only {
    display: inline-block;
}

@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }
    
    .modal-content {
        width: 95%;
        max-height: 90vh;
    }
    
    .modal-header {
        padding: 15px 20px;
    }
    
    .modal-body {
        padding: 15px 20px;
    }
    
    .team-search-container {
        flex-direction: row;
    }
}


.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: white;
}

thead {
    background: #e20713;
    color: white;
}

th {
    padding: 20px 10px;
    text-align: center;
    font-weight: 700;
    font-size: 14px;
    letter-spacing: 0.5px;
    color: white;
    border-top: 2px solid #e20713;
    border-bottom: 2px solid #e20713;
    border-right: 2px solid #e20713;
}

th:first-child {
    border-left: 2px solid #e20713;
}

th:last-child {
    border-right: 2px solid #e20713;
}

th.round-header {
    font-size: 10px;
    line-height: 1.2;
}

th.round-header .round-label {
    display: block;
    font-size: 8px;
}

th.round-header .round-number {
    display: block;
    font-size: 12px;
    margin-top: 2px;
}

th.place-header {
    font-size: 10px;
}

td {
    padding: 0;
    text-align: center;
    border-bottom: 2px solid #e20713;
    border-right: 2px solid #e20713;
    height: 50px;
}

td:first-child {
    border-left: 2px solid #e20713;
}

td:last-child {
    border-right: 2px solid #e20713;
}

tbody tr {
    transition: background-color 0.2s ease;
}

.place-cell {
    font-weight: 700;
    font-size: 18px;
    color: #000000;
    background: white;
    border-left: 0;
    border-right: 0;
    padding: 12px 10px;
}

.change-cell {
    font-weight: 700;
    font-size: 20px;
    background: white;
    border-left: 2px solid #e20713;
    border-right: 2px solid #e20713;
    padding: 12px 10px;
}

.change-positive {
    color: #38761d;
    background-color: #b6d7a8 !important;
}

.change-negative {
    color: #660000;
    background-color: #ea9999 !important;
}

.change-neutral {
    color: #783f04;
    background-color: #f6b26b !important;
}


.team-name {
    font-weight: 700;
    color: #000000;
    text-align: center;
    padding: 0;
    min-width: 120px;
    position: sticky;
    left: 0;
    background: white;
    z-index: 10;
    border-left: 2px solid #e20713;
    border-right: 2px solid #e20713;
}


.team-name-text {
    display: inline-block;
    width: 100%;
    padding: 8px;
    font-size: 18px;
}

.score-input {
    width: 100%;
    height: 100%;
    padding: 0;
    border: none;
    text-align: center;
    font-size: 18px;
    font-weight: 700;
    font-family: 'Montserrat', sans-serif;
    background: transparent;
    transition: background-color 0.2s ease;
}

.score-input:focus {
    outline: none;
    background-color: #f0f8ff;
}

td.score-cell {
    padding: 0;
    height: 50px;
    width: 80px;
    min-width: 80px;
}


td.score-cell {
    padding: 0;
    height: 50px;
}

.total-cell {
    font-weight: 700;
    font-size: 18px;
    color: white;
    background: #e20713;
    padding: 12px 10px;
    position: sticky;
    right: 0;
    z-index: 5;
    border-right: 2px solid #e20713;
    border-left: 2px solid #e20713;
}


thead th:last-child {
    position: sticky;
    right: 0;
    z-index: 20;
    background: #e20713;
}

/* Медальные места */
.medal-gold {
    background: linear-gradient(180deg, #E1AC2C 0%, #F4E180 100%) !important;
    color: #783f04 !important;
}

.medal-silver {
    background: linear-gradient(180deg, #C2C2C2 0%, #E9E9E9 100%) !important;
    color: #434343 !important;
}

.medal-bronze {
    background: linear-gradient(180deg, #ce9363 0%, #EACC77 100%) !important;
    color: #783f04 !important;
}

/* Фиксация колонок при прокрутке */
thead th:nth-child(3) {
    position: sticky;
    left: 0;
    z-index: 20;
    background: #e20713;
    border-left: 2px solid #e20713;
}

thead th:last-child {
    position: sticky;
    right: 0;
    z-index: 20;
    background: #e20713;
    border-right: 2px solid #e20713;
}

tbody tr .team-name {
    left: 0;
}

/* Адаптивный дизайн */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    h1 {
        font-size: 1.8em;
    }
    
    .controls {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
    }
    
    th, td {
        font-size: 12px;
    }
    
    .score-input, .team-name input {
        font-size: 16px;
    }
    
    .place-cell {
        font-size: 16px;
    }

    .team-name-text {
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px;
    }
    
    .container {
        padding: 10px;
        border-radius: 10px;
    }
    
    h1 {
        font-size: 1.5em;
    }
    
    th {
        padding: 15px 5px;
    }
}

.team-name-wrapper {
    position: relative;
}

.team-autocomplete {
    position: fixed;
    background: white;
    border: 2px solid #e20713;
    max-height: 200px;
    overflow-y: auto;
    z-index: 10000;
    display: none;
    min-width: 200px;
}

.team-autocomplete.show {
    display: block;
}


.autocomplete-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 1px solid #e2e8f0;
    transition: background-color 0.2s ease;
}

.autocomplete-item:hover {
    background-color: #f7fafc;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

td.score-cell {
    padding: 0;
    height: 50px;
    width: 80px;
    min-width: 80px;
}

th.round-header {
    width: 80px;
    min-width: 80px;
}

.team-name input::placeholder {
    color: #a0aec0;
    font-style: italic;
}

@media (max-width: 768px) {
    td.score-cell {
        width: 60px;
        min-width: 60px;
    }
    
    th.round-header {
        width: 60px;
        min-width: 60px;
    }
    
    .team-autocomplete {
        max-height: 150px;
        font-size: 14px;
    }
}

.teams-section-header {
    font-size: 14px;
    font-weight: 700;
    color: #718096;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 12px 15px;
    background-color: #f7fafc;
    border-bottom: 2px solid #e2e8f0;
    margin-top: 10px;
}

.teams-section-header:first-child {
    margin-top: 0;
}

.team-list-item.in-table {
    background-color: #f0f8ff;
    border-left: 4px solid #667eea;
}

.team-list-item-actions .btn-add {
    background: #48bb78;
}

.team-list-item-actions .btn-add:hover {
    background: #38a169;
}

.team-list-item-actions .btn-remove {
    background: #f59e0b;
}

.team-list-item-actions .btn-remove:hover {
    background: #d97706;
}

/* Формы */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 700;
    color: #2d3748;
    font-size: 14px;
}

.form-input,
.form-select {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 16px;
    font-family: 'Montserrat', sans-serif;
    font-weight: 600;
    transition: border-color 0.2s ease;
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: #e20713;
}

.form-select {
    cursor: pointer;
    background-color: white;
}

/* Сводка игры */
.game-summary {
    margin-top: 20px;
    padding: 15px;
    background-color: #f7fafc;
    border-radius: 8px;
    border: 2px solid #e2e8f0;
}

.game-summary h3 {
    margin: 0 0 15px 0;
    font-size: 16px;
    color: #2d3748;
}

.game-summary-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #e2e8f0;
}

.game-summary-item:last-child {
    border-bottom: none;
}

.game-summary-label {
    font-weight: 700;
    color: #718096;
}

.game-summary-value {
    font-weight: 700;
    color: #2d3748;
}

/* Большое модальное окно */
.modal-large .modal-content {
    max-width: 900px;
}

/* Фильтры архива */
.archive-filters {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
}

.archive-filters .form-select,
.archive-filters .form-input {
    flex: 1;
}

/* Контейнер архива игр */
.games-archive-container {
    max-height: 500px;
    overflow-y: auto;
}

.game-card {
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 15px;
    transition: all 0.2s ease;
    cursor: pointer;
}

.game-card:hover {
    border-color: #e20713;
    box-shadow: 0 4px 12px rgba(226, 7, 19, 0.1);
}

.game-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 2px solid #e2e8f0;
}

.game-card-title {
    font-size: 18px;
    font-weight: 700;
    color: #2d3748;
}

.game-card-city {
    display: inline-block;
    padding: 6px 12px;
    background-color: #e20713;
    color: white;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
}

.game-card-city.dubai {
    background-color: #3182ce;
}

.game-card-city.abudhabi {
    background-color: #38a169;
}

.game-card-body {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 15px;
}

.game-card-stat {
    text-align: center;
}

.game-card-stat-label {
    font-size: 12px;
    color: #718096;
    margin-bottom: 5px;
}

.game-card-stat-value {
    font-size: 24px;
    font-weight: 700;
    color: #2d3748;
}

.game-card-teams {
    margin-top: 15px;
}

.game-card-teams-title {
    font-size: 14px;
    font-weight: 700;
    color: #718096;
    margin-bottom: 10px;
}

.game-card-top-teams {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.game-card-team {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background-color: #f7fafc;
    border-radius: 6px;
}

/* Призовые места */
.first {
    background: linear-gradient(180deg, #ffd966 0%, #fff4cc 25%, #ffd966 100%) !important;
    color: #7f6000 !important;
}

.second {
    background: linear-gradient(180deg, #d9d9d9 0%, #f0f0f0 25%, #d9d9d9 100%) !important;
    color: #434343 !important;
}

.third {
    background: linear-gradient(180deg, #f6b26b 0%, #fcd5b4 25%, #f6b26b 100%) !important;
    color: #783f04 !important;
}


.game-card-team-name {
    font-weight: 700;
}

.game-card-team-score {
    font-weight: 700;
    font-size: 18px;
}

.game-card-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 2px solid #e2e8f0;
}

.game-card-actions button {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 6px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-load {
    background-color: #3182ce;
    color: white;
}

.btn-load:hover {
    background-color: #2c5282;
}

.btn-delete {
    background-color: #e53e3e;
    color: white;
}

.btn-delete:hover {
    background-color: #c53030;
}

.btn-export {
    background-color: #38a169;
    color: white;
}

.btn-export:hover {
    background-color: #2f855a;
}

.empty-archive {
    text-align: center;
    padding: 60px 20px;
    color: #a0aec0;
}

.empty-archive-icon {
    font-size: 64px;
    margin-bottom: 20px;
}

.empty-archive-text {
    font-size: 18px;
    font-style: italic;
}

@media (max-width: 768px) {
    .game-card-body {
        grid-template-columns: 1fr;
    }
    
    .archive-filters {
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 20px;
    }

    table {
        font-size: 12px;
        min-width: 450px;
    }

    th, td {
        padding: 6px 3px;
        font-size: 11px;
    }

    th.col-team {
        min-width: 100px;
    }

    td.team-name {
        max-width: 100px;
        font-size: 11px;
    }

    input.score-input {
        width: 35px;
        font-size: 13px;
    }

    .status {
        font-size: 13px;
        padding: 8px 12px;
    }
}
