/* ============================================
   AI Adjuster - メインスタイルシート
   ============================================ */

/* リセットと基本設定 */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --color-drive: #E53935;
    --color-inspire: #FDD835;
    --color-harmony: #43A047;
    --color-logic: #1E88E5;
    --color-bg: #f8f9fa;
    --color-surface: #ffffff;
    --color-text: #1a1a2e;
    --color-text-secondary: #555;
    --color-text-muted: #888;
    --color-border: #e2e5e9;
    --color-primary: #1a1a2e;
    --color-primary-hover: #2d2d4e;
    --sidebar-width: 280px;
    --header-height: 56px;
    --input-area-height: 120px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
}

html {
    height: 100%;
}

body {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: var(--color-text);
    background: var(--color-bg);
    height: 100%;
    overflow: hidden;
}

/* ============================================
   スクリーン切り替え
   ============================================ */
.screen {
    display: none;
    height: 100%;
}
.screen.active {
    display: flex;
}

/* ============================================
   ログイン画面
   ============================================ */
#login-screen {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #f8f9fa 0%, #e8ecf0 100%);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 48px 32px;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.login-logo-wrap {
    margin-bottom: 24px;
}

.login-logo {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: var(--shadow-md);
}

.login-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 4px;
    letter-spacing: 0.5px;
}

.login-subtitle {
    font-size: 13px;
    color: var(--color-text-muted);
    margin-bottom: 32px;
}

.login-form {
    text-align: left;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-secondary);
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    font-size: 15px;
    font-family: 'Noto Sans JP', sans-serif;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg);
    color: var(--color-text);
    transition: border-color 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--color-primary);
}

.form-group input::placeholder {
    color: #bbb;
}

.login-btn {
    width: 100%;
    padding: 14px;
    font-size: 15px;
    font-weight: 600;
    font-family: 'Noto Sans JP', sans-serif;
    color: #fff;
    background: var(--color-primary);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 8px;
}

.login-btn:hover {
    background: var(--color-primary-hover);
}

.login-note {
    font-size: 12px;
    color: var(--color-text-muted);
    text-align: center;
    margin-top: 16px;
}

/* ============================================
   チャット画面レイアウト
   ============================================ */
#chat-screen {
    flex-direction: row;
    background: var(--color-bg);
}

/* サイドバー */
.sidebar {
    width: var(--sidebar-width);
    height: 100%;
    background: var(--color-primary);
    color: #fff;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.3s ease;
    z-index: 100;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 16px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-logo {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.sidebar-title {
    font-size: 15px;
    font-weight: 600;
    flex: 1;
}

.sidebar-close {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}

.new-chat-btn {
    margin: 12px 16px;
    padding: 10px;
    font-size: 14px;
    font-weight: 500;
    font-family: 'Noto Sans JP', sans-serif;
    color: #fff;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s;
}

.new-chat-btn:hover {
    background: rgba(255,255,255,0.18);
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px;
}

.conv-item {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 2px;
}

.conv-item:hover {
    background: rgba(255,255,255,0.08);
}

.conv-item.active {
    background: rgba(255,255,255,0.15);
}

.conv-item-title {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: rgba(255,255,255,0.9);
}

.conv-item-date {
    font-size: 11px;
    color: rgba(255,255,255,0.45);
    margin-top: 2px;
}

.conv-item-actions {
    display: none;
    gap: 4px;
    margin-top: 4px;
}

.conv-item:hover .conv-item-actions {
    display: flex;
}

.conv-delete-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,0.5);
    font-size: 11px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
}

.conv-delete-btn:hover {
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.8);
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.logout-btn {
    width: 100%;
    padding: 8px;
    font-size: 13px;
    font-family: 'Noto Sans JP', sans-serif;
    color: rgba(255,255,255,0.7);
    background: none;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.logout-btn:hover {
    color: #fff;
    border-color: rgba(255,255,255,0.3);
}

/* サイドバーオーバーレイ */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 99;
}

/* メインチャットエリア */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-width: 0;
    position: relative;
}

/* ヘッダー */
.chat-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 16px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.sidebar-toggle {
    display: none;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    margin-right: 8px;
}

.sidebar-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--color-text);
    border-radius: 2px;
}

.chat-header-title {
    font-size: 16px;
    font-weight: 600;
}

.chat-header-spacer {
    flex: 1;
}

/* メッセージエリア */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

/* ウェルカム画面 */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    padding: 40px 24px;
}

.welcome-logo {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: var(--shadow-md);
    margin-bottom: 20px;
}

.welcome-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 8px;
}

.welcome-desc {
    font-size: 14px;
    color: var(--color-text-secondary);
    text-align: center;
    margin-bottom: 36px;
    line-height: 1.7;
}

/* クイックアクションボタン（ウェルカム画面用） */
.quick-actions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    width: 100%;
    max-width: 480px;
}

.quick-action-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 16px;
    background: var(--color-surface);
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    font-family: 'Noto Sans JP', sans-serif;
}

.quick-action-btn:hover {
    border-color: var(--color-text-muted);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.qa-icon {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-bottom: 10px;
}

.qa-icon-drive { background: var(--color-drive); }
.qa-icon-inspire { background: var(--color-inspire); }
.qa-icon-harmony { background: var(--color-harmony); }
.qa-icon-logic { background: var(--color-logic); }

.qa-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 4px;
}

.qa-desc {
    display: block;
    font-size: 12px;
    color: var(--color-text-muted);
}

/* コンパクトクイックアクション（会話中） */
.compact-actions {
    display: flex;
    gap: 8px;
    padding: 8px 16px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    overflow-x: auto;
    flex-shrink: 0;
}

.compact-action-btn {
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 500;
    font-family: 'Noto Sans JP', sans-serif;
    color: var(--color-text-secondary);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 20px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

.compact-action-btn:hover {
    border-color: var(--color-text-muted);
    color: var(--color-text);
}

/* メッセージ */
.message {
    padding: 16px 24px;
    display: flex;
    gap: 14px;
    align-items: flex-start;
}

.message + .message {
    border-top: 1px solid #f0f1f3;
}

.message-user {
    background: var(--color-bg);
}

.message-assistant {
    background: var(--color-surface);
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
}

.message-avatar-user {
    background: var(--color-primary);
    color: #fff;
}

.message-avatar-ai {
    overflow: hidden;
}

.message-avatar-ai img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message-content {
    flex: 1;
    min-width: 0;
    font-size: 14.5px;
    line-height: 1.75;
}

/* Markdownレンダリング後のスタイル */
.message-content h1,
.message-content h2,
.message-content h3 {
    margin-top: 16px;
    margin-bottom: 8px;
    font-weight: 700;
}

.message-content h1 { font-size: 18px; }
.message-content h2 { font-size: 16px; }
.message-content h3 { font-size: 15px; }

.message-content p {
    margin-bottom: 8px;
}

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

.message-content ul, .message-content ol {
    margin: 8px 0;
    padding-left: 24px;
}

.message-content li {
    margin-bottom: 4px;
}

.message-content strong {
    font-weight: 700;
}

.message-content blockquote {
    border-left: 3px solid var(--color-border);
    padding: 8px 16px;
    margin: 12px 0;
    color: var(--color-text-secondary);
    background: var(--color-bg);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* コードブロック（コピーボタン付き） */
.code-block-wrap {
    position: relative;
    margin: 12px 0;
}

.message-content pre {
    background: #1a1a2e;
    color: #e0e0e0;
    padding: 16px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 13px;
    line-height: 1.5;
    margin: 0;
}

.message-content code {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 13px;
}

.message-content p code,
.message-content li code {
    background: #f0f1f3;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

.copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 10px;
    font-size: 11px;
    font-family: 'Noto Sans JP', sans-serif;
    color: rgba(255,255,255,0.6);
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.copy-btn:hover {
    color: #fff;
    background: rgba(255,255,255,0.2);
}

.copy-btn.copied {
    color: var(--color-harmony);
    border-color: var(--color-harmony);
}

/* タイピングインジケーター */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.typing-indicator span {
    width: 7px;
    height: 7px;
    background: var(--color-text-muted);
    border-radius: 50%;
    animation: typing 1.2s 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; transform: scale(0.8); }
    30% { opacity: 1; transform: scale(1); }
}

/* 入力エリア */
.chat-input-area {
    padding: 12px 16px 8px;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    flex-shrink: 0;
}

.chat-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 768px;
    margin: 0 auto;
    background: var(--color-bg);
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    transition: border-color 0.2s;
}

.chat-input-wrap:focus-within {
    border-color: var(--color-primary);
}

.chat-input {
    flex: 1;
    border: none;
    background: none;
    font-size: 15px;
    font-family: 'Noto Sans JP', sans-serif;
    color: var(--color-text);
    resize: none;
    max-height: 120px;
    line-height: 1.5;
    padding: 4px 0;
}

.chat-input:focus {
    outline: none;
}

.chat-input::placeholder {
    color: #bbb;
}

.send-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}

.send-btn:disabled {
    background: var(--color-border);
    color: var(--color-text-muted);
    cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
    background: var(--color-primary-hover);
    transform: scale(1.05);
}

.input-note {
    font-size: 11px;
    color: var(--color-text-muted);
    text-align: center;
    margin-top: 6px;
    padding-bottom: 4px;
}

/* ============================================
   レスポンシブ（スマホ対応）
   ============================================ */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100%;
        transform: translateX(-100%);
    }

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

    .sidebar.open + .sidebar-overlay {
        display: block;
    }

    .sidebar-close {
        display: block;
    }

    .sidebar-toggle {
        display: flex;
    }

    .quick-actions-grid {
        grid-template-columns: 1fr;
    }

    .message {
        padding: 12px 16px;
    }

    .chat-input-area {
        padding: 8px 12px 4px;
    }

    .compact-actions {
        padding: 6px 12px;
    }
}

@media (max-width: 480px) {
    .login-container {
        margin: 0 16px;
        padding: 32px 24px;
    }

    .welcome-screen {
        padding: 24px 16px;
    }

    .welcome-title {
        font-size: 20px;
    }

    .qa-label {
        font-size: 13px;
    }
}

/* ============================================
   ヘッダー設定ボタン・モデルバッジ
   ============================================ */
.settings-btn {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.settings-btn:hover {
    color: var(--color-text);
    background: var(--color-bg);
}

.active-model-badge {
    font-size: 10px;
    color: var(--color-text-muted);
    background: var(--color-bg);
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 8px;
    white-space: nowrap;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================
   設定モーダル
   ============================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.modal-container {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 520px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    margin: 16px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 12px;
    border-bottom: 1px solid var(--color-border);
}

.modal-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--color-text);
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}

.modal-close:hover {
    color: var(--color-text);
}

.modal-body {
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-body .form-group {
    margin-bottom: 16px;
}

.modal-body .form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: 5px;
}

.form-select,
.form-input {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    font-family: 'Noto Sans JP', sans-serif;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg);
    color: var(--color-text);
    transition: border-color 0.2s;
}

.form-select:focus,
.form-input:focus {
    outline: none;
    border-color: var(--color-primary);
}

.form-input::placeholder {
    color: #bbb;
}

.settings-divider {
    border-top: 1px solid var(--color-border);
    margin: 20px 0 16px;
}

.settings-section-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 12px;
}

.settings-note {
    font-size: 11px;
    color: var(--color-text-muted);
    line-height: 1.6;
    margin-top: 8px;
}

.modal-footer {
    padding: 12px 24px 20px;
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: flex-end;
}

.modal-save-btn {
    padding: 10px 32px;
    font-size: 14px;
    font-weight: 600;
    font-family: 'Noto Sans JP', sans-serif;
    color: #fff;
    background: var(--color-primary);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s;
}

.modal-save-btn:hover {
    background: var(--color-primary-hover);
}

@media (max-width: 480px) {
    .modal-container {
        max-height: 90vh;
    }

    .active-model-badge {
        display: none;
    }
}

/* ============================================
   ユーティリティ
   ============================================ */

/* スクロールバーのスタイル */
.chat-messages::-webkit-scrollbar,
.conversation-list::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track,
.conversation-list::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.15);
    border-radius: 3px;
}

.conversation-list::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 3px;
}

/* アニメーション */
.message {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
