/* ============================================
   Global Mobile Optimization Styles
   全ページ共通のスマホ最適化CSS
   ============================================ */

/* --- ダブルタップによるズームを無効化 --- */
html {
    touch-action: manipulation;
}

/* --- ベースのモバイル最適化 --- */
@media (max-width: 768px) {
    /* コンテナのパディング調整 */
    .content-wrapper {
        padding: 12px 8px;
    }

    .container {
        padding-left: 10px;
        padding-right: 10px;
    }

    /* テーブルを横スクロール可能に */
    .table-responsive-auto {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table:not(.no-mobile-scroll) {
        min-width: auto;
    }

    /* フォーム要素の最適化 */
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="url"],
    input[type="search"],
    input[type="date"],
    input[type="datetime-local"],
    select,
    textarea {
        font-size: 16px !important; /* iOS zoom防止 */
    }

    /* フレックスのラップ強制 */
    .d-flex:not(.flex-nowrap-mobile) {
        flex-wrap: wrap;
    }

    /* ボタングループの最適化 */
    .btn-group-mobile-stack {
        flex-direction: column;
        width: 100%;
    }
    .btn-group-mobile-stack .btn {
        width: 100%;
    }

    /* カード内パディング削減 */
    .card-body {
        padding: 12px;
    }

    /* h1-h3 フォントサイズ調整 */
    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.3rem; }
    h3 { font-size: 1.15rem; }

    /* max-width制限のあるコンテナを全幅に */
    [style*="max-width: 1200px"],
    [style*="max-width: 1100px"],
    [style*="max-width: 1000px"],
    [style*="max-width:1200px"],
    [style*="max-width:1100px"],
    [style*="max-width:1000px"],
    [style*="max-width:960px"],
    [style*="max-width:1600px"],
    [style*="max-width: 960px"],
    [style*="max-width: 900px"],
    [style*="max-width:900px"] {
        max-width: 100% !important;
        padding-left: 8px !important;
        padding-right: 8px !important;
    }

    /* stickyをモバイルで解除 */
    .sticky-top {
        position: static !important;
    }

    /* 固定幅入力の解除 */
    input[style*="width: 150px"],
    input[style*="width:150px"],
    input[style*="width: 220px"],
    input[style*="width:220px"],
    input[style*="min-width: 250px"],
    input[style*="min-width:250px"],
    input[style*="min-width: 300px"],
    input[style*="min-width:300px"] {
        width: 100% !important;
        min-width: 0 !important;
    }

    /* 固定高さのログエリア調整 */
    [style*="height:350px"],
    [style*="height: 350px"],
    [style*="height:400px"],
    [style*="height: 400px"] {
        height: 200px !important;
    }

    /* グリッドレイアウトの調整（価格比較フォト表示 #result-photo / ビューアフォト #viewer-photo / ビューアグリッド #viewer-grid は 3 列を維持するため除外） */
    .row:not(#result-photo):not(#viewer-photo):not(#viewer-grid) > [class*="col-lg-"],
    .row:not(#result-photo):not(#viewer-photo):not(#viewer-grid) > [class*="col-xl-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* フラッシュメッセージ */
    #flash-message {
        font-size: 0.85rem;
        padding: 8px 12px;
    }

    /* input-group のモバイル対応 */
    .input-group {
        flex-wrap: wrap;
    }

    /* モーダルのモバイル対応 */
    .modal-dialog {
        margin: 8px;
        max-width: calc(100vw - 16px);
    }

    /* ページネーションの調整 */
    .pagination {
        flex-wrap: wrap;
        gap: 2px;
    }

    .pagination .page-link {
        padding: 6px 10px;
        font-size: 0.85rem;
    }

    /* 横スクロールヒント */
    .table-responsive::after {
        content: '';
        display: block;
    }

    /* リンクの長いURL対策 */
    a {
        word-break: break-word;
    }

    /* pre/code要素のオーバーフロー対策 */
    pre, code {
        word-break: break-all;
        white-space: pre-wrap;
    }

    /* アラートのパディング調整 */
    .alert {
        padding: 10px 12px;
        font-size: 0.9rem;
    }

    /* col-md-* もモバイルでフル幅に */
    .row > .col-md-5,
    .row > .col-md-7,
    .row > .col-md-8,
    .row > .col-md-4 {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

/* --- 小さいスマホ (480px以下) --- */
@media (max-width: 480px) {
    .content-wrapper {
        padding: 8px 4px;
    }

    .card-body {
        padding: 8px;
    }

    /* テーブルのフォントサイズ縮小 */
    table {
        font-size: 0.8rem;
    }

    table th,
    table td {
        padding: 6px 4px;
    }

    /* ボタン間隔調整 */
    .btn {
        padding: 6px 10px;
        font-size: 0.85rem;
    }

    .btn-sm {
        padding: 4px 8px;
        font-size: 0.75rem;
    }

    /* バッジサイズ */
    .badge {
        font-size: 0.7rem;
    }

    h1 { font-size: 1.3rem; }
    h2 { font-size: 1.15rem; }
    h3 { font-size: 1.05rem; }
}

/* --- アクセス履歴カード（モバイル） --- */
@media (max-width: 768px) {
    .access-log-card {
        border-left: 3px solid #dee2e6;
    }

    .access-log-card .badge {
        font-size: 0.65rem;
    }
}

/* --- タブレット (769px - 1024px) --- */
@media (min-width: 769px) and (max-width: 1024px) {
    .content-wrapper {
        padding: 16px 12px;
    }
}
