/* =========================================
   1. 기본 스타일 및 변수 설정
========================================= */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* 라이트 모드 (기본) */
:root {
    /* Background & Container */
    --bg-body: #f4f6f8;
    --bg-container: #ffffff;
    --hover-bg: #e9ecef;
    --input-bg: #ffffff;

    /* Text & Border */
    --text-main: #212529;
    --text-sub: #6c757d;
    --border-color: #dee2e6;

    /* Theme Colors */
    --primary-color: #0d6efd;
    --price-color: #d63384;
    --qos-color: #0a58ca;
    --shadow-color: rgba(0, 0, 0, 0.04);

    /* Table Header */
    --table-header-bg: #f8f9fa;
    --table-header-text: #212529;

    /* Badges */
    --badge-aldat-bg: #ff5722;
    --badge-moyo-bg: #0062cc;
    --badge-gonghom-bg: #20c997;
    --badge-default-bg: #e9ecef;
    --badge-text: #ffffff;
    --badge-default-text: #495057;
}

/* 다크 모드 */
[data-theme="dark"] {
    --bg-body: #121212;
    --bg-container: #1e1e1e;
    --hover-bg: #2c3e50;
    --input-bg: #252525;

    --text-main: #e0e0e0;
    --text-sub: #aaaaaa;
    --border-color: #333333;

    --primary-color: #3a8fd6;
    --price-color: #ff80ab;
    --qos-color: #64b5f6;
    --shadow-color: rgba(0, 0, 0, 0.2);

    --table-header-bg: #252525;
    --table-header-text: #e0e0e0;

    --badge-aldat-bg: #e64a19;
    --badge-moyo-bg: #3a8fd6;
    --badge-gonghom-bg: #1aa179;
    --badge-default-bg: #444444;
    --badge-text: #ffffff;
    --badge-default-text: #ffffff;
}

/* 기본 태그 초기화 및 설정 */
body {
    font-family: 'Pretendard', -apple-system, sans-serif;
    padding: 20px;
    background-color: var(--bg-body);
    color: var(--text-main);
    margin: 0;
    transition: background-color 0.3s, color 0.3s;
    line-height: 1.6;
}

mark {
    background-color: #ffeb3b;
    color: #000;
    padding: 0;
    border-radius: 2px;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}


/* =========================================
   2. 레이아웃 및 컨트롤러 UI
========================================= */
header {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    padding: 10px 0 30px;
}

h1 {
    margin: 0;
    font-size: 1.6rem;
    font-weight: 800;
    text-align: center;
    letter-spacing: -0.5px;
}

.theme-toggle-btn {
    position: absolute;
    right: 0;
    top: 30%;
    transform: translateY(-50%);
    background: var(--bg-container);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 8px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 1.1rem;
    z-index: 10;
    transition: 0.2s;
    box-shadow: 0 2px 5px var(--shadow-color);
}

.theme-toggle-btn:hover {
    background: var(--hover-bg);
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 24px;
    background: var(--bg-container);
    padding: 24px;
    border-radius: 16px;
    box-shadow: 0 4px 16px var(--shadow-color);
    border: 1px solid var(--border-color);
}

.filter-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    width: 100%;
}

input[type="text"],
select {
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    background-color: var(--input-bg);
    color: var(--text-main);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

input[type="text"]:focus,
select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.1);
}


/* =========================================
   3. 슬라이더 UI (공통)
========================================= */
.slider-box {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: border-color 0.2s;
}

.slider-box:hover {
    border-color: #bbbbbb;
}

[data-theme="dark"] .slider-box:hover {
    border-color: #555555;
}

.slider-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.slider-header label {
    font-size: 12px;
    color: var(--text-sub);
    font-weight: 700;
    letter-spacing: -0.3px;
}

.slider-inputs {
    display: flex;
    align-items: center;
    gap: 6px;
}

.slider-inputs input {
    width: 60px;
    padding: 4px 6px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 13px;
    background: var(--bg-container);
    color: var(--text-main);
    text-align: center;
    outline: none;
    font-weight: 600;
}

.slider-inputs span {
    font-size: 13px;
    color: var(--text-sub);
    font-weight: 600;
}

.slider-container {
    position: relative;
    height: 16px;
    display: flex;
    align-items: center;
    margin-top: 4px;
}

.slider-track {
    position: absolute;
    width: 100%;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
    z-index: 1;
}

.slider-range {
    position: absolute;
    height: 4px;
    background: var(--primary-color);
    border-radius: 2px;
    z-index: 2;
    transition: left 0.1s, width 0.1s;
}

.slider-container input[type="range"] {
    position: absolute;
    width: 100%;
    pointer-events: none;
    -webkit-appearance: none;
    background: none;
    outline: none;
    margin: 0;
    z-index: 3;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--primary-color);
    border-radius: 50%;
    border: 2px solid #fff;
    cursor: pointer;
    pointer-events: auto;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}


/* =========================================
   4. 드롭다운 필터 UI (Multi-Select)
========================================= */
.multi-select {
    position: relative;
    display: inline-block;
}

/* 💡 클릭 전 보여지는 summary 버튼의 고정폭 설정 */
.multi-select summary {
    width: 150px; /* 고정 너비 지정 */
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    background-color: var(--input-bg);
    cursor: pointer;
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    white-space: nowrap;
    transition: border-color 0.2s;
}

.multi-select summary:focus {
    border-color: var(--primary-color);
    outline: none;
}

/* 💡 클릭 시 나타나는 드롭다운 옵션 컨테이너 */
.multi-select-options {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 100%;       /* 최소한 버튼 크기만큼은 보장 */
    width: max-content;    /* 내용물 길이에 맞게 자동으로 늘어남 (가변) */
    max-height: 350px;
    overflow-y: auto;
    background: var(--bg-container);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    z-index: 100;
    padding: 8px;
}

.multi-select-options label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    font-size: 14px;
    cursor: pointer;
    border-radius: 6px;
    white-space: nowrap;
    transition: background 0.2s;
    margin-bottom: 2px;
}

.multi-select-options label:hover {
    background: var(--hover-bg);
}


/* =========================================
   5. 데이터 테이블 UI
========================================= */
.table-container {
    background: var(--bg-container);
    border-radius: 16px;
    box-shadow: 0 4px 16px var(--shadow-color);
    border: 1px solid var(--border-color);
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
}

.get-time {
    display: block;
    font-size: 11px;
    color: var(--text-sub);
    margin-top: 6px;
}

.qos-cell {
    color: var(--qos-color);
    font-weight: 700;
}

.price-cell {
    color: var(--price-color);
    font-weight: 800;
    font-size: 1.5rem;
    white-space: nowrap;
    letter-spacing: -0.5px;
}

/* 통신사(MNO) 색상 설정 */
.mno-text {
    font-weight: 800;
    font-size: 14px;
    margin: 0 5px;
    white-space: nowrap;
}
.mno-skt { color: #e02020; }
.mno-kt  { color: #00b3b3; }
.mno-lg  { color: #e60073; }

/* 뱃지(Badge) 설정 */
.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    color: white;
    white-space: nowrap;
}
.badge-aldat   { background-color: var(--badge-aldat-bg); }
.badge-moyo    { background-color: var(--badge-moyo-bg); }
.badge-gonghom { background-color: var(--badge-gonghom-bg); }
.badge-seq {
    background-color: transparent;
    color: var(--text-sub);
    font-size: 12px;
    padding-left: 0;
}

/* 링크/버튼 설정 */
.link-btn {
    display: inline-block;
    text-decoration: none;
    color: white;
    background: var(--primary-color);
    border: none;
    border-radius: 8px;
    font-weight: 700;
    transition: 0.2s;
    white-space: nowrap;
    cursor: pointer;
    padding: 10px 18px;
    font-size: 14px;
    font-family: inherit;
}

.link-btn:hover {
    background: #0b5ed7;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(13, 110, 253, 0.2);
}

.link-btn.error-retry {
    margin-top: 15px;
}

#statusMessage {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-sub);
    font-size: 15px;
}


/* =========================================
   6. 반응형 설정 (Media Queries)
========================================= */

/* --- 🖥️ 데스크탑 (PC) --- */
@media screen and (min-width: 1025px) {
    /* 1번째 줄: 검색창과 각종 선택 옵션들 */
    .filter-group.top-row {
        display: flex;
        flex-wrap: wrap; 
        gap: 12px;
        align-items: center;
    }

    #searchInput {
        flex: 1 1 200px;
        max-width: 250px;
        height: 48px;
        padding: 0 16px;
        font-size: 14px;
    }

    /* 모든 일반 select 48px 높이 통일 */
    .filter-group.top-row select {
        height: 48px;
        padding: 0 14px;
        display: flex;
        align-items: center;
        font-size: 14px;
    }

    /* 멀티선택 48px 높이 통일 (너비는 상단에서 150px 지정됨) */
    .multi-select summary {
        height: 48px;
        padding: 0 14px;
        display: flex;
        align-items: center;
        font-size: 14px;
    }

    #sortSelect {
        margin-left: auto; /* 정렬 옵션을 우측 끝으로 밀어내기 */
    }

    /* 2번째 줄: 슬라이더들 */
    .filter-group.bottom-row {
        display: flex;
        padding-top: 20px;
        border-top: 1px dashed var(--border-color);
        gap: 16px;
        justify-content: flex-start;
    }

    .slider-box {
        width: 250px;
        flex-shrink: 0;
        height: 72px;
        justify-content: center;
    }

    /* 데이터 용량 슬라이더 */
    .slider-box[aria-label="데이터 용량 슬라이더"] {
        width: 250px; 
    }

    /* 테이블 헤더 및 셀 설정 */
    thead {
        background-color: var(--table-header-bg);
        color: var(--table-header-text);
        border-bottom: 2px solid var(--border-color);
    }

    th {
        padding: 16px 12px;
        text-align: center !important;
        font-size: 14px;
        vertical-align: middle;
        white-space: nowrap;
        font-weight: 700;
        color: var(--text-sub);
    }

    td {
        padding: 16px 12px;
        text-align: center;
        border-bottom: 1px solid var(--border-color);
        font-size: 14px;
        vertical-align: middle;
        color: var(--text-main);
    }

    .plan-name-cell {
        text-align: left !important;
        font-weight: 700;
        white-space: nowrap !important;
        width: auto;
        padding-right: 30px;
        font-size: 15px;
    }

    .data-cell {
        white-space: nowrap;
        min-width: 140px;
        text-align: center;
        font-weight: 600;
    }

    .col-fit {
        width: 1%;
        white-space: nowrap;
    }

    .mobile-only {
        display: none !important;
    }
}

/* --- 💻 태블릿 (중간 화면) --- */
@media screen and (min-width: 769px) and (max-width: 1024px) {
    .filter-group.top-row,
    .filter-group.bottom-row {
        display: flex;
        flex-wrap: wrap;
        gap: 12px;
    }

    #searchInput {
        width: 100%;
        height: 48px;
    }
    
    .slider-box {
        flex: 1 1 45%;
        width: auto; /* 태블릿에서는 유동적으로 전환 */
    }

    .slider-box[aria-label="데이터 용량 슬라이더"] {
        flex: 1 1 100%;
        width: auto;
    }

    .filter-group.bottom-row {
        padding-top: 16px;
        border-top: 1px dashed var(--border-color);
    }

    th, td {
        padding: 12px 8px;
        font-size: 13px;
    }

    .mobile-only {
        display: none !important;
    }
}

/* --- 📱 모바일 --- */
@media screen and (max-width: 768px) {
    h1 {
        font-size: 1.3rem;
        padding: 0 40px;
    }

    .controls {
        padding: 16px;
        gap: 12px;
    }

    .filter-group.top-row,
    .filter-group.bottom-row {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        border: none;
        padding-top: 0;
    }

    #searchInput, #sortSelect {
        grid-column: 1 / -1;
        height: 48px;
    }

    .slider-box {
        grid-column: 1 / -1;
        width: auto;
    }

    select,
    .multi-select,
    .multi-select summary {
        width: 100% !important; /* 모바일에서는 100% 꽉 차게 덮어쓰기 */
    }

    /* 테이블을 블록(카드) 형태로 변환 */
    thead {
        display: none !important;
    }

    .table-container {
        background: transparent;
        border: none;
        box-shadow: none;
        overflow: visible;
    }

    tr {
        background: var(--bg-container);
        margin-bottom: 16px;
        padding: 20px;
        border-radius: 16px;
        box-shadow: 0 4px 16px var(--shadow-color);
        border: 1px solid var(--border-color);
        display: block;
    }

    td {
        text-align: left;
        padding: 4px 0;
        border: none;
        width: 100% !important;
        display: block;
    }

    .pc-only {
        display: none !important;
    }

    .mobile-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 12px;
        border-bottom: 1px solid var(--border-color);
        padding-bottom: 12px;
    }

    .plan-title {
        font-size: 1.15rem;
        font-weight: 800;
        line-height: 1.4;
        margin: 8px 0;
    }

    .info-row {
        display: flex;
        gap: 10px;
        color: var(--text-sub);
        font-size: 14px;
        margin-bottom: 6px;
    }

    .price-row {
        margin-top: 16px;
        border-top: 1px dashed var(--border-color);
        padding-top: 16px;
        display: flex;
        align-items: baseline;
        gap: 8px;
    }

    .link-btn {
        width: 100%;
        display: block;
        text-align: center;
        padding: 14px;
        margin-top: 16px;
        font-size: 16px;
    }
}

/* =========================================
   7. 업데이트 알림 토스트 (Toast) UI
========================================= */
.update-toast {
    position: fixed;
    bottom: -100px;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--primary-color);
    color: white;
    padding: 12px 24px;
    border-radius: 30px;
    font-size: 15px;
    font-weight: 800;
    border: none;
    box-shadow: 0 8px 24px rgba(13, 110, 253, 0.4);
    cursor: pointer;
    z-index: 9999;
    transition: bottom 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.update-toast.show {
    bottom: 30px;
}

.update-toast:hover {
    background-color: #0b5ed7;
    transform: translateX(-50%) scale(1.05);
}
