/* ==========================================================================
   GoblinExchange Codex — Chart Styles
   TradingView LWC, ECharts, Canvas Heatmap
   ========================================================================== */

/* ── Chart Container ── */
.chart-card {
    position: relative;
    background: var(--bg-elevated);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-lg);
    overflow: visible;
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-width: 100%;
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.5),
        0 2px 8px rgba(0, 0, 0, 0.4),
        0 8px 24px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.chart-card > * {
    min-width: 0;
    max-width: 100%;
}

.chart-toolbar {
    position: relative;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid rgba(244, 196, 48, 0.12);
    box-shadow: 0 1px 0 rgba(244, 196, 48, 0.08);
    flex-wrap: wrap;
}

.chart-toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.chart-toolbar--price {
    row-gap: 0.625rem;
}

.chart-toolbar-group--ranges,
.chart-toolbar-group--tools {
    min-width: 0;
    flex-wrap: wrap;
}

.chart-toolbar-divider {
    width: 1px;
    height: 1.25rem;
    margin: 0 0.25rem;
    flex: 0 0 auto;
    background: var(--border-subtle);
}

.chart-body {
    position: relative;
    z-index: 1;
    min-height: 320px;
    flex: 1 1 0%;
    overflow: hidden;
}

.chart-empty-state {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8125rem;
    background: rgba(0, 0, 0, 0.3);
    pointer-events: none;
}

.chart-empty-state.visible {
    display: flex;
}

.token-layout-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 1rem;
    align-items: stretch;
}

.token-chart-column {
    min-width: 0;
}

.token-chart-column .chart-card {
    height: 100%;
}

.token-region-sidebar {
    min-width: 0;
}

.token-region-list {
    gap: 0.75rem;
}

.token-region-card {
    display: block;
}

.token-region-label {
    color: var(--text-secondary, #d4d4d4);
}

.token-region-label.is-active {
    color: var(--color-brand, #f4c430);
}

.token-page-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.token-page-main {
    flex: 1 0 auto;
    width: 100%;
    max-width: 1440px;
    margin: 0 auto;
    padding: 0.75rem 1rem;
}

.token-page-footer {
    margin-top: auto;
}

.token-page-heading {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.token-page-heading > div {
    min-width: 0;
}

.token-page-heading > div:first-child,
.token-page-heading > div:last-child {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.token-page-heading h1 {
    font-family: var(--font-display);
    font-size: 1.5rem;
    line-height: 1.15;
    font-weight: 700;
    color: var(--text-primary);
}

.token-page-heading p {
    margin-top: 0.25rem;
    color: var(--text-muted);
    font-size: 0.875rem;
    line-height: 1.35;
}

.token-page-heading .token-icon-entrance {
    width: 2.5rem;
    height: 2.5rem;
    flex: 0 0 2.5rem;
    object-fit: contain;
}

.token-region-sparkline {
    width: 100%;
    height: 52px;
    overflow: hidden;
}

.token-summary-panel {
    padding: 0.75rem;
    margin-bottom: 0.75rem;
}

.token-summary-content {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 0.75rem;
}

.token-summary-content > div:first-child {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.token-summary-content > div:first-child > div:first-child > div:first-child {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    flex-wrap: wrap;
}

.token-summary-content > div:first-child > div:last-child {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-top: 0.25rem;
}

.token-summary-content > div:first-child > div:last-child > div {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.token-summary-stats {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 0.25rem;
}

@media (min-width: 1024px) {
    .token-layout-grid {
        grid-template-columns: minmax(0, 4fr) minmax(220px, 1fr);
    }
}

@media (min-width: 640px) {
    .token-page-heading {
        flex-direction: row;
        align-items: center;
    }
}

@media (min-width: 768px) {
    .token-page-main {
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }

    .token-summary-content {
        flex-direction: row;
        align-items: center;
    }

    .token-page-heading .token-icon-entrance {
        width: 3rem;
        height: 3rem;
        flex-basis: 3rem;
    }

    .chart-body { min-height: 420px; }
}
@media (min-width: 1024px) {
    .chart-body { min-height: 520px; }
}

@media (min-width: 1024px) and (max-height: 1040px) {
    .token-page-main {
        padding-top: 0.625rem !important;
        padding-bottom: 0.625rem !important;
    }

    .token-page-heading {
        margin-bottom: 0.75rem !important;
        gap: 0.75rem !important;
    }

    .token-page-heading h1 {
        font-size: clamp(1.875rem, 2vw, 2.25rem);
    }

    .token-page-heading p {
        margin-top: 0.25rem !important;
        font-size: 0.8125rem;
    }

    .token-summary-panel {
        margin-bottom: 0.75rem !important;
        padding: 0.75rem !important;
    }

    .token-summary-content {
        gap: 0.75rem !important;
    }

    .token-summary-stats {
        gap: 0.625rem !important;
    }

    .token-summary-stats .stat-card {
        min-width: 82px !important;
    }

    .token-summary-stats .stat-value {
        font-size: 0.9375rem;
    }

    .token-layout-grid {
        gap: 0.75rem;
        margin-bottom: 0.75rem !important;
        grid-template-columns: minmax(0, 4.35fr) minmax(210px, 0.95fr);
    }

    .token-page-shell .chart-toolbar {
        gap: 0.375rem;
        padding: 0.625rem 0.875rem;
    }

    .token-page-shell .chart-toolbar-group {
        gap: 0.25rem;
    }

    .token-page-shell .chart-period-btn,
    .token-page-shell .chart-type-btn {
        padding: 0.25rem 0.5rem;
    }

    .token-page-shell .chart-body {
        min-height: clamp(340px, 42vh, 440px);
    }

    .token-page-shell .token-region-sidebar {
        padding: 0.875rem !important;
    }

    .token-page-shell .token-region-sidebar h2 {
        margin-bottom: 0.75rem !important;
    }

    .token-page-shell .token-region-list {
        gap: 0.5rem;
    }

    .token-page-shell .token-region-card {
        padding: 0.75rem !important;
        border-radius: 0.875rem;
    }

    .token-region-sparkline {
        height: 40px;
    }

    .token-page-footer {
        margin-top: 0.75rem !important;
        padding-top: 0.75rem !important;
        padding-bottom: 0.75rem !important;
    }
}

/* ── Period/Type Selectors ── */
.chart-period-btn,
.chart-type-btn {
    padding: 0.25rem 0.625rem;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.chart-period-btn:hover,
.chart-type-btn:hover {
    color: var(--text-secondary);
    background: var(--bg-surface);
}
.chart-period-btn.active,
.chart-type-btn.active {
    color: var(--brand);
    background: var(--brand-soft);
    border-color: rgba(244, 196, 48, 0.2);
}

/* ── Indicator Menu ── */
.indicator-menu {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 20;
    min-width: 200px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    padding: 0.5rem;
    display: none;
}
.indicator-menu.open { display: block; }

.indicator-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.625rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.1s;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}
.indicator-item:hover { background: var(--bg-surface); }

.indicator-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.indicator-check {
    margin-left: auto;
    opacity: 0;
    color: var(--brand);
    font-size: 0.875rem;
}
.indicator-item.active .indicator-check { opacity: 1; }

/* ── Indicator Dropdown (inline, used by token.html & item.html) ── */
.indicator-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 0.375rem);
    z-index: 50;
    min-width: 180px;
    padding: 0.375rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-sm);
    background:
        linear-gradient(180deg, rgba(18, 18, 18, 0.98), rgba(8, 8, 8, 0.98)),
        #080808;
    box-shadow:
        0 18px 44px rgba(0, 0, 0, 0.55),
        0 0 0 1px rgba(0, 0, 0, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.indicator-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.425rem 0.625rem;
    border: none;
    border-radius: 6px;
    background: transparent;
    cursor: pointer;
    transition: background-color 0.1s, color 0.1s;
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-muted);
    text-align: left;
    white-space: nowrap;
    outline: none;
}
.indicator-dropdown-item:hover {
    background: rgba(255, 255, 255, 0.045);
    color: var(--text-secondary);
}
.indicator-dropdown-item:focus-visible {
    box-shadow: 0 0 0 2px rgba(244, 196, 48, 0.35);
}
.indicator-dropdown-item.is-active {
    color: var(--text-primary);
}

.indicator-dropdown-item .indicator-label {
    flex: 1 1 auto;
    min-width: 0;
}

.indicator-dropdown-item .indicator-check-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    color: var(--brand);
    font-size: 0.75rem;
    opacity: 0;
    transition: opacity 0.1s;
}
.indicator-dropdown-item.is-active .indicator-check-icon {
    opacity: 1;
}

/* ── Indicator Modal ── */
.ind-menu {
    position: relative;
    z-index: 40;
}

.tool-btn {
    position: relative;
}

.tool-btn__pip {
    position: absolute;
    top: -0.35rem;
    right: -0.35rem;
    display: inline-flex;
    min-width: 1rem;
    height: 1rem;
    align-items: center;
    justify-content: center;
    padding: 0 0.25rem;
    border-radius: 999px;
    border: 1px solid rgba(0, 0, 0, 0.85);
    background: var(--brand, #f4c430);
    color: #0a0a0a;
    font-size: 0.625rem;
    font-weight: 800;
    line-height: 1;
    box-shadow: 0 0 0 1px rgba(244, 196, 48, 0.2);
}

.ind-menu__pop--modal {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    z-index: 100;
    width: min(92vw, 360px);
    max-height: min(70vh, 520px);
    overflow: auto;
    padding: 0.875rem;
    border: 1px solid rgba(244, 196, 48, 0.2);
    border-radius: 8px;
    background:
        linear-gradient(180deg, rgba(18, 18, 18, 0.98), rgba(7, 7, 7, 0.98)),
        #080808;
    box-shadow:
        0 28px 70px rgba(0, 0, 0, 0.72),
        0 0 0 1px rgba(0, 0, 0, 0.65),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.ind-menu__pop--modal .ind-menu__title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.ind-menu__pop--modal .ind-menu__title {
    min-width: 0;
    color: var(--text-primary, #f5f5f5);
    font-family: var(--font-display, inherit);
    font-size: 0.95rem;
    font-weight: 800;
    line-height: 1.2;
}

.ind-menu__pop--modal .ind-menu__close {
    display: inline-flex;
    width: 2rem;
    height: 2rem;
    flex: 0 0 2rem;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.035);
    color: var(--text-muted, #a3a3a3);
    cursor: pointer;
}

.ind-menu__pop--modal .ind-menu__close:hover,
.ind-menu__pop--modal .ind-menu__close:focus-visible {
    color: var(--brand, #f4c430);
    border-color: rgba(244, 196, 48, 0.28);
    outline: none;
}

.ind-menu__pop--modal .ind-menu__head {
    margin: 0.75rem 0 0.375rem;
    color: var(--text-muted, #a3a3a3);
    font-size: 0.6875rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.ind-menu__pop--modal .ind-menu__head:first-of-type {
    margin-top: 0;
}

.ind-menu__pop--modal .ind-menu__item {
    display: flex;
    width: 100%;
    align-items: center;
    gap: 0.625rem;
    min-height: 2.5rem;
    padding: 0.55rem 0.625rem;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary, #d4d4d4);
    cursor: pointer;
    font: inherit;
    text-align: left;
}

.ind-menu__pop--modal .ind-menu__item:hover,
.ind-menu__pop--modal .ind-menu__item:focus-visible {
    background: rgba(255, 255, 255, 0.045);
    outline: none;
}

.ind-menu__pop--modal .ind-menu__check {
    display: inline-flex;
    width: 1rem;
    height: 1rem;
    flex: 0 0 1rem;
    align-items: center;
    justify-content: center;
    border: 1px solid currentColor;
    border-radius: 999px;
}

.ind-menu__pop--modal .ind-menu__check > span {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 999px;
}

.ind-menu__pop--modal .ind-menu__label {
    min-width: 0;
    overflow-wrap: anywhere;
    font-size: 0.875rem;
    font-weight: 650;
    line-height: 1.25;
}

.ind-menu__pop--modal .ind-menu__item.is-on .ind-menu__label {
    color: var(--text-primary, #f5f5f5);
}

.ind-menu__pop--modal .ind-menu__clear {
    width: 100%;
    margin-top: 0.875rem;
    padding: 0.625rem 0.75rem;
    border: 1px solid rgba(239, 68, 68, 0.24);
    border-radius: 6px;
    background: rgba(239, 68, 68, 0.08);
    color: var(--negative, #ef4444);
    cursor: pointer;
    font: inherit;
    font-size: 0.8125rem;
    font-weight: 800;
}

.ind-menu__pop--modal .ind-menu__clear:hover,
.ind-menu__pop--modal .ind-menu__clear:focus-visible {
    border-color: rgba(239, 68, 68, 0.42);
    background: rgba(239, 68, 68, 0.14);
    outline: none;
}

@media (max-width: 520px) {
    .ind-menu__pop--modal {
        width: min(calc(100vw - 1.5rem), 360px);
        max-height: 82vh;
    }
}

/* ── Fullscreen Overlay ── */
.chart-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: #000;
    display: flex;
    flex-direction: column;
    border-radius: 0;
    border: none;
    box-shadow: none;
    overflow: visible;
}
.chart-fullscreen .chart-toolbar {
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    padding: 0.75rem 1.5rem;
}
.chart-fullscreen .chart-body {
    flex: 1;
    min-height: 0;
    height: 100%;
}
.chart-fullscreen-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 51;
}

/* ── Heatmap ── */
.heatmap-container {
    position: relative;
    overflow-x: auto;
}
.heatmap-canvas {
    display: block;
    image-rendering: pixelated;
    cursor: crosshair;
}
.heatmap-tooltip {
    position: fixed;
    z-index: 100;
    padding: 0.5rem 0.75rem;
    background: var(--tooltip-bg);
    border: 1px solid var(--tooltip-border);
    border-radius: 8px;
    font-size: 0.75rem;
    color: var(--tooltip-text);
    pointer-events: none;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
    white-space: nowrap;
    display: none;
}
.heatmap-tooltip.visible { display: block; }

.heatmap-legend {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.6875rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}
.heatmap-legend-bar {
    width: 148px;
    height: 10px;
    border-radius: 999px;
}

/* ── Regional Bar Chart ── */
.regional-chart-container {
    min-height: 300px;
}

/* ── Quantity Chart ── */
.quantity-chart-container {
    min-height: 200px;
}

/* ── Sparkline (inline SVG) ── */
.sparkline {
    display: inline-block;
    vertical-align: middle;
}
.sparkline svg {
    display: block;
}

/* ── Treemap ── */
.treemap-container {
    min-height: 400px;
    border-radius: var(--radius-lg, 12px);
    overflow: hidden;
    background: rgba(255, 255, 255, 0.01);
    border: 1px solid rgba(255, 255, 255, 0.04);
}

/* ── Chart Crosshair Tooltip ── */
.chart-tooltip {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 20;
    padding: 6px 10px;
    background: rgba(7, 7, 7, 0.92);
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    font-size: 11px;
    line-height: 1.5;
    color: var(--text-secondary);
    pointer-events: none;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.12s;
    font-family: 'Inter', system-ui, sans-serif;
}
.chart-tooltip.visible {
    opacity: 1;
}
.chart-tooltip .ct-date {
    color: var(--text-muted);
    font-size: 10px;
    margin-bottom: 2px;
}
.chart-tooltip .ct-row {
    display: flex;
    align-items: center;
    gap: 6px;
}
.chart-tooltip .ct-label {
    color: var(--text-muted);
    min-width: 14px;
}
.chart-tooltip .ct-val {
    color: #f5f5f5;
    font-variant-numeric: tabular-nums;
}
.chart-tooltip .ct-positive {
    color: var(--positive);
}
.chart-tooltip .ct-negative {
    color: var(--negative);
}
