/* ── Market Intelligence Page ──────────────────────────────────────────────── */

.mi-page {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 5rem);
    max-width: 900px;
    margin: 0 auto;
    padding: 0;
}

/* ── Header ─────────────────────────────────────────────── */
.mi-header {
    padding: 20px 0 16px;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}
.mi-header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.mi-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #111;
    margin: 0;
    letter-spacing: -0.02em;
}
.mi-subtitle {
    font-size: 0.82rem;
    color: #6b7280;
    margin: 2px 0 0;
}
.mi-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: #059669;
    font-weight: 500;
}
.mi-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #059669;
    animation: mi-pulse 2s infinite;
}
@keyframes mi-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ── Chat Container ─────────────────────────────────────── */
.mi-chat-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* ── Messages ───────────────────────────────────────────── */
.mi-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0;
    scroll-behavior: smooth;
}
.mi-messages::-webkit-scrollbar {
    width: 5px;
}
.mi-messages::-webkit-scrollbar-track {
    background: transparent;
}
.mi-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

/* ── Message ────────────────────────────────────────────── */
.mi-message {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    animation: mi-fadeIn 0.3s ease;
}
@keyframes mi-fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.mi-message-user {
    flex-direction: row-reverse;
}
.mi-message-user .mi-bubble {
    background: var(--gkcm-red);
    color: #fff;
    border-radius: 18px 18px 4px 18px;
    max-width: 70%;
}
.mi-message-user .mi-bubble .mi-text {
    font-size: 0.9rem;
    line-height: 1.5;
}

/* Avatar */
.mi-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1rem;
}
.mi-message-assistant .mi-avatar {
    background: linear-gradient(135deg, #C8102E, #8B0000);
    color: #fff;
}
.mi-message-user .mi-avatar {
    background: #e5e7eb;
    color: #374151;
}

/* Bubble */
.mi-bubble {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 18px 18px 18px 4px;
    padding: 14px 18px;
    max-width: 85%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.mi-sender {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #9ca3af;
    margin-bottom: 6px;
}
.mi-message-user .mi-sender {
    color: rgba(255,255,255,0.7);
}

/* Text content */
.mi-text {
    font-size: 0.88rem;
    line-height: 1.7;
    color: #1f2937;
}
.mi-text p {
    margin: 0 0 10px;
}
.mi-text p:last-child {
    margin-bottom: 0;
}
.mi-text strong {
    font-weight: 600;
    color: #111;
}
.mi-text ul, .mi-text ol {
    margin: 8px 0;
    padding-left: 20px;
}
.mi-text li {
    margin-bottom: 4px;
}
.mi-text h3, .mi-text h4 {
    font-size: 0.92rem;
    font-weight: 700;
    margin: 16px 0 6px;
    color: #111;
}
.mi-text h3:first-child, .mi-text h4:first-child {
    margin-top: 0;
}
.mi-text blockquote {
    border-left: 3px solid var(--gkcm-red);
    margin: 12px 0;
    padding: 8px 14px;
    background: #fef2f2;
    border-radius: 0 6px 6px 0;
    font-style: italic;
    color: #7f1d1d;
}
.mi-text code {
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.82rem;
}
.mi-text table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 0.82rem;
}
.mi-text table th,
.mi-text table td {
    border: 1px solid #e5e7eb;
    padding: 8px 10px;
    text-align: left;
}
.mi-text table th {
    background: #f9fafb;
    font-weight: 600;
}
.mi-text table tr:hover {
    background: #f9fafb;
}

/* ── Suggestions ────────────────────────────────────────── */
.mi-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}
.mi-suggestion-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 20px;
    padding: 7px 14px;
    font-size: 0.78rem;
    color: #374151;
    cursor: pointer;
    transition: all 0.15s;
    line-height: 1.3;
}
.mi-suggestion-btn:hover {
    background: #fff;
    border-color: var(--gkcm-red);
    color: var(--gkcm-red);
    box-shadow: 0 2px 6px rgba(200,16,46,0.12);
}
.mi-suggestion-btn i {
    font-size: 0.85rem;
}

/* ── Sources / Citations ────────────────────────────────── */
.mi-sources {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid #e5e7eb;
}
.mi-sources-title {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #9ca3af;
    margin-bottom: 8px;
}
.mi-source-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.76rem;
    color: var(--gkcm-red);
    text-decoration: none;
    margin-right: 12px;
    margin-bottom: 4px;
    padding: 3px 8px;
    background: #fef2f2;
    border-radius: 4px;
    transition: background 0.15s;
}
.mi-source-link:hover {
    background: #fecaca;
    color: var(--gkcm-dark-red);
}
.mi-source-link i {
    font-size: 0.7rem;
}

/* ── Thinking / Loading ─────────────────────────────────── */
.mi-thinking {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    color: #6b7280;
    padding: 6px 0;
}
.mi-thinking-dots {
    display: flex;
    gap: 4px;
}
.mi-thinking-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #9ca3af;
    animation: mi-bounce 1.4s infinite ease-in-out;
}
.mi-thinking-dots span:nth-child(1) { animation-delay: 0s; }
.mi-thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.mi-thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes mi-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}
.mi-thinking-label {
    transition: opacity 0.15s ease;
}
.mi-thinking-elapsed {
    font-size: 0.72rem;
    color: #9ca3af;
    font-variant-numeric: tabular-nums;
}

/* Blinking cursor at the end of streaming text */
.mi-stream-cursor {
    display: inline-block;
    width: 8px;
    height: 1em;
    margin-left: 2px;
    vertical-align: text-bottom;
    background: var(--gkcm-red);
    animation: mi-blink 1s steps(2) infinite;
    border-radius: 1px;
}
@keyframes mi-blink {
    0%, 50% { opacity: 1; }
    50.01%, 100% { opacity: 0; }
}

/* Spinning send button while a response is loading */
.mi-send-btn-loading i {
    animation: mi-spin 0.9s linear infinite;
}

.mi-search-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: #6b7280;
    background: #f3f4f6;
    padding: 5px 12px;
    border-radius: 12px;
    margin-bottom: 8px;
}
.mi-search-indicator i {
    color: var(--gkcm-red);
    animation: mi-spin 1.5s linear infinite;
}
@keyframes mi-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ── Input Area ─────────────────────────────────────────── */
.mi-input-area {
    padding: 16px 0 20px;
    border-top: 1px solid #e5e7eb;
    background: var(--gkcm-light-gray);
    flex-shrink: 0;
}
.mi-input-wrapper {
    max-width: 100%;
}
.mi-input-inner {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #fff;
    border: 1.5px solid #d1d5db;
    border-radius: 16px;
    padding: 8px 8px 8px 16px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.mi-input-inner:focus-within {
    border-color: var(--gkcm-red);
    box-shadow: 0 0 0 3px rgba(200,16,46,0.08);
}
.mi-input {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-size: 0.9rem;
    line-height: 1.5;
    color: #1f2937;
    background: transparent;
    min-height: 24px;
    max-height: 120px;
    font-family: inherit;
}
.mi-input::placeholder {
    color: #9ca3af;
}
.mi-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--gkcm-red);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    flex-shrink: 0;
    font-size: 1.1rem;
}
.mi-send-btn:hover {
    background: var(--gkcm-dark-red);
}
.mi-send-btn:active {
    transform: scale(0.95);
}
.mi-send-btn:disabled {
    background: #d1d5db;
    cursor: not-allowed;
}

.mi-input-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
    padding: 0 4px;
}
.mi-disclaimer {
    font-size: 0.7rem;
    color: #9ca3af;
}
.mi-clear-btn {
    background: none;
    border: none;
    font-size: 0.75rem;
    color: #9ca3af;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 6px;
    transition: color 0.15s, background 0.15s;
}
.mi-clear-btn:hover {
    color: #ef4444;
    background: #fef2f2;
}

/* ── Error state ────────────────────────────────────────── */
.mi-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 0.82rem;
    display: flex;
    align-items: center;
    gap: 8px;
}
.mi-error i {
    color: #ef4444;
    font-size: 1rem;
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
    .mi-page {
        height: calc(100vh - 4.5rem);
    }
    .mi-header {
        padding: 14px 0 12px;
    }
    .mi-title {
        font-size: 1.2rem;
    }
    .mi-subtitle {
        font-size: 0.75rem;
    }
    .mi-bubble {
        max-width: 90%;
        padding: 12px 14px;
    }
    .mi-message-user .mi-bubble {
        max-width: 80%;
    }
    .mi-suggestions {
        flex-direction: column;
    }
    .mi-suggestion-btn {
        width: 100%;
        justify-content: flex-start;
    }
    .mi-avatar {
        width: 30px;
        height: 30px;
        font-size: 0.85rem;
    }
    .mi-input-area {
        padding: 12px 0 16px;
    }
}

/* ── Markdown in responses ──────────────────────────────── */
.mi-text hr {
    border: none;
    border-top: 1px solid #e5e7eb;
    margin: 16px 0;
}
.mi-text a {
    color: var(--gkcm-red);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.mi-text a:hover {
    color: var(--gkcm-dark-red);
}
