/**
 * GravityTreemap CSS
 * Styles for D3-powered treemap visualization
 */

/* ============================================
   Wrapper & Container
   ============================================ */

.gravity-treemap-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 400px;
    overflow: hidden;
    background: var(--gravity-surface-secondary, #f5f5f5);
    border-radius: var(--gravity-radius-md, 8px);
}

.gravity-treemap-container {
    position: relative;
    width: 100%;
    height: calc(100% - 48px); /* Account for toolbar height */
    min-height: 350px; /* Ensure minimum usable height even during loading */
    transform-origin: 0 0;
    transition: transform 0.3s ease-out;
    cursor: grab;
    /* Clip contour overlay and any content that extends beyond bounds */
    overflow: hidden;
}

.gravity-treemap-container:active {
    cursor: grabbing;
}

.gravity-treemap-container--revealing {
    /* Container state during reveal animation */
}

/* ============================================
   Breadcrumb Navigation
   ============================================ */

.gravity-treemap-breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem 1rem;
    background: var(--gravity-surface-primary, #fff);
    border-bottom: 1px solid var(--gravity-border, #e0e0e0);
    font-size: 0.875rem;
}

.gravity-treemap-breadcrumb-item {
    padding: 0.25rem 0.5rem;
    border: none;
    background: transparent;
    color: var(--gravity-text-secondary, #666);
    cursor: pointer;
    border-radius: var(--gravity-radius-sm, 4px);
    transition: background-color 0.15s ease;
}

.gravity-treemap-breadcrumb-item:hover {
    background: var(--gravity-surface-hover, #f0f0f0);
    color: var(--gravity-text-primary, #333);
}

.gravity-treemap-breadcrumb-root {
    font-size: 1.1rem;
}

.gravity-treemap-breadcrumb-icon {
    display: inline-block;
}

.gravity-treemap-breadcrumb-separator {
    color: var(--gravity-text-tertiary, #999);
}

/* ============================================
   Treemap Cells
   ============================================ */

.gravity-treemap-cell {
    position: absolute;
    box-sizing: border-box;
    overflow: hidden;
    border-radius: var(--gravity-radius-sm, 4px);
    background-color: var(--treemap-cell-bg, hsl(60, 70%, 50%));
    opacity: var(--treemap-cell-opacity, 0.8);
    border: 1px solid rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition:
        opacity 0.3s ease,
        background-color 0.3s ease,
        transform 0.15s ease,
        box-shadow 0.15s ease;
}

/* Base z-index by depth level - children always above parents */
.gravity-treemap-cell--level-0 { z-index: 1; }
.gravity-treemap-cell--level-1 { z-index: 2; }
.gravity-treemap-cell--level-2 { z-index: 3; }
.gravity-treemap-cell--level-3 { z-index: 4; }
.gravity-treemap-cell--level-4 { z-index: 5; }
.gravity-treemap-cell--level-5 { z-index: 6; }
.gravity-treemap-cell--level-6 { z-index: 7; }
.gravity-treemap-cell--level-7 { z-index: 8; }
.gravity-treemap-cell--level-8 { z-index: 9; }

/* Only leaf cells get hover visual effects - parents don't jump on top */
.gravity-treemap-cell--leaf:hover,
.gravity-treemap-cell--leaf.gravity-treemap-cell--hovered {
    z-index: 20;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: scale(1.01);
}

/* Focus styles - outline for accessibility, but z-index only for leaf cells */
.gravity-treemap-cell:focus {
    outline: 2px solid var(--gravity-focus, #2196f3);
    outline-offset: 2px;
}

/* Only leaf cells get z-index boost on focus - parents must NOT cover children */
.gravity-treemap-cell--leaf:focus {
    z-index: 21;
}

/* Parent cells: keep outline but NO z-index change to avoid covering children */
.gravity-treemap-cell--parent:focus {
    /* Outline applied from base :focus rule */
    /* z-index intentionally NOT changed - children must stay visible */
}

/* Reveal animation */
.gravity-treemap-cell--revealing {
    opacity: 0;
    background-color: hsl(0, 0%, 80%) !important;
    animation: treemap-reveal 0.5s ease-out forwards;
}

@keyframes treemap-reveal {
    0% {
        opacity: 0;
        background-color: hsl(0, 0%, 80%);
    }
    100% {
        opacity: var(--treemap-cell-opacity, 0.8);
        background-color: var(--treemap-cell-bg, hsl(60, 70%, 50%));
    }
}

/* ============================================
   Cell Header
   ============================================ */

.gravity-treemap-cell-header {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.5rem;
    background: rgba(255, 255, 255, 0.85);
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--gravity-text-primary, #333);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Level-based font sizing - aggressive shrink for hierarchy visibility
   Users can hover to see details and zoom for clarity */
.gravity-treemap-cell--level-0 .gravity-treemap-cell-header {
    font-size: 1rem;
    padding: 0.5rem 0.75rem;
    line-height: 1.3;
}

.gravity-treemap-cell--level-1 .gravity-treemap-cell-header {
    font-size: 0.75rem;
    padding: 0.3rem 0.5rem;
    line-height: 1.25;
}

.gravity-treemap-cell--level-2 .gravity-treemap-cell-header {
    font-size: 0.6rem;
    padding: 0.2rem 0.35rem;
    line-height: 1.2;
}

.gravity-treemap-cell--level-3 .gravity-treemap-cell-header {
    font-size: 0.5rem;
    padding: 0.15rem 0.25rem;
    line-height: 1.15;
}

.gravity-treemap-cell--level-4 .gravity-treemap-cell-header {
    font-size: 0.4rem;
    padding: 0.1rem 0.2rem;
    line-height: 1.1;
}

.gravity-treemap-cell--level-5 .gravity-treemap-cell-header {
    font-size: 0.35rem;
    padding: 0.05rem 0.1rem;
    line-height: 1;
}

/* Level 6+ for very deep hierarchies */
.gravity-treemap-cell--level-6 .gravity-treemap-cell-header,
.gravity-treemap-cell--level-7 .gravity-treemap-cell-header,
.gravity-treemap-cell--level-8 .gravity-treemap-cell-header {
    font-size: 0.3rem;
    padding: 0.025rem 0.05rem;
    line-height: 1;
}

.gravity-treemap-cell-title {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================
   Trend Indicator Integration
   Uses GravityTrendIndicator component - these are integration styles only
   ============================================ */

.gravity-treemap-cell-header .gravity-trend-indicator {
    flex-shrink: 0;
    /* Scale indicator with header font size */
    font-size: inherit;
    /* Better centering for small sizes */
    line-height: 1;
}

/* Micro size fixes for treemap context */
.gravity-treemap-cell-header .gravity-trend-indicator--micro {
    /* Ensure consistent sizing at micro scale */
    --gravity-trend-size: 1.1em;
}

/* Fix arrow centering at micro sizes */
.gravity-treemap-cell-header .gravity-trend-indicator--micro .gravity-trend-arrow {
    /* Center the icon properly */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6em;
    line-height: 1;
}

/* Trend indicators scale with zoom via CSS transforms.
   No hiding based on size - let them scale naturally.
   Very tiny indicators are still useful visual markers. */

/* ============================================
   Tooltip
   ============================================ */

.gravity-treemap-tooltip {
    position: fixed;
    z-index: 1000;
    min-width: 200px;
    max-width: 300px;
    padding: 0.75rem;
    background: var(--gravity-surface-primary, #fff);
    border-radius: var(--gravity-radius-md, 8px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    border: 1px solid var(--gravity-border, #e0e0e0);
    pointer-events: none;
    animation: tooltip-fade-in 0.15s ease-out;
}

@keyframes tooltip-fade-in {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.gravity-treemap-tooltip-header {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.625rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--gravity-border-light, #eee);
}

.gravity-treemap-tooltip-level {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--gravity-text-tertiary, #999);
}

.gravity-treemap-tooltip-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--gravity-text-primary, #333);
}

.gravity-treemap-tooltip-metrics {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.gravity-treemap-tooltip-metric {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8125rem;
}

.gravity-treemap-tooltip-metric-label {
    color: var(--gravity-text-secondary, #666);
}

.gravity-treemap-tooltip-metric-value {
    font-weight: 500;
    color: var(--gravity-text-primary, #333);
}

.gravity-treemap-tooltip-metric-level {
    font-size: 0.75rem;
    color: var(--gravity-text-tertiary, #999);
    margin-left: 0.25rem;
}

.gravity-treemap-tooltip-trend--up {
    color: var(--gravity-success, #4caf50);
}

.gravity-treemap-tooltip-trend--down {
    color: var(--gravity-error, #f44336);
}

.gravity-treemap-tooltip-trend--stable {
    color: var(--gravity-warning, #ff9800);
}

.gravity-treemap-tooltip-footer {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--gravity-border-light, #eee);
    font-size: 0.75rem;
    color: var(--gravity-text-tertiary, #999);
    text-align: center;
}

/* ============================================
   Loading State
   ============================================ */

.gravity-treemap-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 200px;
    gap: 1rem;
    color: var(--gravity-text-secondary, #666);
}

.gravity-treemap-loading-spinner {
    width: 2rem;
    height: 2rem;
    border: 3px solid var(--gravity-border, #e0e0e0);
    border-top-color: var(--gravity-primary, #2196f3);
    border-radius: 50%;
    animation: treemap-spin 0.8s linear infinite;
}

@keyframes treemap-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================
   Time Slider (toolbar integration)
   ============================================ */

.gravity-treemap-time-slider-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    max-width: 300px;
    min-width: 150px;
    margin: 0 1rem;
}

.gravity-treemap-time-slider-container .gravity-slider {
    flex: 1;
}

.gravity-treemap-time-slider-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--gravity-text-primary, #333);
    white-space: nowrap;
    min-width: fit-content;
}

/* ============================================
   Toolbar
   ============================================ */

.gravity-treemap-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    background: var(--gravity-surface-primary, #fff);
    border-bottom: 1px solid var(--gravity-border, #e0e0e0);
    min-height: 2.5rem;
    /* Keep toolbar above treemap content when zoomed */
    position: relative;
    z-index: 50;
}

.gravity-treemap-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

.gravity-treemap-toolbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--gravity-border, #e0e0e0);
    border-radius: var(--gravity-radius-sm, 4px);
    background: var(--gravity-surface-primary, #fff);
    color: var(--gravity-text-secondary, #666);
    font-size: 0.8125rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.gravity-treemap-toolbar-btn:hover {
    background: var(--gravity-surface-hover, #f5f5f5);
    color: var(--gravity-text-primary, #333);
    border-color: var(--gravity-border-dark, #ccc);
}

.gravity-treemap-toolbar-btn--active {
    background: var(--gravity-primary-light, #e3f2fd);
    color: var(--gravity-primary, #2196f3);
    border-color: var(--gravity-primary, #2196f3);
}

.gravity-treemap-toolbar-btn--active:hover {
    background: var(--gravity-primary-light, #bbdefb);
}

.gravity-treemap-toolbar-icon {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
}

.gravity-treemap-toolbar-btn-label {
    white-space: nowrap;
}

/* ============================================
   Navigation Controls (Zoom/Pan)
   ============================================ */

.gravity-treemap-nav-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-left: 0.5rem;
    padding-left: 0.75rem;
    border-left: 1px solid var(--gravity-border, #e0e0e0);
}

.gravity-treemap-pan-cross {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
}

.gravity-treemap-pan-middle {
    display: flex;
    align-items: center;
    gap: 1px;
}

.gravity-treemap-zoom-controls {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.gravity-treemap-nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 1px solid var(--gravity-border, #e0e0e0);
    border-radius: var(--gravity-radius-sm, 4px);
    background: var(--gravity-surface-primary, #fff);
    color: var(--gravity-text-secondary, #666);
    cursor: pointer;
    transition: all 0.15s ease;
}

.gravity-treemap-nav-btn:hover {
    background: var(--gravity-surface-hover, #f0f0f0);
    color: var(--gravity-text-primary, #333);
    border-color: var(--gravity-border-dark, #ccc);
}

.gravity-treemap-nav-btn:active {
    background: var(--gravity-surface-active, #e0e0e0);
    transform: scale(0.95);
}

.gravity-treemap-nav-btn svg {
    width: 14px;
    height: 14px;
}

.gravity-treemap-reset-btn {
    width: 22px;
    height: 22px;
}

.gravity-treemap-reset-btn svg {
    width: 12px;
    height: 12px;
}

/* ============================================
   Contour Overlay
   ============================================ */

.gravity-treemap-contour-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    /* Clip contours to the treemap boundaries */
    overflow: hidden;
}

.gravity-treemap-contour-band {
    pointer-events: all;
    cursor: pointer;
    /* Distinctive solid borders between bands */
    stroke-width: 2.5px;
    stroke-linejoin: round;
    stroke-linecap: round;
    transition: fill-opacity 0.2s ease, stroke-width 0.2s ease;
    /* Subtle drop shadow for depth */
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.15));
}

/* Band 0: Critical (0-25%) - Red */
.gravity-treemap-contour-band--0 {
    fill: rgba(244, 67, 54, 0.2);
    stroke: #d32f2f; /* Darker, solid red */
}

/* Band 1: Needs Improvement (25-50%) - Orange */
.gravity-treemap-contour-band--1 {
    fill: rgba(255, 152, 0, 0.2);
    stroke: #e65100; /* Darker, solid orange */
}

/* Band 2: Developing (50-70%) - Yellow */
.gravity-treemap-contour-band--2 {
    fill: rgba(255, 235, 59, 0.2);
    stroke: #f9a825; /* Golden yellow for visibility */
}

/* Band 3: Proficient (70-85%) - Light Green */
.gravity-treemap-contour-band--3 {
    fill: rgba(139, 195, 74, 0.2);
    stroke: #558b2f; /* Darker, solid green */
}

/* Band 4: Mastery (85-100%) - Green */
.gravity-treemap-contour-band--4 {
    fill: rgba(76, 175, 80, 0.2);
    stroke: #2e7d32; /* Dark green */
}

/* Hover state - highlight band */
.gravity-treemap-contour-band:hover,
.gravity-treemap-contour-band--hovered {
    stroke-width: 4px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.25));
}

.gravity-treemap-contour-band--0:hover,
.gravity-treemap-contour-band--0.gravity-treemap-contour-band--hovered {
    fill: rgba(244, 67, 54, 0.35);
}

.gravity-treemap-contour-band--1:hover,
.gravity-treemap-contour-band--1.gravity-treemap-contour-band--hovered {
    fill: rgba(255, 152, 0, 0.35);
}

.gravity-treemap-contour-band--2:hover,
.gravity-treemap-contour-band--2.gravity-treemap-contour-band--hovered {
    fill: rgba(255, 235, 59, 0.35);
}

.gravity-treemap-contour-band--3:hover,
.gravity-treemap-contour-band--3.gravity-treemap-contour-band--hovered {
    fill: rgba(139, 195, 74, 0.35);
}

.gravity-treemap-contour-band--4:hover,
.gravity-treemap-contour-band--4.gravity-treemap-contour-band--hovered {
    fill: rgba(76, 175, 80, 0.35);
}

/* Focus styles for accessibility */
.gravity-treemap-contour-band:focus {
    outline: 2px solid var(--gravity-focus, #2196f3);
    outline-offset: 2px;
}

/* ============================================
   Contour Panel
   ============================================ */

.gravity-treemap-contour-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: 280px;
    height: 100%;
    background: var(--gravity-surface-primary, #fff);
    border-left: 1px solid var(--gravity-border, #e0e0e0);
    box-shadow: -4px 0 12px rgba(0, 0, 0, 0.1);
    transform: translateX(100%);
    transition: transform 0.25s ease-out;
    z-index: 100;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.gravity-treemap-contour-panel--visible {
    transform: translateX(0);
}

/* Panel header */
.gravity-treemap-contour-panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem;
    border-bottom: 1px solid var(--gravity-border, #e0e0e0);
    background: var(--gravity-surface-secondary, #fafafa);
}

.gravity-treemap-contour-panel-header-content {
    flex: 1;
    min-width: 0;
}

.gravity-treemap-contour-panel-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--gravity-text-primary, #333);
}

.gravity-treemap-contour-panel-range {
    display: block;
    font-size: 0.75rem;
    color: var(--gravity-text-secondary, #666);
    margin-top: 0.25rem;
}

.gravity-treemap-contour-panel-close {
    width: 1.75rem;
    height: 1.75rem;
    padding: 0.25rem;
    border: none;
    border-radius: var(--gravity-radius-sm, 4px);
    background: transparent;
    color: var(--gravity-text-tertiary, #999);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
    flex-shrink: 0;
}

.gravity-treemap-contour-panel-close:hover {
    background: var(--gravity-surface-hover, #f0f0f0);
    color: var(--gravity-text-primary, #333);
}

.gravity-treemap-contour-panel-close svg {
    width: 100%;
    height: 100%;
}

/* Panel stats */
.gravity-treemap-contour-panel-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    padding: 1rem;
    border-bottom: 1px solid var(--gravity-border, #e0e0e0);
}

.gravity-treemap-contour-panel-stat {
    text-align: center;
}

.gravity-treemap-contour-panel-stat-value {
    display: block;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--gravity-text-primary, #333);
}

.gravity-treemap-contour-panel-stat-label {
    display: block;
    font-size: 0.6875rem;
    color: var(--gravity-text-tertiary, #999);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

/* Panel list */
.gravity-treemap-contour-panel-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.gravity-treemap-contour-panel-list-title {
    margin: 0 0 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gravity-text-secondary, #666);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.gravity-treemap-contour-panel-empty {
    padding: 1rem;
    text-align: center;
    color: var(--gravity-text-tertiary, #999);
    font-size: 0.875rem;
}

.gravity-treemap-contour-panel-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem;
    margin-bottom: 0.375rem;
    border: 1px solid var(--gravity-border-light, #eee);
    border-radius: var(--gravity-radius-sm, 4px);
    background: var(--gravity-surface-primary, #fff);
    cursor: default;
    text-align: left;
    font-size: 0.8125rem;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.gravity-treemap-contour-panel-item--clickable {
    cursor: pointer;
}

.gravity-treemap-contour-panel-item--clickable:hover {
    background: var(--gravity-surface-hover, #f5f5f5);
    border-color: var(--gravity-border, #e0e0e0);
}

.gravity-treemap-contour-panel-item--clickable:disabled {
    cursor: default;
    opacity: 0.7;
}

.gravity-treemap-contour-panel-item-level {
    flex-shrink: 0;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--gravity-text-tertiary, #999);
    text-transform: uppercase;
}

.gravity-treemap-contour-panel-item-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--gravity-text-primary, #333);
}

.gravity-treemap-contour-panel-item-confidence {
    flex-shrink: 0;
    font-weight: 500;
    color: hsl(var(--confidence-hue, 60), 70%, 35%);
}

.gravity-treemap-contour-panel-more {
    padding: 0.5rem;
    text-align: center;
    font-size: 0.75rem;
    color: var(--gravity-text-tertiary, #999);
}

/* Statistical validity caveat */
.gravity-treemap-contour-panel-caveat {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    margin: 0 0.75rem;
    background-color: rgba(255, 193, 7, 0.1);
    border: 1px solid rgba(255, 193, 7, 0.3);
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--gravity-warning, #f9a825);
}

.gravity-treemap-contour-panel-caveat-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    stroke: currentColor;
}

/* Band color indicator bar at bottom */
.gravity-treemap-contour-panel-band-indicator {
    height: 4px;
    flex-shrink: 0;
}
