:root {
    --bg-dark: #0f172a;
    --bg-darker: #020617;
    --card-bg: rgba(30, 41, 59, 0.7);
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #10b981;
    --danger: #ef4444;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: rgba(255, 255, 255, 0.1);
    --sidebar-width: 200px;
    --font-family: 'Inter', sans-serif;
}

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

/* 모바일 브라우저의 자동 폰트 확대(text auto-inflation) 비활성화.
   같은 CSS 폰트 크기라도 블록별 텍스트 길이에 따라 확대 배율이 달라져
   숫자 크기가 들쭉날쭉 보이던 문제를 방지한다. */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    background-color: var(--bg-darker);
    color: var(--text-main);
    font-family: var(--font-family);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--card-bg);
    border-radius: 4px;
}

/* Layout */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #c8e6f8 0%, #a4ccec 100%);
    border-right: 1px solid rgba(100, 160, 210, 0.4);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px 12px;
}

.logo-img {
    width: 100%;
    height: auto;
    border-radius: 12px;
    object-fit: contain;
}

nav {
    display: flex;
    flex-direction: column;
    padding: 0 16px;
    gap: 8px;
    flex: 1;
}

.nav-item {
    padding: 10px 14px;
    border-radius: 8px;
    color: #1e3a5c;
    text-decoration: none;
    font-size: 1.1rem;
    font-weight: 500;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.nav-item:hover {
    background-color: rgba(0, 60, 120, 0.1);
    color: #0f2035;
}

.nav-item.active {
    background-color: rgba(25, 90, 160, 0.18);
    color: #1a5a9e;
    border-left: 3px solid #1a5a9e;
}

.sidebar .sidebar-bottom button {
    color: #1e3a5c;
    border-color: rgba(30, 58, 92, 0.35);
}

.sidebar-bottom {
    padding: 24px 16px;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 32px;
    padding-top: calc(32px + 64px);
    display: flex;
    flex-direction: column;
    gap: 24px;
    min-width: 0;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

header h2 {
    font-size: 28px;
    font-weight: 600;
}

/* Fixed page header (top bar) */
.page-header {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    z-index: 8;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #0c1a2e;
    padding: 14px 32px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}

/* Fixed bottom nav background */
.mobile-bottom-nav {
    background-color: #0c1a2e;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    color: var(--text-muted);
    font-size: 14px;
}

/* Buttons */
button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    outline: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.2s ease;
}

.btn-primary {
    background-color: var(--primary);
    color: #fff;
    padding: 10px 20px;
    box-shadow: 0 4px 14px 0 rgba(59, 130, 246, 0.39);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.23);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: transparent;
    color: var(--text-main);
    border: 1px solid var(--border);
    padding: 8px 16px;
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.btn-secondary.recording {
    background-color: rgba(239, 68, 68, 0.15);
    border-color: #ef4444;
    animation: pulse-recording 1.2s ease-in-out infinite;
}

@keyframes pulse-recording {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.ai-loading-bubble {
    font-style: italic;
    animation: pulse-recording 1.2s ease-in-out infinite;
}

.ai-suggestion-chip:hover {
    background: rgba(59, 130, 246, 0.15);
    border-color: var(--primary);
}

.btn-action {
    background-color: rgba(59, 130, 246, 0.15);
    color: var(--primary);
    border: 1px solid rgba(59, 130, 246, 0.3);
    padding: 8px 16px;
}

.btn-action:hover {
    background-color: rgba(59, 130, 246, 0.25);
    border-color: rgba(59, 130, 246, 0.5);
    color: #60a5fa;
}

.toggle-group {
    display: inline-flex;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 4px;
}

.btn-toggle {
    background: transparent;
    color: var(--text-muted);
    padding: 6px 12px;
    font-size: 13px;
    border-radius: 6px;
}

.btn-toggle:hover {
    color: var(--text-main);
}

.btn-toggle.active {
    background: var(--primary);
    color: #fff;
}

.full-width {
    width: 100%;
}

/* Cards */
.card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    min-width: 0;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2);
}

/* Summary Cards */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    row-gap: 4px;
    column-gap: 8px;
}

.summary-card h3 {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-weight: 500;
}

.summary-card .value {
    font-size: 28px;
    font-weight: 700;
}

.summary-card .rate {
    font-size: 28px;
    margin-top: 4px;
    font-weight: 700;
}

.summary-card .benchmark-value {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
    opacity: 0.8;
}

.positive { color: var(--success); }
.negative { color: var(--danger); }

/* Charts Section */
.charts-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.chart-card h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 20px;
}

.chart-card.full-width {
    grid-column: 1 / -1;
}

.chart-container {
    position: relative;
    height: 300px;
    width: 100%;
}

/* Morning Briefing */
.briefing-top-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
}
.taxtips-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}
.taxtip-card {
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s;
}
.taxtip-card:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
}
.taxtip-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.68rem;
    text-align: center;
    margin-bottom: 16px;
}
.taxtip-table th, .taxtip-table td {
    border: 1px solid var(--border);
    padding: 6px 4px;
    color: var(--text-main);
    line-height: 1.3;
}
.taxtip-table th {
    background: rgba(255, 255, 255, 0.08);
    font-weight: 600;
}
.taxtip-table .tt-label {
    background: rgba(34, 197, 94, 0.25);
    font-weight: 700;
}
.taxtip-table .tt-cyan { background: #67e8f9; color: #1a1a1a; font-weight: 700; }
.taxtip-table .tt-orange { background: #fb923c; color: #1a1a1a; font-weight: 700; }
/* tt-yellow(최우선순위 표시)는 tt-cyan/tt-orange와 같은 칸에 함께 붙을 수 있어
   두 클래스보다 뒤에 선언해, 같이 붙으면 노란색이 우선 표시되게 한다. */
.taxtip-table .tt-yellow { background: #fde047; color: #1a1a1a; font-weight: 700; }
.taxtip-table .tt-ok { background: rgba(34, 197, 94, 0.25); }
.taxtip-table .tt-fail { background: rgba(239, 68, 68, 0.3); }
.briefing-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.briefing-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 74px 54px;
    align-items: center;
    column-gap: 5px;
    min-height: 44px;
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.briefing-name {
    font-weight: 600;
    font-size: 0.88em;
    min-width: 0;
    /* 긴 지수명(예: 코스피200 야간선물, 필라델피아반도체(SOX))이 잘리지 않도록
       한 줄로 자르는 대신 여러 줄로 줄바꿈해 전부 표시한다. */
    white-space: normal;
    word-break: keep-all;      /* 한글은 어절(단어) 단위로 줄바꿈 */
    overflow-wrap: anywhere;   /* 공백 없는 긴 토큰도 넘치지 않게 */
    line-height: 1.25;
}
.briefing-price {
    font-size: 0.82em;
    color: var(--text-muted);
    text-align: right;
    white-space: nowrap;
}
.briefing-change {
    font-weight: 700;
    font-size: 0.85em;
    text-align: right;
    white-space: nowrap;
}
.briefing-empty {
    color: var(--text-muted);
    font-size: 0.85em;
    text-align: center;
    padding: 16px 0;
}
.briefing-news-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.briefing-news-item {
    display: block;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border);
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-main);
    transition: background 0.15s ease;
}
.briefing-news-item:hover {
    background: rgba(59, 130, 246, 0.12);
}
.briefing-news-title {
    font-size: 0.9em;
    font-weight: 600;
    line-height: 1.4;
    display: block;
    margin-bottom: 4px;
}
.briefing-news-source {
    font-size: 0.75em;
    color: var(--text-muted);
}
.briefing-pos {
    color: var(--success);
    font-weight: 600;
}
.briefing-neg {
    color: var(--danger);
    font-weight: 600;
}
.briefing-keyword {
    color: var(--text-main);
    font-weight: 700;
}
.briefing-source {
    color: var(--text-muted);
    font-size: 0.85em;
}
.briefing-ai-text {
    white-space: pre-wrap;
    line-height: 1.7;
    font-size: 0.92rem;
}
.briefing-outlook-card {
    border: 1px solid rgba(59, 130, 246, 0.35);
    background: rgba(59, 130, 246, 0.06);
}

/* 종목 상세 분석 모달 상단 통계 (종가/선형피팅/이평/편차/DD/초과낙폭) */
.analysis-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(78px, 1fr));
    gap: 10px 8px;
    font-size: 12px;
    background: rgba(0, 0, 0, 0.25);
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    margin-bottom: 2px;
}
.analysis-stat-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.analysis-stat-item .stat-label {
    color: var(--text-muted);
    font-size: 0.85em;
    white-space: nowrap;
}
.analysis-stat-item strong {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 변동성 차트는 범례가 변동성·하방변동성·VKOSPI 3개라 편차/DD 차트(범례 2개)보다
   좁은 화면에서 범례가 두 줄로 줄바꿈되기 쉬움 - 그만큼 실제 그래프가 그려지는
   영역이 줄어 다른 차트보다 작아 보이므로, 모바일 폭에서는 컨테이너 높이를
   늘려 줄바꿈된 범례 줄만큼을 보정한다. */
@media (max-width: 768px) {
    .analysis-chart-vol-wrap {
        height: 168px !important;
        min-height: 148px !important;
    }
}

/* Modals */
.modal {
    display: none; /* Hidden by default */
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    overflow-y: auto;
    padding: 20px;
}

.modal.show {
    display: flex !important;
    opacity: 1;
}

.modal-content {
    margin: auto;
    background-color: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: scale(0.95);
    transition: transform 0.3s ease;
}

/* 투자자 프로필 설문의 보기 칩(선택형 버튼) */
.ip-chip {
    padding: 8px 14px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s ease;
}
.ip-chip:hover {
    border-color: var(--primary);
    color: var(--text-main);
}
.ip-chip.selected {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    font-weight: 600;
}

.modal.show .modal-content {
    transform: scale(1);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.close-btn {
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.2s;
}

.close-btn:hover {
    color: var(--text-main);
}

.modal-body {
    padding: 24px;
}

.help-text {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
    line-height: 1.5;
    background: rgba(255, 255, 255, 0.05);
    padding: 12px;
    border-radius: 8px;
}

.help-text code {
    color: var(--primary);
    background: rgba(0,0,0,0.3);
    padding: 2px 4px;
    border-radius: 4px;
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 500;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px 16px;
    background-color: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-main);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
}

/* Data Table */
.table-container {
    overflow-x: auto;
}

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

.data-table th,
.data-table td {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.data-table th {
    color: var(--text-muted);
    font-weight: 500;
}

.data-table tbody tr {
    transition: background-color 0.2s;
}

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

.btn-edit {
    background: transparent;
    color: var(--primary);
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 4px 8px;
    border-radius: 4px;
}

.btn-edit:hover {
    background-color: rgba(59, 130, 246, 0.1);
}

.btn-delete {
    background: transparent;
    color: var(--danger);
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 4px 8px;
    border-radius: 4px;
}

.btn-delete:hover {
    background-color: rgba(239, 68, 68, 0.1);
}

.badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.badge.deposit, .badge.sell { background-color: rgba(16, 185, 129, 0.1); color: var(--success); }
.badge.withdraw, .badge.buy { background-color: rgba(239, 68, 68, 0.1); color: var(--danger); }

/* Management Modal Styles */
.management-list {
    list-style: none;
    margin-bottom: 16px;
    max-height: 200px;
    overflow-y: auto;
}

.management-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 14px;
}

.add-form {
    display: flex;
    gap: 8px;
}

.add-form input,
.add-form select {
    flex: 1;
    padding: 12px 16px;
    background-color: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-main);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s;
    margin-bottom: 0;
}

.add-form input:focus,
.add-form select:focus {
    outline: none;
    border-color: var(--primary);
}

/* Autocomplete Suggestions */
.suggestions-list {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background-color: var(--bg-dark);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 8px 8px;
    z-index: 1000;
    max-height: 200px;
    overflow-y: auto;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

.suggestion-item {
    padding: 10px 16px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-main);
    border-bottom: 1px solid var(--border);
    transition: background-color 0.2s;
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Responsive */
@media (max-width: 1024px) {
    .charts-section {
        grid-template-columns: 1fr;
    }
    .briefing-top-cards {
        grid-template-columns: 1fr;
    }
    .taxtips-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 5px 0 25px rgba(0, 0, 0, 0.5);
    }
    .sidebar.active {
        transform: translateX(0);
        width: var(--sidebar-width) !important;
        display: flex !important;
    }
    .sidebar.active .logo-img {
        width: 140px !important;
    }
    .sidebar.active nav {
        padding: 0 10px !important;
        gap: 4px !important;
    }
    .sidebar.active .nav-item {
        padding: 10px 10px !important;
        font-size: 17px !important;
    }
    .sidebar.active .sidebar-bottom {
        padding: 10px 10px !important;
    }
    .sidebar.active .sidebar-bottom button {
        padding: 6px 0 !important;
        font-size: 13px !important;
        color: #1e3a5c !important;
        margin-bottom: 6px !important;
    }
    .sidebar-overlay.active {
        display: block !important;
        opacity: 1;
    }
    .main-content {
        margin-left: 0;
        padding: 12px;
        padding-top: calc(12px + 56px) !important;
        padding-bottom: 70px;
        gap: 12px !important;
    }
    .page-header {
        left: 0 !important;
        padding: 10px 16px !important;
    }
    .main-content .card {
        margin-bottom: 12px !important;
    }
    .main-content section {
        margin-bottom: 12px !important;
        gap: 12px !important;
    }
    .hamburger-btn {
        display: block !important;
    }
    .mobile-bottom-nav {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-around !important;
        align-items: center !important;
    }
    .mobile-nav-btn {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 6px !important;
        width: auto !important;
        flex: 1 !important;
        padding: 8px 4px !important;
        background: transparent !important;
        border: none !important;
    }
    .mobile-nav-btn.mobile-nav-btn-hidden {
        display: none !important;
        flex: 0 !important;
        width: 0 !important;
        padding: 0 !important;
        overflow: hidden !important;
    }
    .mobile-nav-btn span:first-child {
        font-size: 20px !important;
    }
    .mobile-nav-btn span:last-child {
        display: inline-block !important;
        font-size: 13px !important;
    }
    .summary-cards {
        grid-template-columns: repeat(2, 1fr) !important;
        row-gap: 4px !important;
        column-gap: 12px !important;
    }
    .summary-card {
        padding: 14px !important;
    }
    .summary-card h3 {
        font-size: 11px !important;
        margin-bottom: 4px !important;
    }
    .summary-card .value, .summary-card .rate {
        font-size: 18px !important;
    }
    header h2, .page-header h2 {
        font-size: 20px !important;
    }
    
    /* 모달 전체화면 모바일 대응 */
    .modal {
        padding: 0 !important;
    }
    .modal-content {
        width: 100vw !important;
        height: 100vh !important;
        max-width: none !important;
        border-radius: 0 !important;
        border: none !important;
        margin: 0 !important;
        display: flex;
        flex-direction: column;
    }
    .modal-body {
        flex: 1;
        overflow-y: auto;
        padding: 16px !important;
    }
    .modal-header {
        padding: 16px !important;
    }
    .close-btn {
        font-size: 32px !important;
        padding: 4px 12px;
    }
    /* 보유종목이력 날짜별 상세내역 가로 스크롤 레이아웃 최적화 */
    .history-detail-container {
        flex-direction: column !important;
        height: auto !important;
    }
    .history-detail-sidebar {
        width: 100% !important;
        border-right: none !important;
        border-bottom: 1px solid var(--border);
        flex-direction: row !important;
        padding-bottom: 10px !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        white-space: nowrap !important;
        gap: 8px !important;
    }
    .history-detail-tab-btn {
        width: auto !important;
        display: inline-block !important;
        padding: 8px 12px !important;
    }
    .history-detail-content {
        padding-left: 0 !important;
        margin-top: 15px !important;
    }
    .history-summary-box {
        flex-wrap: wrap !important;
        gap: 10px !important;
    }
    .history-summary-item {
        border-left: none !important;
        padding-left: 0 !important;
        flex: 1 1 45% !important;
    }
    /* 테이블 및 UI 글자 크기 축소 */
    .data-table th, .data-table td {
        font-size: 11px !important;
        padding: 8px 6px !important;
    }
    .management-section h3 {
        font-size: 13px !important;
    }
    .management-section h3 span {
        font-size: 12px !important;
    }
    /* 설정 창 스타일 축소 */
    .settings-modal-container {
        flex-direction: column !important;
        gap: 12px !important;
    }
    .settings-sidebar {
        width: 100% !important;
        flex-direction: row !important;
        overflow-x: auto !important;
        white-space: nowrap !important;
        border-right: none !important;
        border-bottom: 1px solid var(--border) !important;
        padding-bottom: 8px !important;
    }
    .settings-tab-btn {
        padding: 6px 12px !important;
        font-size: 11px !important;
        display: inline-block !important;
    }
    .settings-content-area {
        padding-left: 0 !important;
    }
    .settings-content-area h3 {
        font-size: 13px !important;
    }
    .settings-content-area p {
        font-size: 10.5px !important;
    }
    .settings-content-area label {
        font-size: 10.5px !important;
    }
    .settings-content-area input, .settings-content-area select, .settings-content-area button {
        font-size: 11px !important;
        padding: 6px 10px !important;
    }
    .management-list li {
        font-size: 11px !important;
        padding: 6px 10px !important;
    }
    /* 도움말 창 축소 */
    .help-modal-container {
        flex-direction: column !important;
        /* 모바일: 헤더+하단 네비 제외 전체 높이 사용, 작은 화면에서 min-height가
           넘치지 않도록 해제 */
        height: calc(100vh - 152px) !important;
        height: calc(100dvh - 152px) !important;
        min-height: 0 !important;
    }
    .help-sidebar {
        width: 100% !important;
        flex-direction: row !important;
        overflow-x: auto !important;
        white-space: nowrap !important;
        border-right: none !important;
        border-bottom: 1px solid var(--border) !important;
    }
    .help-tab-btn {
        padding: 6px 12px !important;
        font-size: 11px !important;
        display: inline-block !important;
    }
    .help-content {
        padding-left: 0 !important;
        font-size: 11px !important;
    }
    /* 자료실 축소 - 설정 탭처럼 한 줄로 가로 스크롤 */
    .archive-tabs {
        overflow-x: auto !important;
        flex-wrap: nowrap !important;
        white-space: nowrap !important;
    }
    .archive-tab-btn {
        padding: 8px 14px !important;
        font-size: 11px !important;
        flex-shrink: 0 !important;
    }
    .archive-section label, .archive-section span {
        font-size: 11px !important;
    }
    /* 위 규칙이 절세팁 카드 제목의 span(아이콘/제목 텍스트)까지 11px로 줄여버려
       데스크톱과 달리 모바일에서만 제목이 설명보다 작아 보이던 문제를 보정 */
    span.taxtip-card-icon {
        font-size: 1.4rem !important;
    }
    span.taxtip-card-title-text {
        font-size: 0.85rem !important;
    }
    .archive-section input, .archive-section button {
        font-size: 11px !important;
    }
    .taxtip-table {
        font-size: 10px !important;
    }
    .taxtip-table th, .taxtip-table td {
        padding: 4px 3px !important;
    }
}

/* 360px 이하 초소형 스마트폰 대응 */
@media (max-width: 360px) {
    .main-content {
        padding: 10px !important;
        padding-bottom: 70px !important;
    }
    header h2 {
        font-size: 16px !important;
    }
    #mobile-hamburger-btn {
        font-size: 20px !important;
        padding: 2px 4px !important;
    }
    /* 요약 카드: 1열로 변경 */
    .summary-cards {
        grid-template-columns: 1fr !important;
        gap: 4px !important;
    }
    .summary-card {
        padding: 10px !important;
    }
    .summary-card h3 {
        font-size: 10px !important;
    }
    .summary-card .value, .summary-card .rate {
        font-size: 15px !important;
    }
    .mobile-nav-btn {
        gap: 2px !important;
        padding: 6px 2px !important;
    }
    .mobile-nav-btn span:first-child {
        font-size: 14px !important;
    }
    .mobile-nav-btn span:last-child {
        font-size: 10px !important;
    }
    .card {
        padding: 14px !important;
    }
    /* 히트맵 셀 크기 축소 */
    .heatmap-cell {
        width: 38px !important;
        height: 18px !important;
        font-size: 8px !important;
    }
    .heatmap-header {
        font-size: 8px !important;
    }
    .heatmap-month-header {
        width: 30px !important;
    }
    /* ETF 테이블: 덜 중요한 컬럼 숨김 */
    .col-issuer, .col-date, .col-velocity {
        display: none !important;
    }
    .data-table th, .data-table td {
        font-size: 10px !important;
        padding: 6px 4px !important;
    }
    /* 모달 내부 여백 축소 */
    .modal-body {
        padding: 12px !important;
    }
    .modal-header {
        padding: 10px 12px !important;
    }
}

/* Macro Charts Section */
.macro-charts-section {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}
@media (max-width: 1200px) {
    .macro-charts-section {
        grid-template-columns: 1fr;
    }
}
.macro-card {
    min-height: 350px;
}

/* Global Heatmap CSS */
.heatmap-container {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin-top: 10px;
    overflow-x: auto;
    padding-bottom: 6px;
}
.heatmap-row {
    display: flex;
    gap: 1px;
    flex-wrap: nowrap;
}
.heatmap-cell {
    width: 44px;
    height: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: 600;
    color: white;
    position: relative;
    border-radius: 0;
    flex-shrink: 0;
    line-height: 1;
}
.heatmap-cell span {
    font-size: 0.8em;
    opacity: 0.8;
    margin-bottom: 1px;
}
.heatmap-header {
    background-color: var(--bg-dark);
    justify-content: center;
    align-items: center;
    padding-left: 2px;
    font-size: 9px;
}
.heatmap-month-header {
    width: 36px;
    height: 20px;
    background-color: transparent;
    color: var(--text-muted);
}

/* ==========================================================================
   ETF Total Expense View Styles
   ========================================================================== */

#etf-search-panel .chip {
    padding: 4px 10px;
    font-size: 11px;
}

/* Filter Chips Base */
.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 30px;
    color: var(--text-muted);
    padding: 6px 16px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
}

.chip:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-main);
    border-color: rgba(255, 255, 255, 0.2);
}

.chip.active {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.25), rgba(59, 130, 246, 0.15));
    border-color: var(--primary);
    color: var(--text-main);
    font-weight: 600;
    box-shadow: 0 0 12px rgba(59, 130, 246, 0.3);
}

/* Issuer Brand Custom Colors */
.filter-chips .chip[data-issuer="삼성"] {
    border-color: rgba(59, 130, 246, 0.3);
    color: #3b82f6;
}
.filter-chips .chip[data-issuer="삼성"]:hover {
    background: rgba(59, 130, 246, 0.08);
}
.filter-chips .chip[data-issuer="삼성"].active {
    background: #3b82f6;
    border-color: #3b82f6;
    color: #ffffff;
    box-shadow: 0 0 12px rgba(59, 130, 246, 0.4);
}

.filter-chips .chip[data-issuer="미래에셋"] {
    border-color: rgba(249, 115, 22, 0.3);
    color: #f97316;
}
.filter-chips .chip[data-issuer="미래에셋"]:hover {
    background: rgba(249, 115, 22, 0.08);
}
.filter-chips .chip[data-issuer="미래에셋"].active {
    background: #f97316;
    border-color: #f97316;
    color: #ffffff;
    box-shadow: 0 0 12px rgba(249, 115, 22, 0.4);
}

.filter-chips .chip[data-issuer="한국투자"] {
    border-color: rgba(234, 179, 8, 0.3);
    color: #eab308;
}
.filter-chips .chip[data-issuer="한국투자"]:hover {
    background: rgba(234, 179, 8, 0.08);
}
.filter-chips .chip[data-issuer="한국투자"].active {
    background: #eab308;
    border-color: #eab308;
    color: #020617;
    font-weight: 700;
    box-shadow: 0 0 12px rgba(234, 179, 8, 0.4);
}

.filter-chips .chip[data-issuer="케이비"] {
    border-color: rgba(20, 184, 166, 0.3);
    color: #14b8a6;
}
.filter-chips .chip[data-issuer="케이비"]:hover {
    background: rgba(20, 184, 166, 0.08);
}
.filter-chips .chip[data-issuer="케이비"].active {
    background: #14b8a6;
    border-color: #14b8a6;
    color: #020617;
    font-weight: 700;
    box-shadow: 0 0 12px rgba(20, 184, 166, 0.4);
}

.filter-chips .chip[data-issuer="신한"] {
    border-color: rgba(14, 165, 233, 0.3);
    color: #0ea5e9;
}
.filter-chips .chip[data-issuer="신한"]:hover {
    background: rgba(14, 165, 233, 0.08);
}
.filter-chips .chip[data-issuer="신한"].active {
    background: #0ea5e9;
    border-color: #0ea5e9;
    color: #ffffff;
    box-shadow: 0 0 12px rgba(14, 165, 233, 0.4);
}

.filter-chips .chip[data-issuer="한화"] {
    border-color: rgba(239, 68, 68, 0.3);
    color: #ef4444;
}
.filter-chips .chip[data-issuer="한화"]:hover {
    background: rgba(239, 68, 68, 0.08);
}
.filter-chips .chip[data-issuer="한화"].active {
    background: #ef4444;
    border-color: #ef4444;
    color: #ffffff;
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.4);
}

.filter-chips .chip[data-issuer="키움"] {
    border-color: rgba(236, 72, 153, 0.3);
    color: #ec4899;
}
.filter-chips .chip[data-issuer="키움"]:hover {
    background: rgba(236, 72, 153, 0.08);
}
.filter-chips .chip[data-issuer="키움"].active {
    background: #ec4899;
    border-color: #ec4899;
    color: #ffffff;
    box-shadow: 0 0 12px rgba(236, 72, 153, 0.4);
}

.filter-chips .chip[data-issuer="아문디"] {
    border-color: rgba(34, 197, 94, 0.3);
    color: #22c55e;
}
.filter-chips .chip[data-issuer="아문디"]:hover {
    background: rgba(34, 197, 94, 0.08);
}
.filter-chips .chip[data-issuer="아문디"].active {
    background: #22c55e;
    border-color: #22c55e;
    color: #ffffff;
    box-shadow: 0 0 12px rgba(34, 197, 94, 0.4);
}

.filter-chips .chip[data-issuer="하나"] {
    border-color: rgba(13, 148, 136, 0.3);
    color: #0d9488;
}
.filter-chips .chip[data-issuer="하나"]:hover {
    background: rgba(13, 148, 136, 0.08);
}
.filter-chips .chip[data-issuer="하나"].active {
    background: #0d9488;
    border-color: #0d9488;
    color: #ffffff;
    box-shadow: 0 0 12px rgba(13, 148, 136, 0.4);
}

.filter-chips .chip[data-issuer="others"] {
    border-color: rgba(100, 116, 139, 0.3);
    color: #64748b;
}
.filter-chips .chip[data-issuer="others"]:hover {
    background: rgba(100, 116, 139, 0.08);
}
.filter-chips .chip[data-issuer="others"].active {
    background: #64748b;
    border-color: #64748b;
    color: #ffffff;
    box-shadow: 0 0 12px rgba(100, 116, 139, 0.4);
}

/* ETF Brand Typography Coloring */
.brand-text {
    font-weight: 700;
    margin-right: 4px;
}
.brand-text-kodex { color: #3b82f6; }
.brand-text-tiger { color: #f97316; }
.brand-text-ace { color: #eab308; }
.brand-text-rise { color: #14b8a6; }
.brand-text-sol { color: #0ea5e9; }
.brand-text-plus { color: #ef4444; }
.brand-text-kioom { color: #ec4899; }
.brand-text-hanaro { color: #22c55e; }
.brand-text-1q { color: #0d9488; }
.brand-text-power { color: #a855f7; }
.brand-text-won { color: #3b82f6; }
.brand-text-focus { color: #64748b; }

/* Code Label styling */
.etf-code {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 3px;
    font-family: 'Outfit', 'Inter', sans-serif;
}

/* Rank Badges */
.rank-badge {
    display: inline-block;
    width: 22px;
    height: 22px;
    line-height: 22px;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 700;
    text-align: center;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
}

tr:nth-child(1) .rank-badge {
    background: linear-gradient(135deg, #ffd700, #ffa500);
    color: #020617;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
}

tr:nth-child(2) .rank-badge {
    background: linear-gradient(135deg, #e2e8f0, #94a3b8);
    color: #020617;
    box-shadow: 0 0 10px rgba(226, 232, 240, 0.3);
}

tr:nth-child(3) .rank-badge {
    background: linear-gradient(135deg, #b45309, #78350f);
    color: #ffffff;
    box-shadow: 0 0 10px rgba(180, 83, 9, 0.3);
}

/* Best Value Badge */
.badge-best {
    display: inline-block;
    padding: 1px 4px;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.3);
    border-radius: 3px;
    color: var(--success);
    font-size: 9px;
    font-weight: 600;
    margin-left: 4px;
    vertical-align: middle;
}

/* Earning Rate Text Colors */
.earn-positive { color: var(--danger); font-weight: 700; }
.earn-negative { color: var(--primary); font-weight: 700; }
.earn-zero { color: var(--text-muted); }

/* Table Sorting indicator */
th.sort-active {
    color: var(--primary) !important;
    font-weight: 700;
    border-bottom: 2px solid var(--primary) !important;
}

/* Loading Ring for ETF View */
.loading-ring {
    display: inline-block;
    position: relative;
    width: 64px;
    height: 64px;
}
.loading-ring div {
    box-sizing: border-box;
    display: block;
    position: absolute;
    width: 48px;
    height: 48px;
    margin: 8px;
    border: 4px solid var(--primary);
    border-radius: 50%;
    animation: loading-ring 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
    border-color: var(--primary) transparent transparent transparent;
}
.loading-ring div:nth-child(1) { animation-delay: -0.45s; }
.loading-ring div:nth-child(2) { animation-delay: -0.3s; }
.loading-ring div:nth-child(3) { animation-delay: -0.15s; }

@keyframes loading-ring {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* col-total-fee Hover Interaction */
.col-total-fee {
    cursor: pointer;
    transition: color 0.15s ease;
}

.col-total-fee:hover {
    color: #22d3ee !important;
    text-decoration: underline;
}

/* Help Modal Layout */
.help-modal-container {
    display: flex;
    /* 고정 70vh 대신 화면 남는 높이를 꽉 채움 (AI 비서 카드와 동일 패턴).
       dvh는 모바일 주소창 변화 반영 - 미지원 브라우저는 위 vh 줄로 폴백 */
    height: calc(100vh - 130px);
    height: calc(100dvh - 130px);
    min-height: 500px;
}

.help-sidebar {
    width: 220px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding-right: 16px;
    overflow-y: auto;
}

.help-tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 12px 16px;
    text-align: left;
    border-radius: 8px;
    margin-bottom: 6px;
    font-size: 13.5px;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.help-tab-btn:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.help-tab-btn.active {
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--primary);
    font-weight: 600;
}

.help-content-area {
    flex: 1;
    padding-left: 24px;
    overflow-y: auto;
    line-height: 1.6;
}

.help-section {
    display: none;
}

.help-section.active {
    display: block;
}

.help-section h3 {
    font-size: 1.4em;
    margin-bottom: 16px;
    color: var(--text-main);
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
}

.help-section h4 {
    font-size: 1.1em;
    margin: 16px 0 8px 0;
    color: var(--primary);
}

.help-section p, .help-section ul, .help-section ol {
    margin-bottom: 14px;
    font-size: 13.5px;
    color: var(--text-muted);
}

.help-section ul, .help-section ol {
    padding-left: 20px;
}

.help-section li {
    margin-bottom: 6px;
}

.help-section code {
    color: #60a5fa;
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 5px;
    border-radius: 4px;
    font-family: Consolas, Monaco, monospace;
    font-size: 0.9em;
}

.help-section strong {
    color: var(--text-main);
}

.help-badge-tip {
    background-color: rgba(16, 185, 129, 0.15);
    color: var(--success);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    margin-right: 4px;
}

.help-badge-warn {
    background-color: rgba(239, 68, 68, 0.15);
    color: var(--danger);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    margin-right: 4px;
}

/* Ticker Auto-complete suggestions-list styles */
.suggestions-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 8px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    margin-top: 4px;
}

.suggestions-item {
    padding: 10px 12px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-main);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    transition: background-color 0.15s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.suggestions-item:hover {
    background-color: rgba(59, 130, 246, 0.2);
}

.suggestions-item .suggest-ticker {
    color: var(--text-muted);
    font-size: 11px;
    font-family: 'Outfit', sans-serif;
}

/* Settings View Layout */
.settings-modal-container {
    display: flex;
    height: 60vh;
    min-height: 400px;
}

.settings-sidebar {
    width: 200px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding-right: 16px;
    overflow-y: auto;
}

.settings-tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 12px 16px;
    text-align: left;
    border-radius: 8px;
    margin-bottom: 6px;
    font-size: 13.5px;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.settings-tab-btn:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.settings-tab-btn.active {
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--primary);
    font-weight: 600;
}

.settings-content-area {
    flex: 1;
    padding-left: 24px;
    overflow-y: auto;
    line-height: 1.6;
}

.settings-section {
    display: none;
}

.settings-section.active {
    display: block;
}

.settings-section h3 {
    font-size: 1.4em;
    margin-bottom: 16px;
    color: var(--text-main);
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
}

/* History Detail Modal Layout */
.history-detail-container {
    display: flex;
    height: 70vh;
    min-height: 500px;
}

.history-detail-sidebar {
    width: 200px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding-right: 16px;
    overflow-y: auto;
    gap: 6px;
}

.history-detail-tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 12px 14px;
    text-align: left;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
    width: 100%;
    cursor: pointer;
}

.history-detail-tab-btn:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.history-detail-tab-btn.active {
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--primary);
    font-weight: 600;
}

.history-detail-content {
    flex: 1;
    padding-left: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.history-summary-box {
    display: flex;
    gap: 16px;
    background: rgba(0, 0, 0, 0.2);
    padding: 16px;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.history-summary-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.history-summary-item span {
    font-size: 11px;
    color: var(--text-muted);
}

.history-summary-item strong {
    font-size: 16px;
    color: var(--text-main);
}

/* Warning Alerts Styles */
.alert-warning-item {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.25);
    border-radius: 8px;
    padding: 12px 16px;
    color: #fca5a5;
    font-size: 13.5px;
    line-height: 1.5;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.alert-warning-item .alert-icon {
    font-size: 1.2em;
    flex-shrink: 0;
}

.alert-warning-item .alert-text {
    flex: 1;
}

.alert-warning-item .alert-details {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Admin Control Panel Styles */
.admin-tab-btn {
    transition: background-color 0.2s ease, color 0.2s ease;
}
.admin-tab-btn:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}
.admin-tab-btn.active {
    background-color: rgba(59, 130, 246, 0.1) !important;
    border-color: var(--primary) !important;
    color: var(--primary) !important;
    font-weight: 600;
}
.badge-admin {
    font-weight: 600;
}
.btn-sm {
    padding: 4px 8px !important;
    font-size: 12px !important;
    border-radius: 4px !important;
}

/* ==========================================================================
   자료실 (Archive) 뷰 스타일
   ========================================================================== */
.archive-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 24px;
    border-bottom: 2px solid var(--border);
    padding-bottom: 0;
}

.archive-tab-btn {
    padding: 10px 22px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-weight: 600;
    cursor: pointer;
    font-size: 0.95rem;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s ease;
}

.archive-tab-btn:hover {
    color: var(--text-main);
}

.archive-tab-btn.active {
    border-bottom: 3px solid var(--primary);
    color: var(--primary);
}

.archive-section {
    display: none;
}

.archive-section.active {
    display: block;
}

.notice-card {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 16px;
    background: rgba(255, 255, 255, 0.02);
    backdrop-filter: blur(8px);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.notice-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-color: rgba(255, 255, 255, 0.15);
}

/* AI 비서 답변 경량 마크다운 렌더 (renderMarkdownLite) */
.ai-quant-bubble { width: 95%; }
.ai-md-h {
    margin: 14px 0 6px;
    font-weight: 700;
    line-height: 1.4;
    color: var(--text-main);
}
h4.ai-md-h { font-size: 1rem; }
h5.ai-md-h { font-size: 0.92rem; color: var(--text-muted); }
.ai-md-hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.ai-md-ul { margin: 4px 0 4px; padding-left: 20px; }
.ai-md-ul li { margin: 2px 0; }
.ai-md-gap { height: 8px; }
.ai-md-table-wrap { overflow-x: auto; margin: 8px 0; }
.ai-md-table {
    border-collapse: collapse;
    width: 100%;
    font-size: 0.84rem;
}
.ai-md-table th,
.ai-md-table td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    text-align: left;
    vertical-align: top;
    white-space: nowrap;
}
.ai-md-table th {
    background: rgba(255, 255, 255, 0.06);
    font-weight: 600;
}
.ai-md-table code {
    background: rgba(255, 255, 255, 0.08);
    padding: 1px 4px;
    border-radius: 4px;
    font-size: 0.9em;
}

/* 퀀트 리포트 전체 화면 뷰어: 리포트가 길어 대화 버블 대신 화면을 꽉 채워 보여준다 */
.quant-report-content {
    max-width: 960px;
    width: 96%;
    height: 92vh;
    display: flex;
    flex-direction: column;
}
.quant-report-body {
    flex: 1;
    overflow-y: auto;
    line-height: 1.7;
    font-size: 0.95rem;
    overflow-wrap: anywhere;
}
.quant-report-body .ai-md-table th,
.quant-report-body .ai-md-table td {
    white-space: normal; /* 넓은 화면에서는 셀 줄바꿈 허용이 읽기 편함 */
}
/* 대화창 내 퀀트 리포트 카드(완성 시 자동으로 전체 화면이 열리고, 카드
   자체를 클릭하면 대화 기록에서도 다시 열 수 있음) */
.quant-report-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--primary);
    background: rgba(59, 130, 246, 0.15);
    cursor: pointer;
    transition: background 0.15s;
}
.quant-report-card:hover { background: rgba(59, 130, 246, 0.3); }
@media (max-width: 768px) {
    .quant-report-content { width: 100%; height: 96vh; }
    .quant-report-body { font-size: 0.88rem; padding: 14px; }
}

/* AI 비서 대화 카드: 고정 70vh 대신 화면 남는 높이를 꽉 채운다
   (데스크톱: 상단 헤더+여백 128px 제외 / 모바일: 헤더+하단 네비+여백 152px 제외).
   dvh는 모바일 주소창 변화를 반영하는 단위 - 미지원 브라우저는 위의 vh 줄로 폴백. */
.ai-assistant-card {
    height: calc(100vh - 130px);
    height: calc(100dvh - 130px);
}
@media (max-width: 768px) {
    .ai-assistant-card {
        height: calc(100vh - 152px);
        height: calc(100dvh - 152px);
    }
}

/* AI 비서 상단바: 모바일에서는 버튼을 한 줄로 펼치고 설명 문구를 그 아래로 내려
   설명이 좁은 칸에 세로로 깨지지 않게 한다. */
@media (max-width: 768px) {
    .ai-assistant-topbar {
        flex-direction: column;
        align-items: stretch !important;
        gap: 8px !important;
    }
    .ai-assistant-topbar > p {
        order: 2;
        font-size: 0.72rem !important;
        line-height: 1.4;
    }
    .ai-assistant-actions {
        order: 1;
        flex-wrap: wrap;
    }
    .ai-assistant-actions > button {
        flex: 1 1 auto;
        white-space: nowrap;
    }
}

/* ==========================================================================
   🎮 주식 연습장 (Stock Practice / bTest 포팅)
   ========================================================================== */
:root {
    --sp-accent: var(--primary);
    --sp-accent-ink: #ffffff;
    --sp-accent-soft: rgba(59, 130, 246, 0.14);
    --sp-surface-card: var(--card-bg);
    --sp-surface-page: rgba(0, 0, 0, 0.2);
    --sp-border: var(--border);
    --sp-text: var(--text-main);
    --sp-text-secondary: #cbd5e1;
    --sp-text-muted: var(--text-muted);
    --sp-good: var(--success);
    --sp-critical: var(--danger);
    /* 국내 증시 관례: 상승=붉은색, 하락=초록색 (일반적 positive/negative 색과는 별개) */
    --sp-up: var(--danger);
    --sp-down: var(--success);
}

/* Step bar (1~5 인디케이터 + 보관함 버튼) — .page-header와 동일하게 position:fixed로
   뷰포트에 완전히 고정한다(처음엔 position:sticky를 썼는데, 스크롤 중 아주
   미세하게 같이 움직이는 것처럼 보이는 문제가 있어 이미 안정적으로 동작하는
   .page-header와 같은 방식으로 통일했다). top/left는 .page-header의 실제
   렌더링 높이·사이드바 폭에 맞춰 stock_practice.js가 JS로 정확히 맞춘다.
   fixed라 문서 흐름에서 빠지므로, #sp-step-container에 이 바의 높이만큼
   margin-top을 JS로 부여해 콘텐츠가 가려지지 않게 한다. */
.sp-step-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    position: fixed;
    top: 64px;
    left: var(--sidebar-width);
    right: 0;
    z-index: 5;
    background: var(--bg-darker);
    padding: 10px 32px 14px;
}
.sp-lib-btn { flex-shrink: 0; }
#sp-step-container { margin-top: 70px; } /* JS(syncStepBarLayout)가 정확한 값으로 덮어씀 - 폴백 */

.sp-step-indicator {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    list-style: none;
    flex: 1;
    min-width: 0;
}
.sp-step-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px 2px;
}
.sp-step-btn:disabled {
    cursor: not-allowed;
    opacity: 0.35;
}
.sp-step-circle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    font-weight: 700;
    font-size: 0.92em;
    background: var(--sp-surface-card);
    color: var(--sp-text-muted);
    border: 1px solid var(--sp-border);
}
.sp-step-btn.current .sp-step-circle {
    background: var(--sp-accent);
    color: var(--sp-accent-ink);
    border-color: var(--sp-accent);
}
.sp-step-btn.done .sp-step-circle {
    background: var(--sp-accent-soft);
    color: var(--sp-accent);
    border-color: transparent;
}
.sp-step-label {
    font-size: 0.96em;
    color: var(--sp-text-muted);
    white-space: nowrap;
}
.sp-step-btn.current .sp-step-label {
    color: var(--sp-text);
    font-weight: 600;
}
.sp-step-sep {
    width: 20px;
    height: 1px;
    background: var(--sp-border);
    margin: 0 2px;
}

/* Generic chip / pill buttons */
.sp-chip {
    border-radius: 999px;
    border: 1px solid var(--sp-border);
    padding: 5px 12px;
    font-size: 0.92em;
    color: var(--sp-text-secondary);
    background: transparent;
    cursor: pointer;
    white-space: nowrap;
}
.sp-chip:hover {
    background: var(--sp-accent-soft);
    color: var(--sp-accent);
}
.sp-chip.active {
    background: var(--sp-accent);
    border-color: var(--sp-accent);
    color: var(--sp-accent-ink);
}
.sp-chip.tone-up { border-color: rgba(239,68,68,0.4); background: rgba(239,68,68,0.08); color: var(--sp-up); }
.sp-chip.tone-down { border-color: rgba(16,185,129,0.4); background: rgba(16,185,129,0.08); color: var(--sp-down); }
.sp-chip.tone-sideways { background: rgba(148,163,184,0.12); color: var(--sp-text-muted); }
.sp-chip.disabled, .sp-chip:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
.sp-chip-remove {
    background: var(--sp-accent-soft);
    color: var(--sp-accent);
    border: 1px solid var(--sp-accent);
}

.sp-link-btn {
    background: transparent;
    border: none;
    color: var(--sp-accent);
    font-size: 0.96em;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
}
.sp-link-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.sp-link-btn-danger { color: var(--sp-critical); }

/* Dropdown menu (template pickers) */
.sp-dropdown { position: relative; display: inline-block; }
.sp-dropdown-menu {
    position: absolute;
    left: 0;
    top: calc(100% + 4px);
    z-index: 20;
    min-width: 150px;
    background: var(--bg-dark);
    border: 1px solid var(--sp-border);
    border-radius: 8px;
    box-shadow: 0 12px 30px rgba(0,0,0,0.4);
    overflow: hidden;
}
.sp-dropdown-menu button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 12px;
    background: transparent;
    border: none;
    color: var(--sp-text-secondary);
    font-size: 0.92em;
    cursor: pointer;
}
.sp-dropdown-menu button:hover {
    background: var(--sp-accent-soft);
    color: var(--sp-accent);
}

/* Ticker combobox */
.sp-combobox-wrap { position: relative; }
.sp-combobox-menu {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    z-index: 30;
    max-height: 240px;
    overflow-y: auto;
    background: var(--bg-dark);
    border: 1px solid var(--sp-border);
    border-radius: 8px;
    box-shadow: 0 12px 30px rgba(0,0,0,0.45);
}
.sp-combobox-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 10px;
    font-size: 0.94em;
    cursor: pointer;
    color: var(--sp-text-secondary);
}
.sp-combobox-item:hover { background: var(--sp-accent-soft); color: var(--sp-accent); }
.sp-combobox-item .tk { color: var(--sp-text-muted); font-size: 0.96em; }

/* Portfolio grid (Step 1) */
.sp-grid-scroll { overflow-x: auto; }
.sp-grid-inner { min-width: max-content; }
.sp-grid-row { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.sp-grid-ticker-col { width: 190px; flex-shrink: 0; }
.sp-grid-weight-col { width: 112px; flex-shrink: 0; display: flex; align-items: center; gap: 3px; }
.sp-grid-weight-col input {
    width: 100%;
    min-width: 0;
    text-align: right;
    background: var(--sp-surface-page);
    border: 1px solid var(--sp-border);
    border-radius: 6px;
    color: var(--sp-text);
    padding: 6px 6px;
    font-size: 0.96em;
}
.sp-grid-weight-col .pct { color: var(--sp-text-muted); font-size: 0.9em; }
.sp-grid-portfolio-name {
    width: 100%;
    background: var(--sp-surface-page);
    border: 1px solid var(--sp-border);
    border-radius: 6px;
    color: var(--sp-text);
    padding: 5px 6px;
    font-size: 0.92em;
    font-weight: 600;
}
.sp-grid-remove-btn {
    background: transparent;
    border: none;
    color: var(--sp-text-muted);
    cursor: pointer;
    font-size: 0.96em;
    padding: 2px 4px;
    flex-shrink: 0;
}
.sp-grid-remove-btn:hover { color: var(--sp-critical); }
.sp-grid-remove-btn:disabled { opacity: 0.25; cursor: not-allowed; }
.sp-weight-sum { font-size: 0.9em; color: var(--sp-text-secondary); }
.sp-weight-sum.invalid { color: var(--sp-critical); font-weight: 600; }

.sp-input {
    background: var(--sp-surface-page);
    border: 1px solid var(--sp-border);
    border-radius: 6px;
    color: var(--sp-text);
    padding: 7px 10px;
    font-size: 0.96em;
}
.sp-textarea {
    width: 100%;
    resize: vertical;
    background: var(--sp-surface-page);
    border: 1px solid var(--sp-border);
    border-radius: 8px;
    color: var(--sp-text);
    padding: 10px 12px;
    font-size: 1em;
    line-height: 1.5;
}
.sp-select {
    background: var(--sp-surface-page);
    border: 1px solid var(--sp-border);
    border-radius: 6px;
    color: var(--sp-text);
    padding: 6px 8px;
    font-size: 0.94em;
}

/* Strategy card */
.sp-strategy-card { margin-bottom: 16px; }
.sp-parsed-box {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--sp-border);
    font-size: 0.96em;
}
.sp-parsed-row { display: flex; gap: 8px; margin-bottom: 6px; }
.sp-parsed-row dt { width: 60px; flex-shrink: 0; color: var(--sp-text-muted); }
.sp-error-box {
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid rgba(239,68,68,0.3);
    background: rgba(239,68,68,0.06);
    color: var(--sp-critical);
    font-size: 0.96em;
}

/* Technical analysis toolbar / chart panels */
.sp-ta-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.sp-toggle-group { display: inline-flex; background: rgba(0,0,0,0.25); border-radius: 8px; padding: 3px; gap: 2px; }
.sp-toggle-group button {
    background: transparent; border: none; color: var(--sp-text-muted);
    padding: 5px 10px; font-size: 0.9em; border-radius: 6px; cursor: pointer;
}
.sp-toggle-group button.active { background: var(--sp-accent); color: var(--sp-accent-ink); }
.sp-indicator-picker { border: 1px solid var(--sp-border); border-radius: 10px; padding: 10px; margin-bottom: 10px; background: var(--sp-surface-page); }
.sp-indicator-cat-label { font-size: 0.9em; color: var(--sp-text-muted); margin: 6px 0 4px; }
.sp-chart-panel { margin-bottom: 14px; }
.sp-chart-panel-title { font-size: 0.92em; font-weight: 600; color: var(--sp-text-secondary); margin-bottom: 4px; }
.sp-chart-canvas-wrap { background: var(--sp-surface-card); border-radius: 12px; padding: 6px; }
.sp-phase-legend { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 6px; }
.sp-phase-legend-item { display: flex; align-items: center; gap: 5px; font-size: 0.9em; color: var(--sp-text-secondary); }
.sp-phase-swatch { width: 11px; height: 11px; border-radius: 3px; border: 1px solid var(--sp-border); display: inline-block; }
.sp-indicator-ratios { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-bottom: 6px; font-size: 0.88em; color: var(--sp-text-muted); }

/* Info panel (Minervini / Thomas Carr / Gojiro) */
.sp-info-panel { border: 1px solid var(--sp-border); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.sp-info-zonebar { display: flex; height: 12px; width: 100%; border-radius: 999px; overflow: hidden; margin-bottom: 10px; }
.sp-info-current-badge { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 3px 10px; font-size: 0.9em; font-weight: 600; }
.sp-info-criteria { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 4px 10px; margin-top: 8px; }
.sp-info-criteria-item { display: flex; align-items: center; gap: 6px; font-size: 0.9em; color: var(--sp-text-secondary); }

/* Library / MDD / VolTarget modal tabs */
.modal-content.sp-modal-wide, #sp-modal-library .modal-content { max-width: 560px; }
.sp-tabs { display: flex; gap: 3px; background: rgba(0,0,0,0.25); border-radius: 8px; padding: 3px; margin-bottom: 14px; }
.sp-tab-btn { flex: 1; background: transparent; border: none; color: var(--sp-text-muted); padding: 7px 0; border-radius: 6px; cursor: pointer; font-size: 0.96em; }
.sp-tab-btn.active { background: var(--sp-accent); color: var(--sp-accent-ink); }
.sp-lib-item { border: 1px solid var(--sp-border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; background: var(--sp-surface-page); }
.sp-lib-item-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.sp-lib-item-actions { display: flex; gap: 10px; font-size: 0.9em; flex-shrink: 0; }
.sp-lib-item-meta { font-size: 0.9em; color: var(--sp-text-muted); }

/* Results */
.sp-stat-tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 640px) { .sp-stat-tiles { grid-template-columns: repeat(4, 1fr); } }
.sp-stat-tile { border: 1px solid var(--sp-border); border-radius: 10px; background: var(--sp-surface-card); padding: 10px 12px; }
.sp-stat-tile .lbl { font-size: 0.88em; color: var(--sp-text-muted); }
.sp-stat-tile .val { font-size: 1.2em; font-weight: 700; margin-top: 2px; }
.sp-running-wrap { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 70px 0; }
.sp-color-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.sp-note-box { border: 1px solid var(--sp-border); border-radius: 10px; padding: 10px 12px; font-size: 0.9em; color: var(--sp-text-secondary); background: var(--sp-surface-page); }

/* 종목&비중 표: 종목명 열을 좌측에 고정(sticky)해 가로 스크롤로 포트2~4를
   봐도 어떤 종목의 행인지 계속 보이게 하고, 스크롤 가능함을 알 수 있도록
   우측 끝에 옅은 그라디언트 힌트를 준다(스크롤이 필요 없을 만큼 넓은
   화면에서는 sp-grid-scroll의 scrollWidth<=clientWidth라 그라디언트가
   보여도 실제로 걸리는 콘텐츠가 없어 무해함). */
.sp-grid-scroll { position: relative; }
.sp-grid-scroll::after {
    content: "";
    position: absolute;
    top: 0; right: 0; bottom: 0;
    width: 18px;
    background: linear-gradient(to right, transparent, var(--sp-surface-card));
    pointer-events: none;
}
.sp-grid-row .sp-grid-ticker-col {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--sp-surface-card);
}

/* .sidebar/.main-content이 모바일 레이아웃(사이드바 폭 0)으로 바뀌는 지점과
   동일한 768px 기준으로 .sp-step-bar의 left/여백도 맞춰준다. */
@media (max-width: 768px) {
    .sp-step-bar { left: 0; padding-left: 12px; padding-right: 12px; }
}

@media (max-width: 640px) {
    .sp-stat-tiles { grid-template-columns: repeat(2, 1fr); }

    /* 모바일에서는 현재 단계만 제목을 보여주고 나머지 단계는 번호만 표시해
       "1 2 3 매매전략 4 5"처럼 1~5단계 + 보관함이 항상 한 줄에 들어오게 한다. */
    .sp-step-bar { gap: 6px; padding: 8px 0 10px; }
    .sp-step-indicator { flex-wrap: nowrap; gap: 2px; }
    .sp-step-btn { padding: 4px 2px; }
    .sp-step-btn:not(.current) .sp-step-label { display: none; }
    .sp-step-label { white-space: nowrap; font-size: 0.85em; }
    .sp-step-sep { flex: 1 1 4px; min-width: 3px; width: auto; margin: 0 1px; }
    .sp-step-circle { width: 22px; height: 22px; font-size: 0.8em; flex-shrink: 0; }
    .sp-lib-btn { font-size: 0.8em; padding: 6px 8px; white-space: nowrap; }

    /* 종목&비중 표: 종목명 열 폭을 줄이고 스크롤 힌트를 더 잘 보이게. */
    .sp-grid-ticker-col { width: 130px; }
    .sp-grid-scroll::after { width: 24px; }
}
