/**
 * DataStat design tokens & utilities — dùng chung cho trang lưới, nhóm Standard/Plus/Pro,
 * và tab Thống kê cơ bản để giảm lặp inline style và giữ giao diện đồng bộ.
 * Bổ sung cho code_css_4.2025.css / style.css (không thay thế hoàn toàn).
 */
:root {
  --ds-font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ds-hero: #2c3e50;
  --ds-accent: #e67e58;
  --ds-muted: #7a7a7a;
  --ds-subtle: #6b7280;
  --ds-heading: #111827;
  --ds-tab: #514945;
  --ds-border-input: #d1d5db;
  /* Chiều cao thống nhất ô tìm + dropdown filter */
  --ds-search-h: 3.375rem;
}

/* --- Hero (trang chủ / nhóm công cụ) --- */
.ds-hero-block {
  padding: 1.25rem 0.5rem 0.25rem;
  /* Trong .container: dùng hết chiều ngang để tiêu đề một dòng như mockup */
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
  box-sizing: border-box;
}

.ds-hero-title {
  font-family: var(--ds-font);
  font-size: clamp(2rem, 3.6vw, 3rem);
  font-weight: 700;
  color: var(--ds-hero);
  margin: 0 auto 1rem;
  line-height: 1.2;
  letter-spacing: -0.02em;
  max-width: 100%;
  text-align: center;
}


.ds-hero-line-keep {
  white-space: nowrap;
}

@media (max-width: 480px) {
  .ds-hero-line-keep {
    white-space: normal;
  }
}

.ds-hero-accent {
  color: var(--ds-accent);
  letter-spacing: -0.01em;
}

.ds-hero-lead {
  font-family: var(--ds-font);
  font-size: clamp(1.15rem, 2vw, 1.4rem);
  font-weight: 400;
  color: var(--ds-muted);
  text-align: center;
  margin: 0 auto 1.75rem;
  max-width: min(60rem, 96vw);
  letter-spacing: 0.045em;
  line-height: 1.5;
  padding: 0.35rem 0.75rem 0;
  text-transform: none;
}

/* ── Thanh cuộn cho panel option biểu đồ (khi option quá dài) ── */
.ds-chart-options-scroll {
  scrollbar-width: thin;
  scrollbar-color: #E67E58 rgba(0,0,0,0.04);
  scroll-behavior: smooth;
}
.ds-chart-options-scroll::-webkit-scrollbar { width: 9px; }
.ds-chart-options-scroll::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.04);
  border-radius: 10px;
  margin: 4px 0;
}
.ds-chart-options-scroll::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #E67E58 0%, #d4633b 100%);
  border-radius: 10px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.ds-chart-options-scroll::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #ef8d68 0%, #d4633b 100%);
  background-clip: padding-box;
}
body.dark-mode .ds-chart-options-scroll {
  scrollbar-color: #E67E58 rgba(255,255,255,0.06);
}
body.dark-mode .ds-chart-options-scroll::-webkit-scrollbar-track {
  background: rgba(255,255,255,0.06);
}
body.dark-mode .ds-chart-options-scroll::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #E67E58 0%, #c0562f 100%);
  background-clip: padding-box;
}

/* Cụm tìm + filter: full width; căn giữa hàng con trong hero */
.ds-search-wrap {
  width: 100%;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.ds-hero-block .ds-search-wrap {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: stretch;
  width: 100%;
  max-width: 100%;
}

#main_grid_view .ds-search-row {
  flex: 0 1 auto;
  width: min(100%, 72rem);
  max-width: 100%;
  margin: 0;
  text-align: start;
}

/* Standard / Plus / Pro: một ô tìm — hàng con căn giữa qua flex ở trên */
.ds-hero-block .ds-search-row:not(:has(.ds-search-filter)) {
  flex: 0 1 auto;
  margin: 0;
  text-align: start;
}

/*
 * Hai cột: ô tìm | filter. Chỉ một ô (Standard/Plus/Pro): một cột — không chừa cột trống.
 */
.ds-search-row {
  display: grid;
  gap: 1rem;
  align-items: stretch;
  box-sizing: border-box;
}

/* Có filter: ô tìm ~một phần tư lớn hơn, ô filter dùng hết phần còn lại (không cap 22rem) */
.ds-search-row:has(.ds-search-filter) {
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
}

.ds-search-row:not(:has(.ds-search-filter)) {
  grid-template-columns: 1fr;
  width: min(100%, 42rem) !important;
}

@media (max-width: 640px) {
  .ds-search-row {
    grid-template-columns: 1fr;
  }

  .ds-search-row:not(:has(.ds-search-filter)) {
    width: 100% !important;
  }
}

.ds-search-row > .form-control.ds-search-input {
  min-width: 0;
  width: 100%;
}

/* Shiny: bỏ margin form-group, căng full ô lưới */
.ds-search-row .shiny-input-container,
.ds-search-row .ds-search-filter {
  margin-bottom: 0 !important;
  display: flex;
  align-items: stretch;
  align-self: stretch;
  min-width: 0;
}

.ds-search-row .ds-search-filter {
  width: 100%;
  min-width: 0;
  max-width: none;
  justify-self: stretch;
}

.ds-search-row .ds-search-filter .form-group {
  margin: 0 !important;
  width: 100% !important;
  max-width: none !important;
  display: flex;
  align-items: stretch;
}

.ds-search-row .ds-search-filter .shiny-input-container {
  width: 100% !important;
  max-width: none !important;
  flex: 1 1 auto;
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  align-self: stretch !important;
  min-width: 0 !important;
}

/* Select kéo full ô lưới (native select hay co theo nội dung) */
.ds-search-row .ds-search-filter select#filter_tag.form-control,
.ds-search-row .ds-search-filter select.form-control {
  display: block !important;
  width: 100% !important;
  max-width: none !important;
  min-width: 0 !important;
  flex: 1 1 auto !important;
}

/* Cùng chiều cao tuyệt đối: input text vs select Bootstrap */
.ds-search-row .shiny-input-container .form-control,
.ds-search-row .ds-search-filter select.form-control,
.ds-search-row select.form-control {
  width: 100%;
  height: var(--ds-search-h) !important;
  min-height: var(--ds-search-h) !important;
  max-height: var(--ds-search-h) !important;
  padding: 0 1rem;
  line-height: calc(var(--ds-search-h) - 2px);
  font-size: 17px;
  border-radius: 6px;
  border: 1px solid var(--ds-border-input);
  box-sizing: border-box;
}

/* Native select: cùng line-height với input, tránh cao/thấp lệch */
.ds-search-row select.form-control {
  line-height: calc(var(--ds-search-h) - 2px) !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  appearance: auto;
}

/* Trang chủ: ID cố định — đồng bộ tuyệt đối, thắng rule global */
#main_grid_view .ds-search-row #agent_search.ds-search-input.form-control,
#main_grid_view .ds-search-row select#filter_tag.form-control {
  height: var(--ds-search-h) !important;
  min-height: var(--ds-search-h) !important;
  max-height: var(--ds-search-h) !important;
  line-height: calc(var(--ds-search-h) - 2px) !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  box-sizing: border-box !important;
}

.ds-search-input.form-control {
  height: var(--ds-search-h) !important;
  min-height: var(--ds-search-h) !important;
  max-height: var(--ds-search-h) !important;
  padding: 0 1.1rem;
  line-height: calc(var(--ds-search-h) - 2px);
  border-radius: 6px;
  border: 1px solid var(--ds-border-input);
  font-size: 17px;
  color: #333;
  box-sizing: border-box;
}

/* --- Section (tiêu đề nhóm card trên lưới) --- */
.ds-section-heading {
  font-family: var(--ds-font);
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--ds-heading);
}

.ds-section-lead {
  margin-top: -4px;
  margin-bottom: 1.25rem;
  color: var(--ds-subtle);
}

.ds-section-divider {
  margin: 2.5rem 0 1.75rem 0;
  border-color: #e5e7eb;
}

/* --- Tab labels (Shiny tabset) --- */
.ds-tab-label {
  color: var(--ds-tab);
  font-weight: bold;
}

.ds-tab-sublabel {
  color: var(--ds-tab);
  font-weight: 500;
}

/* --- Nội dung HTML sinh từ server (gợi ý dùng class thay cho inline) --- */
.ds-prose {
  font-family: var(--ds-font);
  font-size: 14px;
  color: #333;
  line-height: 1.8;
  margin-top: 10px;
}

.ds-hint-muted {
  font-size: 12px;
  color: #666;
}

.ds-api-response {
  font-size: 16px;
  text-align: justify;
}

/* --- Dark mode (theo body.dark-mode / html.dark-mode trong app.R) --- */
body.dark-mode .ds-hero-title,
html.dark-mode .ds-hero-title {
  color: #e8e8e8 !important;
}

body.dark-mode .ds-hero-lead,
html.dark-mode .ds-hero-lead {
  color: #b0b0b0 !important;
}

body.dark-mode .ds-section-heading,
html.dark-mode .ds-section-heading {
  color: #f0f0f0 !important;
}

body.dark-mode .ds-section-lead,
html.dark-mode .ds-section-lead {
  color: #c0c0c0 !important;
}

body.dark-mode .ds-tab-label,
body.dark-mode .ds-tab-sublabel,
html.dark-mode .ds-tab-label,
html.dark-mode .ds-tab-sublabel {
  color: #bdbdbd !important;
}

body.dark-mode .ds-search-input.form-control,
html.dark-mode .ds-search-input.form-control,
body.dark-mode .ds-search-row select.form-control,
html.dark-mode .ds-search-row select.form-control {
  background-color: #3a3a3a !important;
  border-color: rgba(255, 255, 255, 0.2) !important;
  color: #f0f0f0 !important;
}

/* app-login-dark tô nền mọi .shiny-input-container → vệt tối rộng hơn select */
body.dark-mode .ds-search-row .ds-search-filter .shiny-input-container,
html.dark-mode .ds-search-row .ds-search-filter .shiny-input-container {
  background-color: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
}

body.dark-mode .ds-prose,
html.dark-mode .ds-prose {
  color: #e5e5e5 !important;
}

body.dark-mode .ds-hint-muted,
html.dark-mode .ds-hint-muted {
  color: #9ca3af !important;
}

body.dark-mode .ds-section-divider,
html.dark-mode .ds-section-divider {
  border-color: rgba(255, 255, 255, 0.12) !important;
}

/* Bảng gt (gt::gt_output): giãn full chiều rộng box thay vì co lại và căn giữa */
.gt_table_container {
  display: block !important;
  width: 100% !important;
}

.gt_table_container .gt_table {
  width: 100% !important;
}

/* ── Bảng DT trong box (Thống kê mô tả/suy luận): sát viền box, gọn ── */
.box-body table.dataTable { margin: 0 !important; }
.box-body .dataTables_wrapper { padding: 0 !important; margin: 0 !important; }
.box-body .dataTables_wrapper .dataTables_scroll { margin: 0 !important; }

/* ── Căn lề bảng mô tả: nội dung CĂN GIỮA cho cân 2 bên, cột "Biến số" căn trái ── */
table.ds-desc-table thead th,
table.ds-desc-table tbody td { text-align: center !important; padding: 8px 10px !important; }
table.ds-desc-table thead th:nth-child(2),
table.ds-desc-table tbody td:nth-child(2) { text-align: left !important; }

/* ── Nút tải biểu đồ định dạng TIFF (thay PDF) — badge chữ thay icon ── */
.tiff-text {
  background-image: none !important;
  background-color: #D55C5A !important;
  color: #fff !important;
  border-radius: 4px !important;
  font-size: 9px !important;
  font-weight: 700 !important;
  line-height: 40px !important;
  text-align: center !important;
  padding: 0 !important;
}
.tiff-text:hover { background-color: orange !important; color: #fff !important; }

/* ── Nút tải biểu đồ dạng icon (JPG/PNG/TIFF) — dùng chung mọi module ──
   Trước đây khối này bị lặp inline trong 5 file descriptive; gom về đây. */
.image-download-button,
.image1-download-button,
.image2-download-button {
  background-size: contain;
  background-color: transparent;
  background-repeat: no-repeat;
  background-position: center;
  width: 40px;
  height: 40px;
  border: none;
  cursor: pointer;
}
.image-download-button  { background-image: url('image.png'); }
.image1-download-button { background-image: url('image1.png'); }
.image2-download-button { background-image: url('image2.png'); }
.image-download-button:hover,
.image1-download-button:hover,
.image2-download-button:hover,
.excel-download-button:hover {
  background-color: orange;
}

/* ── Overlay "Đang tải module..." phủ lên view khi init module lần đầu ──
   Bật/tắt qua custom message 'ds-view-loading' (app-head.js). */
.ds-view-loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  /* Nền ĐẶC (không xuyên thấu): che hẳn các tab chưa kịp ẩn trong lúc init */
  background: #fafafa;
}
.ds-view-loading-inner { margin-top: 16vh; text-align: center; }
.ds-view-loading-spinner {
  width: 44px;
  height: 44px;
  margin: 0 auto 14px auto;
  border: 4px solid #e5e7eb;
  border-top-color: var(--ds-accent, #e67e58);
  border-radius: 50%;
  animation: ds-spin 0.8s linear infinite;
}
@keyframes ds-spin { to { transform: rotate(360deg); } }
.ds-view-loading-text {
  font-family: var(--ds-font, "Inter", sans-serif);
  font-size: 15px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 18px;
}
.ds-view-loading-bar {
  width: 260px;
  height: 12px;
  border-radius: 6px;
  margin: 8px auto;
  background: linear-gradient(90deg, #ececec 25%, #f8f8f8 37%, #ececec 63%);
  background-size: 400% 100%;
  animation: ds-shimmer 1.2s ease infinite;
}
.ds-view-loading-bar.short { width: 180px; }
@keyframes ds-shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}
.dark-mode .ds-view-loading-overlay { background: #161616; }
.dark-mode .ds-view-loading-text { color: #d1d5db; }
.dark-mode .ds-view-loading-spinner { border-color: #333; border-top-color: var(--ds-accent, #e67e58); }
.dark-mode .ds-view-loading-bar {
  background: linear-gradient(90deg, #232323 25%, #2e2e2e 37%, #232323 63%);
  background-size: 400% 100%;
}

/* ── Module "Ghép, nối & chuyển dạng dữ liệu": form bước đều đặn, nút đồng bộ ── */
#data_transform_view .ds-step {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0 10px;
  font-family: var(--ds-font);
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ds-hero, #2c3e50);
}
#data_transform_view .ds-step-num {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ds-accent, #e67e58);
  color: #fff;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
#data_transform_view hr { margin: 14px 0; border-top: 1px solid #e8e2de; }
/* Khung kết quả bên phải: ẩn khi uiOutput chưa render box nào (chưa chạy) */
#data_transform_view .well:has(> .shiny-html-output):not(:has(.box)) { display: none; }
#data_transform_view .form-group { margin-bottom: 12px; }
/* Nút hành động chính + nút tải kết quả — dùng chung mọi module (không scope) */
.ds-btn-run,
.ds-btn-dl {
  width: 100%;
  font-weight: 600;
}
.ds-btn-run {
  /* Trùng màu header box primary (#514945) — chuẩn nút hành động toàn app */
  background: var(--ds-tab, #514945);
  color: #fff;
  border: none;
  margin-bottom: 8px;
}
.ds-btn-run:hover,
.ds-btn-run:focus { background: #6a5e58; color: #fff; }
/* Nút hành động NGUY HIỂM (Xóa/Reset, không hoàn tác) — trùng header box danger */
.ds-btn-danger {
  width: 100%;
  font-weight: 600;
  background: #894242;
  color: #fff;
  border: none;
  margin-bottom: 8px;
}
.ds-btn-danger:hover,
.ds-btn-danger:focus { background: #a05555; color: #fff; }
body.dark-mode #data_transform_view .ds-step,
html.dark-mode #data_transform_view .ds-step { color: #e3dedb !important; }
body.dark-mode #data_transform_view hr,
html.dark-mode #data_transform_view hr { border-top-color: #3a3a3a !important; }

/* ===== Tab con trong module (QUY ĐỊNH CHUNG, docs/MODULE_STANDARDS.md mục 2) =====
   Mọi tabset lồng bên trong một tab của module (tab con, kiểu tabs hoặc pills): chữ đen, không
   khung viền; tab đang chọn chữ đỏ #894242 in đậm. Tab cấp ngoài cùng (TẢI DỮ LIỆU...) không đổi. */
.module-view .tab-content .nav-tabs,
.module-view .tab-content .nav-pills { border-bottom: none !important; }
.module-view .tab-content .nav-tabs > li > a,
.module-view .tab-content .nav-pills > li > a {
  background-color: transparent !important;
  color: #333 !important;
  border: none !important;
  border-radius: 0 !important;
  font-weight: 400;
}
.module-view .tab-content .nav-tabs > li > a:hover,
.module-view .tab-content .nav-pills > li > a:hover {
  background-color: #f5f5f5 !important;
  color: #333 !important;
}
.module-view .tab-content .nav-tabs > li.active > a,
.module-view .tab-content .nav-tabs > li.active > a:hover,
.module-view .tab-content .nav-tabs > li.active > a:focus,
.module-view .tab-content .nav-pills > li.active > a,
.module-view .tab-content .nav-pills > li.active > a:hover,
.module-view .tab-content .nav-pills > li.active > a:focus {
  background-color: #ffffff !important;
  color: #894242 !important;
  border: none !important;
  font-weight: 600 !important;
}
/* Dark mode: giống light mode, tab chọn là ô nền sáng hơn, chữ trắng đậm (đỏ khó đọc trên nền tối) */
body.dark-mode .module-view .tab-content .nav-tabs > li > a,
body.dark-mode .module-view .tab-content .nav-pills > li > a { color: #cfcfcf !important; }
body.dark-mode .module-view .tab-content .nav-tabs > li > a:hover,
body.dark-mode .module-view .tab-content .nav-pills > li > a:hover { background-color: #333333 !important; color: #ffffff !important; }
body.dark-mode .module-view .tab-content .nav-tabs > li.active > a,
body.dark-mode .module-view .tab-content .nav-tabs > li.active > a:hover,
body.dark-mode .module-view .tab-content .nav-tabs > li.active > a:focus,
body.dark-mode .module-view .tab-content .nav-pills > li.active > a,
body.dark-mode .module-view .tab-content .nav-pills > li.active > a:hover,
body.dark-mode .module-view .tab-content .nav-pills > li.active > a:focus { background-color: #3d3d3d !important; color: #ffffff !important; }

/* Khung "Tải dữ liệu" (modules/upload_data_module.R): cột trái hẹp, ô chọn file và các nút
   phải co theo khung, không tràn ra ngoài */
/* Mọi ô chọn file của app (fileInput): co theo khung chứa, tên file dài thì cắt bằng "…" */
.shiny-input-container:has(input[type="file"]) { width: 100% !important; max-width: 100%; }
.input-group:has(.btn-file) { display: flex; align-items: stretch; width: 100%; }
.input-group:has(.btn-file) .input-group-btn { display: flex; width: auto; flex: 0 0 auto; }
/* nút "Chọn file" và ô tên file: cùng chiều cao, cùng màu viền, bo góc liền thành một khối */
.input-group:has(.btn-file) .btn-file,
.input-group:has(.btn-file) .form-control { height: 34px; margin: 0; border: 1px solid #ccc; box-shadow: none; line-height: 20px; }
.input-group:has(.btn-file) .btn-file { display: flex; align-items: center; padding: 6px 10px; border-radius: 4px 0 0 4px; }
.input-group:has(.btn-file) .form-control { flex: 1 1 auto; min-width: 0; width: auto; padding: 6px 10px; border-left: 0; border-radius: 0 4px 4px 0; text-overflow: ellipsis; }
body.dark-mode .input-group:has(.btn-file) .btn-file,
body.dark-mode .input-group:has(.btn-file) .form-control { border-color: rgba(255, 255, 255, .14) !important; }
.ds-upload .btn { white-space: normal; line-height: 1.35; }
.ds-upload-or { display: flex; align-items: center; gap: 8px; color: #888; font-size: 12px; margin: 2px 0 8px; }
.ds-upload-or::before, .ds-upload-or::after { content: ""; flex: 1; border-top: 1px solid #ddd; }
.ds-upload .ds-upload-sample { width: 100%; background: #5a8a5a; color: #fff; border: none; font-weight: bold; }
.ds-upload .ds-upload-sample:hover, .ds-upload .ds-upload-sample:focus { background: #4c784c; color: #fff; }
body.dark-mode .ds-upload-or::before, body.dark-mode .ds-upload-or::after { border-top-color: #444; }
