﻿/* ========================================
   モバイル対応スタイル (Index page)
   index.css から分離 - コード変更なし
   ======================================== */

/* === Mobile overhaul (Index page) === */
/* モバイル用トップバーはデスクトップでは非表示 */
.mobile-appbar {
    display: none;
}

.mobile-composer-footer {
    display: none;
}

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

.mobile-hidden {
    display: block;
}

.mobile-sidebar {
    display: none;
}

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

@media (max-width: 1024px) and (min-width: 769px) {
    .mobile-appbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        position: sticky;
        top: 0;
        left: 0;
        right: 0;
        height: 56px;
        padding: 0 16px;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(16px) saturate(160%);
        -webkit-backdrop-filter: blur(16px) saturate(160%);
        z-index: var(--z-appbar);
    }

    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: var(--touch-target-min);
        height: var(--touch-target-min);
        border-radius: 50%;
        border: none;
        background: transparent;
        color: var(--text-color);
        cursor: pointer;
        transition: background 0.2s ease;
    }

    .mobile-menu-btn:hover {
        background: rgba(0, 0, 0, 0.05);
    }

    .mobile-appbar-title {
        font-size: 1.1rem;
        font-weight: 600;
        color: var(--text-color);
        letter-spacing: -0.02em;
    }

    .mobile-ai-model-selector {
        display: none !important;
    }

    .mobile-sidebar {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        max-width: 85vw;
        background: var(--container-bg);
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
        z-index: var(--z-appbar);
        overflow-y: auto;
    }

    .mobile-sidebar.open {
        transform: translateX(0);
    }

    .mobile-sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.4);
        opacity: 0;
        transition: opacity 0.3s ease;
        z-index: var(--z-dropdown);
    }

    .mobile-sidebar-overlay.visible {
        display: block;
        opacity: 1;
    }

    .mobile-sidebar-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 16px;
        border-bottom: 1px solid var(--border-color);
    }

    .mobile-sidebar-title {
        font-size: 1.1rem;
        font-weight: 600;
        color: var(--text-color);
        margin-left: 8px;
    }

    .mobile-sidebar-close {
        width: var(--touch-target-min);
        height: var(--touch-target-min);
        border-radius: 50%;
        border: none;
        background: transparent;
        color: var(--text-color);
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: background 0.2s ease;
    }

    .mobile-sidebar-close:hover {
        background: rgba(0, 0, 0, 0.05);
    }

    .mobile-sidebar-content {
        padding: 8px;
    }

    .mobile-nav-item {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 12px 16px;
        border-radius: 12px;
        color: var(--text-color);
        text-decoration: none;
        font-size: 0.95rem;
        font-weight: 500;
        margin-bottom: 4px;
        transition: background 0.2s ease;
    }

    .mobile-nav-item:hover {
        background: rgba(0, 0, 0, 0.04);
    }

    .mobile-nav-item svg {
        flex-shrink: 0;
        opacity: 0.7;
    }

    .mobile-nav-divider {
        height: 1px;
        background: var(--border-color);
        margin: 12px 8px;
    }
}

@media (max-width: 768px) {
    .mobile-only {
        display: block !important;
    }

    .mobile-hidden {
        display: none !important;
    }

    .mobile-appbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 56px;
        padding: 0 16px;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(20px) saturate(180%);
        -webkit-backdrop-filter: blur(20px) saturate(180%);
        z-index: var(--z-appbar);
    }

    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: var(--touch-target-min);
        height: var(--touch-target-min);
        border-radius: 50%;
        border: none;
        background: transparent;
        color: var(--text-color);
        cursor: pointer;
        transition: background 0.2s ease;
    }

    .mobile-menu-btn:hover {
        background: rgba(0, 0, 0, 0.05);
    }

    .mobile-appbar-title {
        font-size: 1.1rem;
        font-weight: 600;
        color: var(--text-color);
        letter-spacing: -0.02em;
    }

    .mobile-appbar-center {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4px;
    }

    .mobile-ai-model-selector {
        position: relative;
    }

    .mobile-model-btn {
        display: flex;
        align-items: center;
        gap: 4px;
        padding: 4px 10px;
        background: rgba(0, 0, 0, 0.04);
        border: 1px solid rgba(0, 0, 0, 0.08);
        border-radius: 12px;
        font-size: 0.75rem;
        color: var(--subtext-color);
        cursor: pointer;
        transition: all 0.2s ease;
    }

    .mobile-model-text {
        font-weight: 500;
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mobile-model-icon {
        transition: transform 0.2s ease;
    }

    .mobile-model-icon.rotate {
        transform: rotate(180deg);
    }

    .mobile-model-dropdown {
        position: fixed;
        top: 60px;
        left: 50%;
        transform: translateX(-50%);
        width: calc(100vw - 32px);
        max-width: 400px;
        background: var(--container-bg);
        border: 1px solid var(--border-color);
        border-radius: 16px;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
        max-height: 60vh;
        overflow-y: auto;
        z-index: var(--z-modal);
    }

    .mobile-model-option {
        width: 100%;
        padding: 12px 16px;
        border: none;
        background: transparent;
        color: var(--text-color);
        cursor: pointer;
        transition: background 0.2s ease;
        text-align: left;
    }

    .mobile-model-option:hover {
        background: rgba(0, 0, 0, 0.04);
    }

    .mobile-model-option.selected {
        background: rgba(102, 126, 234, 0.08);
    }

    .mobile-sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.4);
        opacity: 0;
        transition: opacity 0.3s ease;
        z-index: var(--z-dropdown);
    }

    .mobile-sidebar-overlay.visible {
        display: block;
        opacity: 1;
    }

    .mobile-sidebar {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        max-width: 85vw;
        background: var(--container-bg);
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
        z-index: var(--z-appbar);
        overflow-y: auto;
    }

    .mobile-sidebar.open {
        transform: translateX(0);
    }

    .mobile-sidebar-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 16px;
        border-bottom: 1px solid var(--border-color);
    }

    .mobile-sidebar-title {
        font-size: 1.1rem;
        font-weight: 600;
        color: var(--text-color);
        margin-left: 8px;
    }

    .mobile-sidebar-close {
        width: var(--touch-target-min);
        height: var(--touch-target-min);
        border-radius: 50%;
        border: none;
        background: transparent;
        color: var(--text-color);
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: background 0.2s ease;
    }

    .mobile-sidebar-close:hover {
        background: rgba(0, 0, 0, 0.05);
    }

    .mobile-sidebar-content {
        padding: 8px;
    }

    .mobile-nav-item {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 12px 16px;
        border-radius: 12px;
        color: var(--text-color);
        text-decoration: none;
        font-size: 0.95rem;
        font-weight: 500;
        margin-bottom: 4px;
        transition: background 0.2s ease;
    }

    .mobile-nav-item:hover {
        background: rgba(0, 0, 0, 0.04);
    }

    .mobile-nav-item svg {
        flex-shrink: 0;
        opacity: 0.7;
    }

    .mobile-nav-divider {
        height: 1px;
        background: var(--border-color);
        margin: 12px 8px;
    }

    .sidebar-nav {
        display: none !important;
    }

    .sidebar-score {
        display: none !important;
    }

    .score-container {
        display: none !important;
    }

    .ad-column {
        display: none !important;
    }

    .input-bottom-bar {
        display: none;
    }

    /* モバイル: 質問入力コンテナとcomposerフッター */
    .mobile-composer-footer {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: flex-start !important;
        gap: 12px;
        margin-top: 12px;
        width: 100%;
        flex-wrap: nowrap;
        /* 1行に収める */
    }

    /* モバイル: 送信ボタン（右端固定） */
    .composer-submit-btn {
        flex: 0 0 auto;
        width: 44px;
        height: 44px;
        border-radius: 50%;
        border: none;
        background: #000000;
        color: #ffffff;
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
        transition: transform 0.15s ease, box-shadow 0.15s ease;
        cursor: pointer;
        margin-left: auto;
        /* 右端に配置 */
        order: 2;
        /* 送信ボタンを後ろに */
    }

    .composer-submit-btn:hover {
        transform: translateY(-1px);
        box-shadow: 0 8px 22px rgba(0, 0, 0, 0.22);
    }

    .composer-submit-btn:active {
        transform: translateY(0);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    }

    .composer-submit-btn:focus-visible {
        outline: 2px solid rgba(102, 126, 234, 0.6);
        outline-offset: 2px;
    }

    .composer-submit-btn svg {
        width: 20px;
        height: 20px;
        color: currentColor;
        stroke: currentColor;
        display: block;
        transform: translateY(1px);
    }

    .main-layout {
        gap: 0;
        padding: 0;
        margin: 56px 0 0 0;
        min-height: calc(100dvh - 56px);
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .content-ad-wrapper {
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .main-content {
        max-width: 100%;
        width: 100%;
        padding: 20px 16px 24px 16px;
        box-shadow: none;
        border: none;
        background: transparent;
    }

    .modern-form {
        margin: 0 auto;
        background: transparent;
        padding: 0;
        max-width: 600px;
        width: 100%;
    }

    .form-section {
        padding: 0;
        margin-bottom: 0;
    }

    /* モバイル: チャットタイプバッジ（横並び） */
    .mobile-chat-type-badges {
        display: flex !important;
        gap: 10px;
        margin: 0;
        /* margin-bottomは削除 */
        flex: 1 1 auto;
        align-items: center;
        justify-content: flex-start;
        min-width: 0;
        flex-wrap: nowrap;
        order: 1;
        /* チャットタイプを先に */
        max-width: calc(100% - 56px);
        /* 送信ボタンのスペースを確保 */
    }

    .mobile-badge-item {
        flex: 0 1 auto;
        position: relative;
        cursor: pointer;
        display: inline-flex;
    }

    .mobile-badge-item input[type="radio"] {
        position: absolute;
        opacity: 0;
        pointer-events: none;
    }

    .mobile-badge-label {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        gap: 6px;
        padding: 8px 12px;
        border-radius: 20px;
        border: 1.5px solid var(--border-color);
        background: var(--container-bg);
        color: var(--subtext-color);
        font-size: 0.8rem;
        font-weight: 500;
        transition: background 0.35s ease, border-color 0.35s ease, color 0.3s ease, box-shadow 0.45s ease, transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
        white-space: nowrap;
        min-width: auto;
        box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
        will-change: transform, box-shadow, background, border-color;
    }

    .mobile-badge-item.selected .mobile-badge-label {
        transform: translateY(-2px);
        box-shadow: 0 14px 28px -18px rgba(15, 23, 42, 0.24);
        font-weight: 600;
    }

    .mobile-badge-item.private-badge.selected .mobile-badge-label {
        background: linear-gradient(135deg, rgba(16, 185, 129, 0.18) 0%, rgba(16, 185, 129, 0.06) 100%);
        border-color: rgba(16, 185, 129, 0.55);
        color: #0f766e;
    }

    .mobile-badge-item.open-badge.selected .mobile-badge-label {
        background: linear-gradient(135deg, rgba(245, 158, 11, 0.2) 0%, rgba(245, 158, 11, 0.08) 100%);
        border-color: rgba(245, 158, 11, 0.6);
        color: #b45309;
    }

    .mobile-badge-label svg {
        width: 16px;
        height: 16px;
        flex-shrink: 0;
    }

    /* PC版のチャットタイプセクションをモバイルで完全非表示 */
    .chat-type-selection {
        display: none !important;
    }

    .radio-group {
        display: none !important;
    }

    .radio-label {
        display: none !important;
    }

    .question-input-wrapper {
        min-height: 0;
        margin-bottom: 0;
    }

    .question-input-container {
        position: relative;
        left: auto;
        right: auto;
        bottom: auto;
        width: 100%;
        border-radius: 24px;
        min-height: 52px;
        padding: 12px 16px;
        background: rgba(255, 255, 255, 0.9);
        border: 1.5px solid rgba(0, 0, 0, 0.08);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
        display: flex;
        flex-direction: column;
        gap: 8px;
        box-sizing: border-box;
    }

    .question-textarea {
        font-size: 1rem;
        padding: 0;
        min-height: 24px;
        line-height: 1.5;
    }

    .question-textarea::placeholder {
        color: var(--subtext-color);
        opacity: 0.6;
    }

    .flash-messages {
        margin: 0 0 16px 0;
    }
}

@media (max-width: 768px) and (prefers-color-scheme: dark) {
    .mobile-appbar {
        background: rgba(26, 27, 30, 0.95);
    }

    .mobile-menu-btn:hover {
        background: rgba(255, 255, 255, 0.08);
    }

    .mobile-model-btn {
        background: rgba(255, 255, 255, 0.06);
        border-color: rgba(255, 255, 255, 0.1);
    }

    .mobile-model-option:hover {
        background: rgba(255, 255, 255, 0.06);
    }

    .mobile-sidebar {
        background: rgba(26, 27, 30, 0.95);
    }

    .mobile-sidebar-close:hover {
        background: rgba(255, 255, 255, 0.08);
    }

    .mobile-nav-item:hover {
        background: rgba(255, 255, 255, 0.06);
    }

    .composer-submit-btn {
        background: #ffffff;
        color: #000000;
        box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
    }

    .composer-submit-btn:hover {
        box-shadow: 0 8px 22px rgba(0, 0, 0, 0.5);
    }

    .question-input-container {
        background: rgba(40, 42, 48, 0.9);
        border-color: rgba(255, 255, 255, 0.12);
    }
}

/* 1024px以下でもモバイルヘッダーを有効化し、サイドバーを隠す（優先度確保のため末尾に配置） */
@media (max-width: 1024px) {
    .mobile-appbar {
        display: flex !important;
    }

    .sidebar-nav {
        display: none !important;
    }

    .sidebar-score {
        display: none !important;
    }

    .sidebar-footer {
        display: none !important;
    }
}

/* 極小画面向け追加調整（380px以下） */
@media (max-width: 380px) {
    .main-content {
        padding: 20px 12px 24px 12px;
    }

    .question-input-container {
        padding: 10px 16px;
        border-radius: 24px;
    }

    .mobile-badge-label {
        padding: 6px 10px;
        font-size: 0.75rem;
        gap: 4px;
    }

    .mobile-chat-type-badges {
        gap: 6px;
    }
}

/* モバイルドロップダウン内のchat-model-optionにタッチ最適化 */
@media (max-width: 768px) {
    .mobile-model-dropdown .chat-model-option {
        padding: 10px 14px;
        font-size: 12px;
    }
    .mobile-model-dropdown .chat-model-option-name {
        font-size: 13px;
    }
    .mobile-model-dropdown .chat-model-option-desc {
        font-size: 11px;
    }
    .mobile-model-dropdown .chat-model-remaining-badge {
        font-size: 10px;
        padding: 2px 6px;
    }
    .mobile-model-dropdown .chat-model-next-unlock {
        padding: 8px 14px;
        font-size: 11px;
    }
    .mobile-model-dropdown .chat-model-check {
        width: 20px;
        height: 20px;
    }
}