/* ===========================
   Open Demographic - Dark Theme
   Stock Dashboard Style
   =========================== */

:root {
    --bg-base: #080f18;
    --bg-surface: #0d1520;
    --bg-card: #111d2e;
    --bg-card-hover: #162438;
    --bg-input: #0a1423;
    --border-subtle: #1a2744;
    --border-accent: #243656;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #00e5a0;
    --accent-dim: rgba(0, 229, 160, 0.12);
    --accent-glow: rgba(0, 229, 160, 0.3);
    --positive: #00e5a0;
    --negative: #f87171;
    --chart-blue: #60a5fa;
    --chart-purple: #a78bfa;
    --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
    --font-sans: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
    --header-height: 80px;
    --sidebar-width: 280px;
    --sidebar-right-width: 340px;
}

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

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-base);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

a {
    color: inherit;
    text-decoration: none;
}

/* === Header === */
.site-header {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 20px;
    border-bottom: 1px solid var(--border-subtle);
}

.header-nav {
    display: flex;
    gap: 16px;
    align-items: center;
}

.header-nav a {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    letter-spacing: 0.03em;
}

.header-nav a:hover {
    color: var(--accent);
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-mono);
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.logo-icon {
    color: var(--accent);
    font-size: 0.8rem;
}

.logo-accent {
    color: var(--accent);
}

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

/* === Ticker === */
.ticker-strip {
    overflow: hidden;
    white-space: nowrap;
    padding: 6px 0;
    background: var(--bg-base);
    border-top: 1px solid var(--border-subtle);
}

.ticker-inner {
    display: inline-block;
    animation: ticker-scroll 40s linear infinite;
    padding-left: 100%;
}

.ticker-inner:hover {
    animation-play-state: paused;
}

@keyframes ticker-scroll {
    0% { transform: translateX(0); }
    100% { transform: translateX(-100%); }
}

.ticker-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0 8px;
}

.ticker-label {
    color: var(--text-muted);
    font-size: 0.7rem;
    font-family: var(--font-sans);
}

.ticker-value {
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.ticker-unit {
    color: var(--text-muted);
    font-size: 0.7rem;
}

.ticker-change {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 600;
}

.ticker-change.positive { color: var(--positive); }
.ticker-change.negative { color: var(--negative); }

.ticker-divider {
    color: var(--border-accent);
    padding: 0 6px;
    font-size: 0.7rem;
}

/* === Dashboard Grid === */
.dashboard-grid {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr var(--sidebar-right-width);
    height: calc(100vh - var(--header-height));
    overflow: hidden;
}

/* === Sidebar === */
.sidebar {
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-accent) transparent;
}

.sidebar-right {
    border-right: none;
    border-left: 1px solid var(--border-subtle);
}

.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--border-accent);
    border-radius: 2px;
}

.sidebar-section {
    padding: 16px;
    border-bottom: 1px solid var(--border-subtle);
}

.sidebar-title {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.indicator {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
}

.indicator.positive { background: var(--positive); }
.indicator.negative { background: var(--negative); }

/* === Accordion === */
.accordion-section {
    cursor: pointer;
}

.accordion-section:not(.active):hover {
    background: var(--bg-card);
}

.accordion-toggle {
    user-select: none;
    transition: color 0.2s;
}

.accordion-toggle:hover {
    color: var(--text-secondary);
}

.accordion-arrow {
    margin-left: auto;
    font-size: 0.65rem;
    color: var(--text-muted);
    transition: transform 0.25s;
}

.accordion-section.active .accordion-arrow {
    transform: rotate(180deg);
}

.accordion-section.active .sidebar-title {
    color: var(--accent);
}

.accordion-body {
    overflow: hidden;
}

/* === Rankings === */
.ranking-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ranking-item {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s;
}

.ranking-item:hover,
.ranking-item.active {
    background: var(--bg-card-hover);
}

.ranking-item.active {
    border-left: 2px solid var(--accent);
    padding-left: 6px;
}

.ranking-rank {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--text-muted);
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.ranking-name {
    flex: 1;
    font-size: 0.8rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ranking-value {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 600;
    flex-shrink: 0;
}

.ranking-value.positive { color: var(--positive); }
.ranking-value.negative { color: var(--negative); }

/* === Main Content === */
.main-content {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background: var(--bg-base);
}

/* === Map === */
.map-container {
    flex: 1;
    min-height: 400px;
    position: relative;
}

.map-wrapper {
    width: 100%;
    height: 100%;
    position: relative;
}

#map-svg {
    width: 100%;
    height: 100%;
    display: block;
}

#map-svg path.prefecture {
    cursor: pointer;
    transition: opacity 0.15s;
}

#map-svg path.prefecture:hover {
    opacity: 0.8;
    stroke: var(--accent);
    stroke-width: 1.5;
}

#map-svg path.municipality {
    cursor: pointer;
}

#map-svg path.municipality:hover {
    opacity: 0.8;
    stroke: #fff;
    stroke-width: 0.5;
}

.map-controls {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    z-index: 10;
    pointer-events: none;
}

.map-controls > * {
    pointer-events: auto;
}

.map-btn {
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border-accent);
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all 0.15s;
}

.map-btn:hover {
    background: var(--bg-card-hover);
    color: var(--accent);
    border-color: var(--accent);
}

.map-legend {
    background: rgba(13, 21, 32, 0.9);
    padding: 8px 12px;
    border-radius: 4px;
    border: 1px solid var(--border-subtle);
}

.legend-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    display: block;
    margin-bottom: 4px;
}

.legend-bar {
    width: 120px;
    height: 8px;
    border-radius: 2px;
    background: linear-gradient(to right, #440154, #31688e, #35b779, #fde725);
}

.legend-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 2px;
}

.legend-labels span {
    font-size: 0.6rem;
    font-family: var(--font-mono);
    color: var(--text-muted);
}

.map-tooltip {
    position: absolute;
    background: var(--bg-card);
    border: 1px solid var(--border-accent);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    pointer-events: none;
    z-index: 20;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.map-tooltip .tt-name {
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.map-tooltip .tt-value {
    font-family: var(--font-mono);
    font-size: 0.75rem;
}

/* === Prefecture Select (Mobile) === */
.prefecture-select-wrapper {
    padding: 16px;
}

.form-select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-accent);
    border-radius: 6px;
    font-family: var(--font-sans);
    font-size: 1rem;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    cursor: pointer;
}

.form-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-dim);
}

/* === Detail Panel (Right Sidebar) === */
.detail-panel {
    padding: 16px;
}

.detail-header {
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-subtle);
}

.detail-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.detail-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
    display: block;
}

.chart-section {
    margin-bottom: 20px;
}

.chart-title {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.chart-container {
    height: 160px;
    position: relative;
    background: var(--bg-card);
    border-radius: 6px;
    padding: 8px;
    border: 1px solid var(--border-subtle);
}

.chart-container-tall {
    height: 240px;
}

.chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

/* === Metric Cards === */
.metric-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1px;
    background: var(--border-subtle);
    border-top: 1px solid var(--border-subtle);
}

.metric-card {
    background: var(--bg-surface);
    padding: 12px 16px;
}

.metric-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.metric-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.metric-unit {
    font-size: 0.65rem;
    color: var(--text-muted);
}

.metric-change {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 600;
}

.metric-change.positive { color: var(--positive); }
.metric-change.negative { color: var(--negative); }

.metric-value {
    font-family: var(--font-mono);
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.sparkline-container {
    margin-top: 6px;
    height: 30px;
}

/* === Responsive === */
.desktop-only { display: block; }
.mobile-only { display: none; }

@media (max-width: 1200px) {
    :root {
        --sidebar-width: 240px;
        --sidebar-right-width: 300px;
    }
}

@media (max-width: 960px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
        height: auto;
    }

    .sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border-subtle);
    }

    .sidebar-right {
        border-left: none;
        border-top: 1px solid var(--border-subtle);
    }

    .sidebar-left {
        order: 2;
    }

    .main-content {
        order: 1;
    }

    .sidebar-right {
        order: 3;
    }

    .desktop-only { display: none !important; }
    .mobile-only { display: block !important; }

    .metric-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .sidebar-section {
        padding: 12px;
    }

    .ranking-list {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 2px;
    }
}

@media (max-width: 480px) {
    .metric-cards {
        grid-template-columns: 1fr 1fr;
    }

    .header-top {
        padding: 6px 12px;
    }

    .logo {
        font-size: 1rem;
    }
}

/* === Prefecture Detail Page === */
.page-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-surface);
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.breadcrumb {
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.breadcrumb a {
    color: var(--accent);
}

.breadcrumb a:hover {
    text-decoration: underline;
}

.breadcrumb-sep {
    color: var(--text-muted);
}

.data-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
    padding: 20px;
}

.data-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 16px;
}

.data-card-title {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 6px 8px;
    text-align: left;
    font-size: 0.8rem;
    border-bottom: 1px solid var(--border-subtle);
}

.data-table th {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.7rem;
    text-transform: uppercase;
}

.data-table td {
    font-family: var(--font-mono);
    color: var(--text-secondary);
}

.municipality-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 4px;
    padding: 20px;
}

.municipality-link {
    display: block;
    padding: 8px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 4px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    transition: all 0.15s;
}

.municipality-link:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent);
    color: var(--accent);
}

/* === Loading states === */
.loading-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    height: 100%;
}

@keyframes pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

.loading-dot {
    animation: pulse 1.5s infinite;
}

/* === Municipality Info Modal === */
.muni-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.muni-modal-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.muni-modal {
    background: var(--bg-surface);
    border: 1px solid var(--border-accent);
    border-radius: 12px;
    padding: 0;
    width: 420px;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    transform: translateY(20px);
    transition: transform 0.25s;
}

.muni-modal-overlay.show .muni-modal {
    transform: translateY(0);
}

.muni-modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.muni-modal-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.muni-modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.15s;
}

.muni-modal-close:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.muni-modal-body {
    padding: 16px 20px;
}

.muni-stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.muni-stat-item {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 12px;
}

.muni-stat-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.muni-stat-value {
    font-family: var(--font-mono);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.muni-stat-unit {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-left: 2px;
}

.muni-stat-change {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 600;
    margin-top: 2px;
}

.muni-stat-change.positive { color: var(--positive); }
.muni-stat-change.negative { color: var(--negative); }

.muni-modal-link {
    display: block;
    text-align: center;
    padding: 10px;
    margin: 16px 20px;
    background: var(--accent-dim);
    border: 1px solid var(--accent);
    border-radius: 6px;
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.15s;
}

.muni-modal-link:hover {
    background: var(--accent);
    color: var(--bg-base);
}

/* === Real-time Animations === */
@keyframes value-flash {
    0% { color: var(--text-primary); }
    25% { color: var(--accent); }
    100% { color: var(--text-primary); }
}

.value-updating {
    animation: value-flash 0.8s ease-out;
}

@keyframes map-pulse {
    0% { stroke-width: 0.5; opacity: 1; }
    50% { stroke-width: 2.5; opacity: 0.8; }
    100% { stroke-width: 0.5; opacity: 1; }
}

.prefecture-highlight {
    animation: map-pulse 1.5s ease-in-out;
}

.live-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.65rem;
    color: var(--accent);
    font-family: var(--font-mono);
}

.live-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    animation: pulse 2s infinite;
}

.ticker-value.flash-update {
    animation: value-flash 0.8s ease-out;
}

.random-stat-bar {
    padding: 8px 16px;
    background: var(--bg-card);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    overflow: hidden;
}

.random-stat-bar .stat-label {
    color: var(--text-muted);
    white-space: nowrap;
}

.random-stat-bar .stat-value {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--accent);
    white-space: nowrap;
}

@keyframes slide-in-right {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.stat-slide-in {
    animation: slide-in-right 0.4s ease-out;
}

/* === Ad Slots === */
.ad-slot {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    min-height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.ad-slot ins {
    width: 100%;
}

.ad-slot-sidebar {
    margin: 8px 12px;
    border-radius: 6px;
    min-height: 250px;
}

.ad-slot-content {
    margin: 0;
    border-left: none;
    border-right: none;
    min-height: 90px;
}

/* Block AdSense anchor/overlay ads (top/bottom sticky) */
ins.adsbygoogle[data-anchor-status],
ins.adsbygoogle[data-ad-format="autorelaxed"],
div[id^="google_ads_iframe"][style*="position: fixed"],
div[id^="aswift_"][style*="position: fixed"] {
    display: none !important;
    height: 0 !important;
    max-height: 0 !important;
    overflow: hidden !important;
}

@media (max-width: 960px) {
    .ad-slot-sidebar {
        min-height: 100px;
        margin: 8px;
    }
}

/* Share Buttons */
.share-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 12px 20px 0;
}

.share-label {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.share-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s;
}

.share-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-dim);
}

.share-btn-x:hover { color: #fff; border-color: #fff; background: rgba(255,255,255,0.08); }
.share-btn-fb:hover { color: #1877f2; border-color: #1877f2; background: rgba(24,119,242,0.08); }
.share-btn-line:hover { color: #06c755; border-color: #06c755; background: rgba(6,199,85,0.08); }
.share-btn-hatena:hover { color: #00a4de; border-color: #00a4de; background: rgba(0,164,222,0.08); }

/* Site Footer */
.site-footer {
    text-align: center;
    padding: 16px 20px;
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-surface);
}

.site-footer p {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.6;
}

.site-footer a {
    color: var(--text-secondary);
    text-decoration: none;
}

.site-footer a:hover {
    color: var(--accent);
}
