/*
 * SL886 — 美股 3D 市場地圖樣式
 * 沿用 sl886 revamp 冷藍色調；舞台為深色 3D 畫布。
 */

.mm-map-page .mm-terminal {
    --mm-ink: #10244f;
    --mm-ink2: #163c73;
    --mm-sub: #38507a;
    --mm-line: #e6ecf5;
    --mm-line2: #d7e3f8;
    --mm-bg: #f7f9fd;
    --mm-blue: #1f4e9a;
    --mm-blue2: #2463c0;
    --mm-shadow: 0 8px 22px rgba(17, 52, 110, 0.06);
    --mm-stage: #0b1424;
    --mm-stage2: #111d33;
    --mm-up: #16a34a;
    --mm-down: #dc2626;
    --mm-mid: #64748b;
    color: var(--mm-ink);
    margin-top: 16px;
}

.mm-map-page .mm-terminal h2,
.mm-map-page .mm-terminal h3 {
    font-family: 'Noto Serif TC', 'PingFang TC', serif;
}

/* KPI row */
.mm-kpi-row {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.mm-kpi {
    background: #fff;
    border: 1px solid var(--mm-line);
    border-radius: 12px;
    padding: 12px 14px;
    box-shadow: var(--mm-shadow);
    min-width: 0;
}

.mm-kpi__label {
    font-size: 0.72rem;
    letter-spacing: 0.04em;
    color: var(--mm-sub);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mm-kpi__value {
    font-size: 1.22rem;
    font-weight: 700;
    color: var(--mm-ink2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mm-kpi__value--sm {
    font-size: 0.95rem;
}

/* Controls */
.mm-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 18px;
    align-items: flex-end;
    background: #fff;
    border: 1px solid var(--mm-line);
    border-radius: 12px;
    padding: 12px 14px;
    box-shadow: var(--mm-shadow);
    margin-bottom: 16px;
}

.mm-controls__group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.mm-controls__label {
    font-size: 0.74rem;
    color: var(--mm-sub);
    letter-spacing: 0.03em;
}

.mm-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.mm-pill {
    border: 1px solid var(--mm-line2);
    background: var(--mm-bg);
    color: var(--mm-ink2);
    border-radius: 999px;
    padding: 5px 14px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.mm-pill:hover {
    border-color: var(--mm-blue2);
    color: var(--mm-blue2);
}

.mm-pill.active {
    background: linear-gradient(180deg, var(--mm-blue2), var(--mm-blue));
    border-color: var(--mm-blue);
    color: #fff;
}

.mm-btn {
    border: 1px solid var(--mm-line2);
    background: #fff;
    color: var(--mm-ink2);
    border-radius: 10px;
    padding: 7px 13px;
    font-size: 0.83rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s ease;
}

.mm-btn:hover:not(:disabled) {
    border-color: var(--mm-blue2);
    color: var(--mm-blue2);
}

.mm-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.mm-btn--primary {
    background: linear-gradient(180deg, var(--mm-blue2), var(--mm-blue));
    border-color: var(--mm-blue);
    color: #fff;
}

.mm-btn.is-active {
    background: var(--mm-bg);
    border-color: var(--mm-blue2);
    color: var(--mm-blue2);
}

/* Stage */
.mm-stage-wrap {
    position: relative;
    width: 100%;
    height: calc(100dvh - 220px);
    min-height: 520px;
    max-height: 920px;
    border-radius: 16px;
    overflow: hidden;
    background: var(--mm-stage);
    border: 1px solid #0a1424;
    box-shadow: 0 14px 34px rgba(9, 22, 46, 0.24);
}

.mm-stage {
    position: absolute;
    inset: 0;
}

.mm-stage canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

.mm-stage-wrap:fullscreen {
    height: 100vh;
    border-radius: 0;
}

.mm-stage-header {
    position: absolute;
    top: 12px;
    left: 14px;
    right: 14px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    pointer-events: none;
    flex-wrap: wrap;
}

.mm-breadcrumb {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    background: rgba(9, 18, 36, 0.62);
    border: 1px solid rgba(120, 165, 235, 0.22);
    border-radius: 999px;
    padding: 5px 12px;
    backdrop-filter: blur(6px);
}

.mm-crumb {
    background: none;
    border: none;
    color: #cfe0ff;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    padding: 2px 4px;
}

.mm-crumb:hover {
    color: #fff;
    text-decoration: underline;
}

.mm-crumb.is-current {
    color: #fff;
    cursor: default;
    text-decoration: none;
}

.mm-crumb__sep {
    color: #7f9cc9;
}

.mm-stage-sub {
    color: #9db2d4;
    font-size: 0.78rem;
    background: rgba(9, 18, 36, 0.55);
    border-radius: 999px;
    padding: 5px 12px;
    backdrop-filter: blur(6px);
}

/* Legend */
.mm-legend {
    position: absolute;
    right: 14px;
    bottom: 14px;
    width: 220px;
    background: rgba(9, 18, 36, 0.72);
    border: 1px solid rgba(120, 165, 235, 0.22);
    border-radius: 12px;
    padding: 10px 12px;
    backdrop-filter: blur(6px);
    color: #cfe0ff;
}

.mm-legend__title {
    font-size: 0.78rem;
    font-weight: 700;
    margin-bottom: 6px;
}

.mm-legend__bar {
    height: 10px;
    border-radius: 999px;
    background: linear-gradient(90deg, #dc2626, #64748b, #16a34a);
}

.mm-legend__labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: #9db2d4;
    margin-top: 4px;
}

.mm-legend__note {
    font-size: 0.68rem;
    color: #8ba3c9;
    margin-top: 6px;
}

/* Tooltip */
.mm-tooltip {
    position: absolute;
    z-index: 5;
    min-width: 190px;
    max-width: 240px;
    background: rgba(6, 13, 26, 0.94);
    border: 1px solid rgba(120, 165, 235, 0.3);
    border-radius: 10px;
    padding: 9px 11px;
    color: #e8f1ff;
    font-size: 0.78rem;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.12s ease, transform 0.12s ease;
    pointer-events: none;
}

.mm-tooltip.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.mm-tooltip strong {
    display: block;
    font-size: 0.88rem;
    margin-bottom: 4px;
}

.mm-tip__meta {
    color: #9db2d4;
    font-size: 0.72rem;
    margin-bottom: 5px;
}

.mm-tip__row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 1px 0;
}

.mm-tip__row span {
    color: #9db2d4;
}

/* Loading */
.mm-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: #9db2d4;
    font-size: 0.85rem;
    background: rgba(9, 18, 36, 0.55);
    z-index: 6;
}

.mm-loading.is-hidden {
    display: none;
}

.mm-spinner {
    width: 34px;
    height: 34px;
    border: 3px solid rgba(120, 165, 235, 0.25);
    border-top-color: #60a5fa;
    border-radius: 50%;
    animation: mm-spin 0.9s linear infinite;
}

@keyframes mm-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Sidebar */
.mm-side {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    width: 300px;
    max-width: 86%;
    background: rgba(8, 16, 32, 0.94);
    border-left: 1px solid rgba(120, 165, 235, 0.22);
    color: #e8f1ff;
    padding: 40px 16px 16px;
    overflow-y: auto;
    transform: translateX(102%);
    transition: transform 0.22s ease;
    z-index: 7;
    backdrop-filter: blur(8px);
}

.mm-side.is-open {
    transform: translateX(0);
}

.mm-side__empty {
    color: #9db2d4;
    font-size: 0.82rem;
    line-height: 1.7;
}

.mm-side__empty code {
    background: rgba(120, 165, 235, 0.15);
    padding: 1px 6px;
    border-radius: 5px;
    color: #cfe0ff;
}

.mm-side__close {
    position: absolute;
    top: 10px;
    right: 12px;
    background: none;
    border: none;
    color: #9db2d4;
    font-size: 1rem;
    cursor: pointer;
}

.mm-side__head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.mm-side__logo {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    object-fit: contain;
    background: #fff;
    flex: 0 0 36px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.mm-side__head-text {
    min-width: 0;
}

.mm-side__name {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 0;
}

.mm-side__sub {
    color: #8ba3c9;
    font-size: 0.76rem;
    margin-top: 2px;
}

.mm-side__meta {
    display: flex;
    flex-direction: column;
    gap: 6px;
    border-top: 1px solid rgba(120, 165, 235, 0.16);
    padding-top: 10px;
}

.mm-kv {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 0.82rem;
}

.mm-kv span {
    color: #9db2d4;
}

.mm-side__cta {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 14px;
    background: linear-gradient(180deg, #2463c0, #1f4e9a);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 9px 14px;
    font-size: 0.84rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}

.mm-side__cta:hover {
    color: #fff;
    filter: brightness(1.06);
}

.mm-disclaimer {
    margin-top: 14px;
    color: #7f9cc9;
    font-size: 0.7rem;
    line-height: 1.6;
}

/* CSS2D labels */
.mm-label {
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
    white-space: nowrap;
    pointer-events: none;
}

/* 板塊／行業分區標題（嵌套 treemap 頂部窄帶） */
.mm-sector-title {
    color: #c8daf5;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.75);
    white-space: nowrap;
    pointer-events: none;
    padding: 1px 6px;
    border-radius: 4px;
    background: rgba(11, 20, 36, 0.45);
}

.mm-sector-title.is-clickable {
    pointer-events: auto;
    cursor: pointer;
    color: #e8f1ff;
}

.mm-sector-title.is-clickable:hover {
    color: #fff;
    background: rgba(36, 99, 192, 0.55);
}

/* Fallback table */
.mm-fallback {
    display: none;
}

.mm-fallback.is-visible {
    display: block;
}

.mm-table th,
.mm-table td {
    white-space: nowrap;
}

.mm-table .mm-num {
    text-align: right;
}

.mm-up {
    color: var(--mm-up, #16a34a);
    font-weight: 700;
}

.mm-down {
    color: var(--mm-down, #dc2626);
    font-weight: 700;
}

.mm-muted {
    color: #94a3b8;
}

/* Responsive */
@media (max-width: 992px) {
    .mm-kpi-row {
        grid-template-columns: repeat(3, 1fr);
    }

    .mm-stage-wrap {
        height: calc(100dvh - 180px);
        min-height: 440px;
        max-height: none;
    }
}

@media (max-width: 576px) {
    .mm-kpi-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .mm-stage-wrap {
        height: calc(100dvh - 140px);
        min-height: 380px;
        max-height: none;
    }

    .mm-legend {
        width: 168px;
    }

    .mm-side {
        width: 88%;
    }
}
