/* Base Variables */
:root {
    /* Colors */
    --primary: #4F46E5; /* Indigo */
    --primary-light: #818CF8;
    --bg-color: #F8FAFC;
    --surface: #FFFFFF;
    --text-main: #0F172A;
    --text-muted: #64748B;
    --border: #E2E8F0;
    
    /* Status Colors */
    --status-green: #10B981;
    --status-green-bg: #D1FAE5;
    --status-yellow: #F59E0B;
    --status-yellow-bg: #FEF3C7;
    --status-red: #EF4444;
    --status-red-bg: #FEE2E2;

    /* Metrics */
    --border-radius: 16px;
    --border-radius-lg: 24px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-glass: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
    
    /* Animation */
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, Roboto, 'Helvetica Neue', 'Segoe UI', 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    overflow: hidden; /* Prevent body scroll, handle inside views */
    -webkit-font-smoothing: antialiased;
}

/* App Container */
#app {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    position: relative;
    overflow: hidden;
}

/* Views Management */
.view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
    z-index: 10;
    background-color: var(--bg-color);
    overflow-y: auto;
}

.view.active {
    opacity: 1;
    pointer-events: auto;
    z-index: 20;
}

/* ------------------ 
   1. Intro View 
------------------ */
#intro-view {
    display: flex;
    flex-direction: column;
    padding: 24px;
    background: linear-gradient(135deg, #f0f4ff 0%, #ffffff 100%);
}

.intro-header {
    margin-top: 40px;
    margin-bottom: 40px;
}

.intro-header h1 {
    font-size: 32px;
    font-weight: 800;
    line-height: 1.2;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.intro-header h1 span {
    color: var(--primary);
}

.intro-header p {
    color: var(--text-muted);
    font-size: 16px;
}

.region-cards h2 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 16px;
}

.cards-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.card {
    position: relative;
    border-radius: var(--border-radius);
    overflow: hidden;
    height: 120px;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.card:active {
    transform: translateY(0);
}

.card-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    transition: transform 0.5s ease;
}

.card:hover .card-bg {
    transform: scale(1.05);
}

/* Placeholder gradients for region backgrounds */
.wonju-bg { background: linear-gradient(rgba(0,0,0,0.3), rgba(0,0,0,0.6)), url('https://images.unsplash.com/photo-1542314831-c6a4d1424b94?ixlib=rb-4.0.3&auto=format&fit=crop&w=600&q=80') center/cover; }
.cheonan-bg { background: linear-gradient(rgba(0,0,0,0.3), rgba(0,0,0,0.6)), url('https://images.unsplash.com/photo-1533637372993-9c87d60e7f9a?ixlib=rb-4.0.3&auto=format&fit=crop&w=600&q=80') center/cover; }
.suwon-bg { background: linear-gradient(rgba(0,0,0,0.3), rgba(0,0,0,0.6)), url('https://images.unsplash.com/photo-1588668214407-6ea9a6d8c272?ixlib=rb-4.0.3&auto=format&fit=crop&w=600&q=80') center/cover; }

.card-content {
    position: absolute;
    bottom: 0;
    left: 0;
    padding: 16px;
    width: 100%;
    color: white;
}

.card-content h3 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 4px;
}

.card-content p {
    font-size: 13px;
    opacity: 0.9;
}

/* ------------------ 
   2. Transition View 
------------------ */
#transition-view {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--text-main);
    color: white;
    text-align: center;
}

.transition-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    opacity: 0.4;
    filter: blur(4px);
}

.transition-content {
    position: relative;
    z-index: 2;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
    margin: 0 auto 24px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.transition-content h2 {
    font-size: 24px;
    font-weight: 600;
    line-height: 1.4;
}

/* ------------------ 
   3. Map View 
------------------ */
#map-view {
    overflow: hidden;
}

#map {
    width: 100%;
    height: 100%;
    z-index: 1;
}

.top-bar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: var(--shadow-sm);
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
}

.top-bar h2 {
    font-size: 16px;
    font-weight: 600;
}

.top-bar button {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--text-main);
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: var(--transition);
}

.top-bar button:active {
    background-color: rgba(0,0,0,0.05);
}

.legend {
    position: absolute;
    top: 80px;
    right: 16px;
    z-index: 1000;
    padding: 12px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.glass-panel {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: var(--shadow-glass);
    border: 1px solid rgba(255, 255, 255, 0.4);
}

.legend-item {
    display: flex;
    align-items: center;
    font-size: 12px;
    font-weight: 500;
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-right: 8px;
    box-shadow: 0 0 0 2px white;
}

.dot-green { background-color: var(--status-green); }
.dot-yellow { background-color: var(--status-yellow); }
.dot-red { background-color: var(--status-red); }

/* Custom Leaflet Marker styles */
.custom-marker {
    display: flex;
    align-items: center;
    justify-content: center;
}
.marker-pin {
    width: 30px;
    height: 30px;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    position: relative;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    border: 2px solid white;
}
.marker-pin::after {
    content: '';
    width: 14px;
    height: 14px;
    background: white;
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
.marker-green { background-color: var(--status-green); }
.marker-yellow { background-color: var(--status-yellow); }
.marker-red { background-color: var(--status-red); }
.marker-active { transform: scale(1.2); z-index: 1000 !important; }


/* ------------------ 
   4. Bottom Sheet 
------------------ */
.bottom-sheet {
    position: absolute;
    bottom: -100%;
    left: 0;
    width: 100%;
    background-color: var(--surface);
    border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0;
    padding: 0 24px 24px;
    z-index: 1001;
    box-shadow: 0 -10px 25px rgba(0,0,0,0.1);
    transition: bottom 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.1);
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}

.bottom-sheet.show {
    bottom: 0;
}

.sheet-handle-wrap {
    width: 100%;
    padding: 12px 0;
    display: flex;
    justify-content: center;
    cursor: pointer;
}

.sheet-handle {
    width: 40px;
    height: 5px;
    background-color: #CBD5E1;
    border-radius: 10px;
}

.sheet-header {
    margin-bottom: 20px;
}

.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 8px;
}

.badge-green { background-color: var(--status-green-bg); color: #065F46; }
.badge-yellow { background-color: var(--status-yellow-bg); color: #92400E; }
.badge-red { background-color: var(--status-red-bg); color: #991B1B; }

.sheet-header h3 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
}

.btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
}

.btn-primary:hover {
    background-color: #4338CA;
}

.btn-sm {
    padding: 8px 12px;
    font-size: 14px;
    border-radius: 8px;
    width: auto;
}

/* ------------------ 
   5. Detail Panel 
------------------ */
.detail-panel {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    z-index: 2000;
    transition: top 0.4s ease-in-out;
    display: flex;
    flex-direction: column;
}

.detail-panel.show {
    top: 0;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background-color: var(--surface);
    border-bottom: 1px solid var(--border);
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
}

.panel-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--text-main);
    cursor: pointer;
    padding: 4px;
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.detail-section {
    background-color: var(--surface);
    border-radius: var(--border-radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}

.detail-section h4 {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.detail-section h4 i {
    color: var(--primary);
}

/* Chart Mockup */
.chart-container {
    padding: 10px 0;
}

.chart-mockup {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

.bar {
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    font-weight: 600;
    font-size: 14px;
}

.bar-price {
    background-color: var(--border);
    width: 70%;
    color: var(--text-main);
}

.bar-value {
    background-color: var(--status-green-bg);
    width: 90%;
    color: #065F46;
}

.chart-desc {
    font-size: 14px;
    color: var(--text-muted);
    line-height: 1.5;
    background-color: var(--bg-color);
    padding: 12px;
    border-radius: 8px;
}

/* AI Summary Grid */
.ai-summary-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.summary-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px;
    background-color: var(--bg-color);
    border-radius: 12px;
}

.summary-icon {
    width: 36px;
    height: 36px;
    background-color: var(--primary-light);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.summary-text h5 {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 4px;
    font-weight: 600;
}

.summary-text p {
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
}

/* News List */
.news-list {
    list-style: none;
}

.news-list li {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 12px;
    align-items: center;
}

.news-list li:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.news-tag {
    font-size: 11px;
    font-weight: 600;
    color: var(--primary);
    background-color: rgba(79, 70, 229, 0.1);
    padding: 4px 8px;
    border-radius: 4px;
    flex-shrink: 0;
}

.news-title {
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Comments */
.detail-section h4 .count {
    background-color: var(--primary);
    color: white;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 4px;
}

.comment-input-wrap {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.comment-input-wrap input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
    outline: none;
    transition: var(--transition);
}

.comment-input-wrap input:focus {
    border-color: var(--primary);
}

.comment-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.comment-item {
    display: flex;
    gap: 12px;
}

.comment-avatar {
    width: 32px;
    height: 32px;
    background-color: #E2E8F0;
    color: #94A3B8;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.comment-info {
    font-size: 13px;
    margin-bottom: 4px;
}

.comment-info .date {
    color: var(--text-muted);
    font-size: 11px;
    margin-left: 6px;
}

.comment-text {
    font-size: 14px;
    line-height: 1.5;
    background-color: var(--bg-color);
    padding: 10px 12px;
    border-radius: 0 12px 12px 12px;
    display: inline-block;
}

/* Responsive adjustments for PC */
@media (min-width: 768px) {
    #app {
        max-width: 480px;
        height: 850px;
        margin: 20px auto;
        border-radius: 30px;
        box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
        border: 8px solid #1E293B;
    }
    
    body {
        display: flex;
        align-items: center;
        justify-content: center;
        background-color: #E2E8F0;
    }
}
