/* ══════════════════════════════════════════════════════
   주식시장 대시보드 V2 — shadcn/ui Light Theme
   ══════════════════════════════════════════════════════ */

:root {
    /* ── shadcn light palette (20260409: 눈피로 완화 명도/대비 조정) ── */
    --background:    hsl(220 14% 98%);   /* 100% → 98% 오프화이트 */
    --foreground:    hsl(240 10% 12%);   /* 3.9% → 12% 순흑 회피 */
    --card:          hsl(0 0% 100%);
    --card-fg:       hsl(240 10% 12%);

    --muted:         hsl(240 4.8% 95.9%);
    --muted-fg:      hsl(240 3.8% 42%);  /* 46% → 42% 가독성 보강 */

    --accent:        hsl(240 4.8% 95.9%);
    --accent-fg:     hsl(240 5.9% 10%);

    --primary:       hsl(240 5.9% 10%);
    --primary-fg:    hsl(0 0% 98%);

    --secondary:     hsl(240 4.8% 95.9%);
    --secondary-fg:  hsl(240 5.9% 10%);

    --destructive:   hsl(0 84.2% 60.2%);
    --destructive-fg: hsl(0 0% 98%);

    --border:        hsl(240 5.9% 87%);  /* 90% → 87% 카드 경계 강화 */
    --input:         hsl(240 5.9% 87%);
    --ring:          hsl(240 5.9% 10%);

    /* ── 금융 시맨틱 색상 (한국 주식시장 기준) ── */
    /* 상승 = 빨강, 하락 = 파랑 (한국/일본/중국 증시 표준) */
    --up:            hsl(0 85% 48%);
    --up-soft:       hsla(0, 85%, 55%, 0.08);
    --down:          hsl(217 85% 48%);
    --down-soft:     hsla(217, 85%, 55%, 0.08);
    --warn:          hsl(38 92% 45%);
    --blue:          hsl(217 91% 50%);
    --blue-soft:     hsla(217, 91%, 60%, 0.08);

    /* ── 타이포그래피 ── */
    --font-sans: 'Pretendard Variable', 'Pretendard', -apple-system, BlinkMacSystemFont, 'Malgun Gothic', '맑은 고딕', 'Segoe UI', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', 'D2Coding', 'Fira Code', 'Cascadia Code', monospace;

    /* ── 레이아웃 ── */
    --radius-sm: 6px;
    --radius:    8px;
    --radius-lg: 12px;
    --radius-xl: 16px;

    /* ── 브레이크포인트 (20260417 표준화: 3단 mobile/tablet/desktop) ── */
    /* CSS 변수는 @media query 에 사용 불가. 이 값은 참조용 문서화:
       모바일: max-width 480px  (세로폰)
       태블릿: 481 ~ 1024px     (가로폰 + 태블릿)
       데스크톱: 1025px+         (PC)
       기존 480/760/768 혼용 → 점진 정리 중. 신규 코드는 480/1024 권장. */
}

.at-holdings-scroll {
    max-height: 386px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card);
}
.at-holdings-scroll .data-table {
    margin: 0;
}
.at-holdings-scroll .data-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--muted);
}
.at-holdings-scroll .data-table tfoot td {
    position: sticky;
    bottom: 0;
    z-index: 2;
    background: var(--card);
    box-shadow: 0 -1px 0 var(--border);
}
.at-holdings-scroll .data-table.compact th,
.at-holdings-scroll .data-table.compact td {
    padding-top: 6px;
    padding-bottom: 6px;
}

.at-main-tabs {
    display: grid;
    /* 2026-04-24: 3탭 → 4탭 (매매 실행 탭 신규) */
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    margin: 0 0 12px;
}

/* 2026-04-24: 거래 기록 필터 active 표시 */
.at-trade-filters .btn-outline.is-active {
    background: var(--blue-soft);
    border-color: var(--blue);
    color: var(--foreground);
    font-weight: 600;
}
.at-trade-filters .btn-outline {
    padding: 3px 10px;
    font-size: 11px;
}
.at-main-tab {
    min-height: 42px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card);
    color: var(--muted-fg);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}
.at-main-tab.is-active {
    border-color: var(--blue);
    background: var(--blue-soft);
    color: var(--foreground);
}
.at-main-panel {
    display: none;
    margin-bottom: 12px;
}
.at-main-panel.is-active {
    display: block;
}
.at-settings-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.at-setting-action-tabs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(126px, 1fr));
    gap: 8px;
    margin: 8px 0 12px;
}
.at-setting-action-tab {
    min-height: 54px;
    padding: 8px 10px;
    text-align: left;
    border-radius: var(--radius-sm);
    background: var(--background);
}
.at-setting-action-tab b {
    display: block;
    font-size: 12px;
    line-height: 1.25;
}
.at-setting-action-tab small {
    display: block;
    margin-top: 3px;
    color: var(--muted-fg);
    font-size: 10px;
    line-height: 1.25;
}
.at-setting-action-tab:hover {
    border-color: var(--blue);
    background: var(--blue-soft);
}
.at-section-label {
    margin: 0 0 8px;
    font-size: 13px;
    font-weight: 800;
}
.at-settings-split-note {
    margin: 0 0 10px;
    color: var(--muted-fg);
    font-size: 12px;
}
.at-setup-launch-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}
.at-setup-launch-card {
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card);
    cursor: pointer;
    text-align: left;
    transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.at-setup-launch-card:hover {
    border-color: var(--blue);
    background: var(--blue-soft);
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
}
.at-setup-launch-card.is-live {
    border-color: rgba(25, 118, 210, 0.35);
}
.at-setup-launch-head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: flex-start;
    margin-bottom: 10px;
}
.at-setup-launch-meta {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.at-setup-launch-meta span,
.at-portfolio-tags span {
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--background);
    color: var(--muted-fg);
    padding: 3px 8px;
    font-size: 11px;
    white-space: nowrap;
}
.at-portfolio-manager {
    margin: 12px 0;
}
.at-portfolio-manager-head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.at-portfolio-card-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}
.at-portfolio-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card);
    padding: 12px;
}
.at-portfolio-card.is-current {
    border-color: var(--blue);
    background: var(--blue-soft);
}
.at-portfolio-card-head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: flex-start;
    margin-bottom: 10px;
}
.at-portfolio-tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.at-portfolio-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.at-flow-steps {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 12px;
}
.at-flow-steps > div {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card);
    color: var(--muted-fg);
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 700;
    text-align: center;
}
.at-flow-steps > .is-done,
.at-flow-steps > .is-current {
    border-color: var(--blue);
    background: var(--blue-soft);
    color: var(--foreground);
}
.at-kis-inline-settings {
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    background: var(--card);
}
.at-strategy-limit-panel {
    margin: 12px 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    background: var(--card);
}
.at-strategy-limit-title {
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 800;
}
.at-strategy-limit-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}
.at-strategy-limit-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--background);
    padding: 10px 12px;
}
.at-strategy-limit-head {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: center;
    font-size: 12px;
}
.at-strategy-limit-head span {
    border: 1px solid var(--blue);
    border-radius: 999px;
    color: var(--blue);
    background: var(--card);
    padding: 2px 7px;
    font-size: 10px;
    font-weight: 800;
    white-space: nowrap;
}
.at-strategy-limit-value {
    margin-top: 6px;
    font-size: 18px;
    font-weight: 800;
}
.at-strategy-limit-card small {
    display: block;
    margin-top: 4px;
    color: var(--muted-fg);
    font-size: 10px;
}
.at-mode-settings-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}
.at-mode-settings-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card);
    padding: 12px 14px;
}
.at-mode-settings-card.is-current {
    border-color: var(--blue);
    background: var(--blue-soft);
}
.at-mode-settings-head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: flex-start;
    margin-bottom: 10px;
}
.at-mode-title {
    font-size: 14px;
    font-weight: 800;
}
.at-mode-badge {
    border: 1px solid var(--blue);
    border-radius: 999px;
    padding: 2px 8px;
    color: var(--blue);
    background: var(--card);
    font-size: 10px;
    font-weight: 800;
    white-space: nowrap;
}
.at-mode-badge-live {
    border-color: var(--up);
    color: var(--up);
}
.at-setting-chip-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.at-setting-chip-row span {
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--background);
    color: var(--muted-fg);
    padding: 3px 8px;
    font-size: 11px;
    white-space: nowrap;
}
.at-current-mode-note {
    margin: -2px 0 12px;
    color: var(--muted-fg);
    font-size: 12px;
}
.at-config-choice-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}
.at-config-choice-grid .at-config-choice:nth-child(3) {
    grid-column: 1 / -1;
}
.at-config-focus {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
    background: var(--blue-soft) !important;
    transition: outline-color .2s, background .2s;
}
.at-config-choice {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card);
    padding: 9px 10px;
    cursor: pointer;
}
.at-config-choice.is-active {
    border-color: var(--blue);
    background: var(--blue-soft);
}
.at-config-choice input {
    margin-top: 2px;
}
.at-config-choice b {
    display: block;
    font-size: 12px;
}
.at-config-choice small {
    display: block;
    margin-top: 2px;
    color: var(--muted-fg);
    font-size: 10px;
    line-height: 1.4;
}
.at-insight-grid {
    display: grid;
    /* 2026-04-24: 6 박스 → 4 박스 통합 (UI 재설계 Phase 1) */
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}
.at-insight-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card);
    padding: 10px 12px;
    min-height: 74px;
}
.at-insight-card > div:nth-child(2) {
    margin-top: 4px;
    font-size: 16px;
    font-weight: 800;
}
.at-insight-card small {
    display: block;
    margin-top: 4px;
    color: var(--muted-fg);
    font-size: 10px;
}
.at-history-block {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-bottom: 12px;
    background: var(--card);
}
.at-history-block > summary {
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
}
.at-sort-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin: 10px 0;
}
.at-sort-row .btn-outline {
    padding: 4px 10px;
    font-size: 11px;
}
.at-return-bars {
    display: grid;
    gap: 5px;
    margin-top: 10px;
}
.at-return-row {
    display: grid;
    grid-template-columns: 48px minmax(120px, 1fr) 72px;
    gap: 8px;
    align-items: center;
    font-size: 11px;
}
.at-return-row > div {
    height: 12px;
    background: var(--muted);
    border-radius: 999px;
    overflow: hidden;
}
.at-return-row i {
    display: block;
    height: 100%;
    min-width: 2px;
}
.at-return-row i.up {
    background: var(--up);
}
.at-return-row i.down {
    background: var(--down);
}
@media (max-width: 1024px) {
    .at-setup-launch-grid,
    .at-portfolio-card-grid,
    .at-mode-settings-grid,
    .at-strategy-limit-grid,
    .at-flow-steps,
    .at-insight-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .at-insight-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}
@media (max-width: 480px) {
    .at-main-tabs,
    .at-setup-launch-grid,
    .at-portfolio-card-grid,
    .at-mode-settings-grid,
    .at-strategy-limit-grid,
    .at-flow-steps,
    .at-config-choice-grid,
    .at-insight-grid {
        grid-template-columns: 1fr;
    }
    .at-config-choice-grid .at-config-choice:nth-child(3) {
        grid-column: auto;
    }
    .at-return-row {
        grid-template-columns: 42px minmax(0, 1fr) 64px;
    }
}

/* Stock info modal: keep the company-info popup in one non-scrolling window. */
.stock-info-modal .modal-box {
    position: relative;
    width: min(96vw, 1040px);
    max-width: none;
    min-width: 0;
    max-height: calc(100vh - 24px);
    overflow: hidden;
    padding: 18px 20px 14px;
}
.stock-info-modal .modal-title {
    margin-bottom: 12px;
    padding-right: 40px;
}
.stock-info-modal .modal-body,
.stock-info-modal-body {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}
.stock-info-modal .modal-actions:empty {
    display: none;
}
.stock-info-modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 30px;
    height: 30px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card);
    color: var(--muted-fg);
    font-size: 16px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
}
.stock-info-modal-close:hover {
    color: var(--foreground);
    background: var(--muted);
}
.stock-info-modal-body > .card {
    margin-bottom: 10px !important;
    padding: 12px 14px !important;
    border-radius: var(--radius);
    overflow: hidden !important;
}
.stock-info-modal-body .card-title {
    margin-bottom: 8px;
    font-size: 14px;
}
.stock-info-modal-body .card-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 8px !important;
    margin-bottom: 10px !important;
}
.stock-info-modal-body .stat-card {
    min-width: 0;
    padding: 8px 10px !important;
}
.stock-info-modal-body .stat-label {
    font-size: 11px;
}
.stock-info-modal-body .chart-period-btns {
    display: flex;
    gap: 4px;
}
.stock-info-modal-body .chart-period-btns .btn {
    height: 24px;
    padding: 0 8px !important;
    font-size: 11px !important;
}
.stock-info-modal-body div[style*="height:280px"] {
    height: clamp(150px, 28vh, 220px) !important;
}
.stock-info-modal-body .data-table {
    display: table;
    table-layout: fixed;
    overflow: hidden;
}
.stock-info-modal-body .data-table th,
.stock-info-modal-body .data-table td {
    padding: 6px 8px;
    font-size: 12px;
    white-space: normal;
}
.stock-info-modal-body .data-table .num {
    font-size: 12px;
    white-space: nowrap;
}
@media (min-width: 860px) and (min-height: 620px) {
    .stock-info-modal-body {
        display: grid;
        grid-template-columns: minmax(260px, 0.9fr) minmax(360px, 1.1fr);
        gap: 10px;
        align-items: start;
    }
    .stock-info-modal-body > .card,
    .stock-info-modal-body > .card-grid {
        margin-bottom: 0 !important;
    }
    .stock-info-modal-body > .card:nth-child(1) {
        grid-column: 1;
    }
    .stock-info-modal-body > .card:nth-child(2) {
        grid-column: 2;
        grid-row: 1 / span 2;
    }
    .stock-info-modal-body > .card-grid {
        grid-column: 1;
    }
    .stock-info-modal-body > .card:nth-child(n+4) {
        grid-column: 1 / -1;
    }
}
@media (max-width: 768px) {
    .stock-info-modal .modal-box {
        width: calc(100vw - 16px);
        max-height: calc(100vh - 16px);
        margin: 8px;
        padding: 14px 12px 12px;
    }
    .stock-info-modal-body .card-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
    .stock-info-modal-body div[style*="height:280px"] {
        height: clamp(130px, 24vh, 180px) !important;
    }
}

/* ══════════════════════════════════════════════════════
   20260417 전역 안전장치 — 글자 겹침/오른쪽 정렬 방지
   원인:
     1. 한글 긴 문자열이 단어 경계 없이 오버플로 (word-break 기본값)
     2. .data-table 이 .table-wrapper 없이 직접 배치되어 viewport 초과
     3. .card 내부 inline-style width/min-width 고정으로 overflow
     4. body 전체 overflow-x 허용 → 하위 요소 튀어나감
   ══════════════════════════════════════════════════════ */
html, body {
    max-width: 100vw;
    overflow-x: hidden;
    word-break: keep-all;       /* 한글 단어 단위 줄바꿈 */
    overflow-wrap: break-word;  /* 긴 숫자/영문 강제 줄바꿈 */
}
/* 테이블 전역 overflow — wrapper 없이도 동작 */
@media (max-width: 1024px) {
    table.data-table {
        display: block;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    /* 카드 내부 inline-width 고정 방어 */
    .card, .collapsible-body {
        max-width: 100%;
        overflow-x: auto;
    }
    /* 숫자 셀 nowrap 유지 but 전체 테이블은 스크롤 */
    .num, .mono, .text-mono { white-space: nowrap; }
}

/* ── 다크모드 ─────────────────────────────── */
@media (prefers-color-scheme: dark) {
    :root:not(.light) {
        --background:    hsl(240 10% 8%);
        --foreground:    hsl(0 0% 92%);
        --card:          hsl(240 10% 11%);
        --card-fg:       hsl(0 0% 92%);
        --muted:         hsl(240 4% 18%);
        --muted-fg:      hsl(240 3% 60%);
        --accent:        hsl(240 4% 18%);
        --accent-fg:     hsl(0 0% 92%);
        --primary:       hsl(0 0% 92%);
        --primary-fg:    hsl(240 10% 8%);
        --secondary:     hsl(240 4% 18%);
        --secondary-fg:  hsl(0 0% 92%);
        --border:        hsl(240 5% 25%);
        --input:         hsl(240 5% 25%);
        --ring:          hsl(0 0% 92%);
        --up:            hsl(0 75% 55%);
        --up-soft:       hsla(0, 75%, 55%, 0.12);
        --down:          hsl(217 75% 60%);
        --down-soft:     hsla(217, 75%, 55%, 0.12);
        --warn:          hsl(38 85% 50%);
        /* 20260417: 다크모드 zebra-stripe — 밝은 회색이 텍스트와 대비 소실 fix */
        --table-row-alt:   hsl(240 10% 14%);
        --table-row-hover: hsl(240 10% 18%);
    }
}
.dark {
    /* 20260409: 다크모드 배경 8%→11% (눈부심 ↓), 텍스트 92%→88% */
    --background:    hsl(240 10% 11%);
    --foreground:    hsl(0 0% 88%);
    --card:          hsl(240 10% 14%);
    --card-fg:       hsl(0 0% 88%);
    --muted:         hsl(240 4% 20%);
    --muted-fg:      hsl(240 3% 62%);
    --border:        hsl(240 5% 27%);
    --input:         hsl(240 5% 27%);
    --up:            hsl(0 75% 60%);
    --up-soft:       hsla(0, 75%, 55%, 0.12);
    --down:          hsl(217 75% 65%);
    --down-soft:     hsla(217, 75%, 55%, 0.12);
    /* 20260417: 다크모드 zebra-stripe 대비 복원 */
    --table-row-alt:   hsl(240 10% 17%);
    --table-row-hover: hsl(240 10% 22%);
}

/* ── 리셋 ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
    font-family: var(--font-sans);
    background: hsl(220 14% 92%);  /* 96% → 92% 카드와 명확 구분 */
    color: var(--foreground);
    font-size: 15.5px;             /* 14.5 → 15.5 가독성 ↑ */
    line-height: 1.7;              /* 1.65 → 1.7 */
    min-height: 100vh;
    letter-spacing: -0.01em;
    word-break: keep-all;
    /* 20260409: 숫자 정렬 일관 (tabular numerals) */
    font-feature-settings: "tnum" 1, "kern" 1;
    font-variant-numeric: tabular-nums;
}

/* 20260409: 모든 수치/표/입력 영역에서 숫자 폭 일정 */
table, .stat-value, .num, input[type="number"], .price, .pct, .qty {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
}

/* 20260409: 키보드 포커스 가시화 (P0 a11y) */
:focus-visible {
    outline: 2px solid var(--ring);
    outline-offset: 2px;
    border-radius: 4px;
}
button:focus:not(:focus-visible) { outline: none; }

/* 20260409: 색+형태 이중 신호 (4차) */
.signal-up   { color: var(--up);   font-weight: 600; font-variant-numeric: tabular-nums; }
.signal-down { color: var(--down); font-weight: 600; font-variant-numeric: tabular-nums; }
.signal-flat { color: var(--muted-fg); font-variant-numeric: tabular-nums; }

/* 20260409: 명령 팔레트 (2차) */
#cmdPalette input::placeholder { color: var(--muted-fg); }

/* 20260409: 밀도 모드 (5차) */
:root[data-density="compact"] .card { padding: 12px; }
:root[data-density="comfy"]   .card { padding: 22px; }

/* 20260409: 4차 — 포트폴리오 그리드 4열 → 2열 권장 (정보 밀도 ↓) */
@media (min-width: 768px) {
  #tab-portfolio .grid-4 { grid-template-columns: repeat(2, 1fr) !important; }
}

/* ══ 레이아웃 셸 ══════════════════════════════ */
.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ── 헤더 ─────────────────────────────────── */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    padding: 0 28px;
    border-bottom: 1px solid var(--border);
    background: var(--background);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.app-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.app-logo {
    width: 30px; height: 30px;
    background: linear-gradient(135deg, hsl(217 91% 50%) 0%, hsl(262 83% 55%) 100%);
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 14px; color: #fff;
}
.app-title {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--foreground);
}
.header-meta {
    display: flex;
    align-items: center;
    gap: 12px;
}
.trade-date {
    font-size: 12px;
    color: var(--muted-fg);
    font-family: var(--font-mono);
    background: var(--muted);
    padding: 4px 12px;
    border-radius: 9999px;
    border: 1px solid var(--border);
}
.header-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--up);
}

/* ── 메인 탭 ──────────────────────────────── */
.tab-nav {
    display: flex;
    align-items: center;
    gap: 0;
    padding: 0 24px;
    height: 44px;
    border-bottom: 1px solid var(--border);
    background: var(--background);
    overflow-x: auto;
    scrollbar-width: none;
}
.tab-nav::-webkit-scrollbar { display: none; }
.tab-btn {
    position: relative;
    flex-shrink: 0;
    height: 48px;
    padding: 0 20px;
    background: none;
    border: none;
    color: var(--muted-fg);
    font-family: var(--font-sans);
    font-size: 14.5px;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.15s;
}
.tab-btn:hover { color: var(--foreground); }
.tab-btn.active {
    color: var(--foreground);
    font-weight: 700;
}
.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: 0; left: 16px; right: 16px;
    height: 2px;
    background: var(--foreground);
    border-radius: 1px 1px 0 0;
}

/* ── 서브탭 (pill) ────────────────────────── */
.sub-tab-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 16px 4px 8px;
    overflow-x: auto;
    scrollbar-width: none;
}
.sub-tab-nav::-webkit-scrollbar { display: none; }
.sub-tab-btn {
    flex-shrink: 0;
    height: 34px;
    padding: 0 16px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius);
    color: var(--muted-fg);
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}
.sub-tab-btn:hover {
    color: var(--foreground);
    background: var(--background);
    border-color: var(--border);
}
.sub-tab-btn.active {
    background: var(--foreground);
    color: var(--primary-fg);
    font-weight: 600;
    border-color: var(--foreground);
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

/* ── 메인 콘텐츠 ─────────────────────────── */
.main-content {
    flex: 1;
    max-width: 1440px;
    width: 100%;
    margin: 0 auto;
    padding: 0 24px 40px;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.sub-panel { display: none; padding: 8px 0; }
.sub-panel.active { display: block; }

/* ══ 카드 ═════════════════════════════════════ */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px 24px;
    margin-bottom: 18px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    transition: box-shadow 0.15s, border-color 0.15s;
}
.card:hover {
    box-shadow: 0 3px 12px rgba(0,0,0,0.07);
    border-color: hsl(240 5.9% 82%);
}
.card-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--foreground);
    margin-bottom: 16px;
    letter-spacing: -0.02em;
}
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

/* stat 카드 */
.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: box-shadow 0.15s, border-color 0.15s;
}
.stat-card:hover {
    border-color: hsl(240 5.9% 80%);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.stat-label {
    font-size: 12px;
    color: var(--muted-fg);
    font-weight: 600;
    letter-spacing: 0.02em;
}
.stat-value {
    font-size: 22px;
    font-weight: 700;
    font-family: var(--font-mono);
    letter-spacing: -0.03em;
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
}
.stat-sub {
    font-size: 12px;
    font-weight: 400;
    color: var(--muted-fg);
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ══ 테이블 ═══════════════════════════════════ */
.table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--card);
}
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: clamp(11px, 2.8vw, 13.5px); /* 20260412: 반응형 폰트 (480px→11px, 768px+→13.5px) */
}
.data-table thead { background: var(--muted); }
.data-table th {
    text-align: left;
    padding: 11px 14px;
    font-weight: 600;
    font-size: 12px;
    color: var(--muted-fg);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    letter-spacing: 0.01em;
}
.data-table th:hover { color: var(--foreground); }
.data-table th.sort-asc::after { content: " \2191"; opacity: 0.6; }
.data-table th.sort-desc::after { content: " \2193"; opacity: 0.6; }
.data-table td {
    padding: 11px 14px;
    border-bottom: 1px solid hsl(240 5.9% 94%);
    white-space: nowrap;
    color: var(--foreground);
}
.data-table tbody tr { transition: background 0.1s; }
.data-table tbody tr:hover td { background: var(--table-row-hover, hsl(220 14% 96%)); }
.data-table tbody tr:nth-child(even) td { background: var(--table-row-alt, hsl(220 14% 98.5%)); }
.data-table tbody tr:nth-child(even):hover td { background: var(--table-row-hover, hsl(220 14% 96%)); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .num {
    text-align: right;
    font-family: var(--font-mono);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

/* ══ 숫자 색상 ════════════════════════════════ */
.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--muted-fg); }
.up-bg { background: var(--up-soft); border-radius: var(--radius-sm); padding: 2px 6px; }
.down-bg { background: var(--down-soft); border-radius: var(--radius-sm); padding: 2px 6px; }

/* ══ 시그널 뱃지 ══════════════════════════════ */
.signal-badge {
    display: inline-flex;
    align-items: center;
    height: 22px;
    padding: 0 8px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.01em;
}
.signal-5  { background: hsla(142,71%,45%,0.12); color: hsl(142 71% 30%); }
.signal-4  { background: hsla(142,71%,45%,0.08); color: hsl(142 71% 32%); }
.signal-3  { background: hsla(217,91%,60%,0.10); color: hsl(217 91% 40%); }
.signal-2  { background: hsla(240,4%,46%,0.10);  color: var(--muted-fg); }
.signal-1  { background: hsla(30,92%,50%,0.10);  color: hsl(30 80% 38%); }
.signal-0  { background: hsla(0,84%,60%,0.10);   color: hsl(0 70% 42%); }
.signal--1 { background: hsla(0,84%,60%,0.15);   color: hsl(0 70% 38%); }

/* ══ 로딩 / 빈 상태 ══════════════════════════ */
.loading-placeholder, .empty-state, .help-text {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    color: var(--muted-fg);
    font-size: 13px;
    gap: 12px;
}
.loading-spinner {
    width: 20px; height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--foreground);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ══ 입력 폼 ══════════════════════════════════ */
.input-group {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
input[type="text"], input[type="number"], input[type="date"], select {
    height: 36px;
    padding: 0 12px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--foreground);
    font-family: var(--font-sans);
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus {
    border-color: var(--ring);
    box-shadow: 0 0 0 2px hsla(240, 5.9%, 10%, 0.08);
}
input::placeholder { color: hsl(240 3.8% 66%); }

.btn {
    height: 36px;
    padding: 0 16px;
    background: var(--primary);
    color: var(--primary-fg);
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn:hover { opacity: 0.85; }
.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--foreground);
}
.btn-outline:hover { background: var(--muted); }
.btn-secondary {
    background: var(--secondary);
    color: var(--secondary-fg);
}
.btn-secondary:hover { background: hsl(240 4.8% 90%); }
.btn-danger {
    background: var(--destructive);
    color: var(--destructive-fg);
}
.btn-sm { height: 30px; padding: 0 10px; font-size: 12px; }
.btn-ghost {
    background: transparent;
    color: var(--muted-fg);
    border: none;
}
.btn-ghost:hover { color: var(--foreground); background: var(--muted); }

/* ══ 토스트 ═══════════════════════════════════ */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.toast {
    pointer-events: auto;
    padding: 12px 16px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--foreground);
    box-shadow: 0 4px 16px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.06);
    animation: toastIn 0.25s ease-out;
    max-width: 380px;
}
.toast.error { border-left: 3px solid var(--down); }
.toast.success { border-left: 3px solid var(--up); }
@keyframes toastIn {
    from { opacity: 0; transform: translateY(8px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ══ 모달 ═════════════════════════════════════ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: overlayIn 0.15s;
}
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }
.modal-box {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 28px;
    min-width: 380px;
    max-width: 520px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 16px 48px rgba(0,0,0,0.12);
    animation: modalIn 0.2s ease-out;
}
@keyframes modalIn {
    from { opacity: 0; transform: scale(0.96) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 20px;
    letter-spacing: -0.02em;
}
.modal-body input { width: 100%; margin-bottom: 10px; }
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* ══ 히트맵 ═══════════════════════════════════ */
.heatmap-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}
.heatmap-cell {
    padding: 12px;
    border-radius: var(--radius);
    text-align: center;
    border: 1px solid transparent;
    transition: border-color 0.15s;
}
.heatmap-cell:hover { border-color: var(--border); }
.heatmap-cell .sector-name {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 4px;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.heatmap-cell .sector-return {
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 600;
}

/* ══ 주도섹터 캘린더 ══════════════════════════ */
.sector-cal-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}
.sector-cal-table th {
    padding: 6px 4px;
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    color: var(--muted-fg);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid var(--border);
}
.sector-cal-table th:first-child { color: hsl(0 85% 48%); }
.sector-cal-table th:last-child { color: hsl(217 85% 48%); }
.sector-cal-cell {
    vertical-align: top;
    padding: 5px 3px;
    height: 96px;
    border: 1px solid hsl(240 5.9% 90%);
    transition: background 0.1s;
}
.sector-cal-cell.has-data:hover {
    background: hsl(240 4.8% 96%);
}
.sector-cal-cell.weekend,
.sector-cal-cell.holiday {
    background: hsl(240 4.8% 97.5%);
}
.sector-cal-empty {
    height: 96px;
    border: 1px solid hsl(240 5.9% 90%);
}
.sector-cal-day {
    font-size: 12px;
    font-weight: 800;
    color: var(--foreground);
    margin-bottom: 3px;
    text-align: center;
}
.sector-cal-day.sat { color: hsl(217 85% 48%); }
.sector-cal-day.sun, .sector-cal-day.holiday { color: hsl(0 85% 48%); }
.sector-cal-badge {
    font-size: 9px;
    font-weight: 600;
    padding: 1px 4px;
    border-radius: 4px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
    margin-bottom: 1px;
}
.sector-cal-ret-inline {
    font-family: var(--font-mono);
    font-size: 8px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    margin-left: 2px;
}

/* ══ 유틸리티 ═════════════════════════════════ */
.separator { height: 1px; background: var(--border); margin: 16px 0; }
.text-muted { color: var(--muted-fg); }
.text-sm { font-size: 12px; }
.text-mono { font-family: var(--font-mono); }
.font-semibold { font-weight: 600; }

/* ══ 반응형 ═══════════════════════════════════ */
@media (max-width: 768px) {
    .app-header { padding: 0 16px; height: 48px; }
    .app-title { font-size: 14px; }
    .tab-nav { padding: 0 12px; }
    .tab-btn { padding: 0 12px; font-size: 12px; }
    .sub-tab-btn { font-size: 11px; height: 28px; padding: 0 10px; }
    .main-content { padding: 0 12px 24px; }
    .card { padding: 16px; border-radius: var(--radius); }
    .card-grid { grid-template-columns: 1fr; }
    .stat-card { padding: 12px 16px; }
    .stat-value { font-size: 18px; }
    .modal-box { min-width: unset; margin: 16px; }
    .input-group { flex-direction: column; }
    .input-group input, .input-group .btn { width: 100%; }
}
@media (max-width: 480px) {
    .header-meta { gap: 8px; }
    .trade-date { font-size: 10px; padding: 3px 8px; }
    .heatmap-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
    /* 모바일: 테이블 스크롤 + 폰트 축소 */
    .data-table { font-size: 11px; }
    .data-table th, .data-table td { padding: 4px 6px; }
    .data-table .num { font-size: 10px; }
    /* 거래 버튼 축소 */
    .btn-trade { font-size: 10px !important; padding: 2px 6px !important; }
    /* 섹터 캘린더 높이 축소 */
    .sector-cal-cell { height: 72px; }
    .sector-cal-table th { font-size: 10px; }
}

/* ── 로그인 화면 ──────────────────────────────── */
#login-overlay {
    position: fixed; inset: 0; z-index: 9999;
    display: flex; align-items: center; justify-content: center;
    background: var(--background);
}
.login-box {
    width: 440px; padding: 48px 40px;
    border: 1px solid var(--border); border-radius: var(--radius-lg);
    background: var(--card); text-align: center;
}
.login-logo {
    width: 56px; height: 56px; margin: 0 auto 20px;
    background: var(--primary); color: var(--primary-fg);
    border-radius: var(--radius); font-size: 28px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
}
.login-box h2 { margin: 0 0 28px; font-size: 24px; font-weight: 600; }
#login-form input, #register-form input {
    display: block; width: 100%; padding: 14px 16px; margin-bottom: 14px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: 16px; background: var(--background); color: var(--foreground);
    box-sizing: border-box;
}
#login-form input:focus, #register-form input:focus { outline: 2px solid var(--ring); outline-offset: -1px; }
#login-form button, #register-form button[type="submit"] {
    width: 100%; padding: 14px; margin-top: 4px;
    background: var(--primary); color: var(--primary-fg);
    border: none; border-radius: var(--radius-sm);
    font-size: 16px; font-weight: 500; cursor: pointer;
}
#login-form button:hover, #register-form button[type="submit"]:hover { opacity: 0.9; }
#login-form button:disabled, #register-form button[type="submit"]:disabled { opacity: 0.5; cursor: not-allowed; }
.login-disclaimer {
    margin-bottom: 24px; padding: 16px;
    background: var(--muted); border-radius: var(--radius-sm);
    font-size: 14px; line-height: 1.7; color: var(--muted-fg); text-align: left;
}
.login-remember {
    display: flex; align-items: center; gap: 8px;
    margin: 10px 0 6px; font-size: 15px; color: var(--muted-fg); cursor: pointer;
}
.login-remember input[type="checkbox"] {
    width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer;
}
.login-error { margin-top: 14px; color: var(--destructive); font-size: 14px; min-height: 22px; }
.login-register-link {
    margin-top: 20px; font-size: 15px; color: var(--muted-fg);
}
.login-register-link a {
    color: var(--primary); font-weight: 600; text-decoration: none;
}
.login-register-link a:hover { text-decoration: underline; }
.register-success {
    margin-top: 14px; color: var(--up); font-size: 15px; font-weight: 600; min-height: 22px;
}
.modal-overlay {
    position: fixed; inset: 0; z-index: 10000;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.5); backdrop-filter: blur(2px);
}

/* ── 로그아웃 버튼 ──────────────────────────────── */
.btn-logout {
    padding: 4px 12px; margin-left: 8px;
    background: transparent; color: var(--muted-fg);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: 12px; cursor: pointer; white-space: nowrap;
}
.btn-logout:hover { background: var(--muted); color: var(--foreground); }

/* ── 투자 성향 카드 ──────────────────────────── */
.style-card {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    padding: 16px 12px; border: 2px solid var(--border); border-radius: var(--radius);
    cursor: pointer; transition: all 0.2s; text-align: center;
}
.style-card:hover { border-color: var(--ring); background: var(--muted); }
.style-card.active { border-color: var(--primary); background: var(--muted); }
.style-icon { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 20px; color: #fff; }
.style-name { font-size: 16px; font-weight: 700; }

/* ── 거래 버튼 ──────────────────────────────── */
.btn-trade {
    padding: 2px 8px; font-size: 11px; font-weight: 600;
    background: transparent; border: 1px solid var(--border);
    border-radius: 3px; cursor: pointer; margin: 0 1px;
}
.btn-trade:hover { background: var(--muted); }
.style-desc { font-size: 11px; color: var(--muted-fg); line-height: 1.5; }

/* ── 섹터 자금흐름 ──────────────────────────── */
.sector-flow-list { display: block; max-height: 480px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.sector-flow-item { border-bottom: 1px solid var(--border); }
.sector-flow-item:last-child { border-bottom: none; }
.sector-flow-header {
    display: flex; align-items: center; gap: 8px; padding: 10px 14px;
    cursor: pointer; position: relative; transition: background 0.15s;
    min-height: 44px; box-sizing: border-box;
}
.sector-flow-header:hover { background: var(--muted); }
.sector-rank-badge {
    min-width: 24px; height: 24px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 600; background: var(--muted); color: var(--muted-fg);
    flex-shrink: 0;
}
.sector-rank-badge.top3 { background: var(--warn); color: #fff; }
.sector-flow-name { font-size: 14px; font-weight: 500; flex: 1; min-width: 0; }
.sector-flow-bar {
    position: absolute; left: 0; top: 0; height: 100%; border-radius: var(--radius-sm);
    pointer-events: none; z-index: 0;
}
.sector-flow-return { font-size: 14px; font-weight: 600; font-family: var(--font-mono); min-width: 70px; text-align: right; z-index: 1; }
.sector-flow-count { font-size: 11px; color: var(--muted-fg); min-width: 50px; text-align: right; z-index: 1; }
.sector-flow-toggle { font-size: 10px; color: var(--muted-fg); transition: transform 0.2s; z-index: 1; }
.sector-flow-toggle.open { transform: rotate(0deg); }
.sector-flow-stocks { border-top: 1px solid var(--border); background: var(--muted); }
.sector-stock-scroll { max-height: 360px; overflow-y: auto; }
.data-table.compact th, .data-table.compact td { padding: 6px 10px; font-size: 13px; }

/* ── 실시간 차트 탭 버튼 ── */
.chart-tab-btn, .iv-btn { background: var(--muted, #f5f5f5); border: 1px solid var(--border); color: var(--fg); font-size: 12px; padding: 4px 12px; border-radius: var(--radius-sm, 6px); cursor: pointer; transition: all 0.15s; }
.chart-tab-btn.active, .iv-btn.active { background: var(--primary, #2563eb); color: #fff; border-color: var(--primary, #2563eb); }
.chart-tab-btn:hover:not(.active), .iv-btn:hover:not(.active):not(:disabled) { background: var(--border); }
.iv-btn:disabled { cursor: not-allowed; }

/* ── AI 모니터링 탭 ── */
.ai-monitor-section { padding: 16px 0; }
.ai-monitor-section h3 { margin: 0 0 16px; font-size: 16px; font-weight: 600; }
.ai-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 20px; }
.ai-card { background: var(--card-bg, var(--bg)); border: 1px solid var(--border); border-radius: var(--radius-md, 8px); padding: 16px; }
.ai-card-label { font-size: 12px; color: var(--muted-fg); margin-bottom: 4px; }
.ai-card-value { font-size: 28px; font-weight: 700; margin-bottom: 6px; }
.ai-card-sub { font-size: 11px; color: var(--muted-fg); line-height: 1.6; }
.ai-summary-bar { display: flex; flex-wrap: wrap; gap: 16px; padding: 10px 14px; background: var(--muted, #f5f5f5); border-radius: var(--radius-sm, 6px); margin-bottom: 16px; font-size: 13px; }
.empty-state { padding: 40px; text-align: center; color: var(--muted-fg); font-size: 14px; }
@media (max-width: 768px) {  /* 20260417: 760→768 표준화 */
    .ai-cards { grid-template-columns: 1fr; }
    .ai-summary-bar { flex-direction: column; gap: 6px; }
}

/* ══════════════════════════════════════════════════
   Collapsible component (UI-1, 2026-04-10)
   HTML5 <details> 기반 + 모바일 카드뷰 + 하단 탭바
   ══════════════════════════════════════════════════ */

details.collapsible {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    overflow: hidden;
    transition: box-shadow 0.15s;
}
details.collapsible[open] {
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
details.collapsible.collapsible-l2 {
    background: var(--muted);
    margin-bottom: 8px;
}

summary.collapsible-summary {
    cursor: pointer;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 14px;
    color: var(--card-fg);
    list-style: none;
    user-select: none;
    transition: background 0.1s;
}
summary.collapsible-summary::-webkit-details-marker { display: none; }
summary.collapsible-summary:hover { background: var(--muted); }

.collapsible-arrow {
    display: inline-block;
    width: 0; height: 0;
    border-left: 6px solid var(--muted-fg);
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    transition: transform 0.15s;
    flex-shrink: 0;
}
details.collapsible[open] > summary > .collapsible-arrow {
    transform: rotate(90deg);
}

.collapsible-title { flex: 1; }

.collapsible-badge {
    font-size: 11px;
    padding: 3px 8px;
    background: var(--muted);
    border-radius: 999px;
    color: var(--muted-fg);
    font-weight: 500;
    white-space: nowrap;
}
details.collapsible[open] > summary .collapsible-badge {
    background: var(--accent);
    color: var(--accent-fg);
}

.collapsible-body {
    padding: 14px 16px 16px;
    border-top: 1px solid var(--border);
    animation: collapsible-fade-in 0.18s ease-out;
}
.collapsible-l2 .collapsible-body { padding: 10px 12px 12px; }

@keyframes collapsible-fade-in {
    from { opacity: 0; transform: translateY(-2px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ══════════════════════════════════════════════════
   모바일 반응형 (UI-4)
   ══════════════════════════════════════════════════ */

@media (max-width: 768px) {
    /* 컨테이너 패딩 축소 */
    body { font-size: 13px; }
    main, .container, .tab-content { padding: 8px !important; }
    .card { padding: 12px !important; margin-bottom: 10px; border-radius: var(--radius-sm); }
    .card-title { font-size: 14px !important; }

    summary.collapsible-summary { padding: 11px 13px; font-size: 13px; }
    .collapsible-body { padding: 12px 13px 14px; }

    /* 데이터 테이블 → 카드뷰 자동 전환 */
    table.data-table.mobile-card,
    .table-wrapper.mobile-card table.data-table {
        display: block;
        width: 100% !important;
        border: none;
    }
    table.data-table.mobile-card thead,
    .table-wrapper.mobile-card table.data-table thead {
        display: none;
    }
    table.data-table.mobile-card tbody,
    .table-wrapper.mobile-card table.data-table tbody {
        display: block;
    }
    table.data-table.mobile-card tr,
    .table-wrapper.mobile-card table.data-table tr {
        display: block;
        background: var(--card);
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        margin-bottom: 8px;
        padding: 10px 12px;
    }
    table.data-table.mobile-card td,
    .table-wrapper.mobile-card table.data-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 4px 0;
        border: none;
        font-size: 12px;
    }
    table.data-table.mobile-card td::before,
    .table-wrapper.mobile-card table.data-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--muted-fg);
        margin-right: 8px;
    }

    /* 가로 스크롤 방지 */
    .table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* 추천 그리드 1열 */
    div[style*="grid-template-columns:1fr 1fr"],
    div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* sub-tab 가로 스크롤 */
    .sub-tab-bar, [class*="sub-tab"] { overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* 상단 탭 컴팩트 */
    .tab-bar button, .main-tab-btn { padding: 8px 12px; font-size: 12px; }

    /* 하단 fixed 네비 공간 확보 */
    body { padding-bottom: 64px; }
}

/* ══════════════════════════════════════════════════
   하단 탭바 (모바일 전용 fixed bottom nav, UI-4)
   ══════════════════════════════════════════════════ */

.bottom-nav {
    display: none;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: 56px;
    background: var(--card);
    border-top: 1px solid var(--border);
    z-index: 100;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
}
.bottom-nav-inner {
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    height: 100%;
    max-width: 100%;
}
.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px 0;
    cursor: pointer;
    color: var(--muted-fg);
    font-size: 10px;
    background: transparent;
    border: none;
    transition: color 0.1s;
}
.bottom-nav-item.active {
    color: var(--primary);
}
.bottom-nav-icon {
    font-size: 18px;
    line-height: 1;
}

@media (max-width: 768px) {
    .bottom-nav { display: block; }
    /* 상단 탭 모바일에서 숨김 (선택) */
    /* .top-tab-bar { display: none; } */
}

/* ══════════════════════════════════════════════════
   추천 탭 모바일 dense 카드 (UI-A, 2026-04-10)
   A안: 헤더 + 메타 + 신호 + 펼침 상세
   ══════════════════════════════════════════════════ */

/* 데스크탑: 테이블 보임, 모바일 카드 숨김
   20260415: 사용자 요청 — 표 형태 화면 활용 우선. 카드는 phone 전용으로 제한.
   break point 768 → 480 축소 (태블릿/좁은 데스크탑도 테이블 사용). */
.rec-mobile-grid {
    display: none;
    flex-direction: column;
    gap: 8px;
}
.rec-desktop-table { display: block; overflow-x: auto; }

@media (max-width: 480px) {
    .rec-desktop-table { display: none !important; }
    .rec-mobile-grid { display: flex !important; }
}

details.rec-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition: box-shadow 0.15s;
}
details.rec-card[open] {
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

summary.rec-card-summary {
    cursor: pointer;
    padding: 10px 12px;
    list-style: none;
    user-select: none;
}
summary.rec-card-summary::-webkit-details-marker { display: none; }

.rec-card-row1 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}
.rec-rank {
    font-size: 12px;
    color: var(--muted-fg);
    font-weight: 500;
    flex-shrink: 0;
}
.rec-name {
    /* AD-6: 종목명 강조 */
    flex: 1;
    font-size: 16px;
    font-weight: 700;
    color: var(--card-fg);
}
.rec-card-row2 {
    font-size: 11px;
    color: var(--muted-fg);
    margin-bottom: 6px;
}
.rec-card-row3 {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.rec-sig-label {
    font-size: 10px;
    color: var(--muted-fg);
    font-weight: 600;
    margin-right: 1px;
}

/* AD-4: AI 신호 컬러 박스 (pill) */
.sig-pill {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.4;
    white-space: nowrap;
}
.sig-strong-buy   { background: hsl(0 85% 96%);  color: hsl(0 85% 38%);   border: 1px solid hsl(0 85% 80%); }
.sig-buy          { background: hsl(0 85% 97%);  color: hsl(0 75% 45%);   border: 1px solid hsl(0 75% 85%); }
.sig-watch        { background: hsl(38 100% 96%); color: hsl(38 92% 38%);  border: 1px solid hsl(38 92% 80%); }
.sig-neutral      { background: hsl(0 0% 96%);   color: hsl(0 0% 45%);    border: 1px solid hsl(0 0% 85%); }
.sig-caution      { background: hsl(217 95% 96%); color: hsl(217 75% 45%); border: 1px solid hsl(217 75% 85%); }
.sig-avoid        { background: hsl(217 95% 95%); color: hsl(217 85% 40%); border: 1px solid hsl(217 75% 78%); }
.sig-strong-avoid { background: hsl(217 95% 93%); color: hsl(217 90% 35%); border: 1px solid hsl(217 75% 70%); }

/* 정확도 라벨 */
.m-acc {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
    flex-shrink: 0;
}
.m-acc-good    { background: hsla(140, 60%, 50%, 0.15); color: hsl(140 70% 35%); }
.m-acc-mid     { background: hsla(38, 92%, 55%, 0.15);  color: hsl(38 92% 38%); }
.m-acc-bad     { background: hsla(0, 85%, 55%, 0.12);   color: hsl(0 85% 42%); }
.m-acc-pending { background: var(--muted); color: var(--muted-fg); }
.m-acc-none    { background: var(--muted); color: var(--muted-fg); font-style: italic; }

/* 펼침 상세 */
.rec-card-detail {
    padding: 10px 12px 12px;
    border-top: 1px dashed var(--border);
    background: var(--muted);
    animation: collapsible-fade-in 0.18s ease-out;
}
.rec-detail-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    margin-bottom: 4px;
}
.rec-d-label {
    color: var(--muted-fg);
    font-weight: 600;
    min-width: 50px;
}
.rec-d-val {
    color: var(--card-fg);
    font-weight: 600;
    margin-right: 8px;
}
.rec-d-link {
    font-size: 11px;
    color: var(--blue);
    text-decoration: none;
}
.rec-d-link:hover { text-decoration: underline; }

/* RSI/MACD 색상 (모바일 카드용) */
.rec-rsi.oversold   { color: #3498db; font-weight: 700; }
.rec-rsi.overbought { color: #e74c3c; font-weight: 700; }
.rec-macd.bullish   { color: hsl(140 70% 40%); font-weight: 700; }
.rec-macd.bearish   { color: hsl(217 75% 50%); font-weight: 700; }

/* ══════════════════════════════════════════════════
   추천 탭 모바일 보강 (UI-A2, 2026-04-10)
   - 상단 헤더 컴팩트
   - 메인탭 모바일 숨김 (하단 탭바로 대체)
   - sub-tab 가로 스크롤
   - 섹터 카드 multi-row 레이아웃
   ══════════════════════════════════════════════════ */

@media (max-width: 768px) {
    /* 1. 상단 메인 탭 모바일 숨김 (하단 .bottom-nav로 대체) */
    .tab-nav { display: none !important; }

    /* 2. 헤더 — 고정 높이 1줄 + 넘치면 가로 스크롤 (20260417 UI 사고 수정)
       이전: flex-wrap으로 2~3줄 → .sub-tab-nav 위에 겹침. 7개 버튼(🌙/🎙/비번변경/…)이
       360px 폭에서 줄바꿈되어 레이아웃 파손. 고정 1줄 + overflow-x 로 해결. */
    header, .header, .app-header {
        flex-wrap: nowrap !important;
        gap: 6px !important;
        padding: 6px 10px !important;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        position: sticky;
        top: 0;
        background: var(--card);
        z-index: 50;
    }
    header::-webkit-scrollbar, .app-header::-webkit-scrollbar { display: none; }
    .header > *, .app-header > * { font-size: 11px !important; flex-shrink: 0; }
    .header button, .app-header button, .btn-logout {
        padding: 4px 8px !important;
        font-size: 11px !important;
        white-space: nowrap;
        flex-shrink: 0;
    }
    /* 제목 — 너무 길면 줄임표 */
    .header h1, .header .logo, .app-header h1, .app-title {
        font-size: 14px !important;
        font-weight: 700;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 40vw;
    }
    .app-header-left { flex-shrink: 1; min-width: 0; }
    .header-meta { flex-shrink: 0; display: flex; gap: 4px; align-items: center; }
    /* 시스템상태/날짜/마이크/달 등 부속 정보 작게 */
    .header .status-pill, .header .date-box, .header .icon-btn,
    .trade-date, #headerSystemStatus {
        font-size: 10px !important;
        padding: 3px 6px !important;
    }
    /* sub-tab-nav 는 헤더 아래 항상 상위 레이어 */
    .sub-tab-nav { position: relative; z-index: 10; background: var(--background); }
}

/* 극소폭 (~360px) — 비핵심 버튼 아이콘만 */
@media (max-width: 380px) {
    #btnDarkMode, #btnVoice { font-size: 0 !important; padding: 4px 6px !important; }
    #btnDarkMode::before { content: '🌙'; font-size: 14px; }
    #btnVoice::before { content: '🎙'; font-size: 14px; }
    #btnChangePw { display: none; }  /* 설정 메뉴 안으로 이동 (후속) */
    #headerSystemStatus { display: none; }  /* 서버 점으로 대체 */
    .trade-date {
        font-size: 9px !important;
        padding: 2px 5px !important;
        max-width: 65px;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

    /* 3. sub-tab 가로 스크롤 (잘림 방지) */
    .sub-tab-nav, .sub-tab-bar, [class*="sub-tab"] {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;  /* firefox */
        white-space: nowrap;
        flex-wrap: nowrap !important;
        padding-bottom: 4px;
    }
    .sub-tab-nav::-webkit-scrollbar { display: none; }
    .sub-tab-nav .sub-tab-btn, .sub-tab-bar button {
        flex-shrink: 0;
        padding: 6px 10px !important;
        font-size: 12px !important;
    }

    /* 4. 섹터 추천 카드 (sector-flow-header) multi-row 재배치 */
    .sector-flow-list { max-height: none !important; }
    .sector-flow-item { margin-bottom: 8px; }
    .sector-flow-header {
        display: grid !important;
        grid-template-columns: 32px 1fr auto auto;
        grid-template-rows: auto auto;
        grid-template-areas:
            "rank name return toggle"
            "rank meta count toggle";
        gap: 4px 8px;
        padding: 10px 12px !important;
        align-items: center;
    }
    .sector-rank-badge {
        grid-area: rank;
        width: 28px; height: 28px;
        font-size: 13px !important;
        align-self: center;
    }
    .sector-flow-name {
        grid-area: name;
        font-size: 14px !important;
        font-weight: 700;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    /* 점수/모멘텀 라벨 — 두 번째 줄 */
    .sector-flow-header > .text-muted {
        grid-area: meta;
        font-size: 10px !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .sector-flow-return {
        grid-area: return;
        font-size: 14px !important;
        font-weight: 700;
        text-align: right;
        white-space: nowrap;
    }
    .sector-flow-count {
        grid-area: count;
        font-size: 10px !important;
        text-align: right;
        color: var(--muted-fg);
        white-space: nowrap;
    }
    .sector-flow-toggle {
        grid-area: toggle;
        align-self: center;
        font-size: 14px !important;
    }

    /* 5. 섹터 펼침 종목 테이블 — 가로 스크롤 + 컴팩트 */
    .sector-stock-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .sector-stock-scroll table.data-table { font-size: 11px; }
    .sector-stock-scroll table.data-table th,
    .sector-stock-scroll table.data-table td {
        padding: 4px 6px !important;
    }
}

/* ── 2026-04-24: AI 엔진 카드 시각 강조 (C안) ─────────────────── */
/* 엔진 카드는 클릭 시 세션 전환. 호버·포커스·활성 상태를 명확히 표현. */
.at-engine-select {
    position: relative;
}
.at-engine-select:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.12);
    opacity: 1 !important;
}
.at-engine-select:focus-visible {
    outline: 3px solid #2563eb;
    outline-offset: 2px;
    opacity: 1 !important;
}
.at-engine-select:active {
    transform: scale(0.985);
    transition: transform 0.06s ease;
}
.at-engine-select.is-active::before {
    content: '';
    position: absolute;
    top: -2px; left: -2px; right: -2px; bottom: -2px;
    border-radius: inherit;
    pointer-events: none;
    animation: atEngineActivePulse 2.2s ease-in-out infinite;
}
@keyframes atEngineActivePulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(37,99,235,0.0); }
    50%      { box-shadow: 0 0 0 3px rgba(37,99,235,0.25); }
}
/* reduced motion 환경에서는 pulse 끔 */
@media (prefers-reduced-motion: reduce) {
    .at-engine-select { transition: none !important; }
    .at-engine-select.is-active::before { animation: none; }
}

/* ═══════════════════════════════════════════════════════════════
   포트폴리오 구분 팔레트 (2026-04-25 Phase 3)
   Classic(안정형 5D) = 파랑 · Pro(공격형 L3) = 오렌지 · 모의 = 회색/보라
   ─ 어디서든 포트폴리오를 색·아이콘 일관 구분
═══════════════════════════════════════════════════════════════ */
:root {
    --portfolio-classic-bg:    #1976d2;   /* 안정형(5D) Classic */
    --portfolio-classic-fg:    #ffffff;
    --portfolio-classic-stripe:#1976d2;
    --portfolio-pro-bg:        #f59e0b;   /* 공격형(L3) Pro */
    --portfolio-pro-fg:        #ffffff;
    --portfolio-pro-stripe:    #f59e0b;
    --portfolio-sim-bg:        #9ca3af;   /* 모의투자 일반 */
    --portfolio-sim-fg:        #ffffff;
    --portfolio-sim-stripe:    #9ca3af;
    --portfolio-sim-er-bg:     #8b5cf6;   /* 모의 시뮬 (ER) */
    --portfolio-sim-er-fg:     #ffffff;
    --portfolio-manual-bg:     #6b7280;   /* 직접매수 (KIS manual) */
    --portfolio-manual-fg:     #ffffff;
}

/* 공용 뱃지 — inline 에서 class 만 쓰면 일관 색 */
.portfolio-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 600;
    white-space: nowrap;
    line-height: 1.4;
    vertical-align: middle;
}
.portfolio-badge--classic { background: var(--portfolio-classic-bg); color: var(--portfolio-classic-fg); }
.portfolio-badge--pro     { background: var(--portfolio-pro-bg);     color: var(--portfolio-pro-fg); }
.portfolio-badge--sim     { background: var(--portfolio-sim-bg);     color: var(--portfolio-sim-fg); }
.portfolio-badge--sim-er  { background: var(--portfolio-sim-er-bg);  color: var(--portfolio-sim-er-fg); }
.portfolio-badge--manual  { background: var(--portfolio-manual-bg);  color: var(--portfolio-manual-fg); }

/* 좌측 스트라이프 — 카드·리스트 행 포트폴리오 구분용 */
.portfolio-stripe {
    position: relative;
    padding-left: 10px;
}
.portfolio-stripe::before {
    content: '';
    position: absolute;
    left: 0; top: 4px; bottom: 4px;
    width: 3px;
    border-radius: 2px;
    background: var(--portfolio-sim-stripe);
}
.portfolio-stripe--classic::before { background: var(--portfolio-classic-stripe); }
.portfolio-stripe--pro::before     { background: var(--portfolio-pro-stripe); }
.portfolio-stripe--sim::before     { background: var(--portfolio-sim-stripe); }

/* 2026-04-25: AI 위험 경고 체크박스 미확인 시 흔들림 애니메이션 */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

/* 2026-04-25: 추천 탭 상단 regime 배너 (sim_runner 약점 시각화) */
.regime-banner {
    padding: 10px 14px;
    margin-bottom: 12px;
    border-radius: 4px;
    border-left: 4px solid #6c757d;
    background: rgba(108, 117, 125, 0.08);
    font-size: 14px;
}
.regime-banner--bull     { border-left-color: #1a7d3a; background: rgba(26, 125, 58, 0.08); }
.regime-banner--bear     { border-left-color: #b32b2b; background: rgba(179, 43, 43, 0.08); }
.regime-banner--sideways { border-left-color: #6c757d; background: rgba(108, 117, 125, 0.08); }
.regime-banner__title   { font-weight: 600; }
.regime-banner__notes   { margin-top: 4px; font-size: 13px; color: #555; }
.regime-banner__weak    { margin-top: 4px; font-size: 12px; color: #b32b2b; }
.regime-banner__meta    { margin-top: 6px; font-size: 11px; color: #888; }
