/* style.css */
:root {
    --primary-color: #007bff;
    --background-color: #f0f2f5;
    --sidebar-bg: #ffffff;
    --chat-bg: #ffffff;
    --text-color: #333;
    --border-color: #e0e0e0;
}

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

/* html, body {
    height: 100%;
    overflow: hidden;
} */

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    /* 広告表示を考慮し、bodyをflexコンテナにする */
    display: flex;
    flex-direction: column;
}

/* ログインページのラッパー */
.login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    flex-grow: 1; /* 広告以外の残りの高さをすべて使う */
    padding: 1rem;
    min-height: 100vh;
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 40px;
    background-color: var(--chat-bg);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* チャットアプリ本体のコンテナ */
.app-container {
    display: flex;
    width: 100%;
    flex-grow: 1; /* 広告以外の残りの高さをすべて使う */
    align-items: flex-start; /* Let sidebar and chat-area align to top */
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    flex-shrink: 0;
    position: sticky; /* Make sidebar stick to the top */
    top: 0;
    height: 100vh; /* Make it full height */
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

#new-chat-btn {
    width: 100%;
    padding: 0.75rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
}

.chat-history-list {
    flex-grow: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.chat-history-item {
    padding: 0.75rem 1rem;
    margin-bottom: 0.25rem;
    border-radius: 5px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-history-item:hover {
    background-color: #f0f0f0;
}

.chat-history-item.active {
    background-color: var(--primary-color);
    color: white;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
}

.sidebar-footer button {
    width: 100%;
    padding: 0.75rem;
    background-color: #dc3545;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

/* Main Chat Area */
.chat-area {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: center; /* Center content like chat-box and form */
    width: 100%;
    min-height: 100vh; /* Ensure it takes at least full screen height */
}

.chat-header {
    display: flex;
    align-items: center;
    padding: 0 1rem;
    height: 60px;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--chat-bg);
    flex-shrink: 0;
    width: 100%;
}

.menu-toggle-btn {
    display: none; /* デフォルトでは非表示 */
    font-size: 1.5rem;
    background: none;
    border: none;
    cursor: pointer;
    margin-right: 1rem;
}

.chat-header h1 {
    font-size: 1.2rem;
    margin: 0;
}

#token-usage {
    margin-left: auto;
    font-size: 0.9rem;
}

.chat-box {
    flex-grow: 1; /* Takes up space between header and form */
    padding: 1.5rem;
    /* overflow-y: auto; */ /* Removed to allow body scroll */
    width: 100%; /* 親に対して100% */
    max-width: 900px; /* ただし最大幅は900px */
}

.welcome-message {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    color: #888;
    flex-grow: 1;
}

.message {
    display: flex;
    margin-bottom: 1.5rem;
}

.message .role {
    font-weight: bold;
    width: 80px;
    flex-shrink: 0;
}

.message .text {
    max-width: 800px;
    line-height: 1.6;
    white-space: pre-wrap; /* 改行を反映 */
}

.chat-form {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    background-color: var(--chat-bg);
    display: flex;
    gap: 1rem;
    flex-shrink: 0;
    width: 100%;
    max-width: 900px;
    position: sticky;
    bottom: 0;
}

#message-input {
    flex-grow: 1;
    padding: 0.75rem;
    border: 1px solid #ccc;
    border-radius: 5px;
    resize: none;
    font-family: inherit;
    font-size: 1rem;
    height: 50px;
}

#chat-form button {
    padding: 0 1.5rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

/* ローディング表示 */
.message .text .dots {
    display: flex;
    align-items: center;
    padding-top: 8px;
}

.dots span {
    width: 8px;
    height: 8px;
    background-color: #888;
    border-radius: 50%;
    display: inline-block;
    margin: 0 4px;
    animation: dots-blink 1.4s infinite both;
}

.dots span:nth-child(1) { animation-delay: 0s; }
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dots-blink {
    0%, 80%, 100% { opacity: 0; }
    40% { opacity: 1; }
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
    .app-container {
        position: relative;
        overflow-x: hidden;
    }

    .sidebar {
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
        z-index: 1000;
        box-shadow: 2px 0 5px rgba(0,0,0,0.1);
        height: 100%; /* On mobile, not sticky, but full height of parent */
    }

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

    .menu-toggle-btn {
        display: block;
    }

    .chat-area.sidebar-open-overlay::after {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 999;
        cursor: pointer;
    }

    .chat-header, .chat-form, .chat-box {
        max-width: 100%;
    }
}


/* 広告用のスタイル */
.ad-container {
    width: 100%;
    height: 50px; /* 広告の高さ */
    background-color: #f0f0f0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.8rem;
    color: #555;
    flex-shrink: 0; /* 高さが変わらないようにする */
}

/* 広告がある場合のbodyの調整 */
body.with-ad {
    /* JSでapp-containerの高さを調整するため、ここでは何もしない */
}
