/* ========== JANITOR AI TEXT SYSTEM ========== */

/* Base message text - Default to WHITE/NORMAL for Speech/Unformatted text */
.message-content {
    font-size: 17px;
    line-height: 1.75;
    color: #ffffff;
    /* Plain text is white */
    font-style: normal;
    /* Plain text is normal */
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* User messages are always white/normal */
.message-content.user-message {
    color: #ffffff;
    font-style: normal;
}

/* Explicit Dialogue (Speech) - Plain White like JanitorAI */
.chat-dialogue {
    color: #ffffff !important;
    font-style: normal !important;
    font-weight: normal !important;
}

/* Explicit Italic/Narration (*text*) - Gray & Italic */
.chat-italic {
    color: #9ca3af !important;
    font-style: italic !important;
}

/* Bold - White & Bold */
.chat-bold {
    color: #ffffff !important;
    font-weight: 700 !important;
    font-style: normal;
}

/* Fix for the artifacts appearing as text */
[class*="chat-italic"],
[class*="chat-bold"] {
    display: inline;
}

/* ========== EMBEDDED IMAGES ========== */
.chat-embedded-image {
    max-width: 100%;
    max-height: 400px;
    border-radius: 8px;
    margin: 12px 0;
    display: block;
    object-fit: contain;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chat-embedded-image:hover {
    transform: scale(1.02);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}


/* ========== MOBILE MENU BUTTON ========== */
.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: var(--text-main, #fff);
    font-size: 1.5rem;
    line-height: 1;
    border-radius: 6px;
    transition: background 0.2s;
}

.mobile-menu-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Hide mobile menu by default, show on mobile */
@media screen and (max-width: 768px) {
    .mobile-menu-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        order: -1;
    }

    .nav-links,
    .navbar-nav {
        display: none !important;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--bg-dark, #121218);
        flex-direction: column !important;
        padding: 12px !important;
        border-top: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        z-index: 100;
    }

    .nav-links.mobile-open,
    .navbar-nav.mobile-open {
        display: flex !important;
    }

    .nav-links li,
    .navbar-nav li {
        width: 100%;
    }

    .nav-links a,
    .navbar-nav a {
        display: block;
        padding: 12px 16px !important;
        border-radius: 8px;
    }

    .nav-links a:hover,
    .navbar-nav a:hover {
        background: rgba(255, 255, 255, 0.05);
    }

    .nav-container,
    .navbar-content {
        position: relative;
    }
}

@media screen and (min-width: 769px) {
    .mobile-menu-btn {
        display: none !important;
    }

    .mobile-bottom-nav {
        display: none !important;
    }
}

/* ========== MOBILE BOTTOM NAVIGATION - JanitorAI Style ========== */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(18, 18, 24, 0.98);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid rgba(128, 90, 213, 0.2);
    padding: 8px 0;
    z-index: 1000;
    padding-bottom: env(safe-area-inset-bottom, 8px);
    touch-action: manipulation;
}

@media screen and (max-width: 768px) {
    .mobile-bottom-nav {
        display: flex !important;
        justify-content: space-around;
        align-items: center;
    }
}

.mobile-bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: #6b7280;
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 12px;
    transition: all 0.2s ease;
    font-size: 20px;
}

.mobile-bottom-nav a span {
    font-size: 10px;
    font-weight: 500;
}

.mobile-bottom-nav a:hover,
.mobile-bottom-nav a.active {
    color: #c084fc;
    background: rgba(128, 90, 213, 0.1);
}

.mobile-bottom-nav a.active {
    color: #a855f7;
}

/* User Avatar in Bottom Nav */
.mobile-bottom-nav .nav-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    transition: border-color 0.2s;
}

.mobile-bottom-nav a.active .nav-avatar {
    border-color: #a855f7;
}

/* ========== JANITOR AI MOBILE FIXES ========== */

/* ========== TABLET BREAKPOINT (768px) ========== */
@media screen and (max-width: 768px) {

    /* 1. Fix "Zoomed In" feeling by reducing base font size */
    html {
        font-size: 14px !important;
    }

    body {
        font-size: 14px !important;
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100vw !important;
        padding-bottom: 80px !important; /* Space for mobile nav */
    }

    /* 2. Fix Container Widths */
    .container {
        max-width: 100% !important;
        padding-left: 12px !important;
        padding-right: 12px !important;
        overflow-x: hidden !important;
    }

    /* 3. NAVBAR - JanitorAI Style Mobile Header */
    .navbar {
        padding: 0.6rem 0 !important;
        background: rgba(18, 18, 24, 0.95) !important;
        border-bottom: 1px solid rgba(128, 90, 213, 0.15) !important;
    }

    .nav-container,
    .navbar-content {
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 8px !important;
        padding: 0 12px !important;
        position: relative !important;
    }

    /* Mobile menu button - left side */
    .mobile-menu-btn {
        position: absolute !important;
        left: 12px !important;
    }

    .nav-logo,
    .navbar-logo {
        font-size: 1rem !important;
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
    }

    .nav-logo img,
    .navbar-logo img {
        height: 28px !important;
        width: 28px !important;
    }

    .nav-logo span,
    .navbar-logo span {
        font-size: 0.95rem !important;
    }

    /* Hide nav links on mobile (use bottom nav instead) */
    .nav-links,
    .navbar-nav {
        display: none !important;
    }

    .nav-link {
        padding: 0.4rem 0.6rem !important;
        font-size: 0.8rem !important;
    }

    /* Search bar - Full width, JanitorAI style */
    .search-container {
        margin: 12px 0 !important;
        max-width: 100% !important;
    }

    .search-input {
        width: 100% !important;
        padding: 12px 16px 12px 40px !important;
        border-radius: 24px !important;
        background: rgba(255, 255, 255, 0.05) !important;
        border: 1px solid rgba(128, 90, 213, 0.2) !important;
        font-size: 14px !important;
    }

    .search-input:focus {
        border-color: rgba(128, 90, 213, 0.5) !important;
        background: rgba(255, 255, 255, 0.08) !important;
    }

    .search-icon {
        left: 14px !important;
        font-size: 14px !important;
    }

    /* Hide footer on mobile */
    .site-footer {
        display: none !important;
    }

    /* Category/Filter buttons - Horizontal scroll */
    #tagsFilter {
        display: flex !important;
        gap: 6px !important;
        overflow-x: auto !important;
        padding-bottom: 8px !important;
        margin-bottom: 12px !important;
        -webkit-overflow-scrolling: touch !important;
    }

    #tagsFilter button {
        flex-shrink: 0 !important;
        padding: 6px 12px !important;
        border-radius: 16px !important;
        font-size: 12px !important;
    }

    /* Character count and filter bar */
    .flex.justify-between.items-center.mb-lg {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 10px !important;
    }

    #categoryTitle {
        font-size: 1rem !important;
    }

    #sortSelect {
        font-size: 12px !important;
        padding: 6px 10px !important;
    }

    /* 4. CHARACTER GRID - JanitorAI Style Cards */
    .character-grid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
        padding: 10px 0 20px 0 !important;
    }

    .character-card {
        height: auto !important;
        min-height: auto !important;
        border-radius: 12px !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
        background: linear-gradient(180deg, #2a2a3e 0%, #1e1e2e 100%) !important;
        border: 1px solid rgba(128, 90, 213, 0.2) !important;
        position: relative !important;
    }

    /* Character Name Banner - Removed to use standard HTML element
    .character-card::before {
        content: none;
    }
    */

    /* Card Image Area */
    .card-image-wrapper {
        position: relative !important;
        height: 180px !important;
        flex-shrink: 0 !important;
        background: #111318 !important;
    }

    .card-image {
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important;
        object-position: center 18% !important;
        background: #111318 !important;
    }

    /* View Count Badge */
    .card-overlay {
        position: absolute !important;
        top: 8px !important;
        right: 8px !important;
        left: auto !important;
        bottom: auto !important;
        padding: 0 !important;
        background: none !important;
        opacity: 1 !important;
        pointer-events: none !important;
        /* Allow clicks to pass through to card */
    }

    .card-overlay .view-count {
        background: rgba(34, 197, 94, 0.9) !important;
        color: white !important;
        padding: 4px 8px !important;
        border-radius: 6px !important;
        font-size: 11px !important;
        font-weight: 600 !important;
        display: flex !important;
        align-items: center !important;
        gap: 4px !important;
    }

    /* Card Content - Below Image */
    .card-content {
        padding: 10px !important;
        flex: 1 !important;
        display: flex !important;
        flex-direction: column !important;
        background: transparent !important;
        border-top: none !important;
    }

    /* Creator Name */
    .character-creator {
        color: #9ca3af !important;
        font-size: 11px !important;
        margin-bottom: 6px !important;
    }

    .character-creator::before {
        content: "@";
    }

    /* Character Name (Restored) */
    .character-name {
        font-size: 14px !important;
        height: auto !important;
        overflow: hidden !important;
        margin: 0 0 6px 0 !important;
        padding: 0 !important;
        font-weight: 700 !important;
        color: #fff !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 1 !important;
        line-clamp: 1 !important;
        -webkit-box-orient: vertical !important;
    }

    /* Description */
    .character-description {
        font-size: 12px !important;
        line-height: 1.5 !important;
        color: #d1d5db !important;
        -webkit-line-clamp: 4 !important;
        line-clamp: 4 !important;
        display: -webkit-box !important;
        -webkit-box-orient: vertical !important;
        overflow: hidden !important;
        flex: 1 !important;
        margin-bottom: 8px !important;
    }

    /* Stats (Hidden on mobile) */
    .character-stats {
        display: none !important;
    }

    /* Tags - JanitorAI Style */
    .character-tags {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 4px !important;
        padding-top: 8px !important;
        border-top: 1px solid rgba(255, 255, 255, 0.05) !important;
        margin-top: auto !important;
    }

    .tag {
        font-size: 10px !important;
        padding: 3px 8px !important;
        border-radius: 4px !important;
        font-weight: 500 !important;
        white-space: nowrap !important;
    }

    /* Tag Colors - JanitorAI Style */
    .tag-system,
    .tag:nth-child(1) {
        background: rgba(128, 90, 213, 0.2) !important;
        border-color: rgba(128, 90, 213, 0.4) !important;
        color: #c4b5fd !important;
    }

    .tag-custom,
    .tag:nth-child(2) {
        background: rgba(236, 72, 153, 0.15) !important;
        border-color: rgba(236, 72, 153, 0.3) !important;
        color: #f9a8d4 !important;
    }

    .tag:nth-child(3) {
        background: rgba(59, 130, 246, 0.15) !important;
        border-color: rgba(59, 130, 246, 0.3) !important;
        color: #93c5fd !important;
    }

    .tag-limitless {
        background: rgba(220, 38, 38, 0.2) !important;
        border-color: rgba(220, 38, 38, 0.4) !important;
        color: #fca5a5 !important;
    }

    /* Card Action Buttons - Right Side - HIDDEN BY DEFAULT ON MOBILE */
    .card-actions {
        position: absolute !important;
        top: 40px !important;
        right: 4px !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 3px !important;
        opacity: 0 !important;
        /* HIDDEN by default - clean image */
        transition: opacity 0.3s ease !important;
        pointer-events: none !important;
        /* Disable clicks when hidden */
        background: rgba(0, 0, 0, 0.6) !important;
        padding: 5px !important;
        border-radius: 8px !important;
        backdrop-filter: blur(6px) !important;
    }

    /* Show buttons ONLY when EDIT MODE is active */
    body.edit-mode .card-actions {
        opacity: 1 !important;
        pointer-events: auto !important;
    }

    /* Buttons inside actions */
    .card-actions .action-btn {
        pointer-events: auto !important;
        touch-action: manipulation !important;
        background: rgba(255, 255, 255, 0.2) !important;
        border: none !important;
    }

    .card-actions .action-btn:active {
        background: rgba(255, 255, 255, 0.4) !important;
        transform: scale(0.9) !important;
    }

    .action-btn {
        width: 26px !important;
        height: 26px !important;
        border-radius: 6px !important;
        font-size: 12px !important;
    }

    /* 5. PERSONAS GRID */
    .personas-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important;
        gap: 12px !important;
    }

    .persona-card-image {
        aspect-ratio: 1 !important;
    }

    .persona-card-content {
        padding: 10px !important;
    }

    .persona-card-name {
        font-size: 14px !important;
    }

    .persona-card-description {
        font-size: 12px !important;
        -webkit-line-clamp: 2 !important;
        line-clamp: 2 !important;
    }

    .create-persona-card {
        min-height: 240px !important;
    }

    /* 6. FORMS - Mobile Friendly */
    .form-group {
        margin-bottom: 1rem !important;
    }

    .form-input,
    .form-textarea,
    .form-select {
        font-size: 16px !important;
        /* Prevents iOS zoom on focus */
        padding: 0.75rem !important;
    }

    .form-textarea {
        min-height: 80px !important;
    }

    .grid-2,
    .grid.grid-2 {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }

    /* 7. BUTTONS - Touch Friendly */
    .btn {
        min-height: 44px !important;
        padding: 0.6rem 1rem !important;
        font-size: 0.85rem !important;
    }

    .btn-sm {
        min-height: 36px !important;
        padding: 0.4rem 0.75rem !important;
        font-size: 0.75rem !important;
    }

    .btn-icon {
        width: 40px !important;
        height: 40px !important;
    }

    /* 8. MODALS - Improved Mobile Styling */
    .modal {
        display: none;
        /* Hidden by default, toggled by JS to display: flex */
        position: fixed !important;
        inset: 0 !important;
        z-index: 99999 !important;
        background: rgba(0, 0, 0, 0.7) !important;
        backdrop-filter: blur(4px) !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 20px !important;
    }

    /* When active, it usually gets display: block or flex from JS. 
       We need to ensure it uses flex for centering. */
    .modal[style*="display: block"] {
        display: flex !important;
    }

    .modal .settings-card {
        background: #1e1e24 !important;
        border: 1px solid rgba(255, 255, 255, 0.1) !important;
        border-radius: 16px !important;
        width: 100% !important;
        max-width: 400px !important;
        /* Smaller max width for deletion dialog */
        margin: 0 auto !important;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5) !important;
        position: relative !important;
        animation: modalSlideIn 0.2s ease-out !important;
    }

    @keyframes modalSlideIn {
        from {
            transform: scale(0.95);
            opacity: 0;
        }

        to {
            transform: scale(1);
            opacity: 1;
        }
    }

    .modal .settings-header {
        padding: 16px 20px !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05) !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
    }

    .modal .settings-header h3 {
        margin: 0 !important;
        font-size: 1.1rem !important;
        font-weight: 600 !important;
        color: #fff !important;
    }

    .modal .settings-body {
        padding: 20px !important;
    }

    .modal .btn {
        padding: 10px 16px !important;
        font-size: 14px !important;
        border-radius: 8px !important;
        font-weight: 500 !important;
    }

    /* 9. CHAT INTERFACE - Fixed with correct class names from chat.html */
    ._chatLayoutContainer_tront_8 {
        max-width: 100% !important;
        padding-top: 0 !important;
    }

    /* Message Wrapper Padding */
    ._messagesWrapper_1swu7_1 {
        padding-left: 8px !important;
        padding-right: 8px !important;
    }

    /* Message Content Width & Spacing */
    ._messageContent_2xqwb_26 {
        gap: 8px !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        max-width: 100% !important;
    }

    /* Avatar Size */
    ._messageAvatarImage_1v19f_305 {
        width: 38px !important;
        height: 38px !important;
        border-radius: 50% !important;
        /* Circular avatar like reference */
    }

    /* Message Body Text Size */
    .message-content,
    ._messageBody_2xqwb_60,
    .prose {
        font-size: 14px !important;
        /* Smaller font size as requested */
        line-height: 1.5 !important;
        padding: 4px 0 !important;
    }

    /* Input Container Fixed Bottom */
    ._chatInputContainer_14uqx_1 {
        padding: 8px !important;
        background: #121218 !important;
        /* Dark background to match nav */
        border-top: 1px solid rgba(255, 255, 255, 0.05);
    }

    ._chatInputWrapper_14uqx_17 {
        padding-bottom: 0 !important;
    }

    /* Input Box Styling */
    ._chatInputInner_14uqx_30 {
        margin: 0 !important;
        border-radius: 20px !important;
        border: 1px solid rgba(128, 90, 213, 0.3) !important;
        background: rgba(255, 255, 255, 0.05) !important;
    }

    /* Textarea Font */
    ._chatTextarea_dzva7_1 {
        font-size: 14px !important;
        padding: 12px 50px 12px 16px !important;
        /* Increased right padding for button */
        min-height: 44px !important;
    }

    /* Send Button Position */
    ._sendButton_17cr1_106 {
        right: 6px !important;
        bottom: 6px !important;
        /* Slightly tighter to bottom-right corner but safe */
        width: 36px !important;
        /* Slightly smaller button area */
        height: 36px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: transparent !important;
        border-radius: 50% !important;
        transition: background 0.2s !important;
    }

    ._sendButton_17cr1_106:hover {
        background: rgba(255, 255, 255, 0.05) !important;
    }

    /* Hide sidebar toggle if present on mobile layout inside chat */
    ._menuButton_17cr1_32 {
        bottom: 4rem !important;
        /* Move up above input */
    }

    /* 10. SIDEBAR - Hidden by Default on Mobile */
    .sidebar {
        position: fixed !important;
        left: 0 !important;
        top: 0 !important;
        bottom: 0 !important;
        z-index: 200 !important;
        transform: translateX(-100%) !important;
        width: 280px !important;
        background: var(--bg-dark) !important;
    }

    .sidebar.active {
        transform: translateX(0) !important;
    }

    .sidebar-avatar {
        width: 80px !important;
        height: 80px !important;
    }

    /* 11. CARDS & SECTIONS */
    .card,
    .card-glass {
        padding: 1rem !important;
    }

    .card-glass.p-xl {
        padding: 1rem !important;
    }

    /* 12. Chat Text Formatting */
    .message-content,
    ._messageBody_2xqwb_60,
    .prose,
    .chat-dialogue,
    .chat-italic,
    .chat-bold {
        font-size: 15px !important;
        line-height: 1.5 !important;
    }

    /* 13. Fix Layout Padding/Margins */
    ._bar_1lgb1_26,
    .pp-top-bar-inner {
        padding-left: 10px !important;
        padding-right: 10px !important;
        height: auto !important;
        min-height: 56px;
        flex-wrap: wrap;
    }

    ._logoContainer_1lgb1_7 {
        min-width: auto !important;
        margin-right: 10px;
    }

    ._container_fgb7n_1 {
        margin-left: 0 !important;
        margin-right: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
    }

    ._searchInputContainer_1lgb1_19 {
        order: 3;
        width: 100%;
        margin-top: 5px;
    }

    ._main_ckjfh_1,
    ._customPadding_ckjfh_16 {
        padding-left: 10px !important;
        padding-right: 10px !important;
    }

    /* 14. Chat Images */
    .chat-embedded-image {
        max-height: 300px !important;
        width: 100% !important;
        object-fit: contain;
    }

    .pp-top-bar-right {
        margin-left: auto !important;
    }

    .pp-top-bar-auth-buttons-login,
    .pp-top-bar-auth-buttons-register {
        padding: 4px 10px !important;
        font-size: 12px !important;
    }

    /* 15. SEARCH */
    .search-container {
        max-width: 100% !important;
        margin: 1rem 0 !important;
    }

    .search-input {
        padding: 0.75rem 0.75rem 0.75rem 2.5rem !important;
        font-size: 14px !important;
    }

    /* 16. TABS */
    .tabs {
        flex-wrap: wrap !important;
        gap: 0.25rem !important;
    }

    .tab {
        padding: 0.5rem 0.75rem !important;
        font-size: 0.8rem !important;
        flex: 1 1 auto !important;
        text-align: center !important;
    }

    /* 17. HERO SECTION */
    .hero-section {
        padding: 16px 0 !important;
    }

    .hero-text {
        font-size: 1.5rem !important;
    }

    .hero-subtext {
        font-size: 0.85rem !important;
    }

    /* 18. FOOTER */
    .site-footer {
        padding: 16px !important;
    }

    .footer-content {
        flex-direction: column !important;
        gap: 8px !important;
    }

    .footer-links {
        justify-content: center !important;
    }

    /* 19. SETTINGS PAGE */
    .theme-toggle-group {
        flex-direction: column !important;
        gap: 8px !important;
    }

    .theme-btn {
        width: 100% !important;
        justify-content: center !important;
    }

    /* 20. FLEX UTILITIES */
    .flex.gap-md {
        gap: 0.5rem !important;
    }

    .flex.justify-end {
        flex-wrap: wrap !important;
    }

    /* 21. AVATAR UPLOAD */
    .avatar-upload {
        flex-direction: column !important;
    }

    .avatar-preview {
        width: 100px !important;
        height: 100px !important;
    }

    /* 22. SETTINGS MODAL - Mobile Full Screen Fix */
    /* Modal takes full screen on mobile */
    .modal.active,
    #settingsModal.active,
    #generationSettingsModal.active {
        padding: 0 !important;
        align-items: stretch !important;
        justify-content: stretch !important;
    }

    /* Settings card takes full screen */
    .modal.active .settings-card,
    #settingsModal .settings-card,
    #generationSettingsModal .settings-card {
        width: 100% !important;
        max-width: 100% !important;
        height: 100vh !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        margin: 0 !important;
        display: flex !important;
        flex-direction: column !important;
    }

    /* HEADER - Fixed at top, always visible */
    .modal .settings-header,
    #settingsModal .settings-header,
    #generationSettingsModal .settings-header {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        z-index: 9999 !important;
        background: #313338 !important;
        padding: 16px 20px !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        min-height: 56px !important;
    }

    /* Close button - RIGHT SIDE, always visible */
    .modal .settings-header .btn-ghost,
    .modal .settings-header button[onclick*="close"],
    #settingsModal .settings-header button,
    #generationSettingsModal .settings-header button {
        min-width: 44px !important;
        min-height: 44px !important;
        width: 44px !important;
        height: 44px !important;
        font-size: 1.8rem !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: rgba(255, 255, 255, 0.1) !important;
        border-radius: 50% !important;
        color: #fff !important;
        flex-shrink: 0 !important;
        border: 1px solid rgba(255, 255, 255, 0.2) !important;
        cursor: pointer !important;
        padding: 0 !important;
        line-height: 1 !important;
    }

    .modal .settings-header button:active {
        background: rgba(255, 255, 255, 0.25) !important;
        transform: scale(0.95) !important;
    }

    /* Body - scrollable, with padding for fixed header */
    .modal .settings-body,
    #settingsModal .settings-body,
    #generationSettingsModal .settings-body {
        flex: 1 !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        padding-top: 80px !important;
        /* Space for fixed header */
        padding-bottom: 120px !important;
        /* Extra space for bottom buttons + safe area */
        padding-left: 16px !important;
        padding-right: 16px !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: contain !important;
        /* Prevent bounce back */
        height: calc(100vh - 80px) !important;
        max-height: calc(100vh - 80px) !important;
    }

    /* Prevent modal scroll bounce */
    .modal.active {
        overscroll-behavior: contain !important;
        touch-action: pan-y !important;
    }

    .modal .settings-card {
        overflow: hidden !important;
    }

    /* 22b. PRESET CARDS - Mobile Fix */
    .preset-card {
        flex-wrap: wrap !important;
        padding: 12px !important;
    }

    .preset-card-main {
        width: 100% !important;
        flex-shrink: 0 !important;
    }

    /* Show actions always on mobile, not on hover */
    .preset-card-actions {
        position: relative !important;
        right: auto !important;
        top: auto !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        width: 100% !important;
        margin-top: 8px !important;
        flex-wrap: wrap !important;
        justify-content: flex-start !important;
        gap: 6px !important;
    }

    .preset-action-btn {
        padding: 8px 14px !important;
        font-size: 0.75rem !important;
        flex: 0 0 auto !important;
    }

    /* Hide reorder buttons on mobile */
    .preset-card-reorder {
        display: none !important;
    }

    /* Preset badge */
    .preset-card-badge {
        font-size: 0.65rem !important;
        padding: 2px 8px !important;
    }

    /* Edit section on mobile */
    .preset-prompt-section {
        padding-top: 12px !important;
        margin-top: 8px !important;
        border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
    }

    .preset-prompt-textarea {
        font-size: 14px !important;
        min-height: 100px !important;
    }

    /* 23. JANITOR STYLE CARDS */
    .card-janitor {
        min-width: 140px !important;
    }

    .card-janitor .character-name {
        font-size: 11px !important;
    }

    .card-janitor .character-description {
        font-size: 0.65rem !important;
    }

    .character-tags-janitor {
        padding: 0 6px 8px !important;
        gap: 3px !important;
    }

    .tag-system,
    .tag-custom {
        font-size: 10px !important;
        height: 18px !important;
        padding: 0 6px !important;
    }
}

/* ========== SMALL MOBILE BREAKPOINT (480px) ========== */
@media screen and (max-width: 480px) {
    html {
        font-size: 13px !important;
    }

    body {
        font-size: 13px !important;
    }

    .container {
        padding-left: 8px !important;
        padding-right: 8px !important;
    }

    /* Navbar - Even More Compact */
    .nav-container,
    .navbar-content {
        padding: 0 8px !important;
    }

    .nav-logo span,
    .navbar-logo span {
        font-size: 0.9rem !important;
    }

    .nav-links,
    .navbar-nav {
        gap: 0.25rem !important;
    }

    .nav-link {
        padding: 0.3rem 0.4rem !important;
        font-size: 0.7rem !important;
    }

    /* Character Grid - Single/Double Column */
    .character-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }

    .character-card {
        min-height: 220px !important;
    }

    .character-name {
        font-size: 0.8rem !important;
    }

    .character-description {
        font-size: 0.7rem !important;
        -webkit-line-clamp: 2 !important;
        line-clamp: 2 !important;
    }

    /* Personas Grid */
    .personas-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }

    .persona-card-content {
        padding: 8px !important;
    }

    .persona-card-name {
        font-size: 12px !important;
    }

    .create-persona-card {
        min-height: 180px !important;
    }

    .create-icon {
        width: 40px !important;
        height: 40px !important;
        font-size: 24px !important;
    }

    /* Forms */
    .form-input,
    .form-textarea,
    .form-select {
        padding: 0.6rem !important;
    }

    /* Modals */
    .modal-content {
        padding: 12px !important;
        border-radius: 8px !important;
    }

    .modal-title {
        font-size: 1rem !important;
    }

    /* Chat */
    .message-content {
        font-size: 14px !important;
        padding: 0.6rem !important;
    }

    .message-avatar {
        width: 28px !important;
        height: 28px !important;
    }

    /* Cards */
    .card,
    .card-glass,
    .card-glass.p-xl {
        padding: 0.75rem !important;
    }

    /* Buttons */
    .btn {
        font-size: 0.8rem !important;
        padding: 0.5rem 0.75rem !important;
    }

    /* Search */
    .search-input {
        padding: 0.6rem 0.6rem 0.6rem 2.25rem !important;
    }

    /* Tabs */
    .tab {
        font-size: 0.7rem !important;
        padding: 0.4rem 0.5rem !important;
    }

    /* Hero */
    .hero-text {
        font-size: 1.25rem !important;
    }

    .hero-subtext {
        font-size: 0.8rem !important;
    }

    /* Page Headers */
    h1 {
        font-size: 1.5rem !important;
    }

    h2 {
        font-size: 1.25rem !important;
    }

    h3 {
        font-size: 1.1rem !important;
    }

    /* Sidebar */
    .sidebar {
        width: 100% !important;
    }

    .sidebar-avatar {
        width: 60px !important;
        height: 60px !important;
    }

    .sidebar-name {
        font-size: 1rem !important;
    }

    /* Category Filter Buttons */
    #tagsFilter {
        gap: 0.25rem !important;
    }

    #tagsFilter .btn {
        font-size: 0.7rem !important;
        padding: 0.3rem 0.5rem !important;
        min-height: 32px !important;
    }
}

/* ========== LANDSCAPE MOBILE FIX ========== */
@media screen and (max-width: 768px) and (orientation: landscape) {
    .character-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important;
    }

    .modal-content {
        max-height: 85vh !important;
    }

    .chat-messages {
        max-height: calc(100vh - 150px) !important;
    }
}

/* ========== TOUCH DEVICE OPTIMIZATIONS ========== */
@media (hover: none) and (pointer: coarse) {

    /* Larger touch targets */
    .btn,
    .action-btn,
    .nav-btn,
    .tab {
        min-height: 44px !important;
    }

    /* Remove hover effects that don't work on touch */
    .character-card:hover {
        transform: none !important;
    }

    .character-card:hover .card-image {
        transform: none !important;
    }

    .character-card:hover .card-overlay {
        opacity: 1 !important;
    }

    /* MOBILE TOUCH FIX: Ensure card clicks work properly */
    .character-card {
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: transparent !important;
        cursor: pointer !important;
    }

    /* Card overlay should not block touch events */
    .card-overlay {
        pointer-events: none !important;
    }

    /* Show ⋮ menu button on mobile, hide ℹ️ info button */
    .card-info-desktop { display: none !important; }
    .card-menu-mobile { display: inline-flex !important; }

    /* Action buttons - COMPLETELY HIDDEN on mobile to prevent ghost taps */
    .card-actions {
        display: none !important;
    }

    body.edit-mode .card-actions {
        display: flex !important;
        opacity: 1 !important;
        pointer-events: auto !important;
    }

    .card-actions .action-btn {
        pointer-events: auto !important;
        touch-action: manipulation !important;
        min-width: 36px !important;
        min-height: 36px !important;
    }

    /* Better scrolling */
    .character-grid,
    .personas-grid,
    .chat-messages {
        -webkit-overflow-scrolling: touch !important;
    }
}

/* ========== CHAT PAGE MOBILE FIXES - JanitorAI Style ========== */
@media screen and (max-width: 768px) {

    /* ===== CHAT LAYOUT WRAPPER ===== */
    ._chatLayoutWrapper_tront_1,
    ._chatLayoutContainer_tront_8 {
        display: flex !important;
        flex-direction: column !important;
        height: 100vh !important;
        height: 100dvh !important;
        overflow: hidden !important;
    }

    /* ===== HEADER - JanitorAI Style (Single Row) ===== */
    ._headerContainer_1nj3h_1 {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        z-index: 100 !important;
        background: #2b2d31 !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
        padding: 0 !important;
        min-height: auto !important;
    }

    ._headerGrid_1nj3h_17 {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        padding: 10px 12px !important;
        gap: 8px !important;
        max-width: 100% !important;
    }

    ._headerGrid_1nj3h_17>* {
        width: auto !important;
    }

    /* Back Button */
    ._headerGrid_1nj3h_17>div:first-child {
        display: flex !important;
        align-items: center !important;
    }

    ._headerGrid_1nj3h_17>div:first-child button {
        padding: 6px !important;
    }

    ._headerGrid_1nj3h_17>div:first-child span {
        font-size: 0.9rem !important;
        font-weight: 500 !important;
    }

    /* Character Name Divider */
    ._customDivider_7bh05_1 {
        padding: 6px 12px !important;
        background: #313338 !important;
    }

    ._customDividerText_7bh05_26 button {
        font-size: 0.9rem !important;
    }

    /* Model Indicator Badge */
    #modelIndicator {
        font-size: 0.7rem !important;
        padding: 4px 8px !important;
        margin-right: 4px !important;
    }

    /* Menu Button */
    ._menuButton_hs488_60 {
        width: 36px !important;
        height: 36px !important;
    }

    ._menuIcon_hs488_88 {
        width: 1.25rem !important;
        height: 1.25rem !important;
    }

    /* ===== MESSAGES CONTAINER ===== */
    ._messagesWrapper_1swu7_1 {
        flex: 1 !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        padding: 0 !important;
        padding-top: 90px !important;
        /* Header space */
        padding-bottom: 80px !important;
        /* Input space */
        -webkit-overflow-scrolling: touch !important;
    }

    ._messagesMain_1swu7_10 {
        max-width: 100% !important;
        width: 100% !important;
        padding: 0 !important;
    }

    #message-list {
        padding: 8px !important;
    }

    /* ===== INDIVIDUAL MESSAGES - JanitorAI Style ===== */
    .message-container,
    ._messageDisplayWrapper_2xqwb_2 {
        display: flex !important;
        align-items: flex-start !important;
        padding: 12px 8px !important;
        margin-bottom: 0 !important;
        border: none !important;
        border-bottom: none !important;
        gap: 10px !important;
        background: transparent !important;
    }

    /* Message Avatar */
    .message-avatar,
    ._messageAvatarImage_1v19f_305 {
        width: 42px !important;
        height: 42px !important;
        border-radius: 50% !important;
        flex-shrink: 0 !important;
        object-fit: cover !important;
    }

    /* Message Content Area */
    ._messageContent_2xqwb_26,
    .message-content-wrapper {
        flex: 1 !important;
        min-width: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 6px !important;
    }

    /* Message Header (Name + Actions) */
    ._nameContainer_1v19f_270,
    .message-header {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 8px !important;
        margin-bottom: 4px !important;
    }

    ._nameText_1v19f_275,
    .message-name {
        font-size: 14px !important;
        font-weight: 600 !important;
        color: #f2f3f5 !important;
    }

    /* Action Buttons - Always visible on mobile */
    ._controlPanel_1v19f_2,
    .msg-actions {
        display: flex !important;
        align-items: center !important;
        gap: 4px !important;
        opacity: 1 !important;
    }

    ._controlPanelButton_1v19f_8,
    .msg-action-btn {
        width: 28px !important;
        height: 28px !important;
        min-width: 28px !important;
        min-height: 28px !important;
        padding: 4px !important;
        border-radius: 4px !important;
        font-size: 14px !important;
        background: transparent !important;
        color: #9ca3af !important;
    }

    .msg-action-btn:hover,
    ._controlPanelButton_1v19f_8:hover {
        background: rgba(255, 255, 255, 0.1) !important;
        color: #fff !important;
    }

    /* Message Body Text */
    ._messageBody_2xqwb_60,
    .message-content,
    .prose {
        font-size: 13px !important;
        line-height: 1.6 !important;
        color: #dbdee1 !important;
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
        max-width: 100% !important;
    }

    /* Italic text (narration) */
    ._messageBody_2xqwb_60 em,
    .message-content em,
    .prose em {
        color: #9ca3af !important;
    }

    /* Star Rating */
    ._ratingWrapper_1v19f_361 {
        margin-top: 12px !important;
        display: flex !important;
        align-items: center !important;
        gap: 4px !important;
    }

    ._starIcon_165md_15 {
        width: 18px !important;
        height: 18px !important;
    }

    /* Alternative Navigation (swipe between messages) */
    .alt-nav-bottom {
        display: flex !important;
        align-items: center !important;
        justify-content: flex-end !important;
        gap: 2px !important;
        margin-top: 8px !important;
    }

    .alt-nav-btn-bottom {
        width: 24px !important;
        height: 24px !important;
    }

    .alt-counter-bottom {
        font-size: 11px !important;
    }

    /* ===== INPUT AREA - Fixed Bottom ===== */
    ._chatInputContainer_14uqx_1 {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        background: #2b2d31 !important;
        border-top: 1px solid rgba(255, 255, 255, 0.08) !important;
        padding: 10px 12px !important;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)) !important;
        z-index: 100 !important;
    }

    ._chatInputWrapper_14uqx_17 {
        display: flex !important;
        align-items: flex-end !important;
        gap: 8px !important;
        padding: 0 !important;
    }

    ._chatInputInner_14uqx_30 {
        flex: 1 !important;
        max-width: calc(100% - 50px) !important;
        margin: 0 !important;
        background: #383a40 !important;
        background-color: #383a40 !important;
        border: none !important;
        border-color: transparent !important;
        border-radius: 8px !important;
        position: relative !important;
        box-shadow: none !important;
        outline: none !important;
        overflow: hidden !important;
    }

    ._prideRainbowBorder_14uqx_57::before,
    ._prideRainbowBorder_14uqx_57::after {
        display: none !important;
    }

    ._chatTextarea_dzva7_1 {
        width: 100% !important;
        padding: 10px 45px 10px 16px !important;
        font-size: 15px !important;
        min-height: 42px !important;
        max-height: 120px !important;
        background: transparent !important;
        border: none !important;
        color: #fff !important;
        resize: none !important;
    }

    ._chatTextarea_dzva7_1::placeholder {
        color: #6b7280 !important;
    }

    /* Send/Stop Button - Inside input container */
    ._sendButton_17cr1_106,
    ._stopButton_17cr1_1 {
        position: relative !important;
        flex-shrink: 0 !important;
        width: 36px !important;
        height: 36px !important;
        border-radius: 8px !important;
        background: #805ad5 !important;
        color: #fff !important;
        border: none !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    ._stopButton_17cr1_1 {
        background: #ef4444 !important;
    }

    /* Card Button (bottom right) */
    ._cardButton_14uqx_99 {
        position: absolute !important;
        right: 45px !important;
        bottom: 8px !important;
        font-size: 11px !important;
        padding: 4px 8px !important;
    }

    /* ===== MODALS / SETTINGS ===== */
    .settings-card {
        width: 100% !important;
        max-width: 100% !important;
        max-height: 90vh !important;
        border-radius: 16px 16px 0 0 !important;
        margin-top: auto !important;
    }

    .settings-header {
        padding: 14px 16px !important;
    }

    .settings-header h3 {
        font-size: 1rem !important;
    }

    .settings-body {
        padding: 14px !important;
        gap: 14px !important;
    }

    .setting-group {
        padding: 12px !important;
    }

    .setting-group h4 {
        font-size: 0.7rem !important;
        margin-bottom: 12px !important;
    }

    .form-label {
        font-size: 0.8rem !important;
    }

    .form-input {
        padding: 8px !important;
        font-size: 0.85rem !important;
    }

    /* Generation Settings */
    .gen-setting-row {
        margin-bottom: 16px !important;
        padding-bottom: 14px !important;
    }

    .gen-setting-label {
        font-size: 13px !important;
    }

    .gen-setting-value {
        width: 65px !important;
        padding: 6px 8px !important;
        font-size: 12px !important;
    }

    .gen-slider {
        height: 8px !important;
    }

    .gen-slider::-webkit-slider-thumb {
        width: 20px !important;
        height: 20px !important;
    }

    /* Preset Cards */
    .preset-card {
        padding: 10px 12px !important;
    }

    .preset-card-name {
        font-size: 0.85rem !important;
    }

    .preset-card-details {
        font-size: 0.7rem !important;
    }

    /* Bot Choices Slider */
    ._botChoicesContainer_sisz1_1 {
        padding-bottom: 8px !important;
    }

    ._botChoiceButton_sisz1_26 {
        width: 36px !important;
        height: 36px !important;
    }

    /* Think Tag Container */
    ._thinkContent_ll1ul_16 {
        border-radius: 8px !important;
    }

    ._thinkHeader_ll1ul_28 {
        padding: 6px 10px !important;
    }

    ._thinkBody_ll1ul_99 {
        padding: 8px 10px !important;
        font-size: 0.7rem !important;
        max-height: 80px !important;
    }

    /* Accordion Panels */
    ._accordionPanel_1k67a_23 {
        width: calc(100vw - 16px) !important;
        max-width: 100% !important;
    }

    ._panelContent_1k67a_50 {
        padding: 12px !important;
        max-height: 50vh !important;
    }

    /* Alternative Navigation */
    .alt-nav-bottom {
        gap: 2px !important;
        margin-top: 10px !important;
        padding-top: 8px !important;
    }

    .alt-nav-btn-bottom {
        width: 28px !important;
        height: 28px !important;
    }

    .alt-counter-bottom {
        font-size: 12px !important;
        min-width: 32px !important;
    }

    /* Edit Textarea */
    .edit-textarea {
        font-size: 14px !important;
        padding: 10px 12px !important;
    }

    /* Embedded Images in Chat */
    .chat-embedded-image {
        max-width: 100% !important;
        max-height: 200px !important;
    }

    /* Star Rating in Messages */
    ._starIcon_165md_15 {
        width: 0.8rem !important;
        height: 0.8rem !important;
    }

    ._ratingWrapper_1v19f_361 {
        bottom: -1rem !important;
    }
}

/* Chat Mobile - Extra Small Screens */
@media screen and (max-width: 480px) {
    ._headerContainer_1nj3h_1 {
        padding: 6px 8px !important;
    }

    ._headerGrid_1nj3h_17 span {
        font-size: 0.75rem !important;
    }

    ._messageAvatarImage_1v19f_305 {
        width: 32px !important;
        height: 32px !important;
    }

    ._messageBody_2xqwb_60,
    .message-content,
    .prose {
        font-size: 13px !important;
    }

    ._nameText_1v19f_275 {
        font-size: 12px !important;
    }

    ._chatTextarea_dzva7_1 {
        font-size: 14px !important;
        min-height: 38px !important;
    }

    ._sendButton_17cr1_106,
    ._stopButton_17cr1_1 {
        width: 28px !important;
        height: 28px !important;
    }

    .settings-card {
        max-height: 100vh !important;
        border-radius: 0 !important;
    }

    .gen-setting-label {
        font-size: 12px !important;
    }

    .gen-setting-value {
        width: 55px !important;
        font-size: 11px !important;
    }
}

/* ========== CHAT ERROR NOTIFICATION - JanitorAI Style (Fixed Top Center) ========== */
.chat-error-notification {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    z-index: 99999;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: rgba(30, 25, 35, 0.95);
    border: 1px solid rgba(239, 68, 68, 0.4);
    border-radius: 10px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(239, 68, 68, 0.1);
    backdrop-filter: blur(12px);
    max-width: 90vw;
    min-width: 280px;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: auto;
}

.chat-error-notification.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.chat-error-notification.hide {
    opacity: 0;
    transform: translateX(-50%) translateY(-20px);
}

.chat-error-notification .chat-error-icon {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(239, 68, 68, 0.2);
    border-radius: 50%;
    color: #ef4444;
}

.chat-error-notification .chat-error-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.chat-error-notification .chat-error-title {
    color: #ffffff;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
    word-break: break-word;
}

.chat-error-notification .chat-error-status {
    color: #9ca3af;
    font-size: 12px;
    font-weight: 400;
}

.chat-error-notification .chat-error-dismiss {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: #6b7280;
    cursor: pointer;
    border-radius: 6px;
    font-size: 18px;
    font-weight: bold;
    line-height: 1;
    transition: all 0.15s ease;
    margin-left: 8px;
}

.chat-error-notification .chat-error-dismiss:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

/* Mobile responsive */
@media screen and (max-width: 768px) {
    .chat-error-notification {
        top: 10px;
        left: 10px;
        right: 10px;
        transform: translateY(-20px);
        max-width: none;
        min-width: auto;
    }

    .chat-error-notification.show {
        transform: translateY(0);
    }

    .chat-error-notification.hide {
        transform: translateY(-20px);
    }

    .chat-error-notification .chat-error-title {
        font-size: 13px;
    }

    .chat-error-notification .chat-error-status {
        font-size: 11px;
    }
}

/* Character Details Modal Styles */
#charDetailsModal {
    display: none;
    /* Hidden by default */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    /* Dark overlay */
    backdrop-filter: blur(5px);
    z-index: 10000;
    justify-content: center;
    align-items: center;
    padding: 15px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#charDetailsModal.active {
    opacity: 1;
}

#charDetailsContent {
    background: #18181b;
    /* Zinc 900 */
    border: 1px solid rgba(139, 92, 246, 0.2);
    /* Violet border */
    border-radius: 16px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: scale(0.95);
    transition: transform 0.3s ease;
}

#charDetailsModal.active #charDetailsContent {
    transform: scale(1);
}

/* Header with Avatar and Basic Info */
.char-details-header {
    padding: 20px;
    background: linear-gradient(to bottom, rgba(139, 92, 246, 0.1), transparent);
    display: flex;
    gap: 16px;
    align-items: flex-start;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.char-details-avatar {
    width: 80px;
    height: 80px;
    border-radius: 12px;
    object-fit: cover;
    border: 2px solid rgba(139, 92, 246, 0.3);
    flex-shrink: 0;
}

.char-details-header-info {
    flex: 1;
    min-width: 0;
    /* Prevent overlap */
}

.char-details-name {
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    margin: 0 0 4px 0;
    line-height: 1.2;
}

.char-details-creator {
    font-size: 0.85rem;
    color: #9ca3af;
    margin-bottom: 8px;
}

.char-details-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.char-details-tag {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    color: #d1d5db;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Scrollable Content Body */
.char-details-body {
    padding: 20px;
    overflow-y: auto;
    color: #e4e4e7;
    font-size: 0.95rem;
    line-height: 1.6;
}

/* Sections */
.char-info-section {
    margin-bottom: 24px;
}

.char-section-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #a78bfa;
    /* Violet 400 */
    margin-bottom: 8px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}

.char-section-content {
    background: rgba(0, 0, 0, 0.2);
    padding: 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.03);
    white-space: pre-wrap;
    /* Preserve line breaks */
    word-break: break-word;
    /* Prevent overflow */
    max-height: 300px;
    overflow-y: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.85rem;
}

/* Close Button */
.char-details-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.3);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: background 0.2s;
    z-index: 10;
}

.char-details-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Info Icon on Card */
.card-info-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    font-size: 1.1rem;
    color: rgba(167, 139, 250, 0.8);
    transition: all 0.2s;
    line-height: 1;
}

.card-info-btn:hover {
    color: #fff;
    transform: scale(1.1);
    background: rgba(139, 92, 246, 0.2);
    border-radius: 4px;
}

/* ========== MOBILE: Message Header - Name Truncation Fix ========== */
/* Fix for long character names overlapping action buttons on mobile */
@media screen and (max-width: 768px) {

    /* Message header row - FORCE proper flex layout */
    .message-header-row {
        display: flex !important;
        align-items: center !important;
        gap: 4px !important;
        flex-wrap: nowrap !important;
        width: 100% !important;
        overflow: hidden !important;
    }

    /* Character name - HARD LIMIT with ellipsis */
    .message-name-text {
        max-width: 180px !important;
        /* Increased for longer names */
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
        flex: 0 1 auto !important;
        display: inline-block !important;
    }

    /* Verified badge - don't shrink */
    .message-header-row>span:nth-child(2) {
        flex-shrink: 0 !important;
    }

    /* FORCE action buttons to show */
    .msg-actions {
        flex: 0 0 auto !important;
        margin-left: auto !important;
        opacity: 1 !important;
        display: flex !important;
        gap: 2px !important;
        visibility: visible !important;
    }

    /* Compact action buttons */
    .msg-action-btn {
        width: 28px !important;
        height: 28px !important;
        min-width: 28px !important;
        padding: 4px !important;
        flex-shrink: 0 !important;
    }

    .msg-action-btn svg {
        width: 14px !important;
        height: 14px !important;
    }
}

/* Extra small screens */
@media screen and (max-width: 400px) {
    .message-name-text {
        max-width: 80px !important;
    }

    .msg-action-btn {
        width: 24px !important;
        height: 24px !important;
        min-width: 24px !important;
        padding: 2px !important;
    }

    .msg-action-btn svg {
        width: 12px !important;
        height: 12px !important;
    }
}

/* Fix for settings dropdown overflow on mobile/desktop */
._menuList_162rw_8 {
    right: 0 !important;
    left: auto !important;
    transform-origin: top right !important;
    max-width: calc(100vw - 32px) !important;
}

/* ========== TOAST NOTIFICATION ========== */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 999999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: #1a1f2e;
    border: 1px solid rgba(255,255,255,0.10);
    border-radius: 12px;
    padding: 14px 16px 10px 16px;
    min-width: 320px;
    max-width: 400px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.45), 0 2px 8px rgba(0,0,0,0.3);
    display: flex;
    align-items: flex-start;
    gap: 12px;
    pointer-events: all;
    position: relative;
    overflow: hidden;
    transform: translateX(calc(100% + 24px));
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1), opacity 0.25s ease;
}

.toast.toast-visible {
    transform: translateX(0);
    opacity: 1;
}

.toast.toast-hiding {
    transform: translateX(calc(100% + 24px));
    opacity: 0;
    transition: transform 0.25s ease-in, opacity 0.2s ease-in;
}

.toast-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    flex-shrink: 0;
    margin-top: 1px;
}

.toast-body { flex: 1; min-width: 0; }

.toast-title {
    font-size: 13px;
    font-weight: 600;
    color: #f3f4f6;
    line-height: 1.3;
    margin-bottom: 2px;
}

.toast-msg {
    font-size: 12px;
    color: #9ca3af;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.toast-close {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 0;
    font-size: 16px;
    line-height: 1;
    flex-shrink: 0;
    margin-top: -1px;
    transition: color 0.15s;
}
.toast-close:hover { color: #d1d5db; }

.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    border-radius: 0 0 12px 12px;
    transition: width linear;
}

.toast-success .toast-icon { background: rgba(16,185,129,0.15); color: #10b981; }
.toast-success .toast-progress { background: #10b981; }
.toast-error .toast-icon { background: rgba(239,68,68,0.15); color: #ef4444; }
.toast-error .toast-progress { background: #ef4444; }
.toast-info .toast-icon { background: rgba(99,102,241,0.15); color: #6366f1; }
.toast-info .toast-progress { background: #6366f1; }
.toast-warning .toast-icon { background: rgba(245,158,11,0.15); color: #f59e0b; }
.toast-warning .toast-progress { background: #f59e0b; }

/* ========== CHARACTER CARD HIGHLIGHT ========== */
@keyframes cardHighlightPulse {
    0%   { box-shadow: 0 0 0 0 rgba(139,92,246,0.9), 0 0 40px rgba(139,92,246,0.5); border-color: #8b5cf6; }
    40%  { box-shadow: 0 0 0 10px rgba(139,92,246,0),  0 0 60px rgba(139,92,246,0.3); border-color: #a78bfa; }
    100% { box-shadow: 0 0 0 0   rgba(139,92,246,0),   0 0 0   rgba(139,92,246,0);   border-color: transparent; }
}
.card-highlighted {
    animation: cardHighlightPulse 2.5s ease-out forwards !important;
    position: relative;
    z-index: 10;
}

/* ==========================================================================
   MOBILE MODAL LAYOUT — pinned footer (iOS Chrome/Safari toolbar fix)
   --------------------------------------------------------------------------
   Earlier blocks in this file force `.settings-card { height: 100vh }` and
   `.settings-body { height: calc(100vh - 80px) }` with a fixed header. On iOS
   `100vh` is the LARGE viewport (browser toolbars hidden), so the bottom of
   the card renders *behind* Chrome's bottom toolbar and the Save Changes
   button becomes unreachable — the page is scroll-locked (html/body are
   position:fixed) so the toolbars never collapse to make room.

   Fix: `dvh` (visible viewport) instead of `vh`, header back in normal flow,
   body as the only flexible/scrolling child, and `.settings-footer` pinned as
   a non-scrolling sibling with safe-area padding.

   Selectors repeat the ID form so specificity matches the earlier rules;
   being last in the file breaks the tie.
   ========================================================================== */
@media screen and (max-width: 768px) {

    #settingsModal .settings-card,
    #generationSettingsModal .settings-card,
    #promptInspectorModal .settings-card,
    #memoryModal .settings-card,
    #forkChatModal .settings-card,
    #editMessageModal .settings-card,
    .modal.active .settings-card {
        height: 100vh !important;
        height: 100dvh !important;
        max-height: 100vh !important;
        max-height: 100dvh !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        border-radius: 0 !important;
        margin: 0 !important;
    }

    /* Header back in normal flow: same visual result as position:fixed, but it
       no longer forces the body to fake its own height with padding-top. */
    #settingsModal .settings-header,
    #generationSettingsModal .settings-header,
    #promptInspectorModal .settings-header,
    #memoryModal .settings-header,
    #forkChatModal .settings-header,
    #editMessageModal .settings-header,
    .modal.active .settings-header {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        right: auto !important;
        flex: 0 0 auto !important;
        padding-top: calc(14px + env(safe-area-inset-top, 0px)) !important;
    }

    /* The body is the ONLY part that scrolls, and it sizes itself from the
       flex container — no explicit height, no padding-top compensation. */
    #settingsModal .settings-body,
    #generationSettingsModal .settings-body,
    #promptInspectorModal .settings-body,
    #memoryModal .settings-body,
    #forkChatModal .settings-body,
    #editMessageModal .settings-body,
    .modal.active .settings-body {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        height: auto !important;
        max-height: none !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        padding: 14px !important;
        padding-bottom: 24px !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: contain !important;
    }

    /* Pinned action bar. Never scrolls, always above the browser toolbar. */
    #settingsModal .settings-footer,
    #generationSettingsModal .settings-footer,
    #promptInspectorModal .settings-footer,
    #memoryModal .settings-footer,
    #forkChatModal .settings-footer,
    #editMessageModal .settings-footer,
    .modal.active .settings-footer {
        flex: 0 0 auto !important;
        display: flex !important;
        gap: 10px !important;
        justify-content: flex-end !important;
        padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px)) !important;
        background: #2b2d31 !important;
        border-top: 1px solid rgba(255, 255, 255, 0.08) !important;
        box-shadow: 0 -6px 16px rgba(0, 0, 0, 0.35) !important;
    }

    .modal .settings-footer .btn {
        min-height: 44px !important;
        flex: 1 1 auto !important;
        justify-content: center !important;
    }
}

/* Very small screens: same rules, just tighter padding. */
@media screen and (max-width: 480px) {

    #settingsModal .settings-footer,
    #generationSettingsModal .settings-footer,
    #memoryModal .settings-footer,
    #forkChatModal .settings-footer,
    #editMessageModal .settings-footer,
    .modal.active .settings-footer {
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)) !important;
    }
}

/* ==========================================================================
   iOS INPUT ZOOM — form fields must stay >= 16px
   --------------------------------------------------------------------------
   An earlier mobile block drops .form-input to 0.85rem (11.9px at the 14px
   mobile root). Safari and Chrome on iOS auto-zoom the page whenever a focused
   field is under 16px, which is what makes editing a message on a phone feel
   like fighting the viewport. Restore the 16px the earlier @media block at the
   top of this file already intended.
   ========================================================================== */
@media screen and (max-width: 768px) {

    .form-input,
    .form-textarea,
    .form-select,
    .edit-textarea,
    .preset-prompt-textarea,
    #editMessageTextarea,
    #chat-textarea,
    ._chatTextarea_dzva7_1 {
        font-size: 16px !important;
    }

    /* Comfortable line length and spacing for the full-screen editor. */
    #editMessageTextarea {
        line-height: 1.6 !important;
        padding: 12px !important;
        min-height: 0 !important;
        flex: 1 1 auto !important;
    }
}
