/* ============================================================
   ZERETIS — AI CHAT PAGE STYLES (Light Theme)
   ============================================================ */

:root {
    --sidebar-w: 260px;
    --sidebar-bg: #f5f4fb;
    --chat-bg: #faf8ff;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

body.chat-page {
    font-family: 'Plus Jakarta Sans', sans-serif;
    background: var(--chat-bg);
    color: var(--ink);
    overflow: hidden;
}

/* ── HEADER overrides for chat page ── */
.app-header {
    background: var(--white);
    border-bottom: 1px solid var(--border-neutral);
}

/* ── LAYOUT ── */
.main-content-area {
    padding-top: var(--header-h);
    height: 100vh; width: 100%;
    display: flex; overflow: hidden;
}

/* ── SIDEBAR ── */
.sidebar {
    flex-shrink: 0;
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-neutral);
    display: flex; flex-direction: column;
    justify-content: space-between;
    transition: width 0.28s cubic-bezier(0.4,0,0.2,1);
    overflow: hidden;
}

.sidebar-top {
    padding: 16px 12px;
    overflow-y: auto; flex-grow: 1;
    scrollbar-width: thin;
    scrollbar-color: var(--grey-200) transparent;
}
.sidebar-top::-webkit-scrollbar { width: 3px; }
.sidebar-top::-webkit-scrollbar-thumb { background: var(--grey-200); border-radius: 2px; }

.sidebar-header {
    display: flex; align-items: center;
    justify-content: space-between;
    margin-bottom: 14px; padding: 0 4px;
}
.sidebar-header h2 {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.62rem; font-weight: 500;
    letter-spacing: 0.2em; text-transform: uppercase;
    color: var(--grey-400); margin: 0;
}

.collapse-btn {
    background: none; border: none;
    color: var(--grey-400); font-size: 0.85rem;
    cursor: pointer; padding: 6px 8px;
    transition: color 0.2s, background 0.2s, transform 0.3s cubic-bezier(0.4,0,0.2,1);
    line-height: 1; border-radius: 4px;
    flex-shrink: 0;
}
.collapse-btn:hover { color: var(--violet); background: var(--violet-glow); }

/* Rotate arrow when sidebar is collapsed */
.sidebar.collapsed .collapse-btn {
    transform: rotate(180deg);
}

button.new-chat-btn {
    display: none; background: none; border: none;
    color: var(--violet); font-size: 1.3rem;
    cursor: pointer; width: 100%; text-align: center;
    padding: 6px 0; transition: opacity 0.2s;
}
button.new-chat-btn:hover { opacity: 0.7; }

.chat-list { display: flex; flex-direction: column; gap: 2px; }

.chat-item {
    position: relative;
    display: flex; justify-content: space-between; align-items: center;
    padding: 9px 12px; border-radius: var(--radius-sm);
    cursor: pointer; font-size: 0.82rem;
    color: var(--grey-600); white-space: nowrap;
    overflow: hidden; transition: background 0.15s, color 0.15s;
}
.chat-item:hover { background: var(--grey-100); color: var(--ink); }
.chat-item.active { background: var(--violet-pale); color: var(--violet); font-weight: 600; }

.chat-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }

.chat-menu-btn {
    font-size: 1rem; font-weight: 700; transform: rotate(90deg);
    color: var(--violet); opacity: 0; flex-shrink: 0;
    padding: 0 2px; transition: opacity 0.15s;
}
.chat-item:hover .chat-menu-btn { opacity: 1; }

.chat-item.new-chat-btn {
    color: var(--violet); font-size: 0.8rem; font-weight: 600;
    justify-content: flex-start; gap: 8px; margin-top: 8px;
    border: 1.5px dashed var(--border);
    border-radius: var(--radius-sm);
}
.chat-item.new-chat-btn:hover { background: var(--violet-glow); }

.chat-rename-input {
    width: 100%; background: var(--white); border: 1.5px solid var(--violet);
    border-radius: 4px; color: var(--ink);
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 0.82rem; padding: 4px 8px; outline: none;
}

.sidebar-bottom {
    padding: 14px 16px;
    border-top: 1px solid var(--border-neutral);
    background: var(--sidebar-bg);
    flex-shrink: 0;
}

.account-section {
    display: flex; align-items: center; gap: 10px;
    cursor: pointer; padding: 8px; border-radius: var(--radius-md);
    transition: background 0.15s;
    overflow: hidden; /* prevent content bleeding when collapsed */
    min-width: 0;
}
.account-section:hover { background: var(--grey-100); }

.profile-pic {
    width: 34px; height: 34px; min-width: 34px; /* prevent squish */
    border-radius: 50%; object-fit: cover;
    border: 2px solid var(--violet-light);
    flex-shrink: 0;
}
.account-info {
    min-width: 0; /* allow text to truncate */
    overflow: hidden;
}
.account-name {
    font-size: 0.85rem; font-weight: 600; color: var(--ink);
    display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.account-settings { font-size: 0.72rem; color: var(--violet); display: block; }

.sidebar.collapsed { width: 58px; }
.sidebar.collapsed h2,
.sidebar.collapsed .chat-list,
.sidebar.collapsed .account-info { display: none; }
.sidebar.collapsed .collapse-btn { display: block; }
.sidebar.collapsed button.new-chat-btn { display: block; }

/* Collapsed sidebar bottom — center the profile pic */
.sidebar.collapsed .sidebar-bottom { padding: 10px 0; }
.sidebar.collapsed .account-section {
    justify-content: center;
    padding: 8px 0;
    gap: 0;
}
.sidebar.collapsed .profile-pic {
    margin: 0 auto;
}

/* ── CHAT CONTAINER ── */
.chat-container {
    flex-grow: 1; display: flex; flex-direction: column;
    background: var(--chat-bg); height: 100%; overflow: hidden;
}

.chat-box {
    flex-grow: 1; padding: 28px 32px 20px;
    overflow-y: auto; display: flex; flex-direction: column; gap: 4px;
    scrollbar-width: thin; scrollbar-color: var(--grey-200) transparent;
}
.chat-box::-webkit-scrollbar { width: 4px; }
.chat-box::-webkit-scrollbar-thumb { background: var(--grey-200); border-radius: 2px; }

/* ── MESSAGES ── */
.message {
    max-width: 72%; padding: 12px 18px; word-wrap: break-word;
    line-height: 1.65; font-size: 0.88rem;
    animation: msgIn 0.2s ease forwards;
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.user-message {
    align-self: flex-end;
    background: var(--violet);
    color: white;
    border-radius: 18px 18px 4px 18px;
    box-shadow: 0 2px 10px rgba(109,40,217,0.2);
    margin-bottom: 6px;
}

.ai-message {
    align-self: flex-start;
    background: var(--white);
    color: var(--ink);
    border-radius: 4px 18px 18px 18px;
    border: 1px solid var(--border-neutral);
    box-shadow: var(--shadow-sm);
    margin-bottom: 14px;
}

/* ── AI RESPONSE INNER ── */
.ai-response-container { display: flex; flex-direction: column; gap: 12px; }
.ai-response-container > p { color: var(--grey-600); font-size: 0.82rem; }

.solution-section { border-left: 3px solid var(--violet-light); padding-left: 14px; }
.solution-section > p { font-family: 'JetBrains Mono', monospace; font-size: 0.68rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--violet); margin-bottom: 8px; font-weight: 500; }

.math-block, .step-math {
    background: var(--off-white); border: 1px solid var(--border-neutral);
    border-radius: var(--radius-sm); padding: 12px 16px; overflow-x: auto; font-size: 0.95rem;
}

.steps-container { display: flex; flex-direction: column; gap: 8px; }
.step-item { background: var(--grey-50); border: 1px solid var(--border-neutral); border-radius: var(--radius-sm); padding: 10px 14px; }
.step-item > p { font-size: 0.8rem; color: var(--grey-600); margin-bottom: 8px; }
.step-item > p strong { font-family: 'JetBrains Mono', monospace; color: var(--violet); font-size: 0.7rem; letter-spacing: 0.06em; }

/* ── INPUT ── */
.input-container-wrapper {
    padding: 12px 24px 16px;
    background: var(--white);
    border-top: 1px solid var(--border-neutral);
}

.input-container {
    display: flex; align-items: flex-end; gap: 10px;
    background: var(--off-white); border: 1.5px solid var(--border-neutral);
    border-radius: 14px; padding: 10px 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.input-container:focus-within { border-color: var(--violet); box-shadow: 0 0 0 3px rgba(109,40,217,0.08); background: var(--white); }

#user-input {
    flex: 1; background: transparent; border: none; outline: none;
    color: var(--ink); font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 0.9rem; resize: none; height: 40px; max-height: 160px; line-height: 1.5; padding: 6px 0;
}
#user-input::placeholder { color: var(--grey-400); }

#send-button {
    flex-shrink: 0; background: var(--violet); color: white; border: none;
    width: 38px; height: 38px; border-radius: 10px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s, transform 0.15s;
    box-shadow: 0 2px 8px rgba(109,40,217,0.2);
}
#send-button:hover { background: var(--violet-mid); transform: scale(1.05); }
#send-button:disabled { background: var(--grey-200); cursor: not-allowed; transform: none; box-shadow: none; }

.input-hint { font-size: 0.68rem; color: var(--grey-400); text-align: center; margin-top: 8px; font-family: 'JetBrains Mono', monospace; letter-spacing: 0.04em; }

/* ── MODAL OVERLAY ── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(26,23,48,0.4); backdrop-filter: blur(4px);
    z-index: 9999; display: none;
    align-items: center; justify-content: center;
}
.modal-overlay.active { display: flex; }

.modal-dashboard {
    background: var(--white); border: 1px solid var(--border-neutral);
    border-radius: var(--radius-lg); display: flex;
    width: 720px; max-width: 95vw; max-height: 85vh;
    overflow: hidden; box-shadow: var(--shadow-lg);
    animation: modalIn 0.22s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.96) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }

.modal-sidebar {
    width: 200px; flex-shrink: 0;
    background: var(--grey-50); border-right: 1px solid var(--border-neutral);
    display: flex; flex-direction: column; padding: 24px 0;
}
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 0 20px 20px; border-bottom: 1px solid var(--border-neutral); margin-bottom: 12px; }
.mini-profile-pic { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; border: 2px solid var(--violet-light); }
.sidebar-user span { font-size: 0.85rem; font-weight: 600; color: var(--ink); }

.settings-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; flex: 1; }
.nav-item {
    background: none; border: none; color: var(--grey-600);
    padding: 10px 12px; border-radius: var(--radius-sm);
    text-align: left; font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 0.82rem; font-weight: 500; cursor: pointer; transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--grey-100); color: var(--ink); }
.nav-item.active { background: var(--violet-pale); color: var(--violet); font-weight: 600; }

.close-dashboard {
    margin: 16px 10px 0; background: none; border: 1px solid var(--border-neutral);
    border-radius: var(--radius-sm); color: var(--grey-600); padding: 9px 12px;
    font-family: 'Plus Jakarta Sans', sans-serif; font-size: 0.82rem;
    cursor: pointer; transition: border-color 0.2s, color 0.2s;
}
.close-dashboard:hover { border-color: var(--grey-400); color: var(--ink); }

.modal-main { flex: 1; overflow-y: auto; padding: 28px 32px; }
.setting-section { display: none; }
.setting-section.active { display: block; animation: fadeIn 0.2s ease; }
.setting-section h2 { font-family: 'Nunito', sans-serif; font-size: 1.15rem; font-weight: 900; color: var(--ink); margin-bottom: 22px; padding-bottom: 12px; border-bottom: 1px solid var(--border-neutral); }

.control-group { display: flex; flex-direction: column; gap: 7px; margin-bottom: 18px; }
.control-group label { font-family: 'JetBrains Mono', monospace; font-size: 0.62rem; letter-spacing: 0.15em; text-transform: uppercase; color: var(--grey-400); }
.control-group select, .setting-section select {
    background: var(--off-white); border: 1.5px solid var(--border-neutral);
    border-radius: var(--radius-sm); color: var(--ink);
    font-family: 'Plus Jakarta Sans', sans-serif; font-size: 0.85rem;
    padding: 10px 14px; outline: none; cursor: pointer; transition: border-color 0.2s; width: 100%;
}
.control-group select:focus, .setting-section select:focus { border-color: var(--violet); }

.slider { -webkit-appearance: none; width: 100%; height: 4px; background: var(--grey-100); border-radius: 2px; outline: none; margin: 16px 0 10px; }
.slider::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--violet); cursor: pointer; border: 2px solid white; box-shadow: 0 1px 4px rgba(109,40,217,0.3); transition: transform 0.15s; }
.slider::-webkit-slider-thumb:hover { transform: scale(1.2); }
.slider-label { font-family: 'JetBrains Mono', monospace; font-size: 0.75rem; color: var(--violet); }

.danger-btn {
    background: transparent; border: 1.5px solid rgba(220,38,38,0.3);
    color: #dc2626; font-family: 'Plus Jakarta Sans', sans-serif; font-size: 0.82rem;
    font-weight: 600; padding: 10px 18px; border-radius: var(--radius-sm);
    cursor: pointer; margin-top: 18px; transition: background 0.2s, border-color 0.2s;
}
.danger-btn:hover { background: rgba(220,38,38,0.06); border-color: #dc2626; }

.license-card {
    background: var(--off-white); border: 1px solid var(--border-neutral);
    border-radius: var(--radius-md); padding: 18px 20px; display: flex; flex-direction: column; gap: 10px;
}
.license-card p { font-size: 0.82rem; color: var(--grey-600); }
.license-card strong { font-family: 'JetBrains Mono', monospace; font-size: 0.68rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--violet); }
.license-card code { font-family: 'JetBrains Mono', monospace; font-size: 0.75rem; background: var(--grey-100); padding: 2px 6px; border-radius: 4px; color: var(--grey-600); }

/* ── CONFIRM MODAL ── */
.modal-box {
    background: var(--white); border: 1px solid var(--border-neutral);
    padding: 28px; border-radius: var(--radius-md); z-index: 10000;
    position: relative; min-width: 300px; box-shadow: var(--shadow-lg); animation: modalIn 0.2s ease;
}
.modal-box p { margin: 0 0 22px; font-size: 0.9rem; color: var(--grey-800); line-height: 1.6; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.modal-btn { padding: 9px 20px; border: none; border-radius: var(--radius-sm); cursor: pointer; font-family: 'Plus Jakarta Sans', sans-serif; font-size: 0.82rem; font-weight: 600; transition: background 0.2s, transform 0.15s; }
.modal-confirm { background: #dc2626; color: white; }
.modal-confirm:hover { background: #b91c1c; transform: translateY(-1px); }
.modal-cancel { background: var(--grey-100); color: var(--grey-600); }
.modal-cancel:hover { background: var(--grey-200); color: var(--ink); }

/* ── CHAT CONTEXT MENU ── */
.chat-menu-dropdown {
    position: absolute; right: 0; top: 100%;
    background: var(--white); border: 1px solid var(--border-neutral);
    border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
    z-index: 1000; overflow: hidden; min-width: 140px; animation: fadeIn 0.15s ease;
}
.chat-menu-dropdown button { display: block; width: 100%; padding: 10px 16px; border: none; background: none; text-align: left; font-family: 'Plus Jakarta Sans', sans-serif; font-size: 0.82rem; font-weight: 500; cursor: pointer; transition: background 0.15s, color 0.15s; color: var(--grey-600); }
.chat-menu-dropdown button:first-child { color: var(--violet); }
.chat-menu-dropdown button:first-child:hover { background: var(--violet-glow); }
.chat-menu-dropdown button:last-child { color: #dc2626; }
.chat-menu-dropdown button:last-child:hover { background: rgba(220,38,38,0.06); }

/* ── PRICING ── */
.pricing-container {
    display: flex; gap: 10px; padding: 12px 20px;
    background: var(--white); border-top: 1px solid var(--border-neutral);
}
.tier {
    flex: 1; background: var(--grey-50); border: 1px solid var(--border-neutral);
    border-radius: var(--radius-md); padding: 12px 18px;
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.tier h3 { font-family: 'Nunito', sans-serif; font-size: 0.85rem; font-weight: 900; color: var(--grey-800); margin: 0; }
.tier p { font-size: 0.8rem; color: var(--grey-400); margin: 0; flex: 1; }
.tier button { padding: 7px 16px; border-radius: var(--radius-sm); font-family: 'Plus Jakarta Sans', sans-serif; font-size: 0.75rem; font-weight: 600; cursor: pointer; border: 1px solid var(--border-neutral); background: var(--grey-100); color: var(--grey-400); transition: all 0.2s; }
.tier button:disabled { cursor: default; opacity: 0.6; }
.tier.pro { border-color: var(--border); background: var(--violet-pale); }
.tier.pro h3 { color: var(--violet); }
.tier.pro p { color: var(--grey-600); }
.tier.pro button { background: var(--violet); border-color: var(--violet); color: white; box-shadow: 0 2px 8px rgba(109,40,217,0.2); }
.tier.pro button:hover { background: var(--violet-mid); }

/* ── KATEX ── */
.katex { color: var(--ink); font-size: 1em; }
.math-block .katex-display, .step-math .katex-display { margin: 0; overflow-x: auto; }

/* ══════════════════════════════════════════
   MOBILE STYLES — CHAT PAGE
   Breakpoints: 768px (tablet), 480px (phone)
══════════════════════════════════════════ */

@media (max-width: 768px) {
    /* ── Menu button touch target ── */
    #menu-button {
        font-size: 1.4rem;
        padding: 8px 10px;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* ── Sidebar: hidden by default on mobile, slides in as overlay ── */
    .sidebar {
        position: fixed;
        top: var(--header-h);
        left: 0;
        bottom: 0;
        z-index: 150;
        width: 280px !important;
        transform: translateX(-100%);
        transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
        box-shadow: 4px 0 24px rgba(26,23,48,0.12);
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    /* Sidebar overlay backdrop */
    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        top: var(--header-h);
        background: rgba(26,23,48,0.3);
        z-index: 149;
    }

    .sidebar-backdrop.active { display: block; }

    /* ── Chat container takes full width ── */
    .chat-container { width: 100%; }

    /* ── Chat box padding ── */
    .chat-box { padding: 16px 14px 14px; }

    /* ── Message bubbles ── */
    .message { max-width: 90%; font-size: 0.9rem; }

    /* ── Input area ── */
    .input-container-wrapper { padding: 10px 12px 12px; }

    .input-container { padding: 8px 12px; border-radius: 12px; }

    #user-input {
        font-size: 1rem; /* prevent iOS zoom on focus */
        height: 38px;
    }

    #send-button {
        width: 42px;
        height: 42px;
        min-width: 42px;
        border-radius: 10px;
    }

    .input-hint { font-size: 0.62rem; }

    /* ── Pricing strip — stack vertically ── */
    .pricing-container {
        flex-direction: column;
        gap: 8px;
        padding: 10px 12px;
    }

    .tier {
        padding: 10px 14px;
        flex-wrap: nowrap;
        gap: 8px;
    }

    .tier p { display: none; } /* hide description on mobile for space */

    /* ── Modal ── */
    .modal-dashboard {
        flex-direction: column;
        width: 96vw;
        max-height: 90vh;
        border-radius: var(--radius-md);
    }

    .modal-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-neutral);
        padding: 16px 0 10px;
    }

    .settings-nav {
        flex-direction: row;
        overflow-x: auto;
        padding: 0 12px;
        gap: 4px;
        scrollbar-width: none;
    }

    .settings-nav::-webkit-scrollbar { display: none; }

    .nav-item {
        white-space: nowrap;
        padding: 8px 12px;
        font-size: 0.78rem;
    }

    .sidebar-user { padding: 0 16px 14px; }

    .close-dashboard { margin: 10px 12px 0; }

    .modal-main { padding: 20px; }

    /* ── Collapse btn hidden on mobile (sidebar is overlay) ── */
    .collapse-btn { display: none; }

    /* Chat item touch targets */
    .chat-item { min-height: 42px; padding: 10px 12px; }
}

@media (max-width: 480px) {
    .chat-box { padding: 12px 10px 10px; }
    .message { max-width: 95%; padding: 10px 14px; }
    .input-container-wrapper { padding: 8px 10px 10px; }

    /* Pricing: just show name and button */
    .tier { justify-content: space-between; }
}

