/* dashboard.css - Chỉ giữ style độc nhất cho dashboard
 * Các style chung (variables, cards, tables, sections) đã có trong file tương ứng
 */

/* Status bars - loading/error */
.db-status-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 24px;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 1px solid var(--gray-200);
}

.db-loading {
  background: linear-gradient(135deg, rgba(0, 184, 212, .08) 0%, rgba(0, 168, 196, .06) 100%);
  color: #00b8d4;
  border-bottom: 2px solid #7dd3e0;
}

.db-error {
  background: linear-gradient(135deg, rgba(200, 48, 46, .08) 0%, rgba(200, 48, 46, .06) 100%);
  color: var(--error-500);
  border-bottom: 2px solid #f5c0c2;
}

.db-spinner {
  width: 14px;
  height: 14px;
  border: 2.5px solid rgba(0, 120, 212, .18);
  border-top-color: #0e6fba;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Preset buttons */
.db-presets {
  display: flex;
  align-items: center;
  gap: 7px;
}

/* Range strip - bottom of card */
.db-range-strip {
  background: linear-gradient(135deg, #1fbdd3 0%, #00a8bc 100%);
  color: rgba(255, 255, 255, .75);
  padding: 10px 24px;
  font-size: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, .1);
  border-radius: 0 0 10px 10px;
}

.db-range-item {
  display: flex;
  align-items: center;
  gap: 7px;
}

.db-rdot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.db-range-item strong {
  font-weight: 700;
  color: #fff;
  letter-spacing: .3px;
}

.db-range-sep {
  color: rgba(255, 255, 255, .2);
  font-size: 16px;
}

/* Range info inline trong page-header meta slot */
.db-range-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: center;
  font-size: 12px;
  color: rgba(255, 255, 255, .75);
}

/* 3-column chart grid */
.db-grid-3col {
  display: grid;
  grid-template-columns: 3fr 4fr 3fr;
  gap: 4px;
  align-items: stretch;
  grid-auto-rows: 1fr;
}



/* Panel badge reuse */
.db-panel-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.db-panel-dot--purple {
  background: var(--purple);
}

.db-panel-dot--amber {
  background: var(--amber);
}

.db-panel-dot--blue {
  background: var(--blue);
}

.db-header-full {
  width: 100%;
}

.db-badge-hidden {
  display: none;
}

.db-badge-camp-month {
  background: var(--green-lt);
  color: var(--green);
}

.db-badge-camp-range {
  background: var(--blue-lt);
  color: var(--blue);
}

.db-panel-body-np {
  padding: 0;
  width: 100%;
}

.db-activity-padded {
  padding: 12px;
}

.db-panel-badge {
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 999px;
  font-weight: 600;
}

/* Mode toggle */
.db-radio-group {
  display: flex;
  gap: 4px;
  align-items: center;
}

.db-mode-toggle-wrap {
  display: flex;
  justify-content: flex-end;
}

/* Reusable panel header styles */
.db-panel-inner {
  display: flex;
  flex-direction: column;
  width: 100%;
}

.db-panel-header-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.db-panel-header-row-full {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.db-panel-title {
  font-weight: 700;
  font-size: 14px;
}

/* Chart containers */
.db-chart-wrap {
  position: relative;
  width: 100%;
}

.db-chart-svg {
  display: block;
  width: 100%;
  height: 280px;
}

/* Cost chart inner row */
.db-cost-inner-row {
  display: flex;
  flex-direction: row;
  width: 100%;
}

.db-cost-chart-area {
  position: relative;
  flex: 2;
  min-width: 0;
}

.db-cost-types-panel {
  flex: 1;
  padding: 10px 12px;
  border-left: 1px solid var(--border-lt);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Activity grid badges */
.db-activity-sub {
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

/* Campaign analysis table */
.db-campaign-table-body {
  min-width: 860px;
}

.db-table-cell {
  padding: 7px 8px;
  font-size: 12px;
  color: var(--gray-800);
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

.db-table-cell td {
  padding: 7px 8px;
  font-size: 12px;
}

.db-table-cell.r {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Campaign chip */
.db-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: #deeef9;
  color: #0a5290;
}

/* Progress bar in campaign table */
.db-progress-wrap {
  display: flex;
  justify-content: space-between;
  margin-bottom: 3px;
}

.db-progress-label {
  font-size: 10px;
  color: var(--muted);
}

.db-progress-pct {
  font-size: 11px;
  font-weight: 700;
}

/* Badges in campaign analysis header */
.db-camp-badges {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

/* Empty state for merged campaign table */
.db-empty-cell {
  padding: 30px;
  text-align: center;
  color: var(--gray-400);
  font-size: 13px;
}

/* Chart tooltip base (position + styling by charts.js at runtime) */
.db-chart-tooltip {
  position: fixed;
  z-index: 999;
  pointer-events: none;
  background: #1c2033;
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.6;
  box-shadow: 0 4px 20px rgba(0, 0, 0, .25);
  max-width: 220px;
  min-width: 160px;
}

/* Rdot color variants */
.db-rdot--blue {
  background: var(--blue);
}

.db-rdot--light {
  background: rgba(255, 255, 255, .3);
}

.db-rdot--teal {
  background: var(--teal);
}

/* Tooltip inner elements (used by JS-rendered chart tooltips) */
.db-tooltip-title {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 4px;
}

.db-tooltip-value {
  font-weight: 700;
  color: #fff;
}

.db-tooltip-pct {
  color: #aaa;
  font-size: 11px;
  margin-top: 4px;
}

.db-tooltip-costs {
  border-top: 1px solid rgba(255, 255, 255, .15);
  margin: 6px 0 4px;
  padding-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
}

.db-tooltip-cost-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Cost type items in side panel */
.db-cost-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.db-cost-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.db-cost-item-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
}

.db-cost-item-label {
  color: var(--text-2);
}

.db-cost-item-value {
  font-weight: 600;
  color: var(--text);
  font-size: 12px;
  padding-left: 13px;
}

.db-cost-item-pct {
  font-size: 10px;
  color: var(--caption);
  margin-left: 4px;
}

.db-cost-section-title {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--caption);
}

/* ── Legend biểu đồ donut/sunburst — dùng chung mọi trang qua renderSunburst (charts.js) ── */
.db-legend {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.db-legend-title {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--caption);
}

.db-legend-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
}

.db-legend-entry {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.db-legend-main {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.db-legend-entry--stacked .db-legend-main {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.db-legend-entry--stacked .db-legend-main .db-legend-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.db-legend-entry--stacked .db-legend-main .db-legend-value-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding-left: 16px;
}

.db-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.db-legend-label {
  color: var(--text-2);
}

.db-legend-value {
  font-weight: 600;
  color: var(--text);
}

.db-legend-pct {
  color: var(--caption);
  font-size: 11px;
  margin-left: 6px;
}

.db-legend-sub {
  color: var(--caption);
  font-size: 11px;
  padding-left: 16px;
}

.db-legend-empty {
  color: #a8aec8;
  font-size: 12px;
}

.db-cost-section-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.db-radio-btn {
  height: 24px;
  padding: 0 10px;
  border: 1px solid var(--gray-200);
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-400);
  background: transparent;
  cursor: pointer;
  font-family: var(--app-font);
  transition: all 0.16s ease;
}

.db-radio-btn.active {
  background: var(--warning-500);
  border-color: var(--warning-500);
  color: #fff;
}

.db-radio-btn:hover:not(.active) {
  border-color: var(--warning-500);
  color: var(--warning-500);
}

/* ── Bảng phân tích chiến dịch (merged table) ──
 *   3 nhóm màu tương ứng 3 palette của ứng dụng:
 *   Month → primary (xanh pastel), Video → secondary (hồng pastel), Compare → warning (vàng cam)
 */
.db-table-merged {
  min-width: 860px;
}

.db-table-wrap {
  overflow-x: auto;
  border-radius: 0 0 10px 10px;
}

.db-table-scroll-wrapper {
  max-height: 680px;
  overflow-y: auto;
  overflow-x: auto;
  position: relative;
}

.db-table-scroll-wrapper table {
  width: 100%;
  border-collapse: collapse;
}

.db-table-scroll-wrapper thead {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #fff;
}

/* ── Header row 1: group titles ── */
.db-thead-group .db-col-campaign-th {
  vertical-align: middle;
  padding: 8px 10px;
  min-width: 120px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  position: sticky;
  left: 0;
  z-index: 3;
  background: #fff;
  box-shadow: 2px 0 4px -2px rgba(0, 0, 0, 0.08);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--gray-600);
  border-bottom: 2px solid var(--gray-300);
  border-right: 2px solid var(--gray-300);
}

.db-col-group {
  text-align: center;
  padding: 10px 12px 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0.02em;
  white-space: nowrap;
  line-height: 1.2;
  vertical-align: middle;
  border-bottom: 2px solid;
}

/* Nhóm month → primary */
.db-group-month {
  color: var(--primary-700);
  border-bottom: 2px solid var(--primary-200);
  border-left: 3px solid var(--primary-500);
  border-right: 1px solid var(--primary-100);
}

/* Nhóm video → success (xanh lá pastel) */
.db-group-video {
  color: var(--success-700);
  border-bottom: 2px solid var(--success-100);
  border-left: 3px solid var(--success-500);
  border-right: 1px solid var(--success-100);
}

/* Nhóm compare → warning */
.db-group-compare {
  color: var(--warning-700);
  border-bottom: 2px solid var(--warning-100);
  border-left: 3px solid var(--warning-500);
  border-right: 1px solid var(--warning-100);
}

/* ── Header row 2: sub headers ── */
.db-thead-sub th.sub {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 6px 8px;
  border-top: 2px solid;
  border-bottom: 2px solid;
  white-space: nowrap;
  line-height: 1.2;
}

.db-thead-sub th.sub-month {
  background: var(--primary-50);
  color: var(--primary-700);
  border-top: 2px solid var(--primary-200);
  border-bottom: 2px solid var(--primary-200);
  border-right: 1px solid var(--primary-100);
}

.db-thead-sub th.sub-video {
  background: var(--success-50);
  color: var(--success-700);
  border-top: 2px solid var(--success-100);
  border-bottom: 2px solid var(--success-100);
  border-right: 1px solid var(--success-100);
}

.db-thead-sub th.sub-compare {
  background: var(--warning-50);
  color: var(--warning-700);
  border-top: 2px solid var(--warning-100);
  border-bottom: 2px solid var(--warning-100);
  border-right: 1px solid var(--warning-100);
}

/* ── Campaign name sticky cell ── */
.db-col-campaign-cell {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #fff;
  box-shadow: 2px 0 4px -2px rgba(0, 0, 0, 0.08);
  border-right: 2px solid var(--gray-200);
  min-width: 120px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
  font-size: 12px;
  color: var(--gray-800);
  padding: 7px 10px;
}

.db-table-merged tbody tr:hover .db-col-campaign-cell {
  background: var(--gray-50);
}

/* First sub-header of each group gets left border to match group header */
.db-table-merged .db-thead-sub th.sub-month:first-child {
  border-left: 3px solid var(--primary-500);
}

.db-table-merged .db-thead-sub th.sub-video:nth-child(4) {
  border-left: 3px solid var(--success-500);
}

.db-table-merged .db-thead-sub th.sub-compare:nth-child(8) {
  border-left: 3px solid var(--warning-500);
}

/* Last compare cell gets right border to close table edge */
.db-table-merged .db-cell-compare-last {
  border-right: 1px solid var(--warning-100);
}

/* ── Body cells ── */
.db-table-merged tbody td {
  padding: 7px 8px;
  font-size: 12px;
  color: var(--gray-800);
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

.db-table-merged tbody td.r {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.db-table-merged tbody tr:hover {
  background: var(--gray-50);
}

/* Cell background theo nhóm (prefix table để thắng .db-table-merged tbody td specificity) */
.db-table-merged .db-cell-month-first {
  border-left: 3px solid var(--primary-400) !important;
  border-right: 1px solid var(--primary-100);
}

.db-table-merged .db-cell-month {
  border-right: 1px solid var(--primary-100);
}

.db-table-merged .db-cell-video-first {
  border-left: 3px solid var(--success-500) !important;
  border-right: 1px solid var(--success-100);
}

.db-table-merged .db-cell-video {
  border-right: 1px solid var(--success-100);
}

.db-table-merged .db-cell-compare-first {
  border-left: 3px solid var(--warning-500) !important;
}

/* Helpers: delta, bar, chip, empty */
.db-delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
}

.db-delta.up {
  background: var(--success-100);
  color: var(--success-600);
}

.db-delta.down {
  background: var(--error-100);
  color: var(--error-600);
}

.db-delta.flat {
  background: var(--gray-100);
  color: var(--gray-400);
}

.db-bar {
  height: 5px;
  background: var(--gray-200);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 4px;
}

.db-bar-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--app-primary);
  transition: width .5s ease;
}

.db-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: #deeef9;
  color: #0a5290;
}

.db-empty {
  padding: 30px;
  text-align: center;
  color: var(--gray-400);
  font-size: 13px;
}

.np {
  padding: 0;
}

/* Sunburst legend */
.dashboard-sunburst-legend {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 16px 14px;
  border-top: 1px solid var(--border-lt);
}

/* ── Activity panel: 2 cột mặc định (mobile sẽ override bên dưới) ── */
.db-activity-grid {
  grid-template-columns: repeat(2, 1fr);
}

/* Responsive */
@media (max-width: 1024px) {
  .db-grid-3col {
    grid-template-columns: 1fr;
  }

  .db-presets {
    width: 100%;
    justify-content: flex-start;
  }
}

@media (max-width: 768px) {

  /* Filter: date + KPI selects co lại */
  .dashboard-page .filter-inline {
    flex: 1 1 calc(50% - 8px);
    min-width: 130px;
  }

  .db-presets .btn {
    font-size: 11px;
    padding: 6px 8px;
  }

  /* Range info trong header xuống dòng */
  .db-range-inline {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .db-range-inline .db-range-sep {
    display: none;
  }

  .db-range-inline .db-range-item {
    gap: 4px;
  }

  /* Cost panel: xếp chồng chart + cost types */
  .db-cost-inner-row {
    flex-direction: column !important;
  }

  #sunburst-cost-types {
    border-left: none !important;
    border-top: 1px solid var(--border-lt);
    padding: 10px 12px !important;
  }

  /* Sunburst SVG thu nhỏ chiều cao */
  #status-sunburst-svg,
  #sunburst-svg {
    height: 200px !important;
  }

  /* Activity panel grid: 1 cột */
  .db-activity-grid {
    grid-template-columns: 1fr !important;
  }

  /* Campaign analysis header: title + badges xuống dòng */
  .section-card:has(.db-table-scroll-wrapper) .section-header-actions {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .section-card:has(.db-table-scroll-wrapper) .section-header-actions>div:last-child {
    width: 100%;
    justify-content: flex-start;
  }

  /* Mode toggle */
  .db-radio-group {
    justify-content: flex-start;
  }
}

@media (max-width: 480px) {
  .db-presets {
    flex-wrap: wrap;
    gap: 4px;
  }

  .db-presets .btn {
    flex: 1 1 calc(33% - 4px);
    font-size: 10px;
    padding: 5px 6px;
  }

  .dashboard-page .filter-inline {
    flex: 1 1 100%;
    min-width: 0;
  }
}