/* --- Global CSS Reset & Tokens --- */
:root {
    --bg-app: #080a10;
    --bg-panel: #0f131e;
    --bg-panel-header: #141a29;
    --bg-card: #182033;
    --bg-card-hover: #1f2a42;
    --border-color: #1f293d;
    --border-glow: rgba(41, 98, 255, 0.15);
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --accent: #2962ff;
    --accent-glow: rgba(41, 98, 255, 0.4);
    --accent-hover: #1557ff;
    
    --up-color: #26a69a;
    --up-bg: rgba(38, 166, 154, 0.1);
    --up-blink: rgba(38, 166, 154, 0.35);
    
    --down-color: #ef5350;
    --down-bg: rgba(239, 83, 80, 0.1);
    --down-blink: rgba(239, 83, 80, 0.35);
    
    --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: 'Fira Code', source-code-pro, Menlo, Monaco, Consolas, monospace;
    
    --border-radius-sm: 4px;
    --border-radius-md: 8px;
    --border-radius-lg: 12px;
    
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
}

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

body {
    background-color: var(--bg-app);
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.5;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* --- Layout Structure --- */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

/* --- Header --- */
.dashboard-header {
    background: linear-gradient(90deg, var(--bg-panel) 0%, #121824 100%);
    border-bottom: 1px solid var(--border-color);
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    flex-shrink: 0;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    z-index: 10;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 24px;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;   /* <a> 홈링크로 사용 */
    color: inherit;
    cursor: pointer;
    transition: opacity 0.15s;
}
.header-logo:hover { opacity: 0.78; }

/* --- 차트/뉴스 높이 조절 리사이저 (우측 컬럼) --- */
.v-resizer {
    flex-shrink: 0;
    height: 10px;
    margin: -7px 0;          /* 위아래 gap을 잠식해 군더더기 공백 최소화 */
    cursor: row-resize;
    position: relative;
    z-index: 6;
}
.v-resizer::before {
    content: '';
    position: absolute;
    left: 50%; top: 50%;
    transform: translate(-50%, -50%);
    width: 48px; height: 4px;
    border-radius: 3px;
    background: var(--border-color);
    transition: background var(--transition-fast), width var(--transition-fast);
}
.v-resizer:hover::before,
.v-resizer.dragging::before {
    background: var(--accent);
    width: 72px;
}

/* --- 종목 검색 (대시보드 좌측 패널) --- */
.stock-search {
    position: relative;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 8px;
}
.stock-search .search-ico {
    width: 16px; height: 16px;
    color: var(--text-muted);
    flex-shrink: 0;
}
#stock-search-input,
#multi-stock-search {
    flex-grow: 1;
    min-width: 0;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 13px;
}
#stock-search-input::placeholder,
#multi-stock-search::placeholder { color: var(--text-muted); }
.search-clear {
    background: none; border: none; color: var(--text-muted);
    font-size: 18px; cursor: pointer; line-height: 1; padding: 0 4px;
}
.search-clear:hover { color: var(--text-primary); }
.search-results {
    position: absolute;
    top: 100%; left: 8px; right: 8px;
    background-color: var(--bg-panel-header);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    box-shadow: 0 12px 30px rgba(0,0,0,0.45);
    z-index: 50;
    max-height: 340px;
    overflow-y: auto;
    padding: 4px;
}
.search-item {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 9px 12px;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
}
.search-item:hover, .search-item.kbd-active { background-color: var(--bg-card-hover); }
.search-item .si-name { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.search-item .si-code { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); margin-left: 6px; }
.search-item .si-market { font-size: 10.5px; color: var(--text-secondary); border: 1px solid var(--border-color); border-radius: 4px; padding: 1px 6px; }
.search-empty { padding: 14px; text-align: center; color: var(--text-muted); font-size: 12.5px; }

/* --- 텔레그램 매칭 분류 필터 칩 --- */
.news-filter {
    display: flex;
    gap: 6px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    flex-wrap: wrap;
}
.nf-chip {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 11.5px;
    font-weight: 600;
    padding: 4px 11px;
    border-radius: 999px;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}
.nf-chip:hover { color: var(--text-primary); border-color: var(--text-secondary); }
.nf-chip.active { background-color: var(--accent); color: #fff; border-color: var(--accent); }

/* --- 페이지 네비게이션 (대시보드/메인/채팅 공통) --- */
.main-nav { display: flex; gap: 6px; }
.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    padding: 6px 14px;
    border-radius: var(--border-radius-sm);
    border: 1px solid transparent;
    transition: all var(--transition-fast);
    white-space: nowrap;
}
.nav-link:hover { color: var(--text-primary); background-color: rgba(255,255,255,0.04); }
.nav-link.active { color: var(--text-primary); background-color: var(--accent); }

.header-logo h1 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.5px;
    background: linear-gradient(120deg, #ffffff 40%, #cbd5e1 90%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.pulse-icon {
    width: 10px;
    height: 10px;
    background-color: var(--accent);
    border-radius: 50%;
    position: relative;
    box-shadow: 0 0 10px var(--accent);
}

.pulse-icon::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background-color: var(--accent);
    border-radius: 50%;
    animation: ripple 2s infinite ease-in-out;
}

@keyframes ripple {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(3); opacity: 0; }
}

.market-tickers {
    display: flex;
    gap: 16px;
}

.ticker-card {
    background-color: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    padding: 6px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}

.ticker-name {
    font-weight: 600;
    color: var(--text-secondary);
}

.ticker-value {
    font-family: var(--font-mono);
    font-weight: 500;
}

.ticker-change.up { color: var(--up-color); }
.ticker-change.down { color: var(--down-color); }

.header-status {
    display: flex;
    align-items: center;
    gap: 20px;
}

/* 언어 스위처 (i18n.js가 주입) */
.lang-switch {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
}
.lang-switch .lang-opt {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 2px 6px;
    border-radius: 4px;
    transition: color .15s, background .15s;
}
.lang-switch .lang-opt:hover { color: var(--text-primary); }
.lang-switch .lang-opt.active {
    color: var(--text-primary);
    background: var(--bg-elevated, rgba(255,255,255,.08));
    font-weight: 600;
    cursor: default;
}

.time-display {
    font-family: var(--font-mono);
    color: var(--text-secondary);
    font-size: 15px;
    letter-spacing: 0.5px;
}

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

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--text-muted);
}

.connection-status.connected .status-dot {
    background-color: var(--up-color);
    box-shadow: 0 0 8px var(--up-color);
}

.connection-status.disconnected .status-dot {
    background-color: var(--down-color);
    box-shadow: 0 0 8px var(--down-color);
}

/* --- Main Layout Grid --- */
.dashboard-main {
    flex-grow: 1;
    display: flex;
    padding: 16px;
    gap: 16px;
    height: calc(100vh - 64px);
    overflow: hidden;
}

.panel {
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

.panel-header {
    background-color: var(--bg-panel-header);
    border-bottom: 1px solid var(--border-color);
    padding: 14px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.panel-title-area {
    display: flex;
    align-items: center;
    gap: 10px;
}

.panel-title-area h2 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.panel-subtitle {
    font-size: 12px;
    color: var(--text-muted);
}

.stock-panel-content {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.mobile-stock-toggle { display: none; }

/* --- Icons --- */
.icon {
    width: 18px;
    height: 18px;
    color: var(--accent);
}

.icon-sm {
    width: 16px;
    height: 16px;
}

/* --- Left Panel: Stock Table --- */
.left-panel {
    width: 380px;
    flex-shrink: 0;
}

.list-container {
    flex-grow: 1;
    overflow-y: auto;
}

.stock-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.stock-table th, .stock-table td {
    padding: 8px 6px;
    font-size: 12.5px;
    border-bottom: 1px solid #141b29;
}

.stock-table th {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    position: sticky;
    top: 0;
    background-color: var(--bg-panel);
    z-index: 1;
    border-bottom: 2px solid var(--border-color);
}

.stock-table tbody tr {
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.stock-table tbody tr[draggable="true"] { cursor: grab; }
.stock-table tbody tr[draggable="true"]:active { cursor: grabbing; }

.stock-table tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.02);
}

.stock-table tbody tr.active {
    background-color: rgba(41, 98, 255, 0.08);
    border-left: 3px solid var(--accent);
}

.col-rank {
    width: 40px;
    text-align: center;
    font-weight: 600;
    color: var(--text-muted);
}

.col-name {
    max-width: 120px;
}

.stock-name-cell {
    display: flex;
    flex-direction: column;
}

.stock-fullname {
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stock-code-lbl {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.font-mono {
    font-family: var(--font-mono);
}

.text-right {
    text-align: right;
}

/* Price blink animations */
.blink-up {
    animation: blink-green-anim 0.8s ease-out;
}

.blink-down {
    animation: blink-red-anim 0.8s ease-out;
}

@keyframes blink-green-anim {
    0% { background-color: var(--up-blink); }
    100% { background-color: transparent; }
}

@keyframes blink-red-anim {
    0% { background-color: var(--down-blink); }
    100% { background-color: transparent; }
}

/* Color states */
.txt-up { color: var(--up-color); }
.txt-down { color: var(--down-color); }
.txt-flat { color: var(--text-secondary); }

/* --- Right Column & Panels --- */
.right-column {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow: hidden;
}

/* --- Chart Panel --- */
.chart-panel {
    flex: 3 1 0; /* 60% of right side — basis:0 so the ratio holds regardless of content */
    min-height: 0;
    position: relative;
}

.chart-header-details {
    padding: 10px 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.selected-stock-info {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}

.stock-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stock-badge {
    background-color: var(--border-color);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--border-radius-sm);
    padding: 2px 5px;
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--text-secondary);
}

.quote-source-badge {
    padding: 2px 6px;
    border: 1px solid rgba(45, 212, 191, 0.28);
    border-radius: 999px;
    color: #5eead4;
    background: rgba(13, 148, 136, 0.1);
    font-size: 9.5px;
    line-height: 1.4;
    white-space: nowrap;
}

.quote-source-badge.is-delayed {
    border-color: rgba(251, 191, 36, 0.3);
    color: #fbbf24;
    background: rgba(217, 119, 6, 0.1);
}

.quote-source-badge[hidden] { display: none; }

.selected-stock-info h2 {
    font-size: 16px;
    font-weight: 700;
}

.stock-stats-row {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    border-left: 1px solid var(--border-color);
    padding-left: 16px;
}

.stat-item {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 10.5px;
    color: var(--text-muted);
}

.stat-value {
    font-size: 13.5px;
    font-weight: 600;
}

.chart-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chart-settings-wrap {
    position: relative;
}

.btn-chart-settings {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 30px;
    padding: 0 9px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
}

.btn-chart-settings:hover,
.btn-chart-settings[aria-expanded="true"] {
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

.chart-settings-menu {
    position: absolute;
    top: calc(100% + 7px);
    right: 0;
    z-index: 30;
    width: 230px;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: #141a27;
    box-shadow: 0 14px 35px rgba(0, 0, 0, 0.42);
}

.chart-settings-menu[hidden] { display: none; }

.chart-switch {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 32px;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
}

.chart-switch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.chart-switch i {
    position: relative;
    width: 34px;
    height: 18px;
    flex: 0 0 34px;
    border-radius: 999px;
    background: #334155;
    transition: background var(--transition-fast);
}

.chart-switch i::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #cbd5e1;
    transition: transform var(--transition-fast);
}

.chart-switch input:checked + i { background: var(--accent); }
.chart-switch input:checked + i::after { transform: translateX(16px); background: white; }
.chart-switch input:focus-visible + i { outline: 2px solid #93c5fd; outline-offset: 2px; }

.chart-settings-note {
    margin: 8px 0 0;
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 10px;
    line-height: 1.45;
}

.chart-settings-note-secondary {
    margin-top: 5px;
    padding-top: 0;
    border-top: 0;
}

.chart-shortcut-note {
    margin: 7px 0 0;
    color: #93c5fd;
    font-size: 10px;
    line-height: 1.4;
}

.timeframe-group {
    display: flex;
    gap: 2px;
    background-color: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: 2px;
}

.timeframe-badge {
    background-color: transparent;
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.timeframe-badge:hover {
    color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.05);
}

.timeframe-badge.active {
    background-color: var(--accent);
    color: white;
}

.btn-refresh {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: var(--border-radius-sm);
    padding: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.btn-refresh:hover {
    color: var(--text-primary);
    border-color: var(--text-secondary);
    background-color: rgba(255, 255, 255, 0.02);
}

.chart-controls button:disabled,
.btn-discovery:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    filter: grayscale(0.35);
}

.chart-container-wrapper {
    flex-grow: 1;
    min-height: 0;
    position: relative;
    width: 100%;
    background-color: var(--bg-panel);
    display: flex;
    flex-direction: row;
    overflow: hidden;
}

.chart-container-wrapper.stock-drop-target {
    box-shadow: inset 0 0 0 2px #60a5fa, inset 0 0 34px rgba(41, 98, 255, 0.2);
}

.chart-container-wrapper.stock-drop-target::after {
    content: '여기에 놓아 종목 전환';
    position: absolute;
    z-index: 12;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    padding: 10px 16px;
    border: 1px solid rgba(147, 197, 253, 0.72);
    border-radius: 7px;
    color: #eff6ff;
    background: rgba(30, 64, 175, 0.9);
    box-shadow: 0 10px 28px rgba(0,0,0,.35);
    font-size: 13px;
    font-weight: 700;
    pointer-events: none;
}

.chart-stage {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
}

.chart-view {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
}

.range-overlap-heatmap {
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.v827-resistance-overlay {
    position: absolute;
    inset: 0;
    z-index: 3;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.v827-tooltip {
    position: absolute;
    z-index: 9;
    min-width: 190px;
    max-width: min(280px, calc(100% - 20px));
    padding: 9px 10px;
    border: 1px solid rgba(255, 90, 165, 0.45);
    border-radius: 7px;
    color: #e2e8f0;
    background: rgba(15, 19, 30, 0.96);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.42);
    font-size: 10.5px;
    line-height: 1.4;
    pointer-events: none;
}

.v827-tooltip[hidden] { display: none; }
.v827-tooltip-title,
.v827-tooltip-row { display: flex; justify-content: space-between; gap: 12px; }
.v827-tooltip-title { margin-bottom: 5px; color: #f9a8d4; font-size: 11px; }
.v827-tooltip-row span { color: #94a3b8; }
.v827-tooltip strong { color: #f8fafc; font-weight: 600; text-align: right; }

.range-overlap-profile {
    display: none;
    flex: 0 0 92px;
    width: 92px;
    height: 100%;
    border-left: 1px solid rgba(255, 132, 0, 0.2);
    background: #0f131e;
    pointer-events: none;
}

.range-overlap-profile.is-visible {
    display: block;
}

.chart-drawing-overlay {
    position: absolute;
    inset: 0;
    z-index: 4;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.chart-drawing-overlay.is-drawing {
    pointer-events: auto;
    cursor: crosshair;
    touch-action: none;
}

.chart-drawing-overlay.is-editing {
    pointer-events: auto;
    cursor: move;
    touch-action: none;
}

.chart-drawing-toolbar {
    position: absolute;
    z-index: 7;
    top: 8px;
    left: 8px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 5px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 7px;
    background: rgba(15, 19, 30, 0.92);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(5px);
}

.drawing-tool {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 4px;
    color: #94a3b8;
    background: transparent;
    font: 600 16px/1 Inter, sans-serif;
    cursor: pointer;
}

.drawing-tool svg {
    width: 17px;
    height: 17px;
    pointer-events: none;
}

.drawing-tool-position .tp-zone { fill: rgba(34, 197, 94, 0.78); }
.drawing-tool-position .sl-zone { fill: rgba(239, 68, 68, 0.78); }

.drawing-tool:hover {
    color: #f8fafc;
    background: rgba(148, 163, 184, 0.12);
}

.drawing-tool.active {
    color: #facc15;
    border-color: rgba(250, 204, 21, 0.38);
    background: rgba(250, 204, 21, 0.12);
}

.drawing-tool-divider {
    height: 1px;
    margin: 2px 3px;
    background: rgba(148, 163, 184, 0.18);
}

.chart-toast {
    position: absolute;
    z-index: 9;
    left: 50%;
    bottom: 14px;
    max-width: calc(100% - 28px);
    padding: 9px 13px;
    border: 1px solid rgba(34, 197, 94, 0.38);
    border-radius: 7px;
    color: #dcfce7;
    background: rgba(20, 83, 45, 0.94);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.34);
    font-size: 12px;
    pointer-events: none;
    opacity: 0;
    transform: translate(-50%, 8px);
    transition: opacity 140ms ease, transform 140ms ease;
}

.chart-toast.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

.chart-toast.is-error {
    color: #fee2e2;
    border-color: rgba(239, 68, 68, 0.42);
    background: rgba(127, 29, 29, 0.94);
}

.chart-loading {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 19, 30, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    z-index: 5;
    transition: opacity var(--transition-normal);
}

.chart-loading.hidden {
    display: none !important;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(41, 98, 255, 0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s infinite linear;
}

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

/* --- Telegram News Panel --- */
.news-panel {
    flex: 2 1 0; /* 40% of right side — basis:0 so news content can't squeeze the chart */
    min-height: 0;
}

.news-header {
    border-bottom: 1px solid var(--border-color);
}

.badge {
    background-color: rgba(41, 98, 255, 0.1);
    border: 1px solid rgba(41, 98, 255, 0.2);
    color: var(--accent);
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 12px;
    font-weight: 500;
}

.timeline-container {
    flex-grow: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.news-card {
    background-color: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: all var(--transition-fast);
    animation: slide-in 0.3s ease-out;
}

.news-card:hover {
    border-color: rgba(41, 98, 255, 0.3);
    background-color: rgba(255, 255, 255, 0.04);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
}

@keyframes slide-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.news-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
}

.news-meta-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

/* 매칭 분류 배지: 직접언급 / 온톨로지 / 관련·테마 / 관련·유사 */
.news-class-badge {
    flex-shrink: 0;
    font-size: 10.5px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 4px;
    letter-spacing: 0.02em;
    border: 1px solid transparent;
}
.news-class-badge.cls-direct {
    color: var(--accent);
    background: rgba(41, 98, 255, 0.12);
    border-color: rgba(41, 98, 255, 0.35);
}
.news-class-badge.cls-ontology {
    color: #e2a93b;
    background: rgba(226, 169, 59, 0.12);
    border-color: rgba(226, 169, 59, 0.38);
}
.news-class-badge.cls-theme {
    color: var(--up-color);
    background: rgba(38, 166, 154, 0.12);
    border-color: rgba(38, 166, 154, 0.35);
}
.news-class-badge.cls-semantic {
    color: #b07cff;
    background: rgba(176, 124, 255, 0.12);
    border-color: rgba(176, 124, 255, 0.35);
}

.news-source-tag {
    color: var(--accent);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.news-source-tag::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background-color: var(--accent);
    border-radius: 50%;
}

.news-time {
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.news-content {
    font-size: 13.5px;
    color: var(--text-primary);
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-all;
}

.news-content a {
    color: var(--accent);
    text-decoration: none;
}

.news-content a:hover {
    text-decoration: underline;
}

.news-content mark {
    background-color: rgba(41, 98, 255, 0.25);
    color: #ffffff;
    border-bottom: 2px solid var(--accent);
    padding: 0 2px;
    border-radius: 2px;
}

.news-footer {
    display: flex;
    justify-content: flex-end;
    font-size: 11px;
    color: var(--text-muted);
}

.relevance-score {
    display: flex;
    align-items: center;
    gap: 4px;
}

.relevance-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--up-color);
}

/* Empty states */
.empty-timeline {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    gap: 12px;
    padding: 32px 0;
}

.empty-icon {
    width: 48px;
    height: 48px;
    color: var(--border-color);
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #1e293b;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #334155;
}

/* Skeleton loader for tables */
.skeleton-row td {
    color: var(--text-muted);
    text-align: center;
    padding: 32px 0;
    font-style: italic;
}

/* Responsive Media Queries */
@media (max-width: 1200px) {
    .selected-stock-info {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    .stock-stats-row {
        border-left: none;
        padding-left: 0;
        gap: 12px;
    }
    .chart-header-details {
        padding: 8px 12px;
    }
}

/* --- AI 심층분석 버튼 + 리포트 모달 --- */
.btn-report {
    display: inline-flex; align-items: center; gap: 6px;
    background: linear-gradient(135deg, var(--accent), #1557ff);
    color: #fff; border: none; border-radius: var(--border-radius-sm);
    font-size: 12px; font-weight: 600; padding: 6px 12px; cursor: pointer;
    transition: all var(--transition-fast); white-space: nowrap;
}
.btn-report:hover { filter: brightness(1.12); box-shadow: 0 0 14px var(--accent-glow); }
.btn-report-sec { background: transparent; border: 1px solid var(--border-color); color: var(--text-secondary); }
.btn-report-sec:hover { color: var(--text-primary); border-color: var(--accent); background: rgba(41,98,255,0.08); box-shadow: none; filter: none; }
.btn-report:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }
.btn-report .icon-sm { width: 14px; height: 14px; }

.report-modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.report-modal[hidden] { display: none; }
.report-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(2px); }
.report-dialog {
    position: relative; width: min(720px, 92vw); max-height: 88vh;
    background: var(--bg-panel); border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg); box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    display: flex; flex-direction: column; overflow: hidden;
}
.report-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border-color); background: var(--bg-panel-header); }
.report-title { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 700; }
.report-title .icon-sm { width: 16px; height: 16px; color: var(--accent); }
.report-stock { color: var(--accent); }
.report-close { background: none; border: none; color: var(--text-muted); font-size: 24px; line-height: 1; cursor: pointer; padding: 0 4px; }
.report-close:hover { color: var(--text-primary); }
.report-scroll { flex-grow: 1; overflow-y: auto; padding: 18px 20px; min-height: 180px; }
.report-foot { padding: 10px 18px; border-top: 1px solid var(--border-color); font-size: 11px; color: var(--text-muted); text-align: center; }

/* 작성중 로더 (동적 애니메이션) */
.report-loader { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 34px 0; }
.report-loader[hidden] { display: none; }
.report-spinner { width: 38px; height: 38px; border: 3px solid rgba(41,98,255,0.15); border-top-color: var(--accent); border-radius: 50%; animation: rspin 0.8s linear infinite; }
@keyframes rspin { to { transform: rotate(360deg); } }
.report-status-text { font-size: 14px; color: var(--text-secondary); font-weight: 500; }
.rdots i { font-style: normal; animation: rblink 1.4s infinite both; opacity: 0.2; }
.rdots i:nth-child(2) { animation-delay: 0.2s; }
.rdots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes rblink { 0%, 80%, 100% { opacity: 0.2; } 40% { opacity: 1; } }
.report-progress { width: 220px; height: 3px; background: var(--border-color); border-radius: 2px; overflow: hidden; }
.report-progress-bar { width: 35%; height: 100%; background: var(--accent); border-radius: 2px; animation: rprog 1.3s ease-in-out infinite; }
@keyframes rprog { 0% { transform: translateX(-130%); } 100% { transform: translateX(360%); } }
.report-reasoning { max-width: 520px; max-height: 84px; overflow: hidden; font-size: 12px; color: var(--text-muted); line-height: 1.6; text-align: center; opacity: 0.75; padding: 0 10px; }
.report-reasoning[hidden] { display: none; }

/* 리포트 마크다운 */
.report-content { font-size: 14px; line-height: 1.7; color: var(--text-secondary); }
.report-content h2 { font-size: 16px; color: var(--text-primary); margin: 16px 0 8px; padding-bottom: 4px; border-bottom: 1px solid var(--border-color); }
.report-content h2:first-child { margin-top: 0; }
.report-content h3 { font-size: 14px; color: var(--text-primary); margin: 12px 0 6px; }
.report-content ul, .report-content ol { margin: 6px 0 10px; padding-left: 20px; }
.report-content li { margin: 3px 0; }
.report-content p { margin: 6px 0; }
.report-content strong { color: var(--text-primary); font-weight: 600; }
.report-content table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 13px; }
.report-content th, .report-content td { border: 1px solid var(--border-color); padding: 6px 10px; text-align: left; }
.report-content th { background: var(--bg-panel-header); }
.report-content .scursor { display: inline-block; width: 7px; height: 14px; background: var(--accent); animation: rblink 1s infinite; vertical-align: text-bottom; margin-left: 1px; }

/* ④ 타임라인 기간 선택 팝오버 */
.tl-wrap { position: relative; display: inline-flex; }
.tl-menu {
    position: absolute; top: calc(100% + 6px); right: 0; z-index: 50;
    display: flex; flex-direction: column; min-width: 124px; padding: 5px;
    background: var(--bg-panel); border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md); box-shadow: 0 8px 24px rgba(0,0,0,0.45);
}
.tl-menu[hidden] { display: none; }
.tl-menu button {
    text-align: left; padding: 7px 10px; cursor: pointer; font-size: 12.5px;
    background: none; border: none; border-radius: var(--border-radius-sm);
    color: var(--text-secondary); transition: background 0.12s, color 0.12s;
}
.tl-menu button:hover { background: var(--bg-card-hover); color: var(--text-primary); }

/* ② AI 종목 발굴 */
.btn-discovery {
    display: flex; align-items: center; gap: 8px; width: 100%;
    margin: 8px 0 4px; padding: 9px 12px; cursor: pointer;
    background: linear-gradient(90deg, rgba(41,98,255,0.16), rgba(41,98,255,0.05));
    border: 1px solid rgba(41,98,255,0.35); border-radius: var(--border-radius-md);
    color: var(--text-primary); font-size: 13px; font-weight: 600;
    transition: border-color 0.15s, background 0.15s;
}
.btn-discovery:hover { border-color: var(--accent); background: linear-gradient(90deg, rgba(41,98,255,0.26), rgba(41,98,255,0.1)); }
.btn-discovery .disc-ico { font-size: 15px; }
.btn-discovery .disc-hint { margin-left: auto; font-size: 11px; font-weight: 400; color: var(--text-muted); }

.disc-dialog { width: min(640px, 94vw); }
.disc-query-row { display: flex; gap: 8px; padding: 16px 18px 8px; }
#discovery-input {
    flex: 1; padding: 10px 12px; font-size: 14px;
    background: var(--bg-panel-header); border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md); color: var(--text-primary); outline: none;
}
#discovery-input:focus { border-color: var(--accent); }
#discovery-input::placeholder { color: var(--text-muted); }
#discovery-run { white-space: nowrap; }
.disc-examples { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 0 18px 8px; font-size: 11.5px; color: var(--text-muted); }
.disc-examples button {
    padding: 3px 9px; cursor: pointer; font-size: 11.5px;
    background: var(--bg-card); border: 1px solid var(--border-color);
    border-radius: 20px; color: var(--text-secondary); transition: all 0.15s;
}
.disc-examples button:hover { color: var(--text-primary); border-color: var(--accent); }

.disc-results { display: flex; flex-direction: column; gap: 7px; }
.disc-head-line { font-size: 12.5px; color: var(--text-muted); margin-bottom: 4px; }
.disc-head-line strong { color: var(--accent); }
.disc-empty { padding: 28px 10px; text-align: center; color: var(--text-muted); font-size: 13px; }
.disc-row {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; cursor: pointer;
    background: var(--bg-card); border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md); transition: border-color 0.15s, background 0.15s;
}
.disc-row:hover { background: var(--bg-card-hover); border-color: var(--accent); }
.disc-rank { flex: 0 0 22px; text-align: center; font-size: 13px; font-weight: 700; color: var(--text-muted); font-family: var(--font-mono); }
.disc-main { flex: 1; min-width: 0; }
.disc-name-row { display: flex; align-items: baseline; gap: 7px; }
.disc-name { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.disc-code { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); }
.disc-mkt { font-size: 10px; color: var(--text-secondary); border: 1px solid var(--border-color); border-radius: 3px; padding: 0 5px; }
.disc-ev { margin-top: 3px; font-size: 11.5px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.disc-ev-meta { color: var(--text-secondary); }
.disc-metrics { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; flex: 0 0 auto; }
.disc-count { font-size: 12px; color: var(--text-secondary); font-family: var(--font-mono); }
.disc-sim { font-size: 12px; font-weight: 700; color: var(--accent); font-family: var(--font-mono); }

/* ===========================================================
   모바일 반응형 (≤768px): 데스크탑 가로분할/고정 100vh 레이아웃을
   세로 스택 + 문서 스크롤로 전환. 헤더는 2줄로 접고 네비를 분리.
   =========================================================== */
@media (max-width: 768px) {
    /* 고정 뷰포트 스크롤 잠금 해제 → 문서가 세로로 스크롤되게 */
    html, body {
        overflow-x: hidden;
        overflow-y: auto;
        height: auto;
        width: 100%;
    }
    .app-container {
        height: auto;
        min-height: 100dvh;
        width: 100%;
    }

    /* --- 헤더: 여러 줄로 접기. (대시보드는 header-left 중첩 있음) --- */
    .dashboard-header {
        height: auto;
        min-height: 52px;
        flex-wrap: wrap;
        align-items: center;
        padding: 8px 12px;
        gap: 6px 10px;
        position: sticky;
        top: 0;
    }
    .header-logo { gap: 8px; min-width: 0; }
    /* 로고 제목이 한 글자씩 세로로 쪼개지지 않게 */
    .header-logo h1 { font-size: 14.5px; white-space: nowrap; }
    .pulse-icon { width: 8px; height: 8px; flex-shrink: 0; }

    /* 대시보드 전용: 로고+네비를 감싼 header-left를 전폭·세로 스택 */
    .header-left {
        flex: 1 1 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    /* 네비: 직계자식(main/chat)이든 header-left 안(dashboard)이든 전폭 가로스크롤 행 */
    .main-nav {
        order: 3;
        flex: 0 0 100%;
        width: 100%;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding-bottom: 2px;
    }
    .main-nav::-webkit-scrollbar { display: none; }
    .nav-link {
        min-height: 44px;
        padding: 5px 11px;
        display: inline-flex;
        align-items: center;
        font-size: 12px;
        flex-shrink: 0;
        touch-action: manipulation;
    }

    /* 미니 티커(KOSPI/KOSDAQ): 잘리지 않게 축소 + 줄바꿈 허용 */
    .market-tickers { flex: 1 1 auto; flex-wrap: wrap; gap: 6px 8px; min-width: 0; }
    .ticker-card { padding: 4px 9px; font-size: 11.5px; gap: 6px; }

    .header-status { flex: 0 0 auto; gap: 8px; }
    .header-status .status-text { display: none; }  /* 'WS 연결됨' 텍스트 생략, 점만 */
    .time-display { display: none; }  /* 모바일에선 시계 숨김(헤더 폭 절약·잘림 방지) */
    .connection-status { padding: 4px; font-size: 11px; }

    /* --- 대시보드: 좌(380px)/우 가로분할 → 세로 스택 --- */
    .dashboard-main {
        flex-direction: column;
        height: auto;
        overflow: visible;
        padding: 12px;
        gap: 12px;
    }
    .left-panel { width: 100%; flex-shrink: 1; }
    .left-panel .panel-subtitle { display: none; }
    .mobile-stock-toggle {
        min-width: 106px;
        min-height: 44px;
        padding: 0 11px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        border: 1px solid var(--border-color);
        border-radius: 7px;
        color: var(--text-secondary);
        background: rgba(255, 255, 255, 0.035);
        font: 600 12px/1 var(--font-ui);
        cursor: pointer;
        touch-action: manipulation;
    }
    .mobile-stock-toggle:active { background: rgba(41, 98, 255, 0.14); }
    .mobile-stock-toggle-icon {
        font-size: 18px;
        line-height: 1;
        transform: rotate(180deg);
        transition: transform var(--transition-fast);
    }
    .mobile-stock-collapsed .mobile-stock-toggle-icon { transform: none; }
    .mobile-stock-collapsed .stock-panel-content { display: none; }
    .mobile-stock-collapsed {
        position: relative;
        z-index: 20;
        overflow: visible;
    }
    .mobile-stock-collapsed > .panel-header {
        border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0;
    }
    .mobile-stock-collapsed > .stock-switch-search {
        border-radius: 0 0 var(--border-radius-lg) var(--border-radius-lg);
        background: var(--bg-panel);
    }
    .list-container { max-height: 52vh; overscroll-behavior: contain; }
    .right-column { width: 100%; overflow: visible; }

    /* 차트 캔버스의 min-content 폭이 flex 사슬을 타고 위로 전파돼
       panel-header(=차트 컨트롤)까지 부풀리는 것을 차단 (min-width:0) */
    .right-column, .chart-panel, .chart-container-wrapper, .chart-stage, .chart-view { min-width: 0; }
    .chart-container-wrapper { overflow: hidden; }

    /* 차트는 문서 스크롤 안에서 실제 높이가 필요 */
    .chart-panel {
        flex: 0 0 auto;
        height: 56vh;
        min-height: 300px;
        scroll-margin-top: 154px;
    }
    .v-resizer { display: none; }   /* 모바일에선 높이 조절 비활성화 */
    .news-panel {
        flex: 0 0 auto;
        height: clamp(420px, 72dvh, 720px);
        min-height: 420px;
        max-height: 720px;
    }
    .news-panel .timeline-container {
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }

    /* 차트 헤더: 정보/컨트롤을 세로로 → 컨트롤이 전폭을 받아 확실히 줄바꿈 */
    .chart-header-details { flex-direction: column; align-items: stretch; gap: 10px; }
    .chart-controls { flex-wrap: wrap; gap: 6px; width: 100%; }
    .chart-controls button,
    .nf-chip,
    .btn-discovery {
        min-height: 44px;
        touch-action: manipulation;
    }
    .timeframe-badge { min-width: 44px; padding: 4px 11px; }
    .btn-chart-settings { height: 44px; }
    .btn-refresh { width: 44px; height: 44px; }
    .chart-settings-menu {
        left: 0;
        right: auto;
        width: min(280px, calc(100vw - 36px));
    }
    .chart-switch { min-height: 44px; }
    .range-overlap-profile { flex-basis: 64px; width: 64px; }
    .stock-stats-row { border-left: none; padding-left: 0; gap: 12px; }

    /* 패널 헤더가 좁은 화면에서 우측 텍스트가 잘리지 않게 줄바꿈 */
    .panel-header { flex-wrap: wrap; gap: 4px 8px; }
    .panel-subtitle { font-size: 11px; }
    .disc-hint { display: none; }   /* '이슈·테마로 종목 찾기' 힌트 생략(공간 절약) */

    /* 종목 테이블 여백 축소 */
    .stock-table th, .stock-table td { padding: 8px 5px; font-size: 12px; }
    .stock-table tbody tr { height: 44px; }
    .col-name { max-width: 96px; }

    .stock-search { min-height: 52px; padding: 4px 10px; }
    #stock-search-input,
    #multi-stock-search { min-height: 44px; font-size: 16px; }
    .search-clear {
        width: 44px;
        height: 44px;
        flex: 0 0 44px;
        padding: 0;
        touch-action: manipulation;
    }
    .search-item { min-height: 44px; }

    .chart-drawing-toolbar {
        top: auto;
        right: 8px;
        bottom: 8px;
        left: 8px;
        flex-direction: row;
        overflow-x: auto;
        overscroll-behavior-x: contain;
        -webkit-overflow-scrolling: touch;
    }
    .drawing-tool {
        width: 44px;
        height: 44px;
        flex: 0 0 44px;
        touch-action: manipulation;
    }
    .drawing-tool-divider {
        width: 1px;
        height: 34px;
        margin: 5px 2px;
        flex: 0 0 1px;
    }

    /* 리포트/발굴 모달이 화면을 거의 채우도록 */
    .report-dialog { width: 94vw; max-height: 90dvh; }
}

@media (max-width: 480px) {
    .header-logo h1 { font-size: 14px; }
    .nav-link { padding: 5px 9px; }
    .chart-panel { height: 58dvh; min-height: 420px; }
    .news-panel { height: 68dvh; min-height: 400px; }
    .timeline-container { padding: 12px; }
    .range-overlap-profile { flex-basis: 52px; width: 52px; }
}

/* ===========================================================
   모바일 Lite 셸: 콘텐츠는 같은 URL/DOM을 쓰되 탐색 구조와 기본 노출을
   모바일 사용 목적에 맞게 축소한다. 데스크톱에는 영향 없음.
   =========================================================== */
.mobile-chart-more { display: none; }

@media (max-width: 768px) {
    :root {
        --mobile-header-height: 56px;
        --mobile-nav-height: 64px;
    }

    html { scroll-padding-top: calc(var(--mobile-header-height) + 8px); }
    body {
        padding-bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
    }
    .app-container {
        min-height: calc(100dvh - var(--mobile-nav-height) - env(safe-area-inset-bottom));
    }

    /* 상단은 브랜드·언어·연결상태만 남기고 페이지 이동은 하단 탭으로 이동 */
    .dashboard-header {
        position: sticky;
        top: 0;
        z-index: 90;
        width: 100%;
        height: var(--mobile-header-height);
        min-height: var(--mobile-header-height);
        padding: 0 12px;
        flex-wrap: nowrap;
        gap: 10px;
        background: rgba(15, 20, 31, 0.96);
        backdrop-filter: none;
    }
    .header-left {
        flex: 0 0 auto;
        width: auto;
        flex-direction: row;
        align-items: center;
    }
    .header-logo { gap: 8px; }
    .header-logo h1 { font-size: 16px; }
    .pulse-icon { width: 8px; height: 8px; }

    .main-nav {
        position: fixed;
        z-index: 100;
        left: 0;
        right: 0;
        bottom: 0;
        order: initial;
        width: 100%;
        height: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
        padding: 4px 6px max(4px, env(safe-area-inset-bottom));
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 2px;
        overflow: visible;
        border-top: 1px solid var(--border-color);
        background: rgba(15, 20, 31, 0.97);
        box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.28);
        backdrop-filter: blur(16px);
    }
    .nav-link {
        min-width: 0;
        min-height: 54px;
        padding: 4px 2px;
        border: 0;
        border-radius: 9px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        overflow: hidden;
        color: var(--text-muted);
        font-size: 10.5px;
        line-height: 1.1;
        text-overflow: ellipsis;
    }
    .nav-link::before {
        display: block;
        height: 18px;
        color: currentColor;
        font-size: 17px;
        font-weight: 500;
        line-height: 18px;
    }
    .nav-link[href$="/main"]::before { content: "⌂"; }
    .nav-link[href$="/dashboard"]::before { content: "⌕"; }
    .nav-link[href$="/charts"]::before { content: "⌁"; }
    .nav-link[href$="/chat"]::before { content: "✦"; }
    .nav-link[href$="/contact"]::before { content: "⋯"; }
    .nav-link.active {
        color: #93b4ff;
        background: rgba(41, 98, 255, 0.14);
    }

    .market-tickers { display: none; }
    .header-status {
        flex: 1 1 auto;
        min-width: 0;
        justify-content: flex-end;
        gap: 6px;
    }
    .lang-switch { gap: 2px; font-size: 11px; }
    .lang-switch .lang-opt { padding: 5px 6px; }
    .connection-status {
        min-width: 28px;
        height: 28px;
        padding: 0;
        justify-content: center;
        border: 0;
        background: transparent;
    }
    .header-status .status-text,
    .time-display { display: none; }

    /* 종목 탐색: 검색 → 핵심 시세 → 차트 → 뉴스 순으로만 기본 노출 */
    .dashboard-main { padding: 8px; gap: 8px; }
    .left-panel .panel-header { min-height: 58px; padding: 8px 12px; }
    .left-panel .panel-title-area { gap: 7px; }
    .left-panel .panel-title-area h2 { font-size: 14px; }
    .mobile-stock-toggle { min-width: 94px; min-height: 40px; }
    .list-container { max-height: 46dvh; }

    .chart-panel {
        height: 62dvh;
        min-height: 470px;
        scroll-margin-top: calc(var(--mobile-header-height) + 8px);
    }
    .chart-header-details { padding: 10px 12px; gap: 9px; }
    .selected-stock-info { gap: 8px; }
    .stock-title-row { width: 100%; }
    .selected-stock-info h2 { font-size: 17px; }
    .stock-stats-row {
        width: 100%;
        padding-left: 0;
        gap: 8px;
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
    .stat-item { min-width: 0; }
    .stat-value { font-size: 13px; white-space: nowrap; }

    .chart-controls { gap: 6px; }
    .timeframe-group {
        order: 1;
        flex: 1 1 auto;
        min-width: 0;
    }
    .timeframe-badge {
        min-width: 0;
        height: 40px;
        flex: 1 1 0;
        padding: 0 6px;
    }
    .mobile-chart-more {
        order: 2;
        min-width: 76px;
        height: 44px;
        padding: 0 10px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 5px;
        border: 1px solid var(--border-color);
        border-radius: var(--border-radius-sm);
        background: rgba(255, 255, 255, 0.03);
        color: var(--text-secondary);
        font: 600 11px/1 var(--font-ui);
    }
    .mobile-chart-more[aria-expanded="true"] {
        color: var(--text-primary);
        border-color: var(--accent);
        background: rgba(41, 98, 255, 0.12);
    }
    .chart-controls > #btn-ai-report,
    .chart-controls > #btn-compare,
    .chart-controls > .tl-wrap,
    .chart-controls > .chart-settings-wrap,
    .chart-controls > #btn-chart-refresh {
        display: none;
        order: 3;
    }
    .chart-panel.mobile-advanced-open .chart-controls > #btn-ai-report,
    .chart-panel.mobile-advanced-open .chart-controls > #btn-compare,
    .chart-panel.mobile-advanced-open .chart-controls > .tl-wrap,
    .chart-panel.mobile-advanced-open .chart-controls > .chart-settings-wrap,
    .chart-panel.mobile-advanced-open .chart-controls > #btn-chart-refresh {
        display: flex;
    }
    .chart-panel.mobile-advanced-open .chart-controls > .tl-wrap { display: block; }

    .chart-drawing-toolbar { display: none; }
    .chart-panel.mobile-advanced-open .chart-drawing-toolbar { display: flex; }
    .chart-settings-menu {
        position: fixed;
        z-index: 120;
        top: auto;
        right: 12px;
        bottom: calc(var(--mobile-nav-height) + 12px + env(safe-area-inset-bottom));
        left: 12px;
        width: auto;
        max-height: calc(100dvh - var(--mobile-header-height) - var(--mobile-nav-height) - 32px);
        overflow-y: auto;
        padding: 12px 14px;
        border-radius: 12px;
    }
    .chart-shortcut-note { display: none; }

    .news-filter {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding: 8px 10px;
        scrollbar-width: none;
    }
    .news-filter::-webkit-scrollbar { display: none; }
    .nf-chip { min-height: 36px; padding: 4px 12px; flex: 0 0 auto; }
}

@media (max-width: 380px) {
    .lang-switch .lang-opt { padding-inline: 4px; }
    .nav-link { font-size: 10px; }
    .left-panel .panel-title-area h2 { font-size: 13px; }
    .mobile-stock-toggle { min-width: 88px; padding-inline: 8px; }
}
