/* LINEライクなデザインシステム */
:root {
    /* LINEブランドカラー */
    --line-green: #06C755;
    --line-green-dark: #05A548;
    --line-green-light: #E8FDF2;
    --line-gray: #F7F7F7;
    --line-dark-gray: #4A4A4A;
    --line-light-gray: #E5E5EA;
    --line-blue: #007AFF;
    --line-background: #FFFFFF;
    
    /* メッセージバブルカラー */
    --user-bubble: var(--line-green);
    --bot-bubble: #F0F0F0;
    --user-text: #FFFFFF;
    --bot-text: #333333;
    
    /* シャドウとエフェクト */
    --soft-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --message-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    --floating-shadow: 0 4px 16px rgba(6, 199, 85, 0.3);
    
    /* アニメーション */
    --smooth-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --bounce-transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Hiragino Sans', 'ヒラギノ角ゴシック', 'Yu Gothic', 'Meiryo', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--line-background);
    color: var(--line-dark-gray);
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100); /* JavaScriptで設定される動的高さ */
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ヘッダー（LINEライク） */
.line-header {
    background: var(--line-background);
    border-bottom: 1px solid var(--line-light-gray);
    padding: 12px 16px;
    box-shadow: var(--soft-shadow);
    z-index: 100;
    position: relative;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 100%;
}

.chat-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar-container {
    position: relative;
}

.bible-character-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #bce2e8;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: white;
    box-shadow: var(--message-shadow);
    animation: gentle-pulse 3s ease-in-out infinite;
}

@keyframes gentle-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.online-indicator {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: var(--line-green);
    border: 2px solid white;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

.chat-details {
    display: flex;
    flex-direction: column;
}

.chat-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--line-dark-gray);
    margin: 0;
}

.chat-subtitle {
    font-size: 12px;
    color: #8E8E93;
    margin-top: 2px;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.header-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--line-dark-gray);
    cursor: pointer;
    transition: var(--smooth-transition);
}

.header-btn:hover {
    background: var(--line-gray);
}

/* チャットコンテナ */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    background: var(--line-background);
    scroll-behavior: smooth;
}

/* メッセージグループ */
.message-group {
    display: flex;
    margin-bottom: 16px;
    animation: slideInUp 0.4s ease-out;
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.bot-group {
    justify-content: flex-start;
}

.user-group {
    justify-content: flex-end;
}

/* アバター */
.avatar {
    margin-right: 8px;
    margin-top: auto;
}

.bible-character {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #bce2e8;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: white;
    box-shadow: var(--message-shadow);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--line-blue);
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: white;
    margin-left: 8px;
    margin-right: 0;
}

/* メッセージバブル */
.message-content {
    max-width: 75%;
    display: flex;
    flex-direction: column;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: 20px;
    position: relative;
    box-shadow: var(--message-shadow);
    transition: var(--smooth-transition);
    word-wrap: break-word;
    line-height: 1.4;
}

.bot-bubble {
    background: var(--bot-bubble);
    color: var(--bot-text);
    border-bottom-left-radius: 6px;
    margin-left: 0;
}

.user-bubble {
    background: var(--user-bubble);
    color: var(--user-text);
    border-bottom-right-radius: 6px;
    margin-left: auto;
}

.message-text {
    font-size: 15px;
    margin-bottom: 4px;
}

.message-time {
    font-size: 11px;
    opacity: 0.6;
    text-align: right;
    margin-top: 4px;
}

/* 聖書的応答の特別スタイル */
.biblical-response {
    background: linear-gradient(135deg, var(--line-green-light), #F0F9FF);
    border: 1px solid var(--line-green);
    padding: 16px;
    border-radius: 16px;
    margin: 8px 0;
}

.verse-section {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--line-light-gray);
}

.verse-result {
    background: #FAFAFA;
    border-left: 4px solid var(--line-green);
    padding: 12px;
    margin: 8px 0;
    border-radius: 0 12px 12px 0;
}

.verse-ref {
    font-weight: 600;
    color: var(--line-green-dark);
    font-size: 13px;
    margin-bottom: 4px;
}

.verse-text {
    font-size: 14px;
    line-height: 1.5;
    color: var(--line-dark-gray);
}

/* 入力エリア */
.input-area {
    background: var(--line-background);
    border-top: 1px solid var(--line-light-gray);
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
    position: relative;
    z-index: 10;
}

.input-container {
    max-width: 100%;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--line-gray);
    border-radius: 24px;
    padding: 8px 12px;
    transition: var(--smooth-transition);
}

.input-wrapper:focus-within {
    box-shadow: 0 0 0 2px var(--line-green);
}

#message-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 16px; /* iOS zoom防止のため16px以上 */
    padding: 8px 0;
    resize: none;
    outline: none;
    font-family: inherit;
    color: var(--line-dark-gray);
    min-height: 20px;
    max-height: 100px;
    /* モバイル最適化 */
    -webkit-appearance: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    /* 自動補正無効化 */
    autocomplete: off;
    autocorrect: off;
    autocapitalize: off;
    spellcheck: false;
}

#message-input::placeholder {
    color: #8E8E93;
}

.send-button {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--line-green);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--bounce-transition);
    box-shadow: var(--message-shadow);
}

.send-button:disabled {
    background: #C7C7CC;
    cursor: not-allowed;
    transform: scale(0.9);
}

.send-button:not(:disabled):hover {
    transform: scale(1.1);
    box-shadow: var(--floating-shadow);
}

.send-button:not(:disabled):active {
    transform: scale(0.95);
}

.send-button i {
    color: white;
    font-size: 14px;
}

/* タイピングインジケーター */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    margin-top: 8px;
    color: #8E8E93;
    font-size: 13px;
    animation: fadeIn 0.3s ease-in;
}

.typing-dots {
    display: flex;
    gap: 3px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--line-green);
    animation: typing 1.4s infinite;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* クイック返信 */
.quick-replies {
    display: flex;
    gap: 8px;
    padding: 8px 16px;
    overflow-x: auto;
    background: var(--line-background);
}

.quick-reply-btn {
    background: var(--line-gray);
    border: 1px solid var(--line-light-gray);
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 13px;
    color: var(--line-dark-gray);
    cursor: pointer;
    transition: var(--smooth-transition);
    white-space: nowrap;
    flex-shrink: 0;
}

.quick-reply-btn:hover {
    background: var(--line-green-light);
    border-color: var(--line-green);
    color: var(--line-green-dark);
}

/* フローティングヘルプボタン */
.floating-help {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--line-green);
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    box-shadow: var(--floating-shadow);
    transition: var(--bounce-transition);
    z-index: 1000;
}

.floating-help:hover {
    transform: scale(1.1);
}

/* モーダル */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    animation: fadeIn 0.3s ease-in;
}

.modal-content {
    background: white;
    border-radius: 16px;
    padding: 0;
    max-width: 90%;
    max-height: 80%;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    animation: slideInScale 0.3s ease-out;
}

@keyframes slideInScale {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    background: var(--line-green);
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 18px;
}

.modal-close {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: var(--smooth-transition);
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.modal-body {
    padding: 20px;
}

.help-section {
    margin-bottom: 20px;
}

.help-section h4 {
    color: var(--line-green-dark);
    margin-bottom: 12px;
    font-size: 16px;
}

.help-section ul {
    list-style: none;
    padding: 0;
}

.help-section li {
    padding: 8px 0;
    border-bottom: 1px solid var(--line-light-gray);
    font-size: 14px;
    line-height: 1.4;
}

.help-section li:last-child {
    border-bottom: none;
}

/* レスポンシブデザイン */
@media (max-width: 768px) {
    .line-header {
        padding: 10px 12px;
    }
    
    .chat-title {
        font-size: 15px;
    }
    
    .messages-area {
        padding: 16px 12px;
        /* スクロール性能向上 */
        -webkit-overflow-scrolling: touch;
    }
    
    .message-content {
        max-width: 85%;
    }
    
    .input-area {
        padding: 10px 12px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 20px));
    }
    
    .modal-content {
        margin: 20px;
        max-width: calc(100% - 40px);
        /* スクロール性能向上 */
        -webkit-overflow-scrolling: touch;
    }
    
    .floating-help {
        top: 16px;
        right: 16px;
        width: 44px;
        height: 44px;
        font-size: 18px;
    }
    
    /* タッチ対応の改善 */
    .send-button {
        min-width: 44px;
        min-height: 44px;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    
    .quick-reply-btn {
        min-height: 44px;
        padding: 12px 16px;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    
    .header-btn {
        min-width: 44px;
        min-height: 44px;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    
    .floating-help {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
}

/* さらに小さなスクリーンサイズ対応 */
@media (max-width: 480px) {
    .chat-title {
        font-size: 14px;
        max-width: 200px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    .chat-subtitle {
        font-size: 11px;
        max-width: 200px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    .message-content {
        max-width: 90%;
    }
    
    .input-wrapper {
        padding: 6px 10px;
    }
    
    .modal-content {
        margin: 10px;
        max-width: calc(100% - 20px);
        max-height: calc(100% - 40px);
    }
    
    .floating-help {
        top: 12px;
        right: 12px;
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
}

/* 横向きモバイル対応 */
@media screen and (max-height: 500px) and (orientation: landscape) {
    .line-header {
        padding: 8px 12px;
    }
    
    .messages-area {
        padding: 12px;
    }
    
    .input-area {
        padding: 8px 12px;
    }
    
    .floating-help {
        top: 8px;
        right: 8px;
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
}

/* スクロールバーのカスタマイズ */
.messages-area::-webkit-scrollbar {
    width: 4px;
}

.messages-area::-webkit-scrollbar-track {
    background: transparent;
}

.messages-area::-webkit-scrollbar-thumb {
    background: var(--line-light-gray);
    border-radius: 2px;
}

.messages-area::-webkit-scrollbar-thumb:hover {
    background: #C7C7CC;
}

/* アニメーション効果 */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes bounceIn {
    0% {
        opacity: 0;
        transform: scale(0.3);
    }
    50% {
        opacity: 1;
        transform: scale(1.05);
    }
    70% {
        transform: scale(0.9);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* 特別なメッセージタイプ */
.system-message {
    text-align: center;
    font-size: 12px;
    color: #8E8E93;
    margin: 20px 0;
    padding: 8px;
}

.welcome-message {
    animation: bounceIn 0.6s ease-out;
}

/* モバイル固有の最適化 */
@supports (-webkit-appearance: none) {
    /* iOS Safari固有のスタイル */
    #message-input {
        -webkit-appearance: none;
        border-radius: 0;
    }
}

/* タッチデバイス専用の最適化 */
@media (hover: none) and (pointer: coarse) {
    /* タッチデバイスでホバー効果を無効化 */
    .send-button:hover,
    .quick-reply-btn:hover,
    .header-btn:hover,
    .floating-help:hover,
    .modal-close:hover {
        transform: none;
        background: initial;
    }
    
    /* タッチターゲットサイズを44px以上に */
    .send-button,
    .quick-reply-btn,
    .header-btn,
    .floating-help {
        min-width: 44px;
        min-height: 44px;
    }
}

/* フォーカス時の最適化 */
#message-input:focus {
    outline: none;
    /* iOS の青いアウトラインを除去 */
    -webkit-tap-highlight-color: transparent;
}

/* スクロール最適化 */
.messages-area {
    /* スムーズスクロール */
    scroll-behavior: smooth;
    /* iOS の反発スクロール */
    -webkit-overflow-scrolling: touch;
    /* スクロール位置の保持 */
    overscroll-behavior: contain;
}

/* プルトゥリフレッシュ無効化 */
body {
    overscroll-behavior-y: none;
}

/* キーボード表示時の調整 */
@media (max-height: 600px) {
    .messages-area {
        padding-bottom: 10px;
    }
    
    .input-area {
        padding: 8px 12px;
    }
}

/* 非常に小さな画面（古いiPhone SE等）対応 */
@media (max-width: 320px) {
    .chat-title {
        font-size: 13px;
        max-width: 150px;
    }
    
    .chat-subtitle {
        font-size: 10px;
        max-width: 150px;
    }
    
    .message-bubble {
        padding: 10px 12px;
        font-size: 14px;
    }
    
    .input-wrapper {
        padding: 4px 8px;
    }
    
    #message-input {
        font-size: 16px; /* ズーム防止のため維持 */
    }
}