/* ============================================================
   UDream Chat — Design v2
   ============================================================ */

/* ---------- 1. TOKENS ---------- */
:root {
    /* Surfaces */
    --bg:           #0a0a0c;
    --bg-elev:      #121215;
    --bg-elev-2:    #1a1a1f;
    --bg-elev-3:    #22222a;
    --bg-hover:     rgba(255, 255, 255, 0.045);
    --bg-active:    rgba(255, 255, 255, 0.075);

    /* Borders */
    --border:        rgba(255, 255, 255, 0.06);
    --border-strong: rgba(255, 255, 255, 0.12);
    --border-focus:  rgba(220, 38, 38, 0.5);

    /* Text */
    --text:   #f4f4f6;
    --text-2: #b8b8be;
    --text-3: #71717a;
    --text-4: #52525b;

    /* Brand */
    --brand:        #dc2626;
    --brand-hover:  #ef4444;
    --brand-soft:   rgba(220, 38, 38, 0.13);
    --brand-soft-2: rgba(220, 38, 38, 0.22);
    --brand-ring:   rgba(220, 38, 38, 0.18);

    /* Status */
    --success: #10b981;
    --warning: #f59e0b;
    --info:    #3b82f6;
    --danger:  #ef4444;

    /* Radii */
    --r-sm:   6px;
    --r-md:   10px;
    --r-lg:   14px;
    --r-xl:   18px;
    --r-2xl:  24px;
    --r-pill: 999px;

    /* Shadow */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.55);

    /* Motion */
    --ease:    cubic-bezier(0.2, 0.8, 0.2, 1);
    --t-fast:  120ms var(--ease);
    --t-med:   220ms var(--ease);
}

/* ---------- 2. RESET & BASE ---------- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overscroll-behavior-y: none;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    font-size: 14px;
    line-height: 1.55;
    color: var(--text);
    background:
        radial-gradient(900px circle at 100% 0%, rgba(220, 38, 38, 0.045), transparent 55%),
        var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-feature-settings: 'cv11', 'ss01', 'ss03';
    display: flex;
    overflow: hidden;
    position: fixed;
    inset: 0;
}

button {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    background: none;
    border: none;
    cursor: pointer;
}

input, textarea, select {
    font-family: inherit;
    color: var(--text);
}

textarea::placeholder,
input::placeholder {
    color: var(--text-3);
}

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 999px;
    border: 2px solid transparent;
    background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.14); background-clip: padding-box; }

/* Autofill fix */
input:-webkit-autofill,
textarea:-webkit-autofill {
    -webkit-text-fill-color: var(--text);
    -webkit-box-shadow: 0 0 0 1000px var(--bg-elev-2) inset;
    caret-color: var(--text);
}

/* ---------- 3. LAYOUT ---------- */
.app-container {
    display: flex;
    width: 100%;
    height: 100%;
}

.sidebar {
    width: 264px;
    flex-shrink: 0;
    background: var(--bg-elev);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 10;
}

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

/* ---------- 4. SIDEBAR ---------- */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 16px 12px;
    user-select: none;
}

.brand-mark {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    object-fit: cover;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    display: block;
}

.brand-name {
    font-weight: 600;
    font-size: 15px;
    letter-spacing: -0.01em;
    color: var(--text);
}

.sidebar-top-actions {
    padding: 4px 10px 10px;
}

.btn-new-chat {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    color: var(--text);
    background: rgba(255, 255, 255, 0.025);
    font-size: 13.5px;
    font-weight: 500;
    transition: background var(--t-fast), border-color var(--t-fast);
}
.btn-new-chat i { font-size: 12px; color: var(--text-2); }
.btn-new-chat:hover { background: var(--bg-hover); border-color: rgba(255, 255, 255, 0.18); }

.chat-list-container {
    flex: 1;
    overflow-y: auto;
    padding: 6px 8px 14px;
}

.section-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 14px 10px 6px;
}
.section-title span { display: inline-block; }

.section-actions {
    display: flex;
    gap: 4px;
}

.room-action-btn {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    color: var(--text-3);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    transition: background var(--t-fast), color var(--t-fast);
}
.room-action-btn:hover { background: var(--bg-hover); color: var(--text); }
#new-room-btn:hover  { color: var(--info); }
#join-room-btn:hover { color: var(--success); }

.chat-list { list-style: none; }

.chat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    margin-bottom: 1px;
    border-radius: var(--r-md);
    color: var(--text-2);
    font-size: 13.5px;
    cursor: pointer;
    transition: background var(--t-fast), color var(--t-fast);
}
.chat-item:hover { background: var(--bg-hover); color: var(--text); }
.chat-item.active { background: var(--bg-active); color: var(--text); }

.chat-title {
    display: flex;
    align-items: center;
    gap: 9px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}
.chat-title i { font-size: 11px; color: var(--text-3); flex-shrink: 0; }
.chat-title span,
.chat-title { font-weight: 400; }

.chat-actions {
    display: none;
    gap: 8px;
    color: var(--text-3);
    font-size: 12px;
}
.chat-item:hover .chat-actions { display: flex; }
.chat-actions i { transition: color var(--t-fast); cursor: pointer; }
.chat-actions i:hover { color: var(--text); }
.chat-actions .fa-thumbtack:hover { color: var(--brand-hover); }
.chat-actions .fa-trash:hover { color: var(--danger); }
.active-pin { color: var(--brand); }

/* Sidebar bottom area */
.sidebar-bottom-actions {
    padding: 8px 10px 12px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-bottom-btn {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 11px;
    border-radius: var(--r-md);
    font-size: 13px;
    font-weight: 500;
    border: 1px solid transparent;
    color: var(--text-2);
    background: transparent;
    transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.sidebar-bottom-btn i {
    font-size: 13px;
    width: 16px;
    text-align: center;
    color: var(--text-3);
    transition: color var(--t-fast);
}
.sidebar-bottom-btn:hover {
    background: var(--bg-hover);
    color: var(--text);
}
.sidebar-bottom-btn:hover i { color: var(--text); }

/* Shop button — brand accent (per user direction) */
.sidebar-bottom-btn.shop-btn {
    color: var(--text);
    background: var(--brand-soft);
    border-color: var(--brand-ring);
    margin-top: 4px;
}
.sidebar-bottom-btn.shop-btn i { color: var(--brand-hover); }
.sidebar-bottom-btn.shop-btn:hover {
    background: var(--brand-soft-2);
    border-color: rgba(220, 38, 38, 0.45);
}

/* ---------- 5. HEADER ---------- */
.chat-header {
    height: 56px;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    background: rgba(10, 10, 12, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    flex-shrink: 0;
    z-index: 30;
    position: relative;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.header-title-block {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
}

#current-chat-title {
    margin: 0;
    font-size: 14.5px;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -0.005em;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
    transition: color var(--t-fast);
}
#current-chat-title:hover { color: var(--brand-hover); }

#typing-indicator {
    display: none;
    font-size: 11.5px;
    color: var(--brand-hover);
    font-weight: 500;
    margin-top: 2px;
    height: 14px;
    line-height: 1;
    transition: opacity var(--t-fast);
}

.header-controls {
    display: flex;
    gap: 4px;
    align-items: center;
}

/* ---------- 6. ICON BUTTONS ---------- */
.icon-btn {
    width: 34px;
    height: 34px;
    border-radius: var(--r-md);
    color: var(--text-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: background var(--t-fast), color var(--t-fast);
    background: transparent;
    border: 1px solid transparent;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn:active { transform: scale(0.96); }

.header-controls .icon-btn { width: 34px; height: 34px; font-size: 13px; }
#room-settings-btn { color: var(--info); }
#room-settings-btn:hover { background: rgba(59, 130, 246, 0.12); }

/* ---------- 7. MESSAGES ---------- */
.messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 28px 32px 160px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
    align-items: stretch;
}

.message {
    width: fit-content;
    max-width: min(78%, 760px);
    padding: 11px 16px;
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
    position: relative;
    word-wrap: break-word;
    overflow-wrap: break-word;
    border-radius: 18px;
}

/* AI message — borderless, with brand avatar to the left */
.msg-ai {
    align-self: flex-start;
    max-width: min(85%, 820px);
    background: transparent;
    border: none;
    padding: 4px 0 4px 44px;
    border-radius: 0;
}
.msg-ai::before {
    content: "";
    position: absolute;
    left: 0;
    top: 4px;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: url('/public/icon-192.png') center/cover no-repeat;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45), 0 0 0 1px var(--border-strong);
}

/* User message — bubble on the right */
.msg-user {
    align-self: flex-end;
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
    border-radius: 18px 18px 6px 18px;
    padding: 11px 16px;
}

/* Other user (rooms) — bubble on the left */
.msg-other-user {
    align-self: flex-start;
    background: rgba(59, 130, 246, 0.08);
    border: 1px solid rgba(59, 130, 246, 0.22);
    border-radius: 18px 18px 18px 6px;
    padding: 11px 16px;
}

/* System message */
.msg-system {
    align-self: center;
    color: var(--text-3);
    font-size: 12px;
    font-style: italic;
    padding: 4px 12px;
    margin: 6px 0;
    background: transparent;
    border: none;
}

/* Sender label inside message */
.msg-label {
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Action buttons under message (copy/edit/regen) */
.msg-regen-btn,
.msg-edit-btn,
.msg-copy-btn {
    position: absolute;
    bottom: -8px;
    width: 28px;
    height: 28px;
    border-radius: 7px;
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
    color: var(--text-3);
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    cursor: pointer;
    transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
    z-index: 2;
}

.msg-ai .msg-copy-btn  { left: 44px; bottom: -10px; }
.msg-ai .msg-regen-btn { left: 78px; bottom: -10px; }
.msg-ai .msg-edit-btn  { left: 112px; bottom: -10px; }

.msg-user .msg-copy-btn  { right: 0;  left: auto; bottom: -10px; }
.msg-user .msg-regen-btn { right: 34px; left: auto; bottom: -10px; }
.msg-user .msg-edit-btn  { right: 68px; left: auto; bottom: -10px; }

.msg-other-user .msg-copy-btn  { left: 0;  bottom: -10px; }
.msg-other-user .msg-regen-btn { left: 34px; bottom: -10px; }
.msg-other-user .msg-edit-btn  { left: 68px; bottom: -10px; }

.message:hover .msg-regen-btn,
.message:hover .msg-edit-btn,
.message:hover .msg-copy-btn { display: inline-flex; }

.msg-regen-btn:hover { background: var(--bg-elev-3); color: var(--brand-hover); border-color: var(--border-strong); }
.msg-edit-btn:hover  { background: var(--bg-elev-3); color: var(--text); border-color: var(--border-strong); }
.msg-copy-btn:hover  { background: var(--bg-elev-3); color: var(--success); border-color: var(--border-strong); }

/* Inline edit */
.inline-edit-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    min-width: 280px;
}
.inline-edit-textarea {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border-focus);
    border-radius: var(--r-md);
    padding: 12px;
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    resize: vertical;
    min-height: 80px;
    outline: none;
    box-shadow: 0 0 0 3px var(--brand-ring);
}
.inline-edit-actions { display: flex; gap: 8px; justify-content: flex-end; }
.inline-edit-actions button {
    padding: 7px 14px;
    border-radius: var(--r-sm);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--t-fast);
}
.btn-save-edit   { background: var(--brand); color: white; }
.btn-save-edit:hover { background: var(--brand-hover); }
.btn-cancel-edit { background: rgba(255, 255, 255, 0.06); color: var(--text-2); }
.btn-cancel-edit:hover { background: rgba(255, 255, 255, 0.1); color: var(--text); }

.edited-badge {
    font-size: 10.5px;
    color: var(--text-3);
    margin-left: 6px;
    font-style: italic;
}

/* ---------- 8. MARKDOWN INSIDE MESSAGE ---------- */
.message p { margin-bottom: 12px; }
.message p:last-child { margin-bottom: 0; }
.message ul,
.message ol { margin: 6px 0 12px; padding-left: 24px; }
.message ul { list-style-type: disc; }
.message ol { list-style-type: decimal; }
.message li { margin-bottom: 4px; }
.message li ul { list-style-type: circle; margin-top: 4px; margin-bottom: 0; padding-left: 22px; }
.message li ol { margin-top: 4px; margin-bottom: 0; padding-left: 22px; }
.message strong { font-weight: 700; color: #fff; }
.message em { color: var(--text-2); }

.message blockquote {
    border-left: 3px solid var(--brand);
    margin: 14px 0;
    padding: 6px 14px;
    color: var(--text-2);
    background: rgba(255, 255, 255, 0.02);
    border-radius: 0 var(--r-sm) var(--r-sm) 0;
}

.message a {
    color: #93c5fd;
    text-decoration: none;
    border-bottom: 1px solid rgba(147, 197, 253, 0.3);
    transition: border-color var(--t-fast), color var(--t-fast);
}
.message a:hover { color: #bfdbfe; border-bottom-color: #bfdbfe; }

.message table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    font-size: 13.5px;
    border-radius: var(--r-md);
    overflow: hidden;
    border: 1px solid var(--border);
}
.message th,
.message td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); }
.message th { background: var(--bg-elev-2); font-weight: 600; color: var(--text); }
.message tr:last-child td { border-bottom: none; }

.message hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 18px 0;
}

/* ---------- 9. CODE ---------- */
.message pre {
    position: relative;
    background: #0c0c0f;
    border: 1px solid var(--border);
    padding: 38px 14px 14px;
    border-radius: var(--r-md);
    overflow-x: auto;
    margin: 14px 0;
    max-width: 100%;
}
.message pre code {
    background: transparent;
    padding: 0;
    font-family: 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;
    font-size: 13px;
    line-height: 1.55;
    color: #e4e4e7;
}
.message code:not(pre code) {
    background: rgba(255, 255, 255, 0.07);
    padding: 2px 6px;
    border-radius: 5px;
    font-size: 0.88em;
    font-family: 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;
    color: #fbcfe8;
}

.copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    color: var(--text-2);
    border-radius: var(--r-sm);
    padding: 4px 9px;
    font-size: 11.5px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.copy-btn:hover { background: rgba(255, 255, 255, 0.08); color: var(--text); border-color: var(--border-strong); }

.code-lang {
    position: absolute;
    top: 12px;
    left: 14px;
    font-size: 10.5px;
    color: var(--text-3);
    text-transform: uppercase;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    letter-spacing: 0.06em;
}

/* ---------- 10. IMAGES & MEDIA IN MESSAGES ---------- */
.message img {
    max-width: 100%;
    max-height: 420px;
    border-radius: var(--r-lg);
    cursor: zoom-in;
    display: block;
    border: 1px solid var(--border);
    margin-top: 10px;
}

.image-wrapper {
    position: relative;
    display: inline-block;
    margin-top: 10px;
}

.image-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: none;
    gap: 6px;
}
.image-wrapper:hover .image-actions { display: flex; }

.image-id-tag,
.image-id-tag-user { display: none !important; }
.image-id { display: none; }

.img-status {
    font-size: 13px;
    color: var(--text-3);
    margin-top: 8px;
    font-style: italic;
}

.media-dl-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    text-decoration: none;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    transform: translateY(-2px);
    transition: opacity var(--t-fast), transform var(--t-fast), background var(--t-fast);
    z-index: 5;
}
.media-dl-btn:hover { background: rgba(0, 0, 0, 0.85); color: #fff; }
.message:hover .media-dl-btn,
.media-dl-btn:focus { opacity: 1; transform: translateY(0); }
@media (hover: none) { .media-dl-btn { opacity: 0.85; transform: none; } }

/* ---------- 11. INPUT AREA ---------- */
.input-area {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    padding: 12px 20px 18px;
    padding-bottom: max(18px, env(safe-area-inset-bottom));
    display: flex;
    justify-content: center;
    z-index: 10;
    pointer-events: none;
    background: linear-gradient(to bottom, transparent 0%, rgba(10, 10, 12, 0.65) 35%, var(--bg) 100%);
}

.input-container {
    width: 100%;
    max-width: 780px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: auto;
}

.input-box {
    width: 100%;
    background: var(--bg-elev-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-2xl);
    display: flex;
    align-items: flex-end;
    padding: 8px 8px 8px 10px;
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
    box-shadow: var(--shadow-md);
}
.input-box:focus-within {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--brand-ring), var(--shadow-md);
}

#user-input {
    flex: 1;
    background: transparent;
    border: none;
    resize: none;
    min-height: 24px;
    max-height: 200px;
    padding: 8px 10px;
    outline: none;
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
}

.input-box .icon-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--r-md);
    color: var(--text-3);
    flex-shrink: 0;
}
.input-box .icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.icon-btn.send {
    background: var(--brand);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: var(--r-md);
}
.icon-btn.send:hover { background: var(--brand-hover); color: white; }
.icon-btn.send:active { transform: scale(0.94); }

/* Search toggle */
#tools-btn { position: relative; }
#tools-btn.search-active { color: #3b82f6 !important; text-shadow: 0 0 10px rgba(59, 130, 246, 0.4); }

/* File preview */
.file-preview {
    position: relative;
    width: 64px;
    height: 64px;
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 4px;
    align-self: flex-start;
}
.file-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 7px;
}

.remove-file-btn,
#remove-file-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid var(--border-strong);
    color: white;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    transition: background var(--t-fast);
}
.remove-file-btn:hover,
#remove-file-btn:hover { background: var(--danger); }

/* ---------- 12. MODALS — base ---------- */
.welcome-overlay,
.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(8, 8, 10, 0.7);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-y: auto;
}
.modal-overlay {
    display: none;
    position: fixed;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.7);
}

.welcome-content {
    background: var(--bg-elev);
    padding: 32px;
    border-radius: var(--r-xl);
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow-lg);
    text-align: center;
    width: 100%;
    max-width: 420px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}

.welcome-content h2,
.welcome-content h3 {
    margin: 0 0 8px;
    font-size: 22px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
}
.welcome-content > p {
    color: var(--text-2);
    margin: 0 0 22px;
    line-height: 1.55;
    font-size: 14px;
}

.welcome-brand-mark {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    object-fit: cover;
    margin: 0 auto 20px;
    display: block;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5), 0 0 32px rgba(220, 38, 38, 0.15);
}

/* Welcome action stack */
.welcome-actions {
    display: none;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
}

/* Login help block */
.login-help {
    margin-top: 16px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    text-align: center;
    font-size: 12.5px;
    color: var(--text-3);
    line-height: 1.5;
}
.login-help p { margin: 0 0 10px; }
.login-help-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}

#telegram-login-container {
    margin: 16px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 44px;
}

/* ---------- 13. BUTTONS ---------- */
.btn-primary {
    background: var(--brand);
    border: 1px solid var(--brand);
    color: white;
    padding: 11px 16px;
    border-radius: var(--r-md);
    cursor: pointer;
    font-size: 13.5px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
}
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-primary:active { transform: translateY(1px); }

.btn-secondary {
    background: var(--bg-elev-2);
    border: 1px solid var(--border-strong);
    color: var(--text);
    padding: 10px 16px;
    border-radius: var(--r-md);
    cursor: pointer;
    font-size: 13.5px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background var(--t-fast), border-color var(--t-fast);
}
.btn-secondary:hover { background: var(--bg-elev-3); border-color: rgba(255, 255, 255, 0.2); }

.btn-action {
    background: transparent;
    color: var(--text-2);
    border: 1px solid var(--border);
    padding: 7px 12px;
    border-radius: var(--r-sm);
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.btn-action:hover {
    background: var(--bg-hover);
    color: var(--text);
    border-color: var(--border-strong);
}

.btn-ghost {
    background: transparent;
    color: var(--text-2);
    border: none;
    padding: 7px 10px;
    border-radius: var(--r-sm);
    cursor: pointer;
    font-size: 12.5px;
    transition: background var(--t-fast), color var(--t-fast);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }

/* ---------- 14. INPUTS & SELECTS ---------- */
.field-input,
.field-textarea,
.field-select {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    padding: 11px 13px;
    color: var(--text);
    font-size: 14px;
    line-height: 1.45;
    outline: none;
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.field-input:focus,
.field-textarea:focus,
.field-select:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--brand-ring);
}
.field-textarea { resize: vertical; min-height: 92px; line-height: 1.5; }
.field-select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2'><polyline points='6 9 12 15 18 9'/></svg>");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
    cursor: pointer;
}

.field-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-2);
    margin-bottom: 6px;
    display: block;
}

/* ---------- 15. MODAL — generic shell ---------- */
.modal-shell {
    background: var(--bg-elev);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 480px;
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.modal-shell-header {
    padding: 18px 22px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.modal-shell-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 10px;
    letter-spacing: -0.005em;
}
.modal-shell-title i { color: var(--brand); font-size: 14px; }
.modal-shell-body {
    padding: 20px 22px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}
.modal-shell-footer {
    padding: 14px 22px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-shrink: 0;
}
.modal-close-x {
    width: 30px;
    height: 30px;
    border-radius: var(--r-sm);
    color: var(--text-3);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: background var(--t-fast), color var(--t-fast);
    background: transparent;
    border: none;
}
.modal-close-x:hover { background: var(--bg-hover); color: var(--text); }

.modal-form { display: flex; flex-direction: column; gap: 14px; }

/* ---------- 16. SETTINGS MODAL (character) ---------- */
#settings-modal .modal-shell {
    max-width: 1100px;
    width: 100%;
    max-height: calc(100vh - 40px);
    height: 800px;
}
.settings-layout {
    display: flex;
    gap: 0;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}
.settings-left {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px 22px;
    min-width: 0;
}
.settings-right {
    width: 360px;
    min-width: 300px;
    border-left: 1px solid var(--border);
    padding: 20px 22px;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.settings-section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.settings-section-head h4 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-2);
    margin: 0;
}
#custom-prompt-input {
    flex: 1;
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    padding: 14px;
    color: var(--text);
    font-size: 14px;
    line-height: 1.55;
    resize: none;
    outline: none;
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
    min-height: 200px;
}
#custom-prompt-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--brand-ring);
}

.char-filter-row { display: flex; gap: 8px; }
.char-filter-row .field-select { padding: 8px 28px 8px 10px; font-size: 12.5px; }

#char-search-input { margin-bottom: 10px; }

#explore-chars-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 12px;
    padding-right: 4px;
    min-height: 0;
}

/* ---------- 17. PROFILE MODAL ---------- */
.profile-modal-content {
    background: var(--bg-elev) !important;
    padding: 0 !important;
    border-radius: var(--r-xl) !important;
    border: 1px solid var(--border-strong) !important;
    width: 100%;
    max-width: 880px;
    max-height: calc(100vh - 40px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    text-align: left;
}
.profile-modal-content > div:first-child {
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
    position: relative;
}
.profile-layout {
    display: flex;
    flex-direction: row;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}
.profile-left {
    flex: 0 0 340px;
    padding: 22px;
    border-right: 1px solid var(--border);
    overflow-y: auto;
}
.profile-right {
    flex: 1;
    padding: 22px;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}
.profile-right h4 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-2);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}
#profile-info-container {
    background: var(--bg-elev-2);
    padding: 16px;
    border-radius: var(--r-md);
    border: 1px solid var(--border);
}
#characters-list-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    overflow-y: auto;
    padding-right: 4px;
    margin-top: 12px;
    min-height: 0;
}

@media (max-width: 768px) {
    .profile-modal-content { max-width: 100%; max-height: calc(100vh - 40px); }
    .profile-layout {
        flex-direction: column;
        overflow-y: auto;
    }
    .profile-left {
        flex: none;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 18px;
    }
    .profile-right {
        padding: 18px;
        overflow: visible;
    }
    #characters-list-container {
        flex: none;
        max-height: 320px;
    }
}

/* ---------- 18. SHOP MODAL ---------- */
.shop-content {
    background: var(--bg-elev);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 480px;
    position: relative;
}
.shop-redesign {
    max-width: 900px !important;
    padding: 0 !important;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 40px);
}

.shop-header {
    padding: 24px 28px 22px;
    text-align: center;
    border-bottom: 1px solid var(--border);
    background:
        radial-gradient(400px circle at 50% 0%, rgba(220, 38, 38, 0.1), transparent 70%),
        var(--bg-elev);
}
.shop-header h2 {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    gap: 10px;
}
.shop-header h2 i { color: var(--warning); }
.shop-header p {
    margin: 6px 0 0;
    color: var(--text-2);
    font-size: 13.5px;
}

.shop-layout {
    display: grid;
    grid-template-columns: 1fr 1.2fr;
    flex: 1;
    overflow: hidden;
}
.shop-info-section {
    background: var(--bg);
    padding: 24px;
    border-right: 1px solid var(--border);
    overflow-y: auto;
}
.shop-pricing-section {
    padding: 24px;
    overflow-y: auto;
}

.info-card {
    background: var(--bg-elev-2);
    border-radius: var(--r-md);
    padding: 16px 18px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
}
.info-card:last-child { margin-bottom: 0; }
.info-card h4 {
    font-size: 13.5px;
    margin: 0 0 12px;
    color: var(--text);
    font-weight: 600;
}
.premium-benefits ul { list-style: none; padding: 0; margin: 0; }
.premium-benefits li {
    margin-bottom: 8px;
    font-size: 13px;
    color: var(--text-2);
    display: flex;
    gap: 9px;
    align-items: center;
}
.premium-benefits li i { color: var(--success); font-size: 10px; }
.premium-benefits li b { color: var(--text); font-weight: 600; }

.token-rules h4 { color: var(--text); }
.rules-grid { display: flex; flex-direction: column; gap: 6px; }
.rule-item {
    display: flex;
    justify-content: space-between;
    font-size: 12.5px;
    padding: 6px 0;
    border-bottom: 1px dashed var(--border);
    color: var(--text-2);
}
.rule-item:last-child { border-bottom: none; }
.rule-item b { color: var(--text); font-weight: 600; }
.rule-note { font-size: 11.5px; color: var(--text-3); margin-top: 10px; line-height: 1.5; }

.section-label {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-3);
    margin: 14px 0 10px;
    letter-spacing: 0.08em;
    font-weight: 600;
}
.section-label:first-child { margin-top: 0; }

.pricing-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.shop-item {
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 14px;
    text-align: center;
    cursor: pointer;
    transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
}
.shop-item:hover {
    background: var(--bg-elev-3);
    border-color: var(--border-strong);
    transform: translateY(-1px);
}
.shop-item .item-name {
    font-weight: 600;
    font-size: 13.5px;
    color: var(--text);
    margin-bottom: 4px;
}
.shop-item .price {
    color: var(--text-2);
    font-weight: 600;
    font-size: 13px;
}

.premium-item {
    background: linear-gradient(180deg, rgba(220, 38, 38, 0.07), transparent);
    border-color: rgba(220, 38, 38, 0.22);
}
.premium-item:hover {
    background: linear-gradient(180deg, rgba(220, 38, 38, 0.12), rgba(220, 38, 38, 0.02));
    border-color: rgba(220, 38, 38, 0.45);
}
.premium-item .price { color: var(--brand-hover); }

.close-modal {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 30px;
    height: 30px;
    border-radius: var(--r-sm);
    color: var(--text-3);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background var(--t-fast), color var(--t-fast);
    z-index: 5;
}
.close-modal:hover { background: var(--bg-hover); color: var(--text); }

/* ---------- 19. LIGHTBOX ---------- */
#lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(5, 5, 7, 0.88);
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}
#lightbox img {
    max-width: 92%;
    max-height: 88%;
    box-shadow: var(--shadow-lg);
    border-radius: var(--r-lg);
    border: 1px solid var(--border-strong);
}
.lightbox-controls {
    position: absolute;
    bottom: 32px;
    display: flex;
    gap: 10px;
    cursor: default;
}
.lightbox-controls .btn-action {
    background: rgba(20, 20, 24, 0.88);
    padding: 10px 16px;
    font-size: 13px;
    border: 1px solid var(--border-strong);
    color: var(--text);
}
.lightbox-controls .btn-action:hover {
    background: rgba(30, 30, 34, 0.95);
    border-color: var(--brand);
}

/* ---------- 20. TOASTS ---------- */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 260px;
    max-width: 360px;
    padding: 13px 16px;
    background: var(--bg-elev-2);
    border: 1px solid var(--border-strong);
    border-left: 3px solid var(--brand);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-md);
    color: var(--text);
    font-size: 13.5px;
    animation: slide-in-right 320ms var(--ease) forwards;
}
.toast-success { border-left-color: var(--success); }
.toast-success .toast-icon { color: var(--success); }
.toast-info { border-left-color: var(--info); }
.toast-info .toast-icon { color: var(--info); }
.toast-icon { font-size: 18px; flex-shrink: 0; }
.toast-content { flex: 1; line-height: 1.4; }
.toast-close {
    background: transparent;
    border: none;
    color: var(--text-3);
    cursor: pointer;
    font-size: 13px;
    padding: 4px;
    transition: color var(--t-fast);
}
.toast-close:hover { color: var(--text); }

/* ---------- 21. CUSTOM PANELS ---------- */
.custom-panel {
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    margin: 12px 0;
    overflow: hidden;
}
.custom-panel + .custom-panel { margin-top: -4px; }
.custom-panel-header {
    background: rgba(255, 255, 255, 0.025);
    padding: 8px 14px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--brand-hover);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
}
.custom-panel-body { padding: 12px 14px; font-size: 13.5px; color: var(--text); }
.custom-panel-body > *:first-child { margin-top: 0 !important; }
.custom-panel-body > *:last-child { margin-bottom: 0 !important; }

/* ---------- 22. LOADERS ---------- */
.typing-dots {
    display: flex;
    gap: 5px;
    padding: 4px 0;
    font-size: 24px;
    color: var(--text-3);
    line-height: 0;
    align-items: center;
}
.typing-dots span { animation: blink 1.4s infinite both; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

.chat-loader {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-3);
    gap: 12px;
    font-size: 14px;
}

.spinner {
    width: 22px;
    height: 22px;
    border: 2.5px solid var(--border-strong);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

@keyframes blink {
    0%   { opacity: 0.25; transform: translateY(0); }
    20%  { opacity: 1;    transform: translateY(-2px); }
    100% { opacity: 0.25; transform: translateY(0); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slide-in-right {
    from { transform: translateX(110%); opacity: 0; }
    to   { transform: translateX(0);    opacity: 1; }
}
@keyframes slide-in-down {
    from { transform: translateY(-120%); opacity: 0; }
    to   { transform: translateY(0);     opacity: 1; }
}

/* ---------- 23. MOBILE ---------- */
.mobile-only { display: none !important; }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 40;
}

@media (max-width: 768px) {
    .mobile-only { display: inline-flex !important; }

    .sidebar {
        position: fixed;
        left: -290px;
        top: 0;
        bottom: 0;
        width: 280px;
        transition: left 260ms var(--ease);
        z-index: 50;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open { left: 0; }
    .sidebar-overlay.active { display: block; }

    .chat-header { padding: 0 14px; height: 52px; }
    #current-chat-title { font-size: 14px; }

    .messages { padding: 20px 14px 140px; gap: 12px; }
    .message { font-size: 14.5px; max-width: 88%; }
    .msg-ai { padding: 4px 0 4px 38px; max-width: 92%; }
    .msg-ai::before { width: 26px; height: 26px; top: 4px; }
    .msg-ai .msg-copy-btn  { left: 38px; }
    .msg-ai .msg-regen-btn { left: 72px; }
    .msg-ai .msg-edit-btn  { left: 106px; }

    .input-area { padding: 8px 12px 14px; padding-bottom: max(14px, env(safe-area-inset-bottom)); }
    .input-container { gap: 6px; }
    #user-input { font-size: 16px; padding: 7px 8px; }

    .welcome-content { padding: 26px 20px; }
    .modal-shell-header { padding: 16px 18px; }
    .modal-shell-body { padding: 18px; }
    .modal-shell-footer { padding: 12px 18px; }

    #settings-modal .modal-shell {
        max-width: 100%;
        height: calc(100vh - 40px);
    }
    .settings-layout { flex-direction: column; overflow-y: auto; }
    .settings-right {
        width: 100%;
        min-width: 0;
        border-left: none;
        border-top: 1px solid var(--border);
    }
    #custom-prompt-input { min-height: 140px; }

    .shop-redesign { max-height: calc(100vh - 40px); }
    .shop-layout { grid-template-columns: 1fr; overflow-y: auto; }
    .shop-info-section { border-right: none; border-bottom: 1px solid var(--border); }
    .shop-header { padding: 20px; }
    .shop-header h2 { font-size: 19px; }

    #toast-container {
        bottom: unset;
        top: 16px;
        left: 50%;
        right: unset;
        transform: translateX(-50%);
        width: calc(100% - 32px);
        align-items: center;
    }
    .toast { animation: slide-in-down 320ms var(--ease) forwards; }
}

/* ---------- 24. DESKTOP / ULTRAWIDE ---------- */
@media (min-width: 1280px) {
    .messages { padding: 32px 48px 180px; }
}

@media (min-width: 1600px) {
    .input-container { max-width: 860px; }
    .messages { padding-left: 80px; padding-right: 80px; }
}

@media (min-width: 1920px) {
    .sidebar { width: 296px; }
    .input-container { max-width: 920px; }
    .messages { padding-left: 120px; padding-right: 120px; }
    .chat-header { padding: 0 28px; height: 60px; }
}

/* ============================================================
   UDREAM WORKSHOP EXTENSIONS
   ============================================================ */

/* Workspace Content Wrapper */
.workspace-content {
    flex: 1;
    display: flex;
    position: relative;
    height: 100%;
    min-width: 0;
}

.tab-pane {
    display: none;
    width: 100%;
    height: 100%;
    position: absolute;
    inset: 0;
}

.tab-pane.active {
    display: flex;
    flex-direction: row;
}

.tab-pane:not(#tab-chat) {
    display: none;
}

.tab-pane.active:not(#tab-chat) {
    display: block;
}

.app-iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: var(--bg);
}

/* Navigation Rail (Far Left) */
.nav-rail {
    width: 72px;
    background: var(--bg-elev);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 0;
    flex-shrink: 0;
    z-index: 12;
}

.rail-logo {
    width: 34px;
    height: 34px;
    margin-bottom: 8px;
}

.rail-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.rail-tabs {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
    align-items: center;
}

.rail-btn {
    width: 50px;
    height: 44px;
    border-radius: var(--r-md);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: var(--text-3);
    gap: 2px;
    transition: var(--t-fast);
    position: relative;
}

.rail-btn i {
    font-size: 16px;
    transition: transform var(--t-fast);
}

.rail-btn span {
    font-size: 9px;
    font-weight: 500;
}

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

.rail-btn:hover i {
    transform: translateY(-2px);
}

.rail-btn.active {
    color: var(--text);
    background: var(--brand-soft);
    box-shadow: inset 0 0 0 1px var(--brand);
}

.rail-btn.active i {
    color: var(--brand);
}

.rail-bottom {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
    align-items: center;
    margin-top: auto;
}

/* Gallery Drawer */
.gallery-drawer {
    position: fixed;
    top: 0;
    right: -420px;
    width: 400px;
    height: 100%;
    background: var(--bg-elev);
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: right var(--t-med);
}

.gallery-drawer.open {
    right: 0;
}

.gallery-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 999;
    display: none;
    opacity: 0;
    transition: opacity var(--t-med);
}

.gallery-overlay.open {
    display: block;
    opacity: 1;
}

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

.drawer-header h3 {
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
}

.drawer-close-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--r-sm);
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-3);
    transition: var(--t-fast);
}

.drawer-close-btn:hover {
    color: var(--text);
    background: var(--bg-hover);
}

.drawer-filters {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.search-box-container {
    position: relative;
    width: 100%;
}

.search-box-container input {
    width: 100%;
    padding: 10px 12px 10px 36px;
    border-radius: var(--r-sm);
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
    outline: none;
    transition: var(--t-fast);
}

.search-box-container input:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 2px var(--brand-ring);
}

.search-box-container .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-3);
}

.filter-controls, .folder-controls {
    display: flex;
    gap: 8px;
}

.filter-controls select, .folder-controls select {
    flex: 1;
    padding: 8px;
    border-radius: var(--r-sm);
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
    color: var(--text);
    outline: none;
}

.btn-action-small {
    width: 36px;
    height: 36px;
    border-radius: var(--r-sm);
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
    color: var(--text-2);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: var(--t-fast);
}

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

.gallery-items-grid {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    align-content: start;
}

.gallery-item-card {
    position: relative;
    border-radius: var(--r-md);
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
    overflow: hidden;
    width: 100%;
    padding-bottom: 100%;
    cursor: pointer;
    transition: var(--t-fast);
}

.gallery-item-card:hover {
    border-color: var(--brand);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.gallery-item-card img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.gallery-item-hover-actions {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 8px;
    opacity: 0;
    transition: opacity var(--t-fast);
    pointer-events: none;
}

.gallery-item-card:hover .gallery-item-hover-actions {
    opacity: 1;
    pointer-events: auto;
}

.gallery-item-top-actions {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
}

.gallery-item-bottom-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.gallery-item-btn {
    width: 28px;
    height: 28px;
    border-radius: var(--r-sm);
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 12px;
    transition: var(--t-fast);
}

.gallery-item-btn:hover {
    background: var(--brand);
}

.gallery-item-btn.btn-delete:hover {
    background: var(--danger);
}

.gallery-item-badge {
    font-size: 9px;
    background: var(--brand);
    color: #fff;
    padding: 2px 6px;
    border-radius: var(--r-pill);
    font-weight: 600;
    text-transform: uppercase;
}

/* Mobile Responsiveness adjustments for navigation rail */
@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }
    .nav-rail {
        display: none !important;
    }
    .workspace-content {
        height: 100%;
    }
    #global-mobile-menu-btn.show-on-mobile {
        display: flex !important;
    }
    .gallery-drawer {
        width: 100%;
        right: -100%;
    }
}

.gallery-video-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 10px;
    z-index: 5;
    pointer-events: none;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* ---------- 23. GALLERY & LIGHTBOX CUSTOM AUDIO PLAYER ENHANCEMENTS ---------- */

/* Hover Center Action Label ("Відкрити") */
.gallery-item-center-action {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: #ffffff;
    opacity: 0;
    transition: transform var(--t-med), opacity var(--t-med);
    pointer-events: none;
    z-index: 10;
}

.gallery-item-card:hover .gallery-item-center-action {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}

.gallery-item-center-action i {
    font-size: 36px;
    color: #ffffff;
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.6)) drop-shadow(0 0 15px rgba(220, 38, 38, 0.4));
    transition: transform var(--t-fast);
}

.gallery-item-card:hover .gallery-item-center-action i {
    transform: scale(1.05);
}

.gallery-item-center-action span {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    background: rgba(10, 10, 12, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 4px 10px;
    border-radius: var(--r-sm);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* Custom Premium Audio Player Container */
.custom-audio-player {
    width: 360px;
    max-width: 90vw;
    background: rgba(18, 18, 24, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--r-xl);
    padding: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    box-shadow: var(--shadow-lg), 0 8px 32px rgba(0, 0, 0, 0.5), 0 0 80px rgba(220, 38, 38, 0.15);
    margin-top: 20px;
    animation: fadeIn 300ms var(--ease);
}

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

/* Vinyl/CD Disc Container */
.audio-player-disk-container {
    position: relative;
    width: 140px;
    height: 140px;
    margin-bottom: 4px;
}

.audio-player-disk {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: radial-gradient(circle, #2d2d3a 0%, #0d0d12 70%, #050508 100%);
    border: 4px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.1);
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color var(--t-med);
}

.audio-player-disk img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

/* Vinyl grooves look */
.audio-player-disk::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: repeating-radial-gradient(circle, transparent, transparent 3px, rgba(255, 255, 255, 0.03) 4px, transparent 5px);
    pointer-events: none;
}

/* Center spindle hole */
.audio-player-disk::before {
    content: "";
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #0f0f13;
    border: 2px solid rgba(255, 255, 255, 0.15);
    z-index: 5;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.8);
}

.default-disk-art {
    color: rgba(255, 255, 255, 0.25);
    font-size: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Rotating animations */
@keyframes spinDisc {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.audio-player-disk.playing {
    animation: spinDisc 12s linear infinite;
    border-color: rgba(220, 38, 38, 0.3);
}

/* Animated Equalizer Waves */
.audio-player-waves {
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 3px;
    height: 18px;
    align-items: flex-end;
    opacity: 0;
    transition: opacity var(--t-med);
    z-index: 10;
}

.audio-player-waves.playing {
    opacity: 1;
}

.wave-bar {
    width: 3px;
    height: 3px;
    background: var(--brand);
    border-radius: 1px;
}

@keyframes bounceWave {
    0%, 100% { height: 3px; }
    50% { height: 18px; }
}

.audio-player-waves.playing .wave-bar:nth-child(1) { animation: bounceWave 0.8s infinite 0.1s; }
.audio-player-waves.playing .wave-bar:nth-child(2) { animation: bounceWave 0.8s infinite 0.3s; }
.audio-player-waves.playing .wave-bar:nth-child(3) { animation: bounceWave 0.8s infinite 0.5s; }
.audio-player-waves.playing .wave-bar:nth-child(4) { animation: bounceWave 0.8s infinite 0.2s; }
.audio-player-waves.playing .wave-bar:nth-child(5) { animation: bounceWave 0.8s infinite 0.4s; }
.audio-player-waves.playing .wave-bar:nth-child(6) { animation: bounceWave 0.8s infinite 0.6s; }
.audio-player-waves.playing .wave-bar:nth-child(7) { animation: bounceWave 0.8s infinite 0.3s; }

/* Track Info */
.audio-player-info {
    width: 100%;
    text-align: center;
}

.audio-track-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    margin: 0;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    padding: 0 8px;
}

/* Progress Slider */
.audio-player-progress-container {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
}

.time-label {
    font-size: 11px;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-3);
    min-width: 32px;
}

.audio-progress-bar {
    flex: 1;
    height: 4px;
    border-radius: var(--r-pill);
    background: rgba(255, 255, 255, 0.08);
    outline: none;
    cursor: pointer;
    -webkit-appearance: none;
    position: relative;
    border: none;
}

.audio-progress-bar::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    border-radius: var(--r-pill);
}

.audio-progress-bar::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--brand);
    box-shadow: 0 0 8px var(--brand);
    cursor: pointer;
    margin-top: -4px;
    transition: transform var(--t-fast);
}

.audio-progress-bar::-webkit-slider-thumb:hover {
    transform: scale(1.25);
}

/* Controls buttons */
.audio-player-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    width: 100%;
}

.control-btn-main {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.35), 0 0 20px rgba(220, 38, 38, 0.15);
    transition: transform var(--t-fast), background var(--t-fast), box-shadow var(--t-fast);
}

.control-btn-main:hover {
    transform: scale(1.06);
    background: var(--brand-hover);
    box-shadow: 0 6px 16px rgba(220, 38, 38, 0.5), 0 0 25px rgba(220, 38, 38, 0.25);
}

.control-btn-main:active {
    transform: scale(0.96);
}

.control-btn-sub {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-2);
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: transform var(--t-fast), background var(--t-fast), color var(--t-fast);
}

.control-btn-sub:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
    transform: scale(1.05);
}

.control-btn-sub:active {
    transform: scale(0.95);
}

/* Volume Slider */
.audio-player-volume-container {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    justify-content: center;
    margin-top: 4px;
    opacity: 0.85;
    transition: opacity var(--t-fast);
}

.audio-player-volume-container:hover {
    opacity: 1;
}

.volume-btn {
    font-size: 12px;
    color: var(--text-3);
    transition: color var(--t-fast);
    width: 20px;
    text-align: center;
}

.volume-btn:hover {
    color: var(--text-2);
}

.volume-slider {
    width: 80px;
    height: 3px;
    border-radius: var(--r-pill);
    background: rgba(255, 255, 255, 0.08);
    outline: none;
    cursor: pointer;
    -webkit-appearance: none;
    border: none;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-2);
    cursor: pointer;
    margin-top: -3px;
    transition: background var(--t-fast), transform var(--t-fast);
}

.volume-slider::-webkit-slider-thumb:hover {
    background: #fff;
    transform: scale(1.2);
}
