/* 営業支援データ対話 UI */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Segoe UI', 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', Meiryo, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: #1f2937;
    background-color: #f5f6f8;
    min-height: 100vh;
}

/* ----- ログイン画面 ----- */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.login-card {
    width: 100%;
    max-width: 400px;
    padding: 2rem;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.05);
}

.login-card h1 {
    margin: 0 0 0.25rem 0;
    font-size: 1.5rem;
    font-weight: 600;
}

.login-card .login-subtitle {
    margin: 0 0 1.5rem 0;
    font-size: 0.875rem;
    color: #6b7280;
}

.login-form label {
    display: block;
    margin-top: 1rem;
    font-weight: 500;
    font-size: 0.875rem;
}

.login-form label:first-of-type {
    margin-top: 0;
}

.login-form input[type="text"],
.login-form input[type="password"] {
    display: block;
    width: 100%;
    margin-top: 0.375rem;
    padding: 0.625rem 0.75rem;
    font-size: 1rem;
    border: 1px solid #d1d5db;
    border-radius: 8px;
}

.login-form input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.login-form button[type="submit"] {
    margin-top: 1.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 1rem;
    font-weight: 500;
    color: #fff;
    background-color: #2563eb;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

.login-form button[type="submit"]:hover {
    background-color: #1d4ed8;
}

.login-form .error {
    margin-top: 1rem;
    padding: 0.75rem;
    font-size: 0.875rem;
    color: #dc2626;
    background-color: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
}

/* ----- チャット画面 ----- */
body.body--chat {
    height: 100vh;
    min-height: 0;
    overflow: hidden;
}

.chat-page {
    max-width: 1024px;
    margin: 0 auto;
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 0 1rem 1rem 1rem;
    overflow: hidden;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    height: 56px;
    padding: 0 0.5rem;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
}

.chat-header h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.chat-header-actions {
    display: inline-flex;
    flex-flow: row nowrap;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
    margin-left: auto;
}

.chat-header .header-user-name {
    display: inline-block;
    font-size: 0.875rem;
    color: #6b7280;
    font-weight: 500;
    white-space: nowrap;
    line-height: 1;
}

.chat-header .logout-form {
    display: inline-flex;
    align-items: center;
    margin: 0;
    flex-shrink: 0;
}

.chat-header .btn-logout {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    color: #6b7280;
    background: transparent;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    cursor: pointer;
}

.chat-header .btn-logout:hover {
    color: #1f2937;
    background-color: #f9fafb;
}

.chat-area {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-top: none;
    border-radius: 0 0 8px 8px;
}

.chat-intro {
    margin: 0 0 1rem 0;
    font-size: 0.875rem;
    color: #6b7280;
}

.suggested-questions,
.follow-up-questions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
    margin-bottom: 1rem;
}

.follow-up-questions[aria-hidden="true"] {
    display: none;
}

.suggested-question-btn {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    color: #374151;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    cursor: pointer;
}

.suggested-question-btn:hover {
    background-color: #f9fafb;
    border-color: #9ca3af;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.message {
    max-width: 85%;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    white-space: pre-wrap;
    word-break: break-word;
}

.message--user {
    align-self: flex-end;
    background-color: #2563eb;
    color: #fff;
}

.message--user .message-label {
    font-size: 0.75rem;
    opacity: 0.9;
    margin-bottom: 0.25rem;
}

.message--assistant {
    align-self: flex-start;
    background-color: #f3f4f6;
    border: 1px solid #e5e7eb;
}

.message--assistant .message-label {
    font-size: 0.75rem;
    color: #6b7280;
    margin-bottom: 0.25rem;
}

.message-body {
    margin: 0;
    font-size: 0.9375rem;
    line-height: 1.5;
    white-space: normal;
}

/* Markdown 表示（アシスタント回答） */
.message-body h1, .message-body h2, .message-body h3 {
    margin: 1em 0 0.5em 0;
    font-size: 1.1em;
    font-weight: 600;
}

.message-body h1:first-child, .message-body h2:first-child, .message-body h3:first-child {
    margin-top: 0;
}

.message-body p {
    margin: 0.5em 0;
}

.message-body p:first-child {
    margin-top: 0;
}

.message-body ul, .message-body ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.message-body li {
    margin: 0.25em 0;
}

.message-body code {
    padding: 0.15em 0.4em;
    font-size: 0.9em;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 4px;
}

.message-body pre {
    margin: 0.5em 0;
    padding: 0.75rem;
    overflow-x: auto;
    font-size: 0.875rem;
    line-height: 1.4;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 6px;
    white-space: pre;
}

.message-body pre code {
    padding: 0;
    background: none;
}

.message-body blockquote {
    margin: 0.5em 0;
    padding-left: 1rem;
    border-left: 3px solid #d1d5db;
    color: #4b5563;
}

.message-body a {
    color: #2563eb;
    text-decoration: none;
}

.message-body a:hover {
    text-decoration: underline;
}

.message--user .message-body h1,
.message--user .message-body h2,
.message--user .message-body h3,
.message--user .message-body code,
.message--user .message-body pre,
.message--user .message-body blockquote,
.message--user .message-body a {
    color: inherit;
}

.message--user .message-body a:hover {
    text-decoration: underline;
}

.message--user .message-body {
    color: #fff;
}

.message--error .message-body {
    color: #dc2626;
}

.message.message--error {
    background-color: #fef2f2;
    border-color: #fecaca;
}

.message-loading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.message-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid #e5e7eb;
}

.message--error .message-footer {
    border-top-color: #fecaca;
}

.message-timestamp {
    font-size: 0.75rem;
    color: #6b7280;
    white-space: nowrap;
}

.btn-message-download {
    flex-shrink: 0;
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    color: #374151;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    cursor: pointer;
}

.btn-message-download:hover {
    background-color: #f9fafb;
    border-color: #9ca3af;
}

.conversation-export {
    display: flex;
    justify-content: flex-end;
    margin-top: 1rem;
    padding-top: 0.5rem;
}

.conversation-export[hidden] {
    display: none;
}

.btn-conversation-download {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    cursor: pointer;
}

.btn-conversation-download:hover {
    background-color: #f9fafb;
    border-color: #9ca3af;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #e5e7eb;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.input-area {
    flex-shrink: 0;
    margin-top: 1rem;
    padding: 1rem;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.chat-form {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

.chat-form label {
    flex: 1;
    margin: 0;
}

.chat-form #messageInput {
    display: block;
    width: 100%;
    min-height: 4.5rem;
    padding: 0.625rem 0.75rem;
    font-size: 1rem;
    line-height: 1.5;
    font-family: inherit;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    resize: vertical;
}

.chat-form #messageInput:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.chat-form #messageInput:disabled {
    background-color: #f9fafb;
    cursor: not-allowed;
}

.chat-form .btn-send {
    flex-shrink: 0;
    padding: 0.625rem 1.25rem;
    min-height: 44px;
    font-size: 1rem;
    font-weight: 500;
    color: #fff;
    background-color: #2563eb;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

.chat-form .btn-send:hover:not(:disabled) {
    background-color: #1d4ed8;
}

.chat-form .btn-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* レスポンシブ */
@media (max-width: 640px) {
    .message {
        max-width: 95%;
    }

    .chat-form {
        flex-direction: column;
        align-items: stretch;
    }

    .chat-form .btn-send {
        width: 100%;
    }
}
