/* ==========================================================================
   1. Reset & Base Layout
   ========================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    font-family: sans-serif;
    overflow: hidden;
    overscroll-behavior: none;
}

#appHeaderBar,
#controls,
footer {
    flex: none;
}

/* --------------------------------------------------------------------------
   Header Bar (タイトル & ログインボタンの位置揃え)
   -------------------------------------------------------------------------- */
#appHeaderBar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    background-color: #ffffff;
    border-bottom: 1px solid #e0e0e0;
}

#appHeaderBar .app-title,
#appHeaderBar h1 {
    margin: 0;
    font-size: 18px;
    font-weight: bold;
    color: #212529;
}

#appHeaderBar .btn-login,
#appHeaderBar a.btn-primary,
#appHeaderBar button.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 5px 14px;
    font-size: 13px;
    font-weight: bold;
    color: white;
    background-color: #007bff;
    border-radius: 4px;
    text-decoration: none;
    white-space: nowrap;
    margin: 0;
}

.main-content {
    display: grid;
    grid-template-columns: 1fr minmax(480px, 680px);
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* ==========================================================================
   2. Filter UI (Collapsible)
   ========================================================================== */
#controls.filter-container {
    background: #ffffff;
    border-bottom: 1px solid #ccc;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    z-index: 100;
}

.filter-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 6px 10px;
    background: #f1f3f5;
    cursor: pointer;
    border-bottom: 1px solid #e0e0e0;
    gap: 8px;
}

.filter-summary-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    flex-grow: 1;
}

.filter-summary-label {
    font-size: 11px;
    font-weight: bold;
    color: #495057;
    white-space: nowrap;
    padding-top: 3px;
}

.filter-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
    flex-grow: 1;
}

.summary-chip {
    background: #007bff;
    color: #ffffff;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 12px;
    white-space: nowrap;
}

.toggle-filter-btn {
    background: #495057;
    color: #ffffff;
    border: none;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 11px;
    cursor: pointer;
    flex-shrink: 0;
    white-space: nowrap;
    margin-top: 1px;
}

.toggle-filter-btn:hover {
    background: #343a40;
}

.filter-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out, padding 0.3s ease;
    padding: 0 10px;
}

.filter-body.open {
    max-height: 1000px;
    padding: 8px 10px 4px 10px;
    overflow-y: auto;
}

.filter-row {
    display: flex;
    align-items: center;
    margin-bottom: 4px;
}

.filter-row label {
    width: 110px;
    font-size: 13px;
    font-weight: bold;
    color: #333;
    flex-shrink: 0;
}

.filter-control-inline {
    display: flex;
    gap: 8px;
    flex-grow: 1;
    min-width: 0;
}

.filter-row select,
.filter-row input[type="text"],
.filter-row .multiselect-dropdown {
    width: 100%;
    flex-grow: 1;
    font-size: 13px;
    box-sizing: border-box;
    min-width: 0;
}

.filter-row select,
.filter-row input[type="text"] {
    padding: 3px 6px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background-color: #fff;
    height: 28px;
}

.filter-row button.btn-move,
.filter-row .btn-move {
    white-space: nowrap !important;
    padding: 0 10px;
    font-size: 12px;
    flex-shrink: 0;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ==========================================================================
   2.3 Search Buttons
   ========================================================================== */
.search-action-group {
    display: flex;
    gap: 8px;
    padding: 6px 10px;
    background: #ffffff;
    border-top: 1px solid #e0e0e0;
    width: 100%;
    align-items: center;
}

.btn-primary {
    flex: 3;
    background-color: #007bff;
    color: white;
    border: none;
    padding: 6px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    font-size: 13px;
}

.btn-primary:hover {
    background-color: #0056b3;
}

.btn-reset {
    flex: 2;
    background-color: #6c757d;
    color: white;
    border: none;
    padding: 6px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.btn-reset:hover {
    background-color: #5a6268;
}

.btn-reset:active,
.btn-reset:focus {
    background-color: #6c757d !important;
    outline: none;
}

/* ==========================================================================
   2.4 Multi-select Dropdown
   ========================================================================== */
.multiselect-dropdown {
    position: relative;
    text-align: left;
}

.select-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 6px;
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
    height: 28px;
    font-size: 13px;
}

.select-box .selected-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex-grow: 1;
    display: flex;
    align-items: center;
    height: 100%;
}

.select-box .arrow {
    font-size: 9px;
    color: #555;
    margin-left: 6px;
    transition: transform 0.2s ease;
}

.multiselect-dropdown.open .arrow {
    transform: rotate(180deg);
}

.checkboxes {
    display: none;
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    width: 100%;
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 0 0 4px 4px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.15);
}

.multiselect-dropdown.open .checkboxes {
    display: block;
}

.checkboxes label {
    display: flex;
    align-items: center;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}

.checkboxes label:hover {
    background-color: #f0f0f0;
}

.checkboxes input[type="checkbox"] {
    margin-right: 8px;
    width: 14px;
    height: 14px;
    cursor: pointer;
}

/* ==========================================================================
   3. Map Area
   ========================================================================== */
#map {
    width: 100%;
    height: 100%;
}

/* ==========================================================================
   4. Store Table (CSS Grid)
   ========================================================================== */
#storeTable {
    height: 100%;
    overflow: auto;
    background: #fafafa;
    padding: 0;
    border-right: 1px solid #ccc;
    position: relative;
    z-index: 1;
    width: 100%;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-x pan-y;
    isolation: isolate;
}

.table-header-row,
.store-row {
    display: grid;
    grid-template-columns: 90px 140px 95px 75px 45px 45px 230px;
    width: 920px;
}

.table-header-row {
    position: sticky;
    top: 0;
    z-index: 50;
    background: #e0ecff;
    font-weight: bold;
    color: #222;
    border-bottom: 2px solid #7aa6d9;
    box-shadow: 0 2px 3px rgba(0,0,0,0.1);
    transform: translateZ(0);
}

.table-header-row .col {
    padding: 3px 2px;
    min-height: 36px;
    height: auto;
    font-size: 12px;
    line-height: 1.15;
    text-align: left;
    border-right: 1px solid #ddd;
    display: flex;
    align-items: flex-start;
    white-space: normal;
    word-break: break-all;
}

#storeTable .col {
    padding: 4px 2px;
    border: 1px solid #ddd;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
}

.col-1 {
    position: sticky;
    left: 0;
    z-index: 20;
    background: #ffffff;
    transform: translateZ(0);
}

.col-2 {
    position: sticky;
    left: 90px;
    z-index: 20;
    background: #ffffff;
    box-shadow: 2px 0 5px -1px rgba(0,0,0,0.15);
    transform: translateZ(0);
}

.table-header-row .col-1,
.table-header-row .col-2 {
    z-index: 60;
    background: #e0ecff !important;
}

.store-row:nth-child(even) .col { background: #ffffff; }
.store-row:nth-child(odd) .col { background: #f5f5f5; }
.store-row:nth-child(even) .col-1,
.store-row:nth-child(even) .col-2 { background: #ffffff; }
.store-row:nth-child(odd) .col-1,
.store-row:nth-child(odd) .col-2 { background: #f5f5f5; }

.store-row:hover .col { background: #e6f3ff !important; }
.store-row.selected-row .col { background-color: #ffe4b5 !important; }
.store-row.selected-row .col-1,
.store-row.selected-row .col-2 { background-color: #ffe4b5 !important; }

.col-5 { text-align: right; padding-right: 6px; }

.no-results-message,
#storeTable .no-data {
    text-align: left !important;
    padding-left: 8px;
}

/* ==========================================================================
   5. Leaflet Popup
   ========================================================================== */
.leaflet-popup-content-wrapper {
    font-size: 11px;
    line-height: 1.4;
    color: #333;
    border-radius: 6px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.15);
}

.leaflet-popup-content {
    margin: 10px 12px;
}

.leaflet-popup-content b,
.leaflet-popup-content strong {
    font-size: 13px;
    margin-bottom: 4px;
    color: #111;
}

/* ==========================================================================
   6. Footer (1行維持 ＆ コンパクト化)
   ========================================================================== */
footer {
    padding: 2px 4px;
    padding-bottom: calc(2px + env(safe-area-inset-bottom));
    font-size: 10px;
    text-align: center;
    color: #666;
    background-color: #ffffff;
    border-top: 1px solid #e0e0e0;
    white-space: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
    z-index: 100;
    flex-shrink: 0;
}

footer a {
    color: #007bff;
    text-decoration: none;
    margin: 0 4px;
    padding: 2px 4px;
    display: inline-block;
    font-weight: 500;
}

footer a:hover {
    text-decoration: underline;
}

/* ==========================================================================
   7. Mobile Optimization
   ========================================================================== */
@media (max-width: 768px) {

    body {
        overflow: hidden;
        overscroll-behavior: none;
        height: 100dvh;
    }

    .main-content {
        display: flex;
        flex-direction: column;
        flex: 1;
        min-height: 0;
        overflow: hidden;
    }

    #map {
        height: 260px;
        flex: none;
    }

    #storeTable {
        flex: 1;
        height: 0;
        border-top: 2px solid #ccc;
        border-right: none;
        overflow: auto;
        width: 100%;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        touch-action: pan-x pan-y;
        isolation: isolate;
    }

    #storeTable .table-header-row .col {
        padding: 2px 1px !important;
        font-size: 10px !important;
        line-height: 1.1;
        min-height: 32px;
        align-items: flex-start !important;
    }

    #storeTable .table-header-row,
    #storeTable .store-row {
        grid-template-columns: 85px 85px 70px 60px 40px 40px 210px;
        width: 590px;
        font-size: 11px;
    }

    /* 1・2列目の固定（sticky）を維持 */
    #storeTable .col-1 { 
        position: sticky !important;
        left: 0 !important; 
        z-index: 20;
        transform: translateZ(0);
    }
    #storeTable .col-2 { 
        position: sticky !important;
        left: 85px !important;
        z-index: 20;
        transform: translateZ(0);
    }
    #storeTable .table-header-row .col-1,
    #storeTable .table-header-row .col-2 {
        z-index: 60;
        background: #e0ecff !important;
    }

    .filter-row label {
        width: 85px;
        font-size: 11px;
    }

    .filter-row select,
    .filter-row input[type="text"] {
        font-size: 12px;
    }

    .select-box,
    .select-box .selected-text,
    .checkboxes label {
        font-size: 12px !important;
    }

    .checkboxes {
        position: absolute !important;
        top: calc(100% + 2px) !important;
        left: 0 !important;
        width: 100% !important;
        z-index: 1000 !important;
    }

    /* フッターを1行に維持しつつ、iOS等のホームインジケータ（下部バー）と重ならない最小限のセーフエリア確保 */
    footer {
        padding: 2px 4px;
        padding-bottom: calc(6px + env(safe-area-inset-bottom)) !important;
        font-size: 10px;
        white-space: nowrap;
        overflow-x: auto;
    }

    footer a {
        margin: 0 2px;
        padding: 2px 4px;
        font-size: 10px;
    }
}