/* Industry heatmap — financial terminal treemap */
.ihm-terminal {
    --ihm-ink: #10244f;
    --ihm-ink2: #163c73;
    --ihm-sub: #38507a;
    --ihm-line: #e6ecf5;
    --ihm-line2: #d7e3f8;
    --ihm-bg: #f7f9fd;
    --ihm-blue: #1f4e9a;
    --ihm-blue2: #2463c0;
    --ihm-shadow: 0 8px 22px rgba(17, 52, 110, 0.06);
    --ihm-stage: #0b1424;
    --ihm-stage2: #111d33;
    --ihm-up: #2e7d32;
    --ihm-down: #c62828;
    --ihm-mid: #455a64;
    font-family: 'IBM Plex Sans TC', 'PingFang TC', 'Microsoft JhengHei', sans-serif;
    color: var(--ihm-ink);
}

.ihm-terminal h2,
.ihm-terminal h3,
.ihm-terminal .ihm-title {
    font-family: 'Noto Serif TC', 'PingFang TC', serif;
}

/* KPI row */
.ihm-kpi-row {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.ihm-kpi {
    background: linear-gradient(180deg, #fff 0%, var(--ihm-bg) 100%);
    border: 1px solid var(--ihm-line2);
    border-radius: 12px;
    padding: 14px 16px;
    box-shadow: var(--ihm-shadow);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ihm-kpi:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 28px rgba(17, 52, 110, 0.1);
}

.ihm-kpi__label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--ihm-sub);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
}

.ihm-kpi__value {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--ihm-ink2);
    line-height: 1.2;
}

.ihm-kpi__value--up {
    color: var(--ihm-up);
}

.ihm-kpi__value--down {
    color: var(--ihm-down);
}

/* Controls */
.ihm-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 16px;
    margin-bottom: 20px;
    padding: 16px 18px;
    background: #fff;
    border: 1px solid var(--ihm-line2);
    border-radius: 14px;
    box-shadow: var(--ihm-shadow);
}

.ihm-controls__group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ihm-controls__label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--ihm-sub);
    letter-spacing: 0.03em;
}

.ihm-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.ihm-pill {
    border: 1px solid var(--ihm-line2);
    background: var(--ihm-bg);
    color: var(--ihm-ink2);
    font-size: 0.8rem;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ihm-pill:hover {
    border-color: var(--ihm-blue2);
    color: var(--ihm-blue);
}

.ihm-pill.active {
    background: var(--ihm-blue);
    border-color: var(--ihm-blue);
    color: #fff;
    box-shadow: 0 4px 12px rgba(31, 78, 154, 0.35);
}

.ihm-input,
.ihm-select {
    border: 1px solid var(--ihm-line2);
    border-radius: 8px;
    padding: 7px 10px;
    font-size: 0.85rem;
    min-width: 100px;
    color: var(--ihm-ink2);
    background: #fff;
}

.ihm-btn {
    border: none;
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.ihm-btn--primary {
    background: var(--ihm-blue);
    color: #fff;
}

.ihm-btn--primary:hover {
    background: var(--ihm-blue2);
}

.ihm-btn--ghost {
    background: transparent;
    border: 1px solid var(--ihm-line2);
    color: var(--ihm-ink2);
}

.ihm-btn--ghost:hover {
    border-color: var(--ihm-blue);
    color: var(--ihm-blue);
}

.ihm-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Main layout */
.ihm-main {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 16px;
    margin-bottom: 24px;
}

.ihm-stage-wrap {
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 20px 50px rgba(11, 20, 36, 0.45);
    min-height: 520px;
    background:
        radial-gradient(ellipse at 20% 0%, rgba(36, 99, 192, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 100%, rgba(46, 125, 50, 0.08) 0%, transparent 45%),
        linear-gradient(165deg, var(--ihm-stage) 0%, var(--ihm-stage2) 100%);
}

.ihm-stage-wrap::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 1;
}

.ihm-stage-header {
    position: relative;
    z-index: 2;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px 0;
    color: rgba(255, 255, 255, 0.85);
}

.ihm-stage-title {
    font-family: 'Noto Serif TC', serif;
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
    letter-spacing: 0.02em;
}

.ihm-stage-sub {
    font-size: 0.75rem;
    opacity: 0.65;
}

#ihm-treemap {
    position: relative;
    z-index: 2;
    width: 100%;
    height: 480px;
}

.ihm-loading {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(11, 20, 36, 0.85);
    color: rgba(255, 255, 255, 0.8);
    gap: 12px;
}

.ihm-loading.hidden {
    display: none;
}

.ihm-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(255, 255, 255, 0.15);
    border-top-color: #64b5f6;
    border-radius: 50%;
    animation: ihm-spin 0.8s linear infinite;
}

@keyframes ihm-spin {
    to { transform: rotate(360deg); }
}

/* Sidebar */
.ihm-sidebar {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.ihm-panel {
    background: #fff;
    border: 1px solid var(--ihm-line2);
    border-radius: 14px;
    padding: 16px;
    box-shadow: var(--ihm-shadow);
}

.ihm-panel__title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--ihm-sub);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0 0 12px;
}

.ihm-legend-bar {
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg, var(--ihm-down) 0%, var(--ihm-mid) 50%, var(--ihm-up) 100%);
    margin-bottom: 8px;
}

.ihm-legend-bar--seq {
    background: linear-gradient(90deg, #e3f2fd 0%, var(--ihm-blue) 100%);
}

.ihm-legend-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.72rem;
    color: var(--ihm-sub);
}

.ihm-detail {
    min-height: 120px;
}

.ihm-detail__empty {
    font-size: 0.85rem;
    color: var(--ihm-sub);
    text-align: center;
    padding: 24px 8px;
}

.ihm-detail__name {
    font-family: 'Noto Serif TC', serif;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--ihm-ink);
    margin: 0 0 10px;
}

.ihm-detail__metric {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 12px;
}

.ihm-detail__metric.up { color: var(--ihm-up); }
.ihm-detail__metric.down { color: var(--ihm-down); }

.ihm-detail__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    font-size: 0.8rem;
}

.ihm-detail__item span:first-child {
    display: block;
    color: var(--ihm-sub);
    font-size: 0.7rem;
}

.ihm-detail__link {
    display: inline-block;
    margin-top: 12px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--ihm-blue);
    text-decoration: none;
}

.ihm-detail__link:hover {
    color: var(--ihm-blue2);
    text-decoration: underline;
}

/* Table */
.ihm-table-wrap {
    background: #fff;
    border: 1px solid var(--ihm-line2);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: var(--ihm-shadow);
}

.ihm-table-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--ihm-line);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ihm-table-header h3 {
    margin: 0;
    font-size: 1rem;
    color: var(--ihm-ink2);
}

.ihm-table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.ihm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.ihm-table thead th {
    background: var(--ihm-bg);
    color: var(--ihm-sub);
    font-weight: 600;
    padding: 10px 12px;
    text-align: left;
    white-space: nowrap;
    border-bottom: 1px solid var(--ihm-line);
    cursor: pointer;
    user-select: none;
}

.ihm-table thead th:hover {
    color: var(--ihm-blue);
}

.ihm-table thead th.sorted-asc::after {
    content: ' ▲';
    font-size: 0.65rem;
}

.ihm-table thead th.sorted-desc::after {
    content: ' ▼';
    font-size: 0.65rem;
}

.ihm-table tbody td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--ihm-line);
    white-space: nowrap;
}

.ihm-table tbody tr {
    cursor: pointer;
    transition: background 0.15s ease;
}

.ihm-table tbody tr:hover {
    background: rgba(31, 78, 154, 0.06);
}

.ihm-table tbody tr.selected {
    background: rgba(31, 78, 154, 0.12);
    outline: 2px solid var(--ihm-blue);
    outline-offset: -2px;
}

.ihm-col-name {
    white-space: normal;
    min-width: 140px;
    font-weight: 600;
}

.ihm-col-name a {
    color: var(--ihm-ink2);
    text-decoration: none;
}

.ihm-col-name a:hover {
    color: var(--ihm-blue);
}

.ihm-val-up { color: var(--ihm-up); font-weight: 600; }
.ihm-val-down { color: var(--ihm-down); font-weight: 600; }

/* Hero modifier for home-tabbed */
.category-header.ihm-hero {
    background:
        radial-gradient(ellipse at 30% 20%, rgba(36, 99, 192, 0.35) 0%, transparent 55%),
        linear-gradient(135deg, #0b1424 0%, #163c73 50%, #1a2744 100%);
}

.category-header.ihm-hero .stat-number.text-warning {
    color: #81c784 !important;
}

.category-header.ihm-hero .stat-number.text-info {
    color: #64b5f6 !important;
}

.category-header.ihm-hero .stat-number.text-success {
    color: #aed581 !important;
}

/* Responsive */
@media (max-width: 1200px) {
    .ihm-kpi-row {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 992px) {
    .ihm-main {
        grid-template-columns: 1fr;
    }

    .ihm-sidebar {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .ihm-sidebar .ihm-panel {
        flex: 1 1 240px;
    }
}

@media (max-width: 768px) {
    .ihm-kpi-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .ihm-stage-wrap {
        min-height: 380px;
    }

    #ihm-treemap {
        height: 340px;
    }

    .ihm-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .ihm-pills {
        justify-content: flex-start;
    }
}
