/* ===================================
   モバイル専用スタイル
   携帯電話用UI最適化
   =================================== */

/* モバイル用のグローバル調整 */
@media (max-width: 768px) {
    
    /* タッチ操作の最適化 */
    * {
        -webkit-tap-highlight-color: rgba(102, 126, 234, 0.2);
        touch-action: manipulation;
    }

    body {
        font-size: 16px; /* iOS Safariのズーム防止 */
        overflow-x: hidden;
    }

    .container {
        width: 100%;
        min-height: 100vh;
        display: flex;
        flex-direction: column;
    }

    /* ===================================
       モバイルヘッダー - コンパクト化
       =================================== */
    .header {
        padding: 0.75rem 1rem;
        position: sticky;
        top: 0;
        z-index: 1000;
    }

    .header-top {
        flex-direction: column;
        gap: 0.75rem;
        align-items: flex-start;
        margin-bottom: 0.75rem;
    }

    .logo-section {
        flex-direction: row;
        align-items: center;
        gap: 0.75rem;
        width: 100%;
        justify-content: space-between;
    }

    .logo {
        height: 45px;
        padding: 3px;
    }

    .title-group h1 {
        font-size: 1.1rem;
    }

    .title-group h1 i {
        font-size: 1rem;
    }

    .subtitle {
        font-size: 0.75rem;
        display: none; /* モバイルでは非表示 */
    }

    .sync-status {
        padding: 0.35rem 0.75rem;
        font-size: 0.75rem;
        border-radius: 15px;
    }

    /* 統計バー - 2列レイアウト */
    .stats-bar {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
        padding-top: 0.75rem;
        border-top: 1px solid rgba(255, 255, 255, 0.2);
    }

    .stat-item {
        font-size: 0.8rem;
        justify-content: center;
        text-align: center;
        flex-direction: column;
        gap: 0.25rem;
    }

    .stat-item i {
        font-size: 1rem;
    }

    .stat-item strong {
        font-size: 1.2rem;
    }

    /* ===================================
       モバイルレイアウト - タブ切り替え
       =================================== */
    .main-content {
        display: flex;
        flex-direction: column;
        width: 100%;
        height: auto;
        position: relative;
    }

    /* サイドバーをボトムシートに変更 */
    .sidebar {
        width: 100vw;
        max-height: none;
        height: auto;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
        z-index: 900;
        transform: translateY(calc(100% - 70px)); /* 一部だけ表示 */
        transition: transform 0.3s ease;
        padding: 0;
        overflow: hidden;
    }

    .sidebar.expanded {
        transform: translateY(0);
        max-height: 70vh;
        overflow-y: auto;
    }

    /* サイドバー開閉ハンドル */
    .sidebar::before {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        background: #ddd;
        border-radius: 2px;
        margin: 10px auto;
        cursor: pointer;
    }

    /* サイドバーヘッダー（タップで開閉） */
    .sidebar-header-mobile {
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        padding: 0.75rem 1rem;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        cursor: pointer;
        border-radius: 20px 20px 0 0;
        user-select: none;
        -webkit-user-select: none;
    }

    .sidebar-header-mobile h2 {
        font-size: 1rem;
        font-weight: 600;
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    .sidebar-header-mobile .toggle-icon {
        font-size: 1.2rem;
        transition: transform 0.3s ease;
    }

    .sidebar.expanded .toggle-icon {
        transform: rotate(180deg);
    }

    /* サイドバーコンテンツ */
    .sidebar-content {
        padding: 1rem;
        max-height: calc(70vh - 70px);
        overflow-y: auto;
    }

    .sidebar-section {
        margin-bottom: 1.5rem;
        padding-bottom: 1.25rem;
    }

    .sidebar-section h3 {
        font-size: 0.95rem;
        margin-bottom: 0.75rem;
    }

    /* マップをフルスクリーン風に */
    .map-wrapper {
        width: 100vw;
        height: 60vh;
        min-height: 500px;
        position: relative;
        order: -1; /* マップを最初に表示 */
    }

    #map {
        width: 100% !important;
        height: 100% !important;
    }

    /* ===================================
       モバイルボタン - タッチしやすく
       =================================== */
    .btn {
        padding: 1rem 1.5rem;
        font-size: 1rem;
        min-height: 48px; /* タッチターゲットサイズ */
    }

    #addPinBtn {
        position: fixed;
        bottom: 90px; /* サイドバーの上 */
        right: 1rem;
        width: auto;
        border-radius: 50px;
        box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
        z-index: 950;
        padding: 1rem 1.5rem;
    }

    #addPinBtn i {
        margin-right: 0.5rem;
    }

    /* ユーザー設定 */
    .user-settings input {
        padding: 0.75rem;
        font-size: 1rem;
    }

    /* フィルターセクション - コンパクト化 */
    .filter-group {
        margin-bottom: 1rem;
    }

    .checkbox-group {
        gap: 0.35rem;
    }

    .checkbox-group label {
        padding: 0.5rem 0.35rem;
        font-size: 0.9rem;
    }

    .checkbox-group input[type="checkbox"] {
        width: 18px;
        height: 18px;
    }

    /* 凡例 - コンパクト表示 */
    .legend {
        font-size: 0.85rem;
    }

    .legend-item {
        padding: 0.35rem;
        margin-bottom: 0.35rem;
    }

    /* ===================================
       モバイルモーダル - フルスクリーン
       =================================== */
    .modal-content {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
        overflow-y: auto;
        animation: slideUpFull 0.3s ease;
    }

    @keyframes slideUpFull {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }

    .modal-header {
        padding: 1rem;
        position: sticky;
        top: 0;
        background: white;
        z-index: 10;
    }

    .modal-header h2 {
        font-size: 1.2rem;
    }

    .close-btn {
        width: 35px;
        height: 35px;
        font-size: 1.5rem;
    }

    /* フォーム要素 */
    form {
        padding: 1rem;
    }

    .form-group {
        margin-bottom: 1.25rem;
    }

    .form-group label {
        font-size: 0.95rem;
        margin-bottom: 0.5rem;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 0.85rem;
        font-size: 16px; /* iOS Safariのズーム防止 */
        border-radius: 8px;
    }

    .form-group select {
        appearance: none;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 0.75rem center;
        padding-right: 2.5rem;
    }

    .modal-footer {
        padding: 1rem;
        position: sticky;
        bottom: 0;
        background: white;
        border-top: 1px solid #e0e0e0;
        display: flex;
        gap: 0.75rem;
    }

    .modal-footer .btn {
        flex: 1;
        min-height: 50px;
    }

    /* ===================================
       モバイルフッター - コンパクト
       =================================== */
    .footer {
        padding: 0.75rem 1rem;
        font-size: 0.8rem;
    }

    .footer strong {
        display: block;
        margin-top: 0.25rem;
    }

    /* ===================================
       モバイル通知 - 上部表示
       =================================== */
    .notification {
        top: 10px;
        right: 10px;
        left: 10px;
        padding: 0.85rem 1rem;
        font-size: 0.9rem;
        border-radius: 10px;
    }

    /* ===================================
       Leafletコントロール - モバイル最適化
       =================================== */
    .leaflet-control-zoom {
        border: none !important;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2) !important;
    }

    .leaflet-control-zoom a {
        width: 40px !important;
        height: 40px !important;
        line-height: 40px !important;
        font-size: 20px !important;
    }

    .leaflet-popup-content-wrapper {
        border-radius: 12px;
    }

    .leaflet-popup-content {
        margin: 0.75rem;
        min-width: 200px;
        font-size: 0.9rem;
    }

    .popup-content h3 {
        font-size: 1.1rem;
        margin-bottom: 0.5rem;
    }

    .popup-content p {
        margin: 0.35rem 0;
        font-size: 0.85rem;
    }

    .popup-delete-btn {
        padding: 0.65rem 1rem;
        font-size: 0.9rem;
        min-height: 44px;
    }

    /* ===================================
       横向き対応
       =================================== */
    @media (orientation: landscape) and (max-height: 500px) {
        .header {
            padding: 0.5rem 1rem;
        }

        .logo {
            height: 35px;
        }

        .title-group h1 {
            font-size: 0.95rem;
        }

        .stats-bar {
            display: none; /* 横向き時は統計を非表示 */
        }

        .sidebar {
            transform: translateY(calc(100% - 50px));
        }

        #addPinBtn {
            bottom: 60px;
            padding: 0.75rem 1.25rem;
        }

        .main-content {
            height: auto;
            min-height: calc(100vh - 100px);
        }

        .map-wrapper {
            height: calc(100vh - 150px);
        }
    }
}

/* ===================================
   小型スマートフォン (iPhone SE等)
   =================================== */
@media (max-width: 375px) {
    .header {
        padding: 0.5rem 0.75rem;
    }

    .logo {
        height: 40px;
    }

    .title-group h1 {
        font-size: 1rem;
    }

    .sync-status {
        font-size: 0.7rem;
        padding: 0.3rem 0.6rem;
    }

    .stats-bar {
        gap: 0.35rem;
    }

    .stat-item {
        font-size: 0.75rem;
    }

    .stat-item strong {
        font-size: 1rem;
    }

    #addPinBtn {
        padding: 0.85rem 1.25rem;
        font-size: 0.9rem;
    }

    .sidebar-section h3 {
        font-size: 0.9rem;
    }

    .checkbox-group label {
        font-size: 0.85rem;
    }
}

/* ===================================
   タブレット縦向き
   =================================== */
@media (min-width: 769px) and (max-width: 1024px) and (orientation: portrait) {
    .sidebar {
        width: 100%;
        max-height: 50vh;
    }

    .map-wrapper {
        height: 50vh;
    }

    #addPinBtn {
        position: absolute;
        bottom: auto;
        top: 1rem;
        right: 1rem;
    }
}

/* ===================================
   スワイプジェスチャーヒント
   =================================== */
@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-5px);
    }
}

.sidebar::after {
    content: '⌃';
    position: absolute;
    top: 5px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.2rem;
    color: #999;
    animation: bounce 2s infinite;
    pointer-events: none;
}

.sidebar.expanded::after {
    content: '⌄';
    animation: none;
}

/* ===================================
   タッチフレンドリーな調整
   =================================== */
@media (hover: none) and (pointer: coarse) {
    /* タッチデバイス専用スタイル */
    
    .btn:active {
        transform: scale(0.95);
    }

    .checkbox-group label:active {
        background: #e8e8e8;
    }

    /* リンクとボタンのタップエリアを大きく */
    a, button, input[type="checkbox"], select {
        min-height: 44px;
        min-width: 44px;
    }
}
