/* ═══════════════════════════════════════
   CHAT LAYOUT
   ═══════════════════════════════════════ */

.chat-layout {
    display: flex;
    height: 100%;
    overflow: hidden;
    min-height: 0;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-width, 280px);
    min-width: var(--sidebar-width, 280px);
    background: var(--panel);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.2s ease, min-width 0.2s ease;
}

/* Desktop collapse — hides sidebar content, keeps border strip */
.sidebar.desktop-collapsed {
    width: 0;
    min-width: 0;
    border-right-color: transparent;
    overflow: hidden;
}

/* Floating expand button — shows when sidebar is collapsed. JS toggles .visible */
.sidebar-expand-btn {
    display: none;
    position: fixed;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    z-index: 150;
    background: var(--panel);
    border: 1px solid var(--green-dim);
    border-left: none;
    border-radius: 0 8px 8px 0;
    color: var(--green);
    font-size: 18px;
    cursor: pointer;
    padding: 14px 8px;
    line-height: 1;
    font-family: inherit;
    transition: background 0.15s, padding 0.15s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.sidebar-expand-btn.visible {
    display: block;
}

.sidebar-expand-btn:hover {
    padding-left: 12px;
    background: var(--panel-2);
}

@media (max-width: 768px) {
    .sidebar-expand-btn { display: none !important; }
}

/* Collapse toggle button — top-right of sidebar header */
.sidebar-collapse-btn {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 14px;
    cursor: pointer;
    padding: 2px 5px;
    border-radius: 4px;
    line-height: 1;
    transition: color 0.15s, background 0.15s;
    flex-shrink: 0;
}

.sidebar-collapse-btn:hover {
    color: var(--text);
    background: rgba(var(--green-rgb), 0.06);
}

/* On mobile sidebar is already an overlay — hide the collapse button */
@media (max-width: 768px) {
    .sidebar-collapse-btn {
        display: none;
    }
}

.sidebar-header {
    padding: 12px;
    border-bottom: 1px solid var(--line);
}

.sidebar-new-chat {
    width: 100%;
    padding: 10px;
    font-size: 13px;
}

.sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.sidebar-item-wrap {
    position: relative;
    overflow: hidden;
}

/* When the context-menu dropdown is open we have to lift the overflow clip,
 * otherwise the swipe-to-delete mask hides every menu item except the first.
 * .has-open-menu is toggled in JS when openSidebarDropdown() fires. */
.sidebar-item-wrap.has-open-menu {
    overflow: visible;
    z-index: 20;
}

/* Swipe-to-delete action — hidden by default, only visible during touch swipe.
   Never shows on devices with hover (desktop/trackpad). */
.sidebar-item-swipe-action {
    display: none;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 100px;
    align-items: center;
    justify-content: center;
    background: var(--red);
    color: var(--bg);
    font-size: 20px;
    z-index: 0;
    pointer-events: none;
}

/* Only reveal swipe action when item is actively being swiped */
.sidebar-item-wrap.swiping .sidebar-item-swipe-action,
.sidebar-item-wrap.swipe-open .sidebar-item-swipe-action {
    display: flex;
}

.sidebar-item {
    position: relative;
    padding: 10px 12px;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: all 0.15s;
    z-index: 1;
    will-change: transform;
}

.sidebar-item:hover {
    background: rgba(var(--green-rgb), 0.05);
}

.sidebar-item.active {
    background: rgba(var(--green-rgb), 0.08);
    border-left-color: var(--green);
}

/* Synthetic "📝 Черновик" entry for unsent new-chat prompts. Painted in
   amber to visually separate it from real persisted conversations. */
.sidebar-item-draft {
    background: rgba(var(--amber-rgb), 0.06);
    border-left-color: var(--amber);
}
.sidebar-item-draft:hover {
    background: rgba(var(--amber-rgb), 0.12);
}
.sidebar-item-draft.active {
    background: rgba(var(--amber-rgb), 0.14);
    border-left-color: var(--amber);
}
.sidebar-item-draft .sidebar-item-title {
    color: var(--amber);
    font-weight: 600;
}
.sidebar-item-draft .sidebar-item-time {
    color: var(--amber);
    opacity: 0.7;
    font-style: italic;
}

.sidebar-item-title {
    font-size: 13px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-item.active .sidebar-item-title {
    color: var(--green);
}

.sidebar-item-preview {
    font-size: 11px;
    color: var(--muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    /* opacity removed — --muted already carries appropriate contrast per theme */
}

.sidebar-item-time {
    font-size: 10px;
    color: var(--muted);
    margin-top: 2px;
    opacity: 0.5;
}

.sidebar-item-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 2px;
}

.sidebar-item-actions {
    display: none;
    gap: 4px;
    margin-top: 4px;
}

/* Hover actions replaced by menu button - keep for fallback */
.sidebar-item:hover .sidebar-item-actions {
    display: none;
}

.sidebar-footer {
    border-top: 1px solid var(--line);
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-user {
    padding: 8px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--line);
    font-size: 12px;
}

.sidebar-user-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-user-name {
    color: var(--green);
    font-size: 13px;
}

.sidebar-user-sub {
    color: var(--muted);
    font-size: 11px;
    margin-top: 2px;
}

.sidebar-user-balance {
    color: var(--amber);
    font-size: 13px;
    margin-top: 4px;
    font-weight: bold;
}

/* Subscription badges */
.sub-badge {
    display: inline-block;
    font-size: 9px;
    padding: 1px 6px;
    border-radius: 4px;
    letter-spacing: 0.5px;
    font-weight: bold;
    vertical-align: middle;
}

.sub-badge.free {
    background: rgba(90, 122, 86, 0.2);
    color: var(--muted);
    border: 1px solid rgba(90, 122, 86, 0.3);
}

.sub-badge.plus {
    background: rgba(var(--amber-rgb), 0.15);
    color: var(--amber);
    border: 1px solid rgba(var(--amber-rgb), 0.3);
}

.sub-badge.pro {
    background: rgba(var(--green-rgb), 0.1);
    color: var(--green);
    border: 1px solid rgba(var(--green-rgb), 0.3);
}

/* Premium = Генерал: top-tier gold gradient badge */
.sub-badge.premium {
    background: linear-gradient(135deg, rgba(217, 164, 58, 0.28), rgba(255, 213, 107, 0.2));
    color: #f3cd6a;
    border: 1px solid rgba(217, 164, 58, 0.5);
    text-shadow: 0 0 6px rgba(255, 213, 107, 0.35);
}

.sidebar-link {
    background: none;
    border: none;
    color: var(--muted);
    font-family: inherit;
    font-size: 12px;
    padding: 6px 8px;
    text-align: left;
    cursor: pointer;
    border-radius: 4px;
}

.sidebar-link:hover {
    color: var(--green);
    background: rgba(var(--green-rgb), 0.05);
}

.sidebar-loading, .sidebar-empty {
    color: var(--muted);
    font-size: 12px;
    text-align: center;
    padding: 20px;
}

.sidebar-empty-hint {
    margin-top: 8px;
    font-size: 11px;
    opacity: 0.6;
}

/* Skeleton loading */
.skeleton-item {
    padding: 10px 12px;
}

.skeleton-line {
    height: 12px;
    background: linear-gradient(90deg, var(--panel-2) 25%, rgba(var(--green-rgb), 0.06) 50%, var(--panel-2) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
    margin-bottom: 6px;
}

.skeleton-line.short {
    width: 60%;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Message skeleton */
.msg-skeleton {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
}

.msg-skeleton-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.msg-skeleton-row.right {
    align-items: flex-end;
}

.msg-skeleton-bubble {
    height: 40px;
    width: 65%;
    border-radius: 16px;
    background: linear-gradient(90deg, var(--panel-2) 25%, rgba(var(--green-rgb), 0.04) 50%, var(--panel-2) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

.msg-skeleton-bubble.short {
    width: 45%;
    height: 32px;
}

/* ── Chat main ── */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
    transition: box-shadow 0.2s;
    z-index: 10;
}

.chat-header.scrolled {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

.sidebar-toggle {
    display: none;
}

.chat-title {
    font-size: 14px;
    color: var(--green);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.chat-balance {
    font-size: 11px;
    color: var(--amber);
    white-space: nowrap;
    transition: color 0.2s;
}

.chat-balance.balance-low {
    color: var(--amber);
    animation: balancePulse 2s infinite;
}

.chat-balance.balance-empty {
    color: var(--red);
    font-weight: 600;
    animation: balancePulse 1.2s infinite;
}

@keyframes balancePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}

.low-balance-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: rgba(var(--amber-rgb), 0.08);
    border-bottom: 1px solid rgba(var(--amber-rgb), 0.3);
    color: var(--amber);
    font-size: 13px;
    animation: bannerSlideDown 0.25s ease-out;
}

.low-balance-banner.empty {
    background: rgba(var(--red-rgb), 0.1);
    border-bottom-color: rgba(var(--red-rgb), 0.4);
    color: var(--red);
}

.low-balance-banner .lbb-text {
    flex: 1;
    line-height: 1.4;
}

.low-balance-banner .lbb-balance {
    font-weight: 600;
}

.low-balance-banner .lbb-btn {
    background: var(--green);
    color: var(--bg);
    text-decoration: none;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    transition: background 0.15s;
}

.low-balance-banner .lbb-btn:hover {
    background: var(--green-dim);
}

.low-balance-banner .lbb-close {
    background: transparent;
    border: none;
    color: inherit;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    opacity: 0.6;
    padding: 0 4px;
}

.low-balance-banner .lbb-close:hover {
    opacity: 1;
}

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

@media (max-width: 480px) {
    .low-balance-banner {
        font-size: 12px;
        padding: 8px 12px;
        flex-wrap: wrap;
    }
    .low-balance-banner .lbb-text {
        flex-basis: 100%;
    }
}

/* Single-line model switcher in chat header:
 *  - friendly label + ▾ arrow (click opens picker)
 *  - compact 📋 button next to it (click copies full model id)
 */
.chat-model {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    padding: 0;
    border-radius: 6px;
    white-space: nowrap;
    min-width: 0;
}

.chat-model-switch {
    background: transparent;
    border: none;
    color: var(--muted);
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.15s;
}

.chat-model-switch:hover {
    background: rgba(var(--green-rgb), 0.08);
    color: var(--green-dim);
}

.chat-model-label {
    font-weight: 600;
}

.chat-model-arrow {
    font-size: 9px;
    color: var(--green);
    opacity: 0.6;
}

.chat-model-copy-btn {
    background: var(--panel-2);
    border: 1px solid var(--line);
    color: var(--muted);
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
    padding: 4px 7px;
    border-radius: 6px;
    line-height: 1;
    transition: all 0.15s;
    flex-shrink: 0;
}

.chat-model-copy-btn:hover {
    background: rgba(var(--green-rgb), 0.12);
    border-color: var(--green-dim);
    color: var(--green);
    transform: scale(1.05);
}

/* ── Messages ── */
.chat-messages {
    flex: 1 1 auto;
    min-height: 0; /* critical: allows flex child to shrink and scroll */
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: relative;
}

.chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    color: var(--muted);
    gap: 8px;
    /* Sit naturally at the top of the scroll container so long content can
       scroll. Add breathing room from chat header. */
    padding: 32px 8px 16px;
    flex: 0 0 auto;
}

.empty-icon {
    font-size: 48px;
    opacity: 0.5;
}

.empty-text {
    font-size: 16px;
}

.empty-hint {
    font-size: 12px;
    opacity: 0.7;
    max-width: 480px;
    line-height: 1.5;
}

.empty-prompts-title,
.empty-features-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--amber);
    margin-top: 22px;
    margin-bottom: 8px;
    font-weight: 600;
}
.empty-features-title {
    color: var(--muted);
    margin-top: 28px;
}

/* Suggested prompts */
.empty-prompts {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 4px;
    width: 100%;
    max-width: 480px;
}

.empty-prompt-btn {
    background: var(--panel);
    border: 1px solid var(--line);
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    padding: 10px 16px;
    border-radius: 12px;
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
}

.empty-prompt-btn:hover {
    border-color: var(--green-dim);
    background: rgba(var(--green-rgb), 0.04);
}

.empty-features {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-top: 28px;
    width: 100%;
    max-width: 560px;
}

.empty-feature {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 14px;
    border: 1px dashed var(--line);
    border-radius: 12px;
    background: rgba(var(--green-rgb), 0.02);
    text-align: left;
}

.empty-feature-icon {
    font-size: 24px;
    flex-shrink: 0;
    line-height: 1;
}

.empty-feature-title {
    font-size: 13px;
    color: var(--green);
    font-weight: 600;
    margin-bottom: 4px;
}

.empty-feature-desc {
    font-size: 12px;
    color: var(--muted);
    line-height: 1.4;
}

@media (max-width: 640px) {
    .empty-features {
        grid-template-columns: 1fr;
        gap: 8px;
        max-width: 360px;
    }
    .empty-feature {
        padding: 12px;
    }
}

/* AI suggested buttons after response */
.ai-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 16px 16px;
    max-width: 85%;
    animation: msgFadeIn 0.3s ease;
    background: linear-gradient(180deg, rgba(var(--green-rgb), 0.035), rgba(var(--green-rgb), 0.01));
    border: 1px solid rgba(var(--green-rgb), 0.08);
    border-radius: 16px;
    margin-top: -2px;
}

.ai-suggestions-title {
    width: 100%;
    font-size: 11px;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: var(--muted);
    opacity: 0.8;
    margin-bottom: 2px;
}

.ai-suggestion-btn {
    background: var(--panel);
    border: 1px solid var(--line);
    color: var(--green);
    font-family: inherit;
    font-size: 13px;
    padding: 8px 14px;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.ai-suggestion-btn:hover {
    border-color: var(--green-dim);
    background: rgba(var(--green-rgb), 0.06);
    text-shadow: 0 0 6px rgba(var(--green-rgb), 0.3);
}

.ai-suggestion-btn:active {
    transform: scale(0.96);
}

.empty-prompt-btn:hover {
    border-color: var(--green-dim);
    background: rgba(var(--green-rgb), 0.06);
    color: var(--green);
}

.msg {
    max-width: 85%;
    position: relative;
    animation: msgFadeIn 0.2s ease-out;
}

/* User bubbles can get wider — they're usually questions/code pastes/file
 * attachments that read better at full width. Assistant replies stay at
 * the default 85% so long paragraphs wrap into a comfortable reading
 * measure. */
.msg.user {
    max-width: 92%;
}

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

.msg.user {
    align-self: flex-end;
}

.msg.assistant {
    align-self: flex-start;
}

.msg.system {
    align-self: center;
    max-width: 90%;
}

/* Avatar dots */
.msg-avatar {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-bottom: 4px;
}

.msg.assistant .msg-avatar {
    background: var(--green);
    box-shadow: 0 0 6px rgba(var(--green-rgb), 0.4);
}

.msg.user .msg-avatar {
    background: var(--amber);
    box-shadow: 0 0 6px rgba(var(--amber-rgb), 0.4);
}

.msg.user .bubble {
    background: rgba(var(--amber-rgb), 0.12);
    border: 1px solid rgba(var(--amber-rgb), 0.2);
    border-right: 2px solid var(--amber);
    /* Preserve newlines from the user's textarea — .bubble sets textContent
     * for user messages, so default white-space: normal collapses \n into
     * single spaces. pre-wrap keeps breaks AND wraps long lines. */
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.msg.assistant .bubble {
    background: var(--panel);
    border: 1px solid var(--line);
    border-left: 2px solid var(--green);
}

.system-bubble {
    background: rgba(var(--red-rgb), 0.1) !important;
    border-color: rgba(var(--red-rgb), 0.2) !important;
    border-left: 2px solid var(--red) !important;
    color: var(--red) !important;
    font-size: 12px;
    text-align: center;
}

/* System message with retry */
.system-retry-btn {
    display: block;
    background: none;
    border: 1px solid rgba(var(--red-rgb), 0.3);
    color: var(--red);
    font-family: inherit;
    font-size: 11px;
    padding: 4px 12px;
    border-radius: 6px;
    cursor: pointer;
    margin: 8px auto 0;
    transition: all 0.15s;
}

.system-retry-btn:hover {
    background: rgba(var(--red-rgb), 0.1);
}

/* Primary recovery action inside system error bubbles (e.g. "Пополнить
 * баланс" on INSUFFICIENT_BALANCE). Green to set it apart from the
 * neutral "Повторить" button. */
.system-cta-btn {
    display: inline-block;
    margin: 10px 0 2px;
    padding: 8px 18px;
    background: linear-gradient(135deg, var(--green), var(--green-dim));
    border: 1px solid var(--green);
    border-radius: 8px;
    color: var(--bg);
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.15s;
}
.system-cta-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(var(--green-rgb), 0.28);
}

.bubble {
    padding: 12px 16px;
    border-radius: 16px;
    line-height: 1.6;
    font-size: 14px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.bubble pre {
    background: var(--panel-2);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 13px;
    position: relative;
}

.bubble code {
    color: var(--green);
    font-family: 'Share Tech Mono', 'Courier New', monospace;
    font-size: 13px;
}

.bubble pre code {
    color: var(--text);
}

.bubble p {
    margin: 0 0 8px;
}

.bubble p:last-child {
    margin-bottom: 0;
}

.bubble ul, .bubble ol {
    padding-left: 20px;
    margin: 8px 0;
}

.bubble li {
    margin-bottom: 4px;
}

.bubble a {
    color: var(--green);
    text-decoration: underline;
    text-decoration-style: dotted;
}

.bubble a:hover {
    text-shadow: 0 0 8px rgba(var(--green-rgb), 0.3);
}

.bubble blockquote {
    border-left: 3px solid var(--green-dim);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--muted);
}

.bubble hr {
    border: none;
    border-top: 1px solid var(--line);
    margin: 12px 0;
}

.bubble table {
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 13px;
    width: 100%;
}

.bubble th, .bubble td {
    border: 1px solid var(--line);
    padding: 6px 10px;
    text-align: left;
}

.bubble th {
    background: rgba(var(--green-rgb), 0.06);
    color: var(--green-dim);
}

/* Generated media (images/files from model responses) */
.msg-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.msg-attachment-card {
    position: relative;
    display: inline-block;
    max-width: 100%;
}

.msg-attachment-image {
    display: block;
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
    background: var(--panel-2);
    line-height: 0;
    transition: border-color 0.15s, transform 0.15s;
    max-width: 100%;
    padding: 0;
    cursor: zoom-in;
    font: inherit;
    color: inherit;
}

.msg-attachment-image:hover {
    border-color: var(--green);
    transform: scale(1.01);
}

.msg-attachment-image img {
    display: block;
    max-width: 320px;
    max-height: 320px;
    width: 100%;
    height: auto;
    object-fit: contain;
    /* Prevent huge images from loading full-size into layout */
    background: rgba(var(--green-rgb), 0.02);
}

/* Download button overlay */
.msg-attachment-dl {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 36px;
    height: 36px;
    /* Intentional dark scrim over user-uploaded image — theme-agnostic */
    background: rgba(0, 0, 0, 0.65);
    border: 1px solid var(--green-dim);
    color: var(--green);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-size: 16px;
    opacity: 0;
    transform: translateY(-4px);
    transition: all 0.18s;
    z-index: 2;
}

.msg-attachment-card:hover .msg-attachment-dl {
    opacity: 1;
    transform: translateY(0);
}

.msg-attachment-dl:hover {
    background: var(--green);
    color: var(--bg);
    border-color: var(--green);
}

/* Generic file attachment */
.msg-attachment-file {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(var(--green-rgb), 0.03);
    color: var(--text);
    text-decoration: none;
    font-size: 13px;
    transition: all 0.15s;
    max-width: 100%;
}

.msg-attachment-file:hover {
    border-color: var(--green-dim);
    background: rgba(var(--green-rgb), 0.08);
}

.msg-attachment-file-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.msg-attachment-file-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.msg-attachment-file-dl {
    color: var(--green);
    font-size: 14px;
    flex-shrink: 0;
}

@media (max-width: 560px) {
    .msg-attachment-image img {
        max-width: 100%;
        max-height: 260px;
    }
    /* Always show download button on touch devices */
    .msg-attachment-dl {
        opacity: 0.9;
        transform: none;
    }
}

/* ── Sidebar position (data-driven from world config) ── */

body[data-sidebar="right"] .chat-layout {
    flex-direction: row-reverse;
}

body[data-sidebar="right"] .sidebar {
    border-right: none;
    border-left: 1px solid var(--line);
}

body[data-sidebar="top"] .chat-layout {
    flex-direction: column;
}

body[data-sidebar="top"] .sidebar {
    width: 100%;
    min-width: 100%;
    max-height: 48px;
    flex-direction: row;
    align-items: center;
    border-right: none;
    border-bottom: 1px solid var(--line);
    overflow: hidden;
}

body[data-sidebar="top"] .sidebar-header,
body[data-sidebar="top"] .sidebar-list {
    display: none;
}

body[data-sidebar="top"] .sidebar-footer {
    width: 100%;
    padding: 0 12px;
}

body[data-sidebar="top"] .sidebar-user {
    display: none;
}

body[data-sidebar="top"] .sidebar-menu-body {
    display: flex !important;
    flex-direction: row;
    gap: 4px;
    align-items: center;
}

body[data-sidebar="top"] .sidebar-menu-body.collapsed {
    display: flex !important;
}

body[data-sidebar="top"] .sidebar-menu-toggle {
    display: none;
}

body[data-sidebar="top"] .sidebar-nav-links {
    display: flex;
    flex-direction: row;
    gap: 4px;
}

body[data-sidebar="top"] .sidebar-nav-link {
    white-space: nowrap;
    padding: 6px 10px;
    font-size: 13px;
}

body[data-sidebar="top"] .sidebar-link,
body[data-sidebar="top"] .sidebar-theme-toggle {
    white-space: nowrap;
    padding: 6px 10px;
    font-size: 13px;
}

body[data-sidebar="none"] .sidebar {
    display: none;
}

body[data-sidebar="none"] .chat-main {
    width: 100%;
}
