/* 메인 CSS - 모바일 대응 개선 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Noto Sans KR', sans-serif;
    background: #f0f2f5;
    color: #333;
    min-height: 100vh;
    overflow-x: hidden;
}

.container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    background: #fff;
    min-height: 70px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
    z-index: 100;
    flex-wrap: wrap;
}

.logo {
    font-size: 24px;
    font-weight: 700;
    color: #2c3e50;
}

.main-wrapper {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.sidebar {
    width: 80px;
    background: #2c3e50;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 20px;
    gap: 20px;
    flex-shrink: 0;
}

.nav-item {
    width: 50px;
    height: 50px;
    background: rgba(255,255,255,0.1);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 24px;
}

.nav-item:hover {
    background: rgba(255,255,255,0.2);
    transform: scale(1.1);
}

.nav-item.active {
    background: rgba(255,255,255,0.3);
}

/* 데스크톱 그리드 레이아웃 */
.content-area {
    flex: 1;
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(18, 1fr);
    grid-template-rows: repeat(12, 1fr);
    gap: 10px;
    overflow-y: auto;
    overflow-x: hidden;
}

.widget {
    background: #fff;
    border-radius: 16px;
    padding: 0;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    transition: all 0.3s;
    overflow: hidden;
}

.widget:hover {
    box-shadow: 0 8px 30px rgba(0,0,0,0.12);
    transform: translateY(-2px);
}

/* 강수 정보 그리드 - 웹에서는 고정 높이 */
.info-grid {
    grid-column: 1 / span 12;
    grid-row: 1 / span 6;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 10px;
    padding: 0;
    background: transparent;
    box-shadow: none;
}

.small-widget {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.08);
    transition: all 0.3s;
    cursor: pointer;
    overflow: hidden;
    position: relative;
    height: 100%;
    min-height: 160px;
}

.small-widget:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.12);
}

/* 기상영상 위젯 */
.weather-image-widget {
    grid-column: 13 / span 6;
    grid-row: 1 / span 6;
    position: relative;
    overflow: hidden;
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: 300px;
}

/* 누적 강수 */
.accumulated-widgets {
    grid-column: 1 / span 8;
    grid-row: 7 / span 6;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0;
    background: transparent;
    box-shadow: none;
    min-height: 300px;
}

.accumulated-widget {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    transition: all 0.3s;
    overflow: hidden;
    height: 100%;
    min-height: 250px;
}

/* 지도 영역 */
.map-widget {
    grid-column: 9 / span 4;
    grid-row: 7 / span 6;
    position: relative;
    overflow: hidden;
    padding: 0;
    background: #f5f5f5;
    min-height: 300px;
}

/* 수위 위젯 */
.waterlevel-widgets {
    grid-column: 13 / span 6;
    grid-row: 7 / span 6;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-template-rows: repeat(6, 1fr);
    gap: 10px;
    padding: 0;
    background: transparent;
    box-shadow: none;
    min-height: 300px;
}

#waterlevel-nakdong {
    grid-column: 1 / span 6;
    grid-row: 1 / span 2;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    overflow: hidden;
    min-height: 100px;
}

#waterlevel-geumho {
    grid-column: 1 / span 6;
    grid-row: 3 / span 2;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    overflow: hidden;
    min-height: 100px;
}

/* 신천과 남천/위천 동일한 크기로 수정 */
#waterlevel-sincheon {
    grid-column: 1 / span 3;
    grid-row: 5 / span 2;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    overflow: hidden;
    min-height: 100px;
}

#waterlevel-namcheon-wicheon {
    grid-column: 4 / span 3;
    grid-row: 5 / span 2;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    overflow: hidden;
    min-height: 100px;
}

iframe {
    border: none;
    width: 100%;
    height: 100%;
    display: block;
}

/* 태블릿 대응 (768px ~ 1024px) */
@media (max-width: 1024px) and (min-width: 769px) {
    .content-area {
        display: flex;
        flex-direction: column;
        gap: 20px;
        padding: 15px;
        overflow-y: auto;
    }
    
    .info-grid {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: repeat(3, 1fr);
        gap: 10px;
        min-height: 400px;
        width: 100%;
    }
    
    .weather-image-widget,
    .accumulated-widgets,
    .map-widget,
    .waterlevel-widgets {
        width: 100%;
        min-height: 350px;
    }
    
    .waterlevel-widgets {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        grid-template-rows: repeat(2, 1fr);
        gap: 10px;
        min-height: 400px;
    }
    
    #waterlevel-nakdong,
    #waterlevel-geumho {
        grid-column: span 1;
        grid-row: span 1;
    }
    
    #waterlevel-sincheon,
    #waterlevel-namcheon-wicheon {
        grid-column: span 1;
        grid-row: span 1;
    }
}

/* 모바일 대응 (768px 이하) */
@media (max-width: 768px) {
    header {
        flex-direction: column;
        gap: 10px;
        padding: 15px;
        text-align: center;
    }
    
    .logo {
        font-size: 18px;
    }
    
    .sidebar {
        display: none;
    }
    
    .main-wrapper {
        flex-direction: column;
    }
    
    .content-area {
        display: flex;
        flex-direction: column;
        gap: 15px;
        padding: 10px;
        overflow-y: auto;
        overflow-x: hidden;
        grid-template-columns: none;
        grid-template-rows: none;
    }
    
    .info-grid,
    .weather-image-widget,
    .accumulated-widgets,
    .map-widget,
    .waterlevel-widgets {
        width: 100%;
        order: initial;
        position: relative;
        display: block;
        margin-bottom: 15px;
    }
    
    .info-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        grid-template-rows: none;
        grid-auto-rows: minmax(120px, auto);
        gap: 10px;
        min-height: auto;
        height: auto;
    }
    
    .small-widget {
        height: auto !important;
        min-height: 120px;
    }
    
    .weather-image-widget {
        min-height: 350px;
        height: 350px;
    }
    
    .accumulated-widgets {
        min-height: 300px;
        height: auto;
    }
    
    .accumulated-widget {
        min-height: 280px;
        height: 280px;
    }
    
    .map-widget {
        min-height: 350px;
        height: 350px;
    }
    
    .waterlevel-widgets {
        display: flex;
        flex-direction: column;
        gap: 10px;
        background: transparent;
        box-shadow: none;
        min-height: auto;
    }
    
    #waterlevel-nakdong,
    #waterlevel-geumho,
    #waterlevel-sincheon,
    #waterlevel-namcheon-wicheon {
        width: 100%;
        height: 180px;
        min-height: 180px;
        margin-bottom: 10px;
    }
}

/* 작은 모바일 (480px 이하) */
@media (max-width: 480px) {
    header {
        padding: 10px;
    }
    
    .logo {
        font-size: 16px;
    }
    
    .content-area {
        padding: 8px;
        gap: 12px;
    }
    
    .info-grid {
        grid-template-columns: 1fr;
        grid-auto-rows: minmax(100px, auto);
        gap: 8px;
    }
    
    .small-widget {
        height: auto !important;
        min-height: 100px;
    }
    
    .weather-image-widget {
        min-height: 300px;
        height: 300px;
    }
    
    .accumulated-widget {
        min-height: 250px;
        height: 250px;
    }
    
    .map-widget {
        min-height: 300px;
        height: 300px;
    }
    
    #waterlevel-nakdong,
    #waterlevel-geumho,
    #waterlevel-sincheon,
    #waterlevel-namcheon-wicheon {
        height: 160px;
        min-height: 160px;
    }
}

/* iOS Safari 대응 */
@supports (-webkit-touch-callout: none) {
    .content-area {
        -webkit-overflow-scrolling: touch;
    }
    
    .widget,
    .small-widget {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
}

/* 가로 모드 대응 */
@media (max-width: 768px) and (orientation: landscape) {
    header {
        min-height: 50px;
        padding: 5px 15px;
    }
    
    .logo {
        font-size: 16px;
    }
    
    .content-area {
        padding: 8px;
    }
    
    .info-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }
    
    .small-widget {
        height: 100px;
        min-height: 100px;
    }
    
    .weather-image-widget,
    .map-widget {
        height: 250px;
        min-height: 250px;
    }
    
    .accumulated-widget {
        height: 200px;
        min-height: 200px;
    }
    
    #waterlevel-nakdong,
    #waterlevel-geumho,
    #waterlevel-sincheon,
    #waterlevel-namcheon-wicheon {
        height: 140px;
        min-height: 140px;
    }
}