      /* --- Toasts (non-blocking notifications, replace alert()) ----------- */
      #toast-host {
        position: fixed;
        left: 50%;
        bottom: 24px;
        transform: translateX(-50%);
        z-index: 10050;
        display: flex;
        flex-direction: column;
        gap: 8px;
        align-items: center;
        pointer-events: none;
        max-width: min(92vw, 440px);
      }
      .toast {
        pointer-events: auto;
        background: #1e3a8a;
        color: #fff;
        padding: 11px 16px;
        border-radius: 10px;
        font-size: 14px;
        line-height: 1.4;
        box-shadow: 0 8px 24px rgba(30, 58, 138, 0.28);
        opacity: 0;
        transform: translateY(10px);
        transition: opacity 0.25s ease, transform 0.25s ease;
        max-width: 100%;
      }
      .toast--show { opacity: 1; transform: translateY(0); }
      .toast--error { background: #b91c1c; box-shadow: 0 8px 24px rgba(185, 28, 28, 0.28); }
      .toast--success { background: #047857; box-shadow: 0 8px 24px rgba(4, 120, 87, 0.28); }
      @media (prefers-reduced-motion: reduce) {
        .toast { transition: opacity 0.2s ease; transform: none; }
        .toast--show { transform: none; }
      }

      /* --- Retry button on failed assistant messages --------------------- */
      .chat-retry-btn {
        margin-top: 10px;
        padding: 7px 14px;
        background: #2563eb;
        color: #fff;
        border: none;
        border-radius: 8px;
        font-size: 13px;
        font-weight: 600;
        cursor: pointer;
        transition: background 0.2s;
      }
      .chat-retry-btn:hover { background: #1d4ed8; }

      /* --- Send button "stop generating" state --------------------------- */
      .send-btn.send-btn--stop img { display: none; }
      .send-btn.send-btn--stop {
        opacity: 1 !important;
        cursor: pointer;
      }
      .send-btn.send-btn--stop::after {
        content: '';
        width: 15px;
        height: 15px;
        border-radius: 3px;
        background: #2563eb;
      }
      .send-btn.send-btn--stop:hover { background: rgba(37, 99, 235, 0.12); }

      /* Prevent horizontal scrolling */
      html, body {
        overflow-x: hidden;
        max-width: 100vw;
      }
      
      /* Ensure hero section doesn't constrain chat container */
      section.hero {
        max-width: 100% !important;
        width: 100% !important;
        padding: 20px !important;
        box-sizing: border-box;
      }
      
      .ai-designer-pro-gate {
        display: none;
        position: fixed;
        inset: 0;
        z-index: 300;
        align-items: center;
        justify-content: center;
        padding: 24px;
        background: rgba(30, 58, 138, 0.45);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
      }
      .ai-designer-pro-gate__card {
        max-width: 480px;
        width: 100%;
        background: rgba(255, 255, 255, 0.95);
        border-radius: 16px;
        padding: 32px 28px;
        box-shadow: 0 24px 60px rgba(30, 58, 138, 0.2);
        border: 1px solid rgba(255, 255, 255, 0.7);
        text-align: center;
      }
      .ai-designer-pro-gate__card h2 {
        margin: 0 0 12px;
        color: #1e3a8a;
        font-size: 1.5rem;
      }
      .ai-designer-pro-gate__card p {
        margin: 0 0 20px;
        color: #4b5563;
        line-height: 1.55;
        font-size: 15px;
      }
      .ai-designer-pro-gate__actions {
        display: flex;
        flex-direction: column;
        gap: 10px;
      }
      .ai-designer-pro-gate__actions a {
        text-decoration: none;
      }

      .chat-container {
        width: 100%;
        max-width: 1400px;
        min-width: min(100%, 1400px);
        margin: 0 auto;
        height: calc(100vh - 120px);
        max-height: calc(100vh - 120px);
        display: flex;
        flex-direction: column;
        padding: 20px;
        box-sizing: border-box;
        flex-shrink: 0;
        position: relative;
        overflow: hidden;
      }
      
      .chat-input-container {
        max-width: 900px;
        margin: 0 auto;
        width: 100%;
      }
      
      .chat-messages {
        flex: 1 1 auto;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 20px;
        background: rgba(255, 255, 255, 0.4);
        border-radius: 12px;
        backdrop-filter: blur(10px);
        border: 1px solid var(--border);
        margin-bottom: 20px;
        display: flex;
        flex-direction: column;
        gap: 16px;
        min-width: 0;
        width: 100%;
        min-height: 0;
        transition: border-color 0.2s, background 0.2s;
      }
      
      /* Drag and drop styles */
      .chat-messages.drag-over {
        border: 2px dashed #2563eb;
        background: rgba(37, 99, 235, 0.1);
      }
      
      /* Drop files message - centered when shown on drag */
      .chat-container::before {
        content: 'Drop files here to upload';
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        background: rgba(37, 99, 235, 0.9);
        color: white;
        padding: 20px 40px;
        border-radius: 12px;
        font-size: 18px;
        font-weight: 600;
        z-index: 100;
        pointer-events: none;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
        opacity: 0;
        transition: opacity 0.2s ease-in;
      }
      
      .chat-container.drag-over::before {
        opacity: 1;
      }
      
      .message {
        display: flex;
        gap: 12px;
        animation: fadeIn 0.3s ease-in;
        min-width: 0;
        width: 100%;
      }
      
      @keyframes fadeIn {
        from { opacity: 0; transform: translateY(10px); }
        to { opacity: 1; transform: translateY(0); }
      }
      
      .message.user {
        flex-direction: row-reverse;
      }
      
      .message-avatar {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 600;
        flex-shrink: 0;
      }
      
      .message.user .message-avatar {
        width: 36px;
        height: 36px;
        align-self: flex-start;
        margin-top: 0;
      }
      
      .message.user .message-avatar {
        background: #2563eb;
        padding: 0;
        overflow: hidden;
      }
      
      .message.user .message-avatar img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        border-radius: 50%;
      }
      
      .message.assistant .message-avatar {
        background: transparent;
        color: white;
        padding: 0;
        overflow: hidden;
      }
      
      .message.assistant .message-avatar img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        border-radius: 50%;
      }
      
      .message-content {
        padding: 12px 16px;
        border-radius: 12px;
        max-width: min(70%, 600px);
        word-wrap: break-word;
        overflow-wrap: break-word;
        min-width: 0;
        box-sizing: border-box;
      }
      
      .message.assistant .message-content {
        white-space: pre-wrap;
      }
      
      .message.assistant .message-content strong {
        font-weight: 600;
      }
      
      .message.assistant .message-content ul,
      .message.assistant .message-content ol {
        margin: 8px 0;
        padding-left: 24px;
      }
      
      .message.assistant .message-content li {
        margin: 4px 0;
      }
      
      .message.user .message-content {
        background: #2563eb;
        color: white;
        border-bottom-right-radius: 4px;
      }
      
      .message.assistant .message-content {
        background: rgba(255, 255, 255, 0.8);
        color: #1e3a8a;
        border-bottom-left-radius: 4px;
      }
      
      .message-files-container {
        margin-top: 8px;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        max-width: 100%;
      }
      
      .message-file {
        margin-top: 0;
        padding: 8px;
        background: rgba(0, 0, 0, 0.05);
        border-radius: 8px;
        font-size: 0.9rem;
        display: inline-block;
        box-sizing: border-box;
        width: fit-content;
        max-width: 100%;
      }
      
      .message-file img {
        max-width: 300px;
        max-height: 200px;
        border-radius: 6px;
        height: auto;
        width: auto;
        display: block;
        margin: 0;
        padding: 0;
        box-sizing: border-box;
        cursor: pointer;
        transition: opacity 0.2s, transform 0.2s;
        object-fit: contain;
      }
      
      .message-file img:hover {
        opacity: 0.9;
        transform: scale(1.02);
      }
      
      /* For single image, allow it to be larger */
      .message-files-container.single-image .message-file img {
        max-width: 100%;
        max-height: 300px;
      }
      
      .message-file a {
        color: inherit;
        text-decoration: underline;
      }
      
      .chat-input-container {
        display: flex;
        flex-direction: column;
        background: rgba(255, 255, 255, 0.5);
        border-radius: 24px;
        backdrop-filter: blur(10px);
        border: 1px solid rgba(37, 99, 235, 0.2);
        padding: 8px 16px 12px 16px;
        min-width: 0;
        box-sizing: border-box;
        flex-shrink: 0;
        box-shadow: 0 2px 8px rgba(37, 99, 235, 0.1);
        max-width: 900px;
        margin: 0 auto;
        width: 100%;
      }
      
      .file-preview-container {
        display: none;
        padding: 8px 0;
        border-bottom: 1px solid rgba(37, 99, 235, 0.2);
        margin-bottom: 8px;
      }
      
      .file-preview-container.has-files {
        display: block;
      }
      
      .file-preview-list {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
      }
      
      .file-preview-item {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 6px 10px;
        background: rgba(37, 99, 235, 0.1);
        border-radius: 6px;
        font-size: 14px;
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
        color: #1e3a8a;
      }
      
      .file-preview-item img {
        width: 40px;
        height: 40px;
        object-fit: cover;
        border-radius: 4px;
      }
      
      .file-preview-item .file-info {
        flex: 1;
        min-width: 0;
      }
      
      .file-preview-item .file-name {
        font-weight: 500;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      
      .file-preview-item .file-size {
        font-size: 12px;
        color: #6b7280;
      }
      
      .file-preview-item .file-remove {
        background: none;
        border: none;
        color: #ef4444;
        cursor: pointer;
        padding: 4px;
        font-size: 18px;
        line-height: 1;
        opacity: 0.7;
        transition: opacity 0.2s;
      }
      
      .file-preview-item .file-remove:hover {
        opacity: 1;
      }
      
      .chat-input-row {
        display: flex;
        align-items: flex-end;
        gap: 8px;
        min-width: 0;
        width: 100%;
        position: relative;
      }
      
      .input-bottom-controls {
        display: flex;
        align-items: center;
        gap: 8px;
        position: absolute;
        bottom: 0;
        left: 2px;
        padding-bottom: 4px;
        z-index: 10;
        pointer-events: auto;
      }
      
      .reload-btn {
        padding: 8px;
        background: transparent;
        color: #2563eb;
        border: none;
        border-radius: 8px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: background 0.2s, color 0.2s;
        height: 36px;
        width: 36px;
        flex-shrink: 0;
        position: relative;
        z-index: 11;
        pointer-events: auto;
      }
      
      .reload-btn img {
        filter: brightness(0) saturate(100%) invert(27%) sepia(95%) saturate(2598%) hue-rotate(212deg) brightness(99%) contrast(96%);
        width: 20px !important;
        height: 20px !important;
        object-fit: contain;
        transition: filter 0.2s;
      }
      
      .reload-btn:hover {
        background: rgba(37, 99, 235, 0.1);
      }
      
      .reload-btn:hover img {
        filter: brightness(0) saturate(100%) invert(27%) sepia(95%) saturate(2598%) hue-rotate(212deg) brightness(110%) contrast(96%);
      }
      
      .bug-report-btn {
        padding: 8px;
        background: transparent;
        color: #2563eb;
        border: none;
        border-radius: 8px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: background 0.2s, color 0.2s, transform 0.2s;
        height: 40px;
        width: 40px;
        flex-shrink: 0;
        position: relative;
        z-index: 11;
        pointer-events: auto;
        margin-right: 8px;
        transform: translate(-60px, 42px);
      }

      .send-controls.send-controls--pro .bug-report-btn {
        transform: translate(-84px, 42px);
      }
      
      .bug-report-btn img {
        filter: brightness(0) saturate(100%) invert(27%) sepia(95%) saturate(2598%) hue-rotate(212deg) brightness(99%) contrast(96%);
        width: 28px !important;
        height: 28px !important;
        object-fit: contain;
        transition: filter 0.2s;
      }
      
      .bug-report-btn:hover {
        background: rgba(37, 99, 235, 0.1);
      }
      
      .bug-report-btn:hover img {
        filter: brightness(0) saturate(100%) invert(27%) sepia(95%) saturate(2598%) hue-rotate(212deg) brightness(110%) contrast(96%);
      }
      
      .bug-report-popup {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        display: none;
        align-items: center;
        justify-content: center;
        z-index: 10000;
        backdrop-filter: blur(4px);
      }
      
      .bug-report-popup.active {
        display: flex;
      }
      
      .bug-report-popup-content {
        background: white;
        border-radius: 16px;
        padding: 24px;
        max-width: 500px;
        width: 90%;
        max-height: 80vh;
        overflow-y: auto;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
        position: relative;
      }
      
      .bug-report-popup-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 20px;
      }
      
      .bug-report-popup-title {
        font-size: 24px;
        font-weight: bold;
        color: #1e3a8a;
        margin: 0;
      }
      
      .bug-report-popup-close {
        background: transparent;
        border: none;
        font-size: 28px;
        color: #6b7280;
        cursor: pointer;
        padding: 0;
        width: 32px;
        height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 8px;
        transition: background 0.2s;
      }
      
      .bug-report-popup-close:hover {
        background: rgba(0, 0, 0, 0.05);
      }
      
      .bug-report-form {
        display: flex;
        flex-direction: column;
        gap: 16px;
      }
      
      .bug-report-form-group {
        display: flex;
        flex-direction: column;
        gap: 8px;
      }
      
      .bug-report-form-label {
        font-size: 14px;
        font-weight: 600;
        color: #374151;
      }
      
      .bug-report-form-input,
      .bug-report-form-textarea {
        padding: 10px 12px;
        border: 1px solid #d1d5db;
        border-radius: 8px;
        font-size: 14px;
        font-family: inherit;
        transition: border-color 0.2s;
      }
      
      .bug-report-form-input:focus,
      .bug-report-form-textarea:focus {
        outline: none;
        border-color: #2563eb;
        box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
      }
      
      .bug-report-form-textarea {
        resize: vertical;
        min-height: 120px;
      }
      
      .bug-report-form-actions {
        display: flex;
        gap: 12px;
        justify-content: flex-end;
        margin-top: 8px;
      }
      
      .bug-report-form-submit,
      .bug-report-form-cancel {
        padding: 10px 20px;
        border: none;
        border-radius: 8px;
        font-size: 14px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s;
      }
      
      .bug-report-form-submit {
        background: #2563eb;
        color: white;
      }
      
      .bug-report-form-submit:hover {
        background: #1d4ed8;
      }
      
      .bug-report-form-submit:disabled {
        background: #9ca3af;
        cursor: not-allowed;
      }
      
      .bug-report-form-cancel {
        background: #f3f4f6;
        color: #374151;
      }
      
      .bug-report-form-cancel:hover {
        background: #e5e7eb;
      }
      
      .message-tag-selector {
        position: relative;
        margin-left: 8px;
        transform: translate(-5px, 0px);
      }
      
      .message-tag-btn {
        display: flex;
        align-items: center;
        gap: 4px;
        padding: 4px 12px;
        background: #2563eb;
        border: none;
        border-radius: 18px;
        cursor: pointer;
        transition: background 0.2s;
        color: white;
        font-size: 14px;
        font-weight: 500;
        height: 32px;
        flex-shrink: 0;
        position: relative;
        z-index: 11;
        pointer-events: auto;
      }
      
      .message-tag-btn:hover {
        background: #1d4ed8;
      }
      
      .message-tag-text {
        color: white;
        font-weight: bold;
        font-family: inherit;
      }
      
      .message-tag-chevron {
        color: white;
        transition: transform 0.2s;
      }
      
      .message-tag-selector.open .message-tag-chevron {
        transform: rotate(180deg);
      }
      
      .message-tag-dropdown {
        position: absolute;
        bottom: calc(100% + 8px);
        left: 50%;
        transform: translateX(-50%);
        background: rgba(255, 255, 255, 0.95);
        border: 1px solid rgba(37, 99, 235, 0.2);
        border-radius: 12px;
        box-shadow: 0 4px 16px rgba(37, 99, 235, 0.15);
        min-width: 165px;
        padding: 8px;
        display: none;
        z-index: 1000;
        backdrop-filter: blur(10px);
      }
      
      .message-tag-selector.open .message-tag-dropdown {
        display: block;
      }
      
      .message-tag-option {
        padding: 10px 12px;
        cursor: pointer;
        border-radius: 8px;
        transition: background 0.2s;
      }
      
      .message-tag-option:hover {
        background: rgba(37, 99, 235, 0.1);
      }
      
      .message-tag-option-name {
        color: #1e3a8a;
        font-size: 14px;
        font-weight: 500;
      }
      
      .file-upload-btn {
        padding: 8px;
        background: transparent;
        color: #2563eb;
        border: none;
        border-radius: 8px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: background 0.2s;
        height: 36px;
        width: 36px;
        flex-shrink: 0;
        position: relative;
        z-index: 11;
        pointer-events: auto;
      }
      
      .file-upload-btn img {
        filter: brightness(0) saturate(100%) invert(27%) sepia(95%) saturate(2598%) hue-rotate(212deg) brightness(99%) contrast(96%);
        width: 20px !important;
        height: 20px !important;
        object-fit: contain;
        transition: filter 0.2s;
      }
      
      .file-upload-btn:hover {
        background: rgba(37, 99, 235, 0.1);
      }
      
      .file-upload-btn:hover img {
        filter: brightness(0) saturate(100%) invert(27%) sepia(95%) saturate(2598%) hue-rotate(212deg) brightness(110%) contrast(96%);
      }
      
      .file-upload-btn input {
        display: none;
      }
      
      .chat-input-wrapper {
        flex: 1;
        position: relative;
        display: flex;
        align-items: center;
        margin-left: 0;
        margin-bottom: 40px;
        margin-top: -5px;
      }
      
      .chat-input-wrapper::before {
        content: '';
        position: absolute;
        bottom: 0;
        left: 0;
        width: 56px;
        height: 40px;
        z-index: 5;
        pointer-events: none;
      }
      
      .chat-input {
        width: 100%;
        padding: 12px 16px 12px 8px;
        border: none;
        border-radius: 0;
        font-size: 16px;
        font-family: inherit;
        resize: none;
        min-height: 48px;
        max-height: 50px;
        background: transparent;
        color: #1e3a8a;
        line-height: 1.5;
        box-sizing: border-box;
        overflow-y: auto;
        overflow-x: hidden;
        margin: 0;
      }
      
      .chat-input::placeholder {
        color: #6b7280;
      }
      
      .chat-input:focus {
        outline: none;
      }
      
      .chat-input.multi-line {
        overflow-y: auto;
      }
      
      .send-btn {
        padding: 8px;
        background: transparent;
        border: none;
        border-radius: 8px;
        cursor: pointer;
        transition: background 0.2s;
        height: 48px;
        width: 48px;
        flex-shrink: 0;
        position: absolute;
        bottom: 32px;
        right: 0;
        display: flex;
        align-items: center;
        justify-content: center;
      }
      
      .send-btn img {
        width: 30px !important;
        height: 30px !important;
        object-fit: contain;
        transition: filter 0.2s;
      }
      
      .send-btn:not(:disabled) img {
        filter: brightness(0) saturate(100%) invert(27%) sepia(95%) saturate(2598%) hue-rotate(212deg) brightness(99%) contrast(96%);
      }
      
      .send-btn:hover:not(:disabled) {
        background: rgba(37, 99, 235, 0.1);
      }
      
      .send-btn:hover:not(:disabled) img {
        filter: brightness(0) saturate(100%) invert(27%) sepia(95%) saturate(2598%) hue-rotate(212deg) brightness(110%) contrast(96%);
      }
      
      .send-btn:disabled {
        opacity: 0.5;
        cursor: not-allowed;
      }
      
      .send-btn:disabled img {
        filter: brightness(0) invert(0.4);
      }
      
      .send-controls {
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        gap: 8px;
        flex-shrink: 0;
        position: relative;
      }
      
      .model-selector {
        position: relative;
      }
      
      .model-selector-btn {
        display: flex;
        align-items: center;
        gap: 4px;
        padding: 6px 10px;
        background: transparent;
        border: none;
        border-radius: 6px;
        cursor: pointer;
        transition: background 0.2s;
        color: #1e3a8a;
        font-size: 14px;
        font-weight: 500;
      }
      
      .model-selector-btn:hover {
        background: rgba(37, 99, 235, 0.1);
      }
      
      .model-selector-text {
        color: #1e3a8a;
        font-weight: bold;
        font-family: inherit;
      }
      
      .model-selector-chevron {
        color: #1e3a8a;
        transition: transform 0.2s;
      }
      
      .model-selector.open .model-selector-chevron {
        transform: rotate(180deg);
      }
      
      .model-dropdown {
        position: absolute;
        bottom: calc(100% + 8px);
        right: 0;
        background: rgba(255, 255, 255, 0.95);
        border: 1px solid rgba(37, 99, 235, 0.2);
        border-radius: 12px;
        box-shadow: 0 4px 16px rgba(37, 99, 235, 0.15);
        min-width: 200px;
        padding: 8px;
        display: none;
        z-index: 1000;
        backdrop-filter: blur(10px);
      }
      
      .model-selector.open .model-dropdown {
        display: block;
      }
      
      .model-dropdown-header {
        padding: 12px 16px 8px 16px;
        color: #6b7280;
        font-size: 12px;
        font-weight: 500;
        text-transform: uppercase;
        letter-spacing: 0.5px;
      }
      
      .model-option {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 12px 16px;
        border-radius: 8px;
        cursor: pointer;
        transition: background 0.2s;
      }
      
      .model-option:hover {
        background: rgba(37, 99, 235, 0.1);
      }
      
      .model-option-content {
        flex: 1;
      }
      
      .model-option-name {
        color: #1e3a8a;
        font-size: 14px;
        font-weight: 500;
        margin-bottom: 4px;
      }
      
      .model-option-description {
        color: #6b7280;
        font-size: 12px;
      }
      
      .model-badge {
        background: #2563eb;
        color: white;
        font-size: 10px;
        font-weight: 600;
        padding: 2px 6px;
        border-radius: 10px;
        margin-left: 12px;
      }
      
      .typing-indicator {
        padding: 12px 16px;
        color: #6b7280;
        font-style: italic;
      }

      .message-image-loading {
        margin-top: 8px;
        padding-top: 4px;
        padding-bottom: 4px;
      }

      .image-thumbnail-strip {
        display: none;
        flex-direction: column;
        gap: 6px;
        padding: 8px 12px 0;
        border-top: 1px solid #e5e7eb;
      }

      .image-thumbnail-strip.visible {
        display: flex;
      }

      .image-thumbnail-strip-label {
        font-size: 11px;
        font-weight: 600;
        color: #6b7280;
        text-transform: uppercase;
        letter-spacing: 0.04em;
      }

      .image-thumbnail-strip-header {
        display: flex;
        align-items: center;
        gap: 6px;
      }

      .image-thumbnail-strip-help-wrap {
        position: relative;
        display: inline-flex;
        align-items: center;
      }

      .image-thumbnail-strip-help {
        width: 16px;
        height: 16px;
        border-radius: 50%;
        border: 1px solid #9ca3af;
        background: #f9fafb;
        color: #6b7280;
        font-size: 11px;
        font-weight: 700;
        line-height: 1;
        padding: 0;
        cursor: help;
        flex-shrink: 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
      }

      .image-thumbnail-strip-help:hover,
      .image-thumbnail-strip-help:focus-visible {
        border-color: #2563eb;
        color: #2563eb;
        background: #eff6ff;
        outline: none;
      }

      .image-thumbnail-strip-tooltip {
        position: absolute;
        left: 50%;
        bottom: calc(100% + 8px);
        transform: translateX(-50%);
        z-index: 20;
        visibility: hidden;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.15s ease, visibility 0.15s ease;
        width: max-content;
        max-width: 260px;
        padding: 8px 10px;
        border-radius: 8px;
        background: #1e3a8a;
        color: #fff;
        font-size: 12px;
        font-weight: 400;
        line-height: 1.45;
        text-transform: none;
        letter-spacing: normal;
        text-align: left;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
      }

      .image-thumbnail-strip-tooltip::after {
        content: '';
        position: absolute;
        top: 100%;
        left: 50%;
        transform: translateX(-50%);
        border: 6px solid transparent;
        border-top-color: #1e3a8a;
      }

      .image-thumbnail-strip-help-wrap:hover .image-thumbnail-strip-tooltip,
      .image-thumbnail-strip-help-wrap:focus-within .image-thumbnail-strip-tooltip {
        visibility: visible;
        opacity: 1;
      }

      .image-thumbnail-strip-scroll {
        display: flex;
        gap: 8px;
        overflow-x: auto;
        padding-bottom: 4px;
        scrollbar-width: thin;
      }

      .image-thumbnail-item {
        flex: 0 0 auto;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4px;
        cursor: pointer;
        background: none;
        border: none;
        padding: 0;
        font: inherit;
      }

      .image-thumbnail-preview {
        width: 64px;
        height: 64px;
        border-radius: 8px;
        object-fit: cover;
        border: 2px solid transparent;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
        transition: border-color 0.15s, box-shadow 0.15s;
      }

      .image-thumbnail-item.selected .image-thumbnail-preview {
        border-color: #2563eb;
        box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25);
      }

      .image-thumbnail-item:hover .image-thumbnail-preview {
        border-color: #93c5fd;
      }

      .image-thumbnail-caption {
        max-width: 88px;
        font-size: 10px;
        color: #6b7280;
        text-align: center;
        line-height: 1.2;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
      }

      .image-thumbnail-item.selected .image-thumbnail-caption {
        color: #1e3a8a;
        font-weight: 600;
      }
      
      .empty-state {
        text-align: center;
        color: #6b7280;
        padding: 40px 20px;
        width: 100%;
        box-sizing: border-box;
      }

      .empty-state h3 {
        color: #1e3a8a;
        margin-bottom: 8px;
      }

      /* AI-generated image container - relative positioning for download button */
      /* Masked image carousel - Simple implementation */
      .masked-image-carousel {
        position: relative;
        display: inline-block;
        max-width: 100%;
      }
      
      .masked-image-carousel-viewport {
        position: relative;
        display: inline-block;
        overflow: hidden;
      }
      
      .masked-image-carousel-track {
        display: flex;
        transition: transform 0.3s ease;
      }
      
      .masked-image-carousel-item {
        flex: 0 0 100%;
        position: relative;
      }
      
      .masked-image-carousel-nav {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        background: rgba(0, 0, 0, 0.6);
        border: none;
        color: white;
        font-size: 24px;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 20;
        transition: background 0.2s;
      }
      
      .masked-image-carousel-nav:hover {
        background: rgba(0, 0, 0, 0.8);
      }
      
      .masked-image-carousel-nav:disabled {
        opacity: 0.3;
        cursor: not-allowed;
      }
      
      .masked-image-carousel-nav.prev {
        left: 10px;
      }
      
      .masked-image-carousel-nav.next {
        right: 10px;
      }
      
      /* Right arrow positioned inside image container */
      .masked-image-carousel-item .ai-image-container .masked-image-carousel-nav.next {
        position: absolute;
        right: 10px;
        top: 50%;
        transform: translateY(-50%);
      }
      
      .masked-image-carousel-dots {
        display: flex;
        justify-content: center;
        gap: 8px;
        padding: 0;
        position: absolute;
        bottom: 12px;
        left: 50%;
        transform: translateX(-50%);
        z-index: 15;
      }
      
      /* Dots positioned inside image container */
      .masked-image-carousel-item .ai-image-container .masked-image-carousel-dots {
        position: absolute;
        bottom: 12px;
        left: 50%;
        transform: translateX(-50%);
      }
      
      .masked-image-carousel-dot {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: rgba(0, 0, 0, 0.3);
        border: none;
        cursor: pointer;
        padding: 0;
        transition: background 0.2s, transform 0.2s;
      }
      
      .masked-image-carousel-dot:hover {
        background: rgba(0, 0, 0, 0.5);
        transform: scale(1.2);
      }
      
      .masked-image-carousel-dot.active {
        background: #2563eb;
        transform: scale(1.3);
      }
      
      .ai-image-container {
        position: relative;
        display: inline-block;
        max-width: 100%;
      }
      
      /* AI-generated image styles - smaller by default, clickable */
      .ai-generated-image {
        max-width: 100%;
        max-height: 300px;
        border-radius: 8px;
        display: block;
        margin: 0;
        width: auto;
        height: auto;
        box-sizing: border-box;
        cursor: pointer;
        transition: transform 0.2s, opacity 0.2s;
        transform-origin: center;
      }
      
      /* Scale image when hovering over container (image or button) */
      .ai-image-container:hover .ai-generated-image {
        opacity: 0.9;
        transform: scale(1.02);
      }
      
      /* Download button for AI-generated images */
      .ai-image-download-btn {
        position: absolute;
        top: 8px;
        right: 8px;
        background: rgba(0, 0, 0, 0.7);
        border: none;
        border-radius: 6px;
        width: 36px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: background 0.2s, transform 0.2s;
        z-index: 10;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
        padding: 0;
        transform-origin: center;
      }
      
      .ai-image-download-btn img {
        width: 20px;
        height: 20px;
        object-fit: contain;
        filter: brightness(0) invert(1);
      }
      
      .ai-image-download-btn:hover {
        background: rgba(0, 0, 0, 0.9);
        transform: scale(1.1);
      }
      
      .ai-image-download-btn:active {
        transform: scale(0.95);
      }
      
      /* Move download button to maintain distance from edge when image scales */
      /* When image scales by 1.02 from center, the top-right corner moves outward */
      /* For a typical 300px image: corner moves by ~1.5px (half of 3px increase) */
      /* We use a small fixed value that works well for most image sizes */
      .ai-image-container:hover .ai-image-download-btn {
        transform: translate(1.5px, -1.5px);
      }
      
      .ai-image-container:hover .ai-image-download-btn:hover {
        transform: translate(1.5px, -1.5px) scale(1.1);
      }
      
      .ai-image-container:hover .ai-image-download-btn:active {
        transform: translate(1.5px, -1.5px) scale(0.95);
      }
      
      /* Mask button - styled like download button, positioned to the left */
      .ai-image-mask-btn {
        position: absolute;
        top: 8px;
        right: 48px; /* Position to the left of download button (36px button + 8px gap + 4px spacing) */
        background: rgba(0, 0, 0, 0.7);
        border: none;
        border-radius: 6px;
        width: 36px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: background 0.2s, transform 0.2s;
        z-index: 10;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
        padding: 0;
        transform-origin: center;
      }
      
      .ai-image-mask-btn img {
        width: 20px;
        height: 20px;
        object-fit: contain;
        filter: brightness(0) invert(1);
      }
      
      .ai-image-mask-btn:hover {
        background: rgba(0, 0, 0, 0.9);
        transform: scale(1.1);
      }
      
      .ai-image-mask-btn:active {
        transform: scale(0.95);
      }
      
      /* Move mask button to maintain distance from edge when image scales (same as download button) */
      .ai-image-container:hover .ai-image-mask-btn {
        transform: translate(1.5px, -1.5px);
      }
      
      .ai-image-container:hover .ai-image-mask-btn:hover {
        transform: translate(1.5px, -1.5px) scale(1.1);
      }
      
      .ai-image-container:hover .ai-image-mask-btn:active {
        transform: translate(1.5px, -1.5px) scale(0.95);
      }
      
      /* Mask editor modal */
      .mask-editor-modal {
        display: none;
        position: fixed;
        z-index: 10001;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.6);
        backdrop-filter: blur(5px);
        animation: fadeIn 0.3s ease-in;
      }
      
      /* Blur the CANVASES, not the container — otherwise the loading spinner/text
         overlay (a child of the container) would get blurred along with them. */
      .mask-editor-canvas-container.processing .mask-editor-canvas,
      .mask-editor-canvas-container.processing #mask-editor-mask-canvas {
        pointer-events: none;
        cursor: not-allowed;
        filter: blur(3px);
        opacity: 0.7;
        transition: filter 0.3s, opacity 0.3s;
      }
      
      .mask-editor-canvas-container.processing #mask-editor-mask-canvas {
        opacity: 0.5;
      }
      
      .mask-editor-modal.active {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 20px;
        box-sizing: border-box;
      }
      
      .mask-editor-content {
        background: #ffffff;
        border-radius: 16px;
        padding: 24px;
        max-width: 90vw;
        max-height: 90vh;
        display: flex;
        flex-direction: column;
        gap: 16px;
        box-sizing: border-box;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
      }
      
      .mask-editor-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        color: #1e3a8a;
      }
      
      .mask-editor-title {
        font-size: 20px;
        font-weight: 600;
        margin: 0;
        color: #1e3a8a;
      }
      
      .mask-editor-close {
        background: transparent;
        border: none;
        color: #1e3a8a;
        font-size: 32px;
        cursor: pointer;
        padding: 0;
        width: 36px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 6px;
        transition: background 0.2s;
      }
      
      .mask-editor-close:hover {
        background: rgba(37, 99, 235, 0.1);
        color: #2563eb;
      }
      
      .mask-editor-canvas-container {
        position: relative;
        display: inline-block;
        border: 2px solid #2563eb;
        border-radius: 8px;
        overflow: hidden;
        background: #000;
      }
      
      .mask-editor-canvas {
        display: block;
        max-width: 100%;
        max-height: 70vh;
        cursor: crosshair;
      }
      
      #mask-editor-mask-canvas {
        position: absolute;
        top: 0;
        left: 0;
        pointer-events: auto;
        mix-blend-mode: multiply;
      }
      
      .mask-editor-controls {
        display: flex;
        flex-direction: column;
        gap: 12px;
        color: #1e3a8a;
        /* Tighten the gap between the image and the brush/erase row */
        margin-top: -8px;
      }
      
      .mask-editor-brush-controls {
        display: flex;
        align-items: center;
        gap: 12px;
        flex-wrap: wrap;
      }
      
      .mask-editor-brush-label {
        font-size: 14px;
        font-weight: 500;
        color: #1e3a8a;
      }
      
      .mask-editor-brush-slider {
        flex: 1;
        min-width: 150px;
        max-width: 300px;
        height: 6px;
        border-radius: 3px;
        background: #e5e7eb;
        outline: none;
        -webkit-appearance: none;
        appearance: none;
      }
      
      .mask-editor-brush-slider::-webkit-slider-thumb {
        -webkit-appearance: none;
        appearance: none;
        width: 18px;
        height: 18px;
        border-radius: 50%;
        background: #2563eb;
        cursor: pointer;
        border: 2px solid #ffffff;
        box-shadow: 0 2px 4px rgba(37, 99, 235, 0.3);
      }
      
      .mask-editor-brush-slider::-webkit-slider-thumb:hover {
        background: #1d4ed8;
        box-shadow: 0 2px 6px rgba(37, 99, 235, 0.5);
      }
      
      .mask-editor-brush-slider::-moz-range-thumb {
        width: 18px;
        height: 18px;
        border-radius: 50%;
        background: #2563eb;
        cursor: pointer;
        border: 2px solid #ffffff;
        box-shadow: 0 2px 4px rgba(37, 99, 235, 0.3);
      }
      
      .mask-editor-brush-slider::-moz-range-thumb:hover {
        background: #1d4ed8;
        box-shadow: 0 2px 6px rgba(37, 99, 235, 0.5);
      }
      
      .mask-editor-brush-slider::-moz-range-track {
        height: 6px;
        border-radius: 3px;
        background: #e5e7eb;
      }
      
      .mask-editor-brush-size-display {
        min-width: 40px;
        text-align: center;
        font-weight: 600;
        color: #2563eb;
      }
      
      .mask-editor-toolrow {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        flex-wrap: wrap;
      }
      .mask-editor-note {
        margin: 0;
        text-align: right;
        font-size: 12.5px;
        font-style: italic;
        color: #6b7280;
      }

      .mask-editor-tools {
        display: inline-flex;
        gap: 6px;
        padding: 4px;
        border-radius: 10px;
        background: #f3f4f6;
        border: 1px solid #e5e7eb;
        align-self: flex-start;
      }
      .mask-editor-tool-btn {
        display: inline-flex;
        align-items: center;
        gap: 7px;
        padding: 7px 14px;
        border: none;
        border-radius: 8px;
        background: transparent;
        color: #1e3a8a;
        font-size: 14px;
        font-weight: 600;
        font-family: inherit;
        cursor: pointer;
        transition: background 0.15s, color 0.15s;
      }
      .mask-editor-tool-btn:hover {
        background: rgba(37, 99, 235, 0.1);
      }
      .mask-editor-tool-btn.is-active {
        background: #2563eb;
        color: #fff;
      }
      .mask-editor-tool-btn svg {
        width: 16px;
        height: 16px;
      }

      .mask-editor-actions {
        display: flex;
        gap: 8px;
        flex-wrap: wrap;
      }
      
      .mask-editor-btn {
        padding: 10px 20px;
        border: none;
        border-radius: 8px;
        font-size: 14px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s;
      }
      
      .mask-editor-btn-primary {
        background: #2563eb;
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
      }
      
      .mask-editor-btn-primary img {
        width: 16px;
        height: 16px;
        margin-left: 8px;
        filter: brightness(0) invert(1);
        object-fit: contain;
      }
      
      .mask-editor-btn-primary:hover {
        background: #1d4ed8;
      }
      
      .mask-editor-btn-secondary {
        background: #f3f4f6;
        color: #1e3a8a;
        border: 1px solid #e5e7eb;
      }
      #mask-editor-clear {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
      }
      .mask-editor-clear-icon {
        width: 15px;
        height: 15px;
        flex-shrink: 0;
      }
      
      .mask-editor-btn-secondary:hover {
        background: #e5e7eb;
        border-color: #2563eb;
        color: #2563eb;
      }
      
      .mask-editor-btn:disabled {
        opacity: 0.5;
        cursor: not-allowed;
      }
      
      .mask-editor-prompt-container {
        display: flex;
        flex-direction: column;
        gap: 8px;
      }
      
      .mask-editor-prompt-label {
        font-size: 14px;
        font-weight: 500;
        color: #1e3a8a;
      }
      
      .mask-editor-prompt-input {
        padding: 12px;
        border: 2px solid #e5e7eb;
        border-radius: 8px;
        background: #ffffff;
        color: #1e3a8a;
        font-size: 14px;
        font-family: inherit;
      }
      
      .mask-editor-prompt-input:focus {
        outline: none;
        border-color: #2563eb;
        background: #ffffff;
        box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
      }
      
      .mask-editor-prompt-input::placeholder {
        color: #9ca3af;
      }

      #mask-editor-ref-file {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
      }
      .mask-editor-ref-container {
        display: flex;
        flex-direction: column;
        gap: 8px;
      }
      .mask-editor-ref-label {
        font-size: 14px;
        font-weight: 500;
        color: #1e3a8a;
      }
      .mask-editor-ref-row {
        display: flex;
        align-items: center;
        gap: 12px;
        flex-wrap: wrap;
      }
      .mask-editor-ref-add {
        display: inline-flex;
        align-items: center;
        padding: 8px 14px;
        border-radius: 8px;
        border: 1px dashed #93c5fd;
        background: rgba(37, 99, 235, 0.06);
        color: #2563eb;
        font-size: 13px;
        font-weight: 600;
        cursor: pointer;
        transition: background 0.18s ease, border-color 0.18s ease;
      }
      .mask-editor-ref-add:hover {
        background: rgba(37, 99, 235, 0.12);
        border-color: #2563eb;
      }
      .mask-editor-ref-add.hidden {
        display: none;
      }
      .mask-editor-ref-preview {
        position: relative;
        display: inline-flex;
      }
      .mask-editor-ref-preview.hidden {
        display: none;
      }
      .mask-editor-ref-preview img {
        display: block;
        width: 72px;
        height: 72px;
        object-fit: cover;
        border-radius: 8px;
        border: 1px solid rgba(37, 99, 235, 0.25);
      }
      .mask-editor-ref-remove {
        position: absolute;
        top: -6px;
        right: -6px;
        width: 22px;
        height: 22px;
        border: none;
        border-radius: 999px;
        background: #1e3a8a;
        color: #fff;
        font-size: 14px;
        line-height: 1;
        cursor: pointer;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
      }
      .mask-editor-ref-hint {
        font-size: 12px;
        color: #64748b;
        line-height: 1.4;
      }

      /* MOBILE ONLY: the mask editor's top (header) and bottom (action buttons)
         were getting hidden behind the mobile browser's URL bar / toolbar. The
         modal is positioned to the VISUAL viewport in JS (syncMaskEditorToViewport)
         so it never sits behind the browser chrome; this block is the styling +
         a 100dvh fallback for browsers without the visualViewport API. The modal
         scrolls, with breathing room top/bottom (safe-area insets for notches). */
      @media (max-width: 768px) {
        .mask-editor-modal {
          height: 100dvh;
        }
        .mask-editor-modal.active {
          justify-content: flex-start;
          overflow-y: auto;
          -webkit-overflow-scrolling: touch;
          padding-top: calc(env(safe-area-inset-top, 0px) + 28px);
          padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 28px);
          padding-left: 14px;
          padding-right: 14px;
        }
        .mask-editor-content {
          max-height: none;
          max-width: 100%;
          width: 100%;
          margin: auto 0;
        }
      }

      /* Image modal/lightbox */
      .image-modal {
        display: none;
        position: fixed;
        z-index: 10000;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.9);
        backdrop-filter: blur(5px);
        animation: fadeIn 0.3s ease-in;
        cursor: pointer;
      }
      
      .image-modal.active {
        display: flex;
        align-items: center;
        justify-content: center;
      }
      
      .image-modal-content {
        max-width: 95%;
        max-height: 95%;
        width: auto;
        height: auto;
        border-radius: 8px;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
        animation: zoomIn 0.3s ease-in;
        cursor: default;
      }
      
      @keyframes zoomIn {
        from { transform: scale(0.8); opacity: 0; }
        to { transform: scale(1); opacity: 1; }
      }
      
      .image-modal-close {
        position: absolute;
        top: 20px;
        right: 30px;
        cursor: pointer;
        z-index: 10001;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: rgba(0, 0, 0, 0.5);
        border-radius: 50%;
        transition: background 0.2s;
        font-size: 0;
        line-height: 1;
      }
      
      .image-modal-close::before {
        content: '×';
        display: block;
        color: white;
        font-size: 40px;
        font-weight: bold;
        transform: translateY(-3px);
      }
      
      .image-modal-close:hover {
        background: rgba(0, 0, 0, 0.8);
      }
      
      @media (max-width: 768px) {
        .chat-container {
          height: calc(100vh - 100px);
          padding: 10px;
        }
        
        .message-content {
          max-width: 75%;
        }
        
        .chat-input-container {
          padding: 12px;
        }
        
        .file-preview-item {
          max-width: 100%;
        }
      }
      
      /* Custom Stagify Scrollbar */
      * {
        scrollbar-width: thin;
        scrollbar-color: #2563eb rgba(255, 255, 255, 0.2);
      }
      
      *::-webkit-scrollbar {
        width: 10px;
        height: 10px;
      }
      
      *::-webkit-scrollbar-track {
        background: rgba(255, 255, 255, 0.1);
        border-radius: 10px;
      }
      
      *::-webkit-scrollbar-thumb {
        background: #2563eb;
        border-radius: 10px;
        border: 2px solid transparent;
        background-clip: padding-box;
      }
      
      *::-webkit-scrollbar-thumb:hover {
        background: #1d4ed8;
        background-clip: padding-box;
      }
