/* ====================================================
   스타포스 기댓값 계산기 스타일 (cube_calc 패턴 그대로)
   ==================================================== */
.sf-calc-container { max-width: 1100px; margin: 0 auto; padding: 40px 20px 80px; }
.sf-calc-header { text-align: center; margin-bottom: 30px; }
.sf-calc-header h1 { font-size: 28px; color: #3C3744; margin: 0 0 8px; }
.sf-calc-sub { color: #666; font-size: 14px; margin: 0; }

.input-card {
    background: #fff; border: 1px solid #e6e8ef; border-radius: 12px;
    padding: 24px; margin-bottom: 22px;
}

/* 계산 모드 (단일 / 비교) 토글 + 시나리오 탭 */
.compare-mode-row {
    display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
    padding-bottom: 14px;
    border-bottom: 1px solid #eef0f5;
    margin-bottom: 16px;
}
.compare-mode-label { font-size: 13px; font-weight: 700; color: #3C3744; }
.compare-mode-toggle {
    display: inline-flex; border: 1px solid #ccd3e0;
    border-radius: 6px; overflow: hidden;
}
.compare-mode-btn {
    background: #fff; border: 0;
    padding: 6px 14px; font-size: 12px; font-weight: 600;
    color: #666; cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.compare-mode-btn + .compare-mode-btn { border-left: 1px solid #ccd3e0; }
.compare-mode-btn:hover:not(.active) { background: #f4f5f9; color: #3C3744; }
.compare-mode-btn.active { background: #3C3744; color: #fff; }
.compare-mode-hint {
    font-size: 11px; color: #888;
    margin: 0; flex: 1; min-width: 200px;
}

.scenario-tab-bar {
    display: flex; gap: 6px;
    background: #f8f9fb; padding: 5px;
    border-radius: 10px;
    margin-bottom: 16px;
}
.scenario-tab {
    flex: 1; background: transparent; border: 0;
    padding: 10px 16px; font-size: 13px; font-weight: 700;
    color: #888; cursor: pointer;
    border-radius: 7px;
    transition: background 0.12s, color 0.12s;
}
.scenario-tab:hover:not(.active) { background: rgba(255,255,255,0.6); color: #3C3744; }
.scenario-tab.active {
    background: #fff; color: #3C3744;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.scenario-tab[data-scenario="A"].active { border-top: 2px solid #f39c12; }
.scenario-tab[data-scenario="B"].active { border-top: 2px solid #3498db; }

/* 비교 결과 카드 */
.compare-summary-card {
    background: #fff; border: 1px solid #e6e8ef;
    border-radius: 12px; padding: 20px;
    margin-bottom: 22px;
}
.compare-summary-header {
    font-size: 14px; font-weight: 700; color: #3C3744;
    margin-bottom: 14px;
}
.compare-percentile-wrap { margin-top: 22px; }
.compare-percentile-header {
    font-size: 13px; font-weight: 700; color: #3C3744;
    margin-bottom: 10px;
}
.compare-table-wrap { overflow-x: auto; }
.compare-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.compare-table th {
    background: #f7f8fb; color: #555;
    font-weight: 700;
    padding: 10px 14px;
    text-align: right;
    font-size: 12px;
}
.compare-table th:first-child { text-align: left; }
.compare-table th:nth-child(2) { color: #b27200; }   /* A = 주황 톤 */
.compare-table th:nth-child(3) { color: #1f6691; }   /* B = 파랑 톤 */
.compare-table th:nth-child(4) { color: #3C3744; }
.compare-table td {
    padding: 10px 14px;
    border-top: 1px solid #f0f1f5;
    text-align: right;
    color: #3C3744;
    font-variant-numeric: tabular-nums;
}
.compare-table td:first-child {
    text-align: left; font-weight: 700; color: #3C3744;
}
/* 차이값을 유리한 시나리오의 색으로 — A 유리=주황, B 유리=파랑 */
.compare-table .diff-favors-a { color: #b27200; font-weight: 700; }
.compare-table .diff-favors-b { color: #1f6691; font-weight: 700; }
.compare-table .diff-zero     { color: #aab0c0; }
.compare-table tr:hover td:not(:first-child) { background: #fafbfd; }
.compare-table .winner-tag {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 7px;
    font-size: 10px;
    font-weight: 800;
    border-radius: 10px;
    letter-spacing: 0.3px;
    vertical-align: middle;
}
.compare-table .winner-tag.tag-a { background: #f39c12; color: #fff; }
.compare-table .winner-tag.tag-b { background: #3498db; color: #fff; }

/* 종합 추천 배너 — 평균 비용 기준 어느 쪽이 유리한지 시각화 */
.compare-recommendation {
    display: flex; align-items: center; gap: 8px;
    padding: 14px 18px;
    border-radius: 10px;
    font-size: 14px;
    margin-bottom: 18px;
    line-height: 1.4;
}
.compare-recommendation.favors-a {
    background: #fff3e7;
    color: #8a5800;
    border-left: 4px solid #f39c12;
}
.compare-recommendation.favors-b {
    background: #e7f0ff;
    color: #154d6b;
    border-left: 4px solid #3498db;
}
.compare-recommendation.neutral {
    background: #f4f5f9;
    color: #555;
    border-left: 4px solid #aab0c0;
}
.compare-recommendation b { font-weight: 800; }

.field-group { margin-bottom: 16px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.field-label { display: block; font-size: 13px; font-weight: 700; color: #3C3744; margin-bottom: 6px; }
.field-hint  { font-size: 11px; color: #888; margin: 6px 0 0; }
.field-group input[type="number"] {
    width: 100%; padding: 10px;
    border: 1px solid #e6e8ef; border-radius: 8px;
    font-size: 14px; background: #fff; box-sizing: border-box;
}

.sim-count-bar { display: flex; gap: 8px; }
.sim-count-btn {
    padding: 8px 16px;
    background: #fff;
    border: 1px solid #e6e8ef;
    border-radius: 18px;
    font-size: 12px; color: #555;
    cursor: pointer;
}
.sim-count-btn.active { background: #3C3744; color: #fff; border-color: #3C3744; }

.event-toggles {
    display: flex; flex-wrap: wrap; gap: 10px;
    background: #f8f9fb; padding: 14px; border-radius: 8px;
}
.revival-label-row {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 6px;
}
.revival-all-btn {
    background: #fff; border: 1px solid #ccd3e0; border-radius: 6px;
    padding: 4px 12px; font-size: 11px; font-weight: 600; color: #666;
    cursor: pointer;
}
.revival-all-btn:hover { background: #f4f5f9; color: #3C3744; }
.revival-all-btn.active { background: #3C3744; color: #fff; border-color: #3C3744; }
.revival-btn-group { display: flex; gap: 6px; }
.revival-opt-btn {
    background: #fff8e7;
    border-color: #f39c12;
    color: #b27200;
}
.revival-opt-btn:hover {
    background: #f39c12;
    color: #fff;
    border-color: #f39c12;
}
.revival-opt-btn.active {
    background: #f39c12;
    color: #fff;
    border-color: #f39c12;
}
.event-toggle.locked {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
    background: #f4f5f9;
}
.event-toggle.locked input { cursor: not-allowed; }
.event-toggle {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 14px; background: #fff;
    border: 1px solid #e6e8ef; border-radius: 8px;
    cursor: pointer; font-size: 13px;
    transition: border-color 0.12s, background 0.12s;
}
.event-toggle:has(input:checked) { border-color: #f39c12; background: #fff8e7; }
.event-toggle input { margin: 0; }
.event-toggle .event-desc { font-size: 11px; color: #888; margin-left: 4px; }

.calc-btn {
    width: 100%; padding: 14px;
    background: #3C3744; color: #fff;
    border: 0; border-radius: 10px;
    font-size: 16px; font-weight: 700;
    cursor: pointer; margin-top: 6px;
}
.calc-btn:hover { background: #2a2530; }
.calc-btn:disabled { background: #aab0c0; cursor: not-allowed; }

.progress-wrap {
    background: #fff; border: 1px solid #e6e8ef; border-radius: 10px;
    padding: 18px; margin-bottom: 22px;
}
.progress-label { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 13px; font-weight: 700; color: #3C3744; }
.progress-bar { height: 8px; background: #f0f0f0; border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: #3C3744; transition: width 0.2s ease; }

.result-wrap {
    background: #fff; border: 1px solid #e6e8ef; border-radius: 12px;
    padding: 24px; margin-bottom: 22px;
}
.result-section-title {
    font-size: 18px; color: #3C3744; margin: 0 0 18px;
    display: flex; align-items: center; gap: 10px;
    justify-content: space-between;
}
.result-title-text { display: inline-flex; align-items: center; gap: 10px; }
.ok-badge { font-size: 11px; background: #27ae60; color: #fff; padding: 3px 9px; border-radius: 20px; font-weight: 700; }
.unit-toggle-group {
    display: inline-flex;
    border: 1px solid #ccd3e0;
    border-radius: 6px;
    overflow: hidden;
}
.unit-toggle-btn {
    background: #fff;
    border: 0;
    padding: 6px 14px;
    font-size: 12px; font-weight: 600;
    color: #666;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.unit-toggle-btn + .unit-toggle-btn { border-left: 1px solid #ccd3e0; }
.unit-toggle-btn:hover:not(.active) { background: #f4f5f9; color: #3C3744; }
.unit-toggle-btn.active { background: #3C3744; color: #fff; }

.summary-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.summary-card {
    background: #f8f9fb; border-radius: 10px; padding: 18px;
}
.summary-card.highlight { background: #3C3744; color: #fff; }
.summary-card .label { font-size: 12px; opacity: 0.85; margin-bottom: 6px; }
.summary-card .value {
    font-size: clamp(15px, 1.5vw, 22px);
    font-weight: 800;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.25;
    letter-spacing: -0.3px;
}
.summary-card .value-raw {
    font-size: 11px;
    opacity: 0.5;
    font-family: 'Roboto Mono', 'Courier New', monospace;
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0.5px;
    font-weight: 500;
}
.summary-card .sub {
    font-size: 11px; opacity: 0.7;
    display: flex; flex-wrap: wrap;
    column-gap: 10px; row-gap: 2px;
}
.summary-card .sub > span { white-space: nowrap; }

.percentile-card {
    background: #f8f9fb; border-radius: 10px; padding: 18px;
}
.percentile-card-header { font-size: 14px; font-weight: 700; color: #3C3744; margin-bottom: 12px; }

/* 임의 백분위 조회 — 사용자 입력 % → 즉시 결과 */
.percentile-lookup {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    background: #fff;
    border: 1px solid #e6e8ef;
    border-radius: 10px;
    padding: 12px 16px;
    margin-bottom: 14px;
}
.lookup-input-group {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 13px; font-weight: 700; color: #3C3744;
    flex-shrink: 0;
}
.lookup-input-group input {
    width: 78px;
    padding: 6px 10px;
    border: 1px solid #ccd3e0;
    border-radius: 6px;
    font-size: 14px; font-weight: 700;
    text-align: right;
    background: #fff8e7;
    color: #b27200;
    font-variant-numeric: tabular-nums;
}
.lookup-input-group input:focus {
    outline: none;
    border-color: #f39c12;
    box-shadow: 0 0 0 2px rgba(243, 156, 18, 0.15);
}
.lookup-suffix { font-size: 13px; color: #666; }
.lookup-result-group {
    display: flex; flex-direction: column;
    flex: 1; min-width: 0;
}
.lookup-value {
    font-size: 18px; font-weight: 800; color: #3C3744;
    line-height: 1.2;
    letter-spacing: -0.3px;
}
.lookup-sub { font-size: 11px; color: #888; margin-top: 2px; }
.percentile-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.percentile-table th {
    background: #f7f8fb;
    color: #555;
    font-weight: 700;
    padding: 10px 14px;
    text-align: left;
    font-size: 12px;
}
.percentile-table th.num,
.percentile-table td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.percentile-table td {
    padding: 9px 14px;
    border-top: 1px solid #f0f1f5;
    color: #444;
}
.percentile-table tr:hover td { background: #fafbfd; }
.percentile-table .pct-label {
    font-weight: 700;
    color: #3C3744;
}

/* 분포 차트 */
.chart-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 22px;
}
.chart-grid.chart-grid--large {
    grid-template-columns: 1fr;
}
.chart-card {
    background: #fff;
    border: 1px solid #e6e8ef;
    border-radius: 12px;
    padding: 16px 18px;
    /* Grid item 의 기본 min-width: auto 가 canvas intrinsic width 에 막혀 축소 안되는 버그 방지 */
    min-width: 0;
    overflow: hidden;
}
.chart-box {
    position: relative;
    height: 280px;
    min-width: 0;
}
.chart-grid--large .chart-box { height: 480px; }
.chart-box > canvas {
    max-width: 100% !important;
}
.chart-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: 14px;
    font-weight: 700;
    color: #3C3744;
    margin-bottom: 10px;
}
.chart-card-title { display: inline-flex; align-items: center; gap: 6px; }
.chart-card-header .chart-sub {
    font-size: 11px;
    font-weight: 500;
    color: #888;
    margin-left: 6px;
}
.chart-size-toggle {
    display: inline-flex;
    border: 1px solid #ccd3e0;
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
}
.chart-size-btn {
    background: #fff;
    border: 0;
    padding: 5px 12px;
    font-size: 11px; font-weight: 600;
    color: #666;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.chart-size-btn + .chart-size-btn { border-left: 1px solid #ccd3e0; }
.chart-size-btn:hover:not(.active) { background: #f4f5f9; color: #3C3744; }
.chart-size-btn.active { background: #3C3744; color: #fff; }

.error-banner {
    background: #fee; border: 1px solid #f99;
    border-radius: 8px; padding: 14px;
    color: #991b1b; font-size: 13px;
    margin-bottom: 16px;
}

@media (max-width: 720px) {
    .sf-calc-container { padding: 22px 12px 60px; }
    .sf-calc-header h1 { font-size: 22px; }
    .sf-calc-sub { font-size: 13px; }

    /* 입력 카드 — 패딩 축소 */
    .input-card { padding: 16px; }
    .field-row { grid-template-columns: 1fr; gap: 12px; }

    /* 계산 모드 / 시나리오 탭 */
    .compare-mode-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    .compare-mode-hint { font-size: 10px; min-width: 0; }
    .scenario-tab { padding: 9px 12px; font-size: 12px; }

    /* 파괴방지/확정복구 라벨 + 버튼 — 좁은 화면에서 wrap */
    .revival-label-row {
        flex-wrap: wrap;
        gap: 8px;
    }
    .revival-btn-group { flex-shrink: 0; }
    .revival-all-btn { font-size: 10px; padding: 4px 10px; }

    /* 결과 영역 */
    .result-wrap { padding: 18px 14px; }
    .result-section-title {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .summary-cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .summary-card { padding: 14px 12px; }
    .summary-card .value { font-size: clamp(13px, 4.5vw, 18px); }

    /* 임의 백분위 조회 */
    .percentile-lookup {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .lookup-input-group input { width: 100%; max-width: 120px; }
    .lookup-value { font-size: 16px; }

    /* 백분위표 (단일 모드) */
    .percentile-table th, .percentile-table td { padding: 8px 9px; font-size: 12px; }

    /* 비교 결과 */
    .compare-summary-card { padding: 16px 14px; }
    .compare-recommendation {
        font-size: 12px;
        padding: 12px 14px;
        align-items: flex-start;
        flex-wrap: wrap;
    }
    .compare-table th, .compare-table td { padding: 8px 9px; font-size: 12px; }
    .compare-table .winner-tag { display: block; margin: 4px 0 0; padding: 1px 6px; font-size: 9px; }

    /* 차트 */
    .chart-grid { grid-template-columns: 1fr; gap: 12px; }
    .chart-card { padding: 14px 12px; }
    .chart-card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    .chart-card-title { font-size: 13px; }
    .chart-card-header .chart-sub { display: block; margin-left: 0; font-size: 10px; }
    .chart-box { height: 240px; }
    .chart-size-btn { padding: 4px 10px; font-size: 10px; }

    /* 단위/크기 토글 */
    .unit-toggle-btn { padding: 5px 10px; font-size: 11px; }
}

@media (max-width: 480px) {
    .sf-calc-container { padding: 18px 10px 50px; }
    .sf-calc-header h1 { font-size: 19px; }
    .input-card { padding: 14px 12px; }

    /* 이벤트 토글 — 풀폭 버튼화 */
    .event-toggles { padding: 10px; gap: 6px; }
    .event-toggle { padding: 7px 10px; font-size: 12px; }

    /* 결과 카드 — 1컬럼 */
    .summary-cards { grid-template-columns: 1fr; }
    .summary-card .value { font-size: 18px; }

    /* 컴팩트 표 */
    .percentile-table th, .percentile-table td,
    .compare-table th, .compare-table td { padding: 7px 6px; font-size: 11px; }

    .compare-table .winner-tag { font-size: 8px; padding: 1px 5px; }
}
