.vs-app {
    max-width: 1100px;
    margin: 0 auto;
    font-size: 14px;
}

.vs-controls {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}

.vs-btn-primary, .vs-btn-secondary {
    padding: 8px 16px;
    border-radius: 4px;
    border: 1px solid #ccc;
    cursor: pointer;
    text-decoration: none;
    color: #222;
    background: #f5f5f5;
}

.vs-btn-primary {
    background: #2271b1;
    color: #fff;
    border-color: #2271b1;
}

.vs-status {
    margin-bottom: 12px;
    color: #555;
}

.vs-table {
    width: 100%;
    border-collapse: collapse;
}

.vs-table th, .vs-table td {
    border: 1px solid #e0e0e0;
    padding: 8px 10px;
    text-align: right;
}

.vs-table th:nth-child(2), .vs-table th:nth-child(3),
.vs-table td:nth-child(2), .vs-table td:nth-child(3) {
    text-align: left;
}

.vs-table thead th {
    background: #fafafa;
}

.vs-company-link {
    color: #2271b1;
    text-decoration: none;
}

.vs-company-link:hover {
    text-decoration: underline;
}

.vs-stale {
    color: #b32d2e;
    font-size: 11px;
}

.vs-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.vs-modal-content {
    background: #fff;
    padding: 24px;
    border-radius: 6px;
    max-width: 700px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    overflow-x: hidden;        /* 프레임이 가로로 스크롤되지 않게 */
    box-sizing: border-box;
    position: relative;
}

/* 넓은 표(재무제표 등)는 프레임이 아니라 표 안에서만 가로 스크롤 */
.vs-modal-tw {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: 12px;
}
.vs-modal-tw .vs-modal-table { margin-top: 0; }

/* 팝업 내 디스플레이 광고 — 콘텐츠 폭을 넘지 않게 */
.vs-modal-ad {
    max-width: 100%;
    overflow: hidden;
    margin: 14px 0;
    text-align: center;
}
.vs-modal-ad ins { max-width: 100%; }

.vs-modal-close {
    position: absolute;
    top: 12px; right: 16px;
    cursor: pointer;
    font-size: 20px;
}

.vs-modal-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 12px;
}

.vs-modal-table th, .vs-modal-table td {
    border: 1px solid #e0e0e0;
    padding: 6px 8px;
    text-align: right;
}

/* --- v1.1 추가: 등락 색상, 스파크라인, 팝업 그룹 --- */
.vs-up { color: #1a7f37; }
.vs-down { color: #b32d2e; }
.vs-left { text-align: left !important; }
.vs-spark { vertical-align: middle; }
.vs-muted { color: #888; font-size: 13px; }
.vs-th-sub { display: block; font-size: 10px; font-weight: 400; color: #9aa0a6; margin-top: 1px; }

.vs-table { font-size: 13px; }
.vs-table th, .vs-table td { padding: 6px 8px; }

.vs-chart { width: 100%; height: auto; background: #fafafa; border: 1px solid #eee; border-radius: 4px; }
.vs-chart-lbl { font-size: 11px; fill: #888; }

.vs-modal-content h4 {
    margin: 18px 0 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid #eee;
    font-size: 15px;
}
.vs-mgroup {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 16px;
}
.vs-mrow {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px dotted #f0f0f0;
}
.vs-mlabel { color: #666; }
.vs-mval { font-weight: 600; }

/* 날짜 표기 */
.vs-data-date {
    font-size: 12px;
    color: #666;
    margin: 6px 0 8px;
    padding: 4px 10px;
    background: #f8f9fa;
    border-left: 3px solid #2271b1;
    border-radius: 2px;
}

/* PC: 스크롤 없이 한 화면에 모두 표시 (폰트·여백 최소화) */
.vs-app { max-width: 100%; }
.vs-table-wrap {
    width: 100%;
    box-sizing: border-box;
}
.vs-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
    table-layout: fixed;
}
.vs-table th, .vs-table td {
    padding: 5px 2px;
    text-align: center;
    border-bottom: 1px solid #eee;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.vs-table thead th {
    position: sticky;
    top: 0;
    background: #f5f6f8;
    font-weight: 600;
    font-size: 10.5px;
    z-index: 1;
}
/* 기업명 컬럼만 조금 넓게, 나머지는 좁게 */
.vs-table th:nth-child(3), .vs-table td:nth-child(3) {
    text-align: left;
    white-space: normal;
    word-break: keep-all;
}
.vs-table .vs-company-link {
    font-size: 11px;
}
.vs-spark { vertical-align: middle; }

/* 모바일: 종목당 카드, 내부는 2열 그리드로 안정적 정렬 */
@media screen and (max-width: 768px) {
    .vs-mobile-tip { display: block; }

    .vs-table-wrap { width: 100%; }

    /* 테이블 구조를 블록으로 해제 */
    .vs-table { display: block; width: 100%; table-layout: auto; border-collapse: collapse; }
    .vs-table thead { display: none; }
    .vs-table tbody { display: block; width: 100%; }

    /* 각 종목 = 카드 */
    .vs-table tbody tr {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 4px 14px;
        margin: 0 0 10px;
        border: 1px solid #e2e4e8;
        border-radius: 10px;
        padding: 10px 12px;
        background: #fff;
        box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    }

    /* 일반 셀: 라벨(좌) + 값(우)을 한 줄에 — 카드 높이 최소화 */
    .vs-table tbody td {
        display: flex;
        flex-direction: row;
        align-items: baseline;
        justify-content: space-between;
        gap: 6px;
        padding: 0;
        margin: 0;
        border: none;
        text-align: right;
        white-space: nowrap;
        overflow: hidden;
        font-size: 13px;
        min-width: 0;
    }
    .vs-table tbody td::before {
        content: attr(data-label);
        font-size: 11px;
        font-weight: 600;
        color: #999;
        margin: 0;
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* 기업명: 카드 맨 위 전체 폭 */
    .vs-table tbody td.vs-cell-company {
        grid-column: 1 / -1;
        flex-direction: row;
        align-items: baseline;
        justify-content: flex-start;
        font-size: 15px;
        font-weight: 700;
        padding-bottom: 6px;
        margin-bottom: 2px;
        border-bottom: 1px solid #f0f0f0;
        white-space: normal;
    }
    .vs-table tbody td.vs-cell-company::before { display: none; }
    .vs-table tbody td.vs-cell-company a { color: #2271b1; text-decoration: none; }

    /* 순위: 종목코드와 같은 줄(전체 폭 차지 안 함) */
    .vs-table tbody td.vs-cell-rank {
        flex-direction: row;
        align-items: baseline;
        justify-content: flex-start;
        color: #555;
        font-size: 13px;
        font-weight: 700;
        padding: 0;
        margin: 0;
    }
    .vs-table tbody td.vs-cell-rank::before { display: none; }
    .vs-table tbody td.vs-cell-rank::after { content: "위"; margin-left: 1px; }

    /* 종목코드: 순위 옆처럼 작게, 전체 폭 */
    .vs-table tbody td[data-label="종목코드"] {
        grid-column: 1 / -1;
        flex-direction: row;
        gap: 6px;
        align-items: center;
        font-size: 11px;
        color: #aaa;
        margin-top: -4px;
        padding-bottom: 4px;
    }
    .vs-table tbody td[data-label="종목코드"]::before { margin-bottom: 0; }

    /* 값 강조 */
    .vs-table tbody td > span,
    .vs-table tbody td strong { font-weight: 600; }

    /* 스파크라인 셀은 전체 폭으로 */
    .vs-table tbody td[data-label="20일추세"] { grid-column: 1 / -1; }
    .vs-table tbody td[data-label="20일추세"] svg { width: 100%; max-width: 200px; height: 28px; }

    /* 저평가점수: 강조 박스, 전체 폭 */
    .vs-table tbody td[data-label="저평가점수"] {
        grid-column: 1 / -1;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        background: #f5f8ff;
        border-radius: 6px;
        padding: 8px 10px;
        margin-top: 4px;
    }
    .vs-table tbody td[data-label="저평가점수"]::before {
        margin-bottom: 0;
        font-size: 12px;
        color: #555;
    }
    .vs-table tbody td[data-label="저평가점수"] strong { font-size: 17px; color: #2271b1; }
}
.vs-mobile-tip { display: none; }

/* 모바일 안내 문구 */
.vs-mobile-tip {
    font-size: 12px;
    color: #856404;
    background: #fff8e1;
    border-radius: 6px;
    padding: 8px 12px;
    margin: 8px 0;
}

/* 차트 범례 (종목 vs 코스피) */
.vs-chart-legend {
    font-size: 12px;
    color: #555;
    margin-top: 6px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
}
.vs-leg-line {
    display: inline-block;
    width: 16px;
    height: 3px;
    vertical-align: middle;
    margin-right: 4px;
    border-radius: 2px;
}
.vs-leg-dash {
    background: repeating-linear-gradient(to right, #999 0, #999 4px, transparent 4px, transparent 7px);
}
.vs-chart-note {
    width: 100%;
    font-size: 11px;
    color: #777;
    margin-top: 2px;
}

/* 방어주 기간 선택 탭 */
.vs-period-tabs {
    display: inline-flex;
    gap: 0;
    border: 1px solid #d0d3d9;
    border-radius: 8px;
    overflow: hidden;
    margin-right: 10px;
    vertical-align: middle;
}
.vs-period-btn {
    border: none;
    background: #fff;
    padding: 8px 14px;
    font-size: 13px;
    cursor: pointer;
    color: #555;
    border-right: 1px solid #e2e4e8;
}
.vs-period-btn:last-child { border-right: none; }
.vs-period-btn:hover { background: #f5f6f8; }
.vs-period-btn.vs-period-active {
    background: #2271b1;
    color: #fff;
    font-weight: 600;
}
@media screen and (max-width: 768px) {
    .vs-period-tabs { display: flex; width: 100%; margin: 0 0 8px; }
    .vs-period-btn { flex: 1; }

    /* 팝업: 좁은 화면에서 여백 줄이고, 표 셀은 줄바꿈 없이(넘치면 표만 가로 스크롤) */
    .vs-modal-content { padding: 16px 14px; width: 94%; }
    .vs-modal-table { font-size: 11px; }
    .vs-modal-table th, .vs-modal-table td { padding: 4px 5px; white-space: nowrap; }
}
