/* ═══════════════════════════════════════════════════════════════
   PHÁP GIỚI VŨ TRỤ HOA NGHIÊM — Mindmap
   Thiết kế theo phong cách Angular Material (M3)
   ═══════════════════════════════════════════════════════════════ */

:root {
  /* Angular M3 tonal palette — amber/gold primary */
  --primary: #b45309;
  --primary-container: #fef3c7;
  --on-primary: #ffffff;
  --on-primary-container: #78350f;

  --secondary: #7c3aed;
  --secondary-container: #ede9fe;
  --on-secondary-container: #4c1d95;

  --tertiary: #0e7490;
  --tertiary-container: #cffafe;

  --surface: #ffffff;
  --surface-1: #fefdfb;
  --surface-2: #faf8f5;
  --surface-3: #f5f2ed;
  --surface-variant: #f1ede6;

  --on-surface: #1c1917;
  --on-surface-variant: #57534e;
  --outline: #d6d3d1;
  --outline-variant: #e7e5e4;

  --error: #dc2626;
  --success: #16a34a;

  /* Elevation (Angular M3) */
  --elev-1: 0 1px 2px rgba(28, 25, 23, .06), 0 1px 3px 1px rgba(28, 25, 23, .04);
  --elev-2: 0 1px 2px rgba(28, 25, 23, .06), 0 2px 6px 2px rgba(28, 25, 23, .05);
  --elev-3: 0 4px 8px 3px rgba(28, 25, 23, .06), 0 1px 3px rgba(28, 25, 23, .08);
  --elev-4: 0 6px 10px 4px rgba(28, 25, 23, .07), 0 2px 3px rgba(28, 25, 23, .08);

  /* Shape scale */
  --r-xs: 4px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 24px;
  --r-full: 999px;

  /* Motion */
  --ease-standard: cubic-bezier(.2, 0, 0, 1);
  --ease-emphasized: cubic-bezier(.05, .7, .1, 1);
  --dur-short: 150ms;
  --dur-medium: 250ms;
  --dur-long: 400ms;

  --header-h: 76px;
  --tabbar-h: 56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: 'Be Vietnam Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--surface-2);
  color: var(--on-surface);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ═══════════════ HEADER ═══════════════ */

.app-header {
  position: relative;
  flex: 0 0 auto;
  background: linear-gradient(135deg, #1c1917 0%, #292524 40%, #3f2d1a 100%);
  color: #fef3c7;
  overflow: hidden;
  z-index: 20;
}

.header-glow {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 120% at 15% 0%, rgba(245, 158, 11, .22), transparent 60%),
    radial-gradient(ellipse 50% 100% at 85% 100%, rgba(139, 92, 246, .16), transparent 60%);
  pointer-events: none;
}

.header-inner {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 28px;
  min-height: var(--header-h);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.brand-mark {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  color: #fbbf24;
  animation: spinSlow 40s linear infinite;
}

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

.brand-text h1 {
  margin: 0;
  font-family: 'Philosopher', serif;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: .3px;
  line-height: 1.2;
  color: #fef3c7;
}

.brand-text h1 span {
  background: linear-gradient(90deg, #fbbf24, #f59e0b, #fcd34d);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-text p {
  margin: 3px 0 0;
  font-size: 11.5px;
  color: rgba(254, 243, 199, .62);
  letter-spacing: .2px;
}

.header-stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 16px;
  border-radius: var(--r-md);
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(251, 191, 36, .18);
  backdrop-filter: blur(8px);
  min-width: 84px;
}

.stat-value {
  font-size: 18px;
  font-weight: 700;
  color: #fbbf24;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: rgba(254, 243, 199, .55);
  margin-top: 1px;
}

/* ═══════════════ TAB BAR (Angular Material tabs) ═══════════════ */

.tabbar {
  flex: 0 0 auto;
  background: var(--surface);
  border-bottom: 1px solid var(--outline-variant);
  box-shadow: var(--elev-1);
  z-index: 15;
}

.tabbar-inner {
  display: flex;
  gap: 4px;
  padding: 0 20px;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabbar-inner::-webkit-scrollbar { display: none; }

.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: var(--tabbar-h);
  padding: 0 18px;
  border: 0;
  background: transparent;
  color: var(--on-surface-variant);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--dur-short) var(--ease-standard),
              background var(--dur-short) var(--ease-standard);
  border-radius: var(--r-sm) var(--r-sm) 0 0;
}

.tab svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  transition: transform var(--dur-medium) var(--ease-emphasized);
}

.tab:hover {
  color: var(--on-surface);
  background: var(--surface-2);
}

.tab:hover svg { transform: scale(1.1); }

.tab.is-active {
  color: var(--primary);
  font-weight: 600;
}

.tab.is-active svg { transform: scale(1.05); }

.tab::after {
  content: '';
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--primary);
  transform: scaleX(0);
  transition: transform var(--dur-medium) var(--ease-emphasized);
}

.tab.is-active::after { transform: scaleX(1); }

/* ═══════════════ MAIN / PANELS ═══════════════ */

.app-main {
  flex: 1 1 auto;
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.panel {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  min-height: 0;
}

.panel.is-active {
  display: flex;
  animation: panelIn var(--dur-medium) var(--ease-emphasized);
}

@keyframes panelIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ═══════════════ TOOLBAR ═══════════════ */

.toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--outline-variant);
  flex-wrap: wrap;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-group:last-child { margin-left: auto; }

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  width: 320px;
  max-width: 100%;
}

.search-box svg {
  position: absolute;
  left: 12px;
  width: 17px;
  height: 17px;
  color: var(--on-surface-variant);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  height: 40px;
  padding: 0 62px 0 38px;
  border: 1px solid var(--outline);
  border-radius: var(--r-full);
  background: var(--surface-2);
  font-family: inherit;
  font-size: 13.5px;
  color: var(--on-surface);
  outline: none;
  transition: border-color var(--dur-short), box-shadow var(--dur-short), background var(--dur-short);
}

.search-box input::placeholder { color: #a8a29e; }

.search-box input:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(180, 83, 9, .12);
}

.search-box kbd {
  position: absolute;
  right: 10px;
  font-family: inherit;
  font-size: 10px;
  font-weight: 600;
  color: var(--on-surface-variant);
  background: var(--surface-3);
  border: 1px solid var(--outline-variant);
  border-radius: var(--r-xs);
  padding: 2px 6px;
  pointer-events: none;
}

/* Buttons (Angular M3) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--r-full);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--dur-short) var(--ease-standard),
              box-shadow var(--dur-short) var(--ease-standard),
              transform var(--dur-short) var(--ease-standard);
  user-select: none;
}

.btn svg { width: 17px; height: 17px; flex: 0 0 auto; }

.btn:active { transform: scale(.97); }

.btn-ghost {
  background: transparent;
  color: var(--on-surface-variant);
  border: 1px solid var(--outline);
}

.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--on-surface);
  border-color: var(--on-surface-variant);
}

.btn-primary {
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: var(--elev-1);
}

.btn-primary:hover {
  background: #92400e;
  box-shadow: var(--elev-2);
}

.btn-icon {
  width: 40px;
  padding: 0;
  background: transparent;
  color: var(--on-surface-variant);
  border: 1px solid var(--outline);
}

.btn-icon:hover {
  background: var(--surface-2);
  color: var(--on-surface);
}

.btn-sm { height: 34px; padding: 0 13px; font-size: 12.5px; }
.btn-sm svg { width: 15px; height: 15px; }

.toolbar-zoom {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  border: 1px solid var(--outline-variant);
}

.toolbar-zoom .btn-icon {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: var(--r-full);
}

.zoom-label {
  min-width: 48px;
  text-align: center;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--on-surface-variant);
  font-variant-numeric: tabular-nums;
}

.select {
  height: 40px;
  padding: 0 34px 0 14px;
  border: 1px solid var(--outline);
  border-radius: var(--r-full);
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2357534e' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center / 15px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--on-surface);
  cursor: pointer;
  outline: none;
  appearance: none;
  transition: border-color var(--dur-short), box-shadow var(--dur-short);
}

.select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(180, 83, 9, .12);
}

/* ═══════════════ MINDMAP ═══════════════ */

.mindmap-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 15%, rgba(245, 158, 11, .05), transparent 45%),
    radial-gradient(circle at 80% 85%, rgba(139, 92, 246, .05), transparent 45%),
    var(--surface-2);
}

.mindmap-wrap::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(28, 25, 23, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(28, 25, 23, .035) 1px, transparent 1px);
  background-size: 28px 28px;
  pointer-events: none;
  mask-image: radial-gradient(ellipse 80% 80% at 50% 50%, #000 40%, transparent 100%);
  -webkit-mask-image: radial-gradient(ellipse 80% 80% at 50% 50%, #000 40%, transparent 100%);
}

.mindmap-canvas {
  position: absolute;
  inset: 0;
  cursor: grab;
  touch-action: none;
}

.mindmap-canvas.is-dragging { cursor: grabbing; }

#mindmapSvg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

/* Nodes */
.node-group { cursor: pointer; }

.node-rect {
  transition: filter var(--dur-short) var(--ease-standard),
              stroke-width var(--dur-short) var(--ease-standard);
}

.node-group:hover .node-rect {
  filter: url(#nodeShadowHover);
}

.node-label {
  font-family: 'Be Vietnam Pro', sans-serif;
  font-weight: 600;
  pointer-events: none;
  user-select: none;
}

.node-sub {
  font-family: 'Be Vietnam Pro', sans-serif;
  font-weight: 400;
  pointer-events: none;
  user-select: none;
}

.node-toggle {
  cursor: pointer;
  transition: transform var(--dur-short) var(--ease-standard);
}

.node-toggle:hover { transform: scale(1.18); }

.node-group.is-selected .node-rect {
  stroke-width: 3;
}

.node-group.is-match .node-rect {
  animation: matchPulse 1.4s var(--ease-standard) infinite;
}

@keyframes matchPulse {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(220, 38, 38, 0)); }
  50% { filter: drop-shadow(0 0 8px rgba(220, 38, 38, .75)); }
}

.node-group.is-dimmed { opacity: .18; }

/* Links */
.link-path {
  fill: none;
  stroke-linecap: round;
  transition: stroke-width var(--dur-short), opacity var(--dur-short);
}

.link-path.is-dimmed { opacity: .1; }

/* ═══════════════ LEGEND ═══════════════ */

.legend {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 250px;
  max-height: calc(100% - 32px);
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(14px);
  border: 1px solid var(--outline-variant);
  border-radius: var(--r-lg);
  box-shadow: var(--elev-2);
  overflow: hidden;
  transition: width var(--dur-medium) var(--ease-emphasized);
  z-index: 5;
}

.legend.is-collapsed { width: 52px; }

.legend-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  border-bottom: 1px solid var(--outline-variant);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--on-surface-variant);
  flex: 0 0 auto;
}

.legend.is-collapsed .legend-head span { display: none; }

.legend-toggle {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--on-surface-variant);
  cursor: pointer;
  transition: background var(--dur-short), transform var(--dur-medium) var(--ease-emphasized);
}

.legend-toggle:hover { background: var(--surface-3); }
.legend.is-collapsed .legend-toggle { transform: rotate(180deg); }
.legend-toggle svg { width: 15px; height: 15px; }

.legend-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px;
}

.legend.is-collapsed .legend-body { display: none; }

.legend-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--dur-short);
  font-size: 12.5px;
  color: var(--on-surface);
}

.legend-item:hover { background: var(--surface-3); }

.legend-item.is-off { opacity: .38; }

.legend-dot {
  width: 11px;
  height: 11px;
  border-radius: var(--r-full);
  flex: 0 0 auto;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, .05);
}

.legend-name {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.legend-count {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--on-surface-variant);
  background: var(--surface-3);
  border-radius: var(--r-full);
  padding: 1px 7px;
  font-variant-numeric: tabular-nums;
}

/* ═══════════════ DETAIL PANEL ═══════════════ */

.detail-panel {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 340px;
  max-height: calc(100% - 32px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--outline-variant);
  border-radius: var(--r-lg);
  box-shadow: var(--elev-3);
  overflow: hidden;
  transform: translateX(calc(100% + 24px));
  opacity: 0;
  transition: transform var(--dur-medium) var(--ease-emphasized),
              opacity var(--dur-medium) var(--ease-standard);
  z-index: 6;
}

.detail-panel.is-open {
  transform: translateX(0);
  opacity: 1;
}

.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 0;
  flex: 0 0 auto;
}

.detail-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--on-primary-container);
  background: var(--primary-container);
  border-radius: var(--r-full);
  padding: 3px 10px;
}

.detail-close {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--on-surface-variant);
  cursor: pointer;
  transition: background var(--dur-short);
}

.detail-close:hover { background: var(--surface-3); }
.detail-close svg { width: 17px; height: 17px; }

.detail-title {
  margin: 8px 16px 0;
  font-family: 'Philosopher', serif;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--on-surface);
  flex: 0 0 auto;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 16px 0;
  flex: 0 0 auto;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  color: var(--on-surface-variant);
}

.chip-dot {
  width: 7px;
  height: 7px;
  border-radius: var(--r-full);
}

.detail-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px 16px;
  font-size: 13px;
  color: var(--on-surface-variant);
  line-height: 1.65;
}

.detail-body p { margin: 0 0 10px; }

.detail-body .detail-section {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--outline-variant);
}

.detail-body .detail-section h5 {
  margin: 0 0 8px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--on-surface-variant);
}

.detail-child-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.detail-child-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 9px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: 12.5px;
  color: var(--on-surface);
  cursor: pointer;
  transition: background var(--dur-short);
}

.detail-child-list li:hover { background: var(--surface-3); }

.detail-child-list li .dot {
  width: 6px;
  height: 6px;
  border-radius: var(--r-full);
  flex: 0 0 auto;
}

.detail-child-list li .cnt {
  margin-left: auto;
  font-size: 10px;
  font-weight: 700;
  color: var(--on-surface-variant);
}

.detail-actions {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--outline-variant);
  background: var(--surface-2);
  flex: 0 0 auto;
}

.detail-actions .btn { flex: 1 1 0; }

/* ═══════════════ BREADCRUMB ═══════════════ */

.breadcrumb {
  position: absolute;
  left: 16px;
  bottom: 16px;
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: calc(100% - 400px);
  padding: 7px 14px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(14px);
  border: 1px solid var(--outline-variant);
  border-radius: var(--r-full);
  box-shadow: var(--elev-1);
  font-size: 12px;
  overflow-x: auto;
  scrollbar-width: none;
  z-index: 5;
}

.breadcrumb::-webkit-scrollbar { display: none; }

.breadcrumb:empty { display: none; }

.crumb {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--r-full);
  color: var(--on-surface-variant);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--dur-short), color var(--dur-short);
}

.crumb:hover {
  background: var(--surface-3);
  color: var(--on-surface);
}

.crumb.is-current {
  background: var(--primary-container);
  color: var(--on-primary-container);
  font-weight: 600;
  cursor: default;
}

.crumb-sep {
  color: var(--outline);
  font-size: 11px;
  user-select: none;
}

/* ═══════════════ HINT BAR ═══════════════ */

.hint-bar {
  position: absolute;
  right: 16px;
  bottom: 16px;
  display: flex;
  gap: 14px;
  padding: 7px 16px;
  background: rgba(28, 25, 23, .82);
  backdrop-filter: blur(10px);
  border-radius: var(--r-full);
  font-size: 11px;
  color: rgba(254, 243, 199, .8);
  z-index: 4;
  transition: opacity var(--dur-medium);
}

.hint-bar b { color: #fbbf24; font-weight: 700; }

.hint-bar.is-hidden { opacity: 0; pointer-events: none; }

/* ═══════════════ EXPLORER (Tree) ═══════════════ */

.explorer-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 20px 24px 40px;
}

.tree-view {
  max-width: 1100px;
  margin: 0 auto;
}

.tree-node {
  position: relative;
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--dur-short);
  border-left: 3px solid transparent;
}

.tree-row:hover { background: var(--surface); box-shadow: var(--elev-1); }

.tree-row.is-selected {
  background: var(--primary-container);
  border-left-color: var(--primary);
}

.tree-caret {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: var(--r-xs);
  color: var(--on-surface-variant);
  transition: transform var(--dur-short) var(--ease-standard), background var(--dur-short);
}

.tree-caret:hover { background: var(--surface-3); }
.tree-caret svg { width: 13px; height: 13px; }
.tree-caret.is-open { transform: rotate(90deg); }
.tree-caret.is-leaf { visibility: hidden; }

.tree-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--r-full);
  flex: 0 0 auto;
}

.tree-label {
  flex: 1 1 auto;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--on-surface);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-row.is-root .tree-label {
  font-family: 'Philosopher', serif;
  font-size: 16px;
  font-weight: 700;
}

.tree-badge {
  font-size: 10px;
  font-weight: 700;
  color: var(--on-surface-variant);
  background: var(--surface-3);
  border-radius: var(--r-full);
  padding: 1px 8px;
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}

.tree-children {
  margin-left: 22px;
  padding-left: 12px;
  border-left: 1px dashed var(--outline);
  overflow: hidden;
}

.tree-children.is-collapsed { display: none; }

.tree-row mark {
  background: #fde68a;
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

/* ═══════════════ TABLE ═══════════════ */

.table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 0 20px;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  padding: 12px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--on-surface-variant);
  border-bottom: 2px solid var(--outline-variant);
  white-space: nowrap;
}

.data-table thead th.sortable {
  cursor: pointer;
  user-select: none;
  transition: color var(--dur-short), background var(--dur-short);
}

.data-table thead th.sortable:hover {
  color: var(--primary);
  background: var(--surface-2);
}

.data-table thead th.sortable::after {
  content: '↕';
  margin-left: 6px;
  opacity: .35;
  font-size: 10px;
}

.data-table thead th.sort-asc::after { content: '↑'; opacity: 1; color: var(--primary); }
.data-table thead th.sort-desc::after { content: '↓'; opacity: 1; color: var(--primary); }

.data-table tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--outline-variant);
  color: var(--on-surface);
  vertical-align: middle;
}

.data-table tbody tr {
  transition: background var(--dur-short);
  cursor: pointer;
}

.data-table tbody tr:hover { background: var(--surface-2); }

.col-idx { width: 56px; text-align: right; color: var(--on-surface-variant); font-variant-numeric: tabular-nums; }
.col-branch { width: 190px; }
.col-depth { width: 80px; text-align: center; }
.col-parent { width: 240px; }
.col-children { width: 90px; text-align: center; }

.branch-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  color: var(--on-surface);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.branch-tag .dot {
  width: 7px;
  height: 7px;
  border-radius: var(--r-full);
  flex: 0 0 auto;
}

.depth-pill {
  display: inline-block;
  min-width: 26px;
  padding: 2px 8px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--on-surface-variant);
  font-variant-numeric: tabular-nums;
}

.parent-cell {
  color: var(--on-surface-variant);
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 240px;
}

.table-empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--on-surface-variant);
  font-size: 14px;
}

.table-footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  border-top: 1px solid var(--outline-variant);
  background: var(--surface);
  font-size: 12.5px;
  color: var(--on-surface-variant);
  flex-wrap: wrap;
}

.pager {
  display: flex;
  gap: 4px;
  align-items: center;
}

.pager button {
  min-width: 34px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--outline);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--on-surface-variant);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--dur-short);
}

.pager button:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--on-surface-variant);
  color: var(--on-surface);
}

.pager button.is-active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}

.pager button:disabled { opacity: .4; cursor: not-allowed; }

/* ═══════════════ STATS ═══════════════ */

.stats-grid {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: min-content;
  gap: 18px;
  padding: 20px 24px 40px;
  align-content: start;
  align-items: start;
}

@media (max-width: 900px) {
  .stats-grid { grid-template-columns: minmax(0, 1fr); }
}

.card {
  background: var(--surface);
  border: 1px solid var(--outline-variant);
  border-radius: var(--r-lg);
  box-shadow: var(--elev-1);
  overflow: hidden;
  transition: box-shadow var(--dur-medium);
  min-width: 0;
  height: auto;
}

.card:hover { box-shadow: var(--elev-2); }

.card-wide { grid-column: 1 / -1; }

.card-body > .bar-row:last-child { margin-bottom: 0; }

.card-head {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--outline-variant);
}

.card-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--on-surface);
}

.card-sub {
  display: block;
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--on-surface-variant);
}

.card-body { padding: 18px 20px; }

/* Bar chart */
.bar-row {
  display: grid;
  grid-template-columns: minmax(110px, 220px) minmax(40px, 1fr) 52px;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.bar-label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--on-surface);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  height: 22px;
  background: var(--surface-3);
  border-radius: var(--r-full);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: var(--r-full);
  transition: width var(--dur-long) var(--ease-emphasized);
  min-width: 4px;
}

.bar-value {
  font-size: 12px;
  font-weight: 700;
  color: var(--on-surface-variant);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Donut */
.donut-wrap {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: nowrap;
}

.donut {
  width: 148px;
  height: 148px;
  flex: 0 0 148px;
  transform: rotate(-90deg);
}

.donut circle {
  fill: none;
  stroke-width: 20;
  stroke-linecap: butt;
  transform-origin: 85px 85px;
  transition: stroke-dasharray var(--dur-long) var(--ease-emphasized),
              stroke-dashoffset var(--dur-long) var(--ease-emphasized);
}

.donut-center {
  fill: var(--surface);
}

.donut-total {
  font-family: 'Be Vietnam Pro', sans-serif;
  font-size: 22px;
  font-weight: 800;
  fill: var(--on-surface);
  transform: rotate(90deg);
  transform-origin: 85px 85px;
}

.donut-total-label {
  font-family: 'Be Vietnam Pro', sans-serif;
  font-size: 9.5px;
  font-weight: 600;
  fill: var(--on-surface-variant);
  letter-spacing: .5px;
  transform: rotate(90deg);
  transform-origin: 85px 85px;
}

.donut-legend {
  flex: 1 1 auto;
  min-width: 0;
  max-height: 210px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px 12px;
}

@media (max-width: 1200px) {
  .donut-legend { grid-template-columns: minmax(0, 1fr); }
}

.donut-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--on-surface-variant);
  white-space: nowrap;
}

.donut-legend-item .dot {
  width: 9px;
  height: 9px;
  border-radius: var(--r-full);
  flex: 0 0 auto;
}

.donut-legend-item b {
  margin-left: auto;
  color: var(--on-surface);
  font-variant-numeric: tabular-nums;
}

/* Mini table */
.mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.mini-table th {
  text-align: left;
  padding: 8px 10px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--on-surface-variant);
  border-bottom: 1px solid var(--outline-variant);
}

.mini-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--outline-variant);
  color: var(--on-surface);
}

.mini-table tbody tr:last-child td { border-bottom: 0; }
.mini-table tbody tr:hover { background: var(--surface-2); }

.mini-table .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.ratio-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ratio-track {
  flex: 1 1 auto;
  height: 6px;
  background: var(--surface-3);
  border-radius: var(--r-full);
  overflow: hidden;
  min-width: 60px;
}

.ratio-fill { height: 100%; border-radius: var(--r-full); }

/* ═══════════════ ABOUT ═══════════════ */

.about-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 32px 24px 60px;
}

.about-hero {
  max-width: 820px;
  margin: 0 auto 36px;
  text-align: center;
}

.about-mark {
  width: 84px;
  height: 84px;
  margin: 0 auto 18px;
  color: var(--primary);
  animation: spinSlow 60s linear infinite;
}

.about-hero h2 {
  margin: 0 0 12px;
  font-family: 'Philosopher', serif;
  font-size: 30px;
  font-weight: 700;
  color: var(--on-surface);
  letter-spacing: .3px;
}

.about-lead {
  margin: 0;
  font-size: 15px;
  line-height: 1.75;
  color: var(--on-surface-variant);
}

.about-lead em { color: var(--primary); font-style: normal; font-weight: 600; }

.about-grid {
  max-width: 1000px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px;
}

.about-card {
  background: var(--surface);
  border: 1px solid var(--outline-variant);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--elev-1);
  transition: transform var(--dur-medium) var(--ease-emphasized), box-shadow var(--dur-medium);
}

.about-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--elev-3);
}

.about-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--c) 14%, transparent);
  color: var(--c);
  margin-bottom: 12px;
}

.about-icon svg { width: 22px; height: 22px; }

.about-card h4 {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 700;
  color: var(--on-surface);
}

.about-card p {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--on-surface-variant);
}

.about-card a { color: var(--primary); font-weight: 600; text-decoration: none; }
.about-card a:hover { text-decoration: underline; }

.about-note {
  max-width: 1000px;
  margin: 24px auto 0;
  display: flex;
  gap: 12px;
  padding: 16px 20px;
  background: var(--primary-container);
  border-radius: var(--r-lg);
  color: var(--on-primary-container);
}

.about-note svg { width: 20px; height: 20px; flex: 0 0 auto; margin-top: 1px; }
.about-note p { margin: 0; font-size: 12.5px; line-height: 1.65; }

/* ═══════════════ TOAST ═══════════════ */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 20px);
  padding: 11px 22px;
  background: #1c1917;
  color: #fef3c7;
  border-radius: var(--r-full);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--elev-4);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-medium), transform var(--dur-medium) var(--ease-emphasized);
  z-index: 100;
  max-width: 90vw;
  text-align: center;
}

.toast.is-show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ═══════════════ SCROLLBAR ═══════════════ */

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #d6d3d1;
  border-radius: var(--r-full);
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: #a8a29e; background-clip: content-box; }

/* ═══════════════ RESPONSIVE ═══════════════ */

@media (max-width: 1100px) {
  .legend { width: 210px; }
  .detail-panel { width: 300px; }
  .breadcrumb { max-width: calc(100% - 340px); }
}

@media (max-width: 860px) {
  .header-inner { padding: 12px 16px; }
  .brand-text h1 { font-size: 17px; }
  .brand-text p { display: none; }
  .header-stats { display: none; }
  .toolbar { padding: 8px 12px; gap: 8px; }
  .search-box { width: 100%; }
  .toolbar-group:last-child { margin-left: 0; }
  .legend { display: none; }
  .detail-panel { width: calc(100% - 24px); right: 12px; top: 12px; }
  .breadcrumb { max-width: calc(100% - 24px); left: 12px; bottom: 12px; }
  .hint-bar { display: none; }
  .bar-row { grid-template-columns: 120px 1fr 44px; }
  .stats-grid { padding: 14px; gap: 12px; }
  .about-hero h2 { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
