/* ========================================
   Main Chat Area
   ======================================== */
#main {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    min-width: 0;
}

/* --- Main Header --- */
.main-header {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    gap: 10px;
    width: 100%;
    box-sizing: border-box;
    z-index: 10;
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    /* border-bottom removed — clean look */
    min-height: 48px;
}

/* --- Model Selector Wrapper & Trigger --- */
.model-select-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
    max-width: 280px;
    height: 36px;
    z-index: 100;

    /* Theme variables scoped for Model Selector (Pearl / Light by default) */
    --amc-bg-trigger: transparent;
    --amc-bg-trigger-hover: #ECECF1;
    --amc-bg-dropdown: #f9f9f9;
    --amc-border: #D9D9E3;
    --amc-border-hover: #D9D9E3;
    --amc-text-primary: #000000;
    --amc-text-secondary: #000000;
    --amc-text-tertiary: #666666;
    --amc-selected-accent: #2563eb;
    --amc-shadow: var(--shadow-lg), 0 10px 30px rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] .model-select-wrapper {
    /* Onyx / Dark theme values */
    --amc-bg-trigger: transparent;
    --amc-bg-trigger-hover: #18181b;
    --amc-bg-dropdown: #000000;
    --amc-border: #18181b;
    --amc-border-hover: #27272a;
    --amc-text-primary: #f4f4f5;
    --amc-text-secondary: #a1a1aa;
    --amc-text-tertiary: #52525b;
    --amc-selected-accent: #38bdf8;
    --amc-shadow: var(--shadow-xl), 0 10px 40px rgba(0, 0, 0, 0.4);
}

.model-select-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    height: 36px;
    border-radius: 12px;
    border: 1px solid transparent;
    background-color: var(--amc-bg-trigger);
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    color: var(--amc-text-primary);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    user-select: none;
}

.model-select-trigger:hover {
    border-color: var(--amc-border);
    background-color: var(--amc-bg-trigger-hover);
}

.model-select-trigger:focus-visible,
.model-select-wrapper.open .model-select-trigger {
    outline: none;
    border-color: var(--amc-border-hover);
    background-color: var(--amc-bg-trigger-hover);
    box-shadow: 0 0 0 2px var(--amc-bg-dropdown), 0 0 0 4px var(--amc-border-hover);
}

.model-select-wrapper .model-chevron-svg {
    color: var(--amc-text-tertiary);
    flex-shrink: 0;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.model-select-wrapper.open .model-chevron-svg {
    transform: rotate(180deg);
}

.model-select-current-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
    font-weight: 600;
}

/* --- Model Dropdown Popover --- */
.model-dropdown-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    width: max-content;
    min-width: 280px;
    max-width: 320px;
    max-height: 384px;
    overflow-y: auto;
    background-color: var(--amc-bg-dropdown);
    border: 1px solid var(--amc-border);
    border-radius: 12px;
    box-shadow: var(--amc-shadow);
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    opacity: 0;
    transform: scale(0.95) translateY(-5px);
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1000;
}

.model-dropdown-menu.active {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
}

/* Custom Scrollbar for Dropdown Menu */
.model-dropdown-menu::-webkit-scrollbar {
    width: 6px;
}

.model-dropdown-menu::-webkit-scrollbar-track {
    background: transparent;
}

.model-dropdown-menu::-webkit-scrollbar-thumb {
    background-color: var(--amc-border);
    border-radius: 10px;
}

.model-dropdown-menu::-webkit-scrollbar-thumb:hover {
    background-color: var(--amc-border-hover);
}

/* --- Dropdown Items --- */
.model-dropdown-item {
    display: flex;
    align-items: start;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--amc-text-primary);
    font-size: 14px;
    cursor: pointer;
    user-select: none;
    transition: all 0.15s ease;
    outline: none;
    gap: 10px;
    border: 1px solid transparent;
    background-color: transparent;
}

.model-dropdown-item:hover,
.model-dropdown-item:focus-visible,
.model-dropdown-item.highlighted {
    background-color: var(--amc-bg-trigger-hover);
    border-color: var(--amc-border-hover);
}

.model-dropdown-item.selected {
    background-color: rgba(236, 236, 241, 0.6);
    border-color: var(--amc-border);
}

[data-theme="dark"] .model-dropdown-item.selected {
    background-color: rgba(24, 24, 27, 0.6);
    border-color: var(--amc-border-hover);
}

/* Option left block layout */
.model-item-left {
    display: flex;
    align-items: start;
    gap: 10px;
    min-width: 0;
    flex-grow: 1;
    overflow: hidden;
}

.model-item-icon-wrapper {
    margin-top: 2px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.model-item-icon-svg {
    flex-shrink: 0;
    transition: color 0.15s ease;
}

/* Provider Icon Tints */
.model-item-icon-svg.icon-gemini {
    color: #0ea5e9; /* Sky 500 */
}

.model-item-icon-svg.icon-gpt-claude {
    color: #8b5cf6; /* Violet 500 */
}

.model-item-icon-svg.icon-other {
    color: var(--amc-text-tertiary);
    opacity: 0.7;
}

.model-item-details {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex-grow: 1;
}

.model-item-name {
    font-weight: 500;
    color: var(--amc-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.model-dropdown-item.selected .model-item-name {
    font-weight: 600;
    color: var(--amc-selected-accent);
}

.model-item-id {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: var(--amc-text-tertiary);
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Option right block layout */
.model-item-right {
    display: flex;
    align-items: center;
    align-self: center;
    flex-shrink: 0;
    padding-left: 6px;
}

.model-item-right .check-icon {
    color: var(--amc-selected-accent);
    display: none;
}

.model-dropdown-item.selected .model-item-right .check-icon {
    display: block;
}

.model-select {
    display: none !important;
}

/* --- Chat Container --- */
#chat-container {
    flex-grow: 1;
    overflow-y: auto;
    padding: 24px 5%;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding-bottom: 24px;
    scroll-behavior: smooth;
}

/* ========================================
   Hero Section
   ======================================== */
.hero-container {
    text-align: center;
    margin: auto;
    color: var(--text-primary);
    max-width: 680px;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px 20px;
}

.hero-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-bottom: 12px;
}

.hero-brand-logo {
    width: min(420px, 82vw);
    height: 108px;
    object-fit: cover;
    object-position: center;
    border-radius: var(--radius-md);
}

.hero-brand-logo-light {
    background: #ffffff;
}

.hero-brand-logo-dark {
    display: none;
    background: transparent;
    object-fit: contain;
}

[data-theme="dark"] .hero-brand-logo-light {
    display: none;
}

[data-theme="dark"] .hero-brand-logo-dark {
    display: block;
}

.hero-logo {
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: float 3s ease-in-out infinite;
}

.hero-logo span {
    font-size: 28px;
    color: white;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

.hero-title {
    font-size: 2.5rem;
    font-weight: 800;
    margin: 0;
    letter-spacing: 0;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--text-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero-subtitle {
    font-size: 1.05rem;
    color: var(--text-secondary);
    margin-top: 12px;
    line-height: 1.6;
    max-width: 480px;
}

/* ========================================
   Messages
   ======================================== */
.message {
    display: block;
    max-width: 1056px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    margin-top: 24px;
    padding-inline: 0;
    position: relative;
    animation: messageIn 0.3s ease;
}

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

.message.grouped {
    margin-top: 6px;
}

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

.message-row {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    width: 100%;
}

.message.user .message-row {
    justify-content: flex-end;
}

.message.assistant .message-row,
.message.error .message-row {
    justify-content: flex-start;
}

.message-side {
    position: sticky;
    top: 16px;
    z-index: 10;
    flex: 0 0 40px;
    width: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    align-self: flex-start;
    min-height: 40px;
}

.message-avatar {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--text-primary);
}

.message.grouped .message-avatar {
    visibility: hidden;
}

.message-avatar img {
    width: 29px;
    height: 29px;
    display: block;
    object-fit: contain;
}

.message-avatar .material-symbols-rounded {
    font-size: 29px;
    line-height: 1;
}

.assistant-avatar {
    color: var(--primary);
}

.user-avatar {
    color: var(--text-primary);
}

.error-avatar {
    color: var(--error);
}

.message-content {
    position: relative;
    min-width: 0;
    max-width: 100%;
    padding: 16px 20px;
    border: 1px solid transparent;
    border-radius: 16px;
    color: var(--amc-message-model-text);
    line-height: 1.5;
    font-size: 15px;
    letter-spacing: 0;
    word-break: break-word;
    overflow-wrap: anywhere;
    transition: background-color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.message-content-container {
    max-width: 100%;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* --- Message Side Actions --- */
.message-action-rail {
    position: static;
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: center;
    margin-top: 4px;
    opacity: 0;
    pointer-events: none;
    transform: translateY(4px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.message:hover .message-action-rail,
.message:focus-within .message-action-rail {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.message-action-btn,
.copy-btn,
.regenerate-btn,
.edit-message-btn,
.msg-delete-btn {
    width: 30px;
    height: 30px;
    background-color: var(--amc-message-action-bg);
    border: 0;
    color: var(--amc-message-action-text);
    cursor: pointer;
    padding: 0;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.86;
    transition: opacity 0.16s ease, background-color var(--transition-fast), color var(--transition-fast), transform 0.16s ease;
    box-shadow: none;
}

.message-action-btn:hover,
.copy-btn:hover,
.regenerate-btn:hover,
.edit-message-btn:hover,
.msg-delete-btn:hover {
    background-color: var(--amc-message-action-hover-bg);
    color: var(--text-primary);
    opacity: 1;
    transform: translateY(-1px);
}

.msg-delete-btn:hover {
    color: var(--amc-message-action-danger);
    background-color: var(--error-light);
}

.message-action-btn:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
    opacity: 1;
}

.message-action-btn.is-success,
.copy-btn.is-success {
    color: var(--success);
    background-color: var(--success-light);
    opacity: 1;
}

.message-action-btn span,
.copy-btn span,
.regenerate-btn span,
.edit-message-btn span,
.msg-delete-btn span {
    font-size: 16px;
}

/* --- User Message --- */
.message.user .message-content {
    width: fit-content;
    max-width: 80%;
    padding: 16px 20px;
    background: var(--amc-message-user-bg);
    color: var(--amc-message-user-text);
    border-color: transparent;
    border-radius: 16px;
    border-top-right-radius: 4px;
    box-shadow: var(--shadow-sm);
    font-weight: 400;
    line-height: 1.5;
}

.message-user-text {
    white-space: pre-wrap;
}

/* --- Assistant Message --- */
.message.assistant .message-content {
    background-color: var(--amc-message-model-bg);
    width: 100%;
    max-width: calc(100% - 56px);
    padding: 0;
    border-radius: 0;
    box-shadow: none;
}

.message.error .message-content {
    width: fit-content;
    max-width: 80%;
    background: var(--error-light);
    color: var(--error);
    border-color: transparent;
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
}

.message-answer-body {
    width: 100%;
    min-width: 0;
}

.message-content.is-collapsible.is-collapsed .message-user-text {
    max-height: calc(1.5em * 8);
    overflow: hidden;
}

.message-content.is-collapsible.is-expanded .message-user-text {
    max-height: none;
}

.message-collapse-toggle {
    margin-top: 8px;
    padding: 0;
    border: 0;
    background: transparent;
    color: currentColor;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    opacity: 0.78;
    transition: opacity var(--transition-fast);
}

.message-collapse-toggle:hover {
    opacity: 1;
}

.message-collapse-toggle .material-symbols-rounded {
    font-size: 16px;
    line-height: 1;
}

/* ========================================
   Log Container
   ======================================== */
.log-container.visible {
    display: block;
}

.log-container {
    --thought-border: color-mix(in srgb, var(--border) 86%, transparent);
    --thought-border-active: color-mix(in srgb, var(--border) 58%, var(--text-muted));
    --thought-bg: color-mix(in srgb, var(--bg-elevated) 90%, var(--bg-secondary));
    --thought-bg-open: color-mix(in srgb, var(--bg-secondary) 72%, var(--bg-elevated));
    position: relative;
    margin-bottom: 8px;
    border: 1px solid var(--thought-border);
    border-radius: 14px;
    overflow: hidden;
    max-width: 100%;
    width: 100%;
    background:
        linear-gradient(180deg, color-mix(in srgb, var(--bg-elevated) 74%, transparent), transparent 58%),
        var(--thought-bg);
    box-shadow: 0 1px 2px color-mix(in srgb, #000 5%, transparent);
    transition:
        background-color var(--transition-smooth),
        border-color var(--transition-smooth),
        box-shadow var(--transition-smooth);
}

.log-container:not(.completed),
.log-container:has(.log-details.open) {
    border-color: var(--thought-border-active);
    background:
        linear-gradient(180deg, color-mix(in srgb, var(--bg-elevated) 86%, transparent), transparent 62%),
        var(--thought-bg-open);
    box-shadow:
        0 1px 2px color-mix(in srgb, #000 5%, transparent),
        inset 0 1px 0 color-mix(in srgb, #fff 58%, transparent);
}

.log-container:not(.completed)::after {
    content: '';
    position: absolute;
    top: 0;
    left: -34%;
    width: 34%;
    height: 1px;
    pointer-events: none;
    background: linear-gradient(
        90deg,
        transparent,
        color-mix(in srgb, var(--text-muted) 42%, transparent),
        transparent
    );
    animation: amcThoughtSweep 2.4s cubic-bezier(0.16, 1, 0.3, 1) infinite;
}

.log-summary {
    position: relative;
    padding: 8px 12px;
    background-color: transparent;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
    transition: background-color var(--transition-fast);
    font-weight: 550;
    border-radius: 13px;
    min-height: 42px;
}

.log-summary:hover {
    background-color: color-mix(in srgb, var(--bg-input) 42%, transparent);
}

.log-summary:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: -2px;
}

.log-status-left {
    display: flex;
    align-items: center;
    gap: 9px;
    overflow: hidden;
    flex: 1;
    min-width: 0;
}

.log-spinner {
    width: 22px;
    height: 22px;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--primary);
    flex-shrink: 0;
    border-radius: var(--radius-full);
    transition: color var(--transition-smooth), background-color var(--transition-smooth);
}

.material-symbols-rounded.log-spinner {
    display: inline-flex;
}

.log-spinner.rotating {
    color: transparent;
    font-size: 0;
    background: transparent;
    box-shadow: none;
}

.log-spinner.rotating::before {
    content: '';
    position: absolute;
    inset: 2px;
    display: block;
    border-radius: var(--radius-full);
    background: conic-gradient(
        from 218deg,
        transparent 0deg,
        transparent 38deg,
        #00d1ff 46deg,
        #6978ff 116deg,
        #b15cff 178deg,
        #ff5ab3 236deg,
        #ff8a3d 292deg,
        #ffd166 310deg,
        transparent 326deg,
        transparent 360deg
    );
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 1.7px));
    mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 1.7px));
    animation: amcThinkingSpin 0.82s linear infinite;
}

.log-spinner.completed {
    color: var(--success);
    background: color-mix(in srgb, var(--success-light) 72%, transparent);
}

.log-status-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 620;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.35;
}

.expand-icon {
    color: var(--text-muted);
    transition: transform var(--transition-smooth);
    flex-shrink: 0;
    margin-left: 8px;
}

.expand-icon.expanded {
    transform: rotate(180deg);
}

.log-details {
    background-color: transparent;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 11.5px;
    color: var(--text-secondary);
    max-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    transition: all var(--transition-smooth);
    padding: 0 12px;
    opacity: 0;
}

.log-details.open {
    padding: 8px 10px 10px;
    max-height: 400px;
    opacity: 1;
    border-top: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
    background-color: color-mix(in srgb, var(--bg-input) 28%, transparent);
}

.log-entry {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr);
    gap: 7px;
    margin-bottom: 3px;
    align-items: flex-start;
    line-height: 1.5;
    padding: 5px 7px;
    border: 1px solid color-mix(in srgb, var(--border) 42%, transparent);
    border-radius: 7px;
    min-width: 0;
    color: var(--text-secondary);
    background-color: color-mix(in srgb, var(--bg-elevated) 42%, transparent);
}

.log-entry:last-child {
    margin-bottom: 0;
}

.log-entry span {
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: break-word;
}

.log-entry-dot {
    width: 5px;
    height: 5px;
    margin-top: 0.55em;
    border-radius: 999px;
    background-color: var(--text-muted);
    opacity: 0.8;
}

.log-entry-message {
    min-width: 0;
}

.log-entry.log-search {
    background-color: color-mix(in srgb, var(--bg-elevated) 45%, transparent);
}

.log-entry.log-crawl {
    background-color: color-mix(in srgb, var(--bg-elevated) 45%, transparent);
}

.log-entry.log-analysis {
    background-color: color-mix(in srgb, var(--bg-elevated) 45%, transparent);
}

.log-entry.log-error {
    background-color: var(--error-light);
    color: var(--error);
}

.log-entry.log-search .log-entry-dot {
    background-color: var(--primary);
}

.log-entry.log-crawl .log-entry-dot {
    background-color: var(--success);
}

.log-entry.log-analysis .log-entry-dot {
    background-color: #8b5cf6;
}

.log-entry.log-error .log-entry-dot {
    background-color: var(--error);
}

.log-timestamp {
    color: var(--text-muted);
    font-size: 11px;
    min-width: 60px;
    opacity: 0.7;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.rotating {
    animation: none;
}

@keyframes amcThinkingSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes amcThoughtSweep {
    0% { transform: translateX(0); opacity: 0; }
    16% { opacity: 1; }
    78% { opacity: 1; }
    100% { transform: translateX(395%); opacity: 0; }
}
