/* файл: cargo-stats.css */

/* cargo-stats.css – современные стили для статистики */

.cargo-stats-body {
    padding: 1rem;
    max-height: 80vh;
    overflow-y: auto;
}

/* Вкладки */
.stats-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border, #e2e8f0);
}

.stats-tab {
    padding: 0.5rem 1rem;
    background: transparent;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.stats-tab.active {
    border-bottom-color: var(--primary, #0066cc);
    color: var(--primary, #0066cc);
    font-weight: 600;
}

.stats-tab-content {
    transition: opacity 0.2s;
}

/* Сетка карточек */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

/* Для карточек с финансовыми показателями можно добавить лёгкую границу */
.stat-card {
    background: var(--surface, white);
    border-radius: var(--radius-lg, 16px);
    padding: 1rem 1.2rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid var(--border-light, #f0f0f0);
}

/* Для карточек с отрицательной прибылью (если нужно) */
.stat-card[data-negative="true"] .stat-card-value {
    color: var(--error, #ef4444);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.stat-card-title {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted, #64748b);
    margin-bottom: 0.5rem;
}

.stat-card-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary, #0066cc);
    line-height: 1.2;
}

.stat-card-sub {
    font-size: 0.75rem;
    color: var(--text-muted, #64748b);
    margin-top: 0.5rem;
}

/* Секции */
.stats-section {
    margin-bottom: 2rem;
}

/* Иконки в заголовках секций */
.stats-section-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
}

.section-icon {
    font-size: 1.3rem;
}

/* Горизонтальные бары */
.stats-chart-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    justify-content: space-between;
}

.chart-container {
    flex: 1;
    min-width: 200px;
    background: var(--surface, white);
    border-radius: var(--radius-lg, 16px);
    padding: 1rem 1rem 1rem 1rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.chart-title {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 1rem;
    text-align: center;
}

.chart-bars {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.bar-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
}

.bar-label {
    width: 100px;
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bar-bg {
    flex: 1;
    height: 24px;
    background: var(--background-alt, #f1f5f9);
    border-radius: var(--radius-lg, 16px);
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--primary, #0066cc), #5a9eff);
    border-radius: var(--radius-lg, 16px);
    transition: width 0.6s cubic-bezier(0.2, 0.9, 0.4, 1.1);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 6px;
    color: white;
    font-size: 0.7rem;
    font-weight: bold;
}

.bar-value {
    min-width: 45px;
    text-align: right;
    font-weight: 500;
}

/* Круговая диаграмма (donut) */
.donut-container {
    position: relative;
    width: 200px;
    height: 200px;
    margin: 0 auto 1rem;
}

canvas#statusDonut {
    width: 200px;
    height: 200px;
    display: block;
}

canvas#trendChart {
    width: 100%;
    height: auto;
    display: block;
}

.donut-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.7rem;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: var(--radius-lg, 16px);
}

/* Всплывающая подсказка для доната */
.donut-tooltip {
    position: fixed;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 6px 12px;
    border-radius: var(--radius-md, 8px);
    font-size: 0.8rem;
    pointer-events: none;
    z-index: 10020;
    white-space: nowrap;
    backdrop-filter: blur(4px);
}

.chart-tooltip {
    position: fixed;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 6px 12px;
    border-radius: var(--radius-md, 8px);
    font-size: 0.8rem;
    pointer-events: none;
    z-index: 10020;
    backdrop-filter: blur(4px);
    white-space: nowrap;
}

/* Таблица */
.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.stats-table th,
.stats-table td {
    padding: 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border, #e2e8f0);
}

.stats-table th {
    background: var(--background-alt, #f8fafc);
    font-weight: 600;
}

.top-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.top-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.top-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    padding: 0.25rem 0;
    border-bottom: 1px dashed var(--border);
}

.top-code {
    font-weight: 500;
    color: var(--primary);
}

.top-value {
    font-weight: 600;
    color: var(--text);
}

.top-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 1rem;
}

/* Адаптивность */
@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stats-chart-grid {
        flex-direction: column;
    }

    .bar-label {
        width: 70px;
        font-size: 0.7rem;
    }
}

/* Базовый стиль для всех bar-label */
.bar-label {
    width: 120px;
    /* базовая ширина */
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Для маршрутов – чуть уже */
.route-label {
    width: 100px;
}

/* Для блоков «Способы доставки» и «Типы упаковки» – ещё уже */
.chart-container-7 .bar-label {
    width: 30px;
}

.chart-container-3 .bar-label {
    width: 60px;
}

.chart-container-6 .bar-label {
    width: 100px;
}

.chart-container-4 .bar-label {
    width: 150px;
}

.chart-container-5 .bar-label {
    width: 180px;
}

.month-range-filter .form-group {
    margin-bottom: 0;
}

.month-range-filter input[type="month"] {
    padding: 0.4rem 0.6rem;
    border-radius: var(--radius-lg, 16px);
    border: 1px solid var(--border);
}

.months-checkboxes label {
    transition: background 0.2s;
}

.months-checkboxes label:hover {
    background: var(--background-alt);
}

.months-checkboxes input {
    margin: 0;
}

@media (max-width: 768px) {
    .month-range-filter {
        flex-direction: column;
        align-items: stretch;
    }

    .month-range-filter .form-group {
        width: 100%;
    }

    .month-range-filter button {
        width: 100%;
    }
}

/* Адаптивность на мобильных устройствах */
@media (max-width: 768px) {
    .bar-label {
        width: 80px;
        font-size: 0.7rem;
    }

    .route-label {
        width: 70px;
    }
}