/* ================================
   CSS 변수 정의 - 테마별
================================ */

/* 자동 모드 (기본값 - 시스템 설정 따라감) */
:root {
    --primary-dark: #042641;
    --primary-light: #0d3a5c;
    --secondary-color: #1abc9c;
    --accent-color: #e74c3c;
    --warning-color: #f39c12;
    --card-bg: #0a2d4a;
    --text-light: #ecf0f1;
    --text-muted: #bdc3c7;
    --border-color: #1a4a6e;
    --success-color: #2ecc71;
    --danger-color: #e74c3c;
    --card-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
    --border-radius: 12px;
    --base-font-size: 18px;
    
    /* 모드 표시기 */
    --theme-mode: 'auto';
}

/* 다크 모드 변수 */
[data-theme="dark"] {
    --primary-dark: #042641;
    --primary-light: #0d3a5c;
    --secondary-color: #1abc9c;
    --accent-color: #e74c3c;
    --warning-color: #f39c12;
    --card-bg: #0a2d4a;
    --text-light: #ecf0f1;
    --text-muted: #bdc3c7;
    --border-color: #1a4a6e;
    --success-color: #2ecc71;
    --danger-color: #e74c3c;
    --card-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
    --theme-mode: 'dark';
}

/* 화이트 모드 변수 */
[data-theme="light"] {
    --primary-dark: #f8f9fa;
    --primary-light: #e9ecef;
    --secondary-color: #17a2b8;
    --accent-color: #dc3545;
    --warning-color: #fd7e14;
    --card-bg: #ffffff;
    --text-light: #212529;
    --text-muted: #6c757d;
    --border-color: #dee2e6;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --card-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
    --theme-mode: 'light';
}

/* ================================
   공통 스타일
================================ */
body {
    font-family: 'Segoe UI', 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
    font-size: var(--base-font-size);
    background-color: var(--primary-dark);
    color: var(--text-light);
    min-height: 100vh;
    padding-top: 15px;
    padding-bottom: 30px;
    line-height: 1.8;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 1400px;
    padding-left: 15px;
    padding-right: 15px;
}

/* ================================
   테마 전환 버튼
================================ */
.theme-switcher {
    position: relative;
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 30px;
    padding: 5px;
    width: 160px;
    margin-left: auto;
    margin-right: 10px;
}

.theme-option {
    flex: 1;
    text-align: center;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--text-muted);
    z-index: 1;
}

.theme-option.active {
    color: white;
    background: linear-gradient(135deg, var(--secondary-color), var(--accent-color));
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.theme-option:hover:not(.active) {
    color: var(--text-light);
    background: rgba(255, 255, 255, 0.1);
}

/* ================================
   헤더 스타일
================================ */
.main-header {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary-light));
    color: var(--text-light);
    border-radius: var(--border-radius);
    padding: 20px;
    margin-bottom: 25px;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 15px;
    transition: all 0.3s ease;
}

.header-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.main-header h1 {
    font-weight: 800;
    font-size: 1.8rem;
    margin: 0;
    line-height: 1.3;
    flex: 1;
}

.main-header .badge {
    font-size: 1.3rem;
    padding: 8px 15px;
    white-space: nowrap;
    background: linear-gradient(135deg, var(--secondary-color), var(--accent-color));
}

/* 상태 정보 박스 */
.status-info-box {
    background-color: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(10px);
    padding: 15px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    margin-top: 1px;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.status-info-box i {
    color: var(--secondary-color);
    font-size: 1.1rem;
}

.status-info-box .badge {
    font-size: 1rem;
    padding: 6px 10px;
    font-weight: 600;
    margin: 3px;
}

/* ================================
   센서 카드
================================ */
.sensor-card-dark {
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 20px;
    margin-bottom: 25px;
    height: 100%;
    box-shadow: var(--card-shadow);
    transition: all 0.3s ease;
    border: 1px solid var(--border-color);
}

.sensor-card-dark:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.4);
    border-color: var(--secondary-color);
}

.sensor-card-dark h3 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--text-light);
    display: flex;
    align-items: center;
    border-bottom: 3px solid var(--border-color);
    padding-bottom: 12px;
}

.sensor-card-dark h3 i {
    margin-right: 10px;
    color: var(--secondary-color);
    font-size: 1.6rem;
}

/* 센서 항목 */
.sensor-item-dark {
    display: flex;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 1rem;
}

.sensor-item-dark:last-child {
    border-bottom: none;
}

.sensor-field-dark {
    font-weight: 700;
    color: var(--secondary-color);
    font-size: 1.2rem;
    min-width: 60px;
    text-align: center;
    background-color: rgba(26, 188, 156, 0.1);
    padding: 6px 10px;
    border-radius: 6px;
    margin-right: 10px;
    border: 1px solid rgba(26, 188, 156, 0.2);
}

.sensor-info-dark {
    flex: 1;
    margin: 0 10px;
    display: flex;
    flex-direction: column;
}

.sensor-name-dark {
    color: var(--text-muted);
    font-size: 1rem;
    display: block;
    margin-bottom: 4px;
    font-weight: 500;
}

/* 값과 단위를 같은 줄에 표시 */
.value-unit-container {
    display: flex;
    align-items: baseline;
    gap: 5px;
    flex-wrap: nowrap;
}

.sensor-value-dark {
    font-size: 1.8rem !important;
    font-weight: 800 !important;
    color: var(--text-light) !important;
    line-height: 1;
    white-space: nowrap;
}

/* 단위 스타일 - 값 옆에 바로 붙여서 */
.sensor-unit-dark {
    color: var(--secondary-color);
    font-size: 1.3rem;
    font-weight: 600;
    white-space: nowrap;
    margin: 0;
    padding: 0;
    background: none;
    border: none;
    min-width: auto;
}

.sensor-status-dark {
    font-size: 0.9rem;
    padding: 4px 8px;
    border-radius: 12px;
    margin-left: 10px;
    font-weight: 700;
    background-color: rgba(0, 0, 0, 0.1);
    color: var(--text-light);
}

.nodata-dark {
    color: var(--text-muted) !important;
    font-style: italic;
    font-size: 1.4rem !important;
}

/* 새로고침 버튼 */
.refresh-btn {
    background: linear-gradient(135deg, var(--warning-color), var(--accent-color));
    color: white;
    border: none;
    font-weight: 700;
    font-size: 1rem;
    padding: 8px 15px;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(255, 107, 107, 0.3);
    transition: all 0.3s ease;
    cursor: pointer;
}

.refresh-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(255, 107, 107, 0.4);
}

/* 값 상태 색상 */
.value-positive {
    color: var(--success-color) !important;
}

.value-warning {
    color: var(--warning-color) !important;
}

.value-danger {
    color: var(--danger-color) !important;
}

.value-normal {
    color: var(--secondary-color) !important;
}

/* 센서 카드 테마별 테두리 색상 */
.card-temperature {
    border-left: 6px solid var(--accent-color);
}

.card-carbon {
    border-left: 6px solid var(--success-color);
}

.card-soil {
    border-left: 6px solid var(--warning-color);
}

.card-solar {
    border-left: 6px solid #3498db;
}

.card-calc {
    border-left: 6px solid #9b59b6;
}

.nobr {
    white-space: nowrap;
}

/* 긴급 배지 */
.badge-emergency {
    background: linear-gradient(135deg, #ff4757, #ff3838);
    color: white;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 71, 87, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(255, 71, 87, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(255, 71, 87, 0);
    }
}

/* ================================
   반응형 디자인 - 모바일
================================ */
@media (max-width: 768px) {
    body {
        font-size: 16px !important;
        padding-top: 10px;
        padding-bottom: 15px;
        line-height: 1.6;
    }
    
    .main-header {
        padding: 15px;
        gap: 10px;
    }
    
    .main-header h1 {
        font-size: 1.4rem !important;
        line-height: 1.3;
    }
    
    .main-header .badge {
        font-size: 1rem;
        padding: 6px 12px;
    }
    
    .theme-switcher {
        width: 140px;
        margin: 10px auto 0;
        order: 3;
        width: 100%;
    }
    
    .sensor-card-dark {
        padding: 5px;
        margin-bottom: 5px;
    }
    
    .sensor-card-dark h3 {
        font-size: 1.3rem !important;
        padding-bottom: 1px;
        margin-bottom: 5px;
    }
    
    .sensor-item-dark {
        padding: 0px 0;
        flex-wrap: wrap;
    }
    
    .sensor-field-dark {
        font-size: 1.1rem !important;
        min-width: 55px;
        padding: 5px 8px;
        margin-right: 8px;
        order: 1;
    }
    
    .sensor-info-dark {
        margin: 5px 0;
        width: 100%;
        order: 2;
    }
    
    .sensor-name-dark {
        font-size: 0.9rem !important;
        margin-bottom: 2px;
    }
    
    .value-unit-container {
        gap: 3px;
    }
    
    .sensor-value-dark {
        font-size: 1.5rem !important;
        line-height: 1;
    }
    
    .sensor-unit-dark {
        font-size: 1.1rem !important;
    }
    
    .sensor-status-dark {
        order: 3;
        margin-left: auto;
        margin-top: 5px;
        font-size: 0.8rem;
        padding: 3px 6px;
    }
    
    .status-info-box {
        padding: 12px;
        font-size: 0.9rem;
    }
    
    .status-info-box .badge {
        font-size: 0.9rem !important;
        padding: 5px 8px;
        margin: 2px;
    }
    
    .refresh-btn {
        padding: 6px 12px;
        font-size: 0.9rem !important;
    }
}

@media (max-width: 576px) {
    .main-header h1 {
        font-size: 1.3rem !important;
    }
    
    .sensor-value-dark {
        font-size: 1.4rem !important;
    }
    
    .sensor-unit-dark {
        font-size: 1rem !important;
    }
}

/* 초소형 모바일 대응 */
@media (max-width: 360px) {
    .main-header h1 {
        font-size: 1.2rem !important;
    }
    
    .sensor-card-dark h3 {
        font-size: 1.2rem !important;
    }
    
    .sensor-value-dark {
        font-size: 1.3rem !important;
    }
    
    .sensor-unit-dark {
        font-size: 0.9rem !important;
    }
}

/* 접근성 개선 */
button, .badge, .sensor-field-dark, .refresh-btn {
    min-height: 25px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* 푸터 스타일 */
.footer-dark {
    text-align: center;
    margin-top: 30px;
    color: var(--text-muted);
    font-size: 0.9rem;
    padding: 15px;
    border-top: 2px solid var(--border-color);
    line-height: 1.5;
}

.farm_id {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background-color: var(--success-color);
    color: white;
    border-radius: 50%;
    font-size: 1.0em;
    margin-right: 8px;
}