:root {
    --bg-color: #0d1117;
    --card-bg: rgba(22, 27, 34, 0.85);
    --primary-color: #58a6ff;
    --primary-gradient: linear-gradient(135deg, #58a6ff, #1f6feb);
    --secondary-color: #2ea043;
    --text-color: #c9d1d9;
    --text-muted: #8b949e;
    --border-color: #30363d;
    --accent-color: #f0883e;
    --font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --radius: 12px;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    overflow-x: hidden;
}

#app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end; /* 로고 하단 문구와 수평 정렬 */
    padding: 15px 0 25px 0;
}

.stats-badge {
    background: rgba(88, 166, 255, 0.1);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 100px;
}

.stats-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

#searchCount {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-color);
}

.service-notice {
    font-size: 0.8rem;
    color: #f85149; /* 경고 레드 계열 */
    font-weight: 500;
    margin-top: 5px;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(13, 17, 23, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.loader-box {
    text-align: center;
    background: var(--card-bg);
    padding: 30px 50px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(88, 166, 255, 0.1);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#loadingMsg {
    color: var(--text-color);
    font-weight: 600;
}

.hidden { display: none !important; }

.logo-wrap {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo .icon {
    font-size: 2.5rem;
}

.logo h1 {
    font-size: 1.8rem;
    font-weight: 800;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.service-intro {
    font-size: 0.95rem;
    color: var(--accent-color);
    font-weight: 600;
    opacity: 0.9;
}

.card {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.btn-primary {
    background: var(--primary-gradient);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(88, 166, 255, 0.3);
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
}

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

.search-section {
    position: sticky;
    top: 20px;
    z-index: 100;
}

.search-controls {
    display: flex;
    gap: 15px;
    align-items: center;
}

select {
    background: #161b22;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 10px;
    border-radius: 6px;
    width: 200px;
}

.content-grid {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 20px;
}

.map-container {
    height: 600px;
    padding: 0;
    overflow: hidden;
}

#map {
    height: 100%;
    width: 100%;
    background: #161b22;
}

.result-section {
    display: flex;
    flex-direction: column;
    gap: 20px;
    height: 600px;
    overflow-y: auto;
}

.result-header h2 {
    font-size: 1.25rem;
    margin-bottom: 4px;
}

#selectedAreaLabel {
    color: var(--text-muted);
    font-size: 0.9rem;
}

#bestDongLabel {
    margin-top: 5px;
    font-size: 1rem;
    color: var(--primary-color);
    font-weight: 700;
}

.score-summary {
    display: flex;
    gap: 15px;
}

.total-score-badge, .grade-badge {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px;
    background: rgba(88, 166, 255, 0.1);
    border-radius: 12px;
    border: 1px solid rgba(88, 166, 255, 0.2);
}

.total-score-badge span:last-child, .grade-badge span:last-child {
    font-size: 1.75rem;
    font-weight: 700;
    margin-top: 4px;
}

.chart-container {
    height: 300px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 10px 0;
}

.metrics-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.metric-item {
    padding: 10px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    border-left: 3px solid var(--primary-color);
}

.metric-item .label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.metric-item .value {
    font-weight: 600;
}

.school-section {
    margin-top: 20px;
}

.school-section .tabs {
    display: flex;
    margin-bottom: 10px;
    border-bottom: 2px solid var(--border-color);
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 10px 20px;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: 600;
    transition: all 0.3s;
    display: flex;
    align-items: center;
}

.tab-btn.active {
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    border-bottom: 2px solid var(--primary-color);
    padding: 10px 15px;
}

.tab-btn .icon {
    margin-right: 8px;
    font-size: 1.3rem;
}

.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

th, td {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
}

th {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    text-align: center; /* 헤더 중앙 정렬 */
}

td {
    color: var(--text-color);
}

/* 점수 숫자는 오른쪽 정렬 (지역명/등급 제외) */
td:nth-child(n+3) {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

td:nth-child(1) { text-align: left; }
td:nth-child(2) { text-align: center; }

/* 확장 행 스타일 */
.detail-row {
    background: rgba(88, 166, 255, 0.05);
    display: none;
}

.detail-row.active {
    display: table-row;
}

.detail-content {
    display: flex;
    gap: 80px;
    padding: 30px 50px;
    align-items: center;
    justify-content: center;
    background: #1c2128;
    border-radius: 8px;
    margin: 10px;
    box-shadow: inset 0 2px 8px rgba(0,0,0,0.4);
}

.mini-chart-box {
    width: 260px;
    height: 260px;
    position: relative;
}

.mini-data-table {
    width: 360px; /* 늘어난 정보량에 맞춰 소폭 확대 */
    border-collapse: collapse;
    font-size: 0.85rem;
    margin-top: 0 !important;
}

.mini-data-table th, .mini-data-table td {
    padding: 8px 12px;
    border-bottom: 1px solid #30363d;
    text-align: left !important; /* 상세 표는 좌측 정렬 */
}

.mini-data-table th {
    width: 140px;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.02);
}

.mini-data-table td {
    color: var(--primary-color);
    font-weight: 600;
}

.mini-data-table tr:last-child th, .mini-data-table tr:last-child td {
    border-bottom: none;
}
td strong {
    color: var(--primary-color);
}
.tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}
.tag.s { background-color: rgba(215,58,73,0.15); color: #ff7b72; }
.tag.a { background-color: rgba(227,98,9,0.15); color: #ffa657; }
.tag.b { background-color: rgba(219,171,9,0.15); color: #e3b341; }
.tag.c { background-color: rgba(46,160,67,0.15); color: #56d364; }
.tag.d { background-color: rgba(88,166,255,0.15); color: #79c0ff; }
.tag.e { background-color: rgba(139,148,158,0.15); color: #8b949e; }

/* Map Infographic Labels */
.map-infographic-label {
    background-color: rgba(22, 27, 34, 0.85);
    border: 1px solid #30363d;
    border-radius: 4px;
    color: #c9d1d9;
    padding: 4px 6px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    font-size: 0.75rem;
    line-height: 1.2;
    pointer-events: none;
}
.leaflet-tooltip-left::before, .leaflet-tooltip-right::before, .leaflet-tooltip-top::before, .leaflet-tooltip-bottom::before {
    display: none !important;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    width: 90%;
    max-width: 400px;
}

.input-group {
    margin-top: 15px;
}

.input-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.9rem;
}

.input-group input {
    width: 100%;
    background: #161b22;
    border: 1px solid var(--border-color);
    padding: 10px;
    color: var(--text-color);
    border-radius: 6px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

footer {
    text-align: center;
    padding: 40px 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

@media (max-width: 900px) {
    .content-grid {
        grid-template-columns: 1fr;
    }
    
    .search-controls {
        flex-direction: column;
    }
    
    .search-controls select, .search-controls button {
        width: 100%;
    }
}

/* ─── 탭 콘텐츠 전환 ─────────────────────────── */
.tab-content {
    display: none;
}
.tab-content.active {
    display: block;
}

/* ─── 고등학교현황 정렬 버튼 ─────────────────── */
.sortable-col {
    vertical-align: middle;
    white-space: nowrap;
}

.sort-btns {
    display: inline-flex;
    flex-direction: column;
    margin-left: 6px;
    gap: 1px;
    vertical-align: middle;
}

.sort-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 3px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.6rem;
    line-height: 1;
    padding: 1px 4px;
    transition: all 0.15s;
}

.sort-btn:hover {
    background: rgba(88, 166, 255, 0.15);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.sort-btn.active-sort {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: #fff;
    font-weight: 700;
}

/* ─── 숫자 셀 우측 정렬 ─────────────────────── */
#highSchoolTable td.num-cell {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: #58a6ff;
}

#highSchoolTable td:nth-child(1) {
    color: var(--text-muted);
    font-size: 0.85rem;
}

#highSchoolTable td:nth-child(2) {
    text-align: left;
}

#highSchoolTable th {
    text-align: center;
}

#highSchoolTable tr:hover {
    background: rgba(88, 166, 255, 0.07);
}

.footer-bottom-row {
    margin-top: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 30px;
}

.produced-by {
    margin-top: 0;
    font-size: 0.95rem;
    color: var(--text-muted);
    font-weight: 600;
}

.produced-by span {
    color: #f0883e;
    font-weight: 800;
    margin-left: 6px;
}

.footer-links {
    margin-top: 0;
    display: flex;
    align-items: center;
}

.school-link {
    color: var(--text-color);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s;
}

.school-link:hover {
    color: var(--primary-color);
    text-decoration: underline;
}

.map-icon {
    font-size: 0.9rem;
    opacity: 0.7;
    transition: transform 0.2s;
}

.school-link:hover .map-icon {
    transform: scale(1.2);
    opacity: 1;
}

.footer-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: color 0.15s ease;
}

.footer-link:hover {
    color: var(--primary-color);
}

.footer-link .icon {
    font-size: 1.1rem;
}
