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

body {
    background: linear-gradient(135deg, #0f0c1f 0%, #1a1a2e 50%, #16213e 100%);
    min-height: 100vh;
    font-family: 'Segoe UI', Tahoma, Verdana, sans-serif;
    margin: 0;
    padding: 15px;
    animation: gradientShift 15s ease infinite;
    background-size: 400% 400%;
}

@keyframes gradientShift {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 15px;
    width: 100%;
}

.calculator-card {
    background: rgba(45, 45, 45, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 30px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    border: 1px solid rgba(155, 89, 182, 0.3);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    animation: slideInUp 0.8s ease;
}

.calculator-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 25px 70px rgba(155, 89, 182, 0.4);
}

@keyframes slideInUp {
    from {
        transform: translateY(30px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.card-header {
    background: linear-gradient(135deg, #8e44ad 0%, #9b59b6 100%);
    color: white;
    padding: clamp(20px, 5vw, 35px);
    text-align: center;
}

.card-header h1 {
    margin: 0;
    font-size: clamp(1.2rem, 4vw, 2rem);
    font-weight: 700;
}

.card-header p {
    margin: 10px 0 0;
    font-size: clamp(0.9rem, 2vw, 1.1rem);
    opacity: 0.95;
}

.card-body {
    padding: clamp(15px, 4vw, 35px);
    background: rgba(45, 45, 45, 0.98);
    color: #e0e0e0;
}

/* --- ВКЛАДКИ (НОВЫЙ СТИЛЬ) --- */
.nav-tabs {
    border-bottom: none;
    margin-bottom: 1.8rem;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

.nav-tabs .nav-link {
    color: #d0d0d0;
    background: rgba(30, 30, 45, 0.7);
    border: none;
    border-radius: 40px;
    padding: 10px 24px;
    margin: 0;
    font-weight: 600;
    font-size: 1rem;
    transition: all 0.3s ease;
    backdrop-filter: blur(4px);
}

.nav-tabs .nav-link:hover {
    background: rgba(155, 89, 182, 0.6);
    color: white;
    transform: translateY(-2px);
}

.nav-tabs .nav-link.active {
    background: linear-gradient(135deg, #9b59b6, #8e44ad);
    color: white;
    box-shadow: 0 4px 12px rgba(155, 89, 182, 0.4);
}

#subTab.nav-tabs .nav-link {
    background: rgba(20, 20, 35, 0.8);
    border-radius: 30px;
    padding: 6px 18px;
    font-size: 0.9rem;
}

#subTab.nav-tabs .nav-link.active {
    background: linear-gradient(135deg, #9b59b6, #b96fcf);
}

/* --- КНОПКИ --- */
.btn-calculate,
.btn-add,
.btn-remove,
.btn-export {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    font-weight: 600;
    border-radius: 60px;
    padding: 8px 16px;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    cursor: pointer;
    text-align: center;
    white-space: nowrap;
}

.btn-calculate {
    background: linear-gradient(135deg, #8e44ad 0%, #9b59b6 100%);
    color: white;
    font-size: 1rem;
    padding: 12px 20px;
    width: 100%;
}

.btn-add {
    background: linear-gradient(135deg, #27ae60 0%, #2ecc71 100%);
    color: white;
}

.btn-remove {
    background: linear-gradient(135deg, #c0392b 0%, #e74c3c 100%);
    color: white;
}

.btn-export {
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    color: white;
}

.btn-calculate:hover,
.btn-add:hover,
.btn-remove:hover,
.btn-export:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.3);
}

.button-row {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    gap: 12px;
    margin: 15px 0;
}

.button-row .btn-add,
.button-row .btn-remove,
.button-row .btn-export,
.button-row .btn-calculate {
    flex: 0 1 auto;
    min-width: 130px;
}

@media (max-width: 640px) {
    .button-row {
        flex-wrap: wrap;
        gap: 8px;
    }

    .button-row .btn-add,
    .button-row .btn-remove,
    .button-row .btn-export {
        min-width: 110px;
        padding: 6px 12px;
        font-size: 0.8rem;
    }
}

/* --- ПОЛОСЫ РЕСУРСОВ (ТОЛЬКО ЗАПОЛНЕННАЯ ЧАСТЬ) --- */
.resource-usage {
    display: flex;
    gap: 20px;
    margin: 20px 0;
    flex-wrap: wrap;
}

.resource-item {
    flex: 1;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    min-width: 200px;
}

.resource-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 0.95rem;
}

.resource-bar-container {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    overflow: hidden;
    height: 34px;
    width: 100%;
}

.resource-bar-used {
    background: linear-gradient(90deg, #9b59b6, #8e44ad);
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding-left: 12px;
    color: white;
    font-weight: bold;
    font-size: 0.85rem;
    transition: width 0.2s ease;
    white-space: nowrap;
    width: 0%;
}

/* СООБЩЕНИЕ О ЛИМИТЕ — БЕЛЫЙ ЦВЕТ */
#tspLimitMessage {
    color: white !important;
    font-weight: 500;
}

/* ОБЩИЕ СТИЛИ ФОРМ */
.form-label {
    color: #e0e0e0;
    font-weight: 600;
    margin-bottom: 8px;
    display: block;
}

.form-control {
    background: rgba(64, 64, 64, 0.8);
    border: 2px solid #4a4a4a;
    color: #e0e0e0;
    border-radius: 12px;
    padding: 10px;
    width: 100%;
    transition: all 0.3s ease;
}

.form-control:focus {
    border-color: #9b59b6;
    box-shadow: 0 0 15px rgba(155, 89, 182, 0.3);
    outline: none;
}

.product-row {
    background: rgba(54, 54, 54, 0.9);
    border-radius: 15px;
    padding: 15px;
    margin-bottom: 15px;
    border-left: 5px solid #9b59b6;
}

.result-card {
    background: linear-gradient(135deg, #8e44ad 0%, #9b59b6 100%);
    border-radius: 20px;
    padding: 20px;
    margin-top: 20px;
}

.profit-badge {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 60px;
    padding: 12px 24px;
    display: inline-block;
    font-size: 1.6rem;
    font-weight: bold;
    text-align: center;
}

.profit-badge.negative {
    background: rgba(220, 53, 69, 0.8);
    color: #fff;
}

.stats-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin: 20px 0;
}

.checks-info {
    background: rgba(54, 54, 54, 0.9);
    border-radius: 15px;
    padding: 15px;
    text-align: center;
    border: 1px solid #9b59b6;
}

.charts-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 15px;
    margin: 15px 0;
}

.chart-container {
    background: rgba(54, 54, 54, 0.9);
    border-radius: 15px;
    padding: 15px;
    height: 300px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.chart-container canvas {
    max-width: 100%;
    max-height: 100%;
}

.table-responsive {
    overflow-x: auto;
    border-radius: 15px;
}

.table {
    color: #e0e0e0;
    border-collapse: collapse;
    width: 100%;
}

.table thead th {
    background: linear-gradient(135deg, #8e44ad 0%, #9b59b6 100%);
    color: white;
    padding: 12px 8px;
    font-weight: 600;
    border: none;
}

.table tbody tr {
    border-bottom: 1px solid #4a4a4a;
    transition: background 0.2s;
}

.table tbody tr:hover {
    background: rgba(155, 89, 182, 0.2);
}

.table td,
.table th {
    padding: 10px 8px;
    vertical-align: middle;
}

.tsp-card,
.simplex-card {
    background: rgba(30, 30, 45, 0.8);
    border-radius: 20px;
    padding: 20px;
    border: 1px solid #9b59b6;
    margin-top: 20px;
    overflow-x: auto;
}

.matrix-input {
    width: 70px;
    text-align: center;
    background: rgba(64, 64, 64, 0.9);
    border: 1px solid #9b59b6;
    color: white;
    border-radius: 8px;
    padding: 6px;
}

.tsp-result-badge {
    background: #9b59b6;
    border-radius: 40px;
    padding: 12px 20px;
    font-size: 1.2rem;
    font-weight: bold;
    display: inline-block;
}

.tsp-canvas-container {
    background: #1e1e2a;
    border-radius: 20px;
    padding: 10px;
    margin-top: 20px;
    border: 1px solid #9b59b6;
    text-align: center;
}

canvas#tspGraphCanvas {
    width: 100%;
    height: auto;
    max-width: 800px;
    aspect-ratio: 600/400;
    background: #0f0f1a;
    border-radius: 16px;
    margin: 0 auto;
    display: block;
}

.history-item {
    background: rgba(54, 54, 54, 0.9);
    border: 1px solid #9b59b6;
    border-radius: 10px;
    padding: 12px 15px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 8px;
}

.history-item:hover {
    background: rgba(155, 89, 182, 0.3);
    transform: translateX(5px);
}

@media (max-width: 768px) {
    .matrix-input {
        width: 55px;
        font-size: 0.7rem;
    }

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

    .resource-usage {
        flex-direction: column;
    }

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

    .btn-calculate {
        font-size: 0.9rem;
        padding: 10px;
    }
}

/* ===== МАТРИЦА РАССТОЯНИЙ – ТАБЛИЦА КАК В НАЧАЛЬНОМ ВАРИАНТЕ ===== */
#distanceMatrixContainer {
    overflow-x: auto;
    margin: 15px 0;
}

#distanceMatrixContainer table {
    width: auto;
    margin: 0 auto;
    background: rgba(30, 30, 45, 0.8);
    border-collapse: collapse;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}

#distanceMatrixContainer th,
#distanceMatrixContainer td {
    border: 1px solid #9b59b6;
    padding: 10px 12px;
    text-align: center;
    vertical-align: middle;
    background-color: rgba(0, 0, 0, 0.2);
}

#distanceMatrixContainer th {
    background: linear-gradient(135deg, #8e44ad, #9b59b6);
    color: white;
    font-weight: bold;
    font-size: 1rem;
    padding: 12px 8px;
}

#distanceMatrixContainer td:first-child {
    background: linear-gradient(135deg, #6c3483, #8e44ad);
    color: white;
    font-weight: bold;
}

#distanceMatrixContainer .matrix-input {
    width: 70px;
    text-align: center;
    background: rgba(64, 64, 64, 0.9);
    border: 1px solid #9b59b6;
    color: white;
    border-radius: 10px;
    padding: 8px 5px;
    font-size: 0.9rem;
    transition: all 0.2s;
}

#distanceMatrixContainer .matrix-input:focus {
    border-color: #f39c12;
    outline: none;
    box-shadow: 0 0 8px rgba(243, 156, 18, 0.5);
}

#distanceMatrixContainer .matrix-input[disabled] {
    background: #2c3e50;
    border-color: #7f8c8d;
    color: #bdc3c7;
}

/* ===== ВЫРАВНИВАНИЕ КНОПОК В СИМПЛЕКСЕ И ДВОЙСТВЕННОМ ===== */
#simplexTab .btn-add,
#simplexTab .btn-calculate,
#dualTab .btn-add,
#dualTab .btn-calculate {
    width: 100%;
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    font-size: 0.9rem;
    padding: 8px 12px;
}

@media (max-width: 640px) {

    #simplexTab .btn-add,
    #simplexTab .btn-calculate,
    #dualTab .btn-add,
    #dualTab .btn-calculate {
        white-space: normal;
        font-size: 0.8rem;
        padding: 6px 8px;
        min-height: auto;
    }
}