/* ========================================================
   KOSPI Finviz Stock Heatmap CSS
   Finviz-identical Dark UI Theme
   ======================================================== */

:root {
    --bg-main: #0c0f14;
    --bg-header: #141821;
    --bg-panel: #1a202c;
    --bg-hover: #2d3748;
    --border-color: #232936;
    --border-light: #2d3748;
    
    --text-primary: #f7fafc;
    --text-secondary: #a0aec0;
    --text-muted: #718096;
    
    /* Finviz Color Scale (Global: Green = Up, Red = Down) */
    --c-gain-heavy: #10b981;
    --c-gain-mid: #059669;
    --c-gain-light: #047857;
    --c-neutral: #28303d;
    --c-loss-light: #991b1b;
    --c-loss-mid: #dc2626;
    --c-loss-heavy: #ef4444;

    /* Korean Market Color Scale (Red = Up, Blue = Down) */
    --kr-gain-heavy: #ef4444;
    --kr-gain-mid: #dc2626;
    --kr-gain-light: #b91c1c;
    --kr-neutral: #28303d;
    --kr-loss-light: #1d4ed8;
    --kr-loss-mid: #2563eb;
    --kr-loss-heavy: #3b82f6;

    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple SD Gothic Neo", "Malgun Gothic";
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    width: 100%;
    height: 100%;
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-family);
    overflow: hidden;
    user-select: none;
    -webkit-font-smoothing: antialiased;
}

#app-container {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
}

/* 1. Header Toolbar */
#top-toolbar {
    height: 58px;
    background-color: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    gap: 12px;
    flex-shrink: 0;
    z-index: 100;
}

.brand-section {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-logo {
    display: flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    color: #ffffff;
    font-size: 19px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.brand-badge {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
}

.market-status-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #10b981;
    box-shadow: 0 0 6px rgba(16, 185, 129, 0.6);
}

.status-dot.closed {
    background-color: #f59e0b;
    box-shadow: 0 0 6px rgba(245, 158, 11, 0.6);
}

.kospi-stat {
    font-weight: 700;
}

/* 한국 증시 표준 색상: 상승 빨강, 하락 파랑 (글로벌 초록 지원) */
.stat-up, .text-red { color: #ef4444 !important; }
.stat-down, .text-blue { color: #3b82f6 !important; }
.text-green { color: #10b981 !important; }

/* Coupang Partners Carousel Widget (400x50) */
.coupang-banner-container {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 400px;
    height: 50px;
    overflow: hidden;
    border-radius: 6px;
    background: transparent;
    flex-shrink: 0;
}

.coupang-banner-container iframe {
    display: block !important;
    border: none !important;
    max-width: 100% !important;
    margin: 0 auto !important;
    height: 50px !important;
}

.index-badge {
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid var(--border-color);
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11.5px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.index-badge strong {
    color: #e2e8f0;
}

/* Filter Controls */
.controls-section {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
}

.btn-group {
    display: inline-flex;
    background: #0f1217;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 2px;
}

.btn-pill {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-pill:hover {
    color: #ffffff;
}

.btn-pill.active {
    background: #2b3548;
    color: #ffffff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

.select-control {
    background: #0f1217;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 5px 10px;
    font-size: 12px;
    border-radius: 6px;
    outline: none;
    cursor: pointer;
}

.select-control:focus {
    border-color: #3b82f6;
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-input {
    background: #0f1217;
    border: 1px solid var(--border-color);
    color: #fff;
    padding: 5px 12px 5px 30px;
    font-size: 12px;
    border-radius: 6px;
    width: 140px;
    transition: width 0.2s ease, border-color 0.2s ease;
    outline: none;
}

.search-input:focus {
    width: 200px;
    border-color: #10b981;
}

.search-icon {
    position: absolute;
    left: 8px;
    color: var(--text-muted);
    font-size: 12px;
    pointer-events: none;
}

.btn-action {
    background: #1e2634;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 5px 10px;
    font-size: 12px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: background 0.15s ease;
}

.btn-action:hover {
    background: #2a3447;
}

/* 2. Main Heatmap Canvas Area */
#treemap-container {
    flex: 1;
    position: relative;
    width: 100%;
    height: calc(100vh - 52px - 34px);
    background-color: #0c0e12;
    overflow: hidden;
}

#treemap-svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* Sector Headers & Borders */
.sector-group {
    cursor: default;
}

.sector-rect {
    fill: #12161f;
    stroke: #0a0c10;
    stroke-width: 2px;
}

.sector-title {
    fill: #8f9ba8;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    pointer-events: none;
    user-select: none;
}

/* Stock Tiles */
.stock-node {
    cursor: pointer;
    transition: filter 0.12s ease;
}

.stock-node:hover {
    filter: brightness(1.22);
}

.stock-rect {
    stroke: #0c0f14;
    stroke-width: 1.5px;
    transition: fill 0.3s ease;
}

.stock-text {
    pointer-events: none;
    text-anchor: middle;
    user-select: none;
}

.stock-name {
    fill: #ffffff;
    font-weight: 800;
    letter-spacing: -0.2px;
}

.stock-perf {
    font-weight: 700;
    fill: #ffffff;
    opacity: 0.95;
}

.stock-sub {
    font-weight: 500;
    fill: rgba(255, 255, 255, 0.75);
    font-size: 10px;
}

/* Highlighting during search */
.stock-node.highlighted .stock-rect {
    stroke: #fbbf24;
    stroke-width: 3px;
    filter: drop-shadow(0 0 8px rgba(251, 191, 36, 0.8));
}

.stock-node.dimmed {
    opacity: 0.2;
}

/* 3. Bottom Ticker & Status Toolbar (코스피 · 코스닥 · 코스피 야간선물) */
#bottom-bar {
    min-height: 40px;
    background-color: var(--bg-header);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 16px;
    font-size: 11.5px;
    color: var(--text-secondary);
    flex-shrink: 0;
    gap: 12px;
    z-index: 100;
}

.bottom-indices-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
}

.bottom-index-badge {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 11.5px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: default;
    transition: background 0.15s ease, border-color 0.15s ease;
    white-space: nowrap;
}

.bottom-index-badge:hover {
    background: rgba(255, 255, 255, 0.09);
    border-color: #475569;
}

.bottom-index-badge .index-title {
    font-weight: 800;
    color: #cbd5e1;
}

.bottom-index-badge .index-val {
    font-weight: 700;
    color: #f8fafc;
    font-variant-numeric: tabular-nums;
}

.bottom-index-badge .index-change {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.night-futures-badge {
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.85) 0%, rgba(15, 23, 42, 0.95) 100%);
    border: 1px solid rgba(96, 165, 250, 0.35);
}

.night-futures-badge:hover {
    border-color: #60a5fa;
    background: linear-gradient(135deg, rgba(30, 58, 138, 0.4) 0%, rgba(15, 23, 42, 0.95) 100%);
}

.night-futures-badge .night-icon {
    font-size: 12px;
    line-height: 1;
}

.night-status-pill {
    font-size: 9px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 4px;
    letter-spacing: -0.2px;
}

.night-status-pill.status-open {
    background: rgba(59, 130, 246, 0.25);
    color: #93c5fd;
    border: 1px solid rgba(59, 130, 246, 0.4);
}

.night-status-pill.status-closed {
    background: rgba(148, 163, 184, 0.15);
    color: #94a3b8;
    border: 1px solid rgba(148, 163, 184, 0.3);
}

.footer-source-desc {
    color: var(--text-muted);
    font-size: 11px;
}

.legend-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-label {
    color: var(--text-muted);
}

.legend-bar {
    display: flex;
    border-radius: 3px;
    overflow: hidden;
    height: 18px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.legend-cell {
    width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    color: #ffffff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

.footer-info {
    display: flex;
    align-items: center;
    gap: 14px;
}

.sync-badge {
    color: var(--text-muted);
}

/* 4. Interactive Floating Tooltip */
#stock-tooltip {
    position: absolute;
    display: none;
    z-index: 9999;
    pointer-events: none;
    background: rgba(18, 24, 38, 0.95);
    backdrop-filter: blur(8px);
    border: 1px solid #323d52;
    border-radius: 8px;
    padding: 12px 14px;
    color: #ffffff;
    font-size: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
    min-width: 220px;
    transition: opacity 0.1s ease;
}

.tooltip-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 6px;
    margin-bottom: 8px;
}

.tooltip-title {
    font-size: 14px;
    font-weight: 800;
    color: #ffffff;
}

.tooltip-code {
    font-size: 11px;
    color: #94a3b8;
    font-family: monospace;
}

.tooltip-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    font-size: 11.5px;
}

.tooltip-label {
    color: #94a3b8;
}

.tooltip-val {
    font-weight: 600;
}

/* 5. Stock Detail Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.modal-content {
    background: #161c28;
    border: 1px solid #2b3648;
    border-radius: 12px;
    width: 440px;
    max-width: 90vw;
    box-shadow: 0 16px 40px rgba(0,0,0,0.8);
    overflow: hidden;
}

.modal-header {
    background: #1f2738;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #2b3648;
}

.modal-title-group h3 {
    font-size: 17px;
    font-weight: 800;
}

.modal-title-group span {
    font-size: 12px;
    color: #94a3b8;
}

.modal-close-btn {
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
}

.modal-body {
    padding: 20px;
}

.modal-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 14px;
}

.stat-card {
    background: #0f131a;
    border: 1px solid #232a36;
    padding: 10px 12px;
    border-radius: 8px;
}

.stat-card .lbl {
    font-size: 11px;
    color: #818cf8;
    margin-bottom: 2px;
}

.stat-card .val {
    font-size: 14px;
    font-weight: 700;
}

.modal-footer {
    padding: 14px 20px;
    background: #121620;
    border-top: 1px solid #2b3648;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.btn-external {
    background: #2563eb;
    color: #fff;
    text-decoration: none;
    padding: 8px 14px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-external:hover {
    background: #1d4ed8;
}

/* Loading Overlay */
#loading-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid #334155;
    padding: 14px 24px;
    border-radius: 8px;
    font-size: 13px;
    color: #e2e8f0;
    display: none;
    align-items: center;
    gap: 10px;
    z-index: 500;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.2);
    border-top-color: #10b981;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Kiwoom Live Sync Controls */
.btn-sync {
    background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%) !important;
    border-color: #3b82f6 !important;
    color: #ffffff !important;
    font-weight: 600 !important;
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.25);
    transition: all 0.2s ease;
}

.btn-sync:hover {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%) !important;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.45);
}

.btn-sync.syncing {
    background: #374151 !important;
    border-color: #6b7280 !important;
    cursor: wait !important;
    opacity: 0.9;
    box-shadow: none;
}

.live-update-badge {
    background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.35);
    color: #34d399;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11.5px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    letter-spacing: -0.2px;
}

/* Toast notification */
#toast-notification {
    position: fixed;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #1e293b;
    border: 1px solid #3b82f6;
    color: #f8fafc;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

#toast-notification.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

