/* v11 - Báo cáo tự lắp ghép theo section */

body {
    background: #f1f3f5;
    color: #212529;
}

.report-wrapper {
    max-width: 1600px;
    margin: 0 auto;
}

/* ---------- Bìa + mục lục ---------- */

.cover {
    background: #ffffff;
    border-top: 8px solid #d71920;
    border-radius: .5rem;
    padding: 2rem 2rem 1.5rem;
}

.cover-title {
    font-weight: 800;
    letter-spacing: .02em;
    margin: 0;
    line-height: 1.15;
}

.cover-title span {
    display: block;
}

.cover-title .line-1 {
    font-size: 1.1rem;
    color: #6c757d;
}

.cover-title .line-2 {
    font-size: 2.1rem;
    color: #d71920;
}

.cover-period {
    margin-top: .5rem;
    font-size: 1.05rem;
}

.toc-list {
    margin: 1rem 0 0;
    border-top: 1px solid #dee2e6;
}

/* Nút thêm section ở cuối danh sách: viền nét đứt */
.add-section-dashed {
    border: 2px dashed #ced4da;
    color: #6c757d;
    background: transparent;
    padding: .7rem;
}

.add-section-dashed:hover,
.add-section-dashed:focus-visible {
    border-color: #d71920;
    color: #d71920;
    background: #fff8f8;
}

/* Tên section trong danh sách là liên kết tới section đó */
.section-item a.name {
    display: block;
    color: inherit;
    text-decoration: none;
}

.section-item a.name:hover {
    color: #d71920;
}

/* ---------- Danh sách section (phần cấu hình) ---------- */

.section-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .6rem .25rem;
    border-top: 1px solid #e9ecef;
    background: #ffffff;
}

.section-item:first-child {
    border-top: 0;
}

.section-item.dragging {
    opacity: .4;
}

.section-item.drop-target {
    box-shadow: inset 0 3px 0 #d71920;
}

.section-item .grip {
    cursor: grab;
    color: #adb5bd;
    font-size: 1.2rem;
}

.section-item .info {
    flex: 1;
    min-width: 0;
}

.section-item .name {
    font-weight: 600;
}

.section-item .desc {
    font-size: .82rem;
    color: #6c757d;
}

@media (max-width: 575.98px) {
    .section-item {
        flex-wrap: wrap;
    }

    .section-item .info {
        flex-basis: calc(100% - 2.5rem);
    }

    .section-item .btn-group {
        margin-left: auto;
    }
}

/* ---------- Đầu mục section, dính khi cuộn ---------- */

.section-header {
    position: sticky;
    top: 0;
    z-index: 20;
    border-radius: .375rem;
}

.section-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
}

.section-scope {
    font-size: .85rem;
}

/* Pill cho từng hạng mục bộ lọc ở đầu section (nền trắng trên nền đỏ) */
.section-scope .scope-pill {
    font-weight: 500;
    font-size: .78rem;
    color: #8b0f14 !important;
    white-space: normal;
    text-align: left;
}

/* Số mục đã chọn cạnh tên card trong trình soạn: "Thương hiệu (3)" */
.field-count {
    color: #d71920;
}

/* Tooltip rộng cho danh sách dài (pill đầu section, tỉnh của một vùng) */
.wide-tooltip {
    --bs-tooltip-max-width: 420px;
    --bs-tooltip-font-size: .8rem;
}

.wide-tooltip .tooltip-inner {
    text-align: left;
}

.scope-pill,
.has-tooltip {
    cursor: help;
}

.report-table .has-tooltip {
    text-decoration: underline dotted rgba(215, 25, 32, .6);
    text-underline-offset: 3px;
}

.report-section {
    scroll-margin-top: 8px;
    margin-bottom: 2.5rem;
}

.sub-title {
    font-size: 1rem;
    font-weight: 700;
    margin: 1.25rem 0 .6rem;
}

/* ---------- Bảng số liệu ---------- */

.report-table {
    width: 100%;
    min-width: 1000px;
    border-collapse: collapse;
    background: #ffffff;
    font-size: .9rem;
}

.report-table th,
.report-table td {
    border: 1px solid #707070;
    padding: 6px 7px;
    vertical-align: middle;
}

.report-table thead th {
    background: #d9e2f3;
    text-align: center;
    font-weight: 700;
}

.report-table .label {
    min-width: 170px;
    font-weight: 600;
    text-align: left;
}

.report-table .number {
    text-align: center;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.report-table .col-current {
    background: #fff4d6;
}

.report-table thead .col-current {
    background: #ffe08a;
}

.report-table .col-period {
    background: #e2edf5;
}

/* Số trong ô: đậm; thị phần bên dưới: thường */
.report-table .cell-value {
    display: block;
    font-weight: 700;
}

.report-table .cell-empty {
    color: #adb5bd;
    font-weight: 400;
}

.report-table .total td {
    background: #dce6f1;
    font-weight: 700;
}

.report-table .market td {
    background: #f8f9fa;
    color: #495057;
    font-style: italic;
}

.report-table .share {
    display: block;
    color: #6c757d;
    font-size: .75rem;
    font-weight: 400;
    font-style: normal;
}

/* Thị phần so với kỳ trước: xanh = tăng, đỏ = giảm, xám = không đổi */
.report-table .share-up {
    color: #198754;
}

.report-table .share-down {
    color: #dc3545;
}

.report-table .share-flat {
    color: #868e96;
}

.report-table .cell-link {
    cursor: pointer;
}

.report-table .cell-link:hover {
    text-decoration: underline;
    color: #d71920;
}

.change-up {
    color: #198754;
}

.change-down {
    color: #dc3545;
}

/* ---------- Biểu đồ ---------- */

/* Mỗi phần của section (bảng, từng biểu đồ) là một card */
.part-card {
    border-color: #dee2e6;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
}

.part-title {
    background: #f8f9fa;
    font-weight: 700;
    font-size: .95rem;
    border-left: 4px solid #d71920;
}

.chart-placeholder {
    padding: 3rem 1rem;
    text-align: center;
    color: #adb5bd;
}

/* ---------- Trình soạn section ---------- */

.editor-canvas {
    --bs-offcanvas-width: min(620px, 100vw);
}

/* Nền xám để các card của trình soạn nổi lên */
.editor-canvas .offcanvas-body {
    background: #f1f3f5;
}

/* Mỗi mục của trình soạn section là một card, tên mục là phần đầu card */
.editor-field {
    background: #ffffff;
    border: 1px solid #dee2e6;
    border-radius: .5rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
    padding: 0 1rem .9rem;
    margin-bottom: .85rem;
    overflow: hidden;
}

.editor-field > .form-label {
    display: block;
    margin: 0 -1rem .75rem;
    padding: .55rem 1rem;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    border-left: 4px solid #d71920;
    font-weight: 700;
}

.editor-field > .form-text:last-child,
.editor-field > .form-check:last-child {
    margin-bottom: 0;
}

/* Card "Tên section" luôn dính ở đầu khung soạn khi cuộn */
.editor-field.editor-name {
    position: sticky;
    top: -1rem;
    z-index: 5;
    box-shadow: 0 4px 10px -4px rgba(0, 0, 0, .18);
}

/* Liên kết trong khung soạn (chọn nhanh, bỏ chọn hết...) màu success; "Xóa section" vẫn đỏ */
.editor-canvas .btn-link:not(.text-danger) {
    color: var(--bs-success);
    text-decoration-color: rgba(25, 135, 84, .4);
}

.editor-canvas .btn-link:not(.text-danger):hover,
.editor-canvas .btn-link:not(.text-danger):focus-visible {
    color: #146c43;
}

.chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
}

.chip-list.scroll {
    max-height: 190px;
    overflow: auto;
    border: 1px solid #dee2e6;
    border-radius: .375rem;
    padding: .5rem;
    background: #ffffff;
}

.chip {
    border: 1px solid #ced4da;
    background: #ffffff;
    color: #495057;
    border-radius: 999px;
    padding: .15rem .65rem;
    font-size: .85rem;
    line-height: 1.5;
}

.chip:hover {
    border-color: #6c757d;
}

.chip.on {
    background: #d71920;
    border-color: #d71920;
    color: #ffffff;
}

.chip .count {
    opacity: .7;
    font-size: .75rem;
    margin-left: .25rem;
}

.editor-summary {
    background: #fff8f8;
    border: 1px solid #f1c7c9;
    border-radius: .5rem;
    padding: .75rem 1rem;
    font-size: .88rem;
}

.records-table {
    font-size: .85rem;
    white-space: nowrap;
}

/* ---------- In ---------- */

@media print {
    body {
        background: #ffffff;
    }

    .no-print {
        display: none !important;
    }

    .section-header {
        position: static;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .report-section,
    .cover {
        break-inside: auto;
    }

    .row .part-card,
    .report-table tr {
        break-inside: avoid;
    }

    .report-table {
        min-width: 0;
        font-size: 9px;
    }

    /* Bảng vừa bề ngang trang: thu nhỏ thị phần và cột tên theo cỡ chữ in */
    .report-table .share {
        font-size: 8px;
    }

    .report-table .label {
        min-width: 0;
    }

    .report-table th,
    .report-table td {
        padding: 2px 3px;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Cặp biểu đồ (tròn + cột) nằm cạnh nhau và không tách qua 2 trang */
    .chart-row {
        break-inside: avoid;
    }

    .chart-row > .col-lg-6 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    /* Biểu đồ co theo bề ngang khung. Chiều cao giữ bằng tỉ lệ khung
       (padding-bottom = --chart-ratio, gán ở makeChartScalable) thay vì để SVG tự tính
       "height: auto": Chrome tính sai khi in => biểu đồ tràn ra khỏi card. */
    .chart-ratio-ready {
        min-height: 0 !important;
    }

    .chart-ratio-ready > .apexcharts-canvas {
        position: relative !important;
        width: 100% !important;
        height: 0 !important;
        padding-bottom: var(--chart-ratio) !important;
    }

    .chart-ratio-ready > .apexcharts-canvas > svg {
        position: absolute !important;
        top: 0;
        left: 0;
        width: 100% !important;
        height: 100% !important;
    }

    .table-responsive {
        overflow: visible !important;
    }
}
