:root {
    --viewport-height: 100vh;
}

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

        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            font-size: 15px;
            line-height: 1.6;
            background: #212121;
            color: #ececec;
            height: var(--viewport-height);
            min-height: var(--viewport-height);
            overflow: hidden;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
        }
        body[data-environment="staging"] .main-content {
            background: #041708;
        }

        body[data-environment="staging"] {
            background: linear-gradient(135deg, #0b1f0f 0%, #041708 100%);
        }

        /* Emoji font support - simplified */
        .upgrade-callout,
        .upgrade-callout h4,
        .upgrade-callout li,
        .metadata-badge,
        .advertisement-label,
        .message-metadata {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
        }

        .app {
            display: flex;
            flex-direction: row;
            height: var(--viewport-height);
            min-height: var(--viewport-height);
            width: 100%;
        }

        /* Sidebar */
        .sidebar {
            width: 260px;
            background: #171717;
            border-right: 1px solid #2f2f2f;
            display: flex;
            flex-direction: column;
            flex-shrink: 0;
            transition: width 0.3s ease, transform 0.3s ease, border-width 0.3s ease;
            overflow: hidden;
        }

        .sidebar.collapsed {
            width: 0;
            border-right-width: 0;
            transform: translateX(-260px);
        }

        .sidebar-header {
            padding: 16px;
            border-bottom: 1px solid #2f2f2f;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .new-chat-button {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 10px 16px;
            background: #2f2f2f;
            border: 1px solid #4d4d4d;
            border-radius: 8px;
            color: #ececec;
            font-size: 14px;
            font-weight: 500;
            cursor: pointer;
            transition: background 0.2s;
            width: 100%;
        }

        .new-chat-button:hover {
            background: #3f3f3f;
        }

        .conversations {
            flex: 1;
            overflow-y: auto;
            padding: 8px;
        }

        /* Project Section */
        .project-section {
            margin-bottom: 8px;
        }

        .project-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 8px 12px;
            cursor: pointer;
            color: #ececec;
            font-weight: 500;
            font-size: 13px;
            border-radius: 6px;
            transition: background 0.2s;
            /* Use system-ui first (has built-in emoji support), then emoji fonts */
            font-family: system-ui, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "Android Emoji", "EmojiOne Color", "EmojiOne Mozilla", "Twemoji Mozilla", "Noto Emoji", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            font-variant-emoji: emoji;
            -webkit-font-smoothing: antialiased;
        }

        .project-header:hover {
            background: #2f2f2f;
        }

        .project-header-left {
            display: flex;
            align-items: center;
            gap: 8px;
            /* Ensure emoji fonts are available */
            font-family: system-ui, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "Android Emoji", "EmojiOne Color", "EmojiOne Mozilla", "Twemoji Mozilla", "Noto Emoji", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
        }
        
        .project-name {
            /* Ensure emoji rendering for project names */
            font-family: system-ui, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "Android Emoji", "EmojiOne Color", "EmojiOne Mozilla", "Twemoji Mozilla", "Noto Emoji", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            font-variant-emoji: emoji;
            -webkit-font-smoothing: antialiased;
        }

        .project-chevron {
            font-size: 12px;
            transition: transform 0.2s;
            /* Ensure emoji rendering for chevron */
            font-family: system-ui, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "Android Emoji", "EmojiOne Color", "EmojiOne Mozilla", "Twemoji Mozilla", "Noto Emoji", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            font-variant-emoji: emoji;
            -webkit-font-smoothing: antialiased;
        }

        .project-section.collapsed .project-chevron {
            transform: rotate(-90deg);
        }

        .project-content {
            padding-left: 8px;
            max-height: 1000px;
            overflow: hidden;
            transition: max-height 0.3s ease;
        }

        .project-section.collapsed .project-content {
            max-height: 0;
        }

        /* Conversation Item */
        .conversation-item {
            padding: 8px 12px;
            margin: 2px 0;
            border-radius: 6px;
            cursor: pointer;
            display: flex;
            justify-content: space-between;
            align-items: center;
            transition: background 0.2s;
            color: #b4b4b4;
            font-size: 13px;
            padding-left: 24px;
            /* Ensure emoji fonts are available for conversation items */
            font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "Android Emoji", "EmojiOne Color", "EmojiOne Mozilla", "Twemoji Mozilla", "Noto Emoji", sans-serif;
        }

        .conversation-item:hover {
            background: #2f2f2f;
            color: #ececec;
        }

        .conversation-item.active {
            background: #2f2f2f;
            color: #ececec;
        }

        /* Ensure tooltip positioning */
        .conversation-item { position: relative; }

        /* Unauthenticated state: show history greyed out with hover invite */
        .sidebar.unauth .conversations .conversation-item {
            opacity: 0.5;
        }
        .sidebar.unauth .conversations .conversation-item:hover {
            opacity: 0.8;
        }
        .sidebar.unauth .conversations .conversation-item::after {
            content: 'Sign in to open history';
            position: absolute;
            right: 12px;
            top: 50%;
            transform: translateY(-50%);
            background: rgba(33,33,33,0.95);
            color: #b4b4b4;
            border: 1px solid #4d4d4d;
            padding: 6px 8px;
            border-radius: 6px;
            font-size: 11px;
            white-space: nowrap;
            display: none;
            pointer-events: none;
        }
        .sidebar.unauth .conversations .conversation-item:hover::after {
            display: block;
        }

        .conversation-item.has-files {
            cursor: default;
        }

        .conversation-header {
            display: flex;
            align-items: center;
            gap: 6px;
            flex: 1;
            overflow: hidden;
        }

        .conversation-chevron {
            font-size: 10px;
            transition: transform 0.2s;
            color: #666;
        }

        .conversation-item.collapsed .conversation-chevron {
            transform: rotate(-90deg);
        }

        .conversation-text {
            flex: 1;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            /* Use system-ui first (has built-in emoji support), then emoji fonts, then text fonts */
            font-family: system-ui, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "Android Emoji", "EmojiOne Color", "EmojiOne Mozilla", "Twemoji Mozilla", "Noto Emoji", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            letter-spacing: normal;
            line-height: 1.4;
            /* Ensure proper emoji rendering */
            font-feature-settings: "liga", "kern";
            text-rendering: optimizeLegibility;
            -webkit-font-smoothing: antialiased;
            /* Explicitly enable emoji rendering */
            font-variant-emoji: emoji;
            /* Prevent text from being treated as HTML entities */
            unicode-bidi: embed;
        }

        .conversation-date {
            font-size: 11px;
            color: #666;
            margin-top: 4px;
        }

        .conversation-actions {
            display: flex;
            gap: 4px;
            opacity: 0;
            transition: opacity 0.2s;
        }

        .conversation-item:hover .conversation-actions {
            opacity: 1;
        }

        .conversation-action-btn {
            padding: 2px 6px;
            background: transparent;
            border: none;
            color: #999;
            cursor: pointer;
            border-radius: 4px;
            font-size: 14px;
            transition: all 0.2s;
        }

        .conversation-action-btn:hover {
            background: #4d4d4d;
            color: #ececec;
        }

        /* Sign-in CTA button for unauth sidebar */
        .signin-cta {
            border-color: #19c37d;
            color: #19c37d;
        }
        .signin-cta:hover {
            background: rgba(25, 195, 125, 0.1);
            border-color: #20e68c;
            color: #20e68c;
        }

        .delete-conversation:hover {
            background: #dc3545;
            color: white;
        }

        /* File List */
        .file-list {
            padding-left: 16px;
            max-height: 500px;
            overflow: hidden;
            transition: max-height 0.3s ease;
        }

        .conversation-item.collapsed .file-list {
            max-height: 0;
        }

        .file-item {
            padding: 6px 12px;
            margin: 2px 0;
            border-radius: 4px;
            cursor: pointer;
            color: #8e8ea0;
            font-size: 12px;
            display: flex;
            align-items: center;
            gap: 6px;
            transition: background 0.2s;
        }

        .file-item:hover {
            background: #2f2f2f;
            color: #ececec;
        }

        .file-item.active {
            background: #2f2f2f;
            color: #ececec;
        }

        .file-icon {
            font-size: 12px;
            color: #666;
        }

        .file-name {
            flex: 1;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        /* Sign In Prompt */
        .sign-in-prompt {
            display: none;
            padding: 20px;
            text-align: center;
        }

        .sign-in-prompt.active {
            display: block;
        }

        .sign-in-prompt h3 {
            font-size: 16px;
            font-weight: 600;
            color: #ececec;
            margin-bottom: 12px;
        }

        .sign-in-prompt p {
            font-size: 14px;
            color: #8e8ea0;
            margin-bottom: 20px;
            line-height: 1.5;
        }

        .sign-in-prompt .google-signin-wrapper {
            display: flex;
            justify-content: center;
        }

        .supabase-signin-button {
            padding: 12px 24px;
            background: #fff;
            color: #212121;
            border: none;
            border-radius: 8px;
            font-size: 14px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.2s;
            display: inline-flex;
            align-items: center;
            gap: 8px;
        }

        .supabase-signin-button:hover {
            background: #f0f0f0;
            transform: translateY(-1px);
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }

        .supabase-signin-button:active {
            transform: translateY(0);
        }

        .sign-in-benefits {
            margin-top: 20px;
            text-align: left;
            padding: 16px;
            background: #2f2f2f;
            border-radius: 8px;
        }

        .sign-in-benefits h4 {
            font-size: 13px;
            font-weight: 600;
            color: #ececec;
            margin-bottom: 12px;
        }

        .sign-in-benefits ul {
            list-style: none;
            padding: 0;
        }

        .sign-in-benefits li {
            font-size: 13px;
            color: #b4b4b4;
            margin-bottom: 8px;
            padding-left: 20px;
            position: relative;
        }

        .sign-in-benefits li:before {
            content: "?";
            position: absolute;
            left: 0;
            color: #19c37d;
            font-weight: bold;
        }
          
          .chat-history-panel {
              padding: 16px;
              border-top: 1px solid #2f2f2f;
              background: #141414;
              flex-shrink: 0;
          }
          
          .history-panel-headline {
              display: flex;
              flex-direction: column;
              gap: 4px;
          }
          
          .history-panel-title {
              font-size: 13px;
              font-weight: 600;
              color: #ececec;
              letter-spacing: 0.02em;
          }
          
          .history-panel-description {
              font-size: 12px;
              color: #8e8ea0;
              line-height: 1.4;
          }
          
          .history-panel-actions {
              margin-top: 12px;
              display: flex;
              gap: 8px;
              flex-wrap: wrap;
          }
          
          .history-panel-button {
              flex: 1;
              min-width: 0;
              display: inline-flex;
              align-items: center;
              justify-content: center;
              gap: 6px;
              padding: 8px 10px;
              border-radius: 8px;
              border: 1px solid #4d4d4d;
              background: #1f1f1f;
              color: #ececec;
              font-size: 13px;
              font-weight: 500;
              cursor: pointer;
              transition: background 0.2s, border-color 0.2s;
          }
          
          .history-panel-button svg {
              width: 16px;
              height: 16px;
          }
          
          .history-panel-button:hover {
              background: #2c2c2c;
              border-color: #5d5d5d;
          }
          
          .history-panel-button:active {
              background: #242424;
          }
          
          .history-panel-button:disabled {
              opacity: 0.5;
              cursor: not-allowed;
          }
          
          .history-status-text {
              margin-top: 12px;
              font-size: 12px;
              color: #8e8ea0;
              line-height: 1.4;
          }
          
          .history-status-text.success {
              color: #19c37d;
          }
          
          .history-status-text.error {
              color: #ef4444;
          }

        .sidebar-toggle {
            position: fixed;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            background: #2f2f2f;
            border: 1px solid #4d4d4d;
            border-left: none;
            border-radius: 0 8px 8px 0;
            padding: 12px 8px;
            cursor: pointer;
            /* Keep the toggle above the mobile sidebar so it stays clickable */
            z-index: 1101;
            transition: left 0.3s ease;
        }

        .sidebar-toggle.sidebar-open {
            left: 260px;
        }

        .sidebar-toggle:hover {
            background: #3f3f3f;
        }

        .main-content {
            flex: 1;
            display: flex;
            flex-direction: column;
            min-width: 0; /* Allow flex item to shrink below content size */
            overflow: hidden;
            transition: width 0.3s ease;
        }

        /* Header */
        .header {
            height: 52px;
            background: #212121;
            border-bottom: 1px solid #4d4d4d;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 16px;
            flex-shrink: 0;
        }

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

        .logo {
            height: 24px;
            width: auto;
        }

        .header-title {
            font-size: 14px;
            font-weight: 600;
            color: #ececec;
        }

        .header-right {
            display: flex;
            align-items: center;
            gap: 12px;
        }

        #authButtons {
            display: flex;
        }

        .user-info {
            display: none;
            align-items: center;
            gap: 10px;
        }

        .user-info.active {
            display: flex;
        }

        .user-avatar {
            width: 32px;
            height: 32px;
            border-radius: 50%;
        }

        .user-name {
            font-size: 14px;
            color: #ececec;
        }

        .logout-button {
            padding: 6px 12px;
            background: transparent;
            border: 1px solid #4d4d4d;
            border-radius: 6px;
            color: #ececec;
            font-size: 13px;
            cursor: pointer;
            transition: all 0.2s;
        }

        .logout-button:hover {
            background: #2f2f2f;
        }

        /* Main Content */
        .main {
            flex: 1;
            display: flex;
            flex-direction: column;
            overflow: hidden;
            position: relative;
        }

        /* Empty state - everything centered */
        .app:not(.has-messages) .main {
            justify-content: center;
        }

        /* Messages Area */
        .messages {
            flex: 1;
            overflow-y: auto;
            overflow-x: hidden; /* Prevent horizontal scroll */
            display: flex;
            flex-direction: column;
            width: 100%;
            padding-bottom: 20px; /* Add padding to prevent footer occlusion */
        }

        .app:not(.has-messages) .messages {
            flex: 0;
            overflow: visible;
        }

        .messages-inner {
            flex: 1;
            display: flex;
            flex-direction: column;
            width: 100%;
            min-width: 0; /* Allow flex item to shrink */
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "Android Emoji", "EmojiOne Color", "EmojiOne Mozilla", "Twemoji Mozilla", "Noto Emoji", sans-serif;
            letter-spacing: normal;
            padding-bottom: 80px; /* Extra padding to ensure last message is visible above input */
        }

        /* Empty state - centered */
        .app:not(.has-messages) .messages-inner {
            justify-content: center;
            align-items: center;
        }

        /* With messages - normal flow */
        .app.has-messages .messages-inner {
            justify-content: flex-start;
        }

        .welcome {
            text-align: center;
            padding: 40px 20px;
            max-width: 800px;
            margin: 0 auto;
        }

        .app.has-messages .welcome {
            display: none;
        }

        .welcome h1 {
            font-size: 36px;
            font-weight: 600;
            color: #ececec;
            margin-bottom: 16px;
        }

        .welcome p {
            font-size: 16px;
            color: #b4b4b4;
        }

        /* Message */
        .message {
            width: 100%;
            padding: 16px 24px;
            display: flex;
            justify-content: flex-start;
            min-height: auto; /* Allow content to determine height */
            overflow: visible; /* Don't clip content */
        }

        .message.user {
            background: #212121;
            justify-content: flex-end;
            align-items: flex-end;
        }

        .message.assistant {
            background: #2f2f2f;
            justify-content: flex-start;
        }

        .message-content {
            width: auto;
            padding: 0 16px;
            display: flex;
            gap: 16px;
            min-width: 0; /* Allow flex item to shrink */
            box-sizing: border-box;
            margin-left: 0;
            margin-right: 0;
        }

          .message-body {
              display: flex;
              flex-direction: column;
              gap: 12px;
              flex: 1;
              min-width: 0;
          }

          .message.user .message-body {
              align-items: flex-end;
          }

        .message.assistant .message-content {
            max-width: 100%;
            margin-left: 0;
            margin-right: auto;
        }

        .message.user .message-content {
            flex-direction: row-reverse;
            justify-content: flex-end;
            align-items: flex-end;
            max-width: min(600px, 70%);
            margin-left: auto;
            margin-right: 0;
        }

        .message-avatar {
            width: 32px;
            height: 32px;
            border-radius: 6px;
            background: #19c37d;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 600;
            font-size: 14px;
            color: white;
            flex-shrink: 0;
        }

        .message.user .message-avatar {
            background: #5536da;
        }

        .message-text {
            flex: 1;
            line-height: 1.7;
            color: #ececec;
            font-size: 15px;
            word-wrap: break-word;
            overflow-wrap: break-word;
            word-break: break-word;
            min-width: 0; /* Allow flex item to shrink */
            max-width: 100%; /* Prevent overflow */
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "Android Emoji", "EmojiOne Color", "EmojiOne Mozilla", "Twemoji Mozilla", "Noto Emoji", sans-serif;
            letter-spacing: normal;
            -webkit-font-smoothing: antialiased;
            text-rendering: optimizeLegibility;
        }

.message-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

.copy-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 500;
    color: #e5e7eb;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 999px;
    padding: 4px 12px;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.copy-button svg {
    width: 14px;
    height: 14px;
}

.copy-button:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.35);
    transform: translateY(-1px);
}

.copy-button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.copy-button.copied {
    color: #19c37d;
    border-color: rgba(25, 195, 125, 0.75);
    background: rgba(25, 195, 125, 0.12);
}

.copy-button.copy-error {
    color: #f87171;
    border-color: rgba(248, 113, 113, 0.8);
    background: rgba(248, 113, 113, 0.12);
}
        
        /* Ensure markdown content displays fully */
        .message-text p,
        .message-text ul,
        .message-text ol,
        .message-text pre,
        .message-text table {
            max-width: 100%;
            overflow-wrap: break-word;
            word-wrap: break-word;
        }
        
        .message-text pre {
            overflow-x: auto;
            white-space: pre-wrap;
            word-wrap: break-word;
        }
        
        .message-text code {
            word-break: break-all;
            overflow-wrap: break-word;
        }
          
          .kroki-diagram {
              margin: 16px 0;
              padding: 16px;
              border-radius: 12px;
              border: 1px solid rgba(148, 163, 184, 0.35);
              background: rgba(15, 23, 42, 0.35);
              box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
              backdrop-filter: blur(6px);
          }
          
          .kroki-diagram img {
              display: block;
              max-width: 100%;
              width: 100%;
              height: auto;
              margin: 0 auto 12px;
          }
          
          .kroki-loading {
              font-size: 0.9rem;
              color: #cbd5f5;
              display: flex;
              align-items: center;
              gap: 8px;
          }
          
          .kroki-toolbar {
              display: flex;
              align-items: center;
              justify-content: space-between;
              flex-wrap: wrap;
              gap: 8px;
              font-size: 0.85rem;
              color: #e5e7eb;
          }
          
          .kroki-caption {
              opacity: 0.8;
          }
          
          .kroki-source-toggle {
              border: 1px solid rgba(148, 163, 184, 0.4);
              background: transparent;
              color: #f8fafc;
              border-radius: 999px;
              padding: 4px 12px;
              font-size: 0.8rem;
              cursor: pointer;
              transition: border-color 0.2s ease, background 0.2s ease;
          }
          
          .kroki-source-toggle:hover {
              border-color: rgba(148, 163, 184, 0.8);
              background: rgba(148, 163, 184, 0.12);
          }
          
          .kroki-source {
              margin-top: 10px;
              padding: 12px;
              border-radius: 10px;
              background: rgba(15, 23, 42, 0.55);
              border: 1px solid rgba(11, 15, 25, 0.65);
              font-size: 0.8rem;
              line-height: 1.4;
              overflow-x: auto;
              max-height: 280px;
          }
          
          .kroki-source[hidden] {
              display: none !important;
          }
          
          .kroki-error {
              color: #fda4af;
              font-size: 0.9rem;
              line-height: 1.4;
          }
          
          .kroki-error-meta {
              font-size: 0.75rem;
              opacity: 0.8;
              margin-top: 4px;
          }
        
        .message-text table {
            display: block;
            overflow-x: auto;
            width: 100%;
            max-width: 100%;
        }

        .message.user .message-text {
            text-align: right;
            background: #5536da;
            padding: 10px 14px;
            border-radius: 12px;
            max-width: fit-content;
            margin-left: auto;
            line-height: 1.6;
        }

.message.file {
    background: #1b1b1f;
    justify-content: center;
}

.message.file .message-content {
    max-width: 820px;
    width: 100%;
    padding: 0 20px;
}

.message.file .message-avatar {
    background: #374151;
}

.message.file .message-text {
    background: #111827;
    border-radius: 12px;
    padding: 16px 18px;
    text-align: left;
}

.file-message-title {
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #9ca3af;
    margin-bottom: 4px;
}

.file-message-name {
    font-weight: 600;
    font-size: 1rem;
    color: #f3f4f6;
    margin-bottom: 4px;
}

.file-message-meta {
    font-size: 0.85rem;
    color: #9ca3af;
    margin-bottom: 10px;
}

.file-message-preview {
    background: #0f172a;
    border: 1px solid #1f2937;
    border-radius: 8px;
    padding: 12px;
    max-height: 220px;
    overflow: auto;
    font-family: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
    font-size: 0.85rem;
    color: #e2e8f0;
    white-space: pre-wrap;
    line-height: 1.5;
}

.file-message-preview::-webkit-scrollbar {
    width: 6px;
}

.file-message-preview::-webkit-scrollbar-thumb {
    background: #374151;
    border-radius: 4px;
}

.file-message-image-preview {
    margin-top: 12px;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid #1f2937;
    background: #0f172a;
    max-width: 420px;
}

.file-message-image-preview img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 320px;
    object-fit: cover;
    background: #020617;
}

        /* Message metadata and formatting */
.message-metadata {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(51, 51, 51, 0.35);
    font-size: 12px;
    opacity: 0.9;
    color: #9ca3af;
    align-items: center;
}

.metadata-badge {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "Android Emoji", "EmojiOne Color", "EmojiOne Mozilla", "Twemoji Mozilla", "Noto Emoji", sans-serif;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: rgba(148, 163, 184, 0.12);
    border-radius: 999px;
    font-size: 12px;
    color: #e5e7eb;
    border: 1px solid rgba(148, 163, 184, 0.35);
    font-weight: 500;
    cursor: default;
    transition: background 0.2s ease, color 0.2s ease;
    line-height: 1;
}

.metadata-badge:hover {
    background: rgba(148, 163, 184, 0.25);
    color: #f3f4f6;
}

.metadata-badge strong {
    color: #f9fafb;
    font-weight: 600;
}

.metadata-badge[data-tooltip] {
    position: relative;
}

.metadata-badge[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 50%;
    bottom: calc(100% + 10px);
    transform: translate(-50%, 0);
    background: rgba(15, 23, 42, 0.94);
    color: #f9fafb;
    padding: 10px 12px;
    border-radius: 8px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.45);
    font-size: 12px;
    line-height: 1.45;
    white-space: pre-line;
    max-width: min(320px, 80vw);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 40;
}

.metadata-badge[data-tooltip]::before {
    content: '';
    position: absolute;
    left: 50%;
    bottom: calc(100% + 2px);
    transform: translateX(-50%);
    border-width: 6px;
    border-style: solid;
    border-color: rgba(15, 23, 42, 0.94) transparent transparent transparent;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease;
    pointer-events: none;
    z-index: 39;
}

.metadata-badge[data-tooltip]:hover::after,
.metadata-badge[data-tooltip]:hover::before,
.metadata-badge[data-tooltip]:focus-visible::after,
.metadata-badge[data-tooltip]:focus-visible::before {
    opacity: 1;
    visibility: visible;
}

.metadata-badge[data-tooltip]:hover::after,
.metadata-badge[data-tooltip]:focus-visible::after {
    transform: translate(-50%, -4px);
}

.metadata-badge-hint {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    opacity: 0.55;
    margin-left: 6px;
}

.metadata-badge[data-tooltip]:hover .metadata-badge-hint,
.metadata-badge[data-tooltip]:focus-visible .metadata-badge-hint {
    opacity: 0.9;
}

@media (max-width: 600px) {
    .metadata-badge[data-tooltip]::after {
        left: 0;
        transform: translate(0, 0);
    }

    .metadata-badge[data-tooltip]:hover::after,
    .metadata-badge[data-tooltip]:focus-visible::after {
        transform: translate(0, -4px);
    }

    .metadata-badge[data-tooltip]::before {
        left: 24px;
    }
}

        .message-main-content {
            font-size: 15px;
            line-height: 1.7;
        }

        .message-main-content p {
            margin-bottom: 16px;
        }

        .message-main-content p:last-child {
            margin-bottom: 0;
        }

        .message-main-content a {
            color: #c084fc;
            text-decoration: none;
            border-bottom: 1px solid rgba(192, 132, 252, 0.4);
            transition: all 0.2s;
        }

        .message-main-content a:hover {
            color: #e9d5ff;
            border-bottom-color: #e9d5ff;
        }

        .message-main-content strong {
            font-weight: 600;
            color: #ececec;
        }

        .message-main-content em {
            font-style: italic;
            color: #d0d0d0;
        }

        .message-main-content img {
            max-width: 100%;
            height: auto;
            border-radius: 8px;
            margin: 16px 0;
        }

        /* Markdown elements styling */
        .message-main-content h1,
        .message-main-content h2,
        .message-main-content h3,
        .message-main-content h4,
        .message-main-content h5,
        .message-main-content h6 {
            margin-top: 24px;
            margin-bottom: 12px;
            font-weight: 600;
            color: #ececec;
            line-height: 1.4;
        }

        .message-main-content h1:first-child,
        .message-main-content h2:first-child,
        .message-main-content h3:first-child {
            margin-top: 0;
        }

        .message-main-content h1 {
            font-size: 1.75em;
            border-bottom: 1px solid #4d4d4d;
            padding-bottom: 8px;
        }

        .message-main-content h2 {
            font-size: 1.5em;
            border-bottom: 1px solid #4d4d4d;
            padding-bottom: 6px;
        }

        .message-main-content h3 {
            font-size: 1.25em;
        }

        .message-main-content h4 {
            font-size: 1.1em;
        }

        .message-main-content ul,
        .message-main-content ol {
            margin: 16px 0;
            padding-left: 28px;
        }

        .message-main-content li {
            margin: 6px 0;
            line-height: 1.6;
        }

        .message-main-content li p {
            margin-bottom: 8px;
        }

        .message-main-content blockquote {
            margin: 16px 0;
            padding: 12px 16px;
            border-left: 3px solid #4d4d4d;
            background: rgba(77, 77, 77, 0.1);
            border-radius: 6px;
            color: #b0b0b0;
            line-height: 1.6;
        }

        .message-main-content code {
            background: rgba(77, 77, 77, 0.5);
            padding: 2px 6px;
            border-radius: 3px;
            font-family: 'Monaco', 'Courier New', monospace;
            font-size: 0.9em;
            color: #19c37d;
        }

        .message-main-content pre {
            background: #1a1a1a;
            border: 1px solid #4d4d4d;
            border-radius: 8px;
            padding: 16px;
            overflow-x: auto;
            margin: 16px 0;
            line-height: 1.5;
        }

        .message-main-content pre code {
            background: transparent;
            padding: 0;
            color: #ececec;
            font-size: 0.85em;
        }

        .message-main-content table {
            width: 100%;
            border-collapse: collapse;
            margin: 16px 0;
            border: 1px solid #4d4d4d;
            border-radius: 8px;
            overflow: hidden;
        }

        .message-main-content table th,
        .message-main-content table td {
            padding: 10px 14px;
            text-align: left;
            border-bottom: 1px solid #4d4d4d;
            line-height: 1.5;
        }

        .message-main-content table th {
            background: rgba(77, 77, 77, 0.3);
            font-weight: 600;
            color: #ececec;
        }

        .message-main-content table tr:last-child td {
            border-bottom: none;
        }

        .message-main-content table tr:hover {
            background: rgba(77, 77, 77, 0.1);
        }

        .message-main-content hr {
            border: none;
            border-top: 1px solid #4d4d4d;
            margin: 16px 0;
        }

        /* Advertisement styling */
        .advertisement-container {
            margin-top: 16px;
            padding: 12px 16px;
            background: rgba(51, 51, 51, 0.3);
            border-left: 3px solid rgba(255, 193, 7, 0.5);
            border-radius: 8px;
            opacity: 0.7;
            transition: opacity 0.2s ease;
        }

        .advertisement-container:hover {
            opacity: 0.85;
        }

        .advertisement-label {
            font-family: "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "Android Emoji", "EmojiOne Color", "EmojiOne Mozilla", "Twemoji Mozilla", "Noto Emoji", "Segoe UI", ui-sans-serif, -apple-system, system-ui, Helvetica, Arial, sans-serif;
            display: inline-flex;
            align-items: center;
            gap: 4px;
            font-size: 10px;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            color: rgba(255, 193, 7, 0.8);
            margin-bottom: 8px;
            padding: 2px 6px;
            background: rgba(255, 193, 7, 0.1);
            border-radius: 4px;
        }

        .advertisement-content {
            font-size: 13px;
            line-height: 1.6;
            color: rgba(236, 236, 236, 0.65);
        }

        .advertisement-content a {
            color: rgba(255, 193, 7, 0.7);
            text-decoration: none;
            border-bottom: 1px solid rgba(255, 193, 7, 0.3);
        }

        .advertisement-content a:hover {
            color: rgba(255, 193, 7, 0.9);
            border-bottom-color: rgba(255, 193, 7, 0.6);
        }

        .upgrade-callout {
            margin-top: 16px;
            padding: 16px;
            background: linear-gradient(135deg, rgba(25, 195, 125, 0.1), rgba(85, 54, 218, 0.1));
            border-left: 3px solid #19c37d;
            border-radius: 8px;
        }

        .upgrade-callout h4 {
            font-size: 14px;
            font-weight: 600;
            color: #19c37d;
            margin-bottom: 8px;
            font-family: "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "Android Emoji", "EmojiOne Color", "EmojiOne Mozilla", "Twemoji Mozilla", "Noto Emoji", "Segoe UI", ui-sans-serif, -apple-system, system-ui, Helvetica, Arial, sans-serif;
        }

        .upgrade-callout ul {
            list-style: none;
            padding: 0;
            margin: 12px 0;
        }

        .upgrade-callout li {
            padding: 4px 0 4px 20px;
            position: relative;
            font-size: 13px;
            color: #b4b4b4;
        }

        .upgrade-callout li:before {
            content: "?";
            position: absolute;
            left: 0;
            color: #19c37d;
            font-weight: bold;
            font-family: "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "Android Emoji", "EmojiOne Color", "EmojiOne Mozilla", "Twemoji Mozilla", "Noto Emoji", "Segoe UI", ui-sans-serif, -apple-system, system-ui, Helvetica, Arial, sans-serif;
        }

        .upgrade-callout-actions {
            display: flex;
            gap: 12px;
            margin-top: 12px;
        }

        .upgrade-link {
            display: inline-block;
            padding: 8px 16px;
            background: #19c37d;
            color: #212121;
            text-decoration: none;
            border-radius: 6px;
            font-size: 13px;
            font-weight: 600;
            transition: all 0.2s;
        }

        .upgrade-link:hover {
            background: #20e68c;
            transform: translateY(-1px);
        }

        .upgrade-link.secondary {
            background: transparent;
            color: #19c37d;
            border: 1px solid #19c37d;
        }

        .upgrade-link.secondary:hover {
            background: rgba(25, 195, 125, 0.1);
        }

        /* Input Area */
        .input-container {
            padding: 20px 0;
            background: #212121;
            flex-shrink: 0;
        }

        .app:not(.has-messages) .input-container {
            padding: 20px 0;
            flex: 0;
        }

        .input-wrapper {
            max-width: 768px;
            margin: 0 auto;
            padding: 0 24px;
        }

        .input-form {
            position: relative;
            background: #2f2f2f;
            border: 1px solid #4d4d4d;
            border-radius: 24px;
            padding: 10px 10px 10px 16px;
            display: flex;
            align-items: flex-end;
            gap: 10px;
            transition: all 0.2s;
        }
  
          .input-main {
              flex: 1;
              display: flex;
              flex-direction: column;
              gap: 8px;
          }

        .input-form:focus-within {
            border-color: #565656;
            box-shadow: 0 0 0 1px #565656;
        }

  .input-options {
      display: flex;
      align-items: center;
      gap: 12px;
      flex-wrap: wrap;
      justify-content: flex-start;
      margin: 0;
  }
  
  .input-options .thinking-toggle {
      margin-left: auto;
  }

.camera-capture-button,
.file-upload-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: 1px solid #4d4d4d;
    border-radius: 12px;
    padding: 0;
    font-size: 0;
    color: #e5e5e5;
    background: #3a3a3a;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.camera-capture-button svg,
.file-upload-button svg {
    width: 18px;
    height: 18px;
}

.camera-capture-button:hover,
.file-upload-button:hover {
    background: #4c4c4c;
    border-color: #5f5f5f;
    transform: translateY(-1px);
}

.camera-capture-button:disabled,
.file-upload-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.camera-capture-button {
    color: #c7d2fe;
    border-color: #4c4c76;
    background: radial-gradient(circle at 30% 20%, rgba(103, 132, 255, 0.25), rgba(34, 34, 42, 0.6));
}

.camera-capture-button:hover {
    border-color: #7c8dff;
    background: radial-gradient(circle at 30% 20%, rgba(124, 141, 255, 0.35), rgba(44, 44, 58, 0.9));
}

.input-form.drag-over {
    border-style: dashed;
    border-color: #19c37d;
    background: rgba(25, 195, 125, 0.08);
    box-shadow: 0 0 0 1px rgba(25, 195, 125, 0.35);
}

.input-form.drag-over::after {
    content: 'Drop to attach';
    position: absolute;
    top: 16px;
    right: 80px;
    font-size: 12px;
    color: #b3f0d3;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

        .thinking-toggle {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            font-size: 12px;
            color: #d1d5db;
            font-weight: 500;
            cursor: pointer;
            user-select: none;
            line-height: 1.2;
        }

        .thinking-toggle input[type="checkbox"] {
            width: 16px;
            height: 16px;
            margin: 0;
            accent-color: #19c37d;
            flex-shrink: 0;
        }

        .thinking-toggle span {
            white-space: nowrap;
        }

.attachments-container {
    display: none;
    background: #1b1b1b;
    border: 1px solid #333333;
    border-radius: 16px;
    padding: 14px 18px;
    margin: 12px auto 0;
    max-width: 768px;
}

.attachments-container.active {
    display: block;
}

.attachments-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-size: 13px;
    color: #d1d5db;
}

.attachments-clear {
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 12px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.2s ease, color 0.2s ease;
}

.attachments-clear:hover:not(:disabled) {
    background: rgba(148, 163, 184, 0.15);
    color: #e2e8f0;
}

.attachments-clear:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.attachments-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.attachment-pill {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    border: 1px solid #3a3a3a;
    border-radius: 999px;
    padding: 6px 12px 6px 14px;
    background: #262626;
    font-size: 12px;
    color: #e5e7eb;
}

.attachment-pill-main {
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}

.attachment-pill-name {
    font-weight: 600;
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.attachment-pill-meta {
    color: #a1a1aa;
}

.attachment-pill-remove {
    border: none;
    background: transparent;
    color: #a1a1aa;
    font-size: 14px;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    line-height: 1;
}

.attachment-pill-remove:hover {
    color: #fca5a5;
    background: rgba(252, 165, 165, 0.12);
}

.attachment-pill--image {
    border-color: #3b82f6;
    background: rgba(59, 130, 246, 0.12);
}

.attachment-pill--image .attachment-pill-meta {
    color: #cbd5f5;
}

.attachment-pill--image .attachment-pill-meta::before {
    content: 'Photo · ';
    color: #bfdbfe;
}

        #chatInput {
            flex: 1;
            background: transparent;
            border: none;
            color: #ececec;
            font-size: 15px;
            font-family: inherit;
            outline: none;
            resize: none;
            min-height: 24px;
            max-height: 200px;
            line-height: 1.6;
            padding: 4px 0;
            vertical-align: middle;
        }

        #chatInput::placeholder {
            color: #8e8ea0;
        }

        #sendButton {
            width: 32px;
            height: 32px;
            background: #fff;
            border: none;
            border-radius: 16px;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-shrink: 0;
            transition: all 0.2s;
        }

        #sendButton:disabled {
            opacity: 0.4;
            cursor: not-allowed;
        }

        #sendButton:not(:disabled):hover {
            background: #e6e6e6;
        }

        #sendButton svg {
            width: 20px;
            height: 20px;
        }

        /* Loading indicator */
        .loading {
            display: none;
            text-align: center;
            color: #8e8ea0;
            font-size: 14px;
            padding: 12px;
        }

        .loading.active {
            display: block;
        }

        /* Scrollbar */
        .messages::-webkit-scrollbar {
            width: 8px;
        }

        .messages::-webkit-scrollbar-track {
            background: #212121;
        }

.messages::-webkit-scrollbar-thumb {
    background: #4d4d4d;
    border-radius: 4px;
}

.messages::-webkit-scrollbar-thumb:hover {
    background: #5d5d5d;
}

        /* Camera capture overlay */
.camera-capture-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.78);
    backdrop-filter: blur(4px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.camera-capture-modal {
    background: #101014;
    border: 1px solid #1f1f2b;
    border-radius: 24px;
    width: min(640px, 100%);
    max-width: 640px;
    color: #f8fafc;
    box-shadow: 0 15px 60px rgba(0, 0, 0, 0.45);
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px;
}

.camera-capture-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.camera-capture-title {
    font-size: 1rem;
    font-weight: 600;
}

.camera-capture-close {
    border: none;
    background: transparent;
    color: #cbd5f5;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 4px 8px;
}

.camera-preview-frame {
    position: relative;
    border-radius: 20px;
    overflow: hidden;
    border: 1px solid #272737;
    background: #05060a;
    min-height: 320px;
}

.camera-preview-frame video,
.camera-preview-frame canvas,
.camera-preview-frame img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.camera-preview-frame canvas,
.camera-preview-frame img {
    background: #000;
}

.camera-status {
    font-size: 0.85rem;
    color: #9ca3af;
    min-height: 20px;
}

.camera-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

.camera-controls button {
    border: none;
    border-radius: 999px;
    padding: 10px 20px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.camera-controls button:hover {
    transform: translateY(-1px);
}

.camera-btn {
    background: #2563eb;
    color: #f8fafc;
}

.camera-btn-secondary {
    background: rgba(15, 23, 42, 0.8);
    color: #cfd8f7;
    border: 1px solid rgba(99, 102, 241, 0.35);
}

.camera-btn-danger {
    background: rgba(248, 113, 113, 0.1);
    color: #fecaca;
    border: 1px solid rgba(248, 113, 113, 0.4);
}

.camera-btn:disabled,
.camera-btn-secondary:disabled,
.camera-btn-danger:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

@media (max-width: 640px) {
    .camera-capture-modal {
        padding: 16px;
    }

    .camera-controls {
        justify-content: center;
    }

    .camera-controls button {
        flex: 1;
        min-width: 45%;
    }
}

        /* Hidden controls */
        .controls {
            display: none;
        }

        /* Footer text */
        .footer-text {
            text-align: center;
            font-size: 12px;
            color: #8e8ea0;
            padding: 8px 20px 0;
            max-width: 768px;
            margin: 0 auto;
        }

        .footer-text a {
            color: #c084fc;
            text-decoration: underline;
        }

        .footer-text a:hover {
            color: #e9d5ff;
        }

        .version-info {
            position: fixed;
            bottom: 12px;
            right: 16px;
            font-size: 10px;
            color: #4d4d4d;
            font-family: 'Monaco', 'Courier New', monospace;
            z-index: 10;
            padding: 4px 8px;
            background: rgba(33, 33, 33, 0.8);
            border-radius: 4px;
            backdrop-filter: blur(4px);
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .version-info:hover {
            color: #8e8ea0;
            background: rgba(47, 47, 47, 0.9);
        }

        .status-lights {
            display: flex;
            gap: 6px;
            align-items: center;
        }

        .status-light {
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background: #4d4d4d;
            position: relative;
            cursor: help;
            transition: all 0.3s ease;
        }

        .status-light::before {
            content: '';
            position: absolute;
            inset: -2px;
            border-radius: 50%;
            background: inherit;
            opacity: 0.3;
            animation: pulse 2s infinite;
        }

        @keyframes pulse {
            0%, 100% { transform: scale(1); opacity: 0.3; }
            50% { transform: scale(1.5); opacity: 0; }
        }

        .status-light.active {
            background: #19c37d;
            box-shadow: 0 0 4px rgba(25, 195, 125, 0.6);
        }

        .status-light.warning {
            background: #ffa500;
            box-shadow: 0 0 4px rgba(255, 165, 0, 0.6);
        }

        .status-light.error {
            background: #ef4444;
            box-shadow: 0 0 4px rgba(239, 68, 68, 0.6);
        }

        .status-light.checking {
            background: #8e8ea0;
            animation: pulse 1s infinite;
        }

        .status-light[title]:hover::after {
            content: attr(title);
            position: absolute;
            bottom: 100%;
            right: 0;
            margin-bottom: 4px;
            padding: 8px 12px;
            background: rgba(0, 0, 0, 0.9);
            color: #ececec;
            font-size: 11px;
            white-space: pre-wrap;
            border-radius: 4px;
            z-index: 1000;
            max-width: 300px;
            word-wrap: break-word;
        }
        
        /* Make status light clickable when it has an action URL */
        .status-light[data-action-url] {
            cursor: pointer;
        }
        
        .status-light[data-action-url]:hover {
            opacity: 0.9;
        }
        
        .status-light[data-action-url]:active {
            opacity: 0.7;
        }

        /* Mobile */
        @media (max-width: 768px) {
            .sidebar {
                position: fixed;
                left: 0;
                top: 0;
                height: 100%;
                width: 260px; /* Keep full width on mobile for overlay */
                z-index: 1000;
                box-shadow: 2px 0 8px rgba(0,0,0,0.3);
                /* Default: hidden on mobile */
                transform: translateX(-100%);
            }

            /* Only show sidebar when explicitly not collapsed (user opened it) */
            .sidebar:not(.collapsed) {
                transform: translateX(0);
            }

            /* Explicitly hidden when collapsed */
            .sidebar.collapsed {
                transform: translateX(-100%);
                /* On mobile, keep width for overlay effect */
                width: 260px;
            }
            
            /* Override: Always start hidden on mobile by default */
            /* Higher specificity with !important to ensure hidden */
            body .app .sidebar {
                transform: translateX(-100%) !important;
            }
            
            /* Only show when user has explicitly opened it - requires both:
               sidebar doesn't have collapsed class AND toggle has sidebar-open class */
            body .app #sidebarToggle.sidebar-open ~ #sidebar:not(.collapsed),
            body .app .sidebar:not(.collapsed).sidebar-open {
                transform: translateX(0) !important;
            }

            .sidebar-toggle.sidebar-open {
                left: 260px;
            }

            .sidebar-toggle:not(.sidebar-open) {
                left: 0;
            }

            .welcome h1 {
                font-size: 28px;
            }

            .message-content {
                padding: 0 16px;
                gap: 16px;
            }

            .message.user .message-content {
                max-width: 90%;
                padding: 0 12px;
            }

            .input-wrapper {
                padding: 0 16px;
            }
        }

        /* Position feedback buttons at bottom of message, above metadata */
        .message {
            display: flex;
            flex-direction: column;
        }

        /* Feedback buttons - positioned at bottom, just above metadata */
        /* Reasoning section styles */
        .reasoning-container {
            margin-top: 0.75rem;
            padding-top: 0.75rem;
            border-top: 1px solid rgba(255, 255, 255, 0.1);
        }

        .reasoning-toggle {
            background: transparent;
            border: none;
            color: #888;
            font-size: 11px;
            cursor: pointer;
            padding: 4px 0;
            display: flex;
            align-items: center;
            gap: 4px;
            transition: color 0.2s;
            font-family: inherit;
        }

        .reasoning-toggle:hover {
            color: #aaa;
        }

        .reasoning-toggle-icon {
            font-size: 10px;
            transition: transform 0.2s;
        }

        .reasoning-content {
            margin-top: 0.5rem;
            padding: 0.5rem;
            background: rgba(0, 0, 0, 0.2);
            border-radius: 4px;
            font-size: 11px;
            line-height: 1.5;
            color: #888;
            font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
        }

        .reasoning-step {
            margin-bottom: 0.5rem;
            padding: 0.25rem 0;
            border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        }

        .reasoning-step:last-child {
            margin-bottom: 0;
            border-bottom: none;
        }
          
          .system-prompt-container {
              margin-top: 0.75rem;
              padding-top: 0.75rem;
              border-top: 1px solid rgba(255, 255, 255, 0.1);
          }
          
          .system-prompt-toggle {
              background: transparent;
              border: none;
              color: #888;
              font-size: 11px;
              cursor: pointer;
              padding: 4px 0;
              display: flex;
              align-items: center;
              gap: 4px;
              transition: color 0.2s;
              font-family: inherit;
          }
          
          .system-prompt-toggle:hover {
              color: #aaa;
          }
          
          .system-prompt-toggle-icon {
              font-size: 10px;
              transition: transform 0.2s;
          }
          
          .system-prompt-content {
              margin-top: 0.5rem;
              padding: 0.75rem;
              background: rgba(0, 0, 0, 0.35);
              border-radius: 6px;
              font-size: 12px;
              line-height: 1.6;
              color: #d1d5db;
              font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
              max-height: 280px;
              overflow-y: auto;
              white-space: pre-wrap;
              word-break: break-word;
              border: 1px solid rgba(255, 255, 255, 0.08);
          }

          .system-prompt-container.conversation-history-container {
              border-top: none;
              margin-top: 0.5rem;
              padding-top: 0.5rem;
          }

          .conversation-history-toggle {
              color: #facc15;
          }

          .conversation-history-toggle:hover {
              color: #fde047;
          }

          .conversation-history-toggle-icon {
              color: inherit;
          }

            .system-prompt-container.rag-details-container {
                border-top: none;
                margin-top: 0.5rem;
                padding-top: 0.5rem;
            }

            .rag-details-toggle {
                color: #8ab4f8;
            }

            .rag-details-toggle:hover {
                color: #a1c1ff;
            }

          .prompt-editor {
              background: rgba(15, 23, 42, 0.45);
              border: 1px solid rgba(148, 163, 184, 0.25);
              border-radius: 8px;
              padding: 12px 14px;
              font-size: 13px;
              color: #d1d5db;
              box-sizing: border-box;
          }

          .prompt-editor-header {
              display: flex;
              justify-content: space-between;
              align-items: center;
              gap: 12px;
              margin-bottom: 8px;
              flex-wrap: wrap;
          }

          .prompt-editor-header-left {
              display: flex;
              flex-direction: column;
              gap: 2px;
              min-width: 0;
          }

          .prompt-editor-title {
              font-size: 12px;
              text-transform: uppercase;
              letter-spacing: 0.08em;
              color: #94a3b8;
              font-weight: 600;
          }

          .prompt-editor-agent {
              font-size: 14px;
              font-weight: 600;
              color: #f8fafc;
              word-break: break-word;
          }

          .prompt-editor-hint {
              font-size: 11px;
              color: #9ca3af;
              background: rgba(148, 163, 184, 0.15);
              padding: 4px 8px;
              border-radius: 999px;
              text-transform: uppercase;
              letter-spacing: 0.08em;
          }

          .prompt-editor-description {
              margin: 0 0 10px 0;
              font-size: 12px;
              color: #94a3b8;
              line-height: 1.5;
          }

          .prompt-editor-textarea {
              width: 100%;
              min-height: 110px;
              resize: vertical;
              background: rgba(15, 15, 15, 0.45);
              border: 1px solid rgba(148, 163, 184, 0.25);
              border-radius: 6px;
              padding: 10px 12px;
              color: #e2e8f0;
              font-family: inherit;
              font-size: 13px;
              line-height: 1.55;
              box-sizing: border-box;
          }

          .prompt-editor-textarea:focus {
              outline: none;
              border-color: #38bdf8;
              box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.35);
              background: rgba(15, 23, 42, 0.55);
          }

          .prompt-editor-textarea:disabled {
              opacity: 0.6;
              cursor: not-allowed;
          }

          .prompt-editor-meta {
              display: flex;
              justify-content: flex-end;
              align-items: center;
              margin-top: 8px;
              font-size: 12px;
              color: #9ca3af;
          }

          .prompt-editor-count {
              font-variant-numeric: tabular-nums;
          }

          .prompt-editor-actions {
              display: flex;
              gap: 8px;
              align-items: center;
              margin-top: 12px;
              flex-wrap: wrap;
          }

            .prompt-editor-submit,
            .prompt-editor-cloud-agent,
            .prompt-editor-reset {
              padding: 8px 14px;
              border-radius: 6px;
              font-size: 12px;
              font-weight: 600;
              cursor: pointer;
              transition: all 0.2s ease;
              border: 1px solid transparent;
          }

          .prompt-editor-submit {
              background: #19c37d;
              color: #0f172a;
          }

          .prompt-editor-submit:hover:not(:disabled) {
              background: #22d993;
          }

          .prompt-editor-submit:disabled {
              opacity: 0.6;
              cursor: not-allowed;
          }

          .prompt-editor-reset {
              background: transparent;
              color: #cbd5f5;
              border-color: rgba(148, 163, 184, 0.35);
          }

          .prompt-editor-reset:hover:not(:disabled) {
              background: rgba(148, 163, 184, 0.12);
          }

          .prompt-editor-reset:disabled {
              opacity: 0.6;
              cursor: not-allowed;
          }

            .prompt-editor-cloud-agent {
                background: #2563eb;
                color: #e2e8f0;
            }

            .prompt-editor-cloud-agent:hover:not(:disabled) {
                background: #1d4ed8;
            }

            .prompt-editor-cloud-agent:disabled {
                opacity: 0.6;
                cursor: not-allowed;
            }

          .prompt-editor-status {
              font-size: 12px;
              color: #9ca3af;
              min-height: 16px;
              flex: 1;
          }

          .prompt-editor-status--success {
              color: #34d399;
          }

          .prompt-editor-status--error {
              color: #f87171;
          }

          .prompt-editor-status--warning {
              color: #fbbf24;
          }

        .message-feedback {
            display: flex;
            gap: 8px;
            padding: 8px 16px 4px 16px;
            align-items: center;
            justify-content: center;
            opacity: 0.6;
            transition: opacity 0.2s;
            margin-top: 8px;
            padding-top: 8px;
            border-top: 1px solid rgba(79, 79, 79, 0.3);
        }

        .message:hover .message-feedback {
            opacity: 1;
        }

        .feedback-btn {
            background: transparent;
            border: 1px solid #4d4d4d;
            border-radius: 6px;
            padding: 4px 8px;
            cursor: pointer;
            font-size: 16px;
            line-height: 1;
            transition: all 0.2s;
            color: #ececec;
            display: flex;
            align-items: center;
            justify-content: center;
            min-width: 32px;
            height: 28px;
        }

        .feedback-btn:hover {
            background: #2f2f2f;
            border-color: #6d6d6d;
            transform: scale(1.1);
        }

        .feedback-btn.active {
            background: #2f2f2f;
            border-color: #19c37d;
        }

        .feedback-btn.feedback-good.active {
            border-color: #19c37d;
        }

        .feedback-btn.feedback-ok.active {
            border-color: #ffa500;
        }

        .feedback-btn.feedback-bad.active {
            border-color: #ff4444;
        }

        /* Feedback modal */
        .feedback-modal-overlay {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.7);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 10000;
            padding: 20px;
        }

        .feedback-modal {
            background: #2f2f2f;
            border-radius: 12px;
            max-width: 500px;
            width: 100%;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
            border: 1px solid #4d4d4d;
        }

        .feedback-modal-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 20px;
            border-bottom: 1px solid #4d4d4d;
        }

        .feedback-modal-header h3 {
            margin: 0;
            font-size: 18px;
            color: #ececec;
            font-weight: 600;
        }

        .feedback-modal-close {
            background: transparent;
            border: none;
            color: #ececec;
            font-size: 24px;
            cursor: pointer;
            padding: 0;
            width: 32px;
            height: 32px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 6px;
            transition: background 0.2s;
        }

        .feedback-modal-close:hover {
            background: #3f3f3f;
        }

        .feedback-modal-body {
            padding: 20px;
        }

        .feedback-modal-body p {
            margin: 0 0 12px 0;
            color: #b4b4b4;
            font-size: 14px;
        }

        .feedback-modal-actions {
            display: flex;
            gap: 12px;
            justify-content: flex-end;
            margin-top: 16px;
        }

        .feedback-modal-cancel,
        .feedback-modal-submit {
            padding: 10px 20px;
            border-radius: 6px;
            border: none;
            cursor: pointer;
            font-size: 14px;
            font-weight: 500;
            transition: all 0.2s;
        }

        .feedback-modal-cancel {
            background: transparent;
            color: #b4b4b4;
            border: 1px solid #4d4d4d;
        }

        .feedback-modal-cancel:hover {
            background: #3f3f3f;
            color: #ececec;
        }

        .feedback-modal-submit {
            background: #19c37d;
            color: #fff;
        }

        .feedback-modal-submit:hover:not(:disabled) {
            background: #16a86a;
        }

        .feedback-modal-submit:disabled {
            opacity: 0.6;
            cursor: not-allowed;
        }

        /* Model Controls (only for formul8.ai users) */
        .model-controls {
            display: flex;
            align-items: center;
            gap: 16px;
            padding: 12px 0;
            margin-bottom: 8px;
            border-bottom: 1px solid #4d4d4d;
            flex-wrap: wrap;
        }

        .model-selector-wrapper {
            display: flex;
            flex-direction: column;
            align-items: flex-start;
            gap: 6px;
        }

        .model-selector-row {
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .model-feature-toggles {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .feature-toggle {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            font-size: 12px;
            color: #b4b4b4;
            cursor: pointer;
            user-select: none;
        }

        .feature-toggle input[type="checkbox"] {
            width: 16px;
            height: 16px;
            cursor: pointer;
            accent-color: #19c37d;
        }

        .feature-toggle span {
            line-height: 1;
        }

        #compareModelWrapper {
            display: none;
        }

        .model-label {
            font-size: 13px;
            color: #b4b4b4;
            font-weight: 500;
        }

        .model-select {
            padding: 6px 12px;
            background: #2f2f2f;
            border: 1px solid #4d4d4d;
            border-radius: 6px;
            color: #ececec;
            font-size: 13px;
            cursor: pointer;
            transition: all 0.2s;
            min-width: 180px;
        }

        .model-select:hover {
            border-color: #6d6d6d;
            background: #3f3f3f;
        }

        .model-select:focus {
            outline: none;
            border-color: #19c37d;
            box-shadow: 0 0 0 2px rgba(25, 195, 125, 0.2);
        }

        .compare-toggle {
            display: flex;
            align-items: center;
            gap: 8px;
            cursor: pointer;
            user-select: none;
        }

        .compare-toggle input[type="checkbox"] {
            width: 18px;
            height: 18px;
            cursor: pointer;
            accent-color: #19c37d;
        }

        .compare-toggle-label {
            font-size: 13px;
            color: #b4b4b4;
            font-weight: 500;
        }

        .compare-toggle:hover .compare-toggle-label {
            color: #ececec;
        }

        /* Comparison Container - Two Column Layout */
        .comparison-container {
            width: 100%;
            max-width: 1400px;
            margin: 0 auto;
            padding: 16px 24px;
        }

        .comparison-header {
            text-align: center;
            margin-bottom: 16px;
            padding-bottom: 12px;
            border-bottom: 1px solid #4d4d4d;
        }

        .comparison-header h3 {
            font-size: 16px;
            font-weight: 600;
            color: #ececec;
            margin: 0;
        }

        .comparison-columns {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 16px;
            width: 100%;
        }

        .comparison-item {
            background: #2f2f2f;
            border: 1px solid #4d4d4d;
            border-radius: 8px;
            padding: 16px;
            display: flex;
            flex-direction: column;
        }

        .comparison-item-header {
            display: flex;
            align-items: flex-start;
            justify-content: space-between;
            margin-bottom: 12px;
            padding-bottom: 12px;
            border-bottom: 1px solid #4d4d4d;
            gap: 12px;
        }

        .comparison-item-title {
            font-size: 14px;
            font-weight: 600;
            color: #ececec;
        }

        .comparison-item-model {
            font-size: 12px;
            color: #8e8ea0;
            padding: 4px 8px;
            background: rgba(77, 77, 77, 0.3);
            border-radius: 4px;
        }

        .comparison-item-meta {
            display: flex;
            align-items: center;
            gap: 8px;
            flex-wrap: wrap;
            justify-content: flex-end;
        }

        .comparison-item-header .copy-button {
            padding: 4px 10px;
        }

        .comparison-item-content {
            flex: 1;
            color: #ececec;
            font-size: 15px;
            line-height: 1.7;
            word-wrap: break-word;
            overflow-wrap: break-word;
        }
         
         .comparison-evaluation {
             margin-top: 20px;
             padding-top: 16px;
             border-top: 1px solid #3d3d3d;
         }
         
         .comparison-evaluation-header {
             display: flex;
             align-items: baseline;
             justify-content: space-between;
             gap: 12px;
             margin-bottom: 12px;
         }
         
         .comparison-evaluation-title {
             font-size: 15px;
             font-weight: 600;
             color: #f5f5f5;
         }
         
         .comparison-evaluation-meta {
             font-size: 12px;
             color: #9ca3af;
         }
         
         .comparison-scoreboard {
             display: grid;
             grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
             gap: 12px;
             margin-bottom: 12px;
         }
         
         .comparison-score {
             display: flex;
             justify-content: space-between;
             align-items: center;
             background: rgba(255, 255, 255, 0.04);
             border: 1px solid #3d3d3d;
             border-radius: 6px;
             padding: 12px 14px;
             transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
         }
         
         .comparison-score-name {
             font-size: 14px;
             font-weight: 600;
             color: #e5e7eb;
         }
         
         .comparison-score-values {
             display: flex;
             align-items: baseline;
             gap: 8px;
         }
         
         .comparison-score-value {
             font-size: 20px;
             font-weight: 700;
             color: #f5f5f5;
             min-width: 32px;
             text-align: right;
         }
         
         .comparison-score-grade {
             font-size: 12px;
             font-weight: 600;
             color: #cbd5f5;
             text-transform: uppercase;
             letter-spacing: 0.05em;
         }
         
         .comparison-score-grade:empty {
             display: none;
         }
         
         .comparison-score.winner {
             border-color: #22c55e;
             box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.25);
             background: rgba(34, 197, 94, 0.12);
         }
         
         .comparison-score.runner-up {
             opacity: 0.95;
         }
         
         .comparison-score.tie {
             border-color: #3b82f6;
             box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.25);
             background: rgba(59, 130, 246, 0.12);
         }
         
         .comparison-item.winner {
             border-color: #22c55e;
             box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.25);
         }
         
         .comparison-item.runner-up {
             opacity: 0.95;
         }
         
         .comparison-item.tie {
             border-color: #3b82f6;
             box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.25);
         }
         
         .comparison-evaluation-summary {
             font-size: 14px;
             color: #d4d4d8;
             line-height: 1.6;
         }
         
         .comparison-evaluation-details {
             margin-top: 12px;
             font-size: 14px;
             color: #c5c5d7;
             line-height: 1.6;
         }
         
         .comparison-evaluation-section {
             margin-top: 10px;
         }
         
         .comparison-evaluation-section-title {
             font-weight: 600;
             font-size: 13px;
             text-transform: uppercase;
             letter-spacing: 0.05em;
             color: #a1a1aa;
             margin-bottom: 6px;
         }
         
         .comparison-evaluation-section p {
             margin: 4px 0;
             color: #d4d4d8;
         }
         
         .comparison-evaluation-section p strong {
             color: #f5f5f5;
         }
         
         .comparison-evaluation-raw {
             background: rgba(0, 0, 0, 0.35);
             border: 1px solid #3f3f46;
             border-radius: 6px;
             padding: 10px 12px;
             font-size: 12px;
             color: #e4e4e7;
             overflow-x: auto;
             white-space: pre-wrap;
             word-break: break-word;
         }

        .comparison-item-content p {
            margin-bottom: 12px;
        }

        .comparison-item-content p:last-child {
            margin-bottom: 0;
        }

        .comparison-item.loading {
            opacity: 0.8;
            position: relative;
        }

        .comparison-item.loading .comparison-item-content {
            min-height: 60px;
        }

        .comparison-item.loading .comparison-item-content::after {
            content: 'Loading...';
            color: #8e8ea0;
            font-style: italic;
            display: block;
            margin-top: 8px;
            animation: pulse 1.5s ease-in-out infinite;
        }

        @keyframes pulse {
            0%, 100% { opacity: 0.6; }
            50% { opacity: 1; }
        }

        .comparison-item.loading .comparison-item-header {
            position: relative;
        }

        .comparison-item.loading .comparison-item-header::after {
            content: '';
            position: absolute;
            right: 8px;
            top: 50%;
            transform: translateY(-50%);
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background: #19c37d;
            animation: pulse 1.5s ease-in-out infinite;
        }

        /* Comparison message styling */
        .comparison-message {
            background: #2f2f2f;
        }

        .comparison-inline-container {
            width: 100%;
            max-width: 1400px;
            margin: 0 auto;
        }

        /* Mobile responsive for comparison */
        @media (max-width: 768px) {
            .comparison-columns {
                grid-template-columns: 1fr;
                gap: 12px;
            }

            .model-controls {
                flex-direction: column;
                align-items: flex-start;
                gap: 12px;
            }

            .model-selector-wrapper {
                width: 100%;
            }

            .model-select {
                flex: 1;
            }

            .compare-toggle {
                width: 100%;
            }

            .comparison-container {
                padding: 12px 16px;
            }
        }
