/* ========================================
   レスポンシブ: 全メディアクエリ
   ======================================== */

/* ---- モバイル専用要素（デスクトップ非表示） ---- */
.sp-only-br {
    display: none;
}
.guide-text-sp {
    display: none;
}

/* ---- モバイルメニュー（デスクトップ非表示） ---- */
.mobile-menu-btn {
    display: none;
}

.mobile-nav-overlay {
    display: none;
}

.mobile-nav-overlay.hidden {
    display: none;
}

/* ---- タブレット (1024px) ---- */
@media (max-width: 1024px) {
    .mobile-menu-btn {
        display: block;
        background: none;
        border: none;
        color: #fff;
        font-size: 26px;
        cursor: pointer;
        padding: 4px 8px;
        line-height: 1;
        order: 10;
    }

    .mobile-menu-btn:hover {
        opacity: 0.8;
    }

    .side-nav {
        display: none;
    }

    .side-nav.side-nav-open {
        display: block !important;
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 240px;
        z-index: 200;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
        overflow-y: auto;
        padding-top: 16px;
    }

    .mobile-nav-overlay:not(.hidden) {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 199;
    }

    .header {
        padding: 20px 24px;
    }

    .main-content {
        padding: 20px;
    }

    .filter-grid {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    }

    .section-card {
        padding: 20px;
    }

    .compare-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }
}

/* ---- スマホ横・タブレット縦 (768px) ---- */
@media (max-width: 768px) {
    .header {
        padding: 16px 16px;
        flex-direction: column;
        text-align: center;
        gap: 10px;
    }

    .header-title {
        font-size: 18px;
    }

    .header-right {
        width: 100%;
        justify-content: center;
    }

    .main-content {
        padding: 12px;
    }

    .filter-panel {
        padding: 16px;
    }

    .filter-grid {
        grid-template-columns: 1fr;
    }

    .filter-item-wide {
        grid-column: span 1;
        padding: 8px 0 16px 0;
    }

    .filter-actions {
        flex-direction: column;
    }

    .filter-actions .fetch-button {
        width: 100%;
    }

    .section-actions {
        flex-direction: column;
    }

    .section-actions .fetch-button,
    .section-actions .export-button {
        width: 100%;
    }

    .heatmap-mode-row {
        flex-direction: column;
        align-items: stretch;
    }

    .heatmap-mode-row .fetch-button {
        width: 100%;
    }

    /* --- チャート: 1列化 + コンテナ調整 --- */
    .charts-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .chart-card {
        padding: 12px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Plotlyグラフのコンテナをレスポンシブに（横軸タイトル表示のため高さを確保） */
    .chart-card .dash-graph {
        min-height: 430px;
    }

    .chart-card .js-plotly-plot,
    .chart-card .plotly,
    .chart-card .dash-graph {
        width: 100% !important;
    }

    .chart-card .js-plotly-plot .plotly .main-svg {
        width: 100% !important;
        overflow: hidden;
    }

    /* ランキングテーブル: 横スクロール対応 */
    .chart-card .alert-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        font-size: 12px;
    }

    .chart-card .alert-table th,
    .chart-card .alert-table td {
        padding: 8px 10px;
        white-space: nowrap;
    }

    .stat-cards-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .stat-card {
        padding: 14px 10px;
    }

    .card-value {
        font-size: 18px;
    }

    .sim-container {
        flex-direction: column;
    }

    .sim-form {
        grid-template-columns: 1fr;
    }

    .sim-results {
        min-width: 0;
        width: 100%;
    }

    .loan-container {
        flex-direction: column;
    }

    .loan-form {
        grid-template-columns: 1fr;
    }

    .loan-results {
        min-width: 0;
        width: 100%;
    }

    .compare-grid {
        grid-template-columns: 1fr;
    }

    .alert-form {
        grid-template-columns: 1fr;
    }

    .alert-results {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .alert-table {
        min-width: 500px;
    }

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

    .hazard-links {
        flex-direction: column;
    }

    .hazard-link-button {
        text-align: center;
    }

    .section-card {
        padding: 16px;
    }

    .section-title {
        font-size: 16px;
    }

    /* --- データテーブル: スクロール対応 --- */
    .table-section {
        padding: 12px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table-section .dash-spreadsheet-container {
        overflow-x: auto !important;
    }

    .table-section .dash-table-container {
        overflow-x: auto !important;
    }

    /* Dash DataTableセルを縮小 */
    .table-section .dash-cell {
        font-size: 12px !important;
        padding: 6px 8px !important;
    }

    .table-section .dash-header {
        font-size: 11px !important;
        padding: 8px !important;
    }

    .modal-content {
        width: 95%;
        max-height: 85vh;
    }

    .modal-header {
        padding: 16px;
    }

    .modal-body {
        padding: 16px;
    }

    .pdf-export-row {
        justify-content: stretch;
    }

    .pdf-export-row .fetch-button {
        width: 100%;
    }

    .bookmark-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .loan-method-group {
        flex-wrap: wrap;
        gap: 10px;
    }

    /* --- 地図コンテナ: モバイル最適化 --- */
    .map-container {
        min-height: 350px;
    }

    .leaflet-container {
        touch-action: pan-x pan-y;
    }

    /* --- ウェルカムガイド: 1列化 --- */
    .guide-steps {
        flex-direction: column;
    }

    .guide-step {
        min-width: auto;
    }

    .guide-arrow {
        display: none;
    }
}

/* ---- 小型スマホ (480px) ---- */
@media (max-width: 480px) {
    .header {
        padding: 12px;
    }

    .header-title {
        font-size: 16px;
    }

    .header-subtitle {
        display: none;
    }

    .data-mode-badge {
        font-size: 11px;
        padding: 5px 10px;
    }

    .user-name-badge {
        font-size: 11px;
        padding: 5px 10px;
    }

    .main-content {
        padding: 8px;
    }

    .filter-panel {
        padding: 12px;
        margin-bottom: 16px;
    }

    .filter-title {
        font-size: 14px;
    }

    .price-range-container {
        flex-direction: column;
        align-items: stretch;
    }

    .price-separator {
        text-align: center;
    }

    .stat-cards-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .stat-card {
        padding: 12px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: left;
    }

    .card-label {
        margin-bottom: 0;
        font-size: 11px;
    }

    .card-value {
        font-size: 16px;
    }

    /* --- チャート: 高さ縮小 + パディング最小化 --- */
    .chart-card {
        padding: 8px;
    }

    .chart-title {
        font-size: 13px;
        padding-left: 6px;
        margin-bottom: 8px;
    }

    .charts-row {
        gap: 8px;
        margin-bottom: 8px;
    }

    /* Plotlyグラフの高さをモバイル向けに設定（横軸タイトル表示のため最低限の高さを確保） */
    .chart-card .dash-graph {
        min-height: 380px;
        margin-bottom: 8px;
    }

    .chart-card .js-plotly-plot .plotly .main-svg {
        overflow: hidden;
    }

    .section-card {
        padding: 12px;
        margin-bottom: 16px;
    }

    /* --- モバイル専用要素を表示 --- */
    .sp-only-br {
        display: inline;
    }
    .guide-text-pc {
        display: none;
    }
    .guide-text-sp {
        display: inline;
    }

    /* --- PDF/Excel/共有ボタン: モバイル1行表示 --- */
    .pdf-export-row .export-button {
        font-size: 12px !important;
        padding: 10px 4px !important;
        white-space: nowrap;
    }

    /* --- セクションアクションボタン: モバイル左寄せ --- */
    .section-actions {
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .section-title {
        font-size: 14px;
        margin-bottom: 6px;
    }

    .section-desc {
        font-size: 12px;
    }

    .sim-result-value {
        font-size: 14px;
    }

    .error-toast {
        right: 8px;
        left: 8px;
        max-width: none;
    }

    .hazard-cards-grid {
        grid-template-columns: 1fr;
    }

    .hazard-card p {
        font-size: 16px;
    }

    /* ハザード説明文の改行をモバイルでは非表示 */
    .hazard-card p br {
        display: none;
    }

    /* --- ランキングテーブル: セル縮小 --- */
    .chart-card .alert-table {
        font-size: 11px;
    }

    .chart-card .alert-table th,
    .chart-card .alert-table td {
        padding: 6px 8px;
        font-size: 11px;
    }

    /* --- データテーブル: セル最小化 --- */
    .table-section {
        padding: 8px;
    }

    .table-section .dash-cell {
        font-size: 11px !important;
        padding: 4px 6px !important;
        min-width: 60px !important;
    }

    .table-section .dash-header {
        font-size: 10px !important;
        padding: 6px !important;
    }

    /* ページネーション縮小 */
    .table-section .previous-next-container {
        font-size: 12px;
    }

    .modal-content {
        width: 98%;
        border-radius: var(--radius);
    }

    .modal-header {
        padding: 12px;
    }

    .modal-title {
        font-size: 15px;
    }

    .modal-body {
        padding: 12px;
        font-size: 13px;
    }

    .fetch-button {
        padding: 10px 20px;
        font-size: 13px;
    }

    .export-button {
        width: 100%;
        text-align: center;
    }

    .bookmark-save-button {
        width: 100%;
        text-align: center;
    }

    .bookmark-delete-button {
        width: 100%;
        text-align: center;
    }

    /* --- 履歴テーブル: モバイル対応 --- */
    .history-table {
        font-size: 11px;
    }

    .history-table th,
    .history-table td {
        padding: 6px 8px;
    }

    /* --- 分析履歴アクション行: モバイル折り返し --- */
    .history-action-row {
        flex-wrap: wrap !important;
    }

    .history-action-dropdown {
        flex-basis: 100% !important;
        min-width: 0 !important;
        order: 0;
    }

    .history-action-row .fetch-button,
    .history-action-row .export-button {
        flex: 1 1 0% !important;
        overflow: hidden !important;
        padding: 8px 4px !important;
        font-size: 11px !important;
        white-space: nowrap;
        text-align: center;
        order: 1;
    }

    .footer {
        padding: 16px 12px;
        font-size: 11px;
    }

    .map-legend {
        padding: 8px 10px;
        gap: 2px;
        font-size: 11px;
    }

    /* --- ウェルカムガイド: 小画面対応 --- */
    .welcome-guide {
        padding: 16px;
    }

    .guide-step-text {
        font-size: 13px;
    }
}
