/* ===========================================
   日本系統用蓄電池 可視化マップ - スタイルシート
   =========================================== */

/* CSS Custom Properties */
:root {
    /* Colors - Dark Theme */
    --bg-primary: #0a0a1a;
    --bg-secondary: #12122a;
    --bg-card: rgba(25, 25, 50, 0.85);
    --bg-glass: rgba(255, 255, 255, 0.05);

    /* Text Colors */
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --text-muted: rgba(255, 255, 255, 0.5);

    /* Status Colors */
    --color-under-review: #ff3a3a;
    --color-under-review-glow: rgba(255, 58, 58, 0.6);
    --color-contracted: #ff9500;
    --color-contracted-glow: rgba(255, 149, 0, 0.5);
    --color-connected: #00d084;
    --color-connected-glow: rgba(0, 208, 132, 0.5);

    /* Map Colors */
    --map-land: #1e1e3f;
    --map-border: rgba(100, 100, 180, 0.3);

    /* Layout */
    --container-width: 1400px;
    --header-height: auto;

    /* Spacing */
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2rem;

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;

    /* Shadows */
    --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.4);

    /* Typography */
    --font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* Reset & Base */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    background-image:
        radial-gradient(ellipse at 20% 20%, rgba(255, 58, 58, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(0, 100, 255, 0.08) 0%, transparent 50%);
}

/* Main Grid Layout */
.container {
    max-width: var(--container-width);
    margin: 0 auto;
    padding: var(--spacing-md);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    gap: var(--spacing-md);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    /* 2:1 ratio for map:details */
    gap: var(--spacing-md);
    flex: 1;
}

/* Header */
.header {
    text-align: center;
    padding-bottom: var(--spacing-md);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.app-title {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-xs);
    flex-wrap: wrap;
}

.title-main {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text-primary);
    background: linear-gradient(135deg, #fff 0%, #a5b4fc 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.title-sub {
    font-size: 1.1rem;
    color: var(--text-muted);
    font-weight: 400;
}

.app-description {
    max-width: 800px;
    margin: 0 auto var(--spacing-xs);
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.5;
}

.data-date {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.data-date a {
    color: #a5b4fc;
    text-decoration: none;
}

.data-date a:hover {
    text-decoration: underline;
}

/* Area Cards Section (Top) */
.area-cards-section {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 8px;
    /* Slightly more space for scrollbar interaction */
    -webkit-overflow-scrolling: touch;
}

.area-card-list {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    /* 10 regions */
    gap: var(--spacing-xs);
    min-width: 1200px;
    /* Increased to accommodate content */
}

.area-card {
    background: var(--bg-card);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md);
    padding: var(--spacing-xs);
    text-align: center;
    transition: all 0.2s ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.area-card:hover {
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.3);
    background: rgba(30, 41, 59, 1);
    z-index: 10;
}

.area-card.active {
    border-color: var(--color-under-review);
    box-shadow: 0 0 0 1px var(--color-under-review) inset;
    background: rgba(30, 41, 59, 1);
}

.area-card-name {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-secondary);
    white-space: nowrap;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 2px;
    margin-bottom: 2px;
}

/* Multi-status row in card */
.card-stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    line-height: 1.1;
}

.card-stat-label {
    font-size: 0.65rem;
    color: var(--text-muted);
}

.card-stat-val {
    font-weight: 700;
    font-family: monospace;
}

.val-review {
    color: var(--color-under-review);
}

.val-contract {
    color: var(--color-contracted);
}

.val-connect {
    color: var(--color-connected);
}

.val-vre {
    color: #a5b4fc;
}

/* Light purple for VRE */

/* Map Section */
.map-section {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
    overflow: hidden;
    height: 600px;
    /* Fixed height for dashboard */
}

/* Leaflet Container */
#map-container,
#japan-map {
    width: 100%;
    height: 100%;
}

.leaflet-container {
    background: #0a0a1a !important;
    font-family: var(--font-family);
}

/* Leaflet Popup Overrides */
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
    background: rgba(25, 25, 50, 0.95);
    color: var(--text-primary);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.leaflet-popup-content {
    margin: var(--spacing-sm);
}

/* Legend */
.legend {
    position: absolute;
    bottom: var(--spacing-md);
    left: var(--spacing-md);
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(8px);
    border-radius: var(--radius-md);
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 1000;
}

.legend-title {
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text-secondary);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    font-size: 0.8rem;
}

.legend-color {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.legend-note {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Stats Section (Right Panel) */
.stats-section {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    height: 600px;
    /* Match map height usually */
    overflow-y: auto;
    background: transparent;
    border: none;
    box-shadow: none;
}

.stats-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
}

.stats-title {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-md);
    border-left: 3px solid var(--color-contracted);
    padding-left: 8px;
    font-weight: 700;
}

/* Summary Stats */
.summary-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}

.summary-item {
    text-align: center;
}

.summary-item .label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.summary-item .value {
    font-size: 1.1rem;
    font-weight: 700;
}

.value.danger {
    color: var(--color-under-review);
}

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

.value.success {
    color: var(--color-connected);
}

/* Comparison Bar */
.comparison-bar-container {
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
    display: flex;
}

.comparison-bar {
    height: 100%;
    transition: width 0.5s ease;
}

.bar-under-review {
    background: var(--color-under-review);
}

.bar-contracted {
    background: var(--color-contracted);
}

.bar-connected {
    background: var(--color-connected);
}

/* Region Detail */
.region-detail {
    min-height: 200px;
}

.region-info h3 {
    font-size: 1.4rem;
    font-weight: 800;
    margin-bottom: var(--spacing-sm);
}

.region-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
}

.region-stat {
    background: rgba(0, 0, 0, 0.2);
    padding: 8px;
    border-radius: 6px;
    text-align: center;
}

.region-stat-label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.region-stat-value {
    font-size: 1rem;
    font-weight: 700;
}

.region-share {
    display: block;
    margin-top: 4px;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.region-note {
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.03);
    padding: 10px;
    border-radius: 6px;
}

/* Timeline Chart */
.timeline-card {
    min-height: 180px;
}

.timeline-chart {
    height: 120px;
}

.timeline-line {
    fill: none;
    stroke-width: 2;
}

.timeline-line-under-review {
    stroke: var(--color-under-review);
    filter: drop-shadow(0 0 4px var(--color-under-review-glow));
}

.timeline-line-contracted {
    stroke: var(--color-contracted);
}

.timeline-line-connected {
    stroke: var(--color-connected);
}

.timeline-dot {
    fill: #fff;
    r: 3;
}

.timeline-axis text {
    fill: var(--text-muted);
    font-size: 10px;
}

.timeline-axis line,
.timeline-axis path {
    stroke: rgba(255, 255, 255, 0.2);
}

.timeline-note {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 8px;
}

/* Map Markers CSS */
.custom-marker-icon {
    background: transparent;
    border: none;
}

.map-bubble {
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}

.map-bubble-under-review {
    background: var(--color-under-review);
    opacity: 0.75;
    border: 2px solid var(--color-under-review);
    box-shadow: 0 0 15px var(--color-under-review-glow);
    animation: pulse 2s ease-in-out infinite;
    z-index: 10;
}

.map-bubble-contracted {
    background: var(--color-contracted);
    opacity: 0.8;
    border: 1.5px solid var(--color-contracted);
    z-index: 20;
}

.map-bubble-connected {
    background: var(--color-connected);
    opacity: 0.9;
    border: 1.5px solid var(--color-connected);
    z-index: 30;
}

@keyframes pulse {

    0%,
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.75;
    }

    50% {
        transform: translate(-50%, -50%) scale(1.1);
        opacity: 0.9;
    }
}

.map-label {
    color: #fff;
    text-shadow: 0 0 3px #000;
    font-weight: 700;
    font-size: 11px;
    white-space: nowrap;
    text-align: center;
}

.map-label-value {
    color: #ff6b6b;
    font-size: 10px;
    display: block;
}

.placeholder-text {
    text-align: center;
    color: var(--text-muted);
    opacity: 0.6;
    padding: 20px 0;
}

/* Footer */
.footer {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: auto;
    padding-top: var(--spacing-md);
}

.footer a {
    color: inherit;
    text-decoration: underline;
}

/* ===========================================
   Responsive Design
   =========================================== */

/* Tablet & Mobile Layout Adjustment */
@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
        /* Stack map and stats */
        gap: var(--spacing-sm);
    }

    .map-section {
        height: 500px;
        /* Slightly reduced height */
    }

    .stats-section {
        height: auto;
        /* Allow natural height expansion */
        overflow-y: visible;
        /* No scroll needed usually */
    }

    .area-card-list {
        min-width: 1000px;
        /* Still allow horizontal scroll but slightly tighter */
    }
}

/* Mobile Layout */
@media (max-width: 768px) {
    :root {
        --spacing-md: 1rem;
        /* Compact spacing */
        --spacing-lg: 1.5rem;
    }

    .container {
        padding: var(--spacing-sm);
    }

    .app-title {
        flex-direction: column;
        gap: 4px;
        margin-bottom: var(--spacing-sm);
    }

    .title-main {
        font-size: 1.5rem;
        /* Smaller title */
        line-height: 1.2;
    }

    .title-sub {
        font-size: 0.9rem;
    }

    .app-description {
        font-size: 0.8rem;
    }

    /* Stack cards in scrollable view with better touch targets */
    .area-cards-section {
        margin-bottom: var(--spacing-sm);
    }

    .area-card-list {
        /* On mobile, cards need to be big enough to tap, so horizontal scroll is good.
           Reduce min-width to fit cards proportionally. */
        min-width: 1600px;
        /* Wider scroll canvas for thumb-friendly cards */
        gap: 8px;
    }

    .area-card {
        padding: 8px 6px;
    }

    .area-card-name {
        font-size: 0.8rem;
    }

    .map-section {
        height: 60vh;
        /* Use viewport height for map */
        min-height: 350px;
    }

    /* Move Legend for mobile to avoid overlap */
    .legend {
        bottom: 10px;
        left: 10px;
        padding: 8px;
        transform: scale(0.9);
        transform-origin: bottom left;
    }

    .stats-section {
        gap: var(--spacing-sm);
    }

    .stats-card {
        padding: var(--spacing-sm);
    }

    /* Make summary stats stack if too narrow */
    .summary-row {
        gap: 4px;
    }

    .summary-item .value {
        font-size: 1rem;
    }
}