/* index.html — kiểu dáng trang. Tách nguyên văn từ <style> trong <head> (2026-10-23). */
    :root {
      --row-min:    0px;      /* sàn chiều cao 1 hàng chart — xem .grid */
      --bg:         #eef0f2;
      --bg-card:    #ffffff;
      --border:     #e2e5e9;
      --text:       #1f2937;
      --text-muted: #6b7280;
      --strip-bg:   #5b7275;   /* dải tiêu đề trang kiểu PowerBI */
      --accent:     #f97316;
      --green:      #16a34a;
      --red:        #dc2626;
    }
    * { box-sizing: border-box; margin: 0; padding: 0; }
    html, body { height: 100%; }
    body {
      background: var(--bg);
      color: var(--text);
      font-family: 'Be Vietnam Pro', sans-serif;
      font-size: 13px;
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }

    /* HEADER – dải tiêu đề kiểu PowerBI */
    .header {
      background: var(--strip-bg);
      padding: 5px 14px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      flex: none;
    }
    #logo { height: 18px; vertical-align: middle; margin-right: 10px;
      filter: brightness(0) invert(1); opacity: .95; }   /* wordmark trắng trên nền tối */
    .header-left h1 { font-size: 13px; font-weight: 700; color: #fff; letter-spacing: -.1px; display: inline; vertical-align: middle; }
    .header-left p  { font-size: 11px; color: rgba(255,255,255,.75); display: inline; margin-left: 8px; }
    .header-right   { display: flex; align-items: center; gap: 8px; }
    #user-name      { font-size: 11px; color: rgba(255,255,255,.85); }
    .btn-link {
      background: none;
      border: 1px solid rgba(255,255,255,.35);
      color: rgba(255,255,255,.9);
      border-radius: 5px;
      padding: 3px 10px;
      font-size: 11px;
      font-family: inherit;
      cursor: pointer;
      text-decoration: none;
      transition: border-color .2s, background .2s;
    }
    .btn-link:hover { border-color: #fff; background: rgba(255,255,255,.1); }

    /* FILTER BAR */
    .filter-bar {
      background: var(--bg-card);
      border-bottom: 1px solid var(--border);
      padding: 5px 14px;
      display: flex;
      align-items: center;
      gap: 12px;
      flex-wrap: wrap;
      flex: none;
    }
    .filter-group { display: flex; align-items: center; gap: 6px; }
    .filter-label { font-size: 10px; color: var(--text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: .3px; }
    select.filter-select {
      background: #fff;
      border: 1px solid #cfd4da;
      color: var(--text);
      border-radius: 6px;
      padding: 3px 8px;
      font-size: 12px;
      font-family: inherit;
      cursor: pointer;
    }
    select.filter-select:focus { outline: none; border-color: var(--accent); }
    .btn-refresh {
      background: var(--accent);
      border: none;
      color: #fff;
      border-radius: 6px;
      padding: 4px 12px;
      font-size: 12px;
      font-weight: 700;
      font-family: inherit;
      cursor: pointer;
      transition: opacity .15s;
    }
    .btn-refresh:hover { opacity: .85; }
    .status-dot {
      width: 8px; height: 8px; border-radius: 50%;
      background: #cbd5e1;
      flex-shrink: 0;
    }
    .status-dot.ok      { background: var(--green); }
    .status-dot.error   { background: var(--red); }
    .status-dot.loading { background: var(--accent); animation: pulse 1s infinite; }
    @keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }
    #last-refresh { font-size: 11px; color: var(--text-muted); }

    /* PAGES – chiếm hết phần còn lại của màn hình */
    .page { display: none; flex: 1; min-height: 0; }
    .page.active { display: block; }
    .grid-wrap { height: 100%; padding: 8px 12px; overflow-y: auto; }

    /* GRID: gap 1px làm đường kẻ mảnh giữa các ô */
    .grid {
      display: grid;
      gap: 1px;
      background: var(--border);
      border: 1px solid var(--border);
      border-radius: 8px;
      overflow: hidden;
      /* Vừa đúng một màn hình: các hàng CHIA ĐỀU phần cao còn lại (1fr).
         Nhưng màn thấp (laptop 768px, hay 1080p đặt scale 150% chỉ còn 720px
         CSS) mà vẫn ép 5–7 hàng vào thì mỗi chart chỉ cao 50–80px, số/chú
         thích/cột đè lên nhau. Nên mỗi hàng có sàn `--row-min`: màn lớn sàn =
         0 (giữ nguyên như cũ), màn nhỏ sàn > 0 → lưới cao hơn khung và
         `.grid-wrap` cuộn dọc. `min-height` (không phải `height`) để lưới
         vẫn lấp đầy khung khi còn dư chỗ. */
      min-height: var(--grid-fill, 100%);   /* trang phụ ít hàng: chỉ lấp phần tương ứng — xem buildSubRows */
      grid-auto-rows: minmax(var(--row-min), 1fr);
    }
    .grid.cols-4  { grid-template-columns: 108px 1fr 1.25fr 2.1fr; }
    .grid.cols-2  { grid-template-columns: 108px 1fr; }
    /* Trang Manufacturer (01c): 2 chart trên (cả năm | quý), chart tháng rộng cả hàng dưới */
    .mfr-grid { display: grid; gap: 1px; background: var(--border); border: 1px solid var(--border);
                border-radius: 8px; overflow: hidden; min-height: 100%;
                grid-template-columns: 1fr 1.5fr; grid-template-rows: minmax(var(--row-min), 1fr) minmax(var(--row-min), 1.15fr); }
    .mfr-cell { background: var(--bg-card); padding: 6px 10px; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
    .mfr-cell > .cell { flex: 1; min-height: 0; }
    .mfr-wide { grid-column: 1 / -1; }
    .section-row { display: contents; }
    .section-row > div {
      background: var(--bg-card);
      padding: 6px 10px;
      min-height: 0;
      min-width: 0;
    }

    /* Nhãn hàng (kênh / hãng) – chữ đậm tối như PowerBI */
    .row-label {
      display: flex;
      flex-direction: column;
      justify-content: flex-start;
      padding-top: 4px;
      font-size: 12.5px;
      font-weight: 800;
      color: #111827;
      letter-spacing: .2px;
      line-height: 1.35;
      height: 100%;
    }
    .row-label .sub { font-weight: 600; font-style: italic; font-size: 10px; color: var(--text-muted); }
    /* Dự báo cuối năm dưới nhãn kênh (trang 01a, chỉ FY đang diễn ra) */
    .row-label .fc { margin-top: 7px; font-size: 10px; font-weight: 600;
      color: var(--text-muted); line-height: 1.45; cursor: help; }
    .row-label .fc b.good { color: #15803d; }
    .row-label .fc b.mid  { color: #b45309; }
    .row-label .fc b.low  { color: #dc2626; }

    /* Ô chart: tiêu đề nhỏ + chart lấp phần còn lại */
    .cell { height: 100%; display: flex; flex-direction: column; min-height: 0; position: relative; }
    .cell-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 4px; flex: none; }
    .cell-title { font-size: 11.5px; font-weight: 700; color: #111827; }
    .cell-sub   { font-size: 9px; color: #9ca3af; flex: none; margin-bottom: 1px; }
    .chart-wrap { position: relative; flex: 1; min-height: 0; }
    /* Skeleton: khung xám nhấp nháy phủ lên chart khi trang tải dữ liệu LẦN ĐẦU
       (đổi FY / làm mới nền vẫn giữ số cũ trên màn hình, không nháy skeleton) */
    .page.skel .chart-wrap::after {
      content: ''; position: absolute; inset: 2px; border-radius: 8px; z-index: 5;
      background: linear-gradient(100deg, #eceff3 30%, #f8f9fb 45%, #eceff3 60%);
      background-size: 300% 100%;
      animation: skel-sheen 1.1s linear infinite;
    }
    @keyframes skel-sheen { from { background-position: 100% 0 } to { background-position: -100% 0 } }
    /* Toolbar mini trên góc phải mỗi ô chart (hiện khi hover) */
    .cell-tools { display: flex; gap: 2px; opacity: 0; transition: opacity .12s; flex: none; }
    .cell:hover .cell-tools { opacity: 1; }
    .cell-tools button {
      border: 1px solid var(--border); background: #fff; color: var(--text-muted);
      border-radius: 4px; width: 18px; height: 18px; line-height: 1; font-size: 11px;
      cursor: pointer; padding: 0; display: flex; align-items: center; justify-content: center;
    }
    .cell-tools button:hover { color: var(--accent); border-color: var(--accent); }
    /* Bảng "show as table" chèn trong ô chart */
    .cell-table { position: absolute; inset: 0; background: #fff; overflow: auto; display: none; }
    .cell-table.show { display: block; }
    .cell-table table { border-collapse: collapse; width: 100%; font-size: 10px; }
    .cell-table th, .cell-table td { padding: 2px 6px; border-bottom: 1px solid #eef0f2; text-align: right; white-space: nowrap; }
    .cell-table th:first-child, .cell-table td:first-child { text-align: left; }
    .cell-table thead th { position: sticky; top: 0; background: #fff; font-weight: 700; color: #111827; }
    .tbl-bar { display: flex; justify-content: flex-end; padding: 2px; background: #fff; border-bottom: 1px solid #eef0f2; }
    .tbl-bar button { font-size: 10px; padding: 1px 8px; border: 1px solid var(--border); border-radius: 4px; background: #fff; color: var(--text-muted); cursor: pointer; }
    .tbl-bar button:hover { color: var(--accent); border-color: var(--accent); }
    .quick-panel { display: none; position: absolute; top: 110%; right: 0; z-index: 40; min-width: 190px; max-height: 320px; overflow: auto; background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.14); padding: 6px; }
    .quick-panel.show { display: block; }
    .quick-panel label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text); padding: 3px 6px; border-radius: 5px; white-space: nowrap; cursor: pointer; }
    .quick-panel label:hover { background: #f3f4f6; }
    .quick-panel .qp-actions { display: flex; gap: 4px; padding: 2px 4px 6px; border-bottom: 1px solid #eef0f2; margin-bottom: 4px; }
    .quick-panel .qp-actions button { flex: 1; font-size: 11px; padding: 2px 4px; border: 1px solid var(--border); border-radius: 5px; background: #fff; color: var(--text-muted); cursor: pointer; }
    .quick-panel .qp-actions button:hover { color: var(--accent); border-color: var(--accent); }

    /* Chỉ báo cross-filter (bấm 1 cột → lọc các chart khác cùng trang) */
    .xfilter-bar {
      display: none; position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
      z-index: 30; background: #1f2937; color: #fff; border-radius: 20px;
      padding: 5px 8px 5px 14px; font-size: 12px; align-items: center; gap: 8px;
      box-shadow: 0 3px 12px rgba(0,0,0,.22);
    }
    .xfilter-bar.show { display: flex; }
    .xfilter-bar b { font-weight: 700; }
    .xfilter-bar button {
      border: none; background: rgba(255,255,255,.2); color: #fff; cursor: pointer;
      border-radius: 50%; width: 18px; height: 18px; font-size: 12px; line-height: 1; padding: 0;
    }
    .xfilter-bar button:hover { background: rgba(255,255,255,.35); }

    /* TRANG CANVAS: lưới 12 cột, mỗi ô chart đặt theo x/y/w/h */
    .canvas-grid {
      display: grid;
      grid-template-columns: repeat(12, 1fr);
      grid-auto-rows: 86px;
      gap: 8px;
      padding: 2px;
      min-height: 100%;
    }
    .canvas-tile {
      background: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 6px 10px;
      min-width: 0;
      min-height: 0;
    }

    /* ══ CHẾ ĐỘ SỬA TRỰC TIẾP TRÊN DASHBOARD (kiểu Power BI) ══ */
    .edit-bar {
      display: none; background: #fff7ed; border-bottom: 1px solid #fed7aa;
      padding: 6px 14px; align-items: center; gap: 10px; flex: none;
    }
    body.editing .edit-bar { display: flex; }
    .edit-bar .sp { flex: 1 }
    .edit-bar .warn { font-size: 11.5px; color: #9a3412; }
    /* Tab dấu + để thêm trang (chỉ hiện khi đang sửa) */
    .page-tab.add-tab { display: none; font-weight: 700; color: var(--accent); }
    .tab-x {
      display: none; margin-left: 7px; border: none; background: none; cursor: pointer;
      color: var(--red); font-size: 12px; line-height: 1; padding: 0 2px; border-radius: 3px;
    }
    body.editing .page-tab.custom .tab-x { display: inline; }
    .tab-x:hover { background: #fee2e2; }
    .edit-bar .dirty { color: var(--red); font-weight: 700; font-size: 11.5px; }
    body.editing .page-tab.add-tab { display: inline-block; }
    /* Ô chart khi đang sửa: viền nét đứt + nút công cụ luôn hiện */
    body.editing .canvas-tile { border: 1px dashed var(--accent); }
    body.editing .cell-tools { opacity: 1; }
    .tile-edit-btn {
      position: absolute; top: 2px; right: 2px; z-index: 5; display: none;
      background: var(--accent); color: #fff; border: none; border-radius: 5px;
      font-size: 10.5px; padding: 2px 7px; cursor: pointer; font-family: inherit;
    }
    body.editing .tile-edit-btn { display: block; }
    /* Gridstack trong dashboard */
    .grid-stack { background: transparent; }
    .grid-stack-item-content {
      background: var(--bg-card); border: 1px solid var(--border);
      border-radius: 8px; padding: 6px 10px; overflow: hidden;
      display: flex; flex-direction: column;
    }

    /* ══ EDITOR 3 PANEL trên dashboard ══ */
    #ed-modal { display:none; position:fixed; inset:0; background:rgba(15,23,42,.6); z-index:400; align-items:center; justify-content:center; }
    #ed-modal.show { display:flex; }
    #ed-box { background:#fff; border-radius:12px; width:96vw; height:94vh; display:flex; flex-direction:column; padding:14px 16px; }
    #ed-head { display:flex; align-items:center; justify-content:space-between; gap:10px; flex:none; margin-bottom:10px; }
    #ed-body { flex:1; min-height:0; display:grid; grid-template-columns:220px 1fr 260px 235px; gap:10px; }
    .ed-pane { border:1px solid var(--border); border-radius:10px; display:flex; flex-direction:column; min-height:0; overflow:hidden; }
    .ed-pane > h4 { font-size:12px; font-weight:700; padding:9px 11px; background:#f8f9fa; border-bottom:1px solid var(--border); display:flex; gap:12px; }
    .ed-tab { cursor:pointer; color:var(--text-muted); font-weight:600; }
    .ed-tab.sel { color:var(--accent); border-bottom:2px solid var(--accent); }
    .fmt-row { display:flex; align-items:center; justify-content:space-between; gap:8px; padding:6px 0; border-bottom:1px solid #f1f3f5; font-size:11.5px; }
    .fmt-row select, .fmt-row input[type=number] { width:96px; padding:3px 6px; font-size:11.5px; border:1px solid #cfd4da; border-radius:6px; font-family:inherit; }
    .fmt-sec { font-size:11px; font-weight:700; color:#111827; text-transform:uppercase; letter-spacing:.3px; margin:12px 0 4px; }
    .sw { display:flex; gap:4px; flex-wrap:wrap; }
    .sw i { width:16px; height:16px; border-radius:4px; cursor:pointer; display:inline-block; border:1px solid rgba(0,0,0,.15); }
    .ed-pane > .body { flex:1; overflow:auto; padding:9px 11px; }
    .ed-tblgroup { font-size:11.5px; font-weight:700; color:#111827; margin:8px 0 4px; cursor:pointer; }
    .ed-fld { display:flex; align-items:center; gap:6px; padding:4px 7px; border-radius:6px; font-size:11.5px; cursor:grab; border:1px solid transparent; }
    .ed-fld:hover { background:#f3f4f6; border-color:var(--border); }
    .ed-fld .ic { font-size:10px; width:14px; text-align:center; color:var(--text-muted); }
    .ed-fld.measure .ic { color:#b45309; }
    .ed-well { border:1px dashed #cfd4da; border-radius:8px; min-height:38px; padding:6px; margin-bottom:10px; background:#fafbfc; }
    .ed-well.over { border-color:var(--accent); background:#fff7ed; }
    .ed-well-label { font-size:10.5px; color:var(--text-muted); font-weight:700; text-transform:uppercase; margin-bottom:5px; }
    .ed-chip { display:inline-flex; align-items:center; gap:5px; background:#eef2ff; border:1px solid #c7d2fe; color:#3730a3; border-radius:6px; padding:3px 7px; font-size:11px; margin:2px; flex-wrap:wrap; }
    .ed-chip button { border:none; background:none; cursor:pointer; color:#3730a3; font-size:12px; padding:0; }
    .ed-chip select, .ed-chip input { border:1px solid #c7d2fe; background:#fff; font-size:10.5px; font-family:inherit; padding:1px 4px; border-radius:4px; }
    .ed-types { display:grid; grid-template-columns:repeat(3,1fr); gap:6px; }
    .ed-type { border:1px solid var(--border); border-radius:8px; padding:7px 3px; text-align:center; cursor:pointer; font-size:9.5px; color:var(--text-muted); background:#fff; }
    .ed-type .big { font-size:15px; display:block; }
    .ed-type.sel { border-color:var(--accent); background:#fff7ed; color:#9a3412; font-weight:700; }
    #ed-preview { flex:1; min-height:0; position:relative; padding:8px; }
    /* Modal chọn định dạng export */
    #exp-modal { display:none; position:fixed; inset:0; background:rgba(15,23,42,.55); z-index:460; align-items:center; justify-content:center; }
    #exp-modal.show { display:flex; }
    #exp-box { background:#fff; border-radius:12px; width:420px; padding:20px; }
    .exp-opt {
      display:block; width:100%; text-align:left; border:1px solid var(--border); background:#fff;
      border-radius:9px; padding:11px 13px; margin-bottom:9px; cursor:pointer; font-family:inherit;
    }
    .exp-opt:hover { border-color:var(--accent); background:#fff7ed; }
    .exp-opt b { display:block; font-size:12.5px; color:var(--text); }
    .exp-opt span { display:block; font-size:11px; color:var(--text-muted); margin-top:2px; }

    /* Modal chọn giá trị lọc (nổi trên editor) */
    #val-modal { display:none; position:fixed; inset:0; background:rgba(15,23,42,.55); z-index:450; align-items:center; justify-content:center; }
    #val-modal.show { display:flex; }
    #val-box { background:#fff; border-radius:12px; width:420px; max-height:74vh; display:flex; flex-direction:column; padding:18px; }
    #val-list { flex:1; overflow:auto; margin:10px 0; border:1px solid var(--border); border-radius:8px; padding:8px; }
    #val-list label { display:flex; align-items:center; gap:7px; padding:3px 4px; font-size:12px; cursor:pointer; }

    /* Nhãn hàng có drill-through (bấm để sang trang chi tiết) */
    .row-label.drill { cursor: pointer; }
    .row-label.drill:hover { color: var(--accent); text-decoration: underline; }

    /* MODAL FOCUS – phóng to 1 chart */
    #focus-modal {
      display: none; position: fixed; inset: 0; z-index: 500;
      background: rgba(15,23,42,.55); align-items: center; justify-content: center;
    }
    #focus-modal.show { display: flex; }
    #focus-box {
      background: #fff; border-radius: 12px; width: 86vw; height: 84vh;
      display: flex; flex-direction: column; padding: 16px 18px; box-shadow: 0 12px 48px rgba(0,0,0,.3);
    }
    #focus-head { display: flex; align-items: center; justify-content: space-between; flex: none; margin-bottom: 8px; }
    #focus-title { font-size: 14px; font-weight: 700; color: #111827; }
    #focus-actions { display: flex; gap: 8px; }
    #focus-actions button {
      border: 1px solid var(--border); background: #fff; color: var(--text); border-radius: 7px;
      padding: 5px 12px; font-size: 12px; font-family: inherit; cursor: pointer;
    }
    #focus-actions button:hover { border-color: var(--accent); color: var(--accent); }
    #focus-canvas-wrap { flex: 1; min-height: 0; position: relative; }

    /* Nút phẳng cho filter bar (nền sáng) */
    .btn-flat {
      background: #fff; border: 1px solid #cfd4da; color: var(--text);
      border-radius: 6px; padding: 4px 12px; font-size: 12px; font-family: inherit; cursor: pointer;
    }
    .btn-flat:hover { border-color: var(--accent); color: var(--accent); }

    /* BẢNG VOLUME (trang 03x) – kiểu ma trận PowerBI */
    .vol-wrap {
      height: 100%;
      overflow: auto;
      background: #fff;
      border: 1px solid var(--border);
      border-radius: 8px;
    }
    table.vol { border-collapse: collapse; min-width: 100%; font-size: var(--tbl-fs, 10.5px); }
    .vol th, .vol td { padding: .2em .6em; border-bottom: 1px solid #eef0f2; white-space: nowrap; }
    .vol thead th { position: sticky; background: #fff; z-index: 6; }
    .vol thead tr:nth-child(1) th { top: 0; font-weight: 700; color: #111827; text-align: center; border-bottom: none; }
    .vol thead tr:nth-child(2) th { top: 1.75em; font-size: .86em; color: #9ca3af; font-weight: 600; text-align: right; }
    .vol td.name, .vol th.name {
      text-align: left;
      position: sticky;
      left: 0;
      z-index: 4;
      background: #fff;
      max-width: 260px;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .vol thead th.name { z-index: 8; }
    .vol td.prev { color: #9ca3af; text-align: right; }
    .vol td.cur  { font-weight: 700; color: #111827; text-align: right; }
    .vol .arrow.up   { color: var(--green); font-size: .78em; }
    .vol .arrow.down { color: var(--red);   font-size: .78em; }
    .vol tr.grp td { background: var(--strip-bg); color: #fff; font-weight: 700; }
    .vol tr.grp td.name { background: var(--strip-bg); }
    .vol tr.grp td.prev { color: rgba(255,255,255,.75); font-weight: 600; }
    .vol tr.grp .arrow.up   { color: #86efac; }
    .vol tr.grp .arrow.down { color: #fecaca; }
    .vol tbody tr:nth-child(even):not(.grp) td { background: #f8f9fa; }
    .vol tbody tr:nth-child(even):not(.grp) td.name { background: #f8f9fa; }

    /* TRANG CỬA HÀNG (04x): hàng chart trên + lưới bảng mini dưới */
    .store-layout { min-height: 100%; height: 100%; display: flex; flex-direction: column; gap: 8px; }
    .store-header-grid { flex: none; height: 190px; min-height: 0; }
    .store-tables {
      flex: 1;
      min-height: 0;
      display: grid;
      /* Cột TRÁI: doanh số theo hãng (trên) + số lượng theo hãng (dưới).
         Cột PHẢI: Top SKU trải hết chiều cao (bảng nhiều dòng nhất).
         Cả 3 bảng đều 12 cột số nên chia đôi bề ngang; đặt vị trí TƯỜNG MINH
         để không phụ thuộc thứ tự tự động của grid. */
      grid-template-columns: 1fr 1fr;
      grid-template-rows: 1fr 1fr;
      gap: 8px;
    }
    .mini-wrap.pos-a    { grid-column: 1; grid-row: 1; }
    .mini-wrap.pos-b    { grid-column: 1; grid-row: 2; }
    .mini-wrap.span-all { grid-column: 2; grid-row: 1 / -1; }
    .mini-wrap {
      background: #fff;
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 6px 8px;
      display: flex;
      flex-direction: column;
      min-height: 0;
      min-width: 0;
    }
    .mini-scroll { flex: 1; overflow: auto; min-height: 0; }
    table.mini { border-collapse: collapse; width: 100%; font-size: var(--tbl-fs, 10px); }
    .mini th, .mini td { padding: .18em .5em; border-bottom: 1px solid #eef0f2; text-align: right; white-space: nowrap; }
    .mini th:first-child, .mini td:first-child {
      text-align: left;
      max-width: 150px;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .mini thead th { position: sticky; top: 0; background: #f0f2f4; font-weight: 700;
      color: #111827; z-index: 2; border-bottom: 1px solid #dfe3e7; }
    .mini td.prev, .mini th.prev { color: #9ca3af; font-weight: 500; }
    /* Bảng gộp Năm + Quý: vạch ĐẬM tách khối năm với khối quý, vạch nhạt
       tách từng quý — không có vạch thì 11 cột số dính vào nhau, đọc lạc dòng. */
    .mini th.sep-major, .mini td.sep-major { border-left: 2px solid #9aa3ad; }
    .mini th.sep-minor, .mini td.sep-minor { border-left: 1px solid #dfe3e7; }
    .mini thead th.fq { text-align: center; }
    /* Chú thích màu highlight — đặt cuối trang, chỉ giải nghĩa 2 màu chứ không
       nhồi lại toàn bộ quy tắc (người dùng đã yêu cầu bỏ khối ghi chú dài). */
    .hl-note { display:flex; gap:18px; align-items:center; flex-wrap:wrap;
      font-size:10.5px; color:#6b7280; padding:6px 2px 0; flex:none; }
    .hl-note i { display:inline-block; width:11px; height:11px; border-radius:3px;
      margin-right:5px; vertical-align:-1px; }
    .cell-unit { font-size: 9.5px; color: #9ca3af; font-weight: 400; margin-left: 5px; }
    /* Đỏ = quý ĐANG chạy thấp hơn cùng kỳ năm ngoái; Vàng = quý TRƯỚC thấp hơn.
       Chỉ tô nhạt cả dòng + đậm ô tên để vẫn đọc được số. */
    .mini tbody td.q-red { background: #fee2e2; }
    .mini tbody td.q-amb { background: #fef3c7; }

    /* TOAST THÔNG BÁO */
    #toast {
      display: none;
      position: fixed;
      top: 14px;
      left: 50%;
      transform: translateX(-50%);
      z-index: 400;
      background: #1f2937;
      color: #fff;
      font-size: 12.5px;
      padding: 9px 18px;
      border-radius: 8px;
      box-shadow: 0 4px 16px rgba(0,0,0,.25);
      max-width: 80vw;
    }

    /* PROGRESS BUILD SNAPSHOT */
    #build-progress {
      display: none;
      position: fixed;
      bottom: 46px;
      right: 12px;
      z-index: 300;
      background: #fff;
      border: 1px solid var(--border);
      border-radius: 10px;
      padding: 10px 14px;
      box-shadow: 0 4px 16px rgba(0,0,0,.12);
      min-width: 260px;
      flex-direction: column;
      gap: 6px;
    }
    #bp-text  { font-size: 11.5px; color: var(--text); font-weight: 600; }
    #bp-sub   { font-size: 10.5px; color: var(--text-muted); }
    .bp-bar {
      height: 6px;
      background: #e5e7eb;
      border-radius: 4px;
      overflow: hidden;
    }
    .bp-fill {
      height: 100%;
      width: 0%;
      background: var(--accent);
      border-radius: 4px;
      transition: width .8s ease;
    }

    /* NÚT HIỆN LẠI HEADER (khi đang toàn màn hình) */
    #btn-show-chrome {
      display: none;
      position: fixed;
      top: 6px; right: 6px;
      z-index: 200;
      background: rgba(255,255,255,.92);
      border: 1px solid #cfd4da;
      color: var(--text-muted);
      border-radius: 6px;
      padding: 3px 9px;
      font-size: 11px;
      font-family: inherit;
      cursor: pointer;
      box-shadow: 0 1px 4px rgba(0,0,0,.12);
    }
    #btn-show-chrome:hover { color: var(--accent); border-color: var(--accent); }

    /* PAGE TABS (kiểu PowerBI, dưới đáy) */
    .page-tabs {
      background: #f3f4f6;
      border-top: 1px solid var(--border);
      display: flex;
      align-items: stretch;
      gap: 0;
      padding: 0 8px 0 0;
      flex: none;
    }
    #tab-search {
      flex: none;
      width: 150px;
      align-self: stretch;          /* cao bằng hàng tab */
      margin: 0;
      padding: 0 12px;
      font-size: 12px;
      font-family: inherit;
      border: none;                  /* flat */
      border-right: 1px solid var(--border);
      border-top: 2px solid transparent;
      border-radius: 0;
      background: transparent;
      color: var(--text);
    }
    #tab-search::placeholder { color: var(--text-muted); }
    #tab-search:focus { outline: none; background: #fff; border-top-color: var(--accent); }
    .tabs-scroll {
      flex: 1;
      min-width: 0;
      display: flex;
      gap: 1px;
      overflow-x: auto;
    }
    .page-tab {
      padding: 7px 16px;
      font-size: 12px;
      color: var(--text-muted);
      background: none;
      border: none;
      border-top: 2px solid transparent;
      font-family: inherit;
      cursor: pointer;
      white-space: nowrap;
      transition: color .15s;
    }
    .page-tab:hover  { color: var(--text); }
    .page-tab.active { color: var(--text); border-top-color: var(--accent); background: #fff; font-weight: 700; }

    /* TỪ ĐIỂN SỐ LIỆU */
    #dict-modal { display:none; position:fixed; inset:0; z-index:520;
      background:rgba(15,23,42,.55); align-items:center; justify-content:center; }
    #dict-modal.show { display:flex; }
    #dict-body dt { font-weight:800; color:#111827; margin-top:10px; }
    #dict-body dd { margin:2px 0 0 0; color:#475569; }

    /* PHÂN TÍCH NÂNG CAO */
    #ins-modal { display:none; position:fixed; inset:0; z-index:510;
      background:rgba(15,23,42,.6); align-items:center; justify-content:center; }
    #ins-modal.show { display:flex; }
    .ins-tbl { width:100%; border-collapse:collapse; font-size:11.5px; }
    .ins-tbl th { text-align:left; color:var(--text-muted); font-size:10px;
      text-transform:uppercase; padding:3px 8px; }
    .ins-tbl td { padding:3px 8px; border-top:1px solid #f1f5f9; }
    .ins-tbl td.num { text-align:right; font-weight:700; }

    /* EXECUTIVE SUMMARY */
    #exec-modal { display:none; position:fixed; inset:0; z-index:510;
      background:rgba(15,23,42,.6); align-items:center; justify-content:center; }
    #exec-modal.show { display:flex; }
    #exec-box { background:#f7f8fa; border-radius:14px; width:min(1180px,96vw);
      max-height:90vh; overflow-y:auto; padding:18px 22px; }
    #exec-head { display:flex; align-items:center; gap:12px; margin-bottom:14px; }
    #exec-head span:first-child { font-size:17px; font-weight:800; color:#111827; }
    #exec-sub { font-size:11px; color:var(--text-muted); flex:1; }
    #exec-head button { border:1px solid var(--border); background:#fff; border-radius:7px;
      padding:5px 12px; font-size:12px; cursor:pointer; font-family:inherit; }
    #exec-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(320px,1fr)); gap:12px; }
    .exec-card { background:#fff; border:1px solid var(--border); border-radius:12px; padding:14px 16px; }
    .exec-card h3 { font-size:13px; font-weight:800; color:#111827; margin-bottom:8px; }
    .exec-big { font-size:26px; font-weight:800; color:#111827; }
    .exec-big small { font-size:12px; color:var(--text-muted); font-weight:600; }
    .exec-row { display:flex; justify-content:space-between; font-size:12px; color:#374151; margin-top:4px; }
    .exec-bar { height:7px; background:#eef0f3; border-radius:4px; margin:8px 0 4px; overflow:hidden; }
    .exec-bar i { display:block; height:100%; border-radius:4px; }
    .exec-yoy.up { color:#15803d; font-weight:700; } .exec-yoy.down { color:#dc2626; font-weight:700; }

    /* MENU ⚙ trên header */
    #hmenu { display:none; position:absolute; right:0; top:110%; z-index:600;
      background:#fff; border:1px solid var(--border); border-radius:10px;
      box-shadow:0 10px 32px rgba(0,0,0,.22); min-width:230px; padding:6px; }
    #hmenu.show { display:block; }
    #hmenu button { display:block; width:100%; text-align:left; border:none;
      background:none; padding:8px 12px; font-size:12.5px; font-family:inherit;
      color:var(--text); border-radius:7px; cursor:pointer; }
    #hmenu button:hover { background:#f3f4f6; }
    .hm-sep { height:1px; background:#eef0f2; margin:5px 4px; }
    /* các mục chỉ dùng khi thu gọn header trên mobile (scope #hmenu để thắng
       specificity của #hmenu button) */
    #hmenu .hm-mobile { display:none; }
    /* Switcher chuyển dashboard (Sales / Trade / …) trên header */
    #dash-switch-wrap .btn-link { font-weight:700; }
    #dash-menu { display:none; position:absolute; left:0; top:112%; z-index:600;
      background:#fff; border:1px solid var(--border); border-radius:10px;
      box-shadow:0 10px 32px rgba(0,0,0,.22); min-width:170px; padding:6px; }
    #dash-menu.show { display:block; }
    #dash-menu button { display:block; width:100%; text-align:left; border:none;
      background:none; padding:9px 13px; font-size:13px; font-family:inherit;
      color:var(--text); border-radius:7px; cursor:pointer; white-space:nowrap; }
    #dash-menu button:hover { background:#f3f4f6; }

    /* NLQ – hỏi đáp dữ liệu */
    /* Công tắc ở Cấu hình → Trang & thiết kế (xem /api/ui/features) */
    body.no-exec [onclick*="execOpen"], body.no-exec #exec-modal,
    body.no-ins  [onclick*="insOpen"],  body.no-ins  #ins-modal,
    body.no-ai #nlq-fab, body.no-ai #nlq-panel,
    body.no-ai [onclick*="nlqFabToggle"] { display: none !important; }
    #nlq-fab { position: fixed; right: 18px; bottom: 52px; z-index: 210;
      width: 44px; height: 44px; border-radius: 50%; border: none; cursor: pointer;
      background: var(--accent); color: #fff; font-size: 20px;
      box-shadow: 0 6px 20px rgba(0,0,0,.25); }
    #nlq-panel { display: none; position: fixed; right: 18px; bottom: 104px; z-index: 210;
      width: min(430px, 94vw); max-height: 62vh; background: #fff; border-radius: 14px;
      box-shadow: 0 16px 48px rgba(0,0,0,.3); border: 1px solid var(--border);
      flex-direction: column; overflow: hidden; }
    #nlq-panel.show { display: flex; }
    #nlq-head { display: flex; justify-content: space-between; align-items: center;
      padding: 10px 14px; font-weight: 800; font-size: 13px; border-bottom: 1px solid var(--border); }
    #nlq-head button { border: none; background: none; cursor: pointer; color: var(--text-muted); }
    #nlq-out { flex: 1; overflow-y: auto; padding: 10px 14px; font-size: 12.5px; }
    .nlq-tip { color: var(--text-muted); font-size: 12px; }
    .nlq-q { font-weight: 700; margin: 8px 0 2px; }
    .nlq-a { color: var(--text-muted); margin-bottom: 6px; }
    .nlq-err { color: var(--red); margin: 6px 0; }
    #nlq-out table { border-collapse: collapse; width: 100%; font-size: 11.5px; margin: 4px 0 10px; }
    #nlq-out th, #nlq-out td { border-bottom: 1px solid #eef0f2; padding: 3px 8px; text-align: right; }
    #nlq-out th:first-child, #nlq-out td:first-child { text-align: left; }
    #nlq-inbar { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--border); }
    #nlq-inbar input { flex: 1; border: 1px solid var(--border); border-radius: 8px;
      padding: 8px 11px; font-size: 13px; font-family: inherit; }
    #nlq-inbar button { border: none; background: var(--accent); color: #fff;
      border-radius: 8px; padding: 0 14px; font-size: 15px; cursor: pointer; }

    /* COMMAND PALETTE – Ctrl+K */
    #pal-modal { display: none; position: fixed; inset: 0; z-index: 520;
      background: rgba(15,23,42,.45); justify-content: center; }
    #pal-modal.show { display: flex; }
    #pal-box { margin-top: 12vh; width: min(520px, 92vw); height: fit-content;
      background: #fff; border-radius: 12px; box-shadow: 0 16px 48px rgba(0,0,0,.35); overflow: hidden; }
    #pal-input { width: 100%; border: none; outline: none; padding: 14px 16px;
      font-size: 15px; font-family: inherit; border-bottom: 1px solid var(--border); }
    #pal-list { max-height: 46vh; overflow-y: auto; padding: 6px; }
    .pal-item { display: flex; justify-content: space-between; align-items: center;
      padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 13px; }
    .pal-item b { font-weight: 700; color: #111827; }
    .pal-item span { font-size: 11px; color: var(--text-muted); }
    .pal-item:hover, .pal-item.sel { background: #eef2ff; }
    .pal-empty { padding: 14px; font-size: 12px; color: var(--text-muted); text-align: center; }

    /* MODAL DRILL-DOWN – tháng → tuần → ngày */
    #drill-modal {
      display: none; position: fixed; inset: 0; z-index: 500;
      background: rgba(15,23,42,.55); align-items: center; justify-content: center;
    }
    #drill-modal.show { display: flex; }
    #drill-box {
      background: #fff; border-radius: 12px; width: 78vw; height: 66vh;
      display: flex; flex-direction: column; padding: 16px 18px;
      box-shadow: 0 12px 48px rgba(0,0,0,.3);
    }
    #drill-head { display: flex; align-items: center; justify-content: space-between; flex: none; }
    #drill-title { font-size: 14px; font-weight: 700; color: #111827; }
    .drill-actions { display: flex; gap: 8px; }
    .drill-actions button {
      border: 1px solid var(--border); background: #fff; color: var(--text); border-radius: 7px;
      padding: 5px 12px; font-size: 12px; font-family: inherit; cursor: pointer;
    }
    .drill-actions button:hover { border-color: var(--accent); color: var(--accent); }
    #drill-hint { font-size: 11px; color: var(--text-muted); flex: none; margin: 2px 0 8px; }
    #drill-notes { flex: none; margin-bottom: 8px; }
    .dn-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #111827;
      background: #fffbeb; border: 1px solid #fde68a; border-radius: 7px; padding: 4px 9px; margin-bottom: 4px; }
    .dn-item span { color: var(--text-muted); font-size: 11px; }
    .dn-item button { margin-left: auto; border: none; background: none; color: #9ca3af; cursor: pointer; }
    .dn-item button:hover { color: var(--red); }
    .dn-add { display: flex; gap: 6px; }
    .dn-add input { flex: 1; border: 1px solid var(--border); border-radius: 7px;
      padding: 5px 10px; font-size: 12px; font-family: inherit; }
    .dn-add button { border: 1px solid var(--border); background: #fff; border-radius: 7px;
      padding: 5px 12px; font-size: 12px; font-family: inherit; cursor: pointer; }
    .dn-add button:hover { border-color: var(--accent); color: var(--accent); }
    #drill-canvas-wrap { flex: 1; min-height: 0; position: relative; }
    @media (max-width: 820px) { #drill-box { width: 96vw; height: 80vh; } }

    /* ── MÀN NHỎ / SCALE LỚN (laptop 1366×768, 1080p đặt 125–150%) ──
       Windows scale 150% trên 1920×1080 → trình duyệt chỉ còn 1280×720 CSS px.
       Không ép vừa màn hình nữa mà cho mỗi hàng chart một sàn chiều cao rồi
       cuộn; header không được xuống dòng (nút "Đăng xuất" từng vỡ 2 dòng). */
    @media (max-height: 860px), (max-width: 1300px) {
      :root { --row-min: 168px; }
      .store-layout { height: auto; }
      .store-tables { flex: none; height: 560px; }
    }
    @media (max-width: 1300px) {
      .header { gap: 10px; }
      .header-left { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; }
      .header-left h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
      .header-left p { display: none; }
      #logo { flex: none; }
      .header-right { flex: none; gap: 6px; }
      #user-name { display: none; }
      .filter-bar { gap: 8px; }
    }
    .btn-link { white-space: nowrap; }

    /* ── MOBILE / TABLET (≤ 820px): xếp dọc 1 cột, mỗi chart cao cố định,
       cuộn cả trang thay vì ép vừa màn hình như desktop ── */
    @media (max-width: 820px) {
      .grid { height: auto; min-height: 0; grid-auto-rows: auto; }
      .grid.cols-4, .grid.cols-2 { grid-template-columns: 1fr; }
      .mfr-grid { grid-template-columns: 1fr; grid-template-rows: none; min-height: 0; }
      .mfr-cell { height: 300px; }
      /* Nhãn kênh/khách hàng thành tiêu đề của nhóm chart bên dưới */
      .row-label { height: auto; padding: 4px 0 0; flex-direction: row;
                   align-items: baseline; gap: 8px; font-size: 13.5px; }
      .cell { height: auto; }
      .chart-wrap { flex: none; height: 205px; }

      /* HEADER gọn 1 hàng: logo + tiêu đề 1 dòng (cắt bớt) + nút ☰ Menu */
      .header { padding: 7px 10px; gap: 8px; }
      .header-left { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; }
      .header-left h1 { display: block; font-size: 13px; white-space: nowrap;
                        overflow: hidden; text-overflow: ellipsis; }
      .header-left p { display: none; }          /* ẩn subtitle cho gọn */
      #logo { flex: none; margin-right: 8px; }
      .header-right { flex: none; }
      .hide-mobile { display: none !important; } /* gom hết vào menu ☰ */
      #hmenu .hm-mobile { display: block; }
      #hmenu .hm-sep.hm-mobile { display: block; }
      #hmenu { min-width: 240px; }
      #hmenu button { padding: 11px 14px; font-size: 14px; }  /* chạm dễ hơn */

      .filter-bar { gap: 8px; padding: 6px 10px; }
      #last-refresh { display: none; }
      .page-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
      .vol-wrap, .mini-scroll { overflow-x: auto; }

      /* MODAL Tổng quan / Phân tích: tiêu đề 1 dòng + nút Đóng phải, phụ đề
         xuống dòng riêng; thẻ xếp 1 cột */
      #exec-box { padding: 14px 12px; width: 96vw; }
      #exec-head { flex-wrap: wrap; gap: 8px; }
      #exec-head span:first-child { flex: 1; min-width: 0; font-size: 16px; }
      #exec-sub { order: 3; flex: 0 0 100%; margin-top: 2px; }
      #exec-grid { grid-template-columns: 1fr; }
    }
    /* Máy cảm ứng không có hover → luôn hiện nút công cụ trên ô chart */
    @media (hover: none) {
      .cell-tools { opacity: 1; }
    }

    /* ══ TAB DỌC BÊN TRÁI (kéo rộng được) ═══════════════════════════
       Định vị bằng CSS cố định + đẩy nội dung sang phải bằng padding —
       KHÔNG đụng cấu trúc DOM nên không ảnh hưởng logic trang sẵn có. */
    :root { --sb-w: 190px; }
    body { padding-left: var(--sb-w); }
    .page-tabs {
      position: fixed !important; left: 0; top: 0; bottom: 0;
      width: var(--sb-w); z-index: 400; overflow: hidden;
      flex-direction: column !important; align-items: stretch !important;
      border-top: none !important; border-right: 1px solid var(--border);
      padding: 0 !important;
    }
    .tabs-scroll {
      flex-direction: column !important;
      overflow-y: auto !important; overflow-x: hidden !important;
    }
    .page-tab {
      text-align: left; white-space: normal !important; line-height: 1.25;
      padding: 8px 10px !important;
      border-top: none !important; border-left: 3px solid transparent !important;
    }
    .page-tab.active {
      border-left-color: var(--accent) !important; background: #fff;
    }
    /* Cùng font với tab dashboard Trade (Trade dùng font hệ thống, Sales dùng
       Be Vietnam Pro nên nhìn "khác khác" dù cùng cỡ 12px) */
    .page-tab, #tab-search { font-family: 'Segoe UI', system-ui, sans-serif; }
    #tab-search {
      width: auto !important; align-self: stretch;
      border-right: none !important; border-top: none !important;
      border-bottom: 1px solid var(--border) !important;
      padding: 8px 10px !important;
    }
    #sb-resizer {
      position: fixed; top: 0; bottom: 0; width: 5px; z-index: 401;
      left: calc(var(--sb-w) - 2px); cursor: col-resize;
    }
    #sb-resizer:hover { background: var(--accent); opacity: .45; }
    /* Màn hẹp: trả về thanh tab NGANG như cũ cho dễ dùng trên điện thoại */
    @media (max-width: 700px) {
      body { padding-left: 0; }
      .page-tabs { position: static !important; width: auto; bottom: auto;
        flex-direction: row !important; border-right: none;
        border-top: 1px solid var(--border) !important; }
      .tabs-scroll { flex-direction: row !important;
        overflow-x: auto !important; overflow-y: hidden !important; }
      .page-tab { white-space: nowrap !important; padding: 7px 16px !important;
        border-left: none !important; border-top: 2px solid transparent !important; }
      .page-tab.active { border-top-color: var(--accent) !important; }
      #sb-resizer { display: none; }
    }
    @media print { body { padding-left: 0; }
      .page-tabs, #sb-resizer { display: none !important; } }
