/* ── Reset & Base ────────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #0d0f14;
    --surface: #161b22;
    --surface2: #1c2230;
    --border: #2a3342;
    --accent: #4f8ef7;
    --accent-glow: #4f8ef730;
    --green: #22c55e;
    --text: #e2e8f0;
    --text-dim: #8896a7;
    --text-faint: #4a5568;
    --danger: #ef4444;
    --gold: #f59e0b;
    --radius: 12px;
    --header-h: 60px;
    --sidebar-w: 260px;
}

html,
body {
    height: 100%;
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
}

.hidden {
    display: none !important;
}

/* ── Scrollbar ───────────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

/* ── Header ──────────────────────────────────────────────────── */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    backdrop-filter: blur(10px);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    font-size: 24px;
}

.logo-text {
    display: flex;
    flex-direction: column;
}

.logo-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.1;
}

.logo-sub {
    font-size: 11px;
    color: var(--text-dim);
}

.ai-status {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #1a2a1a;
    border: 1px solid #2d4a2d;
    border-radius: 20px;
    padding: 4px 10px;
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 6px var(--green);
    animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {

    0%,
    100% {
        opacity: 1;
        box-shadow: 0 0 6px var(--green);
    }

    50% {
        opacity: 0.7;
        box-shadow: 0 0 12px var(--green);
    }
}

.ai-label {
    font-size: 12px;
    color: var(--green);
    font-weight: 500;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ── Google Sign-In Button ───────────────────────────────────── */
.btn-google-signin {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #fff;
    color: #1a1a1a;
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.btn-google-signin:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    transform: translateY(-1px);
}

.btn-google-signin.large {
    padding: 14px 28px;
    font-size: 16px;
    border-radius: 12px;
    width: 100%;
    justify-content: center;
}

/* ── User Menu ───────────────────────────────────────────────── */
.user-menu {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
}

.user-menu:hover {
    background: var(--surface2);
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid var(--border);
}

.user-name {
    font-size: 14px;
    font-weight: 500;
}

.chevron {
    font-size: 10px;
    color: var(--text-dim);
}

.user-dropdown {
    position: absolute;
    top: 110%;
    right: 0;
    min-width: 200px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    z-index: 200;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.user-dropdown .dropdown-email {
    font-size: 12px;
    color: var(--text-dim);
    padding: 4px 8px;
}

.user-dropdown .dropdown-tier {
    font-size: 12px;
    font-weight: 700;
    padding: 2px 8px 8px;
}

.user-dropdown hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 4px 0;
}

.user-dropdown button {
    width: 100%;
    background: none;
    border: none;
    color: var(--text);
    text-align: left;
    padding: 8px;
    font-size: 13px;
    cursor: pointer;
    border-radius: 6px;
}

.user-dropdown button:hover {
    background: var(--surface);
}

.usage-badge {
    font-size: 12px;
    color: var(--text-dim);
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 4px 10px;
}

/* ── Login Wall ──────────────────────────────────────────────── */
.login-wall {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: radial-gradient(ellipse at center, #1a2035 0%, #0d0f14 70%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 48px 40px;
    max-width: 420px;
    width: 100%;
    text-align: center;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
}

.login-icon {
    font-size: 56px;
    margin-bottom: 16px;
}

.login-card h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 12px;
}

.login-card p {
    color: var(--text-dim);
    font-size: 15px;
    margin-bottom: 24px;
    line-height: 1.6;
}

.login-features {
    text-align: left;
    margin-bottom: 28px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.feature-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    color: var(--text-dim);
}

.login-legal {
    font-size: 12px;
    color: var(--text-faint);
    margin-top: 14px;
}

/* ── App Layout ──────────────────────────────────────────────── */
.app-layout {
    display: flex;
    height: 100vh;
    padding-top: var(--header-h);
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 13px;
    color: var(--text-dim);
}

.btn-new-chat {
    background: var(--accent);
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s;
}

.btn-new-chat:hover {
    opacity: 0.85;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.history-empty {
    color: var(--text-faint);
    font-size: 13px;
    text-align: center;
    padding: 24px 12px;
}

.history-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.15s;
    border: 1px solid transparent;
}

.history-item:hover {
    background: var(--surface2);
    border-color: var(--border);
    color: var(--text);
}

/* ── Chat Main ───────────────────────────────────────────────── */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

/* ── Ad Banner ───────────────────────────────────────────────── */
.ad-banner {
    background: var(--surface2);
    border-bottom: 1px solid var(--border);
    padding: 8px 20px;
    text-align: center;
}

.ad-placeholder {
    font-size: 12px;
    color: var(--text-faint);
}

.ad-placeholder a {
    color: var(--accent);
    text-decoration: none;
}

/* ── Chat Messages ───────────────────────────────────────────── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 40px;
}

.welcome-icon {
    font-size: 56px;
    margin-bottom: 20px;
}

.welcome-screen h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}

.welcome-sub {
    color: var(--text-dim);
    font-size: 15px;
    margin-bottom: 32px;
}

.suggested-questions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    max-width: 600px;
}

.suggestion-btn {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text-dim);
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.suggestion-btn:hover {
    border-color: var(--accent);
    color: var(--text);
    background: var(--accent-glow);
}

/* ── Message Bubbles ─────────────────────────────────────────── */
.message {
    display: flex;
    flex-direction: column;
    max-width: 780px;
    width: 100%;
    margin: 0 auto;
}

.message.user {
    align-items: flex-end;
}

.message.assistant {
    align-items: flex-start;
}

.bubble {
    padding: 14px 18px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.75;
    max-width: 85%;
}

.message.user .bubble {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message.assistant .bubble {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
    color: var(--text);
}

.bubble strong {
    font-weight: 600;
}

.bubble br+br {
    display: none;
}

/* ── Answer Content Formatting ───────────────────────────────── */
.bubble p {
    margin: 3px 0;
    line-height: 1.7;
}

.bubble .ans-topic {
    font-weight: 700;
    color: var(--text);
    margin: 24px 0 5px;
    font-size: 14px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.bubble .ans-gap {
    height: 6px;
}

.bubble ul {
    margin: 4px 0 6px 16px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    list-style: disc;
}

.bubble ol.roman {
    margin: 4px 0 6px 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
    list-style: none;
    counter-reset: roman-cnt;
}

.bubble ol.roman li {
    counter-increment: roman-cnt;
    display: flex;
    gap: 6px;
}

.bubble ol.roman li::before {
    content: counter(roman-cnt, lower-roman) ".";
    color: var(--accent);
    font-weight: 600;
    min-width: 22px;
    flex-shrink: 0;
}

.bubble li {
    line-height: 1.65;
}

.message-meta {
    font-size: 11px;
    color: var(--text-faint);
    margin-top: 6px;
    padding: 0 4px;
}

.cache-badge {
    display: inline-block;
    background: #1a3a1a;
    border: 1px solid #2d5a2d;
    color: var(--green);
    font-size: 11px;
    border-radius: 20px;
    padding: 2px 8px;
    margin-left: 6px;
}

.ai-badge {
    display: inline-block;
    background: #1a2a3a;
    border: 1px solid #2d4a6a;
    color: var(--accent);
    font-size: 11px;
    border-radius: 20px;
    padding: 2px 8px;
    margin-left: 6px;
}

/* Sources */
.sources-section {
    margin-top: 12px;
}

.sources-toggle {
    font-size: 12px;
    color: var(--accent);
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
}

.sources-list {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.source-link {
    font-size: 12px;
    color: var(--text-dim);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 6px;
}

.source-link:hover {
    color: var(--accent);
}

/* Videos */
.videos-section {
    margin-top: 8px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.video-card {
    font-size: 12px;
    color: var(--accent);
    text-decoration: none;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 10px;
}

.video-card:hover {
    border-color: var(--accent);
}

/* Typing indicator */
.typing-bubble {
    display: flex;
    gap: 5px;
    padding: 16px 18px;
}

.typing-dot {
    width: 7px;
    height: 7px;
    background: var(--text-dim);
    border-radius: 50%;
    animation: bounce 1.2s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-6px);
    }
}

/* Upgrade prompt inline */
.upgrade-prompt {
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    border: 1px solid #4f8ef750;
    border-radius: 12px;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.upgrade-prompt p {
    font-size: 14px;
    color: var(--text-dim);
    flex: 1;
}

.btn-upgrade-inline {
    background: linear-gradient(135deg, var(--accent), #6f6ef7);
    border: none;
    color: #fff;
    font-weight: 600;
    font-size: 13px;
    padding: 8px 18px;
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity 0.2s;
}

.btn-upgrade-inline:hover {
    opacity: 0.9;
}

.btn-upgrade-inline.small {
    padding: 5px 12px;
    font-size: 12px;
}

/* Similar questions list */
.similar-header {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dim);
    margin-bottom: 12px;
}

.similar-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 260px;
    overflow-y: auto;
    margin-bottom: 12px;
}

.similar-q-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    text-align: left;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    white-space: normal;
    line-height: 1.4;
}

.similar-q-btn:hover {
    border-color: var(--accent);
    background: var(--accent-glow);
    color: var(--text);
}

.similar-footer {
    font-size: 12px;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Not found message */
.not-found-msg {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
    padding: 8px 0;
}

.not-found-icon {
    font-size: 32px;
}

.not-found-msg p {
    font-size: 14px;
    color: var(--text-dim);
    max-width: 420px;
    line-height: 1.6;
}

/* ── Input Area ──────────────────────────────────────────────── */
.input-area {
    padding: 16px 20px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 10px 10px 10px 16px;
    transition: border-color 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--accent);
}

#question-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    resize: none;
    max-height: 160px;
    line-height: 1.5;
}

#question-input::placeholder {
    color: var(--text-faint);
}

.send-btn {
    background: var(--accent);
    border: none;
    color: #fff;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s;
    flex-shrink: 0;
}

.send-btn:hover {
    opacity: 0.85;
}

.send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    padding: 0 4px;
}

.footer-note {
    font-size: 11px;
    color: var(--text-faint);
}

.usage-note {
    font-size: 11px;
    color: var(--text-dim);
}

/* ── Upgrade Modal ───────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 300;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 40px;
    max-width: 400px;
    width: 100%;
    text-align: center;
    position: relative;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.7);
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 20px;
    cursor: pointer;
}

.modal-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.modal-card h2 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 10px;
}

.modal-card p {
    color: var(--text-dim);
    font-size: 14px;
    margin-bottom: 20px;
    line-height: 1.6;
}

.pro-features {
    text-align: left;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 24px;
}

.pro-features li {
    font-size: 14px;
    color: var(--text-dim);
}

.pro-price {
    margin-bottom: 20px;
}

.price-amount {
    font-size: 42px;
    font-weight: 800;
    color: var(--text);
}

.price-period {
    font-size: 16px;
    color: var(--text-dim);
}

.btn-upgrade {
    width: 100%;
    background: linear-gradient(135deg, var(--accent), #6f6ef7);
    border: none;
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    padding: 14px;
    border-radius: 12px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.btn-upgrade:hover {
    opacity: 0.9;
}

.modal-legal {
    font-size: 12px;
    color: var(--text-faint);
    margin-top: 12px;
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 640px) {
    .sidebar {
        display: none;
    }

    .logo-title {
        font-size: 14px;
    }

    .user-name {
        display: none;
    }

    .usage-badge {
        display: none;
    }
}