/* Style 3 — Treemap Drill-Down | NQ57 */

/* ── Design tokens ────────────────────────────────── */
:root {
  --s3-primary:    #0369A1;
  --s3-accent:     #7C3AED;
  --s3-text:       #0F172A;
  --s3-muted:      rgba(15,23,42,0.5);
  --s3-glass-bg:   rgba(255,255,255,0.72);
  --s3-glass-bd:   1px solid rgba(255,255,255,0.9);
  --s3-glass-sh:   0 8px 32px rgba(14,116,144,0.12);
  --s3-radius-lg:  16px;
  --s3-radius-md:  8px;
  --s3-sidebar-w:  320px;
}

/* ── Base ─────────────────────────────────────────── */
html, body {
  height: 100%;
  font-family: var(--font-sans, 'Inter', system-ui, sans-serif);
  color: var(--s3-text);
  overflow: hidden;
}

body {
  background: linear-gradient(135deg, #dbeafe 0%, #eff6ff 45%, #e0f2fe 100%) fixed;
  background-attachment: fixed;
}

/* ── Glass card utility ───────────────────────────── */
.glass-card {
  background: var(--s3-glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: var(--s3-glass-bd);
  box-shadow: var(--s3-glass-sh);
  border-radius: var(--s3-radius-lg);
}

/* ── Layout ───────────────────────────────────────── */
.s3-layout {
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  grid-template-columns: 1fr;
  height: 100vh;
  gap: 10px;
  padding: 12px;
  overflow: hidden;
}

/* ── Header ───────────────────────────────────────── */
.s3-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
}

.s3-header .btn-back {
  color: var(--s3-muted);
  border-color: rgba(15,23,42,0.2);
  flex-shrink: 0;
}
.s3-header .btn-back:hover { color: var(--s3-text); }

.s3-header-title {
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.s3-header-title h1 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--s3-text);
  white-space: nowrap;
}

.s3-subtitle {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--s3-accent);
  background: rgba(167,139,250,0.15);
  border: 1px solid rgba(167,139,250,0.35);
  border-radius: 999px;
  padding: 2px 10px;
}

.s3-header-meta {
  font-size: 0.75rem;
  color: var(--s3-muted);
  white-space: nowrap;
}

/* ── KPI Strip ────────────────────────────────────── */
.s3-kpi {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 14px 24px;
  gap: 8px;
}

.kpi-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex: 1;
}

.kpi-label {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--s3-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.kpi-value {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--s3-text);
  white-space: nowrap;
}

.kpi-value.kpi-rate {
  color: var(--s3-primary);
  font-size: 1.2rem;
}

.kpi-divider {
  width: 1px;
  height: 36px;
  background: rgba(15,23,42,0.12);
  flex-shrink: 0;
}

/* ── Controls ─────────────────────────────────────── */
.s3-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 4px;
}

.toggle-group {
  display: flex;
  background: rgba(255,255,255,0.6);
  border: var(--s3-glass-bd);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.toggle-btn {
  padding: 5px 18px;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--s3-muted);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}

.toggle-btn:hover {
  color: var(--s3-text);
  background: rgba(255,255,255,0.6);
}

.toggle-btn.active {
  background: var(--s3-primary);
  color: #FFFFFF;
  font-weight: 700;
}

.s3-count {
  font-size: 0.75rem;
  color: var(--s3-muted);
  margin-left: 4px;
}

/* ── Body ─────────────────────────────────────────── */
.s3-body {
  display: grid;
  grid-template-columns: 1fr var(--s3-sidebar-w);
  gap: 10px;
  min-height: 0;
  overflow: hidden;
}

/* ── Treemap wrap ─────────────────────────────────── */
.s3-treemap-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

#treemap-svg {
  flex: 1;
  display: block;
  width: 100%;
  overflow: hidden;
}

/* ── Tooltip ──────────────────────────────────────── */
.glass-tooltip {
  position: fixed;
  pointer-events: none;
  z-index: var(--tooltip-z, 900);
  padding: 10px 14px;
  border-radius: var(--s3-radius-md);
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(3,105,161,0.2);
  box-shadow: 0 4px 24px rgba(3,105,161,0.15);
  display: none;
  min-width: 160px;
  max-width: 240px;
}

.tt-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--s3-text);
  margin-bottom: 4px;
}

.tt-stats {
  font-size: 0.75rem;
  color: var(--s3-muted);
  margin-bottom: 4px;
  line-height: 1.6;
}

.tt-rate {
  font-size: 1rem;
  font-weight: 700;
}

/* ── Legend ───────────────────────────────────────── */
.s3-legend {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  flex-shrink: 0;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  color: var(--s3-muted);
  font-weight: 500;
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
  opacity: 0.9;
}

/* ── Sidebar ──────────────────────────────────────── */
.s3-sidebar {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(0);
  transition: transform 250ms ease-out;
}

.sidebar-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  color: var(--s3-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 24px;
}

.sidebar-empty-icon {
  font-size: 2.5rem;
  opacity: 0.35;
  color: var(--s3-primary);
}

.sidebar-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px 16px 12px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(15,23,42,0.1);
}

.sidebar-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--s3-text);
  line-height: 1.3;
  margin-bottom: 6px;
}

.sidebar-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(167,139,250,0.18);
  border: 1px solid rgba(167,139,250,0.4);
  color: var(--s3-accent);
  white-space: nowrap;
}

.sidebar-close {
  background: rgba(15,23,42,0.06);
  border: 1px solid rgba(15,23,42,0.12);
  border-radius: 50%;
  color: var(--s3-muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 150ms ease, color 150ms ease;
}
.sidebar-close:hover {
  background: rgba(15,23,42,0.12);
  color: var(--s3-text);
}

.sidebar-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  padding: 12px 16px;
  flex-shrink: 0;
}

.stat-mini {
  background: rgba(255,255,255,0.5);
  border: 1px solid rgba(15,23,42,0.08);
  border-radius: var(--s3-radius-md);
  padding: 8px 6px;
  text-align: center;
}

.stat-mini-label {
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--s3-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.stat-mini-val {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--s3-text);
  word-break: break-all;
}

.sidebar-rate-wrap {
  padding: 8px 16px 14px;
  flex-shrink: 0;
}

.sidebar-rate-label {
  font-size: 0.7rem;
  color: var(--s3-muted);
  font-weight: 500;
  margin-bottom: 2px;
}

.sidebar-rate {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
}

.sidebar-divider {
  height: 1px;
  background: rgba(15,23,42,0.08);
  margin: 0 16px;
  flex-shrink: 0;
}

.sidebar-nv-title {
  padding: 12px 16px 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--s3-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.sidebar-nv-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nv-item {
  background: rgba(255,255,255,0.6);
  border: 1px solid rgba(15,23,42,0.08);
  border-radius: var(--s3-radius-md);
  padding: 8px 10px;
}

.nv-item-name {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--s3-text);
  line-height: 1.35;
  margin-bottom: 4px;
}

.nv-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.nv-item-loai {
  font-size: 0.68rem;
  color: var(--s3-muted);
}

.nv-item-rate {
  font-size: 0.75rem;
  font-weight: 700;
}

.nv-empty {
  font-size: 0.8rem;
  color: var(--s3-muted);
  text-align: center;
  padding: 16px 0;
}

/* ── Scrollbar for sidebar ────────────────────────── */
.sidebar-nv-list::-webkit-scrollbar { width: 4px; }
.sidebar-nv-list::-webkit-scrollbar-track { background: transparent; }
.sidebar-nv-list::-webkit-scrollbar-thumb { background: rgba(15,23,42,0.15); border-radius: 2px; }

/* ── Loading state ────────────────────────────────── */
.s3-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  background: rgba(239,246,255,0.85);
  backdrop-filter: blur(4px);
  border-radius: var(--s3-radius-lg);
  z-index: 10;
}

.s3-loading-text {
  font-size: 0.85rem;
  color: var(--s3-muted);
}

/* ── Spinner override ─────────────────────────────── */
.s3-loading .spinner {
  border-color: rgba(3,105,161,0.15);
  border-top-color: var(--s3-primary);
}

/* ── Error state ──────────────────────────────────── */
.s3-error {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  padding: 24px;
  text-align: center;
}

.s3-error-msg {
  font-size: 0.85rem;
  color: #FCA5A5;
}

/* ── Responsive ───────────────────────────────────── */
@media (max-width: 900px) {
  :root { --s3-sidebar-w: 260px; }
  .s3-header-title h1 { font-size: 1rem; }
  .kpi-label { font-size: 0.62rem; }
  .kpi-value { font-size: 0.9rem; }
}

@media (max-width: 680px) {
  .s3-body { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  :root { --s3-sidebar-w: 100%; }
  .s3-sidebar {
    max-height: 240px;
    transform: translateY(0);
  }
}
