/* =============================================
   CHAT — Main content area, messages, prompt bar,
   welcome screen, and interaction UI.
   Responsive design uses %, vw, clamp for all screens.
   ============================================= */

/* --- Layout --- */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--color-cream);
    position: relative;
    min-width: 0;
    overflow: hidden;
}

.app-layout {
    display: flex;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.chat-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

/* ChatGPT-style: when idle, center greeting + prompt as a group.
   Large padding-bottom shifts the centered group into the upper portion. */
.chat-section:not(.chatting) {
    justify-content: center;
    padding-bottom: 25vh;
}

/* --- Top Bar --- */
.top-bar {
    height: var(--topbar-height);
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Top bar buttons (city, language) */
.top-bar-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.5);
    border: var(--border-light);
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 500;
    color: var(--color-gray-600);
    transition: all var(--transition-fast);
}

.top-bar-chip:hover {
    background: var(--color-white);
    box-shadow: var(--shadow-sm);
    color: var(--color-gray-800);
}

.top-bar-chip .chip-dot {
    width: 6px;
    height: 6px;
    background: var(--color-green);
    border-radius: 50%;
}

.lang-toggle {
    font-weight: 600;
    min-width: 36px;
    justify-content: center;
    font-size: 11px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

/* --- Welcome Screen ---
   In idle state: flex:none so it doesn't stretch,
   letting justify-content:center on parent center the group. */
.welcome-screen {
    flex: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 24px 16px;
    text-align: center;
}

.welcome-screen.hidden {
    display: none;
}

.welcome-greeting {
    font-family: var(--font-serif);
    font-size: clamp(28px, 4vw, 48px);
    font-style: italic;
    color: var(--color-navy);
    line-height: 1.15;
    opacity: 0;
    transform: translateY(12px);
}

.welcome-sub {
    font-size: clamp(14px, 1.5vw, 16px);
    color: var(--color-gray-500);
    margin-top: 12px;
    opacity: 0;
    transform: translateY(12px);
}

/* --- Chat Scroll Area --- */
.chat-scroll-area {
    flex: 1;
    overflow-y: auto;
    padding: 16px 0 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.chat-scroll-area.hidden {
    display: none;
}

.chat-container {
    width: 100%;
    max-width: var(--chat-max-width);
    padding: 0 24px;
}

/* --- Messages --- */
.messages-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding-bottom: 20px;
}

.message {
    display: flex;
    width: 100%;
    animation: fadeIn 0.35s ease forwards;
}

/* User Message */
.message.user {
    justify-content: flex-end;
}

.message.user .message-bubble {
    background-color: var(--color-navy);
    color: var(--color-white);
    border-radius: 20px 20px 4px 20px;
    padding: 14px 20px;
    max-width: 70%;
    font-size: 15px;
    line-height: 1.5;
    box-shadow: var(--shadow-md);
}

/* AI Message */
.message.ai {
    justify-content: flex-start;
    gap: 12px;
}

.ai-avatar {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    background: var(--color-white);
    border: var(--border-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 2px;
}

.ai-avatar img {
    width: 20px;
    height: auto;
}

.message.ai .message-body {
    max-width: 80%;
    font-size: 15px;
    line-height: 1.65;
    color: var(--color-gray-800);
}

/* AI Response Typography */
.message.ai .message-body h1,
.message.ai .message-body h2,
.message.ai .message-body h3,
.message.ai .message-body h4 {
    font-family: var(--font-serif);
    font-weight: 400;
    font-style: italic;
    color: var(--color-navy);
    margin: 24px 0 12px;
    letter-spacing: -0.01em;
}

.message.ai .message-body h3 {
    font-size: 20px;
}

.message.ai .message-body h4 {
    font-size: 18px;
}

.message.ai .message-body p {
    margin-bottom: 10px;
}

.message.ai .message-body ul,
.message.ai .message-body ol {
    padding-left: 20px;
    margin-bottom: 10px;
}

.message.ai .message-body li {
    list-style: disc;
    margin-bottom: 4px;
}

.message.ai .message-body strong {
    font-weight: 600;
    color: var(--color-gray-900);
}

/* --- Inline Citation (text only, no doc icon) --- */
.citation-inline {
    display: inline;
    color: var(--color-orange);
    font-weight: 600;
    font-size: inherit;
    cursor: pointer;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 2px;
    transition: color var(--transition-fast);
}

.citation-inline:hover {
    color: #c2410c;
}

/* --- Bottom Sources Block (with doc icon) --- */
.citations-block {
    margin-top: 14px;
    padding-top: 12px;
    border-top: var(--border-light);
}

.citations-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-gray-500);
    margin-bottom: 8px;
    font-weight: 600;
}

.citation-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--color-orange-soft);
    border: 1.5px solid rgba(249, 115, 22, 0.4);
    color: #c2410c;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    margin: 0 6px 6px 0;
    cursor: pointer;
    transition: all var(--transition-fast);
    line-height: 1;
}

.citation-badge:hover {
    background: var(--color-orange-hover);
    border-color: var(--color-orange);
    transform: translateY(-1px);
}

.citation-badge svg {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
}

/* --- Message Actions (thumbs, copy) --- */
.message-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-top: 8px;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.message.ai:hover .message-actions,
.message-actions:has(.action-btn.active) {
    opacity: 1;
}

.action-btn {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-gray-400);
    transition: all var(--transition-fast);
}

.action-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--color-gray-700);
}

.action-btn.active {
    color: var(--color-orange);
}

/* --- Feedback Form (subtle, blends in) --- */
.feedback-form {
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0;
    transform: translateY(4px);
    transition: all 0.25s ease;
    max-width: 360px;
}

.feedback-form.visible {
    opacity: 1;
    transform: translateY(0);
}

.feedback-textarea {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: var(--radius-sm);
    background: var(--color-white);
    color: var(--color-gray-700);
    font-size: 12px;
    line-height: 1.4;
    resize: none;
    outline: none;
    font-family: var(--font-sans);
    transition: border-color var(--transition-fast);
    min-height: 28px;
}

.feedback-textarea:focus {
    border-color: rgba(0, 0, 0, 0.15);
}

.feedback-textarea::placeholder {
    color: var(--color-gray-400);
}

.feedback-submit-btn {
    padding: 5px 12px;
    background: var(--color-navy);
    color: var(--color-white);
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.feedback-submit-btn:hover {
    background: var(--color-black);
}

/* --- Step Progress (SSE Pipeline) --- */
.step-progress {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 0;
}

.step-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    opacity: 0;
    transform: translateY(6px);
    transition: all 0.35s ease;
}

.step-item.visible {
    opacity: 1;
    transform: translateY(0);
}

.step-dot-wrapper {
    height: 19px;
    /* approximate line-height of step-label to vertically align the dot */
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.step-content {
    display: flex;
    flex-direction: column;
}

.sub-steps-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 4px;
}

.sub-step-item {
    font-size: 11px;
    color: var(--color-gray-400);
    opacity: 0;
    transform: translateY(4px);
    transition: all 0.35s ease;
}

.sub-step-item.visible {
    opacity: 1;
    transform: translateY(0);
}

.step-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-gray-300);
    flex-shrink: 0;
    transition: all 0.3s;
}

.step-item.active .step-dot {
    background: var(--color-navy);
    animation: pulse 1.5s ease-in-out infinite;
}

.step-item.completed .step-dot {
    background: var(--color-green);
    animation: none;
}

.step-item.completed {
    opacity: 0.5;
}

.step-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--color-gray-500);
}

.step-item.active .step-label {
    color: var(--color-navy);
    font-weight: 600;
}

/* --- Prompt Bar ---
   In idle state: prompt is part of the centered group (no extra padding).
   In chatting state: prompt sits at natural bottom.
   padding-bottom reserves space for disclaimer below. */
.prompt-area {
    width: 100%;
    padding: 0 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
    padding-bottom: 36px;
}

/* When chatting, messages push prompt down naturally */
.chat-section.chatting .prompt-area {
    background: linear-gradient(to top, var(--color-cream) 85%, rgba(245, 241, 235, 0));
}

.prompt-wrapper {
    width: 100%;
    max-width: var(--promptbar-max-width);
    background: var(--color-white);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(0, 0, 0, 0.06);
    padding: 4px 6px;
    display: flex;
    align-items: center;
    gap: 2px;
    transition: all var(--transition-fast);
    min-height: 44px;
}

.prompt-wrapper:focus-within {
    box-shadow: var(--shadow-lg);
    border-color: rgba(0, 0, 0, 0.12);
}

/* Search toggle (left) */
.prompt-icon-btn {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-gray-400);
    transition: all var(--transition-fast);
    position: relative;
}

.prompt-icon-btn:hover {
    background: var(--color-gray-100);
    color: var(--color-gray-700);
}

.prompt-icon-btn.active {
    color: var(--color-navy);
    background: rgba(10, 22, 40, 0.06);
}

/* Search tooltip */
.search-tooltip {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-gray-800);
    color: var(--color-white);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--transition-fast);
    z-index: 50;
}

.search-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--color-gray-800);
}

.prompt-icon-btn:hover .search-tooltip {
    opacity: 1;
}

/* Textarea */
.prompt-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 8px 4px;
    min-height: 20px;
    max-height: 120px;
    font-size: 14px;
    color: var(--color-gray-800);
    outline: none;
    resize: none;
    overflow: hidden;
    line-height: 1.45;
}

.prompt-input::placeholder {
    color: var(--color-gray-400);
}

/* Send button (right) */
.send-btn {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--color-navy);
    color: var(--color-white);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

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

.send-btn:disabled {
    background: var(--color-gray-300);
    cursor: not-allowed;
    transform: none;
}

/* Disclaimer — centered in the gap between prompt bar and screen bottom.
   prompt-area has 36px padding-bottom; disclaimer (~17px tall)
   is positioned so it sits in the vertical middle of that gap. */
.disclaimer {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 48px);
    max-width: var(--promptbar-max-width);
    font-size: 11px;
    color: var(--color-gray-400);
    text-align: center;
    line-height: 1.5;
    pointer-events: none;
}

/* --- City Modal --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 22, 40, 0.5);
    backdrop-filter: blur(6px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-card {
    width: min(720px, 90vw);
    max-height: 480px;
    background: var(--color-white);
    border-radius: var(--radius-lg);
    display: flex;
    overflow: hidden;
    box-shadow: var(--shadow-xl);
    animation: fadeInScale 0.3s ease;
}

.modal-list {
    width: 40%;
    padding: 32px;
    background: var(--color-cream);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.modal-title {
    font-family: var(--font-serif);
    font-size: 26px;
    font-style: italic;
    color: var(--color-navy);
    margin-bottom: 20px;
}

.modal-option {
    padding: 10px 14px;
    margin-bottom: 4px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    color: var(--color-gray-600);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all var(--transition-fast);
    cursor: pointer;
}

.modal-option:hover {
    background: rgba(0, 0, 0, 0.04);
    color: var(--color-navy);
}

.modal-option.selected {
    background: var(--color-navy);
    color: var(--color-white);
}

.modal-visual {
    width: 60%;
    position: relative;
    background: var(--color-navy);
    overflow: hidden;
}

.modal-visual img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    position: absolute;
    inset: 0;
    transition: opacity 0.5s;
}

.modal-visual img.active {
    opacity: 1;
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(4px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-white);
    cursor: pointer;
    z-index: 20;
    transition: background var(--transition-fast);
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.4);
}

/* --- Feedback Toast --- */
.feedback-toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--color-navy);
    color: var(--color-white);
    padding: 12px 20px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    z-index: 200;
}

.feedback-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}