/* ============================================================
   STEM Copilot — Stylesheet
   Montserrat, dark/light theme, premium chat UI
   Theme: Dark=#EC642B, Light=#2C2872
   ============================================================ */

/* ── CSS Variables ─────────────────────────────────────────── */

:root {
    --brand: #EC642B;
    --brand-hover: #d4561f;
    --brand-glow: rgba(236, 100, 43, 0.25);
    --bg-main: #000000;
    --bg-sidebar: #0a0a0a;
    --bg-input: #1a1a1a;
    --bg-hover: #1f1f1f;
    --bg-card: #141414;
    --bg-elevated: #1c1c1c;
    --text-primary: #ececec;
    --text-secondary: #888888;
    --text-muted: #555555;
    --border-color: #262626;
    --border-subtle: #1e1e1e;
    --msg-user: #2a2a2a;
    --msg-ai: transparent;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --transition: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    --sidebar-width: 280px;
    --rail-width: 56px;
    --topbar-height: 60px;
}

/* ── Light Mode ── */
[data-theme="light"] {
    --brand: #2C2872;
    --brand-hover: #221f5e;
    --brand-glow: rgba(44, 40, 114, 0.25);
    --bg-main: #f8f9fa;
    --bg-sidebar: #ffffff;
    --bg-input: #ffffff;
    --bg-hover: #f0f0f0;
    --bg-card: #ffffff;
    --bg-elevated: #f5f5f5;
    --text-primary: #1a1a1a;
    --text-secondary: #555555;
    --text-muted: #999999;
    --border-color: #e0e0e0;
    --border-subtle: #eeeeee;
    --msg-user: #e8f0fe;
    --msg-ai: transparent;
}


/* ── Reset & Base ─────────────────────────────────────────── */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    touch-action: manipulation;
    overscroll-behavior: none;
    overflow-x: hidden;
}

body {
    font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    overflow-x: hidden;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
    transition: background-color 0.35s ease, color 0.35s ease;
}

/* Smooth theme transitions */
*, *::before, *::after {
    transition: background-color 0.35s ease, color 0.35s ease, border-color 0.35s ease, box-shadow 0.35s ease, fill 0.35s ease, stroke 0.35s ease;
}

textarea, input, select {
    transition: background-color 0.35s ease, color 0.35s ease, border-color 0.35s ease, box-shadow 0.35s ease;
}


/* ============================================================
   LOGIN SCREEN
   ============================================================ */

.login-screen {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: var(--bg-main);
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-top-actions {
    position: fixed;
    top: 14px;
    right: 16px;
    z-index: 1100;
    display: flex;
    gap: 8px;
}

.login-theme-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.login-theme-btn:hover {
    transform: scale(1.1);
}

.login-theme-btn svg {
    width: 20px;
    height: 20px;
    stroke: var(--text-secondary);
    fill: none;
    stroke-width: 2;
    transition: stroke 0.3s;
}

.login-theme-btn:hover svg {
    stroke: var(--brand);
}

.login-theme-btn .icon-sun { display: block; }
.login-theme-btn .icon-moon { display: none; }
[data-theme="light"] .login-theme-btn .icon-sun { display: none; }
[data-theme="light"] .login-theme-btn .icon-moon { display: block; }

.login-card {
    text-align: center;
    max-width: 400px;
    padding: 48px 36px;
}

.login-logo-stembotix {
    height: 48px;
    margin-bottom: 32px;
    object-fit: contain;
}

.login-title {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text-primary);
    white-space: nowrap;
}

.login-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 32px;
    line-height: 1.6;
}

.google-btn-wrap {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}

.gsi-custom-btn {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 12px 28px;
    color: var(--text-primary);
    font-family: 'Montserrat', sans-serif;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.3s, border-color 0.3s, transform 0.1s;
    white-space: nowrap;
}

.gsi-custom-btn:hover {
    background: var(--bg-hover);
    border-color: var(--brand);
}

.gsi-custom-btn:active {
    transform: scale(0.97);
}

.login-footer {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 16px;
}

.terms-link {
    color: #EC642B;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: opacity 0.2s;
}

.terms-link:hover { opacity: 0.8; }

[data-theme="light"] .terms-link { color: #2C2872; }


/* ============================================================
   BYOK ONBOARDING
   ============================================================ */

.byok-screen {
    position: fixed;
    inset: 0;
    z-index: 999;
    background: var(--bg-main);
    display: flex;
    align-items: center;
    justify-content: center;
}

.byok-card {
    text-align: center;
    width: 100%;
    max-width: 440px;
    padding: 48px 36px;
}

/* On wider screens, give the card room and place the two key fields side-by-side. */
@media (min-width: 760px) {
    .byok-card {
        max-width: 860px;
        padding: 52px 56px;
    }
    .byok-card h2 { font-size: 26px; }
    .byok-fields-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 18px;
        align-items: stretch;
    }
    .byok-fields-grid .byok-field { margin-top: 0; }
    .byok-submit-btn { max-width: 360px; margin-left: auto; margin-right: auto; }
}

.byok-card h2 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 12px;
}

.byok-desc {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 20px;
}

.byok-steps {
    text-align: left;
    padding-left: 20px;
    margin-bottom: 24px;
    font-size: 14px;
    line-height: 2;
    color: var(--text-secondary);
}

.byok-steps a { color: var(--brand); text-decoration: none; }
.byok-steps a:hover { text-decoration: underline; }

.byok-submit-btn {
    width: 100%;
    padding: 14px;
    margin-top: 16px;
    background: var(--brand);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.byok-submit-btn:hover { background: var(--brand-hover); }

.byok-note {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 12px;
}

/* Optional Tavily key block on the BYOK screen */
.byok-optional {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    text-align: left;
}
.byok-optional-label {
    font-size: 13px;
    font-weight: 600;
    margin: 0 0 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.byok-optional-badge,
.settings-optional-badge {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--brand);
    background: color-mix(in srgb, var(--brand) 14%, transparent);
    padding: 2px 7px;
    border-radius: 999px;
}
.byok-optional-desc {
    font-size: 12px;
    color: var(--text-muted);
    margin: 0 0 10px;
}
.byok-optional-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 8px;
}
.byok-optional-hint a { color: var(--brand); text-decoration: none; }
.byok-optional-hint a:hover { text-decoration: underline; }

/* ── Student-friendly BYOK fields ── */
.byok-card {
    max-height: 92vh;
    overflow-y: auto;
}
.byok-desc { text-align: left; }
.byok-desc strong { color: var(--text-primary); }

.byok-field {
    text-align: left;
    margin-top: 18px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--text-primary) 3%, transparent);
}
.byok-field-optional { background: transparent; }

.byok-field-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 700;
    margin: 0 0 6px;
}
.byok-step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}
.byok-required-badge {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #fff;
    background: var(--brand);
    padding: 2px 7px;
    border-radius: 999px;
}
.byok-field-help {
    font-size: 12.5px;
    color: var(--text-secondary);
    line-height: 1.55;
    margin: 0 0 12px;
}
.byok-field-help code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    background: color-mix(in srgb, var(--text-primary) 10%, transparent);
    padding: 1px 5px;
    border-radius: 5px;
}

/* Prominent, obviously-clickable "get your key" link button */
.byok-get-link {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    padding: 11px 14px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--brand);
    text-decoration: underline;
    text-underline-offset: 3px;
    background: color-mix(in srgb, var(--brand) 10%, transparent);
    border: 1px solid color-mix(in srgb, var(--brand) 35%, transparent);
    border-radius: var(--radius);
    transition: background 0.2s, border-color 0.2s;
}
.byok-get-link svg { width: 16px; height: 16px; flex-shrink: 0; }
.byok-get-link:hover {
    background: color-mix(in srgb, var(--brand) 18%, transparent);
    border-color: var(--brand);
}

/* Disabled web-search toggle (no Tavily key) */
.web-search-disabled {
    opacity: 0.45;
    cursor: not-allowed;
}


/* ============================================================
   PWA INSTALL BANNER
   ============================================================ */

.install-banner {
    position: fixed;
    bottom: calc(24px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    z-index: 1050;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
    max-width: 400px;
    width: calc(100% - 32px);
    animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.install-banner-icon { width: 36px; height: 36px; border-radius: 8px; }

.install-banner-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    font-size: 13px;
    line-height: 1.4;
}

.install-banner-text strong { color: var(--text-primary); }
.install-banner-text span { color: var(--text-secondary); font-size: 11px; }

.install-banner-btn {
    background: var(--brand);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.install-banner-btn:hover { background: var(--brand-hover); }

.install-banner-dismiss {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 0 4px;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}


/* ============================================================
   MOBILE TOP NAV BAR
   ============================================================ */

.mobile-topbar {
    display: none; /* shown via media query */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border-color);
    z-index: 100;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
}

.topbar-profile-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
}

.topbar-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border-color);
    transition: border-color 0.2s;
}

.topbar-profile-btn:hover .topbar-avatar,
.topbar-profile-btn:active .topbar-avatar {
    border-color: var(--brand);
}

.topbar-logo {
    height: 30px;
    max-width: 38vw;
    object-fit: contain;
    flex-shrink: 0;
}

.topbar-actions {
    display: flex;
    gap: 2px;
}

.topbar-icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.topbar-icon-btn:hover,
.topbar-icon-btn:active {
    background: var(--bg-hover);
    color: var(--brand);
}


/* ============================================================
   FULL-SCREEN OVERLAYS (Account & History — Mobile)
   ============================================================ */

.fullscreen-overlay {
    position: fixed;
    inset: 0;
    z-index: 500;
    background: var(--bg-main);
    display: none;
    flex-direction: column;
    animation: overlaySlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.fullscreen-overlay.open {
    display: flex;
}

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

.overlay-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.overlay-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.overlay-close-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--bg-hover);
    color: var(--text-primary);
    font-size: 22px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.overlay-close-btn:hover {
    background: var(--brand);
    color: #fff;
}

.overlay-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

/* Account overlay */
.overlay-user-info {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    margin-bottom: 20px;
}

.overlay-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--brand);
}

.overlay-user-details {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.overlay-user-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.overlay-user-email {
    font-size: 12px;
    color: var(--text-secondary);
}

.overlay-menu {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.overlay-menu-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    border-radius: var(--radius);
    border: none;
    background: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    width: 100%;
    text-align: left;
    transition: background 0.2s, color 0.2s;
}

.overlay-menu-item:hover,
.overlay-menu-item:active {
    background: var(--bg-hover);
    color: var(--brand);
}

.overlay-menu-item svg {
    opacity: 0.6;
    flex-shrink: 0;
}

.overlay-menu-item:hover svg { opacity: 1; }

.overlay-menu-logout {
    color: #ff4a4a;
    border-top: 1px solid var(--border-subtle);
    margin-top: 8px;
    padding-top: 16px;
    border-radius: 0 0 var(--radius) var(--radius);
}

.overlay-menu-logout:hover { color: #ff4a4a; background: rgba(255, 74, 74, 0.06); }

/* History overlay */
.overlay-history-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.overlay-history-item {
    padding: 10px 14px;
    border-radius: 10px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    transition: background 0.2s, color 0.2s;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
    position: relative;
}

.overlay-history-main {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
    cursor: pointer;
}

/* Kebab ⋮ menu trigger — always visible */
.overlay-kebab-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    font-size: 18px;
    line-height: 1;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.overlay-kebab-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Context menu that appears below the kebab */
.overlay-ctx-menu {
    display: none;
    position: absolute;
    right: 8px;
    top: calc(100% + 2px);
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.35);
    z-index: 210;
    min-width: 140px;
    overflow: hidden;
    animation: fadeIn 0.12s ease-out;
}

.overlay-ctx-menu.show { display: block; }

.overlay-ctx-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 16px;
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    border: none;
    background: none;
    width: 100%;
    font-family: inherit;
    text-align: left;
}

.overlay-ctx-option:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.overlay-ctx-option.danger:hover {
    color: #ff4a4a;
}

.overlay-ctx-option svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    flex-shrink: 0;
}

.overlay-history-item:hover,
.overlay-history-item:active {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.overlay-history-item.active {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.overlay-history-item svg {
    flex-shrink: 0;
    opacity: 0.4;
}

.overlay-history-item.active svg {
    opacity: 0.8;
    color: var(--brand);
}

.overlay-history-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.overlay-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: 14px;
}


/* ============================================================
   APP CONTAINER
   ============================================================ */

.app-container {
    display: flex;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    overflow-x: hidden;
}


/* ============================================================
   SIDEBAR (desktop only)
   ============================================================ */

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    transition: margin-left 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    z-index: 20;
}

.sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-width));
    opacity: 0;
    pointer-events: none;
}

.sidebar-top {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-logo-row {
    padding: 18px 18px 8px;
    display: flex;
    align-items: center;
}

.sidebar-logo {
    height: 44px;
    object-fit: contain;
}

/* New chat btn — no orange gradient */
.new-chat-btn {
    margin: 8px 14px;
    padding: 12px 16px;
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    transition: background 0.3s, border-color 0.3s, box-shadow 0.3s;
}

.new-chat-btn:hover {
    background: var(--bg-elevated);
    border-color: var(--brand);
    box-shadow: 0 0 12px var(--brand-glow);
}

.new-chat-btn svg {
    color: var(--brand);
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 6px 10px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.history-item {
    position: relative;
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.2s, color 0.2s, transform 0.15s;
}

.history-item.menu-active {
    z-index: 99 !important;
}

.history-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.history-item:active { transform: scale(0.98); }

.history-item.active {
    background: var(--bg-hover);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.history-item:not(.active) { border: 1px solid transparent; }

.thread-icon { flex-shrink: 0; opacity: 0.4; width: 16px; height: 16px; }
.history-item.active .thread-icon { opacity: 0.8; color: var(--brand); }

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

.options-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    padding: 0 4px;
    flex-shrink: 0;
    transition: opacity 0.2s, color 0.2s;
}

.history-item:hover .options-btn, .options-btn.menu-open { opacity: 1; }
.options-btn:hover { color: var(--text-primary); }

.options-menu {
    position: absolute;
    right: 10px;
    top: 40px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    display: none;
    flex-direction: column;
    z-index: 100;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    min-width: 130px;
    overflow: hidden;
}

.options-menu.show { display: flex; }

.option-item {
    padding: 10px 14px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s;
}

.option-item:hover { background: var(--bg-hover); }
.option-item.delete { color: #ff4a4a; }

.rename-input {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
    outline: none;
    border-bottom: 1px solid var(--brand);
    padding: 2px 0;
}

/* Sidebar bottom */
.sidebar-bottom {
    padding: 12px 14px 16px;
    border-top: 1px solid var(--border-color);
    position: relative;
}

.user-profile-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s;
    border: 1px solid transparent;
}

.user-profile-btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-color);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
}

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--bg-hover);
    border: 2px solid var(--border-color);
    transition: border-color 0.2s;
}

.user-profile-btn:hover .user-avatar { border-color: var(--brand); }

.user-name {
    flex: 1;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-menu {
    display: none;
    position: absolute;
    bottom: 72px;
    left: 14px;
    right: 14px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    z-index: 50;
    backdrop-filter: blur(12px);
}

.user-menu.show { display: block; animation: fadeIn 0.15s ease-out; }

.user-menu-item {
    padding: 12px 18px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background 0.2s, color 0.2s;
    color: var(--text-primary);
}

.user-menu-item:hover { background: var(--bg-hover); color: var(--brand); }
.user-menu-item svg { opacity: 0.6; transition: opacity 0.2s; }
.user-menu-item:hover svg { opacity: 1; }

.user-menu-logout { color: #ff4a4a; border-top: 1px solid var(--border-subtle); }
.user-menu-logout:hover { color: #ff4a4a; background: rgba(255, 74, 74, 0.06); }


/* ============================================================
   SIDEBAR RAIL (collapsed — desktop only)
   ============================================================ */

.sidebar-rail {
    width: var(--rail-width);
    flex-shrink: 0;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: none;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    z-index: 20;
}

.sidebar-rail.visible { display: flex; }

.rail-top, .rail-bottom {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.rail-icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.rail-icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.rail-logo { width: 34px; height: 34px; border-radius: 6px; object-fit: contain; }
.rail-avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; background: var(--bg-hover); }


/* ============================================================
   MAIN CHAT AREA
   ============================================================ */

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

.main-header {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    z-index: 10;
}

.toggle-sidebar-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s, color 0.2s;
}

.toggle-sidebar-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.chat-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 64px 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    scroll-behavior: smooth;
}


/* ============================================================
   HERO / WELCOME SCREEN
   ============================================================ */

.hero-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 20px;
    user-select: none;
    padding: 40px 20px;
}

.hero-bot-icon {
    width: 160px;
    height: 160px;
    object-fit: contain;
    filter: drop-shadow(0 8px 24px var(--brand-glow));
}

.hero-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    text-align: center;
    line-height: 1.3;
}

.hero-title .hero-name { color: var(--brand); }

.hero-input-wrap {
    width: 100%;
    max-width: 640px;
}

/* Image chip preview inside hero */
.hero-image-preview {
    display: none;
    gap: 6px;
    margin-bottom: 4px;
    flex-wrap: wrap;
    padding: 0 2px;
}

.hero-image-preview.visible { display: flex; }

.hero-image-preview-thumb {
    display: none; /* replaced by .image-chip-thumb inside */
}

.hero-image-preview-remove {
    display: none; /* replaced by .image-chip-remove inside */
}

.hero-input-box {
    display: flex;
    align-items: flex-end;
    background: var(--bg-input);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-xl);
    transition: border-color 0.3s, box-shadow 0.3s;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
    position: relative; /* Fixed: Absolute attach menu is positioned relative to this box */
}

.hero-input-box:focus-within {
    border-color: var(--text-secondary);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

.hero-input-box textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    padding: 16px 12px;
    font-family: inherit;
    font-size: 15px;
    resize: none;
    outline: none;
    height: 54px;
    max-height: 120px;
    line-height: 1.5;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.hero-input-box textarea::placeholder { color: var(--text-muted); }


/* ============================================================
   MESSAGES
   ============================================================ */

.message-row {
    display: flex;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    animation: fadeIn 0.35s ease-out forwards;
}

.message-row.user { justify-content: flex-end; flex-direction: column; align-items: flex-end; }
.message-row.ai { justify-content: flex-start; }

/* User text preserves the line breaks / indentation the student typed */
.user .message-content .user-text { white-space: pre-wrap; }

.message-content {
    padding: 14px 18px;
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
    overflow-wrap: break-word;
}

.user .message-content {
    max-width: 75%;
    background: var(--msg-user);
    border-bottom-right-radius: 4px;
    color: var(--text-primary);
    margin-left: auto; /* pushes bubble right in any flex container */
}

.ai .message-content { max-width: 100%; background: var(--msg-ai); }

.ai-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background-image: url('/assets/bot.png');
    background-size: cover;
    background-position: center;
    margin-right: 14px;
    flex-shrink: 0;
    margin-top: 4px;
}

.ai-avatar.pulsing { animation: avatarPulse 1.5s ease-in-out infinite; }

@keyframes avatarPulse {
    0%, 100% { opacity: 0.6; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.05); }
}

/* Thinking indicator — bouncing dots */
.thinking-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 0;
    animation: fadeIn 0.3s ease-out;
}

.thinking-indicator.hidden { display: none; }

.thinking-text { display: none; }

.thinking-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}

.thinking-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: dotBounce 1.4s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.16s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.32s; }

@keyframes dotBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Rendered markdown */
.message-content h1, .message-content h2, .message-content h3 {
    margin-top: 16px;
    margin-bottom: 8px;
    font-weight: 600;
}

.message-content h1 { font-size: 1.25em; }
.message-content h2 { font-size: 1.12em; }
.message-content h3 { font-size: 1.05em; }
.message-content p { margin-bottom: 10px; }
.message-content ul, .message-content ol { margin: 8px 0 8px 20px; }
.message-content li { margin-bottom: 4px; }

.message-content code {
    background: rgba(0, 0, 0, 0.15);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.88em;
}

[data-theme="light"] .message-content code { background: rgba(0, 0, 0, 0.06); }

.message-content pre {
    background: #111;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 14px;
    overflow-x: auto;
    margin: 10px 0;
}

[data-theme="light"] .message-content pre { background: #f5f5f5; }
.message-content pre code { background: none; padding: 0; }

.message-content table {
    border-collapse: collapse;
    margin: 10px 0;
    width: max-content;
    min-width: 100%;
}

/* Wrap tables in a scrollable container via JS — but also handle raw tables */
.message-content .table-scroll-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 10px 0;
    width: 100%;
}

.message-content .table-scroll-wrap table {
    margin: 0;
}

.message-content th, .message-content td {
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    text-align: left;
    font-size: 14px;
    white-space: nowrap;
}

.message-content th { background: var(--bg-input); font-weight: 600; }

.message-content blockquote {
    border-left: 3px solid var(--brand);
    padding-left: 12px;
    margin: 10px 0;
    color: var(--text-secondary);
}

.katex { color: var(--text-primary); }
.katex-display { margin: 14px 0; overflow-x: auto; }
.message-image { max-width: 240px; border-radius: 8px; margin-bottom: 8px; }


/* ============================================================
   AI MESSAGE ACTION BAR
   ============================================================ */

.msg-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    padding-top: 6px;
    opacity: 1;
}

.msg-action-btn {
    background: none;
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    padding: 0;
    font-size: 0;
    color: var(--text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.msg-action-btn:hover {
    background: var(--bg-hover);
    color: var(--brand);
}

.msg-action-btn svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; }

/* User-message action bar sits below the bubble, right-aligned */
.message-row.user .msg-actions { margin-top: 4px; padding-top: 0; justify-content: flex-end; }

/* ── Regenerate menu (Try again / Customize) ── */
.regen-wrap { position: relative; display: inline-flex; }

.regen-menu {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    min-width: 220px;
    background: var(--bg-elevated, var(--msg-ai));
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 6px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
    display: none;
    flex-direction: column;
    gap: 2px;
    z-index: 60;
}
.regen-menu.show { display: flex; }

.regen-menu button {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    font-family: inherit;
    background: none;
    border: none;
    border-radius: 8px;
    padding: 8px 10px;
    cursor: pointer;
    text-align: left;
    color: var(--text-primary);
}
.regen-menu button:hover { background: var(--bg-hover); }
.regen-menu button strong { font-size: 13px; font-weight: 600; }
.regen-menu button span { font-size: 11px; color: var(--text-muted); }

/* ── Attach-menu: label + info icon with tooltip ── */
.attach-menu-item .attach-menu-label { flex: 1; text-align: left; }

.attach-info {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    color: var(--text-muted);
    cursor: help;
    flex-shrink: 0;
}
.attach-info:hover { color: var(--brand); }
.attach-info svg { width: 15px; height: 15px; }

.attach-info::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 8px);
    right: -4px;
    width: 220px;
    background: var(--bg-elevated, #1c1c1e);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 11px;
    line-height: 1.45;
    font-weight: 400;
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.4);
    opacity: 0;
    visibility: hidden;
    transform: translateY(4px);
    transition: opacity 0.15s ease, transform 0.15s ease;
    z-index: 70;
    pointer-events: none;
    white-space: normal;
}
.attach-info:hover::after,
.attach-info:focus::after,
.attach-info.show-tip::after {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Mobile: keep the tooltip fully on-screen (it used to overflow the edge). */
@media (max-width: 768px) {
    .attach-info::after {
        width: max-content;
        max-width: calc(100vw - 32px);
        right: -8px;
    }
}

/* ── API-keys settings: grouped sections ── */
.apikey-group { margin-bottom: 26px; }
.apikey-group .settings-hint { margin-top: 2px; margin-bottom: 10px; }

/* ── Inline tool progress (in conversation, below the user bubble) ── */
.inline-tool-progress {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 6px 0 2px;
    max-width: 280px;
}
.inline-tool-label { font-size: 12px; color: var(--text-muted); }
.inline-tool-track {
    position: relative;
    height: 4px;
    border-radius: 999px;
    background: var(--bg-hover);
    overflow: hidden;
}
.inline-tool-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 40%;
    border-radius: 999px;
    background: var(--brand);
    animation: inlineToolSlide 1.1s ease-in-out infinite;
}
@keyframes inlineToolSlide {
    0%   { left: -40%; width: 40%; }
    50%  { width: 55%; }
    100% { left: 100%; width: 40%; }
}


/* ============================================================
   INPUT AREA (bottom bar during chat)
   ============================================================ */

.input-container {
    padding: 16px 20px 10px;
    /* Transparent surround so conversation text remains visible behind/around the
       input bar; only a soft fade at the very bottom keeps text legible under it. */
    background: linear-gradient(180deg, transparent 0%, transparent 55%, color-mix(in srgb, var(--bg-main) 70%, transparent) 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 10;
}

.image-preview-bar {
    max-width: 800px;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
    flex-wrap: wrap;
    padding: 0 4px;
}

.image-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 4px 8px 4px 4px;
    max-width: 200px;
    transition: border-color 0.2s;
}

.image-chip:hover {
    border-color: var(--brand);
}

.image-chip-thumb {
    width: 32px;
    height: 32px;
    border-radius: 5px;
    background-size: cover;
    background-position: center;
    flex-shrink: 0;
}

.image-chip-name {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100px;
}

.image-chip-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.2s, background-color 0.2s;
}

.image-chip-remove:hover {
    color: #ff4a4a;
    background-color: rgba(255, 74, 74, 0.1);
}

.input-box {
    width: 100%;
    max-width: 800px;
    position: relative;
    display: flex;
    align-items: flex-end;
    background: var(--bg-input);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-xl);
    transition: border-color 0.3s, box-shadow 0.3s;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

.input-box:focus-within {
    border-color: var(--text-secondary);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

/* Search-mode chip — clear, dismissible "Web Search is on" indicator above the
   input. The outer row matches the input box's centered max-width so the pill
   lines up with the input's left edge instead of drifting to the page edge. */
.search-mode-chip {
    display: flex;
    justify-content: flex-start;
    align-self: center;
    width: 100%;
    max-width: 800px;
    margin: 0 auto 8px;
    padding: 0 4px;
}
.search-mode-chip-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 6px 5px 11px;
    font-size: 12px;
    font-weight: 500;
    color: var(--brand);
    background: color-mix(in srgb, var(--brand) 12%, transparent);
    border: 1px solid color-mix(in srgb, var(--brand) 35%, transparent);
    border-radius: 999px;
}
.search-mode-chip-pill > svg { width: 14px; height: 14px; }
.search-mode-chip-x {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.15s, background-color 0.15s;
}
.search-mode-chip-x svg { width: 12px; height: 12px; }
.search-mode-chip-x:hover { color: #ff4a4a; background: rgba(255, 74, 74, 0.12); }

.upload-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 16px 4px 16px 16px;
    display: flex;
    align-items: center;
    transition: color 0.2s;
}

.upload-btn:hover { color: var(--text-primary); }

/* Teaching style selector */
.style-selector-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.style-selector-btn {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 6px 10px;
    font-size: 11px;
    font-family: inherit;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
    margin-bottom: 12px;
}

.style-selector-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--brand);
}

.style-selector-btn svg {
    width: 12px;
    height: 12px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    transition: transform 0.2s;
}

.style-selector-btn.open svg { transform: rotate(180deg); }

.style-dropdown {
    display: none;
    position: absolute;
    bottom: 44px;
    right: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    z-index: 100;
    min-width: 240px;
    max-height: 280px;
    overflow-y: auto;
    animation: fadeIn 0.15s ease-out;
}

.style-dropdown.show { display: block; }

.style-option {
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid var(--border-subtle);
}

.style-option:last-child { border-bottom: none; }
.style-option:hover { background: var(--bg-hover); }

.style-option.active { background: var(--brand-glow); }

.style-option-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.style-option.active .style-option-name { color: var(--brand); }

.style-option-desc {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.4;
}


/* ============================================================
   ADAPTIVE ACTION BUTTON (mic ↔ send)
   ============================================================ */

.adaptive-action-btn {
    background: none;
    border: none;
    color: var(--brand);
    cursor: pointer;
    padding: 16px 16px 16px 4px;
    display: flex;
    align-items: center;
    transition: color 0.2s, transform 0.1s;
}

.adaptive-action-btn:hover { color: var(--brand-hover); }
.adaptive-action-btn:active { transform: scale(0.92); }

.adaptive-action-btn svg {
    width: 20px;
    height: 20px;
    transition: opacity 0.2s, transform 0.2s;
}

.adaptive-action-btn .icon-mic {
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

.adaptive-action-btn .icon-send {
    fill: currentColor;
    display: none;
}

/* When text is present */
.adaptive-action-btn.has-text .icon-mic { display: none; }
.adaptive-action-btn.has-text .icon-send { display: block; }

/* Listening state — green to signal active recording */
.adaptive-action-btn.listening {
    color: #10b981 !important;
    animation: micPulse 1.5s infinite ease-in-out;
}

@keyframes micPulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.15); opacity: 0.8; }
}

/* Stop button */
.stop-btn {
    background: none;
    border: none;
    color: var(--brand);
    cursor: pointer;
    padding: 16px 16px 16px 4px;
    display: none;
    align-items: center;
    transition: color 0.2s, transform 0.1s;
}

.stop-btn.visible { display: flex; }
.stop-btn:hover { color: #ff4a4a; }
.stop-btn:active { transform: scale(0.92); }
.stop-btn svg { width: 22px; height: 22px; fill: currentColor; }

/* User input textarea */
#userInput {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    padding: 16px 12px 16px 8px;
    font-family: inherit;
    font-size: 14px;
    resize: none;
    outline: none;
    height: 54px;
    max-height: 200px;
    line-height: 1.5;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

#userInput::-webkit-scrollbar { display: none; }
#userInput::placeholder { color: var(--text-muted); }

.disclaimer-text {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
    margin-top: 10px;
    text-align: center;
}


/* ============================================================
   SETTINGS MODAL
   ============================================================ */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 500;
    align-items: center;
    justify-content: center;
}

.modal-overlay.show { display: flex; }

.settings-modal {
    background: var(--bg-sidebar);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 600px;
    max-width: 92vw;
    height: 520px;
    max-height: 88vh;
    overflow: hidden;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.modal-header h2 { font-size: 18px; font-weight: 600; }

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    padding: 0 4px;
    transition: color 0.2s;
}

.modal-close:hover { color: var(--text-primary); }

.modal-body { padding: 0; overflow: hidden; }

.settings-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.settings-nav {
    width: 160px;
    flex-shrink: 0;
    background: var(--bg-main);
    padding: 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    border-right: 1px solid var(--border-color);
}

.settings-nav-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s, color 0.2s;
    text-align: left;
    width: 100%;
}

.settings-nav-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.settings-nav-btn.active {
    background: var(--bg-hover);
    color: var(--text-primary);
    font-weight: 600;
}

.settings-panel {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    min-width: 0;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

.settings-section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 10px;
}

.settings-input, .settings-textarea {
    width: 100%;
    padding: 11px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.settings-input:focus, .settings-textarea:focus { border-color: var(--brand); }
.settings-input::placeholder, .settings-textarea::placeholder { color: var(--text-muted); }

.settings-textarea { resize: vertical; min-height: 80px; line-height: 1.5; }

.settings-select {
    width: 100%;
    padding: 11px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    outline: none;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23888' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    transition: border-color 0.2s;
}

.settings-select:focus { border-color: var(--brand); }
.settings-select option { background: var(--bg-input); color: var(--text-primary); }

.settings-save-btn {
    margin-top: 12px;
    padding: 10px 24px;
    background: var(--brand);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.settings-save-btn:hover { background: var(--brand-hover); }

.settings-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
    line-height: 1.5;
}

.settings-hint a {
    color: var(--brand);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.settings-hint a:hover { color: var(--brand-hover); }


/* ============================================================
   FEEDBACK FORM
   ============================================================ */

/* ── Star rating ── */
.fb-stars {
    display: flex;
    gap: 4px;
    margin: 8px 0 4px;
}

.fb-star {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.15s, transform 0.15s;
    user-select: none;
    flex-shrink: 0;
}

.fb-star svg {
    width: 26px;
    height: 26px;
    display: block;
    transition: color 0.15s;
}

.fb-star.active, .fb-star.hover {
    color: #f5a623;
    transform: scale(1.15);
}

/* ── Emoji sub-ratings ── */
.fb-subratings {
    display: flex;
    gap: 20px;
    margin: 14px 0 0;
    flex-wrap: wrap;
}

.fb-subrating-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.fb-subrating-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.fb-emojis {
    display: flex;
    gap: 8px;
}

.fb-emoji {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    opacity: 0.45;
    transition: opacity 0.15s, transform 0.15s, color 0.15s;
    user-select: none;
    flex-shrink: 0;
}

.fb-emoji svg {
    width: 28px;
    height: 28px;
    display: block;
}

.fb-emoji.active {
    opacity: 1;
    color: var(--brand);
    transform: scale(1.18);
}

.fb-emoji:hover {
    opacity: 0.8;
    color: var(--text-primary);
    transform: scale(1.1);
}

/* ── Category pills ── */
.fb-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 8px 0 0;
}

.fb-cat-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border: 1.5px solid var(--border-color);
    border-radius: 20px;
    background: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, color 0.2s;
    white-space: nowrap;
}

.fb-cat-icon {
    width: 13px;
    height: 13px;
    stroke: currentColor;
    fill: none;
    flex-shrink: 0;
    display: block;
}

.fb-cat-btn:hover {
    border-color: var(--brand);
    color: var(--text-primary);
}

.fb-cat-btn.active {
    border-color: var(--brand);
    background: rgba(236, 100, 43, 0.12);
    color: var(--brand);
    font-weight: 600;
}

[data-theme="light"] .fb-cat-btn.active {
    background: rgba(44, 40, 114, 0.1);
    border-color: #2C2872;
    color: #2C2872;
}

/* ── Attach area ── */
.fb-attach-area {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 4px 0 0;
}

.fb-attach-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.fb-attach-chip {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: var(--bg-input);
    flex-shrink: 0;
}

.fb-attach-chip img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.fb-attach-chip-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(0,0,0,0.65);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s;
}

.fb-attach-chip-remove:hover { background: #ff4a4a; }

.fb-attach-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 14px;
    border: 1.5px dashed var(--border-color);
    border-radius: 10px;
    background: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
    width: fit-content;
}

.fb-attach-btn:hover {
    border-color: var(--brand);
    color: var(--text-primary);
}

/* ── Cooldown bar ── */
.fb-cooldown-wrap {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.fb-cooldown-bar {
    height: 3px;
    border-radius: 2px;
    background: var(--brand);
    width: 100%;
    transform-origin: left;
    animation: fbCooldown 60s linear forwards;
}

@keyframes fbCooldown {
    from { transform: scaleX(1); }
    to   { transform: scaleX(0); }
}

.fb-cooldown-label {
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
}

/* Appearance tab — theme selector */
.theme-option-group {
    display: flex;
    gap: 10px;
}

.theme-option-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px;
    border-radius: var(--radius);
    border: 2px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, color 0.2s;
}

.theme-option-btn:hover { border-color: var(--text-muted); }

.theme-option-btn.active {
    border-color: var(--brand);
    color: var(--brand);
    background: var(--brand-glow);
}


/* ============================================================
   ANIMATIONS & SCROLLBAR
   ============================================================ */

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

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #555; }

[data-theme="light"] ::-webkit-scrollbar-thumb { background: #ccc; }
[data-theme="light"] ::-webkit-scrollbar-thumb:hover { background: #aaa; }

.cursor::after {
    content: '\25CB';
    animation: blink 1s step-start infinite;
    color: var(--brand);
    margin-left: 2px;
}

@keyframes blink { 50% { opacity: 0; } }


/* ============================================================
   ERROR MESSAGE
   ============================================================ */

.error-message {
    color: #ff4a4a;
    font-family: 'Montserrat', sans-serif;
    font-weight: 600;
    font-style: normal;
    font-size: 14px;
    padding: 0;
    background: none;
    border: none;
    border-radius: 0;
}

/* Chat skeleton loading */
.chat-skeleton {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px 0;
    max-width: 800px;
    margin: 0 auto;
}

.chat-skeleton-row {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.chat-skeleton-row.right { justify-content: flex-end; }

.chat-skeleton-bubble {
    border-radius: 12px;
    background: var(--bg-hover);
    animation: skeletonPulse 1.5s ease-in-out infinite;
}

.chat-skeleton-row.left .chat-skeleton-bubble {
    width: 65%;
    height: 48px;
}

.chat-skeleton-row.right .chat-skeleton-bubble {
    width: 45%;
    height: 32px;
}

@keyframes skeletonPulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.8; }
}

/* Custom select dropdown (PWA-native replacement for <select>) */
.custom-select-wrap {
    position: relative;
    width: 100%;
}

.custom-select-btn {
    width: 100%;
    padding: 11px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: border-color 0.2s;
    outline: none;
    text-align: left;
}

.custom-select-btn:focus,
.custom-select-btn.open {
    border-color: var(--brand);
}

.custom-select-btn svg {
    width: 14px;
    height: 14px;
    stroke: var(--text-muted);
    fill: none;
    stroke-width: 2;
    flex-shrink: 0;
    transition: transform 0.2s;
}

.custom-select-btn.open svg { transform: rotate(180deg); }

.custom-select-list {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    z-index: 200;
    max-height: 220px;
    overflow-y: auto;
    animation: fadeIn 0.15s ease-out;
}

.custom-select-list.show { display: block; }

.custom-select-option {
    padding: 10px 14px;
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    border-bottom: 1px solid var(--border-subtle);
}

.custom-select-option:last-child { border-bottom: none; }
.custom-select-option:hover { background: var(--bg-hover); color: var(--text-primary); }
.custom-select-option.active { background: var(--brand-glow); color: var(--brand); font-weight: 600; }


/* ============================================================
   PWA MODAL DIALOGS (replaces Chrome confirm/prompt)
   ============================================================ */

.pwa-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.15s ease-out;
}

.pwa-modal-overlay.show {
    display: flex;
}

.pwa-modal {
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px;
    width: 90vw;
    max-width: 340px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.2s ease-out;
}

.pwa-modal-message {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
    margin: 0 0 18px;
    line-height: 1.5;
    text-align: center;
}

.pwa-modal-input {
    width: 100%;
    padding: 11px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    margin-bottom: 18px;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.pwa-modal-input:focus {
    border-color: var(--brand);
}

.pwa-modal-actions {
    display: flex;
    gap: 10px;
}

.pwa-modal-btn {
    flex: 1;
    padding: 11px 0;
    border: none;
    border-radius: 10px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
}

.pwa-modal-cancel {
    background: var(--bg-hover);
    color: var(--text-secondary);
}

.pwa-modal-cancel:hover { opacity: 0.8; }

.pwa-modal-ok {
    background: var(--brand);
    color: #fff;
}

.pwa-modal-ok:hover { background: var(--brand-hover); }


/* ============================================================
   SIDEBAR OVERLAY (mobile edge-swipe)
   ============================================================ */

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 35;
    -webkit-tap-highlight-color: transparent;
}

.sidebar-overlay.visible { display: block; }


/* ============================================================
   RESPONSIVE — MOBILE (≤768px)
   ============================================================ */

@media (max-width: 768px) {

    /* Show mobile top bar */
    .mobile-topbar { display: flex; }

    /* Hide desktop sidebar elements */
    .sidebar { display: none !important; }
    .sidebar-rail { display: none !important; }
    .main-header { display: none !important; }

    .app-container {
        overflow: hidden;
        overflow-x: hidden;
        position: relative;
        flex-direction: column;
    }

    .main-chat {
        width: 100vw;
        max-width: 100vw;
        min-width: 0;
        flex: 1;
        overflow-x: hidden;
    }

    .chat-container {
        padding: calc(var(--topbar-height) + 10px) 10px 16px;
        gap: 16px;
        height: 100%;
        overflow-x: hidden;
    }

    .message-row { max-width: 100%; }
    .ai-avatar { display: none; }

    .ai .message-content {
        font-size: 13px;
        line-height: 1.55;
        padding: 0 2px;
    }

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

    .user .message-content {
        max-width: 82%;
        font-size: 13px;
        margin-left: auto;
    }

    .input-container {
        padding: 10px 10px calc(6px + env(safe-area-inset-bottom));
    }

    .disclaimer-text {
        font-size: 10px;
        margin-top: 6px;
    }

    /* Settings modal responsive */
    .settings-modal {
        width: 96vw;
        height: 78vh;
        max-height: 78vh;
    }

    .settings-layout {
        flex-direction: row;
        min-height: unset;
    }

    .settings-nav {
        width: 52px;
        min-width: 52px;
        flex-direction: column;
        padding: 10px 4px;
        border-right: 1px solid var(--border-color);
        border-bottom: none;
        overflow-x: unset;
        overflow-y: auto;
        gap: 4px;
        align-items: center;
    }

    .settings-nav-btn {
        width: 40px;
        height: 40px;
        padding: 0;
        justify-content: center;
        border-radius: 10px;
        white-space: normal;
    }

    .settings-nav-btn span, .settings-nav-btn > :not(svg) { display: none; }

    .settings-nav-btn svg { width: 18px; height: 18px; flex-shrink: 0; }

    .settings-nav-btn.active {
        background: var(--bg-elevated);
        color: var(--brand);
    }

    .settings-panel {
        padding: 14px 12px;
        flex: 1;
        min-width: 0;
    }

    .hero-title { font-size: 22px; }
    .hero-bot-icon { width: 110px; height: 110px; }

    .hero-welcome {
        justify-content: center;
        padding: calc(var(--topbar-height) + 10px) 16px calc(20px + env(safe-area-inset-bottom));
        overflow-y: auto;
        min-height: 0;
    }

    .hero-input-wrap { max-width: 100%; }

    .login-title { font-size: 20px; white-space: normal; }

    /* Horizontal lock */
    html, body, .app-container, .main-chat, .chat-container {
        max-width: 100vw;
        overflow-x: hidden;
    }
}

@media (max-width: 480px) {
    .hero-title { font-size: 20px; }
    .hero-input-box textarea { font-size: 13px; }
    .ai .message-content { font-size: 12.5px; }
    .user .message-content { font-size: 12.5px; }
    .katex-display { overflow-x: auto; font-size: 0.95em; }
    .message-content pre { font-size: 11px; }
}

/* ── Attach wrap and dropdown menu ──────────────────────────────── */
.attach-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.attach-plus-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, transform 0.2s;
    flex-shrink: 0;
}

.attach-plus-btn:hover {
    color: var(--text-primary);
}

.attach-plus-btn svg {
    transition: transform 0.25s ease-in-out, color 0.2s ease-in-out;
    transform-origin: center;
    display: block; /* Avoid inline vertical baseline shift on rotation */
}

.attach-plus-btn.open {
    color: var(--brand);
}

.attach-menu {
    display: none;
    position: absolute;
    bottom: 52px;
    left: 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 6px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    z-index: 101;
    min-width: 170px;
    flex-direction: column;
    gap: 2px;
}

.attach-menu.show {
    display: flex;
}

.attach-menu-item {
    background: none;
    border: none;
    text-align: left;
    padding: 10px 12px;
    font-size: 12px;
    font-family: inherit;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s, color 0.2s;
    width: 100%;
}

.attach-menu-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.attach-menu-item svg {
    width: 14px;
    height: 14px;
    stroke-width: 2.2;
    color: var(--text-secondary);
    transition: color 0.2s;
}

.attach-menu-item[data-active="true"] {
    color: var(--brand);
    font-weight: 500;
}

.attach-menu-item[data-active="true"] svg {
    color: var(--brand);
}

/* Tool Progress Bar */
.tool-progress-bar {
    width: 100%;
    max-width: 800px;
    margin: 0 auto 8px auto;
    padding: 0 10px;
    box-sizing: border-box;
    display: none;
}

.tool-progress-label {
    font-size: 10px;
    color: var(--brand);
    margin-bottom: 4px;
    font-weight: 500;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.tool-progress-track {
    width: 100%;
    height: 3px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 2px;
    overflow: hidden;
}

.tool-progress-fill {
    width: 0%;
    height: 100%;
    background: var(--brand);
    border-radius: 2px;
    transition: width 0.3s ease;
}

/* Doc Chip styling */
.doc-chip {
    background: rgba(99, 102, 241, 0.05) !important;
    border: 1px solid rgba(99, 102, 241, 0.15) !important;
}


/* ============================================================
   CANVAS / NOTES
   ============================================================ */

/* Sidebar "Canvas" button — mirrors .new-chat-btn */
.canvas-open-btn {
    margin: 0 14px 4px;
    padding: 12px 16px;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    transition: background 0.3s, border-color 0.3s, box-shadow 0.3s;
}
.canvas-open-btn:hover {
    background: var(--bg-elevated);
    border-color: var(--brand);
    box-shadow: 0 0 12px var(--brand-glow);
}
.canvas-open-btn svg { color: var(--brand); }

/* Panel: part of the .app-container flex row on desktop */
.canvas-panel {
    width: 0;
    flex-shrink: 0;
    background: var(--bg-sidebar);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width var(--transition);
    z-index: 25;
}
.canvas-panel.open { width: min(460px, 42vw); }

.canvas-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.canvas-header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 15px;
    color: var(--text-primary);
}
.canvas-header-title svg { color: var(--brand); }
.canvas-header-actions { display: flex; gap: 4px; }

.canvas-icon-btn {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}
.canvas-icon-btn:hover { background: var(--bg-hover); color: var(--brand); }

/* List view */
.canvas-list-view { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; }
.canvas-notes-list { display: flex; flex-direction: column; gap: 8px; }

.canvas-note-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}
.canvas-note-card:hover { border-color: var(--brand); }
.canvas-note-card-main { flex: 1; min-width: 0; }
.canvas-note-card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.canvas-note-card-date { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.canvas-note-card-del {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    flex-shrink: 0;
    transition: background 0.2s, color 0.2s;
}
.canvas-note-card-del:hover { background: var(--bg-hover); color: #e5484d; }

.canvas-empty-state {
    flex: 1;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-muted);
    text-align: center;
}
.canvas-empty-state p { margin: 0; font-size: 13px; }
.canvas-empty-new-btn {
    padding: 9px 16px;
    background: var(--brand);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
}
.canvas-empty-new-btn:hover { background: var(--brand-hover); }

/* Editor view */
.canvas-editor-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.canvas-editor-topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.canvas-title-input {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 16px;
    font-weight: 700;
}
.canvas-title-input::placeholder { color: var(--text-muted); }
.canvas-save-status { font-size: 11px; color: var(--text-muted); flex-shrink: 0; white-space: nowrap; }

.canvas-editor-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}
.canvas-export-btn, .canvas-delete-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, color 0.2s;
}
.canvas-export-btn:hover { border-color: var(--brand); color: var(--brand); }
.canvas-export-btn svg { color: var(--brand); }
.canvas-delete-btn { margin-left: auto; }
.canvas-delete-btn:hover { border-color: #e5484d; color: #e5484d; }
.canvas-delete-btn:hover svg { color: #e5484d; }

/* ── Markdown editor + preview ── */
.canvas-md-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.canvas-md-inserts { display: flex; gap: 2px; flex-wrap: wrap; }
.canvas-md-btn {
    min-width: 30px;
    height: 30px;
    padding: 0 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 7px;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.canvas-md-btn:hover { background: var(--bg-hover); color: var(--brand); }
.canvas-md-toolbar.preview-on .canvas-md-inserts { opacity: 0.35; pointer-events: none; }

.canvas-preview-toggle {
    flex-shrink: 0;
    padding: 6px 14px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}
.canvas-preview-toggle:hover { border-color: var(--brand); color: var(--brand); }
.canvas-md-toolbar.preview-on .canvas-preview-toggle { border-color: var(--brand); color: var(--brand); }

.canvas-md-editor {
    flex: 1;
    min-height: 0;
    width: 100%;
    box-sizing: border-box;
    resize: none;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-primary);
    font-family: 'Montserrat', sans-serif;
    font-size: 14px;
    line-height: 1.65;
    padding: 16px;
    overflow-y: auto;
}
.canvas-md-editor::placeholder { color: var(--text-muted); }

.canvas-md-preview {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.65;
    max-width: 100%;
}
.canvas-md-preview table {
    border-collapse: collapse;
    width: 100%;
    margin: 10px 0;
    font-size: 13px;
}
.canvas-md-preview th, .canvas-md-preview td {
    border: 1px solid var(--border-color);
    padding: 6px 10px;
    text-align: left;
}
.canvas-md-preview th { background: var(--bg-elevated); }
.canvas-md-preview img { max-width: 100%; border-radius: 8px; }
.canvas-md-preview pre {
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 12px;
    overflow-x: auto;
}
/* PDF render body (light background, dark text for print) */
.canvas-pdf-body table { border-collapse: collapse; width: 100%; }
.canvas-pdf-body th, .canvas-pdf-body td { border: 1px solid #ccc; padding: 6px 10px; }
.canvas-pdf-body img { max-width: 100%; }

/* Mobile: full-screen slide-in overlay */
@media (max-width: 768px) {
    .canvas-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        border-left: none;
        transform: translateX(100%);
        transition: transform var(--transition);
        z-index: 1200;
    }
    .canvas-panel.open { width: 100%; transform: translateX(0); }
}