/* ════════════════════════════════════════════════════════════════════════
   AI Chat Platform — Stylesheet
   Matches the GapGPT-style screenshots provided by the user
   ════════════════════════════════════════════════════════════════════════ */

:root {
    --bg-primary: #1f1f1f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #2a2a2a;
    --bg-hover: #333;
    --bg-input: #2f2f2f;
    --bg-user-msg: #2f2f2f;
    --bg-menu: #2a2a2a;
    --bg-menu-hover: #3a3a3a;

    --text-primary: #ececec;
    --text-secondary: #cbcbcb;   /* قبلاً #b4b4b4 — روشن‌تر شد */
    --text-muted: #a8a8b3;        /* قبلاً #888 — به‌مراتب روشن‌تر */

    --accent: #9b6dff;
    --accent-hover: #8a5ce8;
    --accent-light: #b48dff;

    --border: #333;
    --border-light: #444;

    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;

    --radius: 10px;
    --radius-lg: 16px;
    --radius-sm: 6px;
    --radius-pill: 999px;

    --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-menu: 0 10px 30px rgba(0, 0, 0, 0.5);
}

/* Image studio polish: keep generated images in the message thread only. */
.img-gallery-wrap,
.img-gallery-strip,
.img-gallery-head {
    display: none !important;
}

.img-main {
    background:
        radial-gradient(circle at 50% 0%, rgba(20,184,166,0.10), transparent 34%),
        linear-gradient(180deg, rgba(255,255,255,0.018), transparent 34%),
        var(--bg-primary);
}

.img-hero {
    max-width: 720px;
    margin: 0 auto;
    padding-top: clamp(34px, 7vh, 68px);
}

.img-hero-icon {
    width: 92px;
    height: 92px;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    border-radius: 28px;
    color: #5eead4;
    background: linear-gradient(145deg, rgba(20,184,166,0.17), rgba(155,109,255,0.13));
    border: 1px solid rgba(94,234,212,0.18);
    box-shadow: 0 18px 48px rgba(0,0,0,0.22);
}

.img-hero h2 {
    font-size: clamp(24px, 3vw, 32px);
    line-height: 1.35;
    background: linear-gradient(135deg, #f8fafc, #a78bfa 42%, #5eead4);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.img-hero p {
    max-width: 560px;
    margin: 8px auto 0;
    color: color-mix(in srgb, var(--text-muted) 84%, #ffffff);
}

.img-composer-wrap {
    gap: 8px;
}

.img-composer {
    border-color: rgba(167,139,250,0.35);
    box-shadow: 0 16px 46px rgba(0,0,0,0.30), 0 0 0 1px rgba(94,234,212,0.06) inset;
}

.img-toolbar {
    /* border: 1px solid rgba(255,255,255,0.08);*/
    /* background: rgba(31,31,31,0.72); */
    /* backdrop-filter: blur(14px);*/
    /* box-shadow: 0 10px 28px rgba(0,0,0,0.18);*/
}

.img-tool-btn,
.img-mode-badge {
    min-height: 38px;
}

.img-tool-btn:hover,
.img-mode-badge {
    border-color: rgba(94,234,212,0.24);
}

.img-result-slot {
    border-radius: 18px;
    border-color: rgba(255,255,255,0.10);
    box-shadow: 0 18px 46px rgba(0,0,0,0.28);
}

.img-result-shimmer::after {
    content: "";
    position: absolute;
    inset: 18%;
    border-radius: 999px;
    border: 1px solid rgba(94,234,212,0.22);
    animation: imgPulseRing 1.5s ease-in-out infinite;
}

@keyframes imgPulseRing {
    0%, 100% { transform: scale(.86); opacity: .45; }
    50% { transform: scale(1.1); opacity: .92; }
}

@media (max-width: 768px) {
    .img-hero {
        padding-top: 26px;
    }
    .img-hero-icon {
        width: 76px;
        height: 76px;
        border-radius: 22px;
    }
    .img-main[data-state="empty"] .img-input {
        min-height: 86px;
    }
    .img-toolbar {
        padding: 7px;
    }
}

/* Final mobile layout contract for wallet/profile: these are document pages,
   not chat panes.  Give touch scrolling a single, unambiguous scroll owner. */
@media (max-width: 768px) {
    body:not(.app-shell):has(.wallet-page) > .layout,
    body:not(.app-shell):has(.profile-page) > .layout {
        height: auto !important;
        min-height: 100dvh !important;
        max-height: none !important;
        overflow: visible !important;
    }
    body:not(.app-shell):has(.wallet-page) .main,
    body:not(.app-shell):has(.profile-page) .main,
    body:not(.app-shell):has(.wallet-page) .chat-area,
    body:not(.app-shell):has(.profile-page) .chat-area {
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
        touch-action: pan-y pinch-zoom !important;
    }
    body:not(.app-shell):has(.wallet-page),
    body:not(.app-shell):has(.profile-page) {
        overscroll-behavior-y: auto !important;
        padding-bottom: calc(78px + env(safe-area-inset-bottom));
    }

    /* The notification panel must show its full body above the bottom nav. */
    .notif-panel,
    body.app-shell .notif-panel {
        top: calc(56px + env(safe-area-inset-top) + 6px) !important;
        bottom: calc(68px + env(safe-area-inset-bottom) + 6px) !important;
        max-height: none !important;
        min-height: min(360px, calc(100dvh - 150px)) !important;
    }
    .notif-panel-body { min-height: 0; overflow-y: auto !important; }
    .notif-item { padding: 14px 16px; }
    .notif-body { display: block; white-space: normal; line-height: 1.7; }

    /* Composer menus have one full-width, tap-friendly sheet instead of a
       narrow floating column that can be clipped by the viewport. */
    body.app-shell .tool-menu.show,
    body.app-shell .tool-submenu.show,
    body.app-shell .kn-menu#personaMenu.show {
        left: 10px !important;
        right: 10px !important;
        width: auto !important;
        max-width: none !important;
        bottom: calc(68px + env(safe-area-inset-bottom)) !important;
        max-height: min(68dvh, 560px) !important;
        overflow-y: auto !important;
        border-radius: 20px !important;
        padding: 12px !important;
        z-index: 1200 !important;
    }
    body.app-shell .kn-menu#personaMenu .persona-menu-item {
        min-height: 58px;
        border: 1px solid rgba(255,255,255,.07);
        border-radius: 14px;
        margin: 5px 0;
        padding: 10px 12px;
        background: rgba(255,255,255,.025);
    }
    body.app-shell .kn-menu#personaMenu .persona-menu-none { border-color: rgba(148,163,184,.22); }
    body.app-shell .kn-menu#personaMenu .persona-custom-link {
        display: block; width: 100%; margin-top: 8px; padding: 12px;
        border-radius: 12px; text-align: center;
        background: rgba(155,109,255,.13); border: 1px dashed rgba(180,141,255,.55);
    }
}

/* Prompt-review dialog for the image studio. */
.img-prompt-review {
    width: min(620px, calc(100vw - 28px)); border: 1px solid rgba(167,139,250,.38);
    border-radius: 20px; padding: 0; color: var(--text-primary); background: var(--bg-secondary);
    box-shadow: 0 22px 70px rgba(0,0,0,.58);
}
.img-prompt-review::backdrop { background: rgba(0,0,0,.62); backdrop-filter: blur(3px); }
.img-prompt-review-card { padding: 20px; }
.img-prompt-review-head { display:flex; align-items:center; justify-content:space-between; font-weight:800; font-size:16px; }
.img-prompt-review-head button { border:0; background:transparent; color:var(--text-muted); font-size:24px; cursor:pointer; }
.img-prompt-review p { color:var(--text-secondary); font-size:13px; line-height:1.8; }
.img-prompt-review textarea { width:100%; box-sizing:border-box; resize:vertical; min-height:130px; border-radius:14px; padding:12px; color:var(--text-primary); background:var(--bg-primary); border:1px solid var(--border); font:inherit; line-height:1.8; direction:auto; }
.img-prompt-review-actions { display:flex; justify-content:flex-end; gap:9px; margin-top:14px; }

/* Model suggestions shown after selecting a quality/cost preference. */
.quality-model-suggestions { margin-top:16px; min-height:0; }
.quality-model-suggestions[hidden] { display:none; }
.quality-model-suggestions-head { display:flex; align-items:center; justify-content:space-between; gap:10px; color:var(--text-secondary); font-size:12.5px; margin-bottom:9px; }
.quality-model-suggestion-list { display:flex; gap:9px; overflow-x:auto; padding:2px 1px 8px; scroll-snap-type:x proximity; }
.quality-model-suggestion { min-width:150px; scroll-snap-align:start; text-align:right; color:var(--text-primary); font:inherit; cursor:pointer; padding:12px; border-radius:14px; border:1px solid rgba(155,109,255,.30); background:linear-gradient(135deg,rgba(155,109,255,.16),rgba(20,184,166,.07)); transition:transform .18s, border-color .18s; }
.quality-model-suggestion:hover { transform:translateY(-2px); border-color:var(--accent-light); }

/* ═════════ 2026 calm / compact interface refresh ═════════ */
.theme-segment {
    display:inline-flex; align-items:center; gap:2px; padding:3px;
    border:1px solid var(--border); border-radius:999px;
    background:color-mix(in srgb,var(--bg-tertiary) 80%,transparent);
}
.theme-segment-btn {
    height:28px; padding:0 8px; display:inline-flex; align-items:center; gap:5px;
    border:0; border-radius:999px; background:transparent; color:var(--text-muted);
    font:600 10.5px/1 'Vazirmatn',sans-serif; cursor:pointer; transition:.18s ease;
}
.theme-segment-btn.active { background:var(--bg-primary); color:var(--text-primary); box-shadow:0 2px 9px rgba(0,0,0,.15); }
.theme-segment-btn[data-theme-choice="light"].active { color:#547266; background:#f7fbf8; }

/* A narrow persona rail above the input. Selecting one gently hides the rest;
   tapping the active chip expands the rail again. */
.persona-dock { gap:6px; align-items:center; margin-bottom:6px; overflow:visible; }
.persona-strip { min-width:0; display:flex; gap:6px; overflow-x:auto; scrollbar-width:none; padding:2px; }
.persona-strip::-webkit-scrollbar { display:none; }
.persona-chip,.persona-custom-chip {
    flex:0 0 auto; min-height:27px; padding:4px 10px; border-radius:999px;
    border:1px solid color-mix(in srgb,var(--accent) 25%,var(--border));
    background:color-mix(in srgb,var(--bg-secondary) 90%,var(--accent) 4%);
    color:var(--text-secondary); font:600 10.5px/1.3 'Vazirmatn',sans-serif;
    cursor:pointer; white-space:nowrap; transition:opacity .18s,transform .18s,background .18s,border-color .18s;
}
.persona-chip:hover { border-color:color-mix(in srgb,var(--accent) 55%,var(--border)); color:var(--text-primary); }
.persona-chip.active { color:#fff; border-color:transparent; background:linear-gradient(135deg,#8062d6,#5f8f83); box-shadow:0 4px 14px rgba(91,76,150,.22); }
.persona-dock.is-collapsed .persona-chip:not(.active) { display:none; }
.persona-dock.is-collapsed .persona-chip.active::after { content:'  ·  تغییر'; opacity:.72; font-weight:400; }
.persona-custom-chip { width:27px; padding:0; display:grid; place-items:center; font-size:15px; color:var(--accent-light); }
.persona-strip-loading { color:var(--text-muted); font-size:10.5px; padding:4px 8px; }
.persona-panel { inset-inline-start:auto; inset-inline-end:0; }

/* Compact model suggestions: names carry the information, repeated helper text
   and decorative logos no longer consume the composer area. */
.chat-quality-suggestions { margin-top:10px; }
.chat-quality-suggestions .quality-model-suggestions-head { margin-bottom:6px; font-size:10.5px; }
.chat-quality-suggestions .quality-model-suggestions-head span:last-child { display:none; }
.chat-quality-suggestions .quality-model-suggestion-list { gap:6px; padding-bottom:4px; }
.chat-quality-suggestions .quality-model-suggestion {
    min-width:0; width:auto; padding:6px 10px; border-radius:10px; text-align:center;
    background:color-mix(in srgb,var(--bg-secondary) 92%,var(--accent) 5%);
    box-shadow:none;
}
.chat-quality-suggestions .quality-model-suggestion img,
.chat-quality-suggestions .quality-model-fallback,
.chat-quality-suggestions .quality-model-suggestion small { display:none; }
.chat-quality-suggestions .quality-model-suggestion strong { font-size:10.5px; font-weight:650; white-space:nowrap; }

/* Calm light theme: warm-white surfaces, sage accents and low-contrast borders. */
html[data-theme="light"] {
    --bg-primary:#f4f8f5; --bg-secondary:#fbfdfb; --bg-tertiary:#e9f0eb;
    --bg-hover:#e3ece6; --bg-input:#ffffff; --bg-user-msg:#e8f1ed;
    --bg-menu:#fbfdfb; --bg-menu-hover:#edf4ef;
    --text-primary:#27352f; --text-secondary:#53645c; --text-muted:#78877f;
    --accent:#6e68b6; --accent-hover:#5e58a4; --accent-light:#7771bf;
    --border:#d7e2da; --border-light:#e6ede8;
    --shadow:0 8px 26px rgba(59,82,69,.08); --shadow-menu:0 18px 44px rgba(59,82,69,.12);
}
html[data-theme="light"] body { background:radial-gradient(circle at 80% 0,#eef4ff 0,transparent 30%),var(--bg-primary); }
html[data-theme="light"] .main-header,
html[data-theme="light"] .sidebar,
html[data-theme="light"] .mobile-bottom-nav { background:color-mix(in srgb,var(--bg-secondary) 91%,transparent)!important; border-color:var(--border)!important; }
html[data-theme="light"] .composer,
html[data-theme="light"] body.app-shell .composer { background:#fff!important; border-color:#d8e4dc!important; box-shadow:0 12px 34px rgba(75,101,86,.10)!important; }
html[data-theme="light"] .model-card-v2,
html[data-theme="light"] .eq-card { background:rgba(255,255,255,.78); border-color:var(--border); box-shadow:0 8px 24px rgba(71,93,80,.06); }
html[data-theme="light"] .nav-item svg { filter:drop-shadow(0 3px 5px rgba(78,93,130,.16)); }

@media (max-width:768px) {
    .theme-segment-label { display:none; }
    .theme-segment-btn { width:27px; padding:0; justify-content:center; }
    body.app-shell #personaBtn { display:grid!important; }
    body.app-shell .persona-dock { display:flex!important; padding-inline:2px; }
    body.app-shell .persona-strip { display:flex!important; }
    body.app-shell .persona-panel.show { bottom:calc(68px + env(safe-area-inset-bottom))!important; }
}

.models-popular-rail {
    display:grid; grid-auto-flow:column; grid-auto-columns:minmax(150px,1fr);
    grid-template-rows:1fr; gap:9px; overflow-x:auto; padding:3px 2px 10px;
    scroll-snap-type:x proximity; scrollbar-width:thin;
}
.model-card-v2.model-card-popular {
    min-height:112px; padding:12px; gap:8px; scroll-snap-align:start;
    background:linear-gradient(145deg,color-mix(in srgb,var(--accent) 10%,var(--bg-secondary)),color-mix(in srgb,#6ba891 7%,var(--bg-secondary)));
}
.model-card-popular .mcv-avatar { width:30px; height:30px; }
.mcv-openai-mark { width:100%; height:100%; display:grid; place-items:center; border-radius:inherit; background:#101513; color:#fff; font:800 9px/1 system-ui,sans-serif; letter-spacing:-.3px; }
.model-card-popular .mcv-title { font-size:13px; }
.model-card-popular .mcv-provider { font-size:10px; }
.model-card-popular .mcv-cta { min-height:29px; padding:4px 9px; font-size:10.5px; }
.models-all-divider { display:flex; align-items:center; gap:12px; margin:24px 0 14px; color:var(--text-muted); font-size:11px; }
.models-all-divider::before,.models-all-divider::after { content:''; height:1px; flex:1; background:linear-gradient(90deg,transparent,var(--border),transparent); }

/* Distinct, softly dimensional navigation icons without adding visual clutter. */
.sidebar-nav .nav-item svg { padding:3px; width:24px; height:24px; border-radius:8px; background:linear-gradient(145deg,rgba(155,109,255,.17),rgba(64,170,145,.10)); color:color-mix(in srgb,var(--accent-light) 80%,var(--text-primary)); box-shadow:inset 0 1px rgba(255,255,255,.10),0 4px 10px rgba(0,0,0,.10); }
.sidebar-nav .nav-item:nth-child(3n+2) svg { background:linear-gradient(145deg,rgba(50,170,155,.17),rgba(73,112,190,.10)); color:#65bba9; }
.sidebar-nav .nav-item:nth-child(3n) svg { background:linear-gradient(145deg,rgba(236,120,95,.15),rgba(191,116,190,.10)); color:#d38da7; }

@media (min-width:1100px) {
    .models-popular-rail { grid-template-columns:repeat(5,minmax(0,1fr)); grid-auto-flow:initial; }
}
.quality-model-suggestion strong,.quality-model-suggestion small { display:block; }
.quality-model-suggestion small { margin-top:4px; color:var(--text-muted); font-size:11px; }

/* ═════════ Last-wins: professional light palette + no accidental scrollbars ═════════
   This block intentionally stays at the end because the legacy stylesheet has
   older light-theme and suggestion rules in several sections. */
.chat-area,
.empty-chat,
.empty-chat-content,
.empty-quality-block,
.chat-quality-suggestions {
    min-width:0;
    max-width:100%;
    overflow-x:hidden !important;
}

.chat-quality-suggestions .quality-model-suggestion-list {
    display:flex;
    flex-wrap:wrap;
    justify-content:center;
    gap:6px;
    width:100%;
    overflow:visible !important;
    padding:2px 1px 4px;
    scroll-snap-type:none;
    scrollbar-width:none;
}
.chat-quality-suggestions .quality-model-suggestion-list::-webkit-scrollbar { display:none; }
.chat-quality-suggestions .quality-model-suggestion {
    min-width:0;
    width:auto;
    max-width:100%;
    padding:6px 12px;
    border-radius:10px;
    text-align:center;
}
.chat-quality-suggestions .quality-model-suggestion img,
.chat-quality-suggestions .quality-model-fallback,
.chat-quality-suggestions .quality-model-suggestion small { display:none; }
.chat-quality-suggestions .quality-model-suggestion strong {
    display:block;
    font-size:10.5px;
    font-weight:700;
    white-space:nowrap;
}

html[data-theme="light"] {
    color-scheme:light;
    --bg-primary:#e8ecea;
    --bg-secondary:#f0f3f1;
    --bg-tertiary:#dce3df;
    --bg-hover:#d5ddd9;
    --bg-input:#f4f6f4;
    --bg-user-msg:#dce5e1;
    --bg-menu:#eef2ef;
    --bg-menu-hover:#e0e7e3;
    --text-primary:#25312c;
    --text-secondary:#4f5e57;
    --text-muted:#718078;
    --accent:#66658f;
    --accent-hover:#57567d;
    --accent-light:#7675a3;
    --border:#cbd5d0;
    --border-light:#d8dfdb;
    --shadow:0 8px 26px rgba(45,61,53,.09);
    --shadow-menu:0 18px 42px rgba(45,61,53,.14);
}
html[data-theme="light"] body {
    background:
        radial-gradient(circle at 12% 4%,rgba(111,119,159,.10),transparent 28%),
        radial-gradient(circle at 88% 12%,rgba(91,132,113,.09),transparent 30%),
        #e8ecea;
}
html[data-theme="light"] .main,
html[data-theme="light"] .chat-area { background:transparent; }
html[data-theme="light"] .main-header,
html[data-theme="light"] .sidebar,
html[data-theme="light"] .mobile-bottom-nav {
    background:rgba(232,236,234,.92) !important;
    border-color:#cbd5d0 !important;
    box-shadow:none !important;
    backdrop-filter:blur(16px);
}
html[data-theme="light"] .empty-quality-block,
html[data-theme="light"] .eq-card,
html[data-theme="light"] .model-card-v2,
html[data-theme="light"] .knowledge-card,
html[data-theme="light"] .audio-card {
    background:#eef2ef !important;
    border-color:#cbd5d0 !important;
    box-shadow:0 8px 24px rgba(45,61,53,.06) !important;
}
html[data-theme="light"] .eq-card.selected {
    background:linear-gradient(145deg,#e3e4ef,#e1e9e5) !important;
    border-color:#8786aa !important;
    box-shadow:0 0 0 2px rgba(102,101,143,.10) !important;
}
html[data-theme="light"] .composer,
html[data-theme="light"] body.app-shell .composer {
    background:#f2f5f3 !important;
    border-color:#c5d0ca !important;
    box-shadow:0 10px 30px rgba(45,61,53,.10) !important;
}
html[data-theme="light"] .chat-quality-suggestions .quality-model-suggestion {
    color:#313d38;
    background:linear-gradient(145deg,#e5e6ef,#e3e9e6) !important;
    border-color:#b9b8d1 !important;
}
html[data-theme="light"] .chat-quality-suggestions .quality-model-suggestion:hover {
    background:linear-gradient(145deg,#dedfed,#dce6e1) !important;
    border-color:#8584aa !important;
}
html[data-theme="light"] .theme-segment {
    background:#dce2df;
    border-color:#c5cfca;
}
html[data-theme="light"] .theme-segment-btn.active {
    background:#eef2ef;
    color:#36443d;
    box-shadow:0 2px 8px rgba(45,61,53,.10);
}
html[data-theme="light"] .nav-item:hover,
html[data-theme="light"] .nav-item.active { background:rgba(102,101,143,.10); }

@media (max-width:640px) {
    .empty-chat-content { width:100%; padding-inline:10px; }
    .empty-quality-block { width:calc(100% - 8px); margin-inline:4px; }
    .chat-quality-suggestions .quality-model-suggestion-list { padding-inline:0; }
}

/* Light chat content: one coherent ink/icon system. */
html[data-theme="light"] .msg,
html[data-theme="light"] .msg-text,
html[data-theme="light"] .msg-content {
    color:#2c3933;
}
html[data-theme="light"] .msg-user .msg-bubble {
    color:#26342e;
    background:#dbe5e0;
    border:1px solid #cbd7d1;
    box-shadow:0 4px 14px rgba(50,70,60,.045);
}
html[data-theme="light"] .msg-assistant .msg-content {
    color:#2b3732;
}
html[data-theme="light"] .msg-actions {
    opacity:.76;
}
html[data-theme="light"] .msg-action-btn {
    color:#66756d !important;
    background:transparent;
}
html[data-theme="light"] .msg-action-btn svg {
    color:inherit;
    stroke:currentColor;
}
html[data-theme="light"] .msg-action-btn:hover,
html[data-theme="light"] .msg-action-btn:focus-visible {
    color:#45496f !important;
    background:#dbe1df;
    outline:none;
}
html[data-theme="light"] .msg-action-btn.active,
html[data-theme="light"] .msg-action-btn.playing {
    color:#5f5e8b !important;
    background:rgba(102,101,143,.11);
}
html[data-theme="light"] .msg-usage-bar {
    color:#68766f;
    background:#dfe5e2;
    border-color:#c8d2cd;
}
html[data-theme="light"] .msg-usage-bar svg { color:#76847d; opacity:.9; }
html[data-theme="light"] .msg-usage-trim {
    color:#866d35 !important;
    background:rgba(151,119,50,.10);
}
html[data-theme="light"] .thinking-panel {
    background:#e3e8e5;
    border-color:#cbd4cf;
}
html[data-theme="light"] .thinking-toggle,
html[data-theme="light"] .thinking-chevron,
html[data-theme="light"] .thinking-char-count {
    color:#68766f;
}
html[data-theme="light"] .thinking-char-count { background:#d8dfdb; }
html[data-theme="light"] .msg-content a { color:#575b8b; text-decoration-color:rgba(87,91,139,.35); }
html[data-theme="light"] .msg-content blockquote {
    color:#506059;
    background:rgba(100,112,106,.06);
    border-color:#8887aa;
}
html[data-theme="light"] .msg-content code:not(pre code),
html[data-theme="light"] .msg-bubble code:not(pre code) {
    color:#4f527f;
    background:#dce2df;
}
html[data-theme="light"] .typing-indicator,
html[data-theme="light"] .thinking-status-wrap { color:#63716a; }
.quality-model-suggestions { opacity:0; transform:translateY(8px); transition:opacity .24s ease,transform .24s ease; }
.quality-model-suggestions.is-visible { opacity:1; transform:none; }
.chat-quality-suggestions .quality-model-suggestion { min-width:170px; animation:qualitySuggestionIn .32s both; animation-delay:calc(var(--suggestion-index, 0) * 55ms); }
.quality-model-suggestion img,.quality-model-fallback { width:30px; height:30px; display:grid; place-items:center; float:right; margin-left:8px; border-radius:9px; object-fit:cover; background:rgba(155,109,255,.18); font-size:10px; font-weight:800; }
.quality-model-empty { color:var(--text-muted); font-size:12px; padding:10px; }
@keyframes qualitySuggestionIn { from { opacity:0; transform:translateY(8px) scale(.97); } to { opacity:1; transform:none; } }

/* Persona lives in its own compact dock above the composer, rather than as a
   fourth icon squeezed inside the text-entry frame. */
.persona-dock {
    position: relative;
    width: min(760px, 100%);
    margin: 0 auto 8px;
    display: flex;
    justify-content: flex-start;
}
.persona-launcher {
    display: inline-flex; align-items: center; gap: 10px;
    max-width: min(320px, 100%); min-height: 44px;
    padding: 7px 11px; border-radius: 14px;
    border: 1px solid rgba(155,109,255,.28);
    background: linear-gradient(135deg, rgba(155,109,255,.13), rgba(20,184,166,.06));
    color: var(--text-primary); font: inherit; text-align: right; cursor: pointer;
    box-shadow: 0 8px 24px rgba(0,0,0,.12);
    transition: transform .16s ease, border-color .16s ease, background .16s ease;
}
.persona-launcher:hover { transform: translateY(-1px); border-color: rgba(180,141,255,.58); }
.persona-launcher-icon {
    width: 32px; height: 32px; flex: 0 0 32px; display: grid; place-items: center;
    border-radius: 10px; background: rgba(155,109,255,.18); font-size: 17px;
}
.persona-launcher-copy { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.persona-launcher-copy strong { font-size: 12.5px; }
.persona-launcher-copy small { color: var(--text-muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.persona-launcher-chevron { color: var(--text-muted); margin-inline-start: auto; transition: transform .16s; }
.persona-dock.has-persona .persona-launcher {
    border-color: rgba(52,211,153,.42);
    background: linear-gradient(135deg, rgba(16,185,129,.14), rgba(155,109,255,.08));
}
.persona-dock.has-persona .persona-launcher-icon { background: rgba(16,185,129,.17); }
.persona-panel { inset-inline-start: 0; bottom: calc(100% + 8px); width: min(420px, calc(100vw - 32px)); max-width: 420px; }

@media (max-width: 768px) {
    .persona-dock { margin-bottom: 6px; padding-inline: 2px; }
    .persona-launcher { min-height: 40px; padding: 5px 9px; border-radius: 13px; }
    .persona-launcher-icon { width: 29px; height: 29px; flex-basis: 29px; }
    .persona-launcher-copy strong { font-size: 11.5px; }
    .persona-launcher-copy small { font-size: 10.5px; }
}

/* Explicit classes avoid depending on :has(), which is important for older
   Android WebViews and installed PWAs. */
@media (max-width: 768px) {
    body.mobile-scroll-page > .layout {
        height: auto !important; min-height: 100dvh !important;
        max-height: none !important; overflow: visible !important;
    }
    body.mobile-scroll-page .main,
    body.mobile-scroll-page .chat-area {
        height: auto !important; min-height: 0 !important; max-height: none !important;
        overflow: visible !important; touch-action: pan-y pinch-zoom !important;
        -webkit-overflow-scrolling: touch !important;
    }
    body.mobile-scroll-page { overflow-y: auto !important; overscroll-behavior-y: auto !important; }
}

/* ─── تم روشن (Light theme) ─── */
html[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f7f7f9;
    --bg-tertiary: #ececf1;
    --bg-hover: #e5e5ea;
    --bg-input: #ffffff;
    --bg-user-msg: #ececf1;
    --bg-menu: #ffffff;
    --bg-menu-hover: #f0f0f4;

    --text-primary: #1a1a1a;
    --text-secondary: #444444;
    --text-muted: #6b6b78;

    --accent: #7c3aed;
    --accent-hover: #6d28d9;
    --accent-light: #8b5cf6;

    --border: #d4d4d8;
    --border-light: #e4e4e7;

    --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    --shadow-menu: 0 10px 30px rgba(0, 0, 0, 0.10);
}

/* وقتی تم 'auto' است، از ترجیح سیستم پیروی می‌کند */
@media (prefers-color-scheme: light) {
    html[data-theme="auto"] {
        --bg-primary: #ffffff;
        --bg-secondary: #f7f7f9;
        --bg-tertiary: #ececf1;
        --bg-hover: #e5e5ea;
        --bg-input: #ffffff;
        --bg-user-msg: #ececf1;
        --bg-menu: #ffffff;
        --bg-menu-hover: #f0f0f4;
        --text-primary: #1a1a1a;
        --text-secondary: #444444;
        --text-muted: #6b6b78;
        --accent: #7c3aed;
        --accent-hover: #6d28d9;
        --accent-light: #8b5cf6;
        --border: #d4d4d8;
        --border-light: #e4e4e7;
        --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
        --shadow-menu: 0 10px 30px rgba(0, 0, 0, 0.10);
    }
}

* { margin: 0; padding: 0; box-sizing: border-box; }
/* پیش‌فرض: body اسکرول‌پذیر است. صفحاتی که scroll داخلی دارند (.layout, .admin-layout, .auth-page)
   خودشان viewport را قفل می‌کنند و body به min-height: 100% می‌نشیند. */
html { height: 100%; }
body { min-height: 100%; }

body {
    font-family: 'Vazirmatn', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    direction: rtl;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-light); text-decoration: none; }
a:hover { color: var(--accent); }

/* ─────────────────────────── Flash Messages ───────────────────────────── */
.flash-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 90%;
}
.flash {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-right: 4px solid var(--info);
    padding: 12px 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 15px;
    animation: slideDown 0.3s ease;
    min-width: 300px;
}
.flash-success { border-right-color: var(--success); }
.flash-danger  { border-right-color: var(--danger); }
.flash-warning { border-right-color: var(--warning); }
.flash-info    { border-right-color: var(--info); }
.flash-close {
    background: none; border: none; color: var(--text-secondary);
    font-size: 22px; cursor: pointer; line-height: 1;
}
.flash-close:hover { color: var(--text-primary); }
@keyframes slideDown {
    from { opacity: 0; transform: translate(-50%, -20px); }
    to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ─────────────────────────── AUTH PAGES ───────────────────────────────── */
.auth-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 20px; overflow: auto;
    background: linear-gradient(135deg, #1a1a1a 0%, #2a1f3d 100%);
}
.auth-card {
    background: var(--bg-secondary); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 40px; width: 100%;
    max-width: 440px; box-shadow: var(--shadow);
}
.auth-logo { text-align: center; margin-bottom: 30px; }
.auth-logo svg { width: 60px; height: 60px; color: var(--accent); }
.auth-logo h1 { font-size: 24px; font-weight: 600; margin-top: 10px; }
.auth-logo p { color: var(--text-secondary); font-size: 14px; margin-top: 5px; }

.form-group { margin-bottom: 18px; }
.form-group label {
    display: block; font-size: 14px; margin-bottom: 6px;
    color: var(--text-secondary); font-weight: 500;
}
.form-control {
    width: 100%; padding: 11px 14px; background: var(--bg-input);
    border: 1px solid var(--border); border-radius: var(--radius);
    color: var(--text-primary); font-family: inherit; font-size: 14px;
    transition: border 0.2s;
}
.form-control:focus { outline: none; border-color: var(--accent); }
.form-error { color: var(--danger); font-size: 12px; margin-top: 4px; display: block; }

.form-check {
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 12px; cursor: pointer;
}
.form-check input { cursor: pointer; }

.btn {
    display: inline-block; padding: 11px 22px;
    background: var(--accent); color: white; border: none;
    border-radius: var(--radius); font-family: inherit; font-size: 14px;
    font-weight: 500; cursor: pointer;
    transition: background 0.2s, transform 0.1s; text-align: center;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); }
.btn-secondary:hover { background: var(--bg-hover); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #c83232; }
.btn-success { background: var(--success); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.auth-footer { text-align: center; margin-top: 20px; color: var(--text-secondary); font-size: 14px; }

/* ─────────────────────────── LAYOUT ───────────────────────────────────── */
.layout { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

/* Sidebar */
.sidebar {
    width: 260px; background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    display: flex; flex-direction: column; flex-shrink: 0;
    min-height: 0;
    overflow-y: auto;             /* اسکرولِ واحد: منو + لیستِ چت با یک اسکرول بالا/پایین می‌روند */
    transition: margin 0.3s ease;
}
.sidebar.collapsed { margin-right: -260px; }

.sidebar-header {
    padding: 12px; display: flex; gap: 6px; align-items: center;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    position: sticky; top: 0; z-index: 3;   /* هنگامِ اسکرول، «گفت‌وگو جدید» بالا می‌ماند */
    background: var(--bg-secondary);
}
.btn-icon {
    background: transparent; border: none; color: var(--text-secondary);
    width: 36px; height: 36px; border-radius: var(--radius);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, color 0.15s; flex-shrink: 0;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-new-chat {
    flex: 1; background: transparent; color: var(--text-primary);
    border: 1px solid var(--border); padding: 8px 12px;
    border-radius: var(--radius); font-family: inherit; font-size: 13px;
    font-weight: 500; cursor: pointer; display: flex; align-items: center;
    justify-content: center; gap: 8px; transition: background 0.15s;
    text-decoration: none;
}
.btn-new-chat:hover { background: var(--bg-hover); color: var(--text-primary); }

.sidebar-nav {
    padding: 6px; border-bottom: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 2px;
    /* بدونِ اسکرولِ مستقل — همراهِ لیستِ چت‌ها در اسکرولِ واحدِ sidebar حرکت می‌کند */
    flex-shrink: 0;
}
.nav-item {
    display: flex; align-items: center; gap: 10px; padding: 8px 10px;
    border-radius: var(--radius); color: var(--text-primary);
    cursor: pointer; transition: background 0.15s;
    font-size: 13.5px; text-decoration: none; flex-shrink: 0;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }

/* لیستِ چت‌ها ارتفاعِ طبیعی می‌گیرد و در اسکرولِ واحدِ sidebar پایین می‌رود */
.chat-list { flex: 0 0 auto; padding: 4px; }
.empty-list-msg {
    padding: 30px 20px; color: #f7f7f9; font-size: 12.5px;
    text-align: center;
}
.chat-section-title {
    font-size: 11.5px; color: #f7f7f9;
    padding: 14px 12px 6px; font-weight: 500;
}

.chat-item {
    display: flex; align-items: center; gap: 10px; padding: 8px 10px;
    border-radius: var(--radius); color: var(--text-primary);
    cursor: pointer; transition: background 0.15s;
    text-decoration: none; margin-bottom: 1px; position: relative;
}
.chat-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.chat-item.active { background: rgba(155, 109, 255, 0.12); }

.chat-item-avatar {
    width: 26px; height: 26px; border-radius: 50%;
    object-fit: cover; flex-shrink: 0; background: var(--bg-tertiary);
}
.avatar-fallback {
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 600; color: var(--text-secondary);
}

.chat-item-title {
    flex: 1; font-size: 13px; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
}

.chat-item-actions { display: none; gap: 2px; }
.chat-item:hover .chat-item-actions { display: flex; }
.chat-action-btn {
    background: transparent; border: none; color: var(--text-secondary);
    width: 24px; height: 24px; border-radius: var(--radius-sm);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.chat-action-btn:hover { background: var(--border-light); color: var(--text-primary); }

.sidebar-footer {
    padding: 10px; border-top: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 4px;
}
.user-info {
    display: flex; align-items: center; gap: 10px; padding: 6px;
    border-radius: var(--radius); text-decoration: none;
    color: var(--text-primary); transition: background 0.15s;
}
.user-info:hover { background: var(--bg-hover); }
.user-avatar {
    width: 30px; height: 30px; background: var(--accent); color: white;
    border-radius: 50%; display: flex; align-items: center;
    justify-content: center; font-weight: 600; flex-shrink: 0; font-size: 13px;
}
.user-meta { flex: 1; min-width: 0; }
.user-meta .name {
    font-size: 12.5px; font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-meta .quota { font-size: 11px; color: #f7f7f9; }
.nav-logout { font-size: 12.5px; color: var(--text-secondary); }

/* ═════════════════════════ MAIN CHAT AREA ════════════════════════════ */
.main {
    flex: 1; display: flex; flex-direction: column;
    min-width: 0; background: var(--bg-primary);
    position: relative;
}

/* Header — model dropdown on the left, hamburger on the right */
.main-header {
    padding: 8px 16px; height: 52px;
    display: flex; align-items: center; justify-content: space-between;
    flex-shrink: 0; background: var(--bg-primary);
}
.header-right { display: flex; align-items: center; gap: 4px; }
.header-left  { display: flex; align-items: center; gap: 4px; }

/* Model picker (top of main area) */
.model-picker { position: relative; }
.model-picker-btn {
    display: flex; align-items: center; gap: 6px;
    background: transparent; border: none; color: var(--text-primary);
    padding: 8px 12px; border-radius: var(--radius);
    font-family: inherit; font-size: 16px; font-weight: 600;
    cursor: pointer; transition: background 0.15s;
}
.model-picker-btn:hover:not(:disabled) { background: var(--bg-hover); }
.model-picker-btn:disabled { cursor: default; opacity: 1; }

.model-dropdown {
    position: absolute; top: calc(100% + 4px); left: 0;
    background: var(--bg-menu); border: 1px solid var(--border);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-menu);
    min-width: 280px; max-height: 400px; overflow-y: auto;
    z-index: 100; padding: 6px;
    opacity: 0; visibility: hidden; transform: translateY(-6px);
    transition: opacity 0.15s, transform 0.15s, visibility 0.15s;
}
.model-dropdown.show {
    opacity: 1; visibility: visible; transform: translateY(0);
}
.model-dropdown-item {
    display: flex; align-items: center; gap: 10px; padding: 10px;
    border-radius: var(--radius); cursor: pointer;
    transition: background 0.15s;
}
.model-dropdown-item:hover { background: var(--bg-menu-hover); }
.model-dropdown-item.selected { background: rgba(155, 109, 255, 0.15); }
.model-dropdown-icon { width: 32px; height: 32px; border-radius: 6px; flex-shrink: 0; object-fit: cover; }
.model-dropdown-info { flex: 1; min-width: 0; }
.model-dropdown-name { font-size: 14px; font-weight: 500; }
.model-dropdown-desc { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.model-dropdown-id { font-size: 11px; color: var(--text-muted); margin-top: 2px; font-family: monospace; }
.badge-premium-mini { font-size: 14px; }

/* ─── Mobile-only simple model dropdown ───
   فقط در موبایل (≤768px) نمایش داده می‌شود — به‌جای modal categorized */
.model-mobile-dropdown {
    display: none;
    position: absolute; top: calc(100% + 6px); right: 0; left: auto;
    background: var(--bg-menu, var(--bg-secondary));
    border: 1px solid var(--border);
    border-radius: var(--radius-lg, 12px);
    box-shadow: var(--shadow-menu, 0 8px 24px rgba(0,0,0,0.35));
    min-width: 240px; max-width: 88vw;
    max-height: 60vh; overflow-y: auto;
    z-index: 200; padding: 6px;
}
.model-mobile-dropdown.show { display: block; }
.model-mobile-item {
    display: flex; align-items: center; gap: 10px;
    width: 100%; padding: 10px 12px;
    background: transparent; border: none; color: var(--text-primary);
    text-align: right; font-family: inherit; font-size: 14px;
    border-radius: var(--radius, 8px);
    cursor: pointer; transition: background 0.15s;
}
.model-mobile-item:hover, .model-mobile-item:focus { background: var(--bg-menu-hover, var(--bg-hover)); }
.model-mobile-item.selected { background: rgba(155, 109, 255, 0.18); }
/* ── آیتم/کارتِ «خودکار» (smart routing) ── */
.model-mobile-auto { background: linear-gradient(135deg, rgba(155,109,255,0.14), rgba(155,109,255,0.04)); font-weight: 600; }
.model-mobile-auto .model-mobile-badge { background: var(--accent, #9b6dff); color: #fff; }
.mp-card-auto {
    border: 1px solid rgba(155,109,255,0.45) !important;
    background: linear-gradient(135deg, rgba(155,109,255,0.12), rgba(155,109,255,0.03)) !important;
}
.mp-auto-block .mp-section-title { color: var(--accent-light, #b48dff); }

/* ── پایگاه دانش (RAG): منو + chipهای پیوست در composer ── */
.kn-attach-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 4px 0; }
.kn-chip {
    display: inline-flex; align-items: center; gap: 6px;
    background: rgba(155,109,255,0.14); color: var(--accent-light, #b48dff);
    border: 1px solid rgba(155,109,255,0.3);
    border-radius: var(--radius-pill, 999px); padding: 3px 10px; font-size: 12px;
}
.kn-chip button {
    background: none; border: none; color: inherit; cursor: pointer;
    font-size: 13px; line-height: 1; padding: 0; opacity: .7;
}
.kn-chip button:hover { opacity: 1; }
.kn-menu {
    position: absolute; bottom: calc(100% + 8px); inset-inline-start: 0;
    min-width: 260px; max-width: 340px; max-height: 320px; overflow-y: auto;
    background: var(--bg-menu, var(--bg-secondary)); border: 1px solid var(--border);
    border-radius: var(--radius-lg, 14px); box-shadow: var(--shadow);
    padding: 8px; z-index: 60; display: none;
}
.kn-menu.show { display: block; }
.kn-menu-title { font-size: 12px; color: var(--text-muted); padding: 4px 8px 8px; font-weight: 600; }
.kn-menu-item {
    display: flex; align-items: center; gap: 10px; padding: 8px;
    border-radius: var(--radius, 8px); cursor: pointer;
	color: var(--text-muted);
}
.kn-menu-item:hover { background: var(--bg-hover); }
.kn-menu-item .kn-menu-name { flex: 1; font-size: 13.5px; }
.kn-menu-item .kn-menu-meta { font-size: 11px; color: var(--text-muted); }
.kn-menu-link {
    display: block; text-align: center; padding: 8px; margin-top: 4px;
    border-top: 1px solid var(--border); color: var(--accent-light, #b48dff);
    font-size: 13px; text-decoration: none;
}
.kn-menu-loading, .kn-menu-empty { padding: 14px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ── Command Palette (Ctrl/Cmd+K) ── */
.cmdk-overlay {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(0,0,0,0.45); backdrop-filter: blur(2px);
    display: flex; align-items: flex-start; justify-content: center;
    padding-top: 12vh;
}
.cmdk-overlay[hidden] { display: none; }
.cmdk-box {
    width: min(620px, 92vw); max-height: 70vh; display: flex; flex-direction: column;
    background: var(--bg-secondary); border: 1px solid var(--border);
    border-radius: var(--radius-lg, 16px); box-shadow: var(--shadow);
    overflow: hidden; animation: cmdk-in .12s ease;
}
@keyframes cmdk-in { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }
.cmdk-input-wrap {
    display: flex; align-items: center; gap: 10px; padding: 14px 16px;
    border-bottom: 1px solid var(--border); color: var(--text-muted);
}
.cmdk-input-wrap input {
    flex: 1; background: none; border: none; outline: none;
    color: var(--text-primary); font-size: 16px; font-family: inherit;
}
.cmdk-esc { font-size: 11px; padding: 2px 6px; border: 1px solid var(--border); border-radius: 5px; color: var(--text-muted); }
.cmdk-results { overflow-y: auto; padding: 6px; }
.cmdk-group { font-size: 11px; color: var(--text-muted); padding: 8px 10px 4px; font-weight: 600; }
.cmdk-item {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px;
    border-radius: var(--radius, 10px); cursor: pointer;
}
.cmdk-item.active { background: rgba(155,109,255,0.16); }
.cmdk-icon { font-size: 17px; width: 22px; text-align: center; }
.cmdk-label { flex: 0 0 auto; max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmdk-sub { color: var(--text-muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmdk-empty { padding: 24px; text-align: center; color: var(--text-muted); font-size: 14px; }

/* ── پوشه‌بندیِ گفتگوها (sidebar) ── */
/* ── جستجوی محلیِ گفتگوها (بالای لیست) ── */
.chat-search-wrap {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 10px; margin: 2px 2px 8px;
    background: var(--bg-tertiary, rgba(255,255,255,0.04));
    border: 1px solid var(--border); border-radius: var(--radius, 8px);
    color: var(--text-muted);
}
.chat-search-wrap svg { flex-shrink: 0; opacity: .75; }
.chat-search {
    flex: 1; min-width: 0; background: none; border: none; outline: none;
    color: var(--text-primary); font-family: inherit; font-size: 13px;
}
.chat-search::placeholder { color: var(--text-muted); }

.chat-new-folder-btn {
    display: flex; align-items: center; gap: 8px; width: 100%;
    padding: 8px 10px; margin: 2px 0 8px; background: none; border: 1px dashed var(--border);
    border-radius: var(--radius, 8px); color: var(--text-muted); cursor: pointer;
    font-family: inherit; font-size: 13px; transition: all .15s;
}
.chat-new-folder-btn:hover { color: var(--accent-light, #b48dff); border-color: var(--accent, #9b6dff); }
.chat-folder { margin-bottom: 4px; }
.chat-folder > summary { list-style: none; }
.chat-folder > summary::-webkit-details-marker { display: none; }
.chat-folder-head {
    display: flex; align-items: center; gap: 8px; padding: 7px 8px;
    border-radius: var(--radius, 8px); cursor: pointer; color: var(--text-secondary);
    font-size: 13px; font-weight: 600;
}
.chat-folder-head:hover { background: var(--bg-hover); }
.chat-folder-head svg { color: var(--folder-color, #9b6dff); flex: 0 0 auto; }
.chat-folder-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-folder-count { font-size: 11px; color: var(--text-muted); background: var(--bg-tertiary); padding: 1px 7px; border-radius: 10px; }
.chat-folder-head .chat-action-btn { opacity: 0; }
.chat-folder-head:hover .chat-action-btn { opacity: .7; }
.chat-folder-body { padding-inline-start: 10px; border-inline-start: 2px solid var(--folder-color, rgba(155,109,255,0.25)); margin-inline-start: 8px; }
.chat-folder[open] > summary .chat-folder-name { color: var(--text-primary); }

/* ── صفحهٔ اشتراکِ عمومی (read-only) ── */
.share-page { max-width: 820px; margin: 0 auto; padding: 16px; width: 100%; }
.share-topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 12px 0 16px; border-bottom: 1px solid var(--border); margin-bottom: 18px;
}
.share-brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.share-conversation { display: flex; flex-direction: column; gap: 18px; }
.share-conversation .msg { display: flex; }
.share-conversation .msg-user { justify-content: flex-start; }
.share-conversation .msg-user .msg-content {
    background: var(--bg-tertiary); border-radius: var(--radius-lg, 16px); padding: 12px 16px; max-width: 85%;
}
.share-conversation .msg-assistant .msg-content { max-width: 100%; line-height: 1.85; }
.share-conversation .msg-content pre {
    background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 10px;
    padding: 12px; overflow-x: auto; direction: ltr; text-align: left;
}
.share-conversation .msg-content code { font-family: ui-monospace, monospace; }
.share-footer {
    margin-top: 32px; padding-top: 18px; border-top: 1px solid var(--border);
    text-align: center; color: var(--text-muted); font-size: 13px;
    display: flex; flex-direction: column; gap: 8px; align-items: center;
}
.share-footer a { color: var(--accent-light, #b48dff); }

/* ── تورِ onboarding ── */
.ob-overlay {
    position: fixed; inset: 0; z-index: 220; background: rgba(0,0,0,0.55);
    backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 16px;
}
.ob-overlay[hidden] { display: none; }
.ob-card {
    position: relative; width: min(440px, 94vw); text-align: center;
    background: var(--bg-secondary); border: 1px solid var(--border);
    border-radius: var(--radius-lg, 18px); box-shadow: var(--shadow); padding: 28px 24px 20px;
    animation: cmdk-in .15s ease;
}
.ob-skip { position: absolute; top: 12px; inset-inline-end: 14px; background: none; border: none; color: var(--text-muted); cursor: pointer; font-family: inherit; font-size: 13px; }
.ob-emoji { font-size: 44px; margin-bottom: 10px; }
.ob-title { margin: 0 0 8px; font-size: 19px; }
.ob-desc { margin: 0 0 18px; color: var(--text-secondary); line-height: 1.85; font-size: 14px; }
.ob-dots { display: flex; gap: 6px; justify-content: center; margin-bottom: 18px; }
.ob-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border); }
.ob-dot.active { background: var(--accent, #9b6dff); width: 18px; border-radius: 4px; }
.ob-actions { display: flex; gap: 10px; justify-content: center; }
.ob-actions .btn { min-width: 90px; }
.model-mobile-icon {
    width: 28px; height: 28px; border-radius: 6px;
    flex-shrink: 0; object-fit: cover;
    display: inline-flex; align-items: center; justify-content: center;
}
.model-mobile-icon-fallback {
    background: var(--bg-tertiary, rgba(255,255,255,0.06));
    color: var(--text-secondary); font-size: 11px; font-weight: 600;
}
.model-mobile-name {
    flex: 1; min-width: 0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.model-mobile-badge {
    font-size: 11px; padding: 2px 6px;
    border-radius: 6px; flex-shrink: 0;
    background: rgba(155, 109, 255, 0.15); color: var(--accent-light, #c4b5fd);
}
.model-mobile-badge.model-mobile-free {
    background: rgba(34, 197, 94, 0.15); color: #22c55e;
}
/* دراپ‌داونِ سادهٔ مدل روی همهٔ اندازه‌ها فعال است (پنجرهٔ مفصلِ قدیمی حذف شد). */

/* Chat area */
.chat-area {
    flex: 1; overflow-y: auto; padding: 0 20px 16px; scroll-behavior: smooth;
}

/* Empty state — centered greeting like screenshot */
.empty-chat {
    display: flex; align-items: center; justify-content: center;
    height: 100%; min-height: 400px;
}
.empty-chat-content {
    text-align: center; padding: 30px;
}
.empty-chat-icon {
    color: var(--accent); margin-bottom: 18px;
    display: inline-flex; opacity: 0.85;
}
.empty-chat h2 {
    font-size: 28px; font-weight: 600;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--accent-light), var(--accent));
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent;
}
.empty-chat p { color: var(--text-secondary); font-size: 15px; }

/* ── Quality / Cost picker در empty-chat ── */
.empty-quality-block {
    max-width: 760px;
    margin: 32px auto 0;
    padding: 18px 18px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 14px;
    text-align: right;
    direction: rtl;
}
.empty-quality-head {
    display: flex; align-items: flex-start; gap: 10px;
    margin-bottom: 14px;
}
.eq-emoji {
    font-size: 20px;
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    background: rgba(155, 109, 255, 0.10);
    border-radius: 9px;
    flex-shrink: 0;
}
.eq-title {
    font-size: 15px; font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 2px;
    -webkit-text-fill-color: initial;
    background: none;
}
.eq-sub {
    font-size: 12.5px; color: var(--text-secondary);
}
.empty-quality-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.eq-card {
    padding: 14px 12px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    text-align: center;
    transition: all 0.18s ease;
    color: var(--text-primary);
    font-family: inherit;
    display: flex; flex-direction: column;
    align-items: center; gap: 4px;
}
.eq-card:hover {
    border-color: var(--accent);
    background: rgba(155, 109, 255, 0.06);
    transform: translateY(-1px);
}
.eq-card.selected {
    border-color: var(--accent);
    background: rgba(155, 109, 255, 0.10);
    box-shadow: 0 0 0 1px rgba(155, 109, 255, 0.25);
}
.eq-card-emoji { font-size: 26px; margin-bottom: 2px; }
.eq-card-title {
    font-size: 13.5px; font-weight: 700;
    color: var(--text-primary);
}
.eq-card-desc {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.45;
}

@media (max-width: 640px) {
    .empty-quality-block {
        margin: 24px 12px 0;
        padding: 14px 14px 12px;
    }
    .empty-quality-row { grid-template-columns: 1fr; gap: 8px; }
    .eq-card { padding: 12px 10px; flex-direction: row; gap: 10px; text-align: right; }
    .eq-card-emoji { font-size: 22px; margin-bottom: 0; }
    .eq-card-title { font-size: 13px; }
    .eq-card-desc { font-size: 11px; }
    .empty-quality-head { gap: 8px; margin-bottom: 12px; }
}

/* Message list */
.message-list {
    max-width: 760px; margin: 0 auto;
    display: flex; flex-direction: column;
    gap: 28px; padding: 16px 0 24px;
}

/* Generic message blocks */
.msg {
    display: flex; flex-direction: column;
    animation: msgFadeIn 0.25s ease;
}
@keyframes msgFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* User message — right-aligned bubble */
.msg-user {
    align-items: flex-start;     /* RTL: flex-start = right */
    align-self: flex-end;
    max-width: 75%;
}
.msg-user .msg-bubble {
    background: var(--bg-user-msg);
    padding: 10px 18px;
    border-radius: 22px;
    font-size: 14.5px; line-height: 1.7;
    word-wrap: break-word;
    color: var(--text-primary);
}
.msg-user .msg-actions {
    display: flex; gap: 4px;
    justify-content: flex-start; /* RTL: actions on the right under the bubble */
    margin-top: 6px; opacity: 0; transition: opacity 0.15s;
}
.msg-user:hover .msg-actions { opacity: 1; }

/* Assistant message — plain text, no bubble */
.msg-assistant {
    align-self: flex-start;
    max-width: 100%;
    width: 100%;
}
.msg-assistant .msg-content {
    font-size: 14.5px; line-height: 1.75;
    white-space: pre-wrap; word-wrap: break-word;
    color: var(--text-primary);
}
/* ── کنترل فاصلهٔ paragraph در پاسخ‌ها ──
   با pre-wrap هر \n\n یک خط خالی visible می‌سازد. CSS زیر فاصلهٔ
   ایجادشده توسط block elements (LaTeX، code، table، list) را
   استاندارد می‌کند تا spacing یکنواخت باشد. */
.msg-assistant .msg-content > .katex-display,
.msg-assistant .msg-content .katex-display {
    margin: 0.6em 0 !important;
}
.msg-assistant .msg-content .code-block-wrap {
    margin: 0.7em 0;
}
.msg-assistant .msg-content > .table-responsive,
.msg-assistant .msg-content > ul,
.msg-assistant .msg-content > ol,
.msg-assistant .msg-content > blockquote {
    margin: 0.5em 0;
}
.msg-assistant .msg-content h1,
.msg-assistant .msg-content h2,
.msg-assistant .msg-content h3,
.msg-assistant .msg-content h4 {
    margin: 0.7em 0 0.35em 0;
    line-height: 1.4;
}
.msg-assistant .msg-content p {
    margin: 0.4em 0;
}
.msg-assistant .msg-actions {
    display: flex; gap: 4px; margin-top: 10px;
    opacity: 0.6; transition: opacity 0.15s;
}
.msg-assistant:hover .msg-actions { opacity: 1; }

.msg-error .msg-content {
    color: #fca5a5;
    background: rgba(239, 68, 68, 0.08);
    padding: 12px 16px;
    border-radius: var(--radius);
    border-right: 3px solid var(--danger);
}

/* Action buttons under each message */
.msg-action-btn {
    background: transparent; border: none;
    color: #f7f7f9;
    width: 30px; height: 30px;
    border-radius: var(--radius-sm); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, color 0.15s;
}
.msg-action-btn:hover {
    background: var(--bg-hover); color: var(--text-primary);
}
.msg-action-btn.active {
    color: var(--accent-light);
}

/* Code blocks inside messages */
.msg-content code, .msg-bubble code {
    background: rgba(0, 0, 0, 0.35);
    padding: 2px 6px; border-radius: 4px;
    font-family: 'Fira Code', monospace; font-size: 0.88em;
}
.msg-content pre, .msg-bubble pre {
    background: #0f0f0f; padding: 14px;
    border-radius: var(--radius); overflow-x: auto;
    margin: 10px 0; border: 1px solid var(--border);
    direction: ltr; text-align: left;
}
.msg-content pre code, .msg-bubble pre code {
    background: none; padding: 0;
}

/* Attachments inside user message bubbles (image previews) */
.msg-attachments {
    display: flex; flex-wrap: wrap; gap: 6px;
    margin-bottom: 6px;
}
.msg-attachment-img {
    max-width: 240px; max-height: 240px;
    border-radius: 12px; object-fit: cover;
    cursor: pointer;
    border: 1px solid var(--border);
}
.msg-attachment-img:hover { opacity: 0.95; }
.msg-attachment-file {
    display: inline-flex; align-items: center; gap: 6px;
    background: rgba(0, 0, 0, 0.3); padding: 6px 10px;
    border-radius: var(--radius); font-size: 12.5px;
}
.msg-text {
    /* keep content readable next to images */
    margin-top: 2px;
}

/* Image generated by AI inside assistant messages */
.msg-generated-image {
    margin: 12px 0;
    max-width: 512px;
}
.msg-generated-image img {
    width: 100%; height: auto;
    border-radius: 12px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: transform 0.2s;
}
.msg-generated-image img:hover { transform: scale(1.01); }

/* Typing indicator — mimics "در حال پردازش • • •" */
.typing-indicator {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 0; color: var(--text-secondary);
    font-size: 14px; animation: msgFadeIn 0.25s;
}
.typing-dots {
    display: inline-flex; gap: 4px;
}
.typing-dots span {
    width: 5px; height: 5px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: typingBlink 1.4s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBlink {
    0%, 60%, 100% { opacity: 0.3; }
    30% { opacity: 1; }
}

/* ═════════════════════════ COMPOSER (INPUT) ══════════════════════════ */
.composer-wrap {
    padding: 8px 16px 14px;
    flex-shrink: 0;
    background: var(--bg-primary);
}

/* Selected tool badges (above input) */
.selected-tools {
    max-width: 760px; margin: 0 auto 6px;
    display: flex; flex-wrap: wrap; gap: 6px;
}
.tool-badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 12px;
    background: rgba(155, 109, 255, 0.15);
    border: 1px solid rgba(155, 109, 255, 0.4);
    color: var(--accent-light);
    border-radius: var(--radius-pill);
    font-size: 12.5px; font-weight: 500;
    cursor: pointer;
}
.tool-badge:hover { background: rgba(155, 109, 255, 0.25); }
.tool-badge .remove {
    display: inline-flex; align-items: center; justify-content: center;
    width: 16px; height: 16px;
}

/* Attachment previews (file/image) */
.attachment-previews {
    max-width: 760px; margin: 0 auto;
    display: flex; flex-wrap: wrap; gap: 6px;
}
.attachment-previews:not(:empty) { margin-bottom: 6px; }
.attachment-card {
    position: relative;
    width: 60px; height: 60px;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
}
.attachment-card img {
    width: 100%; height: 100%; object-fit: cover;
}
.attachment-card .remove-attach {
    position: absolute; top: 2px; right: 2px;
    width: 18px; height: 18px;
    background: rgba(0, 0, 0, 0.7); color: white;
    border: none; border-radius: 50%; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; line-height: 1;
}
/* پیش‌نمایشِ فایلِ غیرتصویری در کامپوزر — آیکونِ فایل به‌جای عکسِ شکسته */
.attachment-card.attachment-file {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; padding: 5px; text-align: center;
}
.attachment-file-emoji { font-size: 24px; line-height: 1; }
.attachment-file-name {
    font-size: 9px; line-height: 1.2; color: var(--text-secondary);
    max-width: 100%; overflow: hidden; word-break: break-all;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}

/* Composer row */
.composer {
    max-width: 760px; margin: 0 auto;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 26px;
    padding: 6px 8px 6px 6px;
    display: flex; align-items: flex-end;
    gap: 6px;
    transition: border 0.2s;
}
.composer:focus-within { border-color: var(--border-light); }

.composer-plus-wrap { position: relative; }

.composer-plus-btn {
    background: transparent; border: 1px solid var(--border-light);
    color: var(--text-secondary);
    width: 36px; height: 36px; border-radius: 50%;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: all 0.15s; flex-shrink: 0;
}
.composer-plus-btn:hover {
    background: var(--bg-hover); color: var(--text-primary);
    border-color: var(--text-secondary);
}
.composer-plus-btn.active {
    background: var(--text-primary); color: var(--bg-primary);
    border-color: var(--text-primary);
}

.composer-input {
    flex: 1; background: transparent; border: none;
    color: var(--text-primary);
    font-family: inherit; font-size: 14.5px;
    line-height: 1.6; resize: none;
    padding: 8px 6px; max-height: 200px; outline: none;
    min-height: 24px;
}
.composer-input::placeholder { color: #f7f7f9; }

.composer-right {
    display: flex; align-items: center; gap: 4px; flex-shrink: 0;
}
.composer-icon-btn {
    background: transparent; border: none;
    color: var(--text-secondary);
    width: 36px; height: 36px; border-radius: 50%;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: background 0.15s;
}
.composer-icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-send {
    background: var(--text-primary); color: var(--bg-primary);
    border: none; width: 36px; height: 36px; border-radius: 50%;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: all 0.2s; flex-shrink: 0;
}
.btn-send:hover:not(:disabled) { background: white; }
.btn-send:disabled {
    background: var(--bg-tertiary); color: #f7f7f9;
    cursor: not-allowed;
}
.btn-send.is-stopping {
    background: #ef4444;
    color: #ffffff;
    animation: pulse-stop 1.4s ease-in-out infinite;
}
.btn-send.is-stopping:hover:not(:disabled) { background: #dc2626; }
@keyframes pulse-stop {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.45); }
    50%      { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

.input-disclaimer {
    text-align: center; font-size: 11.5px;
    color: #f7f7f9; margin-top: 8px;
}

/* ═══════════════════ TOOL MENU (PLUS dropdown) ══════════════════════ */
.tool-menu, .tool-submenu {
    position: absolute;
    bottom: calc(100% + 8px);
    background: var(--bg-menu);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-menu);
    padding: 6px;
    min-width: 220px;
    opacity: 0; visibility: hidden;
    transform: translateY(8px);
    transition: opacity 0.15s, transform 0.15s, visibility 0.15s;
    z-index: 50;
}
.tool-menu { right: 0; }
.tool-submenu {
    right: calc(100% + 8px); /* opens to the LEFT of main menu in RTL */
    bottom: 0;
}
.tool-menu.show, .tool-submenu.show {
    opacity: 1; visibility: visible; transform: translateY(0);
}

.tool-item {
    display: flex; align-items: center; gap: 12px;
    padding: 9px 12px; border-radius: var(--radius);
    cursor: pointer; color: var(--text-primary);
    font-size: 13.5px; transition: background 0.12s;
    user-select: none;
    justify-content: flex-start;
    text-align: right;
}
.tool-item:hover { background: var(--bg-menu-hover); }
.tool-item.active {
    background: rgba(155, 109, 255, 0.15);
    color: var(--accent-light);
}
.tool-item-icon {
    width: 18px; height: 18px;
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--text-secondary); flex-shrink: 0;
}
.tool-item.active .tool-item-icon { color: var(--accent-light); }
.tool-item-label { flex: 1; }
.tool-item-arrow {
    color: #f7f7f9; font-size: 12px;
    display: inline-flex; align-items: center;
}
.tool-item-cost {
    font-size: 11px; color: #f7f7f9;
    background: var(--bg-primary);
    padding: 2px 6px; border-radius: 8px;
}

.tool-menu-empty {
    padding: 16px 12px; text-align: center;
    color: #f7f7f9; font-size: 13px;
}

/* ─────────────────────────── MODELS PAGE ──────────────────────────────── */
.models-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px; padding: 20px;
    max-width: 1200px; margin: 0 auto;
}
.model-card {
    background: var(--bg-secondary); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 18px;
    cursor: pointer; transition: all 0.2s;
    text-decoration: none; color: inherit;
    display: flex; flex-direction: column; gap: 12px;
}
.model-card:hover {
    border-color: var(--accent); transform: translateY(-2px);
    color: inherit;
}
.model-card-header { display: flex; align-items: center; gap: 12px; }
.model-card-avatar {
    width: 44px; height: 44px; border-radius: 10px;
    object-fit: cover; background: var(--bg-tertiary);
}
.model-card-title { font-weight: 600; font-size: 15px; }
.model-card-provider { font-size: 12px; color: #f7f7f9; margin-top: 2px; }
.model-card-desc { color: var(--text-secondary); font-size: 13px; flex: 1; }
.model-card-footer {
    display: flex; justify-content: space-between; align-items: center;
    padding-top: 10px; border-top: 1px solid var(--border); font-size: 12px;
}
.model-card-tools {
    display: flex; flex-wrap: wrap; gap: 4px;
}
.tool-tag {
    font-size: 10.5px; padding: 2px 7px;
    background: rgba(155, 109, 255, 0.12);
    color: var(--accent-light);
    border-radius: 6px;
}

/* ─────────────── Models page v2 — GapGPT-style grouped layout ─────────────── */
.models-page { padding: 0; }

.models-hero {
    text-align: center;
    padding: 36px 24px 16px;
    max-width: 920px; margin: 0 auto;
}
.models-hero-title {
    font-size: 30px; font-weight: 700; margin: 0 0 6px;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}
.models-hero-sub {
    color: var(--text-secondary); font-size: 14px; margin: 0;
}

.models-tabs {
    display: flex; align-items: center; gap: 4px;
    overflow-x: auto; overflow-y: hidden;
    padding: 14px 24px 12px;
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 5;
    background: var(--bg-primary);
    scrollbar-width: thin;
    direction: rtl;
}
.models-tabs::-webkit-scrollbar { height: 4px; }
.models-tabs::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.models-tab {
    flex-shrink: 0;
    background: transparent; border: 0;
    padding: 10px 16px; border-radius: 999px;
    color: var(--text-secondary);
    font-size: 13.5px; font-weight: 500;
    cursor: pointer; transition: all 0.15s ease;
    position: relative; white-space: nowrap;
    font-family: inherit;
}
.models-tab:hover {
    color: var(--text-primary);
    background: rgba(155, 109, 255, 0.07);
}
.models-tab.active {
    color: #10b981;
    font-weight: 700;
}
.models-tab.active::after {
    content: '';
    position: absolute;
    left: 16px; right: 16px; bottom: -13px;
    height: 2px; background: #10b981;
    border-radius: 1px;
}

.models-sections {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
    display: flex; flex-direction: column; gap: 36px;
}

.models-section { animation: fadeInUp 0.3s ease both; }
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0);  }
}

.models-section-head { margin-bottom: 16px; }
.models-section-title {
    font-size: 20px; font-weight: 700; margin: 0 0 4px;
    color: var(--text-primary);
}
.models-section-sub {
    margin: 0; color: var(--text-secondary); font-size: 13px;
}

.models-grid-v2 {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
}

.model-card-v2 {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px 18px 14px;
    display: flex; flex-direction: column; gap: 12px;
    transition: all 0.2s ease;
    position: relative;
    min-height: 200px;
}
.model-card-v2:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(0,0,0,0.18);
}

.mcv-head {
    display: flex; align-items: flex-start;
    justify-content: space-between; gap: 10px;
}
.mcv-meta { flex: 1; min-width: 0; }
.mcv-title {
    font-size: 16px; font-weight: 700; margin: 0 0 2px;
    color: var(--text-primary);
    line-height: 1.3;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mcv-provider {
    font-size: 12px; color: var(--text-secondary);
    font-weight: 500;
}

.mcv-avatar {
    width: 40px; height: 40px; border-radius: 10px;
    background: rgba(155, 109, 255, 0.12);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; overflow: hidden;
}
.mcv-avatar img {
    width: 100%; height: 100%; object-fit: cover; border-radius: 10px;
}
.mcv-avatar-fallback {
    font-size: 13px; font-weight: 700;
    color: var(--accent-light);
    text-transform: uppercase;
}
.mcv-mfr-openai    { background: rgba(16, 163, 127, 0.15); color: #10a37f; }
.mcv-mfr-anthropic { background: rgba(217, 119, 87, 0.15); color: #d97757; }
.mcv-mfr-google    { background: rgba(66, 133, 244, 0.15); color: #4285f4; }
.mcv-mfr-xai       { background: rgba(82, 82, 91, 0.18);  color: #d1d5db; }
.mcv-mfr-deepseek  { background: rgba(77, 107, 254, 0.15); color: #4d6bfe; }
.mcv-mfr-qwen      { background: rgba(97, 92, 237, 0.15);  color: #615ced; }
.mcv-mfr-other     { background: rgba(148, 163, 184, 0.18); color: #94a3b8; }

.mcv-desc {
    color: var(--text-secondary);
    font-size: 13px; line-height: 1.55;
    margin: 0;
    flex: 1;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.mcv-badges {
    display: flex; flex-wrap: wrap; gap: 5px;
}
.mcv-badge {
    font-size: 10.5px; font-weight: 600;
    padding: 3px 8px; border-radius: 6px;
    line-height: 1.5;
}
.mcv-badge-premium { background: rgba(245, 158, 11, 0.14); color: #f59e0b; }
.mcv-badge-free    { background: rgba(16, 185, 129, 0.14); color: #10b981; }
.mcv-badge-info    { background: rgba(59, 130, 246, 0.14); color: #60a5fa; }
.mcv-badge-ctx     { background: rgba(155, 109, 255, 0.14); color: var(--accent-light); }

.mcv-cta {
    display: flex; align-items: center; justify-content: center;
    gap: 6px;
    padding: 9px 14px;
    background: rgba(16, 185, 129, 0.10);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.25);
    border-radius: 10px;
    font-size: 13.5px; font-weight: 600;
    text-decoration: none;
    transition: all 0.15s ease;
    margin-top: auto;
}
.mcv-cta:hover {
    background: rgba(16, 185, 129, 0.18);
    border-color: rgba(16, 185, 129, 0.45);
    color: #10b981;
}
.mcv-cta svg { transform: scaleX(-1); }  /* فلش به سمت چپ (RTL) */

/* ── Tablet (≤768px) ── */
@media (max-width: 768px) {
    .models-hero { padding: 22px 16px 8px; }
    .models-hero-title { font-size: 24px; }
    .models-hero-sub { font-size: 13px; }
    .models-tabs {
        padding: 10px 14px 12px;
        gap: 2px;
        -webkit-overflow-scrolling: touch;
    }
    .models-tab {
        padding: 8px 13px; font-size: 13px;
    }
    .models-tab.active::after { bottom: -13px; left: 13px; right: 13px; }
    .models-sections { padding: 16px 14px 24px; gap: 26px; }
    .models-section-title { font-size: 17px; }
    .models-section-sub { font-size: 12px; }
    .models-grid-v2 {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 10px;
    }
    .model-card-v2 { padding: 14px 14px 12px; min-height: 180px; gap: 10px; }
    .mcv-title { font-size: 14.5px; }
    .mcv-desc { font-size: 12.5px; -webkit-line-clamp: 2; }
    .mcv-cta { padding: 8px 12px; font-size: 13px; }
}

/* ── Phone portrait (≤520px) — single column ── */
@media (max-width: 520px) {
    .models-hero { padding: 18px 14px 6px; }
    .models-hero-title { font-size: 21px; letter-spacing: 0; }
    .models-hero-sub { font-size: 12.5px; }
    .models-tabs {
        padding: 8px 12px 10px;
        position: sticky;
        top: 0;
        z-index: 5;
        background: var(--bg-primary);
        backdrop-filter: blur(6px);
        -webkit-backdrop-filter: blur(6px);
    }
    .models-tab {
        padding: 7px 12px;
        font-size: 12.5px;
        border-radius: 999px;
    }
    .models-tab.active {
        background: rgba(16, 185, 129, 0.12);
    }
    .models-tab.active::after { display: none; }
    .models-sections { padding: 14px 12px 22px; gap: 22px; }
    .models-section-head { margin-bottom: 10px; }
    .models-section-title { font-size: 16px; }
    .models-section-sub { font-size: 11.5px; }
    .models-grid-v2 {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    .model-card-v2 {
        padding: 14px;
        min-height: auto;
        gap: 10px;
        border-radius: 12px;
    }
    .mcv-head { gap: 8px; }
    .mcv-avatar { width: 36px; height: 36px; border-radius: 9px; }
    .mcv-avatar-fallback { font-size: 12px; }
    .mcv-title { font-size: 14.5px; }
    .mcv-provider { font-size: 11.5px; }
    .mcv-desc {
        font-size: 12.5px;
        -webkit-line-clamp: 2;
    }
    .mcv-badge { font-size: 10px; padding: 2px 7px; }
    .mcv-cta { padding: 9px 12px; font-size: 13px; border-radius: 9px; }
}

.badge {
    padding: 3px 8px; border-radius: 4px;
    font-size: 11px; font-weight: 500;
}
.badge-premium { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.badge-active  { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.badge-inactive { background: rgba(239, 68, 68, 0.15); color: #ef4444; }
.badge-cost { background: rgba(155, 109, 255, 0.15); color: var(--accent-light); }

/* ─────────────────────────── ADMIN PAGES ──────────────────────────────── */
.admin-layout { display: flex; height: 100vh; }
.admin-sidebar {
    width: 240px; background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    padding: 18px 12px; flex-shrink: 0; overflow-y: auto;
}
.admin-sidebar h2 {
    font-size: 17px; margin-bottom: 18px;
    color: var(--accent-light); padding: 0 8px;
}
.admin-nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; border-radius: var(--radius);
    color: var(--text-primary); text-decoration: none;
    margin-bottom: 3px; font-size: 13.5px;
    transition: background 0.15s;
}
.admin-nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.admin-nav-item.active { background: var(--accent); color: white; }

.admin-main {
    flex: 1; overflow-y: auto; padding: 24px 30px;
}
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 24px; padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}
.page-header h1 { font-size: 22px; font-weight: 600; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px; margin-bottom: 30px;
}
.stat-card {
    background: var(--bg-secondary); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 20px;
}
.stat-card .label { font-size: 13px; color: #f7f7f9; margin-bottom: 8px; }
.stat-card .value {
    font-size: 28px; font-weight: 600; color: var(--accent-light);
}

.table-container {
    background: var(--bg-secondary); border: 1px solid var(--border);
    border-radius: var(--radius-lg); overflow: hidden;
}
.table-toolbar {
    padding: 14px; border-bottom: 1px solid var(--border);
    display: flex; gap: 12px; align-items: center;
}
table.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
    padding: 12px 14px; text-align: right;
    border-bottom: 1px solid var(--border);
}
.data-table th {
    font-weight: 500; color: var(--text-secondary);
    font-size: 13px; background: var(--bg-tertiary);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover { background: var(--bg-tertiary); }
.table-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.admin-form {
    background: var(--bg-secondary); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 24px; max-width: 900px;
}

/* Admin form sections / fieldsets */
.form-section {
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}
.form-section:last-child { border-bottom: none; padding-bottom: 0; }
.form-section-title {
    font-size: 16px; font-weight: 600;
    margin-bottom: 14px; color: var(--accent-light);
    display: flex; align-items: center; gap: 8px;
}
.form-section-help {
    font-size: 12.5px; color: #f7f7f9;
    margin-bottom: 14px; line-height: 1.7;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}
.form-grid .full-width { grid-column: 1 / -1; }

.form-actions {
    display: flex; gap: 10px;
    padding-top: 16px; border-top: 1px solid var(--border);
    margin-top: 20px;
}
textarea.form-control { min-height: 80px; resize: vertical; font-family: inherit; }

/* Tool config card in admin form */
.tool-config-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    transition: border 0.2s, background 0.2s;
}
.tool-config-card.enabled {
    border-color: var(--accent);
    background: rgba(155, 109, 255, 0.05);
}
.tool-config-header {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 10px;
}
.tool-config-emoji { font-size: 22px; }
.tool-config-title {
    font-weight: 600; font-size: 14.5px;
    flex: 1;
}
.tool-toggle {
    position: relative;
    width: 38px; height: 22px;
    flex-shrink: 0;
}
.tool-toggle input {
    opacity: 0; width: 0; height: 0;
}
.tool-toggle-slider {
    position: absolute; cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--border-light);
    border-radius: 22px;
    transition: 0.2s;
}
.tool-toggle-slider:before {
    position: absolute; content: "";
    height: 16px; width: 16px;
    right: 3px; top: 3px;     /* RTL */
    background: white;
    border-radius: 50%;
    transition: 0.2s;
}
.tool-toggle input:checked + .tool-toggle-slider {
    background: var(--accent);
}
.tool-toggle input:checked + .tool-toggle-slider:before {
    transform: translateX(-16px);  /* RTL */
}
.tool-config-body {
    display: none;
    padding-top: 10px;
    border-top: 1px dashed var(--border);
}
.tool-config-card.enabled .tool-config-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.tool-config-body .full-width { grid-column: 1 / -1; }
.tool-config-body label {
    font-size: 12px;
    color: var(--text-secondary);
    display: block; margin-bottom: 4px;
}
.tool-config-body .form-control {
    padding: 7px 10px;
    font-size: 13px;
}

/* Pagination */
.pagination {
    display: flex; gap: 4px; justify-content: center; padding: 20px;
}
.pagination a, .pagination span {
    padding: 8px 12px; border-radius: var(--radius-sm);
    background: var(--bg-tertiary); color: var(--text-primary);
    text-decoration: none; font-size: 13px;
}
.pagination a:hover { background: var(--bg-hover); }
.pagination .current { background: var(--accent); color: white; }

/* Error page */
.error-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; text-align: center; padding: 20px;
}
.error-page .code {
    font-size: 80px; font-weight: 700;
    color: var(--accent); margin-bottom: 10px;
}
.error-page .message {
    font-size: 18px; color: var(--text-secondary); margin-bottom: 25px;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed; right: 0; top: 0; bottom: 0;
        z-index: 100; box-shadow: -2px 0 10px rgba(0, 0, 0, 0.5);
    }
    .form-grid { grid-template-columns: 1fr; }
    .tool-config-card.enabled .tool-config-body { grid-template-columns: 1fr; }
    .admin-sidebar { width: 200px; }
    .admin-main { padding: 16px; }
    .msg-user { max-width: 90%; }
}

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border-light); border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: #f7f7f9; }

/* ═══════════════════ ADDITIONS — Professional Upgrades ═══════════════════ */

/* ─── Flash auto-dismiss ─── */
.flash { animation: slideDown 0.3s ease, fadeOut 0.4s ease 4s forwards; }
@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; pointer-events: none; }
}

/* ─── Sidebar Search ─── */
.sidebar-search {
    padding: 8px 8px 4px;
}
.sidebar-search-input {
    width: 100%; padding: 8px 12px;
    background: var(--bg-input); border: 1px solid var(--border);
    border-radius: var(--radius-pill); color: var(--text-primary);
    font-family: inherit; font-size: 12.5px;
    transition: border 0.2s; outline: none;
}
.sidebar-search-input:focus { border-color: var(--accent); }
.sidebar-search-input::placeholder { color: #f7f7f9; }

/* ─── Scroll-to-bottom button ─── */
.scroll-bottom-btn {
    position: absolute; bottom: 180px; left: 50%;
    transform: translateX(-50%);
    width: 36px; height: 36px;
    background: var(--bg-tertiary); border: 1px solid var(--border);
    border-radius: 50%; color: var(--text-secondary);
    cursor: pointer; display: flex; align-items: center;
    justify-content: center; z-index: 10;
    transition: all 0.2s; box-shadow: var(--shadow);
}
.scroll-bottom-btn:hover {
    background: var(--bg-hover); color: var(--text-primary);
    transform: translateX(-50%) scale(1.1);
}

/* ─── Code blocks (professional) ─── */
/* ═════════════════════════ MODERN CODE BLOCKS (highlight.js) ═════════════════════════ */
.code-block-wrap {
    margin: 14px 0;
    border-radius: 12px;
    overflow: hidden;
    background: #1e1e2e;
    border: 1px solid rgba(255,255,255,0.08);
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    direction: ltr;
    text-align: left;
    unicode-bidi: isolate;
}

.code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: linear-gradient(180deg, #2a2a3e, #232337);
    border-bottom: 1px solid rgba(255,255,255,0.06);
    min-height: 38px;
    direction: ltr;
}

.code-lang {
    font-size: 12px;
    color: #a8a8c0;
    font-family: 'Fira Code', 'JetBrains Mono', monospace;
    text-transform: lowercase;
    font-weight: 500;
    letter-spacing: 0.3px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.code-lang::before {
    content: '';
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #ff5f56;
    box-shadow: 14px 0 0 #ffbd2e, 28px 0 0 #27c93f;
    margin-left: 28px;
}

.code-line-count {
    color: #6c6c80 !important;
    font-weight: 400 !important;
    font-size: 11px;
}

.code-copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.08);
    color: #a8a8c0;
    font-family: inherit;
    font-size: 11.5px;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 6px;
    transition: all 0.15s;
}
.code-copy-btn:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
    border-color: rgba(255,255,255,0.15);
}
.code-copy-btn.copied {
    color: #27c93f;
    border-color: rgba(39,201,63,0.3);
    background: rgba(39,201,63,0.1);
}

.code-block-wrap pre {
    margin: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    background: transparent !important;
    padding: 16px 18px !important;
    overflow-x: auto;
    direction: ltr;
    text-align: left;
    unicode-bidi: isolate;
}
.code-block-wrap pre code {
    background: none !important;
    padding: 0 !important;
    font-family: 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
    font-size: 13.5px;
    line-height: 1.65;
    color: #cdd6f4;
    direction: ltr;
    text-align: left;
    unicode-bidi: isolate;
}

/* ── Highlight.js color overrides — Catppuccin-inspired ── */
.code-block-wrap .hljs {
    background: transparent !important;
    color: #cdd6f4 !important;
    padding: 0 !important;
}
.code-block-wrap .hljs-comment,
.code-block-wrap .hljs-quote {
    color: #7f849c !important;
    font-style: italic;
}
.code-block-wrap .hljs-keyword,
.code-block-wrap .hljs-selector-tag,
.code-block-wrap .hljs-built_in,
.code-block-wrap .hljs-name,
.code-block-wrap .hljs-tag {
    color: #cba6f7 !important;
    font-weight: 500;
}
.code-block-wrap .hljs-string,
.code-block-wrap .hljs-title,
.code-block-wrap .hljs-section,
.code-block-wrap .hljs-attribute,
.code-block-wrap .hljs-literal,
.code-block-wrap .hljs-template-tag,
.code-block-wrap .hljs-template-variable,
.code-block-wrap .hljs-type {
    color: #a6e3a1 !important;
}
.code-block-wrap .hljs-number,
.code-block-wrap .hljs-link,
.code-block-wrap .hljs-symbol {
    color: #fab387 !important;
}
.code-block-wrap .hljs-variable,
.code-block-wrap .hljs-template-variable,
.code-block-wrap .hljs-class .hljs-title,
.code-block-wrap .hljs-attr,
.code-block-wrap .hljs-property {
    color: #f9e2af !important;
}
.code-block-wrap .hljs-function .hljs-title,
.code-block-wrap .hljs-function-name,
.code-block-wrap .hljs-title.function_ {
    color: #89b4fa !important;
    font-weight: 500;
}
.code-block-wrap .hljs-params {
    color: #f5c2e7 !important;
}
.code-block-wrap .hljs-bullet,
.code-block-wrap .hljs-link,
.code-block-wrap .hljs-meta,
.code-block-wrap .hljs-selector-id,
.code-block-wrap .hljs-selector-class {
    color: #fab387 !important;
}
.code-block-wrap .hljs-addition {
    color: #a6e3a1 !important;
    background-color: rgba(166,227,161,0.1);
}
.code-block-wrap .hljs-deletion {
    color: #f38ba8 !important;
    background-color: rgba(243,139,168,0.1);
}
.code-block-wrap .hljs-emphasis { font-style: italic; }
.code-block-wrap .hljs-strong { font-weight: bold; }
.code-block-wrap .hljs-regexp,
.code-block-wrap .hljs-operator {
    color: #f38ba8 !important;
}

/* Custom scrollbar for code block */
.code-block-wrap pre::-webkit-scrollbar {
    height: 8px;
}
.code-block-wrap pre::-webkit-scrollbar-track {
    background: rgba(255,255,255,0.03);
}
.code-block-wrap pre::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 4px;
}
.code-block-wrap pre::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.25);
}

/* Inline code */
.inline-code {
    background: rgba(155, 109, 255, 0.12) !important;
    padding: 2px 7px !important; border-radius: 5px !important;
    font-family: 'Fira Code', monospace !important; font-size: 0.88em !important;
    color: var(--accent-light) !important;
    direction: ltr; unicode-bidi: isolate; text-align: left;
}

/* ─── Markdown tables ─── */
.table-responsive { overflow-x: auto; margin: 12px 0; }
.md-table {
    width: 100%; border-collapse: collapse;
    font-size: 13.5px;
}
.md-table th, .md-table td {
    padding: 8px 14px; border: 1px solid var(--border);
    text-align: right;
}
.md-table th {
    background: var(--bg-tertiary); font-weight: 600;
    color: var(--accent-light); font-size: 13px;
}
.md-table tr:hover { background: rgba(155, 109, 255, 0.05); }

/* ─── Markdown headings inside messages ─── */
.msg-content h1, .msg-content h2, .msg-content h3, .msg-content h4 {
    margin: 16px 0 8px; font-weight: 600;
    color: var(--text-primary); line-height: 1.4;
}
.msg-content h1 { font-size: 1.4em; }
.msg-content h2 { font-size: 1.25em; }
.msg-content h3 { font-size: 1.1em; }
.msg-content h4 { font-size: 1em; color: var(--text-secondary); }

.msg-content ul, .msg-content ol {
    padding-right: 24px; margin: 8px 0;
}
.msg-content li { margin: 4px 0; }

.msg-content blockquote {
    border-right: 3px solid var(--accent);
    padding: 6px 14px; margin: 10px 0;
    color: var(--text-secondary);
    background: rgba(155, 109, 255, 0.05);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.msg-content hr {
    border: none; border-top: 1px solid var(--border);
    margin: 16px 0;
}

.msg-content a {
    color: var(--accent-light);
    text-decoration: underline;
    text-decoration-color: rgba(155, 109, 255, 0.3);
}
.msg-content a:hover { text-decoration-color: var(--accent); }

/* ─── Streaming cursor ─── */
.msg-content.streaming::after {
    content: '▌';
    animation: blink 0.7s infinite;
    color: var(--accent-light);
    font-weight: 300;
}
@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* ─── Image preview overlay ─── */
.image-preview-overlay {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 9999; display: flex;
    align-items: center; justify-content: center;
    cursor: zoom-out; animation: fadeIn 0.2s ease;
    backdrop-filter: blur(4px);
}
.image-preview-img {
    max-width: 90vw; max-height: 90vh;
    border-radius: 12px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ─── Mobile Sidebar Backdrop (فقط موبایل، فقط با body.sidebar-open) ─── */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

/* فقط در موبایل، فقط وقتی body.sidebar-open داره، نمایش بده */
@media (max-width: 768px) {
    body.sidebar-open .sidebar-backdrop {
        display: block;
        opacity: 1;
        pointer-events: auto;
    }
}

/* در دسکتاپ، در هر حالتی پنهان بمونه */
@media (min-width: 769px) {
    .sidebar-backdrop {
        display: none !important;
        opacity: 0 !important;
        pointer-events: none !important;
    }
}

@media (max-width: 768px) {
    /* پیش‌فرض در موبایل: sidebar بسته (hidden) */
    .sidebar {
        position: fixed; right: 0; top: 0; bottom: 0;
        z-index: 100; box-shadow: -2px 0 10px rgba(0, 0, 0, 0.5);
        transform: translateX(100%);  /* پنهان — خارج از صفحه */
        transition: transform 0.3s ease;
    }
    /* وقتی باز است */
    .sidebar.open,
    body.sidebar-open .sidebar {
        transform: translateX(0);
    }
    .sidebar.collapsed {
        transform: translateX(100%);
        margin-right: 0;
    }
    .scroll-bottom-btn { bottom: 140px; }
}

/* ─── Export button in header ─── */
.btn-export {
    background: transparent; border: none;
    color: var(--text-secondary);
    width: 36px; height: 36px;
    border-radius: var(--radius); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.15s;
}
.btn-export:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ─── Profile page improvements ─── */
.profile-page {
    max-width: 600px; margin: 40px auto; padding: 0 20px;
}
.profile-card {
    background: var(--bg-secondary); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 30px;
}
.profile-header {
    display: flex; align-items: center; gap: 20px;
    margin-bottom: 24px; padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}
.profile-avatar {
    width: 64px; height: 64px; border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    color: white; display: flex; align-items: center;
    justify-content: center; font-size: 26px; font-weight: 700;
    flex-shrink: 0;
}
.profile-name { font-size: 20px; font-weight: 600; }
.profile-email { font-size: 13px; color: #f7f7f9; margin-top: 4px; }

.profile-stats {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px; margin-bottom: 24px;
}
.profile-stat {
    background: var(--bg-tertiary); border-radius: var(--radius);
    padding: 16px; text-align: center;
}
.profile-stat-value {
    font-size: 24px; font-weight: 700;
    color: var(--accent-light); margin-bottom: 4px;
}
.profile-stat-label { font-size: 12px; color: #f7f7f9; }

.profile-quota {
    background: var(--bg-tertiary); border-radius: var(--radius);
    padding: 16px; margin-bottom: 16px;
}
.quota-bar-bg {
    height: 8px; background: var(--border); border-radius: 4px;
    margin-top: 10px; overflow: hidden;
}
.quota-bar-fill {
    height: 100%; border-radius: 4px;
    background: linear-gradient(90deg, var(--accent), var(--accent-light));
    transition: width 0.5s ease;
}

/* ─── Stop generation button ─── */
.btn-stop {
    display: none; align-items: center; gap: 6px;
    padding: 8px 16px; background: var(--danger);
    color: white; border: none; border-radius: var(--radius-pill);
    font-family: inherit; font-size: 13px; cursor: pointer;
    position: absolute; bottom: 100px; left: 50%;
    transform: translateX(-50%); z-index: 10;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
    transition: all 0.2s;
}
.btn-stop:hover { background: #c83232; }
.btn-stop.visible { display: flex; }

/* ═══════════════════ THINKING / REASONING PANEL ═══════════════════════ */

/* نوار وضعیت — در حال اتصال / استنتاج / دریافت پاسخ */
.thinking-status-wrap {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 0 10px;
    color: var(--text-secondary); font-size: 13.5px;
}

.thinking-spinner {
    width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0;
    border: 2px solid var(--border-light);
    border-top-color: var(--accent);
    animation: spin 0.8s linear infinite;
    display: inline-block;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

.thinking-orb {
    position: relative;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    flex: 0 0 34px;
    background:
        radial-gradient(circle at 50% 50%, rgba(255,255,255,0.95) 0 3px, transparent 4px),
        conic-gradient(from 0deg, rgba(139,92,246,0.15), rgba(20,184,166,0.9), rgba(244,114,182,0.8), rgba(139,92,246,0.15));
    box-shadow: 0 0 24px rgba(139,92,246,0.25);
    animation: spin 1.15s linear infinite;
}

.thinking-orb::after {
    content: "";
    position: absolute;
    inset: 5px;
    border-radius: inherit;
    background: var(--surface);
}

.thinking-orb span {
    position: absolute;
    inset: 11px;
    border-radius: inherit;
    background: linear-gradient(135deg, #8b5cf6, #14b8a6);
    z-index: 1;
    animation: waitPulse 1.4s ease-in-out infinite;
}

.thinking-status-stack {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 3px;
}

.thinking-substatus {
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.6;
}

@keyframes waitPulse {
    0%, 100% { transform: scale(0.82); opacity: 0.6; }
    50% { transform: scale(1.08); opacity: 1; }
}

/* پنل Thinking */
.thinking-panel {
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: rgba(155, 109, 255, 0.04);
}

.thinking-toggle {
    width: 100%; display: flex; align-items: center; gap: 8px;
    padding: 10px 14px;
    background: rgba(155, 109, 255, 0.07);
    border: none; cursor: pointer; color: var(--text-secondary);
    font-family: inherit; font-size: 13px; text-align: right;
    transition: background 0.15s;
}
.thinking-toggle:hover { background: rgba(155, 109, 255, 0.12); color: var(--text-primary); }
.thinking-toggle svg:first-child { color: var(--accent); flex-shrink: 0; }
.thinking-toggle-label { flex: 1; text-align: right; }
.thinking-chevron {
    transition: transform 0.25s ease; flex-shrink: 0;
}

/* جمع شده */
.thinking-panel:not(.active) .thinking-chevron {
    transform: rotate(180deg);
}

/* بدنه پنل */
.thinking-body {
    display: none; /* پیشفرض بسته */
    padding: 12px 14px;
    font-size: 13px; line-height: 1.8;
    color: var(--text-secondary);
    max-height: 320px; overflow-y: auto;
    white-space: pre-wrap; word-wrap: break-word;
    border-top: 1px solid var(--border);
    font-family: 'Vazirmatn', system-ui, sans-serif;
}

/* باز شده */
.thinking-panel.active .thinking-body {
    display: block;
}

/* هنگام streaming، نمای اتو-scroll */
.thinking-body::-webkit-scrollbar { width: 4px; }
.thinking-body::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }

/* وقتی thinking در حال دریافت است — نمایش pulse */
.thinking-panel.active .thinking-body::after {
    content: '▋';
    animation: blink 0.7s infinite;
    color: var(--accent);
    font-weight: 300;
}

/* وقتی پاسخ نهایی آمد، cursor رو پاک کن */
.thinking-panel.done .thinking-body::after {
    display: none;
}

/* ══════════════════════════════════════════════════════════════════════
   THINKING / REASONING PANEL — نمایش مراحل استنتاج
   ══════════════════════════════════════════════════════════════════════ */

/* ── نوار وضعیت در حال پردازش ── */
.thinking-status-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 2px 10px;
    color: var(--text-secondary);
    font-size: 13.5px;
}

.thinking-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(155, 109, 255, 0.25);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── پنل thinking (collapsible) ── */
.thinking-panel {
    margin-bottom: 12px;
    border: 1px solid rgba(155, 109, 255, 0.25);
    border-radius: var(--radius);
    background: rgba(155, 109, 255, 0.04);
    overflow: hidden;
}

.thinking-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    text-align: right;
    transition: background 0.15s, color 0.15s;
}

.thinking-toggle:hover {
    background: rgba(155, 109, 255, 0.08);
    color: var(--accent-light);
}

.thinking-toggle svg:first-child {
    color: var(--accent);
    flex-shrink: 0;
}

.thinking-toggle-label {
    flex: 1;
    font-weight: 500;
}

/* نشانگر تعداد کاراکترهای thinking */
.thinking-char-count {
    font-size: 11px;
    color: #f7f7f9;
    background: var(--bg-input);
    padding: 2px 7px;
    border-radius: var(--radius-pill);
    margin-left: 4px;
}

.thinking-chevron {
    flex-shrink: 0;
    transition: transform 0.2s ease;
    color: #f7f7f9;
}

/* حالت باز: chevron چرخیده */
.thinking-panel.active .thinking-chevron {
    transform: rotate(0deg);
}
.thinking-panel:not(.active) .thinking-chevron {
    transform: rotate(180deg);
}

/* بدنه thinking: فقط در حالت active نمایش داده می‌شود */
.thinking-body {
    display: none;
    padding: 12px 16px 14px;
    border-top: 1px solid rgba(155, 109, 255, 0.15);
    font-size: 13px;
    line-height: 1.75;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 360px;
    overflow-y: auto;
    direction: ltr;    /* متن انگلیسی thinking معمولاً LTR است */
    text-align: left;
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 12.5px;
    background: rgba(0, 0, 0, 0.15);
}

.thinking-panel.active .thinking-body {
    display: block;
    animation: thinkFadeIn 0.2s ease;
}

@keyframes thinkFadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* وقتی thinking در حال جریان است — پالس رنگی */
.thinking-panel.live .thinking-toggle {
    color: var(--accent-light);
}

.thinking-panel.live .thinking-spinner-dot {
    display: inline-flex;
    gap: 3px;
    margin-right: 6px;
}

.thinking-panel.live .thinking-spinner-dot span {
    width: 4px; height: 4px;
    background: var(--accent);
    border-radius: 50%;
    animation: typingBlink 1.2s infinite ease-in-out;
}
.thinking-panel.live .thinking-spinner-dot span:nth-child(2) { animation-delay: 0.2s; }
.thinking-panel.live .thinking-spinner-dot span:nth-child(3) { animation-delay: 0.4s; }

/* اسکرول‌بار ظریف برای بدنه thinking */
.thinking-body::-webkit-scrollbar { width: 4px; }
.thinking-body::-webkit-scrollbar-thumb { background: rgba(155, 109, 255, 0.3); border-radius: 2px; }

/* ══════════════════════════════════════════════════════════════════════
   TOKEN USAGE BAR — نمایش آمار توکن زیر هر پیام دستیار
   ══════════════════════════════════════════════════════════════════════ */
.msg-usage-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    margin-top: 8px;
    padding: 6px 10px;
    font-size: 11px;
    color: #f7f7f9;
    direction: ltr;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 6px;
    border: 1px dashed rgba(255, 255, 255, 0.06);
}
.msg-usage-bar span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.msg-usage-bar svg {
    opacity: 0.7;
}
.msg-usage-trim {
    color: #f4b400 !important;
    background: rgba(244, 180, 0, 0.08);
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
}

/* ══════════════════════════════════════════════════════════════════════
   NOTIFICATIONS PANEL — اعلان‌های کاربر
   ══════════════════════════════════════════════════════════════════════ */
.notif-wrap { position: relative; }
.notif-badge {
    position: absolute;
    top: 2px; left: 2px;
    background: var(--danger);
    color: white;
    font-size: 9px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid var(--bg-primary);
    box-shadow: 0 0 0 1px var(--danger);
}
.notif-panel {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    width: 340px;
    max-height: 480px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    display: none;
    flex-direction: column;
    z-index: 1000;
    overflow: hidden;
}
.notif-panel.show { display: flex; }
.notif-panel-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-tertiary);
}
.notif-panel-header strong { font-size: 13px; }
.notif-mark-all {
    background: none; border: none; color: var(--accent-light);
    font-family: inherit; font-size: 11px; cursor: pointer;
    padding: 3px 8px; border-radius: 4px;
}
.notif-mark-all:hover { background: rgba(155, 109, 255, 0.1); }
.notif-panel-body {
    overflow-y: auto;
    flex: 1;
}
.notif-loading {
    padding: 30px; text-align: center;
    color: #f7f7f9; font-size: 12.5px;
}
.notif-empty {
    padding: 40px 20px; text-align: center;
    color: #f7f7f9; font-size: 12.5px;
}
.notif-item {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
    position: relative;
}
.notif-item:hover { background: var(--bg-hover); }
.notif-item.unread {
    background: rgba(155, 109, 255, 0.04);
    border-right: 3px solid var(--accent);
}
.notif-item.unread::before {
    content: '';
    position: absolute;
    top: 16px; left: 14px;
    width: 7px; height: 7px;
    background: var(--accent);
    border-radius: 50%;
}
.notif-title {
    font-size: 13px; font-weight: 500;
    margin-bottom: 4px;
    color: var(--text-primary);
}
.notif-body {
    font-size: 12px; color: var(--text-secondary);
    line-height: 1.5; margin-bottom: 4px;
}
.notif-time {
    font-size: 10.5px; color: #f7f7f9;
    direction: ltr;
}
.notif-item.type-success .notif-title { color: #10b981; }
.notif-item.type-warning .notif-title { color: #f4b400; }
.notif-item.type-danger  .notif-title { color: var(--danger); }
.notif-item.type-info    .notif-title { color: var(--accent-light); }

/* ── Quota status indicator ── */
.quota-info-bar {
    font-size: 11px; color: #f7f7f9;
    display: flex; align-items: center; gap: 8px;
}
.quota-info-bar.warning { color: #f4b400; }
.quota-info-bar.danger  { color: var(--danger); }


.user-meta .quota.quota-warn   { color: #f4b400; font-weight: 500; }
.user-meta .quota.quota-danger { color: var(--danger); font-weight: 600; }

/* ══════════════════════════════════════════════════════════════════════════
   MOBILE OPTIMIZATION — بهینه‌سازی موبایل
   ══════════════════════════════════════════════════════════════════════════ */

/* Tablet breakpoint */
@media (max-width: 1024px) {
    .sidebar { width: 240px; }
}

/* ─── Mobile (≤ 768px) ─── */
@media (max-width: 768px) {
    /* ── Body & Layout ── */
    html, body {
        font-size: 14.5px;
        -webkit-text-size-adjust: 100%;
        overflow-x: hidden;
    }
    body { overscroll-behavior: none; }
    
    .layout {
        position: relative;
        height: 100vh;
        height: 100dvh; /* دینامیک — قبل از iOS keyboard */
        overflow: hidden;
    }
    
    /* ── Sidebar: drawer style ── */
    .sidebar {
        position: fixed !important;
        right: 0; top: 0; bottom: 0;
        width: 85vw !important;
        max-width: 320px !important;
        z-index: 1000 !important;
        transform: translateX(0);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1) !important;
        box-shadow: -4px 0 30px rgba(0, 0, 0, 0.5);
        margin: 0 !important;
        border-radius: 0 !important;
    }
    .sidebar.collapsed {
        transform: translateX(105%) !important;
    }
    /* sidebar-backdrop در رول اصلی بالا تعریف شده — تکرار نمی‌کنیم */
    
    /* ── Main area takes full width ── */
    .main {
        width: 100%;
        height: 100vh;
        height: 100dvh;
        display: flex;
        flex-direction: column;
    }
    
    /* ── Header ── */
    .main-header {
        padding: 8px 10px !important;
        gap: 4px !important;
        min-height: 52px;
        flex-shrink: 0;
        position: sticky;
        top: 0; z-index: 50;
        background: var(--bg-primary);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }
    .main-header .btn-icon {
        width: 38px !important; height: 38px !important;
        padding: 0;
    }
    .main-header .btn-icon svg { width: 20px; height: 20px; }
    
    /* Header model picker on mobile: compact */
    .header-left {
        gap: 4px !important;
        flex: 1;
        min-width: 0; /* اجازه shrink */
    }
    .header-right { gap: 2px !important; }
    
    .model-picker-btn {
        max-width: 180px;
        padding: 6px 10px !important;
        font-size: 13px !important;
        gap: 6px !important;
    }
    .model-picker-btn span#currentModelName {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 110px;
    }
    
    /* Hide some less-used buttons on mobile to save space */
    .main-header .btn-icon[title="اشتراک‌گذاری"] { display: none; }
    
    /* Model dropdown: bottom-sheet style on mobile */
    .model-dropdown {
        position: fixed !important;
        right: 8px !important;
        left: 8px !important;
        top: 60px !important;
        max-height: calc(100vh - 80px) !important;
        max-height: calc(100dvh - 80px) !important;
        width: auto !important;
        min-width: 0 !important;
        max-width: none !important;
        border-radius: 16px !important;
        overflow-y: auto;
        z-index: 200;
    }
    
    /* Notif panel: full-width sheet on mobile */
    .notif-panel {
        position: fixed !important;
        right: 8px !important;
        left: 8px !important;
        top: 60px !important;
        width: auto !important;
        max-height: calc(100vh - 80px) !important;
        max-height: calc(100dvh - 80px) !important;
        z-index: 200;
        border-radius: 16px !important;
    }
    
    /* ── Chat area ── */
    .chat-area {
        flex: 1;
        padding: 8px 4px !important;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .message-list {
        padding: 4px 8px !important;
        gap: 14px !important;
    }
    
    /* Messages: wider on mobile */
    .msg-user {
        max-width: 88% !important;
    }
    .msg-user .msg-bubble {
        padding: 9px 13px !important;
        font-size: 14.5px;
    }
    .msg-assistant {
        padding: 0 4px !important;
    }
    .msg-content {
        font-size: 14.5px;
        line-height: 1.7;
    }
    .msg-content h1 { font-size: 1.25em; }
    .msg-content h2 { font-size: 1.15em; }
    .msg-content h3 { font-size: 1.05em; }
    
    /* Action buttons under each message: bigger touch area */
    .msg-actions {
        gap: 4px !important;
        margin-top: 8px;
    }
    .msg-action-btn {
        width: 34px !important; height: 34px !important;
    }
    
    /* Code blocks: scroll horizontally */
    .code-block-wrap pre { padding: 12px !important; }
    .code-block-wrap code { font-size: 12px !important; }
    .code-block-wrap pre {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Markdown tables: scroll horizontally */
    .table-responsive {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .md-table { font-size: 12.5px; }
    .md-table th, .md-table td { padding: 6px 10px !important; }
    
    /* Generated images: full width on mobile */
    .msg-generated-image img {
        max-width: 100% !important;
        max-height: 60vh !important;
    }
    .msg-attachment-img {
        max-width: 200px !important;
        max-height: 200px !important;
    }
    
    /* ── Composer (bottom input area) ── */
    .composer-wrap {
        padding: 8px 8px 10px !important;
        position: sticky;
        bottom: 0;
        background: var(--bg-primary);
        z-index: 40;
    }
    .composer-card {
        padding: 8px 8px 8px !important;
        border-radius: 18px !important;
    }
    .composer-textarea {
        font-size: 16px !important; /* prevents iOS zoom on focus */
        min-height: 22px !important;
        max-height: 140px !important;
        padding: 8px 6px !important;
    }
    .composer-actions {
        gap: 4px !important;
    }
    .composer-actions .btn-icon-action,
    .composer-actions .btn-send-action,
    .composer-actions button {
        width: 36px !important;
        height: 36px !important;
    }
    
    /* Tool menu (+ button popup): bottom sheet on mobile */
    .tool-menu, .tool-submenu {
        position: fixed !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        top: auto !important;
        width: auto !important;
        max-width: none !important;
        border-radius: 18px 18px 0 0 !important;
        max-height: 70vh;
        overflow-y: auto;
        padding: 12px 10px 30px !important;
        animation: slideUpSheet 0.25s cubic-bezier(0.32, 0.72, 0, 1);
        z-index: 500;
    }
    .tool-menu.show, .tool-submenu.show {
        display: flex !important;
        flex-direction: column;
    }
    @keyframes slideUpSheet {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
    .tool-item {
        padding: 14px 16px !important;
        font-size: 14.5px;
        gap: 12px;
    }
    .tool-item-icon { width: 22px; }
    .tool-item-icon svg { width: 22px !important; height: 22px !important; }
    
    /* Backdrop for tool menu */
    .tool-menu.show::before, .tool-submenu.show::before {
        content: '';
        position: fixed; inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: -1;
        animation: fadeIn 0.2s;
    }
    
    /* Selected tools badges */
    .selected-tools {
        margin: 6px 4px 0 !important;
        gap: 6px !important;
    }
    .tool-badge {
        font-size: 11.5px !important;
        padding: 4px 10px !important;
    }
    
    /* Attachment previews */
    .attachment-card {
        width: 70px !important; height: 70px !important;
    }
    
    /* User meta in sidebar */
    .user-meta {
        font-size: 11.5px;
    }
    
    /* Disclaimer below composer: hide on small screens to save space */
    .composer-disclaimer {
        font-size: 10.5px !important;
        padding: 4px 10px !important;
    }
    
    /* Scroll-to-bottom button */
    .scroll-bottom-btn {
        bottom: 110px !important;
        width: 38px !important; height: 38px !important;
    }
    
    /* ── Sidebar internals on mobile ── */
    .sidebar-search { padding: 10px !important; }
    .sidebar-search-input { font-size: 14px !important; padding: 9px 12px !important; }
    .nav-item, .chat-item {
        padding: 10px 12px !important;
        font-size: 13.5px;
    }
    .chat-item-title { font-size: 13.5px; }
    .btn-new-chat {
        padding: 10px 14px !important;
        font-size: 13.5px;
    }
    
    /* ── Auth pages (login/register) ── */
    .auth-card {
        max-width: 92vw !important;
        padding: 28px 22px !important;
        margin: 16px auto !important;
        border-radius: 14px !important;
    }
    .auth-card h1 { font-size: 22px; }
    .auth-tabs { font-size: 13.5px; }
    
    /* ── Profile page ── */
    .profile-page { margin: 16px auto !important; padding: 0 12px !important; }
    .profile-card { padding: 20px 16px !important; }
    .profile-stats { gap: 8px !important; }
    .profile-stat { padding: 12px 8px !important; }
    .profile-stat-value { font-size: 20px !important; }
    
    /* ── Models grid page ── */
    .models-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
    .model-card { padding: 14px !important; }
    
    /* ── Admin layout: stack vertically ── */
    .admin-layout {
        flex-direction: column;
        height: 100vh;          /* به جای auto — تا اسکرول درست کار کنه */
        height: 100dvh;
        overflow: hidden;
    }
    .admin-sidebar {
        position: fixed !important;
        right: 0; top: 0; bottom: 0;
        width: 75vw !important;
        max-width: 280px !important;
        z-index: 1000;
        transform: translateX(105%);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .admin-sidebar.show { transform: translateX(0); }
    .admin-main {
        margin-right: 0 !important;
        padding: 12px !important;
        width: 100%;
        flex: 1;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        /* فضای کافی برای bottom nav (60px) + safe-area */
        padding-bottom: calc(80px + env(safe-area-inset-bottom)) !important;
    }
    .admin-mobile-header {
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        padding: 10px 14px;
        padding-top: max(10px, env(safe-area-inset-top));
        background: var(--bg-secondary);
        border-bottom: 1px solid var(--border);
        flex-shrink: 0;             /* تو flex parent، header نباید shrink بشه */
        z-index: 100;
    }
    
    /* Stats grid on mobile */
    .stats-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 10px !important;
    }
    .stat-card { padding: 12px 14px !important; }
    .stat-card .value { font-size: 22px !important; }
    .stat-card .label { font-size: 11px !important; }
    
    /* Tables: horizontal scroll */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .data-table {
        min-width: 600px; /* always scrollable */
        font-size: 12.5px;
    }
    .data-table th, .data-table td { padding: 8px 6px !important; }
    
    /* Form on mobile */
    .form-grid { grid-template-columns: 1fr !important; gap: 12px !important; }
    .form-section { padding: 14px !important; }
    .form-group label { font-size: 12.5px !important; }
    .form-control {
        font-size: 16px !important; /* iOS no-zoom */
        padding: 10px 12px !important;
    }
    
    /* Toolbar with action buttons: stack on mobile */
    .table-toolbar {
        flex-direction: column;
        align-items: stretch !important;
        gap: 8px !important;
    }
    .table-toolbar form {
        flex-direction: column !important;
        gap: 6px !important;
    }
    .table-toolbar form .form-control { max-width: none !important; }
    
    /* Buttons: bigger touch targets */
    .btn {
        min-height: 38px;
        padding: 8px 14px;
        font-size: 13.5px;
    }
    .btn-sm { min-height: 32px; padding: 6px 10px; font-size: 12.5px; }
    
    /* Image preview overlay close on tap */
    .image-preview-overlay {
        align-items: flex-start;
        padding-top: env(safe-area-inset-top, 20px);
    }
    .image-preview-img {
        max-width: 95vw !important;
        max-height: 85vh !important;
    }
    
    /* Page header on admin */
    .page-header {
        padding: 12px 0 !important;
        margin-bottom: 12px !important;
    }
    .page-header h1 { font-size: 18px !important; }
    
    /* Token usage bar — smaller on mobile */
    .msg-usage-bar {
        font-size: 10.5px;
        gap: 8px !important;
        padding: 5px 8px !important;
    }
    
    /* Thinking panel — fit to mobile */
    .thinking-panel {
        font-size: 12px;
    }
    .thinking-toggle { padding: 8px 12px !important; }
    .thinking-body {
        padding: 10px 12px 12px !important;
        font-size: 12px;
        max-height: 280px;
    }
    
    /* Toast / Flash messages */
    .flash {
        margin: 8px 12px !important;
        font-size: 13px !important;
        padding: 10px 14px !important;
    }
    
    /* Disable hover effects (don't make sense on touch) */
    .nav-item:hover, .chat-item:hover, .btn-icon:hover {
        background: transparent;
    }
    /* Active state instead */
    .nav-item:active, .chat-item:active {
        background: var(--bg-hover) !important;
    }
}

/* ─── Very small phones (≤ 380px) ─── */
@media (max-width: 380px) {
    .model-picker-btn span#currentModelName { max-width: 80px; }
    .header-right .btn-icon { width: 36px !important; height: 36px !important; }
    .msg-user { max-width: 92% !important; }
    .composer-actions { gap: 2px !important; }
    .stats-grid { grid-template-columns: 1fr !important; }
}

/* ─── Landscape phones ─── */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
    .sidebar { width: 75vw !important; }
    .composer-disclaimer { display: none; }
}

/* ─── Touch-specific polish ─── */
@media (hover: none) and (pointer: coarse) {
    /* Bigger scroll thumb for touch users */
    ::-webkit-scrollbar { width: 4px; }
    /* Remove tap-highlight for cleaner touch feel */
    button, a, [role="button"] {
        -webkit-tap-highlight-color: rgba(155, 109, 255, 0.15);
    }
    /* Disable hover lift effects on touch */
    .model-card:hover, .stat-card:hover { transform: none; }
}

/* ─── iOS safe-area insets (notch handling) ─── */
@supports (padding: env(safe-area-inset-top)) {
    @media (max-width: 768px) {
        .main-header { padding-top: calc(8px + env(safe-area-inset-top)) !important; }
        .composer-wrap { padding-bottom: calc(10px + env(safe-area-inset-bottom)) !important; }
        .sidebar { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
    }
}

/* ── Admin Sidebar Backdrop (mobile only) ── */
.admin-sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 998;
    backdrop-filter: blur(2px);
}
.admin-sidebar-backdrop.show {
    display: block;
    animation: fadeIn 0.2s ease;
}
.admin-mobile-header {
    display: none;
}

/* ══════════════════════════════════════════════════════════════════════
   VOICE RECORDING BANNER + TTS BUTTON
   ══════════════════════════════════════════════════════════════════════ */
.recording-banner {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-secondary);
    border: 1px solid var(--danger);
    border-radius: var(--radius-pill);
    padding: 10px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 9999;
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.35);
    font-size: 13px;
}
.recording-banner .rec-pulse {
    width: 10px; height: 10px;
    background: var(--danger);
    border-radius: 50%;
    animation: recPulse 1s ease-in-out infinite;
}
@keyframes recPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.4); }
}
.recording-banner button {
    padding: 5px 12px;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: var(--radius-pill);
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
}
.recording-banner button:hover { opacity: 0.85; }

/* Voice button while recording */
.composer-actions button.recording,
#voiceBtn.recording {
    background: var(--danger) !important;
    color: white !important;
    animation: recPulse 1.5s ease-in-out infinite;
}

/* TTS button states */
.tts-btn .tts-icon-playing,
.tts-btn .tts-icon-loading { display: none; }
.tts-btn.playing .tts-icon-idle,
.tts-btn.playing .tts-icon-loading { display: none; }
.tts-btn.playing .tts-icon-playing { display: inline-block; color: var(--accent); }
.tts-btn.loading .tts-icon-idle,
.tts-btn.loading .tts-icon-playing { display: none; }
.tts-btn.loading .tts-icon-loading {
    display: inline-block;
    animation: spin 1s linear infinite;
}


/* ── Image Gen Options Panel ── */
.image-gen-options {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    margin-top: 6px;
    padding: 8px 12px;
    background: rgba(155, 109, 255, 0.05);
    border: 1px solid rgba(155, 109, 255, 0.2);
    border-radius: var(--radius);
    font-size: 12px;
    width: 100%;
    flex-basis: 100%;
}
.igo-label {
    color: #f7f7f9;
    font-size: 11.5px;
    margin-left: 2px;
}
.image-gen-options select {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 8px;
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
}
.image-gen-options select:hover { border-color: var(--accent); }
.image-gen-options select:focus { outline: none; border-color: var(--accent); }


/* ── Vision Warning Banner ── */
.vision-warning {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(244, 180, 0, 0.1);
    border: 1px solid rgba(244, 180, 0, 0.3);
    color: #f4b400;
    padding: 8px 14px;
    border-radius: var(--radius);
    font-size: 12.5px;
    margin: 8px auto;
    max-width: 720px;
    animation: slideDown 0.3s ease;
}
.vision-warning svg { flex-shrink: 0; }
.vision-warning span { flex: 1; color: var(--text-secondary); }
.vision-warning button {
    background: transparent; border: none; color: #f7f7f9;
    font-size: 18px; cursor: pointer; padding: 0 4px;
}
.vision-warning button:hover { color: var(--text-primary); }
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}


/* ── Image Actions Overlay (download/copy on hover) ── */
.msg-generated-image {
    position: relative;
    display: inline-block;
}
.msg-generated-image .image-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}
.msg-generated-image:hover .image-actions { opacity: 1; }
.msg-generated-image .image-actions button {
    width: 30px; height: 30px;
    background: rgba(0, 0, 0, 0.65);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(4px);
}
.msg-generated-image .image-actions button:hover {
    background: rgba(0, 0, 0, 0.85);
}

/* Preview overlay actions */
.image-preview-actions {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 8px;
}
.image-preview-actions button {
    width: 40px; height: 40px;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    cursor: pointer;
    backdrop-filter: blur(8px);
    display: flex; align-items: center; justify-content: center;
}
.image-preview-actions button:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ── Toast ── */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    padding: 10px 20px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border);
    font-size: 13px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
    z-index: 99999;
    opacity: 0;
    transition: opacity 0.25s, transform 0.25s;
    pointer-events: none;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}


/* ══════════════════════════════════════════════════════════════════════
   IMAGE STUDIO — صفحه تولید/ویرایش تصویر
   ══════════════════════════════════════════════════════════════════════ */

.image-studio-main {
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ── Mode Switcher (در sidebar) ── */
.mode-switcher {
    display: flex;
    gap: 4px;
    padding: 8px;
    margin: 4px 8px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
}
.mode-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.15s;
}
.mode-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.mode-btn.active {
    background: var(--accent);
    color: white;
}

/* ── Studio Container — 2 column layout ── */
.studio-container {
    flex: 1;
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 0;
    overflow: hidden;
}
@media (max-width: 900px) {
    .studio-container {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
    }
}

/* ── Settings Panel ── */
.studio-panel {
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}
.studio-panel-header {
    padding: 14px 18px;
    font-size: 13px;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ── Tabs (Generate / Edit / Variation) ── */
.studio-mode-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: var(--bg-tertiary);
}
.studio-tab {
    flex: 1;
    padding: 10px 8px;
    background: transparent;
    border: none;
    color: #f7f7f9;
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
}
.studio-tab:hover { color: var(--text-primary); background: rgba(155,109,255,0.05); }
.studio-tab.active {
    color: var(--accent-light);
    border-bottom-color: var(--accent);
    background: rgba(155,109,255,0.08);
}

.studio-tab-content {
    display: none;
    padding: 18px;
}
.studio-tab-content.active { display: block; }

/* ── Form fields ── */
.studio-field {
    margin-bottom: 14px;
}
.studio-field label {
    display: block;
    font-size: 11.5px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}
.studio-field textarea,
.studio-field select,
.studio-field input[type="text"] {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
    padding: 8px 10px;
    transition: border 0.15s;
    outline: none;
    resize: vertical;
}
.studio-field textarea:focus,
.studio-field select:focus,
.studio-field input:focus { border-color: var(--accent); }
.studio-field textarea { min-height: 60px; }

.studio-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.field-hint {
    font-size: 10.5px;
    color: #f7f7f9;
    margin-top: 4px;
}

/* ── Style Presets ── */
.style-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.style-preset {
    padding: 5px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 11.5px;
    cursor: pointer;
    transition: all 0.15s;
}
.style-preset:hover {
    border-color: var(--accent);
    color: var(--accent-light);
    background: rgba(155,109,255,0.08);
    transform: translateY(-1px);
}

/* ── Upload area ── */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 24px 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--bg-input);
}
.upload-area:hover {
    border-color: var(--accent);
    background: rgba(155, 109, 255, 0.04);
}
.upload-area svg {
    color: #f7f7f9;
    margin-bottom: 8px;
}
.upload-area > div { color: var(--text-secondary); font-size: 13px; }
.upload-area small { color: #f7f7f9; font-size: 11px; display: block; margin-top: 4px; }

/* ── Generate Button ── */
.studio-generate-btn {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    color: white;
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
    margin-top: 6px;
    box-shadow: 0 4px 14px rgba(155, 109, 255, 0.25);
}
.studio-generate-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(155, 109, 255, 0.4);
}
.studio-generate-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}
.studio-generate-btn .spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ── Results Panel ── */
.studio-results {
    background: var(--bg-primary);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}
.studio-results-grid {
    flex: 1;
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    align-content: start;
}
.studio-empty-state {
    grid-column: 1/-1;
    text-align: center;
    padding: 80px 20px;
    color: #f7f7f9;
}

/* ── Result Card ── */
.result-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
    animation: resultFadeIn 0.4s ease;
}
@keyframes resultFadeIn {
    from { opacity: 0; transform: translateY(10px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.result-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}
.result-image-wrap {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    background: var(--bg-input);
}
.result-image-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    cursor: zoom-in;
    transition: transform 0.3s;
}
.result-image-wrap:hover img { transform: scale(1.04); }

.result-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
    padding: 12px;
    display: flex;
    gap: 6px;
    justify-content: flex-end;
    opacity: 0;
    transition: opacity 0.2s;
}
.result-image-wrap:hover .result-overlay { opacity: 1; }
.result-overlay button {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.result-overlay button:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.1);
}

.result-meta {
    padding: 12px 14px;
}
.result-prompt {
    font-size: 12.5px;
    color: var(--text-secondary);
    line-height: 1.5;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    margin-bottom: 6px;
}
.result-revised {
    font-size: 11px;
    color: var(--accent-light);
    background: rgba(155, 109, 255, 0.05);
    padding: 4px 8px;
    border-radius: 4px;
    margin-bottom: 6px;
}
.result-info {
    font-size: 10.5px;
    color: #f7f7f9;
    direction: ltr;
}

/* ── Image History (sidebar) ── */
.sidebar-section-title {
    padding: 12px 14px 6px;
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #f7f7f9;
}
.image-history {
    padding: 0 8px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    max-height: 280px;
    overflow-y: auto;
}
.image-history-item {
    aspect-ratio: 1;
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: transform 0.15s, border-color 0.15s;
}
.image-history-item:hover {
    transform: scale(1.05);
    border-color: var(--accent);
}
.image-history-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ══════════════════════════════════════════════════════════════════════
   PWA & MOBILE OPTIMIZATIONS
   ══════════════════════════════════════════════════════════════════════ */

/* iOS Safe Area Support — برای iPhone X و بالاتر */
@supports (padding: max(0px)) {
    body {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
    .layout, .auth-container {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* PWA Standalone Mode — وقتی به‌عنوان اپ نصب شده اجرا می‌شه */
body.pwa-standalone {
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}
body.pwa-standalone input,
body.pwa-standalone textarea,
body.pwa-standalone .msg-content,
body.pwa-standalone [contenteditable] {
    user-select: text;
    -webkit-user-select: text;
}

/* در حالت standalone، header اپ رو مثل یک اپ موبایل کن */
body.pwa-standalone .main-header {
    padding-top: max(12px, env(safe-area-inset-top));
}

/* PWA Install Banner */
#pwaInstallBanner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    color: white;
    padding: max(12px, env(safe-area-inset-bottom)) 16px 12px 16px;
    z-index: 10000;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.4s ease-out;
}
@keyframes slideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}
.pwa-install-content {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 600px;
    margin: 0 auto;
}
.pwa-install-icon {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.18);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}
.pwa-install-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}
.pwa-install-text strong {
    font-size: 14px;
    font-weight: 600;
}
.pwa-install-text span {
    font-size: 11.5px;
    opacity: 0.9;
}
.pwa-install-btn {
    background: white;
    color: var(--accent);
    border: none;
    border-radius: var(--radius-pill);
    padding: 8px 18px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
}
.pwa-install-btn:active {
    transform: scale(0.95);
}
.pwa-install-close {
    background: transparent;
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    opacity: 0.7;
}
.pwa-install-close:hover { opacity: 1; }

/* ══════════════════════════════════════════════════════════════════════
   MOBILE UI — حالت اپ موبایل
   ══════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    /* جلوگیری از zoom کردن iOS هنگام focus روی input */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="search"],
    textarea,
    select {
        font-size: 16px !important;
    }
    
    /* Sidebar مثل bottom-sheet در موبایل */
    .sidebar {
        position: fixed;
        top: 0;
        right: 0;
        height: 100vh;
        height: 100dvh;
        width: 85%;
        max-width: 320px;
        z-index: 1000;
        transform: translateX(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: -4px 0 24px rgba(0, 0, 0, 0.3);
    }
    /* فقط با کلاس .open یا body.sidebar-open باز شود */
    .sidebar.open,
    body.sidebar-open .sidebar {
        transform: translateX(0) !important;
    }
    .sidebar.collapsed {
        transform: translateX(100%);
    }
    /* sidebar-backdrop در بالا تعریف شده، اینجا تکرار نشد */
    
    /* Main content full width */
    .main {
        width: 100vw;
        max-width: 100vw;
    }
    
    /* Header — sticky top bar */
    .main-header {
        position: sticky;
        top: 0;
        background: var(--bg-primary);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        z-index: 100;
        padding: 10px 12px;
        border-bottom: 1px solid var(--border);
    }
    
    /* Composer — bottom fixed مثل اپ موبایل */
    .composer-area, .input-area {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
    
    /* دکمه‌ها بزرگ‌تر برای touch */
    .btn-icon, .btn-sm {
        min-width: 40px;
        min-height: 40px;
    }
    .msg-action-btn {
        min-width: 36px;
        min-height: 36px;
    }
    
    /* صفحات admin — جدول‌ها در موبایل scrollable */
    .admin-container,
    .table-container {
        padding-left: 8px;
        padding-right: 8px;
    }
    .admin-container table,
    .table-container table {
        min-width: 600px;
    }
    .admin-container > div,
    .table-container > div[style*="overflow"] {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Tool menu — bottom sheet */
    .tool-menu {
        position: fixed !important;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 70vh;
        border-radius: 16px 16px 0 0;
        padding-bottom: max(20px, env(safe-area-inset-bottom));
        animation: slideUp 0.25s ease-out;
    }
    
    /* PWA install banner — ablobit */
    #pwaInstallBanner {
        font-size: 13px;
    }
    .pwa-install-text strong { font-size: 13px; }
    .pwa-install-text span   { font-size: 11px; }
    
    /* Notif panel — fullscreen در موبایل */
    .notif-panel {
        position: fixed !important;
        top: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        z-index: 9999 !important;
    }
    .notif-panel.show {
        animation: slideUp 0.3s ease-out;
    }
    
    /* Image studio — single column */
    .studio-container {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
    
    /* Profile — single column */
    .profile-container {
        padding: 12px !important;
    }
}

/* ══════════════════════════════════════════════════════════════════════
   Mobile-only touch optimizations
   ══════════════════════════════════════════════════════════════════════ */

body.is-mobile {
    /* جلوگیری از long-press menu روی iOS */
    -webkit-touch-callout: none;
}
body.is-mobile button,
body.is-mobile a {
    -webkit-tap-highlight-color: transparent;
}

/* Active state برای touch (به جای hover) */
@media (hover: none) and (pointer: coarse) {
    .btn-icon:active,
    .btn:active,
    .nav-item:active,
    .chat-item:active,
    .tool-item:active,
    .msg-action-btn:active {
        background: var(--bg-hover) !important;
        transform: scale(0.96);
    }
    
    /* hover حذف بشه چون کار نمی‌کنه و گاهی stuck می‌شه */
    .btn-icon:hover,
    .nav-item:hover {
        background: transparent;
    }
}

/* ══════════════════════════════════════════════════════════════════════
   App-like UI — وقتی به‌عنوان PWA نصب شده
   ══════════════════════════════════════════════════════════════════════ */

body.pwa-standalone .main-header {
    /* در حالت standalone، header مثل title bar اپ */
    border-bottom: 1px solid var(--border);
}

body.pwa-standalone.is-mobile {
    /* full height */
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

body.pwa-standalone .layout {
    height: 100vh;
    height: 100dvh;
}

/* Pull-to-refresh disable در standalone */
body.pwa-standalone {
    overscroll-behavior-y: contain;
}


/* ══════════════════════════════════════════════════════════════════════
   MOBILE BOTTOM NAVIGATION — مثل اپ‌های موبایل واقعی
   ══════════════════════════════════════════════════════════════════════ */

.mobile-bottom-nav {
    display: none; /* فقط در موبایل نمایش داده می‌شود */
}

@media (max-width: 768px) {
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 60px;
        background: var(--bg-primary);
        border-top: 1px solid var(--border);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        z-index: 500;
        padding-bottom: env(safe-area-inset-bottom);
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.15);
    }
    
    .mobile-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        text-decoration: none;
        color: #f7f7f9;
        font-size: 10.5px;
        font-weight: 500;
        transition: color 0.2s, transform 0.15s;
        position: relative;
        padding: 6px 4px 4px;
        -webkit-tap-highlight-color: transparent;
    }
    
    .mobile-nav-item svg {
        width: 22px;
        height: 22px;
        transition: transform 0.2s;
    }
    
    .mobile-nav-item span {
        font-family: inherit;
        white-space: nowrap;
    }
    
    .mobile-nav-item:active {
        transform: scale(0.92);
    }
    
    .mobile-nav-item.active {
        color: var(--accent);
    }
    
    .mobile-nav-item.active svg {
        transform: scale(1.1);
    }
    
    /* indicator خط بالای آیتم فعال */
    .mobile-nav-item.active::before {
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 32px;
        height: 3px;
        background: var(--accent);
        border-radius: 0 0 3px 3px;
    }
    
    /* وقتی bottom nav هست، فضای کافی برای محتوا اضافه کن */
    .main {
        padding-bottom: calc(60px + env(safe-area-inset-bottom));
    }
    
    /* composer هم باید بالای nav باشه */
    .composer-area, .input-area {
        bottom: calc(60px + env(safe-area-inset-bottom)) !important;
    }
}

/* ══════════════════════════════════════════════════════════════════════
   MOBILE — Top Header مثل اپ‌های موبایل
   ══════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    /* Header به سبک iOS/Android — سنگین‌تر، با عنوان وسط */
    .main-header {
        height: 56px;
        padding: 0 8px !important;
        padding-top: env(safe-area-inset-top) !important;
        height: calc(56px + env(safe-area-inset-top));
        display: flex !important;
        align-items: center;
        gap: 8px;
        background: var(--bg-primary) !important;
    }
    
    /* همبرگر در موبایل — راست */
    .main-header .header-right,
    .main-header .header-left {
        display: flex;
        align-items: center;
        gap: 6px;
    }
    
    /* Title باید کشیده باشه */
    .main-header .model-picker {
        flex: 1;
        max-width: 220px;
    }
    
    .model-picker-btn {
        padding: 6px 10px !important;
        font-size: 13px !important;
    }
    
    /* همه دکمه‌های header → 38x38 */
    .main-header .btn-icon {
        width: 38px;
        height: 38px;
        flex-shrink: 0;
    }
    
    /* Sidebar در موبایل — full slide-in */
    .sidebar {
        width: 88vw !important;
        max-width: 340px !important;
    }
    
    /* Chat list در موبایل — padding بهتر */
    .chat-item {
        padding: 12px 14px !important;
        font-size: 14px;
    }
    
    /* پیام‌ها در موبایل — full width estfade */
    .msg {
        max-width: 92% !important;
    }
    
    .msg-content {
        font-size: 14.5px;
        line-height: 1.6;
    }
    
    /* code blocks در موبایل — scrollable */
    .msg-content pre {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        font-size: 12px;
    }
    
    /* Composer در موبایل */
    .composer {
        padding: 10px 12px !important;
    }
    
    .composer textarea {
        font-size: 16px !important; /* iOS no-zoom */
        min-height: 44px;
        max-height: 120px;
    }
    
    /* دکمه ارسال بزرگ‌تر */
    .send-btn, #sendBtn {
        width: 42px;
        height: 42px;
    }
    
    /* Tools menu = bottom sheet مثل اپ‌های واقعی */
    .tool-menu {
        position: fixed !important;
        bottom: calc(60px + env(safe-area-inset-bottom)) !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        max-height: 60vh;
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 18px 18px 0 0 !important;
        border-bottom: none !important;
        animation: bottomSheetUp 0.3s cubic-bezier(0.32, 0.72, 0, 1);
        padding: 16px 16px 24px !important;
    }
    
    /* handle بالای bottom sheet */
    .tool-menu::before {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        background: var(--border);
        border-radius: 4px;
        margin: 0 auto 14px;
    }
    
    @keyframes bottomSheetUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
    
    /* Layout — full height */
    .layout {
        height: 100vh;
        height: 100dvh;
        overflow: hidden;
    }
    
    /* صفحات auth (login/register) در موبایل */
    .auth-container {
        padding: 20px 16px !important;
        min-height: 100vh;
        min-height: 100dvh;
    }
    
    .auth-card {
        margin: 0 auto;
        padding: 24px 20px !important;
        border-radius: 16px !important;
    }
    
    /* Profile در موبایل */
    .profile-grid {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }
    
    /* Image studio */
    .studio-panel,
    .studio-results {
        border-radius: 12px !important;
    }
    
    .studio-mode-tabs {
        position: sticky;
        top: 0;
        background: var(--bg-tertiary);
        z-index: 10;
        padding: 8px;
        border-radius: 12px 12px 0 0;
    }
    
    /* Admin sidebar در موبایل → drawer عمودی (نه bottom-sheet افقی) */
    /* قانون اصلی drawer در بلاک قبلی @media تعریف شده — اینجا فقط تثبیت */
    .admin-sidebar {
        flex-direction: column;
    }
    .admin-nav-item {
        flex: 0 0 auto;
        white-space: normal;
    }

    .admin-content {
        margin-right: 0 !important;
        padding-bottom: calc(80px + env(safe-area-inset-bottom)) !important;
    }
}

/* ══════════════════════════════════════════════════════════════════════
   PWA Standalone — حذف bottom nav و حالت "اپ مثل" کامل
   ══════════════════════════════════════════════════════════════════════ */

body.pwa-standalone.is-mobile .main-header {
    /* status bar دستگاه را شامل بشه */
    padding-top: calc(env(safe-area-inset-top) + 8px) !important;
}

body.pwa-standalone .mobile-bottom-nav {
    /* در حالت standalone هم safe-area رعایت شود */
    padding-bottom: max(env(safe-area-inset-bottom), 8px);
    height: calc(60px + max(env(safe-area-inset-bottom), 8px));
}

/* Smooth scroll برای حس native */
@media (max-width: 768px) {
    .chat-list,
    .messages-area,
    .admin-content,
    .studio-results-grid,
    .table-container > div {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
}

/* Splash screen-like loader for PWA */
body.pwa-standalone:not(.loaded)::before {
    content: '';
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #0a0a0a, #1a1030);
    z-index: 99999;
    pointer-events: none;
}


/* ── Image Skeleton Loader (placeholder حین لود) ── */
.thumb-skeleton,
.img-skeleton-loader {
    position: absolute;
    inset: 0;
    background: linear-gradient(110deg,
                rgba(155, 109, 255, 0.04) 25%,
                rgba(155, 109, 255, 0.12) 50%,
                rgba(155, 109, 255, 0.04) 75%);
    background-size: 200% 100%;
    animation: skeletonShine 1.5s ease-in-out infinite;
    border-radius: inherit;
}
@keyframes skeletonShine {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Image history items باید position:relative باشن */
.image-history-item {
    position: relative;
    overflow: hidden;
}
.image-history-item img {
    position: relative;
    z-index: 1;
}

/* Result image wrap */
.result-image-wrap {
    position: relative;
}


/* ══════════════════════════════════════════════════════════════════════
   FINAL OVERRIDE — sidebar-backdrop در دسکتاپ هرگز نمایش داده نشود
   این قانون باید آخرین قانون باشد تا همه قوانین قبلی رو override کند
   ══════════════════════════════════════════════════════════════════════ */
@media (min-width: 769px) {
    .sidebar-backdrop,
    body.sidebar-open .sidebar-backdrop,
    .sidebar-backdrop.show {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        pointer-events: none !important;
        background: transparent !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }
    
    /* در دسکتاپ، body.sidebar-open هیچ تأثیری روی main نداشته باشه */
    body.sidebar-open .main {
        filter: none !important;
        opacity: 1 !important;
    }
}


/* ══════════════════════════════════════════════════════════════════════
   READABILITY IMPROVEMENTS
   فونت‌های ریز کمی بزرگتر و رنگشان سفیدتر می‌شود
   ══════════════════════════════════════════════════════════════════════ */

/* اطمینان از حداقل فونت سایز خوانا (12px) */
small,
.small,
.text-xs,
.notif-time,
.msg-time,
.token-count,
.model-card-provider,
.user-meta .quota,
.chat-item-time,
.model-dropdown-desc,
.result-info,
.stat-card .label,
.notif-loading,
.recording-banner,
.image-gen-options,
.igo-label {
    font-size: 12.5px !important;
    color: #c5c5cf !important;
}

/* فونت‌های متنی متوسط — رنگشان سفیدتر */
.notif-msg,
.notif-content,
.profile-grid label,
.form-group small,
.form-group label {
    color: #d4d4dc !important;
    font-weight: 500;
}

/* labels در فرم‌ها */
label {
    color: #d4d4dc;
    font-weight: 500;
}

/* placeholder رنگشان روشن‌تر */
input::placeholder,
textarea::placeholder {
    color: #a0a0b0 !important;
    opacity: 1;
}

/* ==========================================================================
   Locale direction + mobile scroll hardening
   ========================================================================== */
html[dir="ltr"] body,
html[dir="ltr"] .main,
html[dir="ltr"] .tool-page-main,
html[dir="ltr"] .tools-scroll,
html[dir="ltr"] .lib-wrap,
html[dir="ltr"] .nb-main,
html[dir="ltr"] .img-main {
    direction: ltr;
    text-align: left;
}

html[dir="rtl"] body,
html[dir="rtl"] .main,
html[dir="rtl"] .tool-page-main,
html[dir="rtl"] .tools-scroll,
html[dir="rtl"] .lib-wrap,
html[dir="rtl"] .nb-main,
html[dir="rtl"] .img-main {
    direction: rtl;
    text-align: right;
}

html[dir="ltr"] input:not([type="number"]),
html[dir="ltr"] textarea,
html[dir="ltr"] select,
html[dir="ltr"] .msg-content,
html[dir="ltr"] .msg-text,
html[dir="ltr"] .tool-result-card,
html[dir="ltr"] .nb-thread,
html[dir="ltr"] .rdr-reader {
    direction: ltr;
    text-align: left;
}

html[dir="rtl"] input:not([type="number"]),
html[dir="rtl"] textarea,
html[dir="rtl"] select,
html[dir="rtl"] .msg-content,
html[dir="rtl"] .msg-text,
html[dir="rtl"] .tool-result-card,
html[dir="rtl"] .nb-thread,
html[dir="rtl"] .rdr-reader {
    direction: rtl;
    text-align: right;
}

pre,
code,
.code-block,
.code-block-wrap,
.msg-content pre,
.msg-content code {
    direction: ltr !important;
    text-align: left !important;
    unicode-bidi: plaintext;
}

html[dir="ltr"] .sidebar {
    border-right: 1px solid var(--border);
    border-left: 0;
}

html[dir="rtl"] .sidebar {
    border-left: 1px solid var(--border);
    border-right: 0;
}

html[dir="ltr"] .sidebar.collapsed {
    margin-left: -260px;
    margin-right: 0;
}

html[dir="rtl"] .sidebar.collapsed {
    margin-right: -260px;
    margin-left: 0;
}

html[dir="ltr"] .tw-go {
    margin-left: auto;
    margin-right: 0;
}

html[dir="rtl"] .tw-go {
    margin-right: auto;
    margin-left: 0;
}

input::placeholder,
textarea::placeholder {
    color: transparent !important;
}

@media (max-width: 768px) {
    html,
    body {
        overscroll-behavior-y: contain;
        -webkit-overflow-scrolling: touch;
    }

    body.app-shell .layout {
        height: 100dvh !important;
        min-height: 100dvh !important;
        overflow: hidden !important;
    }

    body.app-shell .main {
        min-height: 0 !important;
        height: 100dvh !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        touch-action: pan-y !important;
        overscroll-behavior-y: contain;
        -webkit-overflow-scrolling: touch;
        scroll-padding-bottom: calc(var(--mobile-nav-h, 60px) + 110px + env(safe-area-inset-bottom));
    }

    body.app-shell .chat-area,
    body.app-shell .img-canvas,
    body.app-shell .img-main,
    body.app-shell .nb-main,
    body.app-shell .nb-thread,
    body.app-shell .nb-src-list,
    body.app-shell .tool-page-main,
    body.app-shell .tools-scroll {
        min-height: 0 !important;
        overflow-y: auto !important;
        touch-action: pan-y !important;
        -webkit-overflow-scrolling: touch;
    }

    body:not(.app-shell) .main,
    body:not(.app-shell) .tool-page-main,
    body:not(.app-shell) .tools-scroll,
    body:not(.app-shell) .lib-wrap,
    body:not(.app-shell) .nb-list-wrap,
    body:not(.app-shell) .rdr-reader,
    body:not(.app-shell) .wallet-page,
    body:not(.app-shell) .profile-page,
    body:not(.app-shell) .knowledge-shell {
        overflow-y: auto !important;
        touch-action: pan-y !important;
        -webkit-overflow-scrolling: touch;
    }

    html[dir="ltr"] .sidebar {
        left: 0 !important;
        right: auto !important;
        transform: translateX(-104%) !important;
        box-shadow: 2px 0 18px rgba(0,0,0,0.45);
    }

    html[dir="rtl"] .sidebar {
        right: 0 !important;
        left: auto !important;
        transform: translateX(104%) !important;
        box-shadow: -2px 0 18px rgba(0,0,0,0.45);
    }

    html[dir="ltr"] .sidebar.open,
    html[dir="ltr"] body.sidebar-open .sidebar,
    html[dir="rtl"] .sidebar.open,
    html[dir="rtl"] body.sidebar-open .sidebar {
        transform: translateX(0) !important;
    }

    html[dir="ltr"] .sidebar.collapsed,
    html[dir="rtl"] .sidebar.collapsed {
        margin: 0 !important;
    }
}

/* عنوان‌های ثانوی — boldتر */
.section-title,
.form-section-title,
.studio-section-title {
    font-weight: 600 !important;
    color: #e8e8f0 !important;
}

/* notification time و sidebar items */
.notif-item .notif-time,
.chat-item .chat-item-time {
    color: #b0b0c0 !important;
    font-weight: 500;
}

/* badges خوانا‌تر */
.badge {
    font-weight: 600 !important;
    font-size: 11.5px !important;
    letter-spacing: 0.2px;
}

/* code و pre — کمی روشن‌تر */
code, pre {
    color: #e0e0e8;
}

/* tooltips و hint ها */
.tooltip,
[title]::after,
.hint {
    color: #d4d4dc !important;
}


/* ══════════════════════════════════════════════════════════════════════
   ADMIN MOBILE SCROLL FIX — قطعی تا scroll درست کار کنه
   ══════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    /* در موبایل، body خودش بایست اسکرول کنه نه admin-main تنها */
    body:has(.admin-layout) {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .admin-layout {
        height: auto !important;
        min-height: 100vh;
        overflow: visible !important;
    }
    
    .admin-main {
        overflow: visible !important;
        height: auto !important;
        min-height: 50vh;
        padding-bottom: calc(80px + env(safe-area-inset-bottom)) !important;
    }
    
    /* جدول‌ها در موبایل با scroll افقی */
    .table-container,
    .admin-main table {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* فرم‌ها باید کامل قابل scroll باشن */
    .form-section {
        max-width: 100%;
    }
}


/* ══════════════════════════════════════════════════════════════════════
   Notifications — Clickable items
   ══════════════════════════════════════════════════════════════════════ */
.notif-item.clickable {
    cursor: pointer;
    transition: background 0.15s;
}
.notif-item.clickable:hover {
    background: var(--bg-hover);
}
.notif-item.clickable:active {
    transform: scale(0.98);
}
.notif-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 6px;
}
.notif-arrow {
    color: var(--accent-light);
    font-size: 16px;
    font-weight: 700;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
}
.notif-item.clickable:hover .notif-arrow {
    opacity: 1;
    transform: translateX(-3px);
}
@media (max-width: 768px) {
    /* در موبایل arrow همیشه نمایش بده */
    .notif-arrow {
        opacity: 0.6;
    }
}


/* ═════════════════════════════════════════════════════════════
   ADDITIONS: Header avatar, code blocks, fixes
   ═════════════════════════════════════════════════════════════ */

/* Profile avatar in header */
.header-avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  background: var(--accent);
  color: white; font-weight: 700; font-size: 13px;
  border-radius: 50%;
  text-decoration: none;
  flex-shrink: 0;
  transition: transform .15s, box-shadow .15s;
  margin-right: 4px;
}
.header-avatar:hover { transform: scale(1.05); box-shadow: 0 0 0 3px rgba(155,109,255,.25); }

/* Sidebar: chat-section-title — slightly more polished */
.chat-section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  padding: 12px 12px 4px;
  text-transform: none;
  letter-spacing: 0;
  position: sticky; top: 0;
  background: var(--bg-secondary);
  z-index: 1;
}

/* ─── Fix: Admin sidebar must not overlap content on mobile ─── */
@media (max-width: 768px) {
  .admin-sidebar {
    /* اصلاح z-index و سایه برای پدیداری در موبایل */
    z-index: 1100 !important;
    box-shadow: -4px 0 24px rgba(0,0,0,0.5);
    background: var(--bg-secondary) !important;
  }
  .admin-sidebar-backdrop {
    z-index: 1099 !important;
  }
  .admin-sidebar-backdrop.show {
    opacity: 1; visibility: visible;
  }
  /* hide-by-default: when not 'show' must be hidden */
  .admin-sidebar:not(.show) {
    transform: translateX(105%);
  }
}

/* ─── Modern code blocks for chat ─── */
.msg-content pre, .msg-text pre {
  background: #0d1117 !important;
  border: 1px solid #30363d;
  border-radius: 10px;
  margin: 12px 0;
  overflow: hidden;
  position: relative;
}
.msg-content pre, .msg-text pre code {
  display: block;
  padding: 14px 16px !important;
  overflow-x: auto;
  background: transparent !important;
  color: #e6edf3;
  font-family: 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.6;
  direction: ltr;
  text-align: left;
}
.code-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px;
  background: #161b22;
  border-bottom: 1px solid #30363d;
  font-family: monospace;
  font-size: 11.5px;
  color: #8b949e;
}
.code-header-lang { font-weight: 600; }
.code-header-actions { display: flex; gap: 4px; }
.code-header-btn {
  background: transparent; border: none;
  color: #8b949e; cursor: pointer;
  padding: 3px 8px; border-radius: 4px;
  font-size: 11px;
  transition: all .15s;
}
.code-header-btn:hover { background: rgba(255,255,255,.07); color: #c9d1d9; }
.code-header-btn.copied { color: #3fb950; }

/* Inline code */
.msg-content code:not(pre code), .msg-text code:not(pre code) {
  background: rgba(155,109,255,0.1);
  color: #c8a0ff;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: 'Fira Code', monospace;
}

/* Tables in chat */
.msg-content table, .msg-text table {
  border-collapse: collapse;
  margin: 12px 0;
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
}
.msg-content th, .msg-content td, .msg-text th, .msg-text td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  text-align: right;
}
.msg-content th, .msg-text th {
  background: var(--bg-tertiary);
  font-weight: 600;
}

/* Blockquote */
.msg-content blockquote, .msg-text blockquote {
  border-right: 3px solid var(--accent);
  padding: 6px 14px;
  margin: 10px 0;
  color: var(--text-secondary);
  background: rgba(155,109,255,0.04);
  border-radius: 0 6px 6px 0;
}

/* Lists in chat */
.msg-content ul, .msg-content ol, .msg-text ul, .msg-text ol {
  padding-right: 24px;
  margin: 8px 0;
}
.msg-content li, .msg-text li { margin: 3px 0; }

/* Markdown headings */
.msg-content h1, .msg-content h2, .msg-content h3,
.msg-content h4, .msg-content h5, .msg-content h6 {
  margin: 14px 0 8px;
  font-weight: 700;
  line-height: 1.4;
}
.msg-content h1 { font-size: 20px; }
.msg-content h2 { font-size: 18px; }
.msg-content h3 { font-size: 16px; }
.msg-content h4, .msg-content h5, .msg-content h6 { font-size: 14px; }

/* Links */
.msg-content a, .msg-text a {
  color: var(--accent-light);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.msg-content a, .msg-text a:hover { color: var(--accent); }

/* Mobile fixes */
@media (max-width: 768px) {
  .header-avatar { width: 28px; height: 28px; font-size: 12px; }
  .main-header { padding: 8px 12px !important; }
  .main-header .model-picker-btn { padding: 6px 10px !important; font-size: 13px !important; }
  .header-right, .header-left { gap: 4px; }
}


/* ─── KaTeX / LaTeX rendering ─── */
.katex-block {
    display: block;
    overflow-x: auto;
    margin: 10px 0;
    padding: 6px 4px;
    text-align: center;
}
.katex { font-size: 1em !important; }
.katex-display { margin: 8px 0; }
/* Fix KaTeX font paths */
.katex .katex-html { direction: ltr; text-align: left; }

/* ─── Hint: clipboard paste for images ─── */
.composer-wrap:focus-within .paste-hint {
    display: block;
}

/* ═════════════════ Model Picker Modal ═════════════════ */
.model-picker-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: mp-fade 0.2s ease;
}
.model-picker-modal.show { display: flex; }

@keyframes mp-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

.model-picker-modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 100%;
    max-width: 920px;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: mp-scale 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes mp-scale {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.model-picker-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(155, 109, 255, 0.08), transparent);
}
.model-picker-header h2 {
    font-size: 18px;
    font-weight: 700;
    margin: 0;
    color: var(--text-primary);
}
.model-picker-close {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    width: 32px; height: 32px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.model-picker-close:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.3);
}

/* Search box */
.model-picker-search-wrap {
    padding: 14px 22px;
    position: relative;
    border-bottom: 1px solid var(--border);
}
.model-picker-search-wrap svg {
    position: absolute;
    right: 36px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}
.model-picker-search-wrap input {
    width: 100%;
    padding: 10px 44px 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13.5px;
}
.model-picker-search-wrap input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(155, 109, 255, 0.15);
}

/* Tabs */
.model-picker-tabs {
    display: flex;
    gap: 6px;
    padding: 12px 22px;
    overflow-x: auto;
    border-bottom: 1px solid var(--border);
    scrollbar-width: thin;
}
.model-picker-tabs::-webkit-scrollbar { height: 4px; }
.model-picker-tabs::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.mp-tab {
    --cat-color: var(--accent);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 7px 13px;
    border-radius: 10px;
    cursor: pointer;
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    transition: all 0.15s;
    flex-shrink: 0;
}
.mp-tab:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--cat-color);
}
.mp-tab.active {
    background: linear-gradient(135deg, var(--cat-color), color-mix(in srgb, var(--cat-color) 70%, black));
    color: white;
    border-color: var(--cat-color);
    box-shadow: 0 2px 8px color-mix(in srgb, var(--cat-color) 30%, transparent);
}
.mp-tab-count {
    background: rgba(0, 0, 0, 0.25);
    color: rgba(255, 255, 255, 0.85);
    padding: 1px 7px;
    border-radius: 10px;
    font-size: 10.5px;
    font-weight: 600;
    margin-right: 2px;
}
.mp-tab:not(.active) .mp-tab-count {
    background: var(--border);
    color: var(--text-muted);
}

/* ────────── Sidebar split layout (GapGPT-style) ────────── */
.model-picker-split {
    flex: 1;
    display: flex;
    min-height: 0;
    direction: rtl;
}
.mp-sidebar {
    width: 220px;
    flex-shrink: 0;
    background: var(--bg-primary);
    border-left: 1px solid var(--border);
    padding: 14px 10px;
    overflow-y: auto;
    display: flex; flex-direction: column;
    gap: 8px;
}
.mp-sidebar-title {
    font-size: 12px; font-weight: 700;
    color: var(--text-muted);
    padding: 6px 10px 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.mp-sidebar-list {
    display: flex; flex-direction: column; gap: 3px;
}
.mp-sb-item {
    --cat-color: var(--accent);
    display: flex; align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: 0;
    border-radius: 9px;
    color: var(--text-secondary);
    font-size: 13px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    text-align: right;
    transition: all 0.15s ease;
    position: relative;
}
.mp-sb-item:hover {
    background: rgba(155, 109, 255, 0.08);
    color: var(--text-primary);
}
.mp-sb-item.active {
    background: rgba(155, 109, 255, 0.14);
    color: var(--text-primary);
    font-weight: 600;
}
.mp-sb-item.active::before {
    content: '';
    position: absolute;
    right: 0; top: 8px; bottom: 8px;
    width: 3px;
    background: var(--cat-color);
    border-radius: 2px;
}
.mp-sb-emoji {
    font-size: 16px;
    width: 22px;
    text-align: center;
    color: var(--cat-color);
    flex-shrink: 0;
}
.mp-sb-label {
    flex: 1;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mp-sb-count {
    background: var(--bg-tertiary);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 999px;
    min-width: 22px;
    text-align: center;
}
.mp-sb-item.active .mp-sb-count {
    background: var(--cat-color);
    color: #fff;
}

.mp-main {
    flex: 1;
    display: flex; flex-direction: column;
    min-width: 0;
}

.mp-section-sub {
    color: var(--text-secondary);
    font-size: 12.5px;
    padding: 4px 2px 12px;
    border-bottom: 1px dashed var(--border);
    margin-bottom: 14px;
}
.mp-section-count {
    margin-right: auto;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    font-size: 11px; font-weight: 700;
    padding: 2px 8px; border-radius: 999px;
    min-width: 24px; text-align: center;
}
.mp-group-block { margin-bottom: 22px; }
.mp-group-block:last-child { margin-bottom: 0; }

/* ── Picker split on tablet/phone: sidebar → horizontal scrollable chip row ── */
@media (max-width: 720px) {
    .model-picker-split { flex-direction: column; }
    .mp-sidebar {
        width: 100%;
        border-left: 0;
        border-bottom: 1px solid var(--border);
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 10px 12px;
        gap: 4px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }
    .mp-sidebar::-webkit-scrollbar { height: 0; }
    .mp-sidebar-title { display: none; }
    .mp-sidebar-list {
        flex-direction: row;
        gap: 5px;
        flex-wrap: nowrap;
        width: max-content;
    }
    .mp-sb-item {
        flex-shrink: 0;
        padding: 7px 12px;
        border-radius: 999px;
        white-space: nowrap;
        gap: 6px;
        font-size: 12.5px;
        border: 1px solid transparent;
    }
    .mp-sb-item.active {
        border-color: color-mix(in srgb, var(--cat-color) 40%, transparent);
        background: color-mix(in srgb, var(--cat-color) 14%, transparent);
        color: var(--text-primary);
    }
    .mp-sb-item.active::before { display: none; }
    .mp-sb-emoji { font-size: 14px; width: auto; }
    .mp-sb-label { max-width: none; }
    .mp-sb-count {
        font-size: 10.5px; padding: 1px 6px;
        min-width: 18px;
    }
}

/* ── Phone portrait (≤520px) — make modal full-screen + single column cards ── */
@media (max-width: 520px) {
    .model-picker-modal { padding: 0; }
    .model-picker-modal-content {
        max-height: 100vh;
        max-height: 100dvh;
        height: 100dvh;
        border-radius: 0;
        border: none;
        max-width: 100%;
    }
    .model-picker-header { padding: 12px 14px; }
    .model-picker-header h2 { font-size: 15.5px; }
    .model-picker-close { width: 30px; height: 30px; font-size: 14px; }
    .model-picker-search-wrap { padding: 8px 14px; }
    .model-picker-search-wrap svg { right: 26px; width: 16px; height: 16px; }
    .model-picker-search-wrap input {
        font-size: 13.5px;
        padding: 8px 36px 8px 12px;
    }

    /* Sidebar (horizontal chip row) — slightly tighter */
    .mp-sidebar { padding: 8px 12px; gap: 4px; }
    .mp-sb-item { padding: 6px 11px; font-size: 12px; }

    /* Body — narrower padding + single-column grid */
    .model-picker-body { padding: 10px 12px 16px; }
    .mp-section-header {
        gap: 10px;
        padding: 10px 0 8px;
        margin-bottom: 10px;
    }
    .mp-section-emoji {
        font-size: 18px;
        width: 34px; height: 34px;
        border-radius: 8px;
    }
    .mp-section-title { font-size: 14px; }
    .mp-section-desc { font-size: 11px; }
    .mp-section-sub { font-size: 11.5px; padding: 2px 0 10px; }
    .mp-section-count { font-size: 10.5px; padding: 1px 7px; }
    .mp-grid {
        grid-template-columns: 1fr !important;
        gap: 8px;
    }
    .mp-grid-featured { grid-template-columns: 1fr !important; gap: 10px; }

    /* Card — denser layout */
    .mp-card { padding: 11px 12px; gap: 6px; }
    .mp-card-head { gap: 8px; }
    .mp-card-icon { width: 30px; height: 30px; }
    .mp-card-name { font-size: 13.5px; }
    .mp-card-desc { font-size: 11.5px; -webkit-line-clamp: 2; }
    .mp-tool { font-size: 9.5px; padding: 1px 5px; }
    .mp-card-cost { font-size: 10.5px; }
    .mp-card-featured::before { width: 20px; height: 20px; font-size: 10px; }
    .mp-group-block { margin-bottom: 16px; }
    .mp-empty { padding: 32px 16px; font-size: 12.5px; }
}

/* Body */
.model-picker-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px 22px 22px;
}

.mp-section-header {
    --cat-color: var(--accent);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 0 10px;
    margin-top: 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 14px;
}
.mp-section-header:first-child { margin-top: 0; padding-top: 6px; }
.mp-section-emoji {
    font-size: 22px;
    width: 40px; height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: color-mix(in srgb, var(--cat-color) 15%, transparent);
    border-radius: 10px;
    border: 1px solid color-mix(in srgb, var(--cat-color) 30%, transparent);
}
.mp-section-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 2px;
}
.mp-section-desc {
    font-size: 11.5px;
    color: var(--text-muted);
}

/* Cards grid */
.mp-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 10px;
    margin-bottom: 8px;
}

.mp-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.mp-card:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(155, 109, 255, 0.15);
}

.mp-card-head {
    display: flex;
    align-items: center;
    gap: 10px;
}
.mp-card-icon {
    width: 32px; height: 32px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
}
.mp-card-icon.avatar-fallback {
    background: var(--accent);
    color: white;
    font-weight: 700;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.mp-card-name {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.mp-badge {
    font-size: 11px;
    padding: 2px 5px;
    border-radius: 6px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    flex-shrink: 0;
}
.mp-badge.premium {
    background: rgba(251, 191, 36, 0.12);
    border-color: rgba(251, 191, 36, 0.3);
}
.mp-badge.reasoning {
    background: rgba(167, 139, 250, 0.12);
    border-color: rgba(167, 139, 250, 0.3);
}
.mp-badge.vision {
    background: rgba(96, 165, 250, 0.12);
    border-color: rgba(96, 165, 250, 0.3);
}

.mp-card-desc {
    font-size: 11.5px;
    color: var(--text-secondary);
    line-height: 1.55;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.mp-card-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding-top: 4px;
}
.mp-tool {
    font-size: 10px;
    padding: 2px 6px;
    background: rgba(155, 109, 255, 0.1);
    color: var(--accent-light, #c8a0ff);
    border-radius: 5px;
    border: 1px solid rgba(155, 109, 255, 0.2);
    display: inline-flex;
    align-items: center;
    gap: 3px;
    white-space: nowrap;
}

.mp-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 6px;
    border-top: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
    margin-top: auto;
}
.mp-card-cost {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
}
.mp-card-usage {
    font-size: 10.5px;
    color: #fb923c;
    font-weight: 600;
}

/* ─── Block (top-level: featured / raw / specialized) ─── */
.mp-block { margin-bottom: 22px; }
.mp-block:last-child { margin-bottom: 0; }

/* Featured block — visually distinguished */
.mp-block-featured {
    background: linear-gradient(135deg, rgba(251,191,36,0.06), transparent 60%);
    border: 1px solid rgba(251,191,36,0.18);
    border-radius: 14px;
    padding: 16px 16px 12px;
    margin-bottom: 22px;
}
.mp-block-featured .mp-section-header { border-bottom: 1px solid rgba(251,191,36,0.2); }

.mp-grid-featured {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
}
.mp-card-featured {
    background: linear-gradient(135deg, rgba(251,191,36,0.10), rgba(155,109,255,0.05));
    border-color: rgba(251,191,36,0.30);
    position: relative;
}
.mp-card-featured::before {
    content: '⭐';
    position: absolute;
    top: -6px; left: -6px;
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: white; font-size: 11px;
    width: 22px; height: 22px;
    border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 6px rgba(251,191,36,0.45);
    z-index: 1;
}
.mp-card-featured:hover {
    border-color: #fbbf24;
    box-shadow: 0 6px 18px rgba(251,191,36,0.20);
}

/* ─── Subgroup (manufacturer or category section) ─── */
.mp-subgroup {
    --cat-color: var(--accent);
    margin-bottom: 18px;
}
.mp-subgroup:last-child { margin-bottom: 0; }
.mp-subgroup-head {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px;
    background: color-mix(in srgb, var(--cat-color) 8%, transparent);
    border-right: 3px solid var(--cat-color);
    border-radius: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}
.mp-subgroup-emoji {
    font-size: 18px;
    width: 30px; height: 30px;
    display: inline-flex; align-items: center; justify-content: center;
    background: color-mix(in srgb, var(--cat-color) 20%, transparent);
    border-radius: 8px;
    flex-shrink: 0;
}
.mp-subgroup-label {
    font-size: 14px; font-weight: 700;
    color: var(--text-primary);
}
.mp-subgroup-count {
    font-size: 11px; font-weight: 600;
    padding: 2px 8px; border-radius: 10px;
    background: color-mix(in srgb, var(--cat-color) 18%, transparent);
    color: var(--text-secondary);
}
.mp-subgroup-desc {
    font-size: 11.5px;
    color: var(--text-muted);
    margin-right: auto;
}

/* Free badge for picker cards */
.mp-badge.free {
    background: rgba(52,211,153,0.15);
    border-color: rgba(52,211,153,0.35);
    color: #34d399;
}

/* Empty state */
.mp-empty {
    text-align: center; padding: 50px 20px;
    color: var(--text-muted);
    font-size: 13.5px;
}

/* Mobile */
@media (max-width: 640px) {
    .model-picker-modal { padding: 0; }
    .model-picker-modal-content {
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
        border: none;
    }
    .model-picker-header { padding: 14px 16px; }
    .model-picker-header h2 { font-size: 16px; }
    .model-picker-search-wrap { padding: 10px 16px; }
    .model-picker-tabs { padding: 10px 16px; gap: 5px; }
    .mp-tab { padding: 6px 10px; font-size: 11.5px; }
    .model-picker-body { padding: 10px 16px 16px; }
    .mp-section-emoji { font-size: 18px; width: 34px; height: 34px; }
    .mp-section-title { font-size: 14px; }
    .mp-grid { grid-template-columns: 1fr; gap: 8px; }
    .mp-grid-featured { grid-template-columns: 1fr; gap: 10px; }
    .mp-block-featured { padding: 12px; }
    .mp-subgroup-head { padding: 8px 10px; gap: 8px; }
    .mp-subgroup-label { font-size: 13px; }
    .mp-subgroup-desc { display: none; }
    .mp-card-featured::before { width: 20px; height: 20px; font-size: 10px; }
}

/* Tablet — 2 columns */
@media (min-width: 641px) and (max-width: 900px) {
    .mp-grid { grid-template-columns: repeat(2, 1fr); }
    .mp-grid-featured { grid-template-columns: repeat(2, 1fr); }
}

/* ══════════════════════════════════════════════════════════════════════
   RESPONSIVE FIXES — مرور و اصلاح کارایی دسکتاپ/موبایل
   ══════════════════════════════════════════════════════════════════════ */

/* PWA install banner را روی mobile bottom-nav قرار بده (نه پشتش) */
@media (max-width: 768px) {
    #pwaInstallBanner {
        bottom: calc(60px + env(safe-area-inset-bottom)) !important;
        padding: 10px 14px !important;
        border-radius: 14px 14px 0 0;
    }
}

/* Sticky close button در model picker — همیشه قابل دسترسی روی موبایل */
@media (max-width: 640px) {
    .model-picker-header {
        position: sticky;
        top: 0;
        z-index: 5;
        background: var(--bg-secondary);
    }
    .model-picker-search-wrap {
        position: sticky;
        top: 56px; /* ارتفاع تقریبی header */
        z-index: 4;
        background: var(--bg-secondary);
    }
}

/* Touch target — chat-action-btn روی موبایل کوچک بود */
@media (max-width: 768px) {
    .chat-action-btn {
        width: 34px !important;
        height: 34px !important;
        border-radius: 8px;
    }
    .chat-action-btn svg { width: 16px; height: 16px; }

    /* Action buttons همیشه قابل دسترس باشن، نه فقط روی hover */
    .chat-item-actions {
        opacity: 1 !important;
        visibility: visible !important;
    }

    /* اطمینان از اینکه composer روی بالای bottom-nav است */
    .composer-wrap {
        padding-bottom: calc(10px + env(safe-area-inset-bottom)) !important;
    }
}

/* جلوگیری از overflow افقی متن طولانی در پیام‌ها */
.msg-content,
.msg-text,
.msg-bubble {
    word-wrap: break-word;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* عناوین مدل طولانی در sidebar نباید overflow کنند */
.chat-item-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    flex: 1;
}

/* جلوگیری از scroll افقی کلی روی body */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* روی موبایل، header buttons فضای کافی داشته باشند */
@media (max-width: 480px) {
    .main-header .btn-icon {
        width: 36px !important;
        height: 36px !important;
    }
    /* اگر هم header-left خیلی شلوغ شد، avatar را در آخرین لحظه نگه دار */
    .header-avatar { margin-right: 2px; }
    /* مدل picker روی صفحات کوچک‌تر */
    .model-picker-btn span#currentModelName {
        max-width: 90px !important;
    }
}

/* ─── Notification panel: روی موبایل نباید پشت bottom-nav بره ─── */
@media (max-width: 768px) {
    .notif-panel {
        bottom: calc(70px + env(safe-area-inset-bottom)) !important;
        max-height: calc(100dvh - 140px) !important;
    }
}

/* ─── Tool menu (bottom sheet) — اطمینان از زمانی که bottom-nav وجود ندارد ─── */
body.pwa-standalone .tool-menu {
    bottom: env(safe-area-inset-bottom) !important;
}

/* ─── Studio: روی موبایل، tabs قابل اسکرول افقی ─── */
@media (max-width: 768px) {
    .studio-mode-tabs {
        display: flex;
        gap: 6px;
        overflow-x: auto;
        scrollbar-width: thin;
        -webkit-overflow-scrolling: touch;
        padding: 8px;
    }
    .studio-tab {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    /* image-studio: container اصلی stack شود (ستون‌ها زیر هم) */
    .studio-container {
        flex-direction: column !important;
        gap: 8px;
    }

    /* Audio studio — همان رفتار */
    .audio-studio-main .studio-container {
        flex-direction: column !important;
    }

    /* ─── Image studio: overlay دکمه‌ها (ویرایش/دانلود/کپی/مشابه)
       روی موبایل hover نداریم → باید همیشه visible باشند ─── */
    .result-overlay {
        opacity: 1 !important;
        /* پس‌زمینهٔ کم‌رنگ‌تر تا تصویر زیر دیده شود */
        background: linear-gradient(to top,
                                     rgba(0,0,0,0.55),
                                     rgba(0,0,0,0.15) 60%,
                                     transparent) !important;
        padding: 10px !important;
    }
    .result-overlay button {
        width: 36px !important;
        height: 36px !important;
    }
}

/* ─── جلوگیری از انتخاب متن روی دکمه‌ها (نه روی محتوای پیام) ─── */
button, .btn-icon, .nav-item, .mobile-nav-item, .chat-action-btn,
.msg-action-btn, .composer-icon-btn, .composer-plus-btn, .btn-send,
.studio-tab, .style-preset, .mp-tab, .mp-card {
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* ─── Input zoom prevention iOS — تأیید اضافه (composer-input هم پوشش داده شود) ─── */
@media (max-width: 768px) {
    .composer-input,
    .composer-textarea,
    input,
    textarea,
    select {
        font-size: 16px !important;
    }
}

/* ─── Flash messages روی موبایل (روی mobile-bottom-nav گذاشته نشود) ─── */
@media (max-width: 768px) {
    .flash-container {
        top: max(12px, env(safe-area-inset-top));
    }
}

/* ─── Empty chat icon روی موبایل کمی کوچکتر باشد ─── */
@media (max-width: 480px) {
    .empty-chat-content h2 { font-size: 20px; }
    .empty-chat-content p { font-size: 14px; }
    .empty-chat-icon svg { width: 52px; height: 52px; }
}

/* ══════════════════════════════════════════════════════════════════════
   💰 WALLET — کیف پول، پیش‌نمایش هزینه، badges
   ══════════════════════════════════════════════════════════════════════ */

/* Wallet balance pill در header چت */
.wallet-pill {
    display: inline-flex; align-items: center; gap: 5px;
    background: linear-gradient(135deg, rgba(155,109,255,0.15), rgba(155,109,255,0.05));
    border: 1px solid rgba(155,109,255,0.3);
    color: var(--accent-light);
    padding: 5px 12px; border-radius: 16px;
    text-decoration: none; font-size: 12.5px; font-weight: 600;
    font-variant-numeric: tabular-nums;
    transition: all 0.15s; flex-shrink: 0;
    direction: ltr;
}
.wallet-pill:hover {
    background: linear-gradient(135deg, rgba(155,109,255,0.25), rgba(155,109,255,0.10));
    border-color: var(--accent);
    transform: translateY(-1px);
}
.wallet-pill small { font-size: 10.5px; opacity: 0.8; margin-right: 1px; }
.wallet-pill.low { color: #fbbf24; border-color: rgba(251,191,36,0.4); background: linear-gradient(135deg, rgba(251,191,36,0.15), transparent); }
.wallet-pill.empty { color: #ef4444; border-color: rgba(239,68,68,0.4); background: linear-gradient(135deg, rgba(239,68,68,0.15), transparent); }
.wallet-pill.flash-up { animation: wp-up 1.2s ease; }
.wallet-pill.flash-down { animation: wp-down 1.2s ease; }

/* ── سوییچرِ زبانِ inline در هدر (یکدست در همهٔ صفحات، کنارِ کیف‌پول) ── */
.lang-switcher-inline { position: relative; flex-shrink: 0; }
.lang-switcher-inline > summary {
    list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 5px;
    background: var(--bg-secondary, #1a1a1a); color: var(--text-primary, #fff);
    border: 1px solid var(--border, #333); border-radius: 16px;
    padding: 5px 10px; font-size: 13px; line-height: 1; transition: border-color .15s, background .15s;
}
.lang-switcher-inline > summary:hover { border-color: var(--accent); background: var(--bg-hover); }
.lang-switcher-inline > summary::-webkit-details-marker { display: none; }
.lang-switcher-inline[open] > summary { border-color: var(--accent); }
.lang-menu {
    position: absolute; top: calc(100% + 6px); inset-inline-start: 0; min-width: 150px;
    background: var(--bg-secondary, #1a1a1a); border: 1px solid var(--border, #333);
    border-radius: 12px; padding: 6px; box-shadow: 0 8px 30px rgba(0,0,0,0.35); z-index: 1000;
}
.lang-menu-item {
    display: flex; align-items: center; gap: 9px; padding: 8px 12px;
    border-radius: 8px; text-decoration: none; color: var(--text-primary, #fff); font-size: 13.5px;
}
.lang-menu-item:hover { background: var(--bg-hover, rgba(255,255,255,0.06)); }
.lang-menu-item.active { background: rgba(155,109,255,0.15); color: var(--accent-light, #b794f6); }
.lang-menu-item .flag { font-size: 17px; }
/* روی موبایل آواتارِ هدر اضافه است (پروفایل در نوارِ پایین هست) → پنهان تا هدر شلوغ نشود */
@media (max-width: 680px){
    .header-avatar { display: none; }
    .lang-switcher-inline > summary { padding: 5px 8px; }
}
@keyframes wp-up {
  0%   { background: rgba(52,211,153,0.5); transform: scale(1); }
  30%  { background: rgba(52,211,153,0.3); transform: scale(1.08); box-shadow: 0 0 0 6px rgba(52,211,153,0.15); }
  100% {}
}
@keyframes wp-down {
  0%   { background: rgba(239,68,68,0.3); transform: scale(1); }
  30%  { background: rgba(239,68,68,0.18); transform: scale(0.96); }
  100% {}
}

@media (max-width: 480px) {
    .wallet-pill { padding: 4px 8px; font-size: 11.5px; }
    .wallet-pill svg { width: 12px; height: 12px; }
}

/* ══════════════════════════════════════════════════════════════════════
   📊 USAGE METER PANEL — کنتور مصرف زنده (دسکتاپ + موبایل drawer)
   ══════════════════════════════════════════════════════════════════════ */

/* ── پنل اصلی ── */
.usage-meter {
    position: fixed;
    z-index: 60;
    direction: rtl;
    font-family: inherit;
    /* desktop: sticky on left side, slim */
    left: 16px;
    bottom: 100px;
    width: 240px;
    background: linear-gradient(160deg, rgba(28,28,38,0.95), rgba(20,20,28,0.95));
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 10px 28px rgba(0,0,0,0.35);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    overflow: hidden;
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s;
	display:none;
}
.usage-meter:not(.open) .meter-body { display: none; }
.usage-meter:not(.open) .meter-handle .meter-chevron { transform: rotate(180deg); }

/* ── دستگیره (handle) ── */
.meter-handle {
    width: 100%;
    background: transparent;
    border: 0;
    color: var(--text-primary);
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 600;
    transition: background 0.15s;
}
.meter-handle:hover { background: rgba(255,255,255,0.04); }
.meter-handle-icon { font-size: 16px; }
.meter-handle-text { flex: 1; text-align: right; }
.meter-handle-pill {
    background: rgba(155,109,255,0.18);
    color: var(--accent-light);
    border: 1px solid rgba(155,109,255,0.3);
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    direction: ltr;
}
.meter-chevron {
    color: var(--text-muted);
    font-size: 14px;
    transition: transform 0.2s;
}

/* ── بدنه ── */
.meter-body {
    padding: 6px 12px 12px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0;
}
.meter-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 7px 0;
    font-size: 12px;
    border-bottom: 1px dashed rgba(255,255,255,0.04);
}
.meter-row:last-child { border-bottom: 0; }
.meter-label {
    color: var(--text-muted);
    font-size: 11.5px;
    white-space: nowrap;
}
.meter-value {
    color: var(--text-primary);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    direction: ltr;
    text-align: left;
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.meter-row.tone-success .meter-value { color: #34d399; }
.meter-row.tone-warning .meter-value { color: #fbbf24; }
.meter-row.tone-danger .meter-value  { color: #ef4444; }
.meter-row.meter-row-balance .meter-value { color: var(--accent-light); }
.meter-row.meter-row-model .meter-value {
    max-width: 130px; color: var(--text-secondary);
    direction: rtl; text-align: left; font-size: 11px;
}

/* ── progress bar ── */
.meter-bar-wrap {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255,255,255,0.05);
}
.meter-bar-bg {
    height: 5px;
    background: rgba(255,255,255,0.08);
    border-radius: 3px;
    overflow: hidden;
}
.meter-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.3s ease, background 0.3s;
}
.meter-bar-fill.tone-warning { background: #fbbf24; }
.meter-bar-fill.tone-danger  { background: #ef4444; }
.meter-bar-fill.tone-success { background: #34d399; }
.meter-bar-caption {
    font-size: 10.5px;
    color: var(--text-muted);
    margin-top: 4px;
    text-align: center;
}

/* ── link شارژ ── */
.meter-charge-link {
    display: block;
    text-align: center;
    margin-top: 10px;
    padding: 7px 10px;
    background: rgba(155,109,255,0.10);
    color: var(--accent-light);
    border: 1px solid rgba(155,109,255,0.25);
    border-radius: 8px;
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.15s;
}
.meter-charge-link:hover {
    background: rgba(155,109,255,0.18);
    border-color: var(--accent);
}

/* ══════════════════════════════════════════════════════════════════════
   MOBILE — به‌صورت drawer از پایین (روی mobile-bottom-nav)
   ══════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    .usage-meter {
        left: 0 !important;
        right: 0 !important;
        bottom: calc(60px + env(safe-area-inset-bottom));
        width: auto !important;
        border-radius: 16px 16px 0 0 !important;
        border-bottom: 0 !important;
        border-left: 0 !important;
        border-right: 0 !important;
        box-shadow: 0 -8px 24px rgba(0,0,0,0.45);
        max-height: 60vh;
        overflow-y: auto;
    }
    .usage-meter:not(.open) {
        /* فقط handle قابل دیدن باشد */
    }
    .meter-handle {
        position: relative;
        padding: 9px 14px;
        font-size: 13px;
    }
    /* handle indicator (نوار کوچک بالا) */
    .meter-handle::before {
        content: '';
        position: absolute;
        top: 4px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 3px;
        background: var(--border);
        border-radius: 3px;
    }
    .meter-handle-text { font-size: 12px; }
    .meter-chevron { transform: rotate(-90deg); }
    .usage-meter.open .meter-chevron { transform: rotate(90deg); }
    .meter-body { padding: 10px 16px 14px; }
    .meter-row { padding: 9px 0; font-size: 13px; }
    .meter-label { font-size: 12.5px; }
    .meter-value { font-size: 13px; max-width: none; }
}

/* PWA standalone: meter بالاتر باشد چون bottom-nav ممکن است نباشد */
body.pwa-standalone .usage-meter {
    bottom: max(60px, env(safe-area-inset-bottom)) !important;
}

/* وقتی composer مهم است (focus textarea)، meter را نازک‌تر کن */
@media (max-width: 768px) {
    body:has(.composer-input:focus) .usage-meter:not(.open) .meter-handle {
        padding: 7px 14px;
    }
}


/* ══════════════════════════════════════════════════════════════════════
   🛠 GLOBAL PAGE SCROLL FIX
   ----------------------------------------------------------------------
   پیش‌فرض body در ابتدای این فایل اسکرول‌پذیر تعریف شده.
   صفحاتی که scroll داخلی دارند (.layout, .auth-page) خودشان viewport را
   به ۱۰۰vh قفل می‌کنند و body به min-height نشسته باقی می‌ماند.
   اینجا فقط فضای پایین برای mobile-bottom-nav اضافه می‌کنیم.
   ══════════════════════════════════════════════════════════════════════ */

/* فضای پایین برای mobile-bottom-nav در صفحات اسکرول‌پذیر */
@media (max-width: 768px) {
    .wallet-page,
    .error-page {
        padding-bottom: calc(80px + env(safe-area-inset-bottom)) !important;
    }
    /* pending_approval container (inline-style div) */
    body > div[style*="min-height:100vh"]:not(.layout):not(.auth-card) {
        padding-bottom: calc(80px + env(safe-area-inset-bottom)) !important;
    }
}

/* در دسکتاپ هم wallet نیاز به فضای کافی دارد (و bottom-nav نمایش داده نمی‌شود) */
@media (min-width: 769px) {
    .wallet-page { padding-bottom: 40px !important; }
}


/* ══════════════════════════════════════════════════════════════════════
   🛠 ADMIN SIDEBAR — تثبیت Drawer عمودی روی موبایل
   ----------------------------------------------------------------------
   قانون پیشین یک سایدبارِ افقی (bottom-sheet) ایجاد می‌کرد که به‌هم‌ریخته
   بود. اینجا منوی مدیریت را روی موبایل به صورت drawer عمودی از سمت راست
   با hamburger در .admin-mobile-header تثبیت می‌کنیم.
   ══════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    .admin-sidebar {
        position: fixed !important;
        top: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        left: auto !important;
        width: 78vw !important;
        max-width: 300px !important;
        height: 100vh !important;
        height: 100dvh !important;
        padding: 18px 12px !important;
        padding-top: max(18px, env(safe-area-inset-top)) !important;
        padding-bottom: max(18px, env(safe-area-inset-bottom)) !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 2px !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        border-left: none !important;
        border-right: 1px solid var(--border) !important;
        border-top: none !important;
        background: var(--bg-secondary) !important;
        transform: translateX(105%);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1100;
        box-shadow: -4px 0 24px rgba(0,0,0,0.5);
    }
    .admin-sidebar.show {
        transform: translateX(0) !important;
    }
    .admin-sidebar h2 {
        font-size: 16px !important;
        margin-bottom: 14px !important;
        padding: 0 8px !important;
        white-space: normal !important;
    }
    .admin-sidebar .admin-nav-item {
        display: flex !important;
        align-items: center;
        gap: 10px;
        flex: 0 0 auto !important;
        width: 100% !important;
        padding: 10px 12px !important;
        font-size: 13.5px !important;
        white-space: normal !important;
        border-radius: var(--radius) !important;
        margin-bottom: 2px;
    }
    .admin-sidebar .admin-nav-item svg {
        flex-shrink: 0;
    }

    /* mobile header (hamburger) باید نمایش داده شود */
    .admin-mobile-header {
        display: flex !important;
    }
}


/* ══════════════════════════════════════════════════════════════════════
   🛠 AUTH PAGES — اطمینان از قابلیت اسکرول روی صفحات کوتاه viewport
   ══════════════════════════════════════════════════════════════════════ */
body.auth-page {
    height: auto;
    min-height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
}
.auth-page {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
@media (max-width: 768px) {
    body.auth-page {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ════════════════════════════════════════════════════════════════════════
 *  GUEST LOGIN PROMPT — modal shown after each guest message
 * ════════════════════════════════════════════════════════════════════════ */
.guest-login-prompt {
    position: fixed; inset: 0;
    z-index: 10000;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    animation: fadeIn .2s ease;
}
.guest-login-prompt[hidden] { display: none; }
.guest-login-prompt-backdrop {
    position: absolute; inset: 0;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(4px);
}
.guest-login-prompt-card {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 30px 26px 20px;
    max-width: 380px;
    width: 100%;
    text-align: center;
    box-shadow: 0 25px 60px rgba(0,0,0,0.5);
    animation: slideUpModal .25s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes slideUpModal {
    from { transform: translateY(20px); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}
.guest-login-prompt-close {
    position: absolute;
    top: 12px; left: 14px;
    width: 30px; height: 30px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
    border-radius: 50%;
    transition: background .15s;
}
.guest-login-prompt-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.guest-login-prompt-icon {
    display: inline-flex;
    color: var(--accent);
    background: rgba(155, 109, 255, 0.10);
    width: 72px; height: 72px;
    align-items: center; justify-content: center;
    border-radius: 50%;
    margin-bottom: 14px;
}
.guest-login-prompt-card h3 {
    margin: 0 0 8px;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}
.guest-login-prompt-card p {
    margin: 0 0 18px;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.7;
}
.guest-login-prompt-actions {
    display: flex; gap: 8px;
    margin-bottom: 14px;
}
.guest-login-prompt-actions .btn-primary,
.guest-login-prompt-actions .btn-secondary {
    flex: 1;
    display: inline-flex; align-items: center; justify-content: center;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 13.5px; font-weight: 600;
    text-decoration: none;
    transition: transform .15s, background .15s;
    cursor: pointer;
    border: 1px solid transparent;
}
.guest-login-prompt-actions .btn-primary {
    background: var(--accent);
    color: white;
}
.guest-login-prompt-actions .btn-primary:hover {
    background: var(--accent-light);
    transform: translateY(-1px);
}
.guest-login-prompt-actions .btn-secondary {
    background: transparent;
    color: var(--accent-light);
    border-color: var(--accent);
}
.guest-login-prompt-actions .btn-secondary:hover {
    background: rgba(155, 109, 255, 0.10);
}
.guest-continue-link {
    display: inline-block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-muted);
    text-decoration: none;
    padding: 6px 10px;
    border-radius: 6px;
    transition: color .15s, background .15s;
}
.guest-continue-link:hover {
    color: var(--accent-light);
    background: rgba(155, 109, 255, 0.06);
}
.guest-remaining-hint {
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-muted);
}
.guest-remaining-hint:empty { display: none; }

@media (max-width: 480px) {
    .guest-login-prompt-card {
        padding: 24px 20px 18px;
    }
    .guest-login-prompt-card h3 { font-size: 15px; }
    .guest-login-prompt-card p { font-size: 12.5px; }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ════════════════════════════════════════════════════════════════════════
 *  NOTIFICATION PANEL — final override for mobile
 *  (previous rules at lines ~2355, ~3576, ~5127 had conflicting !important
 *   declarations that produced incorrect layout. This block is authoritative.)
 * ════════════════════════════════════════════════════════════════════════ */
.notif-wrap .btn-icon svg,
#notifBtn svg {
    pointer-events: none;   /* iOS Safari: ensure clicks always hit the <button>, not the SVG */
}

@media (max-width: 768px) {
    .notif-panel {
        position: fixed !important;
        top: calc(56px + env(safe-area-inset-top)) !important;   /* below mobile header */
        bottom: calc(70px + env(safe-area-inset-bottom)) !important; /* above mobile nav */
        left: 8px !important;
        right: 8px !important;
        width: auto !important;
        max-height: none !important;     /* explicit top+bottom defines height — clear earlier max-height */
        border-radius: 14px !important;
        z-index: 9999 !important;
        background: var(--bg-secondary) !important;
        border: 1px solid var(--border) !important;
        box-shadow: 0 12px 36px rgba(0,0,0,0.45) !important;
        overflow: hidden;
    }
    /* keep base hidden / show toggling working with the !important above */
    .notif-panel:not(.show) {
        display: none !important;
    }
    .notif-panel.show {
        display: flex !important;
        flex-direction: column !important;
    }
}

/* ════════════════════════════════════════════════════════════════════════
 *  IMAGE STUDIO — chat-like redesign  (namespace: .img-*)
 * ════════════════════════════════════════════════════════════════════════ */

.img-main {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    min-height: 0;
    background: var(--bg-primary);
    overflow: hidden;
}

.img-main .img-model-fallback {
    width: 22px; height: 22px;
    display: inline-flex; align-items: center; justify-content: center;
    background: rgba(155,109,255,0.12);
    border-radius: 6px;
    font-size: 14px;
}

.img-canvas {
    flex: 1; min-height: 0;
    overflow-y: auto;
    scroll-behavior: smooth;
    padding: 0 20px;
    display: flex;
    flex-direction: column;
}

/* ─── Hero (empty state) ─── */
.img-hero {
    flex: 0 0 auto;
    text-align: center;
    padding: clamp(36px, 8vh, 80px) 16px 18px;
    color: var(--text-secondary);
    animation: imgFade .35s ease;
}
.img-hero-icon {
    color: var(--accent);
    opacity: 0.85;
    margin-bottom: 14px;
    display: inline-flex;
}
.img-hero h2 {
    font-size: clamp(22px, 3vw, 28px);
    font-weight: 700;
    margin: 0 0 6px;
    background: linear-gradient(135deg, var(--accent-light), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}
.img-hero p { font-size: 14.5px; color: var(--text-muted); margin: 0; }

/* ─── Thread (active state) ─── */
.img-thread {
    flex: 1 1 auto;
    max-width: 860px;
    width: 100%;
    margin: 0 auto;
    padding: 24px 0 16px;
    display: flex;
    flex-direction: column;
    gap: 22px;
}

@keyframes imgFade {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ═══════════ Messages ═══════════ */
.img-msg {
    animation: imgFade .25s ease;
    display: flex;
    flex-direction: column;
}
.img-msg-user {
    align-items: flex-end;        /* RTL: bubble to the right */
    align-self: stretch;
}
.img-msg-meta {
    display: flex; align-items: center; gap: 6px;
    font-size: 11.5px; color: var(--text-muted);
    margin-bottom: 6px;
}
.img-msg-tag {
    background: rgba(155,109,255,0.12);
    color: var(--accent-light);
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px; font-weight: 600;
}
.img-msg-tag.tag-edit      { background: rgba(34,197,94,0.12); color: #86efac; }
.img-msg-tag.tag-variation { background: rgba(59,130,246,0.12); color: #93c5fd; }
.img-msg-tag.tag-done      { background: rgba(34,197,94,0.14); color: #86efac; }
.img-msg-tag.tag-error     { background: rgba(239,68,68,0.16); color: #fca5a5; }
.img-msg-model { opacity: 0.7; }

.img-msg-bubble {
    background: var(--bg-user-msg, #2a2440);
    border-radius: 20px;
    padding: 12px 16px;
    max-width: 70%;
    font-size: 14.5px;
    color: var(--text-primary);
    line-height: 1.65;
    word-wrap: break-word;
}
.img-msg-attach {
    display: flex; flex-wrap: wrap; gap: 6px;
    margin-bottom: 8px;
}
.img-msg-thumb {
    width: 76px; height: 76px;
    object-fit: cover; border-radius: 10px;
    cursor: pointer;
    border: 1px solid rgba(255,255,255,0.08);
    transition: transform .15s;
}
.img-msg-thumb:hover { transform: scale(1.04); }

/* ─── Assistant result block ─── */
.img-msg-assistant {
    align-self: stretch;
    align-items: flex-start;
}
.img-result-grid {
    display: grid;
    gap: 10px;
    width: 100%;
    max-width: 720px;
}
.img-result-grid.grid-1 { grid-template-columns: minmax(0, 1fr); }
.img-result-grid.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.img-result-grid.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.img-result-grid.grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.img-result-slot {
    position: relative;
    border-radius: 14px;
    overflow: hidden;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    aspect-ratio: 1 / 1;
}
.img-result-grid.grid-1 .img-result-slot { aspect-ratio: auto; min-height: 320px; }

.img-result-slot img {
    width: 100%; height: 100%;
    object-fit: cover;
    cursor: zoom-in;
    display: block;
    opacity: 0; transition: opacity .35s;
}
.img-result-slot.loaded img,
.img-result-slot img[src] { opacity: 1; }

.img-result-shimmer {
    position: absolute; inset: 0;
    background: linear-gradient(110deg,
        rgba(255,255,255,0.04) 8%,
        rgba(255,255,255,0.10) 18%,
        rgba(255,255,255,0.04) 33%);
    background-size: 200% 100%;
    animation: imgShimmer 1.4s linear infinite;
}
@keyframes imgShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.img-result-tools {
    position: absolute;
    bottom: 8px; left: 8px;
    display: flex; gap: 4px;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(6px);
    border-radius: 999px;
    padding: 4px;
    opacity: 0;
    transition: opacity .18s;
}
.img-result-slot:hover .img-result-tools,
.img-result-slot:focus-within .img-result-tools { opacity: 1; }
.img-result-tools button {
    width: 30px; height: 30px;
    border-radius: 50%;
    border: none; cursor: pointer;
    background: rgba(255,255,255,0.10);
    color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background .15s;
}
.img-result-tools button:hover { background: rgba(255,255,255,0.22); }

.img-result-progress {
    display: flex; align-items: center; gap: 10px;
    margin-top: 10px;
    font-size: 12.5px; color: var(--text-muted);
    flex-wrap: wrap;
}
.img-revised-toggle {
    background: rgba(155,109,255,0.10);
    color: var(--accent-light);
    border: 1px solid rgba(155,109,255,0.25);
    padding: 3px 10px; border-radius: 999px;
    font-size: 11.5px; cursor: pointer;
}
.img-revised {
    display: none;
    flex-basis: 100%;
    background: rgba(155,109,255,0.07);
    border: 1px solid rgba(155,109,255,0.18);
    border-radius: 10px;
    padding: 8px 10px;
    color: var(--text-secondary);
    font-size: 11.5px; font-family: monospace;
    direction: ltr; text-align: left;
    max-height: 120px; overflow: auto;
}
.img-revised.show { display: block; }

.img-spinner {
    width: 14px; height: 14px;
    border: 2px solid rgba(255,255,255,0.18);
    border-top-color: var(--accent-light);
    border-radius: 50%;
    animation: imgSpin .8s linear infinite;
    display: inline-block;
}
@keyframes imgSpin { to { transform: rotate(360deg); } }

/* ═══════════ Composer wrap (state-driven) ═══════════ */
.img-composer-wrap {
    flex-shrink: 0;
    padding: 8px 16px 14px;
    background: var(--bg-primary);
    transition: padding .25s ease;
}
.img-composer-wrap.dragover {
    background: rgba(155,109,255,0.05);
    outline: 2px dashed rgba(155,109,255,0.35);
    outline-offset: -8px;
}

/* Empty state — composer becomes a prominent hero card */
.img-main[data-state="empty"] .img-canvas {
    overflow: hidden;
    padding-bottom: 0;
}
.img-main[data-state="empty"] .img-composer-wrap {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    padding-top: 8px;
}
.img-main[data-state="empty"] .img-thread { display: none; }
.img-main[data-state="empty"] .img-gallery-wrap { margin-top: auto; }

/* Big hero composer when empty */
.img-main[data-state="empty"] .img-composer-wrap {
    padding-top: 18px;
}
.img-main[data-state="empty"] .img-composer {
    max-width: min(840px, 92%);
    padding: 10px 12px;
    border-radius: 22px;
    box-shadow: 0 10px 32px rgba(0,0,0,0.18);
}
.img-main[data-state="empty"] .img-input {
    min-height: 80px;
    padding: 14px 8px;
    font-size: 15.5px;
}
.img-main[data-state="empty"] .img-toolbar,
.img-main[data-state="empty"] .img-gallery-wrap,
.img-main[data-state="empty"] .img-quickrow,
.img-main[data-state="empty"] .img-attach-row {
    max-width: min(840px, 92%);
}

/* Active state — composer is sticky-bottom, gallery becomes a compact strip */
.img-main[data-state="active"] .img-hero { display: none; }
.img-main[data-state="active"] .img-gallery-wrap {
    margin-top: 8px;
    padding: 6px 10px;
}
.img-main[data-state="active"] .img-gallery-strip {
    max-height: 110px;
    grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
}
.img-main[data-state="active"] .img-gallery-head {
    font-size: 11px;
    margin-bottom: 4px;
}

/* ─── Quick row (آخرین تصویر) ─── */
.img-quickrow {
    max-width: 780px;
    width: 100%;
    margin: 0 auto 6px;
    display: flex; flex-wrap: wrap; gap: 6px;
    box-sizing: border-box;
}
.img-quickrow:empty { display: none; }
.img-quick-chip {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 4px 12px 4px 4px;
    background: rgba(155,109,255,0.10);
    border: 1px solid rgba(155,109,255,0.30);
    color: var(--accent-light);
    border-radius: 999px;
    font-size: 12.5px; font-weight: 500;
    cursor: pointer;
    transition: background .15s, transform .15s;
}
.img-quick-chip:hover { background: rgba(155,109,255,0.20); transform: translateY(-1px); }
.img-quick-chip img {
    width: 26px; height: 26px;
    border-radius: 50%; object-fit: cover;
}

/* ─── Attachment row (inside composer wrap) ─── */
.img-attach-row {
    max-width: 780px;
    width: 100%;
    margin: 0 auto;
    display: flex; flex-wrap: wrap; gap: 6px;
    box-sizing: border-box;
}
.img-attach-row:empty { display: none; }
.img-attach-row.has-items { margin-bottom: 8px; }
.img-attach-chip {
    position: relative;
    width: 64px; height: 64px;
    border-radius: 10px;
    overflow: hidden;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
}
.img-attach-chip img { width: 100%; height: 100%; object-fit: cover; }
.img-attach-x {
    position: absolute; top: 2px; right: 2px;
    width: 20px; height: 20px;
    background: rgba(0,0,0,0.7); color: #fff;
    border: none; border-radius: 50%;
    cursor: pointer;
    font-size: 12px; line-height: 1;
    display: flex; align-items: center; justify-content: center;
}
.img-attach-badge {
    position: absolute; bottom: 2px; left: 2px;
    background: rgba(155,109,255,0.85); color: #fff;
    font-size: 9.5px; font-weight: 600;
    padding: 1px 6px; border-radius: 6px;
}

/* ─── Composer ─── */
.img-composer {
    max-width: 780px;
    width: 100%;
    margin: 0 auto;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 26px;
    padding: 6px 6px 6px 6px;
    display: flex; align-items: flex-end;
    gap: 6px;
    transition: border-color .2s, box-shadow .25s;
    box-sizing: border-box;
}
.img-composer:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(155,109,255,0.10);
}

.img-attach-btn, .img-send-btn {
    background: transparent;
    border: 1px solid var(--border-light);
    color: var(--text-secondary);
    width: 38px; height: 38px;
    border-radius: 50%;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s, color .15s, border-color .15s, transform .15s;
    flex-shrink: 0;
}
.img-attach-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

.img-input {
    flex: 1 1 0;
    min-width: 0;          /* allow shrinking — prevents flex blowout */
    background: transparent; border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14.5px;
    line-height: 1.6;
    resize: none; outline: none;
    padding: 8px 6px;
    min-height: 24px;
    max-height: 200px;
}
.img-input::placeholder { color: var(--text-muted); }

.img-send-btn {
    background: var(--text-primary); color: var(--bg-primary);
    border-color: var(--text-primary);
    position: relative;
}
.img-send-btn:hover:not(:disabled) { background: #fff; transform: scale(1.04); }
.img-send-btn:disabled {
    background: var(--bg-tertiary);
    color: var(--text-muted);
    border-color: var(--border);
    cursor: not-allowed;
}
.img-send-btn .icon-stop { display: none; }
.img-send-btn.is-stopping {
    background: #ef4444;
    color: #fff;
    border-color: #ef4444;
    animation: imgPulseStop 1.3s ease-in-out infinite;
}
.img-send-btn.is-stopping:hover { background: #dc2626; transform: none; }
.img-send-btn.is-stopping .icon-send { display: none; }
.img-send-btn.is-stopping .icon-stop { display: inline-block; }
@keyframes imgPulseStop {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.45); }
    50%      { box-shadow: 0 0 0 7px rgba(239,68,68,0); }
}

/* ═══════════ Toolbar (4 dropdown buttons) ═══════════ */
.img-toolbar {
    max-width: 780px;
    width: 100%;
    margin: 10px auto 0;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
    box-sizing: border-box;
}
/* ── Auto-mode badge (replaces removed generate/edit dropdown) ── */
.img-mode-badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px;
    background: rgba(155,109,255,0.12);
    border: 1px solid rgba(155,109,255,0.35);
    color: var(--accent-light);
    border-radius: 999px;
    font-size: 12.5px; font-weight: 600;
    white-space: nowrap;
    cursor: help;
}
.img-mode-badge.is-edit {
    background: rgba(245,158,11,0.12);
    border-color: rgba(245,158,11,0.45);
    color: #f59e0b;
}
.img-mode-emoji { font-size: 14px; line-height: 1; }
.img-mode-text { font-weight: 600; }

.img-tool { position: relative; }
.img-tool-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: 999px;
    font-size: 12.5px; font-weight: 500;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .15s;
    white-space: nowrap;
    font-family: inherit;
}
.img-tool-btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-light);
}
.img-tool-btn.active {
    background: rgba(155,109,255,0.18);
    border-color: rgba(155,109,255,0.50);
    color: var(--accent-light);
}
.img-tool-emoji { font-size: 14px; line-height: 1; }
.img-tool-label { font-weight: 600; }

/* Popover */
.img-tool-pop {
    position: absolute;
    bottom: calc(100% + 10px);
    right: 50%;
    transform: translateX(50%) translateY(6px);
    background: var(--bg-menu);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow-menu);
    padding: 14px;
    min-width: 280px;
    max-width: 340px;
    opacity: 0; visibility: hidden;
    transition: opacity .15s, transform .15s, visibility .15s;
    z-index: 60;
    max-height: min(70vh, 520px);
    overflow-y: auto;
}
.img-tool-pop.show {
    opacity: 1; visibility: visible;
    transform: translateX(50%) translateY(0);
}
.img-tool-pop-wide { min-width: 320px; }

.img-pop-title {
    font-size: 13px; font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 10px;
}
.img-pop-section {
    font-size: 11.5px; font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin: 12px 0 6px;
    display: flex; align-items: center; justify-content: space-between;
}
.img-pop-val {
    color: var(--accent-light);
    font-family: monospace;
    font-weight: 700;
    text-transform: none;
    letter-spacing: 0;
}
.img-pop-hint {
    font-size: 11.5px;
    color: var(--text-muted);
    margin-top: 10px;
    line-height: 1.5;
}

.img-pop-item {
    display: flex; align-items: center; gap: 10px;
    width: 100%;
    padding: 9px 10px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 10px;
    color: var(--text-primary);
    cursor: pointer;
    text-align: right;
    transition: background .15s;
    font-family: inherit;
    margin-bottom: 4px;
}
.img-pop-item:hover { background: var(--bg-menu-hover); }
.img-pop-item.active {
    background: rgba(155,109,255,0.12);
    border-color: rgba(155,109,255,0.30);
}
.img-pop-emoji {
    width: 32px; height: 32px;
    background: rgba(155,109,255,0.10);
    border-radius: 9px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 16px; flex-shrink: 0;
}
.img-pop-name { font-size: 13.5px; font-weight: 600; }
.img-pop-desc { font-size: 11.5px; color: var(--text-muted); margin-top: 1px; }

/* Aspect-ratio grid */
.img-aspect-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}
.img-aspect {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: 10px;
    padding: 8px 4px 6px;
    cursor: pointer;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 4px;
    transition: all .15s;
    font-family: inherit;
}
.img-aspect:hover { border-color: var(--accent); transform: translateY(-1px); }
.img-aspect.active {
    background: rgba(155,109,255,0.10);
    border-color: var(--accent);
    color: var(--accent-light);
}
.img-aspect span { font-size: 11px; font-weight: 600; }
.aspect-box {
    background: currentColor;
    opacity: 0.55;
    border-radius: 3px;
}
.aspect-box.ar-1x1   { width: 22px; height: 22px; }
.aspect-box.ar-16x9  { width: 28px; height: 16px; }
.aspect-box.ar-9x16  { width: 16px; height: 28px; }
.aspect-box.ar-7x4   { width: 26px; height: 16px; }
.aspect-box.ar-4x7   { width: 16px; height: 26px; }
.aspect-box.ar-1x1.small { width: 18px; height: 18px; }

/* Segmented control */
.img-seg {
    display: inline-flex;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px;
    width: 100%;
    gap: 2px;
}
.img-seg-btn {
    flex: 1;
    padding: 6px 10px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    border-radius: 999px;
    cursor: pointer;
    font-size: 12px; font-weight: 600;
    transition: background .15s, color .15s;
    font-family: inherit;
}
.img-seg-btn:hover { color: var(--text-primary); }
.img-seg-btn.active {
    background: var(--accent);
    color: #fff;
}

/* Presets chip grid */
.img-presets {
    display: flex; flex-wrap: wrap; gap: 6px;
}
.img-preset {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: 999px;
    padding: 6px 11px;
    font-size: 12px;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .15s;
    font-family: inherit;
}
.img-preset:hover { background: var(--bg-hover); border-color: var(--border-light); }
.img-preset.flash { background: var(--accent); color: #fff; transform: scale(1.05); }

/* Range / select / inputs / checkbox */
.img-range {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 999px;
    outline: none;
}
.img-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px; height: 16px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    transition: transform .12s;
}
.img-range::-webkit-slider-thumb:hover { transform: scale(1.15); }
.img-range::-moz-range-thumb {
    width: 16px; height: 16px;
    background: var(--accent);
    border-radius: 50%;
    border: none;
    cursor: pointer;
}

.img-pop-select, .img-pop-input, .img-pop-textarea {
    width: 100%;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color .15s;
}
.img-pop-select:focus,
.img-pop-input:focus,
.img-pop-textarea:focus {
    border-color: var(--accent);
}
.img-pop-textarea { resize: vertical; min-height: 56px; }

.img-pop-toggles {
    display: flex; flex-direction: column; gap: 6px;
    margin-top: 10px;
}
.img-pop-check {
    display: flex; align-items: center; gap: 8px;
    font-size: 12.5px; color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}
.img-pop-check input { accent-color: var(--accent); }

/* ═══════════ Gallery ═══════════ */
.img-gallery-wrap {
    max-width: 780px;
    width: 100%;
    margin: 14px auto 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 10px 12px;
    transition: max-height .3s ease;
    box-sizing: border-box;
}
.img-gallery-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 8px;
    font-size: 12px; color: var(--text-secondary);
}
.img-gallery-clear {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background .15s;
}
.img-gallery-clear:hover { background: var(--bg-hover); color: #fca5a5; }

.img-gallery-strip {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 8px;
    max-height: 360px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 4px;
    padding-left: 2px; /* room for scrollbar */
}
.img-gallery-strip::-webkit-scrollbar { width: 6px; }
.img-gallery-strip::-webkit-scrollbar-thumb {
    background: var(--border); border-radius: 3px;
}
.img-gallery-strip::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

.img-gallery-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    padding: 16px;
    width: 100%;
    grid-column: 1 / -1;
}

.img-gallery-item {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 10px;
    overflow: hidden;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    transition: transform .15s, border-color .15s;
}
.img-gallery-item:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
}
.img-gallery-item img {
    width: 100%; height: 100%;
    object-fit: cover;
    cursor: zoom-in;
}
.img-gallery-tools {
    position: absolute;
    inset: auto 0 0 0;
    display: flex; justify-content: center;
    gap: 2px;
    padding: 3px;
    background: linear-gradient(transparent, rgba(0,0,0,0.75));
    opacity: 0;
    transition: opacity .15s;
}
.img-gallery-item:hover .img-gallery-tools { opacity: 1; }
.img-gallery-tools button {
    background: rgba(255,255,255,0.10);
    border: none; color: #fff;
    width: 22px; height: 22px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 11px;
    display: inline-flex; align-items: center; justify-content: center;
}
.img-gallery-tools button:hover { background: rgba(255,255,255,0.22); }

/* ═══════════ Lightbox ═══════════ */
.img-lightbox {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.92);
    z-index: 9000;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    animation: imgFade .2s ease;
    touch-action: pinch-zoom;
}
.img-lightbox[hidden] { display: none; }
.img-lightbox img {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.img-lightbox-close {
    position: absolute;
    top: 14px; left: 14px;
    width: 38px; height: 38px;
    background: rgba(255,255,255,0.10);
    color: #fff; border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: inline-flex; align-items: center; justify-content: center;
    backdrop-filter: blur(6px);
}
.img-lightbox-close:hover { background: rgba(255,255,255,0.20); }
.img-lightbox-actions {
    position: absolute;
    bottom: 24px;
    display: flex; gap: 10px;
    background: rgba(0,0,0,0.65);
    backdrop-filter: blur(8px);
    border-radius: 999px;
    padding: 6px;
}
.img-lightbox-actions button {
    width: 44px; height: 44px;
    background: rgba(255,255,255,0.10);
    color: #fff; border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 17px;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background .15s, transform .15s;
}
.img-lightbox-actions button:hover {
    background: rgba(255,255,255,0.22);
    transform: scale(1.08);
}

/* ═══════════ Toast ═══════════ */
.img-toast {
    position: fixed;
    bottom: 28px; left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(20, 20, 30, 0.92);
    backdrop-filter: blur(8px);
    color: #fff;
    padding: 10px 20px;
    border-radius: 999px;
    font-size: 13px;
    z-index: 9999;
    box-shadow: 0 10px 30px rgba(0,0,0,0.4);
    border: 1px solid rgba(255,255,255,0.08);
    opacity: 0;
    transition: opacity .2s, transform .2s;
    pointer-events: none;
}
.img-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ═══════════ Inpaint mask bar (composer) ═══════════ */
.img-mask-bar {
    display: flex; align-items: center; gap: 10px;
    margin: 4px 2px 0;
    padding: 6px 10px;
    background: rgba(155,109,255,0.07);
    border: 1px solid rgba(155,109,255,0.22);
    border-radius: 12px;
    font-size: 12.5px;
}
.img-mask-bar[hidden] { display: none; }
.img-mask-btn {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--accent); color: #fff;
    border: none; cursor: pointer;
    padding: 6px 12px; border-radius: 999px;
    font-size: 12.5px; font-weight: 600;
}
.img-mask-btn:hover { filter: brightness(1.08); }
.img-mask-status { color: var(--text-muted); }
.img-mask-status.is-set { color: #34d399; font-weight: 600; }
.img-mask-clear {
    margin-inline-start: auto;
    width: 24px; height: 24px; border-radius: 50%;
    border: 1px solid var(--border); background: transparent;
    color: var(--text-muted); cursor: pointer; line-height: 1;
}
.img-mask-clear:hover { color: #f87171; border-color: #f87171; }

/* ═══════════ Inpaint mask editor (modal) ═══════════ */
.img-mask-modal {
    position: fixed; inset: 0; z-index: 10000;
    background: rgba(0,0,0,0.88);
    backdrop-filter: blur(6px);
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
}
.img-mask-modal[hidden] { display: none; }
.img-mask-dialog {
    display: flex; flex-direction: column;
    max-width: min(92vw, 760px); max-height: 92vh;
    background: var(--bg-secondary, #16161f);
    border: 1px solid var(--border);
    border-radius: 18px; overflow: hidden;
}
.img-mask-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; font-size: 14px; font-weight: 600;
    border-bottom: 1px solid var(--border);
}
.img-mask-x {
    width: 30px; height: 30px; border-radius: 50%;
    border: none; cursor: pointer;
    background: rgba(255,255,255,0.08); color: #fff;
}
.img-mask-x:hover { background: rgba(255,255,255,0.18); }
.img-mask-stage {
    position: relative; flex: 1;
    display: flex; align-items: center; justify-content: center;
    overflow: auto; background: #0a0a0f;
    min-height: 200px;
}
.img-mask-stage img {
    display: block; max-width: 100%; max-height: 64vh;
    object-fit: contain; user-select: none; pointer-events: none;
}
.img-mask-canvas {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    max-width: 100%; max-height: 64vh;
    cursor: crosshair; touch-action: none;
}
.img-mask-tools {
    display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
    padding: 12px 16px; border-top: 1px solid var(--border);
}
.img-mask-brush {
    display: flex; align-items: center; gap: 8px;
    font-size: 12.5px; color: var(--text-muted);
}
.img-mask-brush input[type=range] { width: 130px; }
.img-mask-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-inline-start: auto; }
.img-mask-btns button {
    padding: 7px 13px; border-radius: 10px; cursor: pointer;
    font-size: 12.5px; font-weight: 600;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border); color: var(--text);
}
.img-mask-btns button:hover { background: rgba(255,255,255,0.12); }
.img-mask-btns #imgMaskInvertBtn.active {
    background: rgba(155,109,255,0.18);
    border-color: var(--accent); color: var(--accent-light);
}
.img-mask-apply { background: var(--accent) !important; color: #fff !important; border-color: transparent !important; }
.img-mask-apply:hover { filter: brightness(1.08); }

/* ═══════════ Multi-model compare ═══════════ */
.img-cmp-toggle { font-weight: 600; }
.img-cmp-list { display: flex; flex-direction: column; gap: 2px; max-height: 200px; overflow: auto; }
.img-cmp-item { font-size: 12.5px; }
.img-cmp-note { margin-top: 8px; font-size: 11.5px; color: var(--text-muted); line-height: 1.6; }
.img-cmp-label {
    position: absolute; top: 6px; left: 6px; z-index: 3;
    max-width: calc(100% - 12px);
    padding: 2px 9px; border-radius: 999px;
    background: rgba(0,0,0,0.62); backdrop-filter: blur(4px);
    color: #fff; font-size: 11px; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    pointer-events: none;
}
.img-cmp-failed {
    display: flex; align-items: center; justify-content: center;
    background: rgba(248,113,113,0.06);
    border-color: rgba(248,113,113,0.30);
}
.img-cmp-err {
    padding: 0 12px; text-align: center;
    color: #fca5a5; font-size: 12px;
}

/* ═══════════ Sheet backdrop (mobile) ═══════════ */
/* z-index must sit ABOVE .mobile-bottom-nav (500) so the nav is also dimmed
 * while the bottom-sheet is open; tap on the dimmed nav area then closes the sheet. */
.img-sheet-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 750;
    opacity: 0; visibility: hidden;
    transition: opacity .2s, visibility .2s;
}
.img-sheet-backdrop.show {
    opacity: 1; visibility: visible;
}

/* ═══════════ Mobile (≤768px) ═══════════ */
@media (max-width: 768px) {
    .img-canvas {
        padding: 0 12px;
    }
    .img-thread {
        padding: 16px 0 12px;
        gap: 18px;
    }
    .img-msg-bubble {
        max-width: 85%;
        padding: 10px 14px;
        font-size: 14px;
    }
    .img-msg-thumb {
        width: 64px; height: 64px;
    }
    .img-result-grid.grid-1 .img-result-slot { min-height: 240px; }

    .img-composer-wrap {
        padding: 6px 10px calc(10px + env(safe-area-inset-bottom));
    }
    .img-composer {
        max-width: 100%;
        border-radius: 22px;
    }
    .img-attach-btn, .img-send-btn { width: 38px; height: 38px; }
    .img-input { font-size: 16px; }   /* prevent iOS zoom */

    /* Empty state on mobile: composer fills width, textarea is tall */
    .img-main[data-state="empty"] .img-composer { max-width: 100%; padding: 8px 10px; }
    .img-main[data-state="empty"] .img-input {
        min-height: 110px;
        font-size: 16px;
        padding: 12px 6px;
    }
    .img-main[data-state="empty"] .img-toolbar,
    .img-main[data-state="empty"] .img-gallery-wrap,
    .img-main[data-state="empty"] .img-quickrow,
    .img-main[data-state="empty"] .img-attach-row { max-width: 100%; }

    .img-toolbar {
        max-width: 100%;
        flex-wrap: nowrap;
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        justify-content: flex-start;
        margin-top: 8px;
        padding-bottom: 2px;
        scrollbar-width: none;
    }
    .img-toolbar::-webkit-scrollbar { display: none; }
    .img-tool { scroll-snap-align: start; flex-shrink: 0; }
    .img-tool-btn { padding: 7px 12px; font-size: 12px; }

    .img-attach-row { max-width: 100%; }
    .img-quickrow { max-width: 100%; }

    /* Popovers → bottom-sheet, sitting ABOVE the mobile bottom-nav (60px tall) */
    .img-tool-pop {
        position: fixed;
        left: 0; right: 0;
        bottom: calc(60px + env(safe-area-inset-bottom));
        top: auto;
        transform: translateY(calc(100% + 60px + env(safe-area-inset-bottom)));
        min-width: 100%; max-width: 100%;
        max-height: 70vh;
        border-radius: 22px 22px 0 0;
        padding: 22px 18px 20px;
        z-index: 800;          /* above mobile nav (500) and backdrop (750) */
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .img-tool-pop.show { transform: translateY(0); }
    .img-tool-pop::before {
        content: '';
        position: absolute;
        top: 8px; left: 50%;
        transform: translateX(-50%);
        width: 40px; height: 4px;
        background: var(--border-light);
        border-radius: 999px;
    }
    .img-tool-pop .img-pop-title {
        margin-top: 12px;
        font-size: 14.5px;
    }

    .img-gallery-wrap {
        max-width: 100%;
        margin-top: 10px;
        padding: 8px 10px;
        border-radius: 14px;
    }
    .img-gallery-strip {
        grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
        max-height: 290px;
        gap: 6px;
    }

    /* Header tweaks already covered by .model-picker-btn media query in chat header */
    .img-main .model-picker-btn span#imgCurrentModelName { max-width: 110px; }

    /* Lightbox */
    .img-lightbox { padding: 0; }
    .img-lightbox img { max-height: 100vh; border-radius: 0; }
    .img-lightbox-actions { bottom: calc(20px + env(safe-area-inset-bottom)); }

    /* Mask editor on mobile */
    .img-mask-modal { padding: 0; }
    .img-mask-dialog { max-width: 100vw; max-height: 100vh; border-radius: 0; }
    .img-mask-stage img, .img-mask-canvas { max-height: 56vh; }
    .img-mask-tools { gap: 8px; }
    .img-mask-brush input[type=range] { width: 90px; }
    .img-mask-btns { margin-inline-start: 0; }
}

/* Tablet sweet spot — keep composer centered but not too wide */
@media (min-width: 769px) and (max-width: 1024px) {
    .img-composer, .img-toolbar, .img-attach-row,
    .img-quickrow, .img-gallery-wrap, .img-thread {
        max-width: 680px;
    }
}

/* Hide body scroll when bottom sheet is open */
body.img-sheet-open { overflow: hidden; }

/* ══════════════════════════════════════════════════════════════════════
   WEB-SEARCH PANEL — جست‌وجوی وبِ چندزبانه (DDG + 5-lang + Wikipedia)
   ══════════════════════════════════════════════════════════════════════ */

.websearch-panel {
    margin-bottom: 12px;
    border: 1px solid rgba(59, 178, 255, 0.28);
    border-radius: var(--radius);
    background: linear-gradient(180deg, rgba(59,178,255,0.06), rgba(59,178,255,0.02));
    overflow: hidden;
}

.websearch-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    text-align: right;
    transition: background 0.15s, color 0.15s;
}
.websearch-toggle:hover {
    background: rgba(59, 178, 255, 0.08);
    color: var(--text-primary);
}
.websearch-toggle svg:first-child { color: #3bb2ff; flex-shrink: 0; }
.websearch-toggle-label { flex: 1; text-align: right; font-weight: 500; }

.websearch-stat-pill {
    padding: 3px 9px;
    background: rgba(59,178,255,0.14);
    color: #66c6ff;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    flex-shrink: 0;
}

.websearch-panel:not(.active) .thinking-chevron { transform: rotate(180deg); }

/* Body */
.websearch-body {
    display: none;
    padding: 10px 14px 12px;
    border-top: 1px solid rgba(59,178,255,0.2);
    font-size: 12.5px;
    line-height: 1.7;
    color: var(--text-secondary);
}
.websearch-panel.active .websearch-body { display: block; }

/* Phase chips row */
.websearch-phases {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px dashed rgba(59,178,255,0.18);
}
.ws-phase {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(255,255,255,0.04);
    color: var(--text-muted);
    font-size: 11.5px;
    transition: background 0.2s, color 0.2s;
}
.ws-phase-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px; height: 18px;
    border-radius: 50%;
    background: rgba(255,255,255,0.08);
    color: var(--text-secondary);
    font-size: 10.5px;
    font-weight: 700;
}
.ws-phase.active {
    background: rgba(59,178,255,0.16);
    color: #66c6ff;
}
.ws-phase.active .ws-phase-num {
    background: #3bb2ff;
    color: #fff;
    animation: spin 1.4s linear infinite;
}
.ws-phase.done {
    background: rgba(98,212,143,0.12);
    color: #6dd49d;
}
.ws-phase.done .ws-phase-num { background: #4caf78; color: #fff; }
.ws-phase-sep {
    color: var(--text-muted);
    opacity: 0.5;
    font-size: 11px;
}

/* Meta rows: datetime / keywords / question_type / translations */
.websearch-meta {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
}
.ws-meta-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
}
.ws-meta-row > span { color: var(--text-muted); min-width: 90px; }
.ws-meta-row > b { color: var(--text-primary); font-weight: 500; }

.ws-trans-wrap {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 4px 12px;
    margin-top: 4px;
    padding: 6px 10px;
    background: rgba(255,255,255,0.03);
    border-radius: 8px;
}
.ws-trans-row {
    display: flex;
    align-items: baseline;
    gap: 6px;
    font-size: 12px;
}
.ws-trans-row > span { color: var(--text-muted); min-width: 50px; }
.ws-trans-row > b { color: var(--text-primary); font-weight: 400; }

/* Stats row */
.websearch-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}
.ws-stat {
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
    padding: 3px 9px;
    background: rgba(255,255,255,0.04);
    border-radius: 8px;
    font-size: 12px;
}
.ws-stat > b { color: var(--text-primary); font-weight: 700; }
.ws-stat > span { color: var(--text-muted); }

/* Log lines */
.websearch-log {
    max-height: 220px;
    overflow-y: auto;
    padding: 8px 10px;
    background: rgba(0,0,0,0.18);
    border-radius: 8px;
    font-family: 'Vazirmatn', system-ui, sans-serif;
    font-size: 12px;
    line-height: 1.7;
    color: var(--text-secondary);
}
.ws-log-line {
    padding: 1px 0;
    direction: rtl;
    word-break: break-word;
    white-space: pre-wrap;
}
.ws-log-phase {
    color: #66c6ff;
    font-weight: 600;
    padding-top: 4px;
    margin-top: 4px;
    border-top: 1px dotted rgba(59,178,255,0.18);
}
.websearch-log::-webkit-scrollbar { width: 4px; }
.websearch-log::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }

/* Mobile: compress phase chips */
@media (max-width: 540px) {
    .ws-phase-name { display: none; }
    .ws-phase { padding: 4px 6px; }
    .ws-meta-row > span { min-width: 70px; font-size: 11.5px; }
    .ws-trans-wrap { grid-template-columns: 1fr; }
}

/* ══════════════════════════════════════════════════════════════════════
   NOTEBOOK LM — لیستِ نوت‌بوک‌ها + ورک‌اسپیسِ دوپنله با استناد (.nb-*)
   ══════════════════════════════════════════════════════════════════════ */

/* ── لیستِ نوت‌بوک‌ها ── */
.nb-intro-box {
    display: flex; align-items: flex-start; gap: 12px;
    background: linear-gradient(135deg, rgba(155,109,255,0.09), transparent 70%);
    border: 1px solid rgba(155,109,255,0.28); border-radius: 14px;
    padding: 15px 17px; margin: 0 0 18px;
}
.nb-intro-icon {
    font-size: 22px; line-height: 1; flex-shrink: 0;
    width: 42px; height: 42px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    background: rgba(155,109,255,0.16);
}
.nb-intro {
    margin: 0; font-size: 16px; line-height: 1.9;
    color: var(--text-primary); font-weight: 400;
}
.nb-intro b { color: var(--accent-light); font-weight: 700; }
@media (max-width: 680px){
    .nb-intro-box { gap: 10px; padding: 12px 13px; }
    .nb-intro-icon { width: 36px; height: 36px; font-size: 19px; }
    .nb-intro { font-size: 14px; line-height: 1.8; }
}
.nb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 14px;
}
.nb-card {
    position: relative;
    display: flex; flex-direction: column; gap: 6px;
    padding: 18px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 14px;
    text-decoration: none; color: var(--text);
    transition: border-color .15s, transform .12s, box-shadow .15s;
    min-height: 120px;
}
.nb-card:hover { border-color: var(--accent); transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.nb-card:active { transform: translateY(0) scale(.99); }
.nb-card-icon {
    width: 42px; height: 42px; border-radius: 12px; font-size: 22px;
    display: flex; align-items: center; justify-content: center;
    background: rgba(155,109,255,0.12);
}
.nb-card-title { font-weight: 600; font-size: 14.5px; line-height: 1.4;
    overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.nb-card-meta { font-size: 12px; color: var(--text-muted); margin-top: auto; }
.nb-card-del {
    position: absolute; top: 8px; inset-inline-end: 8px;
    width: 26px; height: 26px; border-radius: 7px;
    border: none; background: transparent; cursor: pointer;
    color: var(--text-muted); opacity: 0; transition: opacity .15s, background .15s;
}
.nb-card:hover .nb-card-del { opacity: 1; }
.nb-card-del:hover { background: rgba(248,113,113,.14); color: #f87171; }
.nb-card-new {
    align-items: center; justify-content: center; text-align: center;
    border-style: dashed; border-color: rgba(155,109,255,0.42);
    cursor: pointer; color: var(--accent-light);
    background: linear-gradient(135deg, rgba(155,109,255,0.06), transparent);
}
.nb-card-new:hover { color: var(--accent-light); border-color: var(--accent); }
.nb-card-new .nb-card-icon { background: rgba(155,109,255,0.16); }

.nb-list-wrap {
    background:
        radial-gradient(circle at 82% 4%, rgba(20,184,166,0.10), transparent 28%),
        radial-gradient(circle at 8% 18%, rgba(155,109,255,0.10), transparent 30%);
}
.nb-intro-box {
    position: relative;
    overflow: hidden;
    min-height: 132px;
    align-items: center;
    background:
        linear-gradient(135deg, rgba(20,184,166,0.14), rgba(155,109,255,0.12)),
        var(--bg-secondary);
    border-color: rgba(94,234,212,0.20);
    box-shadow: 0 18px 44px rgba(0,0,0,0.22);
}
.nb-intro-box::after {
    content: "";
    position: absolute;
    inset: auto -52px -74px auto;
    width: 190px;
    height: 190px;
    border-radius: 50%;
    border: 1px solid rgba(94,234,212,0.18);
}
.nb-intro-icon {
    background: rgba(20,184,166,0.16);
    color: #99f6e4;
    border: 1px solid rgba(94,234,212,0.16);
}
.nb-card {
    background: linear-gradient(180deg, rgba(255,255,255,0.035), rgba(255,255,255,0.012)), var(--bg-secondary);
    border-color: rgba(255,255,255,0.08);
    box-shadow: 0 12px 28px rgba(0,0,0,0.13);
}
.nb-card-icon {
    background: rgba(20,184,166,0.12);
    border: 1px solid rgba(94,234,212,0.10);
}

/* ── ورک‌اسپیس ── */
.nb-main { display: flex; flex-direction: column; min-height: 0; }
.nb-model-badge {
    font-size: 12px; color: var(--text-secondary);
    background: var(--bg-secondary); border: 1px solid var(--border);
    padding: 5px 10px; border-radius: 999px; white-space: nowrap;
}
.nb-workspace {
    flex: 1; min-height: 0;
    display: grid; grid-template-columns: 320px 1fr; gap: 0;
}

/* ── پنلِ منابع (چپ) ── */
.nb-sources {
    border-inline-end: 1px solid var(--border);
    display: flex; flex-direction: column; min-height: 0;
    background: var(--bg-primary);
}
.nb-sources-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px; font-weight: 600; font-size: 14px;
    border-bottom: 1px solid var(--border);
}
.nb-src-count {
    background: var(--accent); color: #fff; font-size: 11px;
    min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
    display: inline-flex; align-items: center; justify-content: center;
}
.nb-add-bar { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 14px 6px; }
.nb-add-btn {
    flex: 1 1 auto; min-width: 84px; padding: 8px 6px; font-size: 12.5px; cursor: pointer;
    border: 1px solid var(--border); border-radius: 9px;
    background: var(--bg-secondary); color: var(--text); white-space: nowrap;
}
.nb-add-btn:hover { border-color: var(--accent); color: var(--accent-light); }
.nb-add-panel { padding: 6px 14px 12px; display: flex; flex-direction: column; gap: 8px; }
.nb-add-panel[hidden] { display: none; }
.nb-input {
    width: 100%; padding: 9px 11px; font-size: 13px; font-family: inherit;
    border: 1px solid var(--border); border-radius: 9px;
    background: var(--bg-secondary); color: var(--text); resize: vertical;
}
.nb-input:focus { outline: none; border-color: var(--accent); }
.nb-add-actions { display: flex; gap: 8px; }
.nb-warn { margin: 4px 14px; padding: 8px 10px; font-size: 12px;
    color: var(--warning); background: rgba(245,158,11,.08);
    border: 1px solid var(--warning); border-radius: 8px; }
.nb-warn code { font-size: 11px; }

/* picker (پایگاه دانش / چت) */
.nb-pick-label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.nb-pick-list { display: flex; flex-direction: column; gap: 5px; max-height: 240px; overflow-y: auto; }
.nb-pick-empty { font-size: 12px; color: var(--text-muted); padding: 10px 4px; }
.nb-pick {
    display: flex; align-items: center; gap: 9px; width: 100%; text-align: start;
    padding: 9px 11px; cursor: pointer;
    border: 1px solid var(--border); border-radius: 9px;
    background: var(--bg-secondary); color: var(--text);
}
.nb-pick:hover { border-color: var(--accent); }
.nb-pick-ic { font-size: 16px; }
.nb-pick-main { min-width: 0; display: flex; flex-direction: column; }
.nb-pick-name { font-size: 13px; font-weight: 500; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap; }
.nb-pick-meta { font-size: 11px; color: var(--text-muted); }

.nb-src-list { flex: 1; overflow-y: auto; padding: 6px 10px 14px; }
.nb-src-empty { padding: 20px 14px; text-align: center; color: var(--text-muted); font-size: 12.5px; }
.nb-src {
    display: flex; align-items: flex-start; gap: 9px;
    padding: 10px; margin-bottom: 6px; border-radius: 10px;
    border: 1px solid var(--border); background: var(--bg-secondary);
}
.nb-src-ic { font-size: 18px; line-height: 1.2; }
.nb-src-main { flex: 1; min-width: 0; }
.nb-src-name { font-size: 13px; font-weight: 500; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap; }
.nb-src-meta { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.nb-src-meta.is-ready { color: #34d399; }
.nb-src-meta.is-proc { color: var(--accent-light); }
.nb-src-meta.is-error { color: #f87171; }
.nb-src-url { font-size: 11px; color: var(--text-muted); text-decoration: none;
    display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nb-src-url:hover { color: var(--accent-light); }
.nb-src-del { border: none; background: transparent; cursor: pointer;
    color: var(--text-muted); font-size: 18px; line-height: 1; padding: 0 2px; }
.nb-src-del:hover { color: #f87171; }

/* ── چت (راست) ── */
.nb-chat { display: flex; flex-direction: column; min-height: 0; }
.nb-thread { flex: 1; overflow-y: auto; padding: 22px clamp(12px, 5vw, 60px);
    display: flex; flex-direction: column; gap: 18px; }
.nb-hero { margin: auto; text-align: center; color: var(--text-muted); max-width: 420px; }
.nb-hero-icon { font-size: 44px; }
.nb-hero h3 { margin: 12px 0 6px; color: var(--text); font-size: 18px; }
.nb-hero p { font-size: 13.5px; line-height: 1.7; }
.nb-msg { display: flex; }
.nb-msg-user { justify-content: flex-end; }
.nb-msg-assistant { flex-direction: column; align-items: flex-start; }
.nb-bubble {
    max-width: 760px; padding: 12px 16px; border-radius: 14px;
    font-size: 14.5px; line-height: 1.85; word-wrap: break-word;
}
.nb-msg-user .nb-bubble { background: var(--accent); color: #fff;
    border-bottom-right-radius: 4px; max-width: 78%; }
.nb-msg-assistant .nb-bubble { background: var(--bg-secondary);
    border: 1px solid var(--border); color: var(--text);
    border-bottom-left-radius: 4px; }
.nb-cite {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 16px; height: 16px; padding: 0 4px; margin: 0 1px;
    font-size: 10.5px; font-weight: 700; vertical-align: super;
    background: rgba(99,102,241,.18); color: var(--accent-light);
    border-radius: 5px; cursor: pointer; user-select: none;
    border: 1px solid rgba(99,102,241,.30);
}
.nb-cite:hover { background: var(--accent); color: #fff; }
.nb-typing { color: var(--text-muted); font-size: 13px; }
.nb-err { color: #f87171; font-size: 13.5px; }
.nb-cited { margin-top: 8px; padding: 10px 14px; max-width: 760px;
    background: var(--bg-secondary); border: 1px dashed var(--border);
    border-radius: 12px; font-size: 12.5px; }
.nb-cited-h { color: var(--text-muted); margin-bottom: 6px; font-weight: 600; }
.nb-cited-item { padding: 2px 0; color: var(--text-secondary);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nb-composer {
    display: flex; gap: 10px; align-items: flex-end;
    padding: 12px clamp(12px, 5vw, 60px) 18px;
    border-top: 1px solid var(--border);
}
.nb-composer-input {
    flex: 1; resize: none; max-height: 160px;
    padding: 12px 16px; font-size: 14.5px; font-family: inherit;
    border: 1px solid var(--border); border-radius: 16px;
    background: var(--bg-secondary); color: var(--text); line-height: 1.6;
}
.nb-composer-input:focus { outline: none; border-color: var(--accent); }
.nb-send-btn {
    width: 44px; height: 44px; flex-shrink: 0; border: none; cursor: pointer;
    border-radius: 50%; background: var(--accent); color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
}
.nb-send-btn:hover { filter: brightness(1.08); }
.nb-send-btn:disabled { opacity: .5; cursor: default; }

/* ── citation popover ── */
.nb-cite-pop {
    position: absolute; z-index: 9999; max-width: 320px;
    background: var(--bg-secondary); border: 1px solid var(--border);
    border-radius: 12px; padding: 12px 14px; box-shadow: 0 12px 34px rgba(0,0,0,.4);
}
.nb-cite-pop[hidden] { display: none; }
.nb-cite-pop-head { font-size: 12.5px; color: var(--accent-light); margin-bottom: 6px; }
.nb-cite-pop-body { font-size: 12.5px; color: var(--text-secondary);
    line-height: 1.7; max-height: 200px; overflow-y: auto; white-space: pre-wrap; }

/* ── سوییچرِ تبِ موبایل (منابع/چت) — روی دسکتاپ مخفی ── */
.nb-mobile-tabs { display: none; gap: 6px; padding: 8px 12px;
    border-bottom: 1px solid var(--border); background: var(--bg-primary); flex-shrink: 0; }
.nb-mtab { flex: 1; padding: 9px 10px; border-radius: 10px;
    border: 1px solid var(--border); background: var(--bg-secondary);
    color: var(--text-secondary); font-family: inherit; font-size: 13.5px;
    cursor: pointer; transition: background .15s, color .15s, border-color .15s; }
.nb-mtab.active { background: rgba(155,109,255,0.16); color: var(--accent-light);
    border-color: rgba(155,109,255,0.5); font-weight: 600; }

/* ── موبایل (صفحهٔ جزئیات): تب‌بندیِ منابع/چت — هر پنل تمام‌قد، چت پیش‌فرض ── */
@media (max-width: 820px) {
    .nb-mobile-tabs { display: flex; }
    .nb-workspace { grid-template-columns: 1fr; grid-template-rows: 1fr; min-height: 0; }
    .nb-sources { border-inline-end: none; max-height: none; display: none; }
    .nb-chat { display: flex; }
    .nb-workspace.show-sources .nb-sources { display: flex; }
    .nb-workspace.show-sources .nb-chat { display: none; }
    .nb-bubble { max-width: 100%; }
    .nb-msg-user .nb-bubble { max-width: 88%; }
    .nb-composer-input { font-size: 16px; }   /* جلوگیری از zoom در iOS */
    /* نوارِ افزودنِ منبع: اسکرولِ افقی به‌جای شکستن به چند خط */
    .nb-add-bar { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .nb-add-btn { white-space: nowrap; flex-shrink: 0; }
}

/* ── موبایل (صفحهٔ لیست): هدرِ تمیز + کارت‌های فشرده‌تر ── */
@media (max-width: 680px) {
    .nb-list-wrap { padding: 14px 12px !important; }
    .nb-list-header .nb-subtitle { display: none; }
    .nb-new-btn { padding: 8px 12px; font-size: 17px; line-height: 1; }
    .nb-new-btn .nb-new-text { display: none; }
    .nb-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .nb-card { min-height: 92px; padding: 14px 12px; border-radius: 16px; }
    .nb-card-icon { width: 38px; height: 38px; font-size: 20px; }
    /* روی موبایل hover نیست → دکمهٔ حذف همیشه نیمه‌نمایان و قابلِ‌لمس */
    .nb-card .nb-card-del { opacity: .55; width: 30px; height: 30px; }
}


/* ══════════════════════════════════════════════════════════════════════
   MOBILE SCROLL FIX (همهٔ صفحات کاربر + ادمین) — ۲۰۲۶/۰۶
   صفحاتِ معمولی روی موبایل باید در سطحِ سند (body) اسکرول شوند. فقط صفحاتِ
   «چت‌مانند» (body.app-shell: chat/image/audio studio, psych, compare) پوستهٔ
   ثابتِ ۱۰۰vh با اسکرولِ داخلی را نگه می‌دارند تا کامپوزر سنجاق بماند.
   ══════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  body:not(.app-shell) {
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
      overscroll-behavior-y: none;
  }
  /* رهاکردنِ قفلِ ارتفاع/overflow روی کانتینرهای صفحه تا محتوا کلیپ نشود */
  body:not(.app-shell) .layout,
  body:not(.app-shell) .admin-layout {
      height: auto !important;
      min-height: 100dvh;
      overflow: visible !important;
  }
  body:not(.app-shell) .main,
  body:not(.app-shell) .admin-main {
      height: auto !important;
      min-height: 0 !important;
      overflow: visible !important;
  }
  /* فضای کافی در پایین تا نوارِ ناوبریِ پایینِ ثابت محتوا را نپوشاند */
  body:not(.app-shell) .main,
  body:not(.app-shell) .admin-main,
  body:not(.app-shell) .wallet-page,
  body:not(.app-shell) .profile-page,
  body:not(.app-shell) .lib-wrap {
      padding-bottom: calc(78px + env(safe-area-inset-bottom)) !important;
  }
  /* صفحاتِ app-shell: مطمئن شو خودِ body اسکرولِ سندی نگیرد (اسکرول داخلی است) */
  body.app-shell { overflow: hidden; }
}

/* ── ورود با گوگل + جداکنندهٔ «یا» (login/register) ── */
.auth-divider {
    display: flex; align-items: center; text-align: center;
    color: var(--text-muted, #888); font-size: 12.5px; margin: 18px 0 14px;
}
.auth-divider::before, .auth-divider::after {
    content: ""; flex: 1; height: 1px; background: var(--border, #333);
}
.auth-divider span { padding: 0 12px; }
.btn-google {
    display: flex; align-items: center; justify-content: center; gap: 10px;
    width: 100%; padding: 11px 14px; border-radius: 12px;
    background: #fff; color: #1f1f1f; font-family: inherit; font-size: 14px; font-weight: 600;
    border: 1px solid rgba(0,0,0,0.12); cursor: pointer; text-decoration: none;
    transition: box-shadow .15s, transform .05s;
}
.btn-google:hover { box-shadow: 0 2px 10px rgba(0,0,0,0.18); }
.btn-google:active { transform: translateY(1px); }
.btn-google svg { flex: 0 0 auto; }

/* ==========================================================================
   Mobile UX refresh for chat-like screens
   Goal: calmer attention, larger touch targets, less bottom clutter.
   ========================================================================== */
@media (max-width: 768px) {
    :root {
        --mobile-nav-h: 58px;
        --mobile-header-h: 54px;
        --mobile-sheet-radius: 22px;
    }

    html {
        scroll-padding-bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom));
    }

    body.app-shell {
        background: var(--bg-primary);
        touch-action: manipulation;
    }

    body.app-shell .layout,
    body.app-shell .main {
        height: 100dvh !important;
        min-height: 100dvh;
    }

    body.app-shell .main {
        padding-bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom)) !important;
        background:
            linear-gradient(180deg, rgba(255,255,255,0.025), rgba(255,255,255,0) 96px),
            var(--bg-primary);
    }

    body.app-shell .main-header {
        height: calc(var(--mobile-header-h) + env(safe-area-inset-top)) !important;
        min-height: calc(var(--mobile-header-h) + env(safe-area-inset-top)) !important;
        padding: env(safe-area-inset-top) 8px 6px !important;
        gap: 4px !important;
        border-bottom: 1px solid rgba(255,255,255,0.06);
        background: color-mix(in srgb, var(--bg-primary) 88%, transparent) !important;
        backdrop-filter: blur(18px);
        -webkit-backdrop-filter: blur(18px);
    }

    body.app-shell .main-header .btn-icon {
        width: 38px !important;
        height: 38px !important;
        border-radius: 13px !important;
        color: var(--text-secondary);
    }

    body.app-shell .main-header .btn-icon:active,
    body.app-shell .mobile-nav-item:active,
    body.app-shell .composer-plus-btn:active,
    body.app-shell .composer-icon-btn:active,
    body.app-shell .btn-send:active {
        transform: scale(0.96);
    }

    body.app-shell .header-left {
        flex: 0 0 auto;
        min-width: 0;
        justify-content: flex-start;
        gap: 3px;
        overflow: visible;
    }

    body.app-shell .header-right {
        flex: 1 1 0;
        min-width: 0;
        gap: 3px;
    }

    body.app-shell .header-left > .wallet-pill {
        display: inline-flex !important;
        flex: 0 1 auto;
        max-width: 98px;
        height: 34px;
        min-height: 34px;
        padding: 0 8px !important;
        gap: 4px;
        border-radius: 16px !important;
        font-size: 12px !important;
        white-space: nowrap;
    }

    body.app-shell .header-left .wallet-pill svg {
        width: 13px;
        height: 13px;
        flex: 0 0 auto;
    }

    body.app-shell .header-left .wallet-pill span {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        direction: ltr;
    }

    body.app-shell .header-left .wallet-pill small {
        font-size: 10px;
        margin-right: 0;
    }

    body.app-shell .header-left .notif-wrap {
        display: inline-flex !important;
        flex: 0 0 auto;
    }

    body.app-shell .header-left .header-avatar {
        display: inline-flex !important;
        flex: 0 0 auto;
        width: 32px !important;
        height: 32px !important;
        font-size: 13px !important;
    }

    body.app-shell .lang-switcher-inline > summary {
        width: 34px !important;
        height: 34px !important;
        padding: 0 !important;
        justify-content: center;
        border-radius: 14px !important;
        background: transparent;
    }

    body.app-shell .lang-switcher-inline > summary span {
        display: none;
    }

    body.app-shell .lang-switcher-inline > summary svg {
        width: 19px;
        height: 19px;
    }

    body.app-shell .notif-wrap .btn-icon {
        width: 34px !important;
        height: 34px !important;
        border-radius: 14px !important;
    }

    body.app-shell .notif-badge {
        min-width: 16px;
        height: 16px;
        padding: 0 4px;
        font-size: 10px;
        line-height: 16px;
        top: -3px;
        right: -3px;
    }

    body.app-shell .btn-new-chat {
        width: 38px !important;
        height: 38px !important;
        padding: 0 !important;
        border-radius: 13px !important;
        background: var(--bg-secondary) !important;
        color: var(--text-secondary) !important;
        border: 1px solid rgba(255,255,255,0.08);
        box-shadow: none !important;
    }

    body.app-shell .btn-new-chat:hover,
    body.app-shell .btn-new-chat:active {
        filter: none !important;
        color: var(--text-primary) !important;
        background: var(--bg-hover) !important;
    }

    body.app-shell .btn-new-chat-label {
        display: none !important;
    }

    body.app-shell .model-picker {
        flex: 1 1 auto;
        min-width: 0;
        max-width: none !important;
    }

    body.app-shell .model-picker-btn {
        width: 100%;
        min-height: 38px;
        border-radius: 999px !important;
        padding: 7px 8px !important;
        background: var(--bg-secondary) !important;
        border-color: rgba(255,255,255,0.08) !important;
        box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
    }

    body.app-shell .model-picker-btn span#currentModelName,
    body.app-shell .model-picker-btn span#imgCurrentModelName {
        max-width: min(22vw, 94px) !important;
        font-size: 13px;
    }

    body.app-shell .chat-area {
        padding: 10px 0 0 !important;
        scroll-padding-bottom: 128px;
        overscroll-behavior: contain;
    }

    body.app-shell .message-list {
        width: 100%;
        max-width: 100%;
        gap: 18px !important;
        padding: 8px 14px 18px !important;
    }

    body.app-shell .empty-chat {
        min-height: 58dvh;
        align-items: flex-start;
        padding-top: 13dvh;
    }

    body.app-shell .empty-chat-content {
        padding: 18px 18px 0;
    }

    body.app-shell .empty-chat-icon {
        margin-bottom: 14px;
        opacity: .72;
        transform: scale(.9);
    }

    body.app-shell .empty-chat h2 {
        font-size: 24px;
        line-height: 1.35;
        margin-bottom: 6px;
    }

    body.app-shell .empty-chat p {
        font-size: 14px;
        line-height: 1.8;
        color: var(--text-muted);
    }

    body.app-shell .empty-quality-block {
        width: min(100%, 340px);
        margin: 20px auto 0 !important;
        padding: 0 !important;
        border: 0 !important;
        border-radius: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
    }

    body.app-shell .empty-quality-head {
        display: none !important;
    }

    body.app-shell .empty-quality-row {
        display: grid !important;
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        gap: 6px !important;
        padding: 4px;
        border-radius: 18px;
        background: rgba(255,255,255,0.045);
        border: 1px solid rgba(255,255,255,0.07);
    }

    body.app-shell .eq-card {
        min-height: 42px;
        padding: 8px 4px !important;
        gap: 3px !important;
        border: 0 !important;
        border-radius: 14px !important;
        background: transparent !important;
        box-shadow: none !important;
        transform: none !important;
        text-align: center !important;
    }

    body.app-shell .eq-card.selected {
        background: rgba(155,109,255,0.22) !important;
        color: var(--text-primary);
    }

    body.app-shell .eq-card-emoji {
        display: none !important;
    }

    body.app-shell .eq-card-title {
        font-size: 12px !important;
        line-height: 1.3;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    body.app-shell .eq-card-desc {
        display: none !important;
    }

    body.app-shell .msg {
        animation-duration: .18s;
    }

    body.app-shell .msg-user {
        max-width: 86% !important;
    }

    body.app-shell .msg-user .msg-bubble {
        padding: 10px 14px !important;
        border-radius: 19px 19px 7px 19px !important;
        font-size: 15px;
        line-height: 1.75;
        background: color-mix(in srgb, var(--bg-user-msg) 88%, var(--accent) 12%);
        box-shadow: 0 6px 18px rgba(0,0,0,0.12);
    }

    body.app-shell .msg-assistant {
        max-width: 100% !important;
        padding: 0 2px !important;
    }

    body.app-shell .msg-assistant .msg-content {
        font-size: 15px;
        line-height: 1.85;
        letter-spacing: 0;
    }

    body.app-shell .msg-actions,
    body.app-shell .msg-user .msg-actions,
    body.app-shell .msg-assistant .msg-actions {
        opacity: .78;
        gap: 6px !important;
    }

    body.app-shell .msg-action-btn {
        width: 36px !important;
        height: 36px !important;
        border-radius: 12px !important;
    }

    body.app-shell .msg-content pre,
    body.app-shell .msg-bubble pre,
    body.app-shell .code-block-wrap pre {
        border-radius: 14px;
        max-width: calc(100vw - 28px);
    }

    body.app-shell .composer-wrap {
        position: sticky;
        bottom: 0;
        z-index: 70;
        padding: 6px 10px 8px !important;
        background:
            linear-gradient(180deg, rgba(10,10,10,0), var(--bg-primary) 18px),
            var(--bg-primary);
    }

    body.app-shell .selected-tools,
    body.app-shell .kn-attach-chips,
    body.app-shell .attachment-previews {
        max-width: 100%;
        flex-wrap: nowrap;
        overflow-x: auto;
        overscroll-behavior-x: contain;
        scrollbar-width: none;
        padding-inline: 2px;
    }

    body.app-shell .selected-tools::-webkit-scrollbar,
    body.app-shell .kn-attach-chips::-webkit-scrollbar,
    body.app-shell .attachment-previews::-webkit-scrollbar {
        display: none;
    }

    body.app-shell .composer {
        max-width: 100%;
        min-height: 50px;
        border-radius: 24px !important;
        padding: 6px !important;
        align-items: flex-end;
        gap: 4px;
        background: color-mix(in srgb, var(--bg-input) 90%, white 4%);
        border-color: rgba(255,255,255,0.09);
        box-shadow: 0 10px 34px rgba(0,0,0,0.26);
    }

    body.app-shell .composer:focus-within {
        border-color: color-mix(in srgb, var(--accent) 48%, transparent);
        box-shadow: 0 12px 36px rgba(0,0,0,0.32), 0 0 0 3px rgba(155,109,255,0.10);
    }

    body.app-shell .composer-plus-wrap {
        flex: 0 0 auto;
    }

    body.app-shell .composer-plus-btn,
    body.app-shell .composer-icon-btn,
    body.app-shell .btn-send {
        width: 40px !important;
        height: 40px !important;
        min-width: 40px;
        border-radius: 15px !important;
    }

    body.app-shell #knBtn,
    body.app-shell #personaBtn {
        display: none !important;
    }

    body.app-shell .composer-plus-btn,
    body.app-shell .composer-icon-btn {
        border: 0;
        background: transparent;
        color: var(--text-muted);
    }

    body.app-shell .composer-plus-btn.active,
    body.app-shell .composer-plus-btn:hover,
    body.app-shell .composer-icon-btn:hover {
        background: rgba(255,255,255,0.07);
        color: var(--text-primary);
    }

    body.app-shell .btn-send {
        background: var(--accent);
        color: #fff;
        box-shadow: 0 8px 20px rgba(155,109,255,0.28);
    }

    body.app-shell .btn-send:disabled {
        background: var(--bg-tertiary);
        color: var(--text-muted);
        box-shadow: none;
    }

    body.app-shell .composer-input {
        min-width: 0;
        min-height: 38px !important;
        max-height: 132px !important;
        padding: 8px 6px !important;
        font-size: 16px !important;
        line-height: 1.55;
    }

    body.app-shell .composer-input::placeholder {
        color: color-mix(in srgb, var(--text-muted) 82%, white 8%);
    }

    body.app-shell .input-disclaimer {
        display: none;
    }

    body.app-shell:has(.composer-input:focus) .main {
        padding-bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom)) !important;
    }

    body.app-shell:has(.composer-input:focus) .usage-meter:not(.open),
    body.app-shell:has(.composer-input:focus) .scroll-bottom-btn {
        opacity: 0;
        pointer-events: none;
    }

    .mobile-bottom-nav {
        height: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom)) !important;
        padding: 5px 8px max(5px, env(safe-area-inset-bottom)) !important;
        gap: 4px;
        background: color-mix(in srgb, var(--bg-primary) 86%, transparent) !important;
        border-top: 1px solid rgba(255,255,255,0.08) !important;
        box-shadow: 0 -10px 30px rgba(0,0,0,0.26) !important;
        transform: translateY(0) !important;
        pointer-events: auto !important;
        visibility: visible !important;
        opacity: 1 !important;
        transition: none;
    }

    .mobile-nav-item {
        min-width: 0;
        min-height: 46px;
        border-radius: 16px;
        gap: 2px !important;
        padding: 5px 3px !important;
        color: var(--text-muted) !important;
    }

    .mobile-nav-item svg {
        width: 21px !important;
        height: 21px !important;
    }

    .mobile-nav-item span {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 10px;
        line-height: 1.2;
    }

    .mobile-nav-item.active {
        background: rgba(155,109,255,0.12);
        color: var(--accent-light) !important;
    }

    .mobile-nav-item.active::before {
        display: none;
    }

    .mobile-nav-item.active svg {
        transform: none !important;
    }

    body.app-shell .tool-menu,
    body.app-shell .tool-submenu,
    body.app-shell .kn-menu,
    body.app-shell .model-mobile-dropdown {
        position: fixed !important;
        inset-inline: 0 !important;
        inset-block-start: auto !important;
        inset-block-end: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom)) !important;
        top: auto !important;
        bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom)) !important;
        left: 0 !important;
        right: 0 !important;
        width: auto !important;
        min-width: 0 !important;
        max-width: none !important;
        max-height: min(72dvh, 560px) !important;
        border-radius: var(--mobile-sheet-radius) var(--mobile-sheet-radius) 0 0 !important;
        padding: 22px 14px calc(16px + env(safe-area-inset-bottom)) !important;
        background: color-mix(in srgb, var(--bg-menu) 94%, white 3%) !important;
        border: 1px solid rgba(255,255,255,0.08) !important;
        border-bottom: 0 !important;
        box-shadow: 0 -18px 48px rgba(0,0,0,0.42) !important;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        z-index: 820 !important;
        transform: translateY(110%);
        opacity: 0;
        visibility: hidden;
        transition: transform .24s cubic-bezier(.22,.9,.24,1), opacity .2s, visibility .2s;
    }

    body.app-shell .model-mobile-dropdown {
        margin: 0 !important;
    }

    body.app-shell:has(.composer-input:focus) .tool-menu,
    body.app-shell:has(.composer-input:focus) .tool-submenu,
    body.app-shell:has(.composer-input:focus) .kn-menu,
    body.app-shell:has(.composer-input:focus) .model-mobile-dropdown {
        bottom: env(safe-area-inset-bottom) !important;
    }

    body.app-shell .tool-menu.show,
    body.app-shell .tool-submenu.show,
    body.app-shell .kn-menu.show,
    body.app-shell .model-mobile-dropdown.show {
        transform: none !important;
        opacity: 1;
        visibility: visible;
        display: flex !important;
        flex-direction: column;
    }

    body.app-shell .tool-menu::before,
    body.app-shell .tool-submenu::before,
    body.app-shell .kn-menu::before,
    body.app-shell .model-mobile-dropdown::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        width: 42px;
        height: 4px;
        border-radius: 999px;
        background: rgba(255,255,255,0.22);
        transform: translateX(-50%);
    }

    body.app-shell .tool-item,
    body.app-shell .kn-menu-item,
    body.app-shell .model-mobile-item {
        min-height: 48px;
        padding: 12px 12px !important;
        border-radius: 15px !important;
        font-size: 14px;
    }

    body.app-shell .tool-mobile-quick {
        display: grid !important;
        grid-template-columns: 24px minmax(0, 1fr) auto;
        column-gap: 12px;
        align-items: center;
        background: rgba(255,255,255,0.045);
        border: 1px solid rgba(255,255,255,0.055);
        margin-bottom: 6px;
    }

    body.app-shell .tool-mobile-quick .tool-item-label {
        font-weight: 700;
        color: var(--text-primary);
    }

    body.app-shell .tool-item-hint {
        font-size: 11.5px;
        color: var(--text-muted);
        white-space: nowrap;
    }

    body.app-shell .persona-menu-title {
        padding: 2px 4px 12px !important;
        font-size: 13px !important;
        color: var(--text-secondary) !important;
        text-align: right;
    }

    body.app-shell .persona-menu-item {
        width: 100%;
        border: 0;
        cursor: pointer;
        text-align: right;
        grid-template-columns: 34px minmax(0, 1fr) auto;
        display: grid !important;
        background: rgba(255,255,255,0.035);
        margin-bottom: 7px;
        font-family: inherit;
    }

    body.app-shell .persona-menu-item:hover,
    body.app-shell .persona-menu-item:focus {
        background: rgba(155,109,255,0.14);
        outline: none;
    }

    body.app-shell .persona-emoji {
        width: 30px;
        height: 30px;
        border-radius: 10px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background: rgba(155,109,255,0.12);
        font-size: 16px;
    }

    body.app-shell .persona-menu-item .kn-menu-name {
        font-size: 14.5px !important;
        line-height: 1.5;
        color: var(--text-primary);
        font-weight: 650;
    }

    body.app-shell .persona-menu-item .kn-menu-meta {
        align-self: center;
        font-size: 11px !important;
        color: var(--text-muted);
        background: rgba(255,255,255,0.055);
        border-radius: 999px;
        padding: 3px 8px;
    }

    body.app-shell .persona-custom-link {
        border: 0 !important;
        background: rgba(155,109,255,0.10) !important;
        border-radius: 14px;
        margin-top: 8px;
        width: 100%;
        cursor: pointer;
        font-family: inherit;
        font-weight: 700;
    }

    body.app-shell .persona-custom-form {
        padding: 4px;
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    body.app-shell .persona-custom-input {
        width: 100%;
        padding: 11px 12px;
        border: 1px solid rgba(255,255,255,0.10);
        border-radius: 12px;
        background: var(--bg-secondary);
        color: var(--text-primary);
        font: inherit;
        font-size: 16px;
    }

    body.app-shell .persona-custom-textarea {
        min-height: 120px;
        resize: vertical;
        line-height: 1.7;
    }

    body.app-shell .model-mobile-name,
    body.app-shell .kn-menu-name,
    body.app-shell .tool-item-label {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    body.app-shell .model-picker {
        position: relative;
    }

    body.app-shell .model-mobile-dropdown {
        position: absolute !important;
        top: calc(100% + 10px) !important;
        bottom: auto !important;
        left: 50% !important;
        right: auto !important;
        width: min(286px, calc(100vw - 20px)) !important;
        max-height: min(70dvh, 560px) !important;
        border-radius: 20px !important;
        padding: 14px 10px !important;
        transform: translateX(-50%) translateY(8px) !important;
        box-shadow: 0 18px 46px rgba(0,0,0,0.42) !important;
    }

    body.app-shell .model-mobile-dropdown.show {
        transform: translateX(-50%) translateY(0) !important;
    }

    body.app-shell .model-mobile-dropdown::before {
        display: none;
    }

    body.app-shell .notif-panel {
        left: 10px !important;
        right: 10px !important;
        top: calc(var(--mobile-header-h) + env(safe-area-inset-top) + 8px) !important;
        bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom) + 10px) !important;
        max-height: none !important;
        border-radius: 20px !important;
    }

    body.app-shell .usage-meter {
        left: 10px !important;
        right: 10px !important;
        bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom) + 8px) !important;
        width: auto !important;
        border-radius: 18px !important;
    }

    body.app-shell .scroll-bottom-btn {
        bottom: calc(var(--mobile-nav-h) + 84px + env(safe-area-inset-bottom)) !important;
        width: 40px !important;
        height: 40px !important;
        border-radius: 14px !important;
    }
}

@media (max-width: 380px) {
    body.app-shell .main-header {
        padding-left: 6px !important;
        padding-right: 6px !important;
        gap: 3px !important;
    }

    body.app-shell .main-header .btn-icon,
    body.app-shell .btn-new-chat {
        width: 36px !important;
        height: 36px !important;
    }

    body.app-shell .model-picker {
        min-width: 46px;
        max-width: none !important;
    }

    body.app-shell .model-picker-btn {
        justify-content: center;
        padding: 7px 6px !important;
    }

    body.app-shell .model-picker-btn span#currentModelName,
    body.app-shell .model-picker-btn span#imgCurrentModelName {
        display: none;
    }

    body.app-shell .header-left {
        gap: 2px;
    }

    body.app-shell .header-left > .wallet-pill {
        max-width: 86px;
        padding: 0 7px !important;
    }

    body.app-shell .header-left .wallet-pill svg {
        display: none;
    }

    body.app-shell .composer-plus-btn,
    body.app-shell .composer-icon-btn,
    body.app-shell .btn-send {
        width: 38px !important;
        height: 38px !important;
        min-width: 38px;
    }

    body.app-shell .composer {
        gap: 2px;
        padding: 5px !important;
    }

    .mobile-nav-item span {
        font-size: 9.5px;
    }
}

/* Final mobile scroll contract.
   Regular pages scroll on the document; app-shell pages keep their fixed chat-like shell. */
@media (max-width: 768px) {
    :root {
        --mobile-nav-h: 60px;
    }

    html {
        height: auto !important;
        min-height: 100%;
        overflow-x: hidden !important;
        overflow-y: auto !important;
    }

    body:not(.app-shell),
    body:not(.app-shell).pwa-standalone,
    body:not(.app-shell).pwa-standalone.is-mobile {
        position: static !important;
        height: auto !important;
        min-height: 100dvh !important;
        max-height: none !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        overscroll-behavior-y: contain;
        touch-action: pan-y;
        -webkit-overflow-scrolling: touch;
    }

    body:not(.app-shell) .layout,
    body:not(.app-shell) .main,
    body:not(.app-shell) .admin-layout,
    body:not(.app-shell) .admin-main {
        height: auto !important;
        max-height: none !important;
        min-height: 0 !important;
        overflow: visible !important;
    }

    body:not(.app-shell) .layout,
    body:not(.app-shell) .admin-layout {
        min-height: 100dvh !important;
    }

    body:not(.app-shell) .chat-area,
    body:not(.app-shell) .models-page,
    body:not(.app-shell) .tools-scroll,
    body:not(.app-shell) .ub-scroll,
    body:not(.app-shell) .nb-list-wrap,
    body:not(.app-shell) .tool-page-main,
    body:not(.app-shell) .rdr-reader,
    body:not(.app-shell) .nb-thread,
    body:not(.app-shell) .nb-src-list,
    body:not(.app-shell) .main > [style*="overflow-y:auto"],
    body:not(.app-shell) .main > [style*="overflow-y: auto"] {
        max-height: none !important;
        overflow-y: visible !important;
    }

    body:not(.app-shell) .rdr-body,
    body:not(.app-shell) .nb-workspace {
        min-height: auto !important;
        overflow: visible !important;
    }

    body:not(.app-shell) .wallet-page,
    body:not(.app-shell) .profile-page,
    body:not(.app-shell) .lib-wrap,
    body:not(.app-shell) .chat-area,
    body:not(.app-shell) main,
    body:not(.app-shell) .admin-main,
    body:not(.app-shell) .tools-scroll,
    body:not(.app-shell) .ub-scroll,
    body:not(.app-shell) .nb-list-wrap,
    body:not(.app-shell) .tool-run-wrap,
    body:not(.app-shell) .rdr-reader,
    body:not(.app-shell) .nb-thread,
    body:not(.app-shell) .nb-src-list,
    body:not(.app-shell) .main > [style*="overflow-y:auto"],
    body:not(.app-shell) .main > [style*="overflow-y: auto"] {
        padding-bottom: calc(var(--mobile-nav-h) + 28px + env(safe-area-inset-bottom)) !important;
    }

    body.app-shell,
    body.app-shell.pwa-standalone,
    body.app-shell.pwa-standalone.is-mobile {
        height: 100dvh !important;
        min-height: 100dvh !important;
        overflow: hidden !important;
    }

    .mobile-bottom-nav {
        height: var(--mobile-nav-h);
        transform: translateY(0) !important;
        opacity: 1 !important;
        pointer-events: auto !important;
    }
}

/* Final override: mobile app pages must accept finger scrolling. */
@media (max-width: 768px) {
    body.app-shell .main {
        overflow-y: auto !important;
        overflow-x: hidden !important;
        touch-action: pan-y !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior-y: contain;
    }

    body.app-shell .chat-area,
    body.app-shell .img-canvas,
    body.app-shell .img-main,
    body.app-shell .nb-main,
    body.app-shell .nb-thread,
    body.app-shell .nb-src-list,
    body.app-shell .tool-page-main,
    body.app-shell .tools-scroll {
        overflow-y: auto !important;
        touch-action: pan-y !important;
        -webkit-overflow-scrolling: touch !important;
    }

    html[dir="ltr"] .sidebar {
        left: 0 !important;
        right: auto !important;
        transform: translateX(-104%) !important;
    }

    html[dir="rtl"] .sidebar {
        right: 0 !important;
        left: auto !important;
        transform: translateX(104%) !important;
    }

    html[dir="ltr"] .sidebar.open,
    html[dir="ltr"] body.sidebar-open .sidebar,
    html[dir="rtl"] .sidebar.open,
    html[dir="rtl"] body.sidebar-open .sidebar {
        transform: translateX(0) !important;
    }

    html[dir="ltr"] .sidebar.collapsed,
    html[dir="rtl"] .sidebar.collapsed {
        margin: 0 !important;
    }
}

/* Mobile scroll hardening for regular pages.
   Some user/admin pages use body scrolling, some keep an inner scroll area.
   These final rules make both patterns finger-scrollable and leave chat-like
   app-shell pages on their own fixed viewport contract. */
@media (max-width: 768px) {
    html,
    body:not(.app-shell) {
        height: auto !important;
        min-height: 100% !important;
        max-height: none !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        touch-action: pan-y !important;
        -webkit-overflow-scrolling: touch !important;
    }

    body:not(.app-shell) .layout,
    body:not(.app-shell) .main,
    body:not(.app-shell) .admin-layout,
    body:not(.app-shell) .admin-main,
    body:not(.app-shell) .chat-area,
    body:not(.app-shell) .tools-scroll,
    body:not(.app-shell) .tool-page-main,
    body:not(.app-shell) .ub-scroll,
    body:not(.app-shell) .wallet-page,
    body:not(.app-shell) .profile-page,
    body:not(.app-shell) .lib-wrap,
    body:not(.app-shell) .nb-list-wrap,
    body:not(.app-shell) .knowledge-shell {
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow-y: visible !important;
        touch-action: pan-y !important;
        -webkit-overflow-scrolling: touch !important;
    }

    body:not(.app-shell) .layout,
    body:not(.app-shell) .admin-layout {
        min-height: 100dvh !important;
        align-items: stretch;
    }

    body:not(.app-shell) .main,
    body:not(.app-shell) .admin-main,
    body:not(.app-shell) .wallet-page,
    body:not(.app-shell) .profile-page,
    body:not(.app-shell) .tools-scroll,
    body:not(.app-shell) .tool-run-wrap,
    body:not(.app-shell) .lib-wrap,
    body:not(.app-shell) .nb-list-wrap,
    body:not(.app-shell) .knowledge-shell {
        padding-bottom: calc(92px + env(safe-area-inset-bottom)) !important;
    }

    body:not(.app-shell).sidebar-open,
    body:not(.app-shell).admin-sidebar-open {
        overflow: hidden !important;
    }
}

/* Final mobile scroll guard for non-chat pages.
   Wallet, profile, tools, library and admin pages are not app-shell routes, but
   many of them still use the same flex layout. Keep those layouts viewport-bound
   and make their inner content panes finger-scrollable so mobile browsers do not
   end up with a locked body and no scroll target. */
@media (max-width: 768px) {
    body:not(.app-shell):not(.auth-page) {
        height: auto !important;
        min-height: 100dvh !important;
        max-height: none !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        touch-action: pan-y !important;
        -webkit-overflow-scrolling: touch !important;
    }

    body:not(.app-shell) > .layout,
    body:not(.app-shell) > .admin-layout {
        height: 100dvh !important;
        min-height: 100dvh !important;
        max-height: 100dvh !important;
        overflow: hidden !important;
    }

    body:not(.app-shell) .main,
    body:not(.app-shell) .admin-main {
        min-height: 0 !important;
        height: auto !important;
        max-height: none !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        touch-action: pan-y !important;
        -webkit-overflow-scrolling: touch !important;
    }

    body:not(.app-shell) .chat-area,
    body:not(.app-shell) .tools-scroll,
    body:not(.app-shell) .tool-page-main,
    body:not(.app-shell) .tool-run-wrap,
    body:not(.app-shell) .wallet-page,
    body:not(.app-shell) .profile-page,
    body:not(.app-shell) .lib-wrap,
    body:not(.app-shell) .nb-main,
    body:not(.app-shell) .nb-list-wrap,
    body:not(.app-shell) .knowledge-shell,
    body:not(.app-shell) .ub-scroll {
        min-height: 0 !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        overscroll-behavior-y: contain;
        touch-action: pan-y !important;
        -webkit-overflow-scrolling: touch !important;
        padding-bottom: calc(96px + env(safe-area-inset-bottom)) !important;
    }

    body:not(.app-shell):not(.sidebar-open):not(.admin-sidebar-open) {
        overflow-y: auto !important;
    }
}

/* Last-wins repairs for pages reported as locked on physical mobile devices. */
@media (max-width: 768px) {
    body:not(.app-shell):has(.wallet-page) > .layout,
    body:not(.app-shell):has(.profile-page) > .layout {
        height: auto !important; min-height: 100dvh !important;
        max-height: none !important; overflow: visible !important;
    }
    body:not(.app-shell):has(.wallet-page) .main,
    body:not(.app-shell):has(.profile-page) .main,
    body:not(.app-shell):has(.wallet-page) .chat-area,
    body:not(.app-shell):has(.profile-page) .chat-area {
        height: auto !important; max-height: none !important;
        overflow: visible !important; touch-action: pan-y pinch-zoom !important;
    }
    body:not(.app-shell):has(.wallet-page), body:not(.app-shell):has(.profile-page) {
        padding-bottom: calc(78px + env(safe-area-inset-bottom)); overscroll-behavior-y: auto !important;
    }
    .notif-panel, body.app-shell .notif-panel {
        top: calc(56px + env(safe-area-inset-top) + 6px) !important;
        bottom: calc(68px + env(safe-area-inset-bottom) + 6px) !important;
        height: calc(100vh - 140px) !important;
        height: calc(100dvh - 140px) !important;
        max-height: none !important; min-height: 0 !important;
    }
    .notif-panel-body { min-height: 0; overflow-y: auto !important; }
    .notif-item { padding: 14px 16px; }
    .notif-body { display:block; white-space:normal; line-height:1.7; }
    body.app-shell .tool-menu.show, body.app-shell .tool-submenu.show,
    body.app-shell .kn-menu#personaMenu.show {
        left:10px !important; right:10px !important; width:auto !important; max-width:none !important;
        bottom:calc(68px + env(safe-area-inset-bottom)) !important;
        max-height:min(68dvh, 560px) !important; overflow-y:auto !important;
        border-radius:20px !important; padding:12px !important; z-index:1200 !important;
    }
    body.app-shell .kn-menu#personaMenu .persona-menu-item {
        min-height:58px; border:1px solid rgba(255,255,255,.07); border-radius:14px;
        margin:5px 0; padding:10px 12px; background:rgba(255,255,255,.025);
    }
    body.app-shell .kn-menu#personaMenu .persona-custom-link {
        display:block; width:100%; margin-top:8px; padding:12px; border-radius:12px;
        text-align:center; background:rgba(155,109,255,.13); border:1px dashed rgba(180,141,255,.55);
    }
}

.img-prompt-review { width:min(620px, calc(100vw - 28px)); border:1px solid rgba(167,139,250,.38); border-radius:20px; padding:0; color:var(--text-primary); background:var(--bg-secondary); box-shadow:0 22px 70px rgba(0,0,0,.58); }
.img-prompt-review::backdrop { background:rgba(0,0,0,.62); backdrop-filter:blur(3px); }
.img-prompt-review-card { padding:20px; }
.img-prompt-review-head { display:flex; align-items:center; justify-content:space-between; font-weight:800; font-size:16px; }
.img-prompt-review-head button { border:0; background:transparent; color:var(--text-muted); font-size:24px; cursor:pointer; }
.img-prompt-review p { color:var(--text-secondary); font-size:13px; line-height:1.8; }
.img-prompt-review textarea { width:100%; box-sizing:border-box; resize:vertical; min-height:130px; border-radius:14px; padding:12px; color:var(--text-primary); background:var(--bg-primary); border:1px solid var(--border); font:inherit; line-height:1.8; direction:auto; }
.img-prompt-review-actions { display:flex; justify-content:flex-end; gap:9px; margin-top:14px; }
.quality-model-suggestions { margin-top:16px; min-height:0; }
.quality-model-suggestions[hidden] { display:none; }
.quality-model-suggestions-head { display:flex; align-items:center; justify-content:space-between; gap:10px; color:var(--text-secondary); font-size:12.5px; margin-bottom:9px; }
.quality-model-suggestion-list { display:flex; gap:9px; overflow-x:auto; padding:2px 1px 8px; scroll-snap-type:x proximity; }
.quality-model-suggestion { min-width:150px; scroll-snap-align:start; text-align:right; color:var(--text-primary); font:inherit; cursor:pointer; padding:12px; border-radius:14px; border:1px solid rgba(155,109,255,.30); background:linear-gradient(135deg,rgba(155,109,255,.16),rgba(20,184,166,.07)); transition:transform .18s,border-color .18s; }
.quality-model-suggestion:hover { transform:translateY(-2px); border-color:var(--accent-light); }
.quality-model-suggestion strong,.quality-model-suggestion small { display:block; }
.quality-model-suggestion small { margin-top:4px; color:var(--text-muted); font-size:11px; }

/* FINAL OVERRIDES — keep at EOF so legacy duplicated rules cannot win. */
/* Unified ink and icon colors for light-mode conversation content. */
html[data-theme="light"] .msg,
html[data-theme="light"] .msg-text,
html[data-theme="light"] .msg-content { color:#2c3933; }
html[data-theme="light"] .msg-user .msg-bubble {
    color:#26342e; background:#dbe5e0; border:1px solid #cbd7d1;
    box-shadow:0 4px 14px rgba(50,70,60,.045);
}
html[data-theme="light"] .msg-assistant .msg-content { color:#2b3732; }
html[data-theme="light"] .msg-actions { opacity:.76; }
html[data-theme="light"] .msg-action-btn { color:#66756d !important; background:transparent; }
html[data-theme="light"] .msg-action-btn svg { color:inherit; stroke:currentColor; }
html[data-theme="light"] .msg-action-btn:hover,
html[data-theme="light"] .msg-action-btn:focus-visible {
    color:#45496f !important; background:#dbe1df; outline:none;
}
html[data-theme="light"] .msg-action-btn.active,
html[data-theme="light"] .msg-action-btn.playing {
    color:#5f5e8b !important; background:rgba(102,101,143,.11);
}
html[data-theme="light"] .msg-usage-bar {
    color:#68766f; background:#dfe5e2; border-color:#c8d2cd;
}
html[data-theme="light"] .msg-usage-bar svg { color:#76847d; opacity:.9; }
html[data-theme="light"] .msg-usage-trim { color:#866d35 !important; background:rgba(151,119,50,.10); }
html[data-theme="light"] .thinking-panel { background:#e3e8e5; border-color:#cbd4cf; }
html[data-theme="light"] .thinking-toggle,
html[data-theme="light"] .thinking-chevron,
html[data-theme="light"] .thinking-char-count { color:#68766f; }
html[data-theme="light"] .thinking-char-count { background:#d8dfdb; }
html[data-theme="light"] .msg-content a { color:#575b8b; text-decoration-color:rgba(87,91,139,.35); }
html[data-theme="light"] .msg-content blockquote {
    color:#506059; background:rgba(100,112,106,.06); border-color:#8887aa;
}
html[data-theme="light"] .msg-content code:not(pre code),
html[data-theme="light"] .msg-bubble code:not(pre code) { color:#4f527f; background:#dce2df; }
html[data-theme="light"] .typing-indicator,
html[data-theme="light"] .thinking-status-wrap { color:#63716a; }

.chat-area,.empty-chat,.empty-chat-content,.empty-quality-block,.chat-quality-suggestions {
    min-width:0; max-width:100%; overflow-x:hidden !important;
}
.chat-quality-suggestions .quality-model-suggestion-list {
    display:flex; flex-wrap:wrap; justify-content:center; gap:6px;
    width:100%; overflow:visible !important; padding:2px 1px 4px;
    scroll-snap-type:none; scrollbar-width:none;
}
.chat-quality-suggestions .quality-model-suggestion-list::-webkit-scrollbar { display:none; }
.chat-quality-suggestions .quality-model-suggestion {
    min-width:0; width:auto; max-width:100%; padding:6px 12px; border-radius:10px; text-align:center;
}
.chat-quality-suggestions .quality-model-suggestion img,
.chat-quality-suggestions .quality-model-fallback,
.chat-quality-suggestions .quality-model-suggestion small { display:none; }
.chat-quality-suggestions .quality-model-suggestion strong {
    display:block; font-size:10.5px; font-weight:700; white-space:nowrap;
}
html[data-theme="light"] {
    color-scheme:light;
    --bg-primary:#e8ecea; --bg-secondary:#f0f3f1; --bg-tertiary:#dce3df;
    --bg-hover:#d5ddd9; --bg-input:#f4f6f4; --bg-user-msg:#dce5e1;
    --bg-menu:#eef2ef; --bg-menu-hover:#e0e7e3;
    --text-primary:#25312c; --text-secondary:#4f5e57; --text-muted:#718078;
    --accent:#66658f; --accent-hover:#57567d; --accent-light:#7675a3;
    --border:#cbd5d0; --border-light:#d8dfdb;
    --shadow:0 8px 26px rgba(45,61,53,.09); --shadow-menu:0 18px 42px rgba(45,61,53,.14);
}
html[data-theme="light"] body {
    background:radial-gradient(circle at 12% 4%,rgba(111,119,159,.10),transparent 28%),
               radial-gradient(circle at 88% 12%,rgba(91,132,113,.09),transparent 30%),#e8ecea;
}
html[data-theme="light"] .main,html[data-theme="light"] .chat-area { background:transparent; }
html[data-theme="light"] .main-header,
html[data-theme="light"] .sidebar,
html[data-theme="light"] .mobile-bottom-nav {
    background:rgba(232,236,234,.92) !important; border-color:#cbd5d0 !important;
    box-shadow:none !important; backdrop-filter:blur(16px);
}
html[data-theme="light"] .empty-quality-block,
html[data-theme="light"] .eq-card,
html[data-theme="light"] .model-card-v2,
html[data-theme="light"] .knowledge-card,
html[data-theme="light"] .audio-card {
    background:#eef2ef !important; border-color:#cbd5d0 !important;
    box-shadow:0 8px 24px rgba(45,61,53,.06) !important;
}
html[data-theme="light"] .eq-card.selected {
    background:linear-gradient(145deg,#e3e4ef,#e1e9e5) !important;
    border-color:#8786aa !important; box-shadow:0 0 0 2px rgba(102,101,143,.10) !important;
}
html[data-theme="light"] .composer,html[data-theme="light"] body.app-shell .composer {
    background:#f2f5f3 !important; border-color:#c5d0ca !important;
    box-shadow:0 10px 30px rgba(45,61,53,.10) !important;
}
html[data-theme="light"] .chat-quality-suggestions .quality-model-suggestion {
    color:#313d38; background:linear-gradient(145deg,#e5e6ef,#e3e9e6) !important;
    border-color:#b9b8d1 !important;
}
html[data-theme="light"] .chat-quality-suggestions .quality-model-suggestion:hover {
    background:linear-gradient(145deg,#dedfed,#dce6e1) !important; border-color:#8584aa !important;
}
html[data-theme="light"] .theme-segment { background:#dce2df; border-color:#c5cfca; }
html[data-theme="light"] .theme-segment-btn.active {
    background:#eef2ef; color:#36443d; box-shadow:0 2px 8px rgba(45,61,53,.10);
}
html[data-theme="light"] .nav-item:hover,
html[data-theme="light"] .nav-item.active { background:rgba(102,101,143,.10); }
@media (max-width:640px) {
    .empty-chat-content { width:100%; padding-inline:10px; }
    .empty-quality-block { width:calc(100% - 8px); margin-inline:4px; }
    .chat-quality-suggestions .quality-model-suggestion-list { padding-inline:0; }
}

/* هویت مدل پاسخ‌دهنده + انتخاب تعاملی مدل جایگزین */
.msg-model-identity{display:flex;align-items:center;gap:8px;min-height:28px;margin:0 0 8px;color:var(--text-secondary);font-size:11px;font-weight:650}
.msg-model-logo{width:26px!important;height:26px!important;min-width:26px!important;min-height:26px!important;max-width:26px!important;max-height:26px!important;display:grid;place-items:center;overflow:hidden;flex:0 0 26px!important;border:1px solid var(--border);border-radius:9px;background:rgba(255,255,255,.06);color:var(--accent-light);font-size:8px}
.msg-model-logo img,.msg-assistant .msg-model-logo img{display:block!important;width:26px!important;height:26px!important;min-width:26px!important;min-height:26px!important;max-width:26px!important;max-height:26px!important;object-fit:cover!important;border-radius:8px!important;margin:0!important}.msg-model-name{color:var(--text-primary)}.msg-model-identity small{padding:3px 6px;border-radius:6px;background:rgba(255,255,255,.045);color:var(--text-muted);font-size:8px}
.replacement-picker{margin-top:4px;padding:17px;border:1px solid rgba(245,158,11,.3);border-radius:18px;background:linear-gradient(145deg,rgba(245,158,11,.08),rgba(255,255,255,.018))}
.replacement-picker>header{display:flex;align-items:flex-start;gap:11px;margin-bottom:14px}.replacement-picker>header>span{display:grid;place-items:center;width:31px;height:31px;flex:none;border-radius:10px;background:rgba(245,158,11,.15);color:#f7c565;font-weight:900}
.replacement-picker h3{margin:0 0 5px;font-size:13px}.replacement-picker p{margin:0;color:var(--text-secondary);font-size:10.5px;line-height:1.8}
.replacement-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
.replacement-model{min-width:0;display:flex;align-items:center;gap:9px;padding:10px;border:1px solid var(--border);border-radius:13px;background:rgba(255,255,255,.035);color:var(--text-primary);text-decoration:none;text-align:right;font:inherit;cursor:pointer;transition:.18s}
.replacement-model:hover{border-color:var(--accent);background:rgba(139,92,246,.1);transform:translateY(-1px)}.replacement-model>span:nth-child(2){min-width:0;flex:1;display:flex;flex-direction:column;gap:3px}
.replacement-model b{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:11px}.replacement-model small{color:var(--text-muted);font-size:8.5px}.replacement-model em{color:var(--text-muted);font-size:8px;font-style:normal;white-space:nowrap}
.replacement-model.locked{opacity:.68}.replacement-logo{width:32px;height:32px;display:grid;place-items:center;overflow:hidden;flex:none;border:1px solid var(--border);border-radius:10px;background:rgba(255,255,255,.06);font-size:9px;color:var(--accent-light)}
.replacement-logo img{width:100%;height:100%;object-fit:cover}.replacement-picker.is-selected{pointer-events:none;opacity:.62}.replacement-empty{grid-column:1/-1;padding:10px;text-align:center}
@media(max-width:600px){.replacement-grid{grid-template-columns:1fr}.replacement-picker{padding:13px}.msg-model-identity{margin-bottom:6px}}
