/* ==========================================================================
   Xưởng biểu đồ (Chart Studio)
   - .st-*  màn hình chính: thanh công cụ, lưới biểu đồ, hộp thoại
   - .sv-*  lưới sheet kiểu Excel (BCQTSheetView)
   - .cw-*  hộp thoại tạo biểu đồ (BCQTChartWizard)
   Dùng lại biến màu của styles.css để đồng bộ với phần còn lại của trang.
   ========================================================================== */

/* ---------------------------------------------------------------- Thanh công cụ */
.st-bar {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.7rem 0.85rem;
  margin-bottom: 0.9rem;
  box-shadow: 0 2px 10px -6px rgba(43, 24, 18, 0.18);
}
.st-bar-row {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.st-bar-sub {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--border);
}
.st-bar-meta {
  margin-top: 0.5rem;
  font-size: 0.74rem;
  color: var(--text-muted);
}

.st-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 150px;
}
.st-field-grow { flex: 1 1 240px; }
.st-field-block { display: block; margin-bottom: 0.7rem; }
.st-field-block span { display: block; margin-bottom: 0.25rem; }
.st-field > span {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.st-sel,
.st-inp {
  width: 100%;
  padding: 0.44rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-family: inherit;
  font-size: 0.86rem;
  color: var(--text);
  background: #fff;
}
.st-sel:focus,
.st-inp:focus {
  outline: 2px solid var(--accent-dim);
  border-color: var(--accent);
}

.st-btns { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.st-btn {
  padding: 0.44rem 0.72rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.14s, border-color 0.14s, color 0.14s;
  white-space: nowrap;
}
.st-btn:hover:not(:disabled) { background: var(--surface); border-color: var(--accent); }
.st-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.st-btn-sm { padding: 0.28rem 0.5rem; font-size: 0.74rem; }
.st-btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.st-btn-primary:hover:not(:disabled) { background: var(--accent-bright); border-color: var(--accent-bright); }
.st-btn-primary:disabled { background: #cbbfc2; border-color: #cbbfc2; color: #fff; }
.st-btn-danger { color: #b3261e; }
.st-btn-danger:hover:not(:disabled) { background: #fdeceb; border-color: #e0a9a5; }
.st-btn.is-dirty {
  animation: st-pulse 1.8s ease-in-out infinite;
}
@keyframes st-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(154, 24, 60, 0.35); }
  50% { box-shadow: 0 0 0 5px rgba(154, 24, 60, 0); }
}

.st-meta { font-size: 0.74rem; color: var(--text-muted); align-self: center; }
.st-toolrow {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-bottom: 0.6rem;
}
.st-toolhint { font-size: 0.76rem; color: var(--text-muted); }

/* ---------------------------------------------------------------- Lưới biểu đồ */
.st-grid { min-height: 180px; }
.st-card {
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 10px -6px rgba(43, 24, 18, 0.2);
}
.st-card-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  padding: 0.38rem 0.5rem 0.38rem 0.62rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #fff 0%, var(--surface) 160%);
  cursor: move;
  flex: 0 0 auto;
}
.st-card-t {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.st-card-h span:not(.st-card-t):not(.st-card-tools) {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.74rem;
}
.st-card-tools { display: flex; gap: 0.1rem; flex: 0 0 auto; }
.st-ic {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
}
.st-ic:hover { background: var(--accent-dim); color: var(--accent); }
.st-ic-x:hover { background: #fdeceb; color: #b3261e; }
.st-card-b { flex: 1 1 auto; min-height: 0; position: relative; }

.st-chart-empty { display: grid; place-items: center; }
.st-empty {
  padding: 1rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  max-width: 90%;
}

.st-blank {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-muted);
  border: 2px dashed var(--border);
  border-radius: 14px;
  background: var(--bg-elevated);
}
.st-blank h3 { margin: 0 0 0.4rem; color: var(--text); font-size: 1rem; }
.st-blank p { margin: 0 0 0.8rem; font-size: 0.85rem; }
.st-blank-sm { padding: 1.1rem; font-size: 0.85rem; margin-top: 0.6rem; }

/* ---------------------------------------------------------------- KPI & bảng */
.st-kpi-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  padding: 0.7rem;
  height: 100%;
  align-content: flex-start;
  overflow: auto;
}
.st-kpi-card {
  flex: 1 1 140px;
  min-width: 128px;
  position: relative;
  padding: 0.6rem 0.7rem 0.75rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--kpi, var(--accent));
  border-radius: 10px;
  background: linear-gradient(180deg, #fff 0%, #fdfbfa 100%);
  overflow: hidden;
}
.st-kpi-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.st-kpi-value {
  font-size: 1.42rem;
  font-weight: 800;
  line-height: 1.15;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.st-kpi-delta { font-size: 0.72rem; font-weight: 700; margin-top: 0.15rem; }
.st-kpi-delta.up { color: var(--success); }
.st-kpi-delta.down { color: #b3261e; }
.st-kpi-delta span { font-weight: 400; color: var(--text-muted); margin-left: 0.25rem; }
.st-kpi-spark {
  display: block;
  width: 100%;
  height: 22px;
  margin-top: 0.3rem;
  opacity: 0.75;
}

.st-table-wrap { height: 100%; overflow: auto; }
.st-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.79rem;
}
.st-table th,
.st-table td {
  padding: 0.33rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.st-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  font-weight: 700;
  color: var(--text);
  z-index: 1;
}
.st-th-label,
.st-td-label { text-align: left; font-variant-numeric: normal; }
.st-td-label { font-weight: 600; }
.st-table tbody tr:hover { background: var(--accent-dim); }
.st-tr-total td {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  font-weight: 800;
  border-top: 2px solid var(--border);
}

/* ---------------------------------------------------------------- Hộp thoại chung */
.st-dlg-ov {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(35, 21, 16, 0.44);
  display: grid;
  place-items: center;
  padding: 1.2rem;
}
.st-dlg {
  background: var(--bg-elevated);
  border-radius: 14px;
  /* Giới hạn cứng để hộp thoại không chiếm gần hết màn hình trên máy to */
  width: min(560px, calc(100vw - 2rem));
  max-height: min(640px, 82vh);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  overflow: hidden;
}
/* Bản rộng (xem dữ liệu sheet) cần chiều cao cố định cho lưới, nhưng vẫn phải có trần */
.st-dlg.is-wide { width: min(1100px, 94vw); height: min(660px, 82vh); }
.st-dlg-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
}
.st-dlg-b { padding: 0.9rem; overflow: auto; flex: 1 1 auto; min-height: 0; }
.st-dlg-help {
  margin: 0 0 0.8rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.st-dlg-actions { display: flex; justify-content: flex-end; gap: 0.4rem; margin-top: 0.4rem; }
.st-dlg-scroll { max-height: min(380px, 50vh); overflow: auto; }
.st-wbview { height: 100%; }
.st-dlg.is-wide .st-dlg-b { display: flex; }

.st-hist { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.st-hist th,
.st-hist td { padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--border); text-align: left; }
.st-hist thead th { background: var(--surface); position: sticky; top: 0; }

.st-prog {
  height: 8px;
  background: var(--surface);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}
.st-prog-bar { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

/* ==========================================================================
   Lưới sheet kiểu Excel
   ========================================================================== */
.sv-root { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.sv-topbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-bottom: 0.35rem;
  flex: 0 0 auto;
  flex-wrap: wrap;
}
.sv-tabs { display: flex; gap: 0.2rem; overflow-x: auto; flex: 1 1 auto; }
.sv-tab {
  padding: 0.24rem 0.6rem;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 7px 7px 0 0;
  background: var(--surface);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.sv-tab.is-on { background: #fff; color: var(--accent); border-color: var(--accent); }
.sv-addr {
  font-size: 0.74rem;
  color: var(--text-muted);
  display: flex;
  gap: 0.35rem;
  align-items: baseline;
  flex: 0 0 auto;
}
.sv-addr code {
  background: var(--accent-dim);
  color: var(--accent);
  padding: 0.1rem 0.35rem;
  border-radius: 5px;
  font-weight: 700;
}

.sv-frame {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 52px 1fr;
  grid-template-rows: 26px 1fr;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.sv-corner {
  grid-area: 1 / 1;
  background: var(--surface);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.sv-head {
  grid-area: 1 / 2;
  overflow: hidden;
  position: relative;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.sv-head-inner { position: relative; height: 100%; will-change: transform; }
.sv-ch {
  position: absolute;
  top: 0;
  height: 100%;
  display: grid;
  place-items: center;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-muted);
  border-right: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.sv-ch:hover { background: var(--accent-dim); color: var(--accent); }
.sv-gutter {
  grid-area: 2 / 1;
  overflow: hidden;
  position: relative;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.sv-gutter-inner { position: relative; will-change: transform; }
.sv-rh {
  position: absolute;
  left: 0;
  width: 100%;
  display: grid;
  place-items: center;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.sv-rh:hover { background: var(--accent-dim); color: var(--accent); }

.sv-scroll { grid-area: 2 / 2; overflow: auto; position: relative; }
.sv-canvas { position: relative; }
.sv-cells { position: absolute; inset: 0; }
.sv-c {
  position: absolute;
  padding: 0 5px;
  display: flex;
  align-items: center;
  font-size: 0.76rem;
  line-height: 1.2;
  color: var(--text);
  border-right: 1px solid rgba(43, 24, 18, 0.07);
  border-bottom: 1px solid rgba(43, 24, 18, 0.07);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  user-select: none;
  cursor: cell;
  background: #fff;
}
.sv-c.is-num { justify-content: flex-end; font-variant-numeric: tabular-nums; }
.sv-c.is-merge { background: #fffdf7; font-weight: 600; justify-content: center; text-align: center; }

.sv-sel { position: absolute; inset: 0; pointer-events: none; }
.sv-rect {
  position: absolute;
  border: 2px solid var(--accent);
  background: rgba(154, 24, 60, 0.09);
  border-radius: 2px;
}
.sv-hl {
  position: absolute;
  border: 1.5px dashed var(--hl, #2563eb);
  background: color-mix(in srgb, var(--hl, #2563eb) 10%, transparent);
  border-radius: 2px;
}
.sv-hl-tag {
  position: absolute;
  top: -15px;
  left: -1px;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 0 4px;
  border-radius: 3px 3px 0 0;
  background: var(--hl, #2563eb);
  color: #fff;
  white-space: nowrap;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sv-hint { flex: 0 0 auto; padding-top: 0.3rem; font-size: 0.7rem; color: var(--text-muted); }

/* ==========================================================================
   Hộp thoại tạo biểu đồ
   ========================================================================== */
body.cw-locked { overflow: hidden; }
.cw-overlay {
  position: fixed;
  inset: 0;
  z-index: 950;
  background: rgba(35, 21, 16, 0.5);
  display: grid;
  place-items: center;
  padding: 1rem;
}
.cw-overlay.is-picking .sv-scroll { cursor: crosshair; }
.cw-modal {
  /* Hộp thoại tạo biểu đồ cần chỗ cho lưới sheet, nhưng không cần kín màn hình */
  width: min(1240px, 96vw);
  height: min(740px, 88vh);
  background: var(--bg-elevated);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.cw-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #fff, var(--surface) 220%);
  flex: 0 0 auto;
}
.cw-head-l { display: flex; align-items: center; gap: 0.5rem; flex: 1 1 auto; min-width: 0; }
.cw-head-r { display: flex; align-items: center; gap: 0.4rem; flex: 0 0 auto; }
.cw-badge {
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #fff;
  background: var(--accent);
  padding: 0.18rem 0.44rem;
  border-radius: 5px;
}
.cw-title {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 460px;
  padding: 0.35rem 0.5rem;
  border: 1px solid transparent;
  border-radius: 8px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  background: transparent;
}
.cw-title:hover { border-color: var(--border); }
.cw-title:focus { border-color: var(--accent); outline: none; background: #fff; }
.cw-wb { font-size: 0.74rem; color: var(--text-muted); margin-right: 0.3rem; }
.cw-btn {
  padding: 0.42rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}
.cw-btn:hover { background: var(--surface); }
.cw-btn.is-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.cw-btn.is-primary:hover { background: var(--accent-bright); }
.cw-btn.cw-sm { padding: 0.28rem 0.55rem; font-size: 0.75rem; }

.cw-body {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 430px;
}
.cw-left {
  min-width: 0;
  padding: 0.6rem;
  border-right: 1px solid var(--border);
  display: flex;
  background: #fbfaf9;
}
.cw-grid { flex: 1 1 auto; min-width: 0; min-height: 0; }
.cw-right { display: flex; flex-direction: column; min-height: 0; background: var(--bg-elevated); }

.cw-preview-box {
  flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0.6rem 0.6rem;
  background: #fff;
}
.cw-preview-h {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}
.cw-preview-h span { font-weight: 600; text-transform: none; letter-spacing: 0; }
.cw-preview {
  height: min(250px, 30vh);
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
  background: #fff;
}
.cw-warn {
  margin-top: 0.4rem;
  padding: 0.4rem 0.5rem;
  border-radius: 8px;
  background: #fff7e6;
  border: 1px solid #f0d49a;
  color: #7a5307;
  font-size: 0.74rem;
  line-height: 1.45;
  max-height: 70px;
  overflow: auto;
}

.cw-tabs { display: flex; gap: 0.15rem; padding: 0.4rem 0.6rem 0; flex: 0 0 auto; }
.cw-tab {
  padding: 0.35rem 0.7rem;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  background: transparent;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
}
.cw-tab.is-on { background: var(--surface); color: var(--accent); border-color: var(--border); }
.cw-panel {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 0.7rem 0.6rem 1.4rem;
  border-top: 1px solid var(--border);
}

.cw-sec { margin-bottom: 0.9rem; }
.cw-lbl {
  display: block;
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}
.cw-lbl2 { font-size: 0.78rem; color: var(--text); flex: 0 0 104px; }
.cw-lbl3 { display: block; font-size: 0.7rem; color: var(--text-muted); margin: 0.3rem 0 0.15rem; }
.cw-help { margin: 0.35rem 0 0; font-size: 0.74rem; color: var(--text-muted); line-height: 1.45; }
.cw-inp {
  width: 100%;
  padding: 0.36rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.82rem;
  color: var(--text);
  background: #fff;
}
.cw-inp:focus { outline: none; border-color: var(--accent); }
.cw-sm-inp { flex: 1 1 auto; }
.cw-row { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.4rem; }
.cw-chk {
  display: flex;
  align-items: center;
  gap: 0.38rem;
  font-size: 0.8rem;
  margin-top: 0.34rem;
  cursor: pointer;
}
.cw-actions { display: flex; gap: 0.35rem; margin-top: 0.5rem; flex-wrap: wrap; }

.cw-seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.cw-segb {
  padding: 0.34rem 0.65rem;
  border: none;
  background: #fff;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}
.cw-segb + .cw-segb { border-left: 1px solid var(--border); }
.cw-segb.is-on { background: var(--accent); color: #fff; }
.cw-seg-sm .cw-segb { padding: 0.26rem 0.6rem; font-size: 0.75rem; }

/* ô nhập địa chỉ + nút bắt vùng */
.cw-refrow { display: flex; gap: 0.3rem; }
.cw-ref {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.36rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
  background: #fff;
  text-transform: uppercase;
}
.cw-ref:focus { outline: none; border-color: var(--accent); }
.cw-ref.is-target { background: #fff8e1; border-color: var(--warning); }
.cw-ref.is-bad { border-color: #b3261e; background: #fdeceb; }
.cw-pick {
  flex: 0 0 auto;
  width: 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 0.95rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
}
.cw-pick:hover { background: var(--surface); color: var(--accent); }
.cw-pick.is-on {
  background: var(--warning);
  border-color: var(--warning);
  color: #fff;
  animation: st-pulse 1.4s ease-in-out infinite;
}

/* danh sách chuỗi */
.cw-series { display: flex; flex-direction: column; gap: 0.45rem; }
.cw-sitem {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.45rem 0.5rem 0.55rem;
  background: #fdfcfb;
}
.cw-sitem-h { display: flex; align-items: center; gap: 0.35rem; }
.cw-dot { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.cw-sname { flex: 1 1 auto; min-width: 0; font-size: 0.8rem; }
.cw-x {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}
.cw-x:hover { background: #fdeceb; color: #b3261e; }
.cw-sitem-opts { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.4rem; flex-wrap: wrap; }
.cw-mini { display: flex; align-items: center; gap: 0.25rem; font-size: 0.72rem; color: var(--text-muted); }
.cw-mini select {
  padding: 0.16rem 0.3rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.72rem;
  background: #fff;
}
.cw-color {
  width: 28px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: none;
  cursor: pointer;
}
.cw-link {
  border: none;
  background: none;
  padding: 0;
  font-family: inherit;
  font-size: 0.72rem;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}

.cw-peek { border: 1px dashed var(--border); border-radius: 9px; padding: 0.45rem 0.6rem; background: #fbfaf9; }
.cw-peek ul { margin: 0; padding-left: 1.05rem; font-size: 0.76rem; color: var(--text); }
.cw-peek li { margin-bottom: 0.1rem; }
.cw-peek code,
.cw-peek-cats code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.72rem;
  color: var(--text-muted);
}
.cw-peek-cats { margin-top: 0.3rem; font-size: 0.76rem; }

/* thư viện mẫu biểu đồ */
.cw-gallery { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.35rem; }
.cw-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.22rem;
  padding: 0.45rem 0.2rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  font-family: inherit;
  font-size: 0.66rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text-muted);
  text-align: center;
  cursor: pointer;
}
.cw-tile:hover { border-color: var(--accent); background: var(--accent-dim); }
.cw-tile.is-on { border-color: var(--accent); background: var(--accent); color: #fff; }
.cw-ico { width: 26px; height: 26px; fill: currentColor; stroke: currentColor; }
.cw-tile.is-on .cw-ico { fill: #fff; stroke: #fff; }

/* bảng màu */
.cw-pals { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.3rem; }
.cw-pal {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-family: inherit;
  font-size: 0.74rem;
  color: var(--text);
  cursor: pointer;
}
.cw-pal.is-on { border-color: var(--accent); background: var(--accent-dim); font-weight: 700; }
.cw-pal-sw { display: flex; gap: 1px; flex: 0 0 auto; }
.cw-pal-sw i { width: 8px; height: 14px; border-radius: 1px; }
.cw-pal-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 1100px) {
  .cw-body { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .cw-left { border-right: none; border-bottom: 1px solid var(--border); min-height: 300px; }
  .cw-right { max-height: 52vh; }
  .cw-gallery { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ==========================================================================
   Tab trong bố cục
   ========================================================================== */
.st-tabs {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-bottom: 0.7rem;
  padding-bottom: 0.35rem;
  border-bottom: 2px solid var(--border);
  flex-wrap: wrap;
}
.st-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.85rem;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 9px 9px 0 0;
  background: transparent;
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  margin-bottom: -0.35rem;
}
.st-tab:hover { background: var(--surface); color: var(--text); }
.st-tab.is-on {
  background: var(--bg-elevated);
  color: var(--accent);
  border-color: var(--border);
  box-shadow: 0 2px 0 0 var(--bg-elevated);
}
.st-tab-n {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.05rem 0.34rem;
  border-radius: 99px;
  background: var(--surface);
  color: var(--text-muted);
}
.st-tab.is-on .st-tab-n { background: var(--accent-dim); color: var(--accent); }
.st-tab-add { font-size: 1rem; padding: 0.3rem 0.65rem; }
.st-tabs-gap { flex: 1 1 auto; }

/* ---------------------------------------------------------------- Nguồn theo năm */
.st-srcs {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  flex: 1 1 320px;
}
.st-srcs-lbl {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-right: 0.15rem;
}
.st-srcs-empty { font-size: 0.8rem; color: var(--text-muted); font-style: italic; }
.st-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.22rem 0.3rem 0.22rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  font-size: 0.78rem;
  color: var(--text);
  max-width: 260px;
  overflow: hidden;
  white-space: nowrap;
}
.st-chip b { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.st-chip.is-cur { border-color: var(--accent); background: var(--accent-dim); }
.st-chip.is-cur b { color: var(--accent); }
.st-chip.is-bad { border-color: #e0a9a5; background: #fdeceb; color: #b3261e; }
.st-chip-x {
  width: 18px; height: 18px;
  display: grid; place-items: center;
  border: none; border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem; line-height: 1;
  cursor: pointer;
}
.st-chip-x:hover { background: #fdeceb; color: #b3261e; }

.st-inp-xs { width: 78px; padding: 0.2rem 0.35rem; font-size: 0.78rem; }
.st-dim { color: var(--text-muted); font-size: 0.78rem; }
.st-drill td:nth-child(2) { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ==========================================================================
   Thành phần trình bày (tiêu đề mục · hộp văn bản · đường kẻ)
   ========================================================================== */
.st-card.is-pres {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}
.st-card.is-pres .st-card-h {
  background: transparent;
  border-bottom: none;
  opacity: 0;
  transition: opacity 0.14s;
}
.st-card.is-pres:hover .st-card-h { opacity: 1; }
.st-card.can-drill .st-card-b { cursor: pointer; }

.st-al-left { text-align: left; }
.st-al-center { text-align: center; }
.st-al-right { text-align: right; }

.st-heading {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0.3rem 0.1rem;
}
.st-heading-t {
  font-size: 1.02rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: var(--text);
  line-height: 1.25;
}
.st-heading-s { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.15rem; }
.st-tone-accent .st-heading-t {
  color: var(--accent);
  text-transform: uppercase;
  border-left: 4px solid var(--accent);
  padding-left: 0.55rem;
}
.st-tone-accent.st-al-center .st-heading-t,
.st-tone-accent.st-al-right .st-heading-t { border-left: none; padding-left: 0; }
.st-tone-plain .st-heading-t { font-weight: 700; color: var(--text); }
.st-tone-line .st-heading-t {
  color: var(--text);
  padding-bottom: 0.3rem;
  border-bottom: 2px solid var(--accent);
  display: inline-block;
}

.st-textbox {
  height: 100%;
  overflow: auto;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elevated);
}
.st-textbox-t { font-size: 0.84rem; font-weight: 700; margin-bottom: 0.25rem; color: var(--text); }
.st-textbox-b { color: var(--text-muted); line-height: 1.55; }
.st-size-sm .st-textbox-b { font-size: 0.78rem; }
.st-size-md .st-textbox-b { font-size: 0.87rem; }
.st-size-lg .st-textbox-b { font-size: 1rem; }

.st-divider {
  height: 100%;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.st-divider::before,
.st-divider::after {
  content: "";
  flex: 1 1 auto;
  height: 1px;
  background: var(--border);
}
.st-divider.st-al-left::before { flex: 0 0 12px; }
.st-divider.st-al-right::after { flex: 0 0 12px; }
.st-divider-label {
  flex: 0 0 auto;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* Ô nhập nhiều dòng + nhãn có checkbox trong hộp thoại biểu đồ */
.cw-ta { resize: vertical; min-height: 70px; font-family: inherit; line-height: 1.5; }
.cw-mini-chk { gap: 0.3rem; }
.cw-stride { border: 1px dashed var(--border); border-radius: 9px; padding: 0.5rem 0.6rem; background: #fbfaf9; }
