/**
 * 토스 미니앱 - 주식 비교 차트 스타일
 * 개선: 섹터별 그룹, 날짜 선택, 모바일 최적화
 */

:root {
    --toss-blue: #3182F6;
    --toss-blue-light: #F2F8FF;
    --toss-blue-dark: #1b64da;
    --toss-gray-50: #F9FAFB;
    --toss-gray-100: #F2F4F6;
    --toss-gray-200: #E5E8EB;
    --toss-gray-300: #D1D6DB;
    --toss-gray-400: #B0B8C1;
    --toss-gray-500: #8B95A1;
    --toss-gray-600: #6B7684;
    --toss-gray-700: #4E5968;
    --toss-gray-800: #333D4B;
    --toss-gray-900: #191F28;
    --toss-white: #FFFFFF;
    --toss-red: #F04452;
    --toss-green: #3DBC6F;

    --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    --border-radius: 16px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    height: 100%;
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--toss-gray-50);
    color: var(--toss-gray-900);
    -webkit-text-size-adjust: 100%;
    overflow-x: hidden;
    line-height: 1.5;
}

#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding-bottom: 20px;
}

/* 헤더 */
.header {
    background: var(--toss-white);
    padding: 18px 24px;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.title {
    font-size: 22px;
    font-weight: 800;
    color: var(--toss-gray-900);
    letter-spacing: -0.5px;
}

/* 탭 네비게이션 */
.tab-nav {
    display: flex;
    background: var(--toss-white);
    padding: 0 8px;
    border-bottom: 1px solid var(--toss-gray-100);
}

.tab-btn {
    flex: 1;
    padding: 14px 0;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    font-size: 16px;
    font-weight: 700;
    color: var(--toss-gray-400);
    cursor: pointer;
    font-family: inherit;
    transition: var(--transition);
}

.tab-btn.active {
    color: var(--toss-blue);
    border-bottom-color: var(--toss-blue);
}

.tab-btn:hover {
    color: var(--toss-gray-800);
}

/* 탭 콘텐츠 */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* 검색 영역 */
.search-section {
    background: var(--toss-white);
    padding: 24px;
    margin: 12px 16px;
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
}

.search-label {
    font-size: 14px;
    font-weight: 700;
    color: #191F28;
    margin-bottom: 10px;
}

.search-container {
    flex: 1;
    position: relative;
}

.search-row {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

#search-input,
#unified-input,
#per-input {
    width: 100%;
    background: var(--toss-gray-100);
    border: 1px solid transparent;
    border-radius: var(--border-radius);
    padding: 14px 18px;
    font-size: 16px;
    color: var(--toss-gray-900);
    font-family: inherit;
    transition: var(--transition);
}

#search-input:focus,
#unified-input:focus,
#per-input:focus {
    outline: none;
    border-color: var(--toss-blue);
    background: var(--toss-white);
    box-shadow: 0 0 0 4px rgba(49, 130, 246, 0.12);
}

#unified-input::placeholder,
#per-input::placeholder {
    color: var(--toss-gray-400);
}

.search-results {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: var(--toss-white);
    border-radius: var(--border-radius);
    padding: 8px 0;
    max-height: 280px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
    border: 1px solid var(--toss-gray-100);
}

.search-results.hidden {
    display: none;
}

.search-result-item {
    padding: 14px 20px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: var(--transition);
}

.search-result-item:hover {
    background: var(--toss-gray-50);
}

.search-result-item .name {
    font-size: 14px;
    color: #191F28;
}

.search-result-item .symbol {
    font-size: 13px;
    color: #3182F6;
    font-weight: 600;
}

.divider {
    height: 1px;
    background: #E5E8EB;
    margin: 16px 0;
}

.search-hint {
    font-size: 12px;
    color: #ADB5BD;
    margin-top: 6px;
    margin-bottom: 12px;
}

#ticker-input {
    flex: 1;
    min-width: 0;
    background: #F7F8FA;
    border: 1px solid #E5E8EB;
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 16px;
    color: #191F28;
    font-family: inherit;
    text-transform: uppercase;
}

#ticker-input::placeholder {
    color: #ADB5BD;
    text-transform: none;
}

#ticker-input:focus {
    outline: none;
    border-color: #3182F6;
}

.btn-add {
    width: 52px;
    height: 52px;
    background: var(--toss-blue);
    color: var(--toss-white);
    border: none;
    border-radius: var(--border-radius);
    font-size: 28px;
    font-weight: 300;
    cursor: pointer;
    flex-shrink: 0;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-add:hover {
    background: var(--toss-blue-dark);
    transform: scale(1.05);
}

.btn-add:active {
    transform: scale(0.95);
}

/* 티커 태그 */
.ticker-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 32px;
}

.ticker-tag {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #F7F8FA;
    border: 1px solid #E5E8EB;
    border-radius: 16px;
    padding: 6px 8px 6px 12px;
}

.tag-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.tag-name {
    font-size: 13px;
    font-weight: 600;
    color: #191F28;
}

.tag-remove {
    background: none;
    border: none;
    color: #8B95A1;
    font-size: 16px;
    padding: 0;
    cursor: pointer;
    min-width: 20px;
    min-height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 섹터별 빠른 선택 */
.sector-section {
    background: var(--toss-white);
    padding: 16px 24px;
    margin: 0 16px 12px;
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    max-height: 280px;
    overflow-y: auto;
}

/* Global Filter 래퍼 */
.global-filter {
    margin-bottom: 4px;
}

.global-filter .global-search {
    margin-bottom: 0;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.global-filter .sector-section {
    margin-top: 0;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}

.sector-group {
    margin-bottom: 14px;
}

.sector-group:last-child {
    margin-bottom: 0;
}

.sector-title {
    font-size: 13px;
    font-weight: 600;
    color: #4E5968;
    margin-bottom: 8px;
}

.sector-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chip {
    background: var(--toss-white);
    border: 1px solid var(--toss-gray-200);
    border-radius: 20px;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 600;
    color: var(--toss-gray-700);
    cursor: pointer;
    font-family: inherit;
    transition: var(--transition);
    user-select: none;
    white-space: nowrap;
}

.chip:hover {
    background: var(--toss-gray-50);
    border-color: var(--toss-gray-300);
    transform: translateY(-1px);
}

.chip:active {
    background: var(--toss-blue-light);
    border-color: var(--toss-blue);
    color: var(--toss-blue);
    transform: translateY(0) scale(0.96);
}

/* ===== 모바일: 섹터칩 가로 스크롤 ===== */
@media (max-width: 768px) {
    .sector-section {
        max-height: none;
        overflow-y: visible;
        padding: 12px 16px;
    }

    .sector-scroll-container {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .sector-group {
        margin-bottom: 0;
    }

    .sector-chips {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
        gap: 6px;
    }

    /* 스크롤바 숨기기 (기능은 유지) */
    .sector-chips::-webkit-scrollbar {
        display: none;
    }

    .sector-chips {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

    .chip {
        padding: 8px 14px;
        font-size: 13px;
        flex-shrink: 0;
    }

    .sector-title {
        font-size: 12px;
        margin-bottom: 6px;
    }
}

/* 날짜 선택 */
.date-section {
    background: var(--toss-white);
    padding: 24px;
    margin: 12px 16px;
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
}

.date-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-bottom: 12px;
}

.date-field {
    flex: 1;
}

.date-field label {
    display: block;
    font-size: 12px;
    color: #8B95A1;
    margin-bottom: 4px;
}

.date-field input {
    width: 100%;
    background: #F7F8FA;
    border: 1px solid #E5E8EB;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
    color: #191F28;
    font-family: inherit;
}

.date-sep {
    color: #8B95A1;
    padding-bottom: 10px;
}

.btn-apply {
    background: #3182F6;
    color: #FFFFFF;
    border: none;
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    height: 40px;
}

.quick-periods {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 4px;
}

.period-chip {
    background: #F7F8FA;
    border: none;
    border-radius: 16px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    color: #8B95A1;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
}

.period-chip.active {
    background: #3182F6;
    color: #FFFFFF;
}

/* 차트 영역 */
.chart-section {
    background: #FFFFFF;
    margin-top: 8px;
    padding: 16px 0;
    flex: 1;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px 12px;
}

.chart-title {
    font-size: 16px;
    font-weight: 700;
    color: #191F28;
}

.chart-unit {
    font-size: 13px;
    color: #8B95A1;
}

#chart-container {
    width: 100%;
    height: 260px;
}

/* 범례 */
.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 20px 0;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.legend-name {
    font-size: 12px;
    font-weight: 600;
    color: #191F28;
}

.legend-value {
    font-size: 12px;
    font-weight: 700;
}

.legend-value.up {
    color: #00C853;
}

.legend-value.down {
    color: #FF5252;
}

/* 로딩 */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading.hidden {
    display: none;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #E5E8EB;
    border-top-color: #3182F6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* 히트맵 탭 스타일 */
.heatmap-section {
    padding: 24px;
    margin: 12px 16px;
    background: var(--toss-white);
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
}

.heatmap-header {
    margin-bottom: 24px;
}

.heatmap-title {
    font-size: 22px;
    font-weight: 800;
    color: var(--toss-gray-900);
    margin-bottom: 8px;
}

.heatmap-desc {
    font-size: 14px;
    color: var(--toss-gray-600);
}

.heatmap-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
    min-height: 300px;
}

.heatmap-box {
    aspect-ratio: 1 / 1;
    border-radius: 8px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: var(--transition);
    color: var(--toss-white);
    text-align: center;
}

.heatmap-box:hover {
    transform: scale(1.05);
    z-index: 10;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

.hb-ticker {
    font-size: 16px;
    font-weight: 800;
}

.hb-change {
    font-size: 13px;
    font-weight: 700;
    margin: 2px 0;
}

.hb-name {
    font-size: 10px;
    opacity: 0.8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

/* 히트맵 색상 단계 */
.heatmap-box.up-deep {
    background: #F04452;
}

/* 강한 상승 (붉은색 - 한국 기준) */
.heatmap-box.up {
    background: #FF8A92;
}

.heatmap-box.neutral {
    background: #E5E8EB;
    color: #6B7684;
}

.heatmap-box.down {
    background: #7EB1FF;
}

.heatmap-box.down-deep {
    background: #3182F6;
}

/* 강한 하락 (파란색 - 한국 기준) */

/* 미국 주식 색상 기준인 경우 (상승 초록, 하락 빨강) 도 고려할 수 있으나, 
   사용자의 기존 요청 맥락(한국 주식 포함)에 맞춰 한국식/토스식으로 설정 */

.heatmap-legend {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--toss-gray-100);
}

.legend-box {
    font-size: 11px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 4px;
    color: var(--toss-white);
}

.heatmap-loading,
.heatmap-error {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 0;
    color: var(--toss-gray-500);
}

@media (max-width: 480px) {
    .heatmap-container {
        grid-template-columns: repeat(3, 1fr);
    }

    .heatmap-box {
        padding: 8px;
    }

    .hb-ticker {
        font-size: 14px;
    }

    .hb-change {
        font-size: 11px;
    }
}

/* 탭 네비게이션 개선 (공통) */
.tab-nav {
    display: flex;
    background: var(--toss-white);
    padding: 0 8px;
    border-bottom: 1px solid var(--toss-gray-100);
    position: sticky;
    top: 58px;
    /* 헤더 높이만큼 */
    z-index: 900;
}

/* 탭 네비게이션 */
.tab-nav {
    display: flex;
    background: #FFFFFF;
    border-bottom: 1px solid #E5E8EB;
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    padding: 14px 16px;
    font-size: 15px;
    font-weight: 600;
    color: #8B95A1;
    cursor: pointer;
    font-family: inherit;
    position: relative;
}

.tab-btn.active {
    color: #3182F6;
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: #3182F6;
}

/* 탭 콘텐츠 */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* 히트맵 기간 선택 */
.heatmap-period-section {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    background: #FFFFFF;
    overflow-x: auto;
}

.heatmap-period-btn {
    background: #F7F8FA;
    border: none;
    border-radius: 20px;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 600;
    color: #8B95A1;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
}

.heatmap-period-btn.active {
    background: #3182F6;
    color: #FFFFFF;
}

/* 지표 선택 */
.metric-section {
    display: flex;
    gap: 8px;
    padding: 8px 16px;
    background: #FFFFFF;
    overflow-x: auto;
}

.metric-btn {
    background: #FFFFFF;
    border: 1px solid #E5E8EB;
    border-radius: 16px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    color: #4E5968;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
}

.metric-btn.active {
    background: #191F28;
    border-color: #191F28;
    color: #FFFFFF;
}

/* 히트맵 필터 */
.heatmap-filter-section {
    display: flex;
    gap: 8px;
    padding: 8px 16px 12px;
    background: #FFFFFF;
    border-bottom: 1px solid #E5E8EB;
    overflow-x: auto;
}

.filter-btn {
    background: #FFFFFF;
    border: 1px solid #E5E8EB;
    border-radius: 16px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    color: #4E5968;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
}

.filter-btn.active {
    background: #191F28;
    border-color: #191F28;
    color: #FFFFFF;
}

/* 히트맵 그리드 - Finviz 스타일 */
.heatmap-section {
    padding: 0;
    background: #0b0e11;
    min-height: calc(100vh - 280px);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.heatmap-grid {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    min-width: 100%;
    height: auto;
    background: #0b0e11;
}

/* Finviz 섹터 컨테이너 */
.finviz-sector {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    border-right: 1px solid #1a1d21;
}

.finviz-sector-header {
    background: #1a1d21;
    color: #888;
    padding: 4px 6px;
    font-size: 9px;
    font-weight: bold;
    text-align: center;
    letter-spacing: 0.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.finviz-stocks {
    flex: 1;
    background: #0b0e11;
}

.heatmap-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: transform 0.15s;
    flex: 1 1 80px;
    min-width: 60px;
    min-height: 60px;
}

.heatmap-cell:active {
    transform: scale(0.95);
}

.cell-symbol {
    font-size: 12px;
    font-weight: 700;
    color: #FFFFFF;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.cell-change {
    font-size: 11px;
    font-weight: 600;
    color: #FFFFFF;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    margin-top: 2px;
}

/* 히트맵 범례 */
.heatmap-legend {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    background: #191F28;
}

.legend-bar {
    width: 150px;
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(to right, #d63031, #636e72, #00b894);
}

.heatmap-legend .legend-label {
    font-size: 12px;
    color: #8B95A1;
    font-weight: 500;
}

/* 히트맵 로딩/에러 메시지 */
.heatmap-loading,
.heatmap-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 300px;
    color: #FFFFFF;
    font-size: 16px;
    font-weight: 600;
    background: rgba(30, 35, 45, 0.9);
    border-radius: 12px;
}

/* Finviz Treemap 스타일 */
.treemap-sector {
    display: flex;
    flex-direction: column;
    background: #1a1d21;
    border-radius: 4px;
    overflow: hidden;
    min-width: 100px;
    margin: 2px;
    flex: 1;
}

.sector-header {
    background: #2a2e35;
    color: #a0a8b3;
    padding: 4px 8px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    text-align: center;
    border-bottom: 1px solid #3a3e45;
}

.stocks-grid {
    display: flex;
    flex-wrap: wrap;
    padding: 2px;
    gap: 1px;
}

.treemap-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
    border: 1px solid rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.treemap-cell:hover {
    z-index: 10;
    transform: scale(1.08);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.cell-ticker {
    font-size: 11px;
    font-weight: 700;
    color: #FFFFFF;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}

.cell-ticker-small {
    font-size: 8px;
    font-weight: 700;
    color: #FFFFFF;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}

.cell-price {
    font-size: 9px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}

.treemap-cell .cell-change {
    font-size: 9px;
    margin-top: 0;
}

/* 종목 상세 팝업 */
.stock-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #1a1d21;
    border: 1px solid #3182F6;
    border-radius: 12px;
    padding: 16px;
    min-width: 260px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #333;
}

.popup-ticker {
    font-size: 20px;
    font-weight: 700;
    color: #FFFFFF;
}

.popup-close {
    background: none;
    border: none;
    color: #888;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.popup-close:hover {
    color: #fff;
}

.popup-content {
    margin-bottom: 16px;
}

.popup-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #2a2e35;
}

.popup-row:last-child {
    border-bottom: none;
}

.popup-label {
    color: #888;
    font-size: 13px;
}

.popup-value {
    color: #fff;
    font-size: 14px;
    font-weight: 600;
}

.popup-value.up {
    color: #30cc5a;
}

.popup-value.down {
    color: #f23645;
}

.popup-chart-btn {
    width: 100%;
    padding: 12px;
    background: #3182F6;
    border: none;
    border-radius: 8px;
    color: #FFFFFF;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.popup-chart-btn:hover {
    background: #1a6dd9;
}

/* 섹터 종목 리스트 모달 */
.sector-list-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #1a1d21;
    border: 1px solid #3182F6;
    border-radius: 12px;
    width: 90%;
    max-width: 450px;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

.sector-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid #333;
}

.sector-list-title {
    font-size: 18px;
    font-weight: 700;
    color: #FFFFFF;
}

.sector-list-close {
    background: none;
    border: none;
    color: #888;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.sector-list-close:hover {
    color: #fff;
}

.sector-list-subheader {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    padding: 8px 16px;
    background: #2a2e35;
    color: #888;
    font-size: 11px;
    font-weight: 600;
}

.sector-list-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.sector-list-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    padding: 12px 16px;
    border-bottom: 1px solid #2a2e35;
    cursor: pointer;
    transition: background 0.15s;
}

.sector-list-row:hover {
    background: #2a2e35;
}

.sl-ticker {
    font-weight: 600;
    color: #fff;
}

.sl-price {
    color: #ccc;
}

.sl-change {
    font-weight: 600;
}

.sl-change.up {
    color: #30cc5a;
}

.sl-change.down {
    color: #f23645;
}

.sl-cap {
    color: #888;
    font-size: 12px;
}

/* 지표 선택 */
.metric-section {
    background: transparent;
    padding: 12px 0;
    margin: 0 16px;
    box-shadow: none;
    border-radius: 0;
}

.metric-label {
    display: none;
    /* 레이블 숨김으로 더 깔끔하게 */
}

.metric-chips {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 12px;
    padding: 8px 4px;
    -webkit-overflow-scrolling: touch;
}

.metric-chips::-webkit-scrollbar {
    display: none;
}

.metric-chip {
    padding: 10px 20px;
    border: 1px solid var(--toss-gray-200);
    border-radius: 50px;
    /* 알약 형태 */
    background: var(--toss-white);
    font-size: 14px;
    font-weight: 600;
    color: var(--toss-gray-500);
    cursor: pointer;
    font-family: inherit;
    transition: var(--transition);
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}

.metric-chip:hover {
    border-color: var(--toss-gray-300);
    background: var(--toss-gray-50);
}

.metric-chip.active {
    background: var(--toss-blue);
    color: var(--toss-white);
    border-color: var(--toss-blue);
    box-shadow: 0 4px 12px rgba(49, 130, 246, 0.3);
}

/* FWD PER 섹션 */
.per-section {
    background: var(--toss-white);
    padding: 28px 24px;
    margin: 12px 16px;
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
}

.per-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
}

.per-header-left {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.per-header-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.per-title {
    font-size: 20px;
    font-weight: 800;
    color: var(--toss-gray-900);
}

.metric-description {
    font-size: 14px;
    color: var(--toss-gray-600);
    line-height: 1.5;
}

.update-badge {
    font-size: 12px;
    font-weight: 700;
    color: var(--toss-blue);
    background: var(--toss-blue-light);
    padding: 4px 10px;
    border-radius: 8px;
    white-space: nowrap;
}

.per-source {
    font-size: 12px;
    color: var(--toss-gray-400);
    margin-top: 4px;
}

/* 푸터 및 면책 조항 */
.app-footer {
    padding: 40px 24px;
    background: #F9FAFB;
    border-top: 1px solid #E5E8EB;
    margin-top: 40px;
}

.disclaimer {
    max-width: 800px;
    margin: 0 auto;
    font-size: 12px;
    color: #8B95A1;
    line-height: 1.6;
}

.disclaimer p {
    margin-bottom: 8px;
}

.disclaimer strong {
    color: #4E5968;
}

.per-sort {
    display: flex;
    gap: 4px;
}

.sort-btn {
    padding: 6px 10px;
    border: 1px solid #E5E8EB;
    border-radius: 8px;
    background: #F7F8FA;
    font-size: 12px;
    color: #4E5968;
    cursor: pointer;
    font-family: inherit;
}

.sort-btn.active {
    background: #3182F6;
    color: #FFFFFF;
    border-color: #3182F6;
}

.per-empty {
    text-align: center;
    padding: 40px 20px;
    color: #8B95A1;
    font-size: 14px;
}

/* PER 테이블 컨테이너 (모바일 스크롤 지원) */
#per-table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    margin: 0 -4px;
    padding: 0 4px;
}

/* PER 테이블 */
.per-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 15px;
    min-width: 600px;
    /* 모바일에서 테이블이 찌그러지지 않도록 최소 너비 보장 */
}

.per-table thead th {
    padding: 14px 12px;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    color: var(--toss-white);
    background: var(--toss-blue);
    /* 파란색 배경 헤더 */
    border-bottom: none;
    white-space: nowrap;
}

/* 첫 번째 헤더(종목명) 스타일 */
.per-table thead th:first-child {
    border-top-left-radius: 12px;
    text-align: left;
    padding-left: 18px;
}

/* 마지막 헤더 스타일 */
.per-table thead th:last-child {
    border-top-right-radius: 12px;
}

.per-table tbody tr {
    transition: var(--transition);
    border-bottom: 1px solid var(--toss-gray-100);
}

.per-table tbody tr:hover {
    background: var(--toss-blue-light);
    transform: none;
    /* 테이블 로우 스케일링은 가독성을 위해 제거 */
}

.per-table td {
    padding: 16px 10px;
    vertical-align: middle;
}

.td-name {
    min-width: 100px;
}

.stock-name {
    font-weight: 700;
    color: var(--toss-gray-900);
    font-size: 15px;
    line-height: 1.3;
}

.stock-ticker {
    font-size: 13px;
    color: var(--toss-gray-500);
    font-weight: 500;
}

.td-price {
    font-weight: 600;
    color: var(--toss-gray-900);
    white-space: nowrap;
}

.td-per {
    text-align: center;
}

.per-value {
    font-weight: 800;
    font-size: 17px;
    display: block;
    letter-spacing: -0.2px;
}

.per-grade {
    font-size: 12px;
    font-weight: 700;
    display: block;
    margin-top: 4px;
}

.td-eps {
    color: #4E5968;
    text-align: right;
    white-space: nowrap;
}

/* PER 바 차트 */
.per-bars {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid #E5E8EB;
}

.per-bars-title {
    font-size: 14px;
    font-weight: 600;
    color: #4E5968;
    margin-bottom: 12px;
}

.per-bar-row {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    gap: 8px;
}

.per-bar-label {
    width: 80px;
    font-size: 12px;
    font-weight: 600;
    color: #191F28;
    text-align: right;
    flex-shrink: 0;
}

.per-bar-track {
    flex: 1;
    height: 20px;
    background: #F2F4F6;
    border-radius: 4px;
    overflow: hidden;
}

.per-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
}

.per-bar-value {
    width: 50px;
    font-size: 13px;
    font-weight: 700;
    text-align: right;
    flex-shrink: 0;
}

/* 모바일 대응 */
@media (max-width: 480px) {
    .per-table {
        font-size: 12px;
    }

    .per-value {
        font-size: 14px;
    }

    .per-header {
        flex-direction: column;

        .per-bar-label {
            width: 60px;
            font-size: 11px;
        }
    }
}

/* 경제 지표 탭 스타일 */
.macro-section {
    padding: 24px;
    margin: 12px 16px;
    background: var(--toss-white);
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
}

.macro-header {
    margin-bottom: 28px;
}

.macro-title {
    font-size: 22px;
    font-weight: 800;
    color: var(--toss-gray-900);
    margin-bottom: 8px;
}

.macro-desc {
    font-size: 14px;
    color: var(--toss-gray-600);
    line-height: 1.5;
}

.macro-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.macro-card {
    background: var(--toss-gray-50);
    border: 1px solid var(--toss-gray-100);
    border-radius: 20px;
    padding: 20px;
    transition: var(--transition);
    cursor: pointer;
    /* 클릭 커서 강제 */
    position: relative;
    /* z-index 맥락 생성 */
}

.macro-card:hover {
    border-color: var(--toss-blue);
    background: var(--toss-white);
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.05);
}

.mc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.mc-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--toss-gray-900);
}

.link-icon {
    font-size: 12px;
    color: var(--toss-gray-400);
    margin-left: 4px;
    vertical-align: middle;
}

.mc-symbol {
    font-size: 11px;
    font-weight: 600;
    color: var(--toss-gray-400);
    background: var(--toss-white);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid var(--toss-gray-100);
}

.mc-value-row {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 8px;
}

.mc-mini-chart {
    height: 80px;
    margin: 10px -10px 0 -10px;
    pointer-events: none;
}

.mc-chart-dates {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: var(--toss-gray-400);
    margin-bottom: 12px;
    padding: 0 2px;
}

.no-chart {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--toss-gray-400);
    font-size: 12px;
}

.mc-value {
    font-size: 24px;
    font-weight: 800;
    color: var(--toss-gray-900);
    letter-spacing: -0.5px;
}

.mc-change {
    font-size: 14px;
    font-weight: 700;
}

.mc-change.up {
    color: var(--toss-red);
}

.mc-change.down {
    color: var(--toss-blue);
}

.mc-desc {
    font-size: 13px;
    color: var(--toss-gray-600);
    line-height: 1.4;
    padding-top: 12px;
    border-top: 1px solid var(--toss-gray-100);
}

.macro-loading-inner {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 0;
}

@media (max-width: 480px) {
    .macro-grid {
        grid-template-columns: 1fr;
    }
}

/* 한줄 요약 박스 (신호등 포함) */
.macro-summary-box {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    background: linear-gradient(135deg, #F0F6FF, #E8F5E9);
    border: 1px solid #D0E3FF;
    border-radius: 16px;
    margin-bottom: 20px;
    transition: all 0.3s ease;
}

.traffic-light {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
    background: #2a2a2a;
    padding: 8px 6px;
    border-radius: 12px;
}

.tl-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    transition: all 0.3s ease;
}

.tl-dot.active {
    background: var(--dot-color);
    box-shadow: 0 0 8px var(--dot-color), 0 0 16px var(--dot-color);
    animation: glow 2s ease-in-out infinite alternate;
}

@keyframes glow {
    from {
        box-shadow: 0 0 6px var(--dot-color);
    }

    to {
        box-shadow: 0 0 14px var(--dot-color), 0 0 20px var(--dot-color);
    }
}

.summary-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.summary-label {
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.summary-text {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--toss-gray-800);
    line-height: 1.7;
    word-break: keep-all;
}

/* 순유동성 카드 */
.net-liquidity-card {
    background: linear-gradient(135deg, #1a1f36 0%, #2d1b4e 100%) !important;
    border: none !important;
    color: #fff;
}

.net-liquidity-card .mc-name {
    color: #fff;
    font-size: 18px;
}

.net-liquidity-card .mc-symbol {
    background: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.net-liquidity-card .mc-value {
    color: #fff;
    font-size: 28px;
}

.net-liquidity-card .mc-desc {
    color: rgba(255, 255, 255, 0.7);
    border-top-color: rgba(255, 255, 255, 0.15);
}

.net-liquidity-card .mc-chart-dates span {
    color: rgba(255, 255, 255, 0.5);
}

.net-liquidity-card:hover {
    background: linear-gradient(135deg, #232847 0%, #3a2363 100%) !important;
    border-color: transparent !important;
    transform: translateY(-4px);
    box-shadow: 0 16px 32px rgba(45, 27, 78, 0.3);
}

.nl-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    color: #FFD700;
    background: rgba(255, 215, 0, 0.15);
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 6px;
    vertical-align: middle;
    letter-spacing: 0.5px;
}

/* ========================
   AI 채팅 섹션 스타일
   ======================== */
.ai-section {
    margin: 12px 16px;
    background: var(--toss-white);
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 160px);
}

.ai-header {
    padding: 24px 24px 16px;
}

.ai-title {
    font-size: 22px;
    font-weight: 800;
    color: var(--toss-gray-900);
    margin-bottom: 6px;
}

.ai-desc {
    font-size: 14px;
    color: var(--toss-gray-600);
    line-height: 1.5;
}

/* 추천 질문 */
.ai-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 24px 16px;
}

.ai-suggest-btn {
    padding: 8px 14px;
    border: 1px solid var(--toss-gray-200);
    border-radius: 20px;
    background: var(--toss-gray-50);
    font-size: 13px;
    color: var(--toss-gray-700);
    cursor: pointer;
    font-family: inherit;
    transition: var(--transition);
    white-space: nowrap;
}

.ai-suggest-btn:hover {
    border-color: var(--toss-blue);
    color: var(--toss-blue);
    background: var(--toss-blue-light);
}

/* 채팅 컨테이너 */
.ai-chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 0 24px;
    min-height: 300px;
    max-height: 50vh;
    -webkit-overflow-scrolling: touch;
}

.ai-messages {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 8px 0;
}

/* 메시지 */
.ai-message {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    animation: fadeInUp 0.3s ease;
}

.ai-message.ai-user {
    flex-direction: row-reverse;
}

.ai-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--toss-gray-100);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.ai-message.ai-user .ai-avatar {
    background: var(--toss-blue-light);
}

.ai-bubble {
    max-width: 80%;
    padding: 14px 18px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.7;
    color: var(--toss-gray-900);
    word-break: break-word;
}

.ai-message.ai-bot .ai-bubble {
    background: var(--toss-gray-50);
    border: 1px solid var(--toss-gray-100);
    border-top-left-radius: 4px;
}

.ai-message.ai-user .ai-bubble {
    background: var(--toss-blue);
    color: white;
    border-top-right-radius: 4px;
}

/* 마크다운 렌더링 */
.ai-bubble h2,
.ai-bubble h3,
.ai-bubble h4 {
    margin: 12px 0 6px;
    font-weight: 700;
}

.ai-bubble h2 {
    font-size: 17px;
}

.ai-bubble h3 {
    font-size: 15px;
}

.ai-bubble h4 {
    font-size: 14px;
}

.ai-bubble ul,
.ai-bubble ol {
    margin: 8px 0;
    padding-left: 20px;
}

.ai-bubble li {
    margin-bottom: 4px;
}

.ai-bubble pre {
    background: var(--toss-gray-900);
    color: #e0e0e0;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 13px;
    margin: 8px 0;
}

.ai-bubble code.inline-code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

.ai-bubble strong {
    font-weight: 700;
    color: inherit;
}

/* 타이핑 애니메이션 */
.ai-typing {
    padding: 16px 20px !important;
}

.typing-dots {
    display: flex;
    gap: 6px;
    align-items: center;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--toss-gray-400);
    animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.4;
    }

    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 입력 영역 */
.ai-input-area {
    padding: 16px 24px 20px;
    border-top: 1px solid var(--toss-gray-100);
}

.ai-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.ai-input {
    flex: 1;
    padding: 12px 16px;
    border: 1.5px solid var(--toss-gray-200);
    border-radius: 16px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
    line-height: 1.5;
    max-height: 120px;
    min-height: 44px;
}

.ai-input:focus {
    border-color: var(--toss-blue);
}

.ai-input::placeholder {
    color: var(--toss-gray-400);
}

.ai-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--toss-blue);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: var(--transition);
}

.ai-send-btn:hover {
    background: var(--toss-blue-dark);
    transform: scale(1.05);
}

.ai-send-btn:disabled {
    background: var(--toss-gray-300);
    cursor: not-allowed;
    transform: none;
}

.ai-input-hint {
    font-size: 11px;
    color: var(--toss-gray-400);
    margin-top: 8px;
    text-align: center;
}

/* 모바일 대응 */
@media (max-width: 480px) {
    .ai-section {
        margin: 8px;
        max-height: calc(100vh - 140px);
    }

    .ai-chat-container {
        max-height: 45vh;
        padding: 0 14px;
    }

    .ai-bubble {
        max-width: 88%;
        font-size: 13px;
        padding: 12px 14px;
    }

    .ai-header {
        padding: 16px 16px 12px;
    }

    .ai-suggestions {
        padding: 0 16px 12px;
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    .ai-suggest-btn {
        font-size: 12px;
        flex-shrink: 0;
    }

    .ai-input-area {
        padding: 12px 14px 16px;
    }
}