* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    height: -webkit-fill-available;
}

:root {
    --vh: 1vh;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: #343541;
    color: #ececf1;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    height: calc(var(--vh, 1vh) * 100); /* Fallback for custom property */
    overflow: hidden;
    position: fixed;
    width: 100%;
    top: 0;
    left: 0;
    -webkit-overflow-scrolling: touch;
}

.app-container {
    display: flex;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    height: calc(var(--vh, 1vh) * 100); /* Fallback for custom property */
    position: relative;
}

/* サイドバー */
.sidebar {
    width: 260px;
    background-color: #202123;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #4d4d4f;
}

.new-chat-btn {
    margin: 12px;
    padding: 12px 16px;
    background-color: transparent;
    border: 1px solid #565869;
    border-radius: 6px;
    color: #ececf1;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background-color 0.2s;
}

.new-chat-btn:hover {
    background-color: #40414f;
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 0 12px;
}

.history-section h3 {
    font-size: 12px;
    color: #8e8ea0;
    margin: 20px 0 8px;
    font-weight: 500;
}

.history-item {
    padding: 12px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    transition: background-color 0.2s;
}

.history-item:hover {
    background-color: #2a2b32;
}

.history-item.active {
    background-color: #343541;
}

.sidebar-footer {
    border-top: 1px solid #4d4d4f;
    padding: 12px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
}

.user-info:hover {
    background-color: #40414f;
}

.avatar {
    width: 32px;
    height: 32px;
    background-color: #565869;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

/* メインコンテンツ */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 850px;
    margin: 0 auto;
    width: 100%;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.welcome-message {
    text-align: center;
    padding: 60px 20px;
}

.welcome-message h1 {
    font-size: 36px;
    margin-bottom: 16px;
}

.welcome-message p {
    color: #8e8ea0;
    font-size: 16px;
    line-height: 1.5;
}

.message {
    padding: 20px 0;
}

.message-content {
    display: flex;
    gap: 20px;
    max-width: 850px;
    margin: 0 auto;
}

.message.user {
    background-color: #343541;
}

.message.assistant {
    background-color: #444654;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background-color: #5436da;
}

.message.assistant .message-avatar {
    background-color: #10a37f;
}

.message-text {
    flex: 1;
    line-height: 1.6;
    font-size: 16px;
}

.message-text p {
    margin-bottom: 12px;
}

.message-text p:last-child {
    margin-bottom: 0;
}

.typing-indicator {
    display: inline-block;
}

.typing-indicator span {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #8e8ea0;
    margin: 0 2px;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        opacity: 0.3;
    }
    30% {
        opacity: 1;
    }
}

/* 入力エリア */
.input-container {
    padding: 20px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    border-top: 1px solid #565869;
    background-color: #343541;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background-color: #40414f;
    border: 1px solid #565869;
    border-radius: 8px;
    padding: 12px;
}

#messageInput {
    flex: 1;
    background: transparent;
    border: none;
    color: #ececf1;
    font-size: 16px;
    resize: none;
    outline: none;
    max-height: 200px;
    line-height: 1.5;
}

.send-button {
    width: 32px;
    height: 32px;
    background-color: #10a37f;
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s;
}

.send-button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.send-button:not(:disabled):hover {
    opacity: 0.8;
}

.input-footer {
    text-align: center;
    margin-top: 12px;
    font-size: 12px;
    color: #8e8ea0;
}

/* モバイル対応 */
@media (max-width: 768px) {
    .sidebar {
        display: none;
    }
    
    .main-content {
        width: 100%;
        height: 100%;
    }
    
    .chat-container {
        padding: 0;
        height: 100%;
    }
    
    .chat-messages {
        padding-bottom: 20px;
        padding-top: calc(20px + env(safe-area-inset-top));
    }
    
    .welcome-message {
        padding: 40px 20px;
    }
    
    .welcome-message h1 {
        font-size: 28px;
    }
    
    .welcome-message p {
        font-size: 14px;
    }
    
    .message-content {
        padding: 0 16px;
    }
    
    .input-container {
        padding: 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
    
    #messageInput {
        font-size: 16px;
        /* Prevent zoom on iOS when focusing input */
        -webkit-text-size-adjust: 100%;
    }
}

/* スクロールバー */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background-color: #565869;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background-color: #8e8ea0;
}