/* ===========================================
   CELLYN Design System - CSS Custom Properties
   Phase 5: UI Polish - Unified Color Palette
   =========================================== */

:root {
    /* Primary Colors - Updated Brand Palette */
    --color-primary: #7055E2;
    --color-primary-dark: #461FC5;
    --color-primary-light: #DDD8F1;
    --color-gradient-start: #7F65EB;
    --color-gradient-end: #703DC1;

    /* Success Colors */
    --color-success: #22c55e;
    --color-success-bg: #dcfce7;
    --color-success-dark: #16a34a;

    /* Error Colors */
    --color-error: #ef4444;
    --color-error-bg: #fee2e2;
    --color-error-dark: #dc2626;

    /* Warning Colors */
    --color-warning: #f59e0b;
    --color-warning-bg: #fef3c7;
    --color-warning-dark: #d97706;

    /* Neutral Colors */
    --color-text-primary: #1f2937;
    --color-text-secondary: #6b7280;
    --color-text-muted: #9ca3af;
    --color-border: #e5e7eb;
    --color-bg-primary: #ffffff;
    --color-bg-secondary: #f9fafb;
    --color-bg-tertiary: #f3f4f6;

    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-2xl: 20px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.1);

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 300ms ease;
    --transition-slow: 500ms ease;

    /* Z-Index Scale */
    --z-dropdown: 100;
    --z-modal: 200;
    --z-tooltip: 300;
}

/* ===========================================
   Status Indicator - Progress Display
   =========================================== */

.status-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: linear-gradient(135deg, rgba(112, 85, 226, 0.08) 0%, rgba(112, 61, 193, 0.08) 100%);
    border-radius: var(--radius-md);
    border-left: 3px solid var(--color-primary);
    animation: fadeIn 0.3s ease;
}

.status-indicator .spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--color-primary-light);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.status-indicator .status-text {
    color: var(--color-text-primary);
    font-size: 14px;
    font-weight: 500;
}

.analyzing-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--color-bg-secondary);
    border-radius: var(--radius-md);
}

.analyzing-indicator .spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

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

/* ===========================================
   Thinking/Progress Text - Simple Inline
   =========================================== */

.thinking-text {
    color: var(--color-text-secondary);
    font-size: 14px;
    font-style: italic;
    animation: thinkingPulse 1.5s ease-in-out infinite;
}

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

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f5f5f5;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    background: #7F65EB;
    color: white;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-md);
}

.header h1 {
    font-size: 18px;
    font-weight: 600;
}

.status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

/* V4 ENHANCEMENT: Additional status indicators */
.status-dot.hardcode {
    background: #fbbf24;
}

.status-dot.error {
    background: #ef4444;
}

.hardcode-badge {
    background: rgba(251, 191, 36, 0.2);
    color: #92400e;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: 600;
    margin-left: 8px;
}

/* V10 INTEGRATION: Hardcode toggle from v4 */

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

.tabs {
    background: white;
    display: flex;
    border-bottom: 1px solid #e5e7eb;
    padding: 0 8px;
}

.tab {
    padding: 8px 10px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.3s;
    font-size: 13px;
    color: #6b7280;
    font-weight: 500;
}

.tab:hover {
    color: #374151;
}

.tab.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: white;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.selection-card {
    margin: 10px 16px 0 16px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-left: 4px solid #6366f1;
    border-radius: 6px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.selection-card-title {
    font-size: 12px;
    font-weight: 600;
    color: #374151;
    padding: 8px 12px 0 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.selection-card-body {
    padding: 8px 12px 12px 12px;
    color: #1f2937;
    font-size: 13px;
}

/* Tooltip version of current selection (hover over chat area) */
.selection-tooltip {
    position: absolute;
    top: -10px;
    right: 0;
    background: rgba(17,24,39,0.88); /* dark gray */
    color: #fff;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 11px; /* smaller font */
    line-height: 1.2;
    white-space: nowrap; /* single line */
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: none; /* only show on hover */
    pointer-events: none; /* avoid blocking interactions */
    z-index: 20;
}
.chat-container:hover .selection-tooltip {
    display: block;
}

/* Chat Tab Styles */
.chat-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    background: #f9fafb;
}

.message {
    margin-bottom: 12px;
    padding: 10px 14px;
    border-radius: 8px;
    max-width: min(75%, 65ch);
    line-height: 1.45;
    animation: slideIn 0.3s ease-out;
}

.message.user {
    /* Fallback background for old structure without .message-bubble */
    background: #7F65EB;
    color: white;
    margin-left: auto;
    max-width: min(70%, 60ch);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    text-align: left;
    padding: 10px 14px;
    border-radius: 14px;
}

/* Remove background/padding from container when using new bubble structure */
.message.user:has(.message-bubble) {
    background: none;
    padding: 0;
}

.message.assistant {
    background: white;
    border: 1px solid #e5e7eb;
    padding: 10px 14px;
}

/* Remove background/padding from container when using new bubble structure */
.message.assistant:has(.message-bubble) {
    background: none;
    border: none;
    padding: 0;
}

.message.system {
    background: #fef3c7;
    border: 1px solid #fcd34d;
    text-align: center;
    max-width: 100%;
    font-size: 12px;
}

.chat-input-container {
    display: flex;
    gap: 8px;
}

.chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.3s;
}

.chat-input:focus {
    border-color: #7055E2;
}

.send-button {
    padding: 10px 20px;
    background: #7055E2;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s;
}

.send-button:hover {
    background: #703DC1;
}

.send-button:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}

/* Automation Tab Styles */
.automation-section {
    margin-bottom: 24px;
}

.automation-section h3 {
    font-size: 16px;
    margin-bottom: 12px;
    color: #374151;
}

.automation-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}

.automation-btn {
    padding: 12px;
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 13px;
}

.automation-btn:hover {
    background: #f3f4f6;
    border-color: #7055E2;
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.automation-btn.primary {
    background: #7055E2;
    color: white;
    border-color: #7055E2;
}

.automation-btn.primary:hover {
    background: #703DC1;
}

/* Trainer Tab Styles */
.trainer-section {
    background: white;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.trainer-section h3 {
    font-size: 16px;
    margin-bottom: 16px;
    color: #374151;
    display: flex;
    align-items: center;
    gap: 8px;
}

.trainer-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.trainer-input {
    flex: 1;
    padding: 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 13px;
}

.trainer-button {
    padding: 10px 20px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.3s;
}

.trainer-button.start {
    background: #10b981;
    color: white;
}

.trainer-button.stop {
    background: #ef4444;
    color: white;
}

.trainer-button.test {
    background: #3b82f6;
    color: white;
}

.trainer-button.save {
    background: #8b5cf6;
    color: white;
}

.trainer-button:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.trainer-button:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    transform: none;
}

.trainer-status {
    padding: 12px;
    background: #f3f4f6;
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 12px;
}

.trainer-result {
    padding: 12px;
    border-radius: 6px;
    font-size: 13px;
    margin-top: 12px;
}

.recording-indicator {
    background: #fee2e2;
    border: 2px solid #ef4444;
    color: #dc2626;
    padding: 12px;
    border-radius: 6px;
    text-align: center;
    font-weight: bold;
    animation: blink 1s infinite;
}

@keyframes blink {
    50% { opacity: 0.5; }
}

.actions-list {
    max-height: 200px;
    overflow-y: auto;
    background: #f8f9fa;
    border-radius: 6px;
    padding: 12px;
    font-family: monospace;
    font-size: 11px;
}

.action-item {
    padding: 4px 0;
    border-bottom: 1px solid #e5e7eb;
}

.skills-list {
    max-height: 300px;
    overflow-y: auto;
}

/* Settings Tab Styles */
.settings-group {
    background: white;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.settings-group h3 {
    font-size: 16px;
    margin-bottom: 16px;
    color: #374151;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f3f4f6;
}

.setting-item:last-child {
    border-bottom: none;
}

.setting-label {
    font-size: 14px;
    color: #4b5563;
}

.setting-value {
    font-size: 14px;
    color: #111827;
    font-weight: 500;
}

.log-container {
    background: #1f2937;
    color: #d1d5db;
    padding: 12px;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    max-height: 200px;
    overflow-y: auto;
}

.log-entry {
    margin-bottom: 4px;
}

.log-time {
    color: #6b7280;
    margin-right: 8px;
}

/* Office Dialog Styles */
.office-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    z-index: 1000;
    min-width: 300px;
    max-width: 500px;
    padding: 20px;
}

.office-dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}

.office-dialog h3 {
    margin-bottom: 16px;
    color: #374151;
}

.office-dialog input {
    width: 100%;
    padding: 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    margin-bottom: 16px;
}

.office-dialog-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.office-dialog-button {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}

.office-dialog-button.primary {
    background: #7055E2;
    color: white;
}

.office-dialog-button.secondary {
    background: #e5e7eb;
    color: #374151;
}

/* Animations */
@keyframes slideIn {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Markdown rendering styles inside messages */
.message h1, .message h2, .message h3, .message h4, .message h5, .message h6 {
    margin: 8px 0 6px 0;
}
.message p { margin: 6px 0; }
.message ul, .message ol { margin: 6px 0 6px 18px; }
.message pre.md-code {
    background: #0b1020;
    color: #f3f4f6;
    padding: 10px;
    border-radius: 6px;
    overflow: auto;
}
.message code.md-inline {
    background: #eef2ff;
    color: #111827;
    padding: 1px 4px;
    border-radius: 4px;
}
 .message a { color: #2563eb; text-decoration: underline; }
 .message hr { border: 0; border-top: 1px solid #e5e7eb; margin: 10px 0; }

/* Responsive width for small screens */
@media (max-width: 640px) {
    .message,
    .message.user,
    .message.assistant {
        max-width: 90%;
    }
}

/* ========================================
   MODERN CHAT UI ENHANCEMENTS
   ======================================== */

/* Modern Input Container */
.chat-input-wrapper {
    padding: 10px 12px;
    border-top: 1px solid #e5e7eb;
    background: white;
}

.input-container {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: #f9fafb;
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    padding: 8px 10px;
    transition: all 0.2s ease;
}

.input-container:focus-within {
    border-color: #6366f1;
    background: white;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.1);
}

.chat-input-modern {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-size: 13px;
    font-family: inherit;
    color: #1f2937;
    outline: none;
    min-height: 20px;
    max-height: 100px;
    line-height: 1.4;
    overflow-y: auto;
}

.chat-input-modern::placeholder {
    color: #9ca3af;
}

.input-actions {
    display: flex;
    align-items: center;
}

.send-btn-modern {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: #6366f1;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.send-btn-modern:hover:not(:disabled) {
    background: #4f46e5;
    transform: scale(1.05);
}

.send-btn-modern:active:not(:disabled) {
    transform: scale(0.95);
}

.send-btn-modern:disabled {
    background: #e5e7eb;
    cursor: not-allowed;
    opacity: 0.5;
}

/* Modern Chat Bubbles */
.message {
    display: flex;
    gap: 8px;
    margin: 10px 0;
    animation: slideInMessage 0.3s ease-out;
    align-items: flex-start;
    font-size: 13px;
}

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

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.avatar-circle {
    width: 100%;
    height: 100%;
    background: #6366f1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 11px;
    font-weight: 600;
}

.avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message-content {
    max-width: 75%;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

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

.message-bubble {
    padding: 8px 12px;
    border-radius: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.message.user .message-bubble {
    background: #7F65EB;
    color: white;
    border-radius: 14px 14px 2px 14px;
}

.message.assistant .message-bubble {
    background: white;
    color: #1f2937;
    border: 1px solid #e5e7eb;
    border-radius: 14px 14px 14px 2px;
}

/* Markdown Formatting Styles */
.message-bubble strong {
    font-weight: 600;
    color: inherit;
}

.message-bubble em {
    font-style: italic;
    color: inherit;
}

.message-bubble code.md-inline {
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.9em;
    color: #d63384;
}

.message.user .message-bubble code.md-inline {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.message-bubble pre.md-code {
    background: #f6f8fa;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 12px;
    overflow-x: auto;
    overflow-y: auto;
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    margin: 8px 0;
}

.message.user .message-bubble pre.md-code {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}

.message-bubble pre.md-code code {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.85em;
    line-height: 1.5;
    color: #1f2937;
}

.message.user .message-bubble pre.md-code code {
    color: #fff;
}

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

.message-bubble li {
    margin: 4px 0;
    line-height: 1.6;
}

.message-bubble h1, .message-bubble h2, .message-bubble h3,
.message-bubble h4, .message-bubble h5, .message-bubble h6 {
    margin: 12px 0 8px 0;
    font-weight: 600;
    line-height: 1.3;
}

.message-bubble h1 { font-size: 1.5em; }
.message-bubble h2 { font-size: 1.3em; }
.message-bubble h3 { font-size: 1.15em; }
.message-bubble h4 { font-size: 1.05em; }
.message-bubble h5 { font-size: 1em; }
.message-bubble h6 { font-size: 0.95em; }

.message-bubble p {
    margin: 8px 0;
    line-height: 1.6;
}

.message-bubble p:first-child {
    margin-top: 0;
}

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

.message-bubble hr {
    border: none;
    border-top: 1px solid #e5e7eb;
    margin: 12px 0;
}

.message.user .message-bubble hr {
    border-top-color: rgba(255, 255, 255, 0.3);
}

.message-bubble a {
    color: #7055E2;
    text-decoration: underline;
}

.message.user .message-bubble a {
    color: #fff;
    text-decoration: underline;
    opacity: 0.9;
}

.message-bubble a:hover {
    opacity: 0.8;
}

.message-timestamp,
.message-time {
    font-size: 10px;
    color: #9ca3af;
    padding: 0 4px;
    margin-top: 4px;
}

/* Specific styles for user and AI timestamps */
.message.user .message-timestamp {
    text-align: right;
}

.message.assistant .message-timestamp {
    text-align: left;
}

.message-actions {
    display: flex;
    gap: 4px;
    margin-top: 4px;
}

.action-btn {
    padding: 6px;
    background: transparent;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    cursor: pointer;
    color: #6b7280;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.action-btn:hover {
    background: #f3f4f6;
    border-color: #6366f1;
    color: #6366f1;
}

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

/* ===========================================
   ENHANCED THINKING INDICATOR
   Phase 26.8.2: Compact, professional status display
   =========================================== */

.thinking-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    margin: 8px 0;
    background: rgba(112, 85, 226, 0.04);
    border-radius: 10px;
    border: 1px solid rgba(112, 85, 226, 0.08);
    animation: thinking-enter 0.25s ease-out;
    position: relative;
    overflow: hidden;
}

/* Shimmer overlay for thinking indicator */
.thinking-indicator::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.1),
        transparent
    );
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

@keyframes thinking-enter {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Enhanced thinking dots with wave animation */
.thinking-dots {
    display: flex;
    gap: 6px;
    position: relative;
    z-index: 1;
}

.thinking-dots .dot {
    width: 5px;
    height: 5px;
    background: #7055E2;
    border-radius: 50%;
    animation: dot-wave 1.4s infinite ease-in-out;
    will-change: transform, opacity;
}

.thinking-dots .dot:nth-child(1) {
    animation-delay: 0s;
}

.thinking-dots .dot:nth-child(2) {
    animation-delay: 0.2s;
}

.thinking-dots .dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes dot-wave {
    0%, 60%, 100% {
        transform: translateY(0) scale(1);
        opacity: 0.6;
    }
    30% {
        transform: translateY(-8px) scale(1.1);
        opacity: 1;
    }
}

/* Enhanced thinking text with smooth transition */
.thinking-text {
    color: #64748b;
    font-size: 13px;
    font-weight: 500;
    transition: opacity 0.2s ease, transform 0.2s ease;
    position: relative;
    z-index: 1;
    flex: 1;
}

/* Thinking text fade animation for state changes */
.thinking-text.fade {
    opacity: 0;
    transform: translateX(-4px);
}

/* Phase 26.8.2: Thinking timer - compact */
.thinking-timer {
    font-size: 11px;
    color: #94a3b8;
    font-variant-numeric: tabular-nums;
    min-width: 24px;
    text-align: right;
    margin-left: auto;
    position: relative;
    z-index: 1;
}

/* Phase 26.4: Transformation animation when converting to message */
.thinking-indicator.transforming {
    animation: thinking-transform 0.15s ease-out forwards;
}

@keyframes thinking-transform {
    to {
        opacity: 0;
        transform: scale(0.98) translateY(-4px);
    }
}

/* Progress bar under thinking indicator (optional) */
.thinking-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 2px;
    background: linear-gradient(90deg, #6366f1, #8b5cf6, #a855f7);
    border-radius: 0 0 16px 16px;
    animation: progress-pulse 2s ease-in-out infinite;
    width: 30%;
}

@keyframes progress-pulse {
    0%, 100% {
        width: 20%;
        opacity: 0.5;
    }
    50% {
        width: 80%;
        opacity: 1;
    }
}

/* Streaming Text Container - CRITICAL for visibility */
.message-text {
    display: inline !important;
    opacity: 1 !important;
    visibility: visible !important;
    color: inherit;
    font-size: inherit;
    line-height: inherit;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* ===========================================
   60 FPS STREAMING ANIMATIONS
   Phase 4: UI Polish - GPU-accelerated animations
   =========================================== */

/* Streaming Cursor - GPU-accelerated blink */
.message.streaming .cursor-blink {
    display: inline-block;
    width: 2px;
    height: 18px;
    background: #6366f1;
    margin-left: 2px;
    vertical-align: middle;
    /* Use transform for GPU acceleration */
    animation: cursor-blink 1s ease-in-out infinite;
    will-change: opacity;
}

@keyframes cursor-blink {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0;
    }
}

/* Cursor fade-out animation when streaming completes */
.cursor-blink.fade-out {
    animation: cursor-fade 0.2s ease-out forwards;
}

@keyframes cursor-fade {
    to {
        opacity: 0;
        transform: scale(0.5);
    }
}

/* Hide cursor when streaming is complete */
.message:not(.streaming) .cursor-blink {
    display: none;
}

/* Message actions slide-in animation */
.message-actions.slide-in {
    animation: slide-in-actions 0.3s ease-out forwards;
}

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

/* Smooth text container for streaming */
.message.streaming .message-text {
    /* Optimize for text rendering during streaming */
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Message bubble entrance animation */
.message {
    animation: message-enter 0.3s ease-out forwards;
    will-change: opacity, transform;
}

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

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #1f2937;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
    z-index: 10000;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* Smooth Scrolling */
.chat-messages {
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* =========================================
   NEW LAYOUT STYLES - Fixed Input & Scrollable Chat
   ========================================= */

/* Simple Header */
.header-simple {
    background: #7F65EB;
    color: white;
    padding: 6px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

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

.header-title h1 {
    font-size: 15px;
    font-weight: 600;
    margin: 0;
    letter-spacing: -0.02em;
}

.header-title h1 #app-version {
    font-weight: 600;
}

.header-title .status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    opacity: 0.9;
}

/* ============================================
   Header Action Icons (Phase 1 UI Upgrade)
   ============================================ */

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-right: 4px;
}

.header-icon-btn {
    width: 26px;
    height: 26px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: all 0.2s;
}

.header-icon-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

.header-icon-btn:active {
    transform: scale(0.95);
}

.header-icon-btn svg {
    width: 16px;
    height: 16px;
}

/* Welcome Text (inside chat tab only) */
.welcome-text-container {
    background: #f9fafb;
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.welcome-text {
    margin: 0;
    font-size: 13px;
    color: #6b7280;
    text-align: center;
    line-height: 1.5;
}

/* New Content Layout */
.content-new {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 76px); /* Full height minus header (40px) + tabs (36px) */
    overflow: hidden;
}

.content-new #chat-tab.active {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Scrollable Chat Messages Area */
.chat-messages-scrollable {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    background: #f9fafb;
    scroll-behavior: smooth;
}

.chat-messages-scrollable::-webkit-scrollbar {
    width: 6px;
}

.chat-messages-scrollable::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages-scrollable::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.chat-messages-scrollable::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Fixed Input at Bottom */
.chat-input-fixed {
    flex-shrink: 0;
    padding: 12px 16px 16px 16px;
    background: white;
    border-top: 1px solid #e5e7eb;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
}

.chat-input-fixed .input-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 100%;
    border: 1.5px solid #e5e7eb;
    border-radius: 12px;
    padding: 6px 6px 6px 14px;
    background: white;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-input-fixed .input-container:focus-within {
    border-color: #7055E2;
    box-shadow: 0 0 0 3px rgba(112, 85, 226, 0.1);
}

.chat-input-fixed .chat-input-modern {
    flex: 1;
    min-height: 40px;
    max-height: 120px;
    padding: 2px 0;
    border: none;
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    outline: none;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: transparent;
}

/* Hide textarea scrollbar */
.chat-input-fixed .chat-input-modern::-webkit-scrollbar {
    width: 0;
    display: none;
}

.chat-input-fixed .chat-input-modern {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.chat-input-fixed .send-btn-modern {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    background: #7F65EB;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.chat-input-fixed .send-btn-modern:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(112, 85, 226, 0.3);
}

.chat-input-fixed .send-btn-modern:active:not(:disabled) {
    transform: scale(0.98);
}

.chat-input-fixed .send-btn-modern:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Undo Button - Inline (after execution results) */
.undo-btn-inline {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: #f3f4f6;
    color: #6b7280;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.undo-btn-inline:hover {
    background: #e5e7eb;
    color: #374151;
    border-color: #d1d5db;
}

.undo-btn-inline:active {
    transform: scale(0.95);
}

.undo-btn-inline.undo-success {
    background: #dcfce7;
    color: #16a34a;
    border-color: #86efac;
}

.undo-btn-inline.undo-warning {
    background: #fef3c7;
    color: #d97706;
    border-color: #fcd34d;
}

.undo-btn-inline svg {
    flex-shrink: 0;
}

/* Override old chat-messages padding since it's now inside scrollable container */
.chat-messages-scrollable .chat-messages {
    padding: 0;
    max-height: none;
    overflow: visible;
}

/* Automation and Settings tabs: display content at top with scrolling */
#automation-tab.active,
#settings-tab.active {
    overflow-y: auto;
    padding: 16px;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Ensure automation and settings sections start from top */
#automation-tab .automation-section,
#settings-tab .settings-group {
    margin: 0;
}

/* === SCROLL TO BOTTOM BUTTON === */
.scroll-to-bottom-btn {
    position: absolute;
    bottom: 80px;
    right: 20px;
    padding: 10px 16px;
    background: #6366f1;
    color: white;
    border: none;
    border-radius: 24px;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
    z-index: 1000;
    opacity: 0;
    transform: translateY(10px);
}

.scroll-to-bottom-btn.show {
    opacity: 1;
    transform: translateY(0);
    display: flex;
}

.scroll-to-bottom-btn:hover {
    background: #4f46e5;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.5);
}

.scroll-to-bottom-btn:active {
    transform: translateY(0);
}

/* Make chat-messages-scrollable container relative for absolute positioning */
.chat-messages-scrollable {
    position: relative;
}

/* === MARKDOWN RENDERING STYLES === */

/* Tables */
.md-table {
    width: 100%;
    max-width: 100%;
    border-collapse: collapse;
    margin: 4px 0;
    font-size: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    overflow-x: auto;
    overflow-y: auto;
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    display: block;
}

.md-table thead {
    background: #7F65EB;
    color: white;
}

.md-table th {
    padding: 6px 8px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid #461FC5;
    white-space: nowrap;
}

.md-table tbody tr {
    border-bottom: 1px solid #e5e7eb;
    transition: background-color 0.15s;
}

.md-table tbody tr:last-child {
    border-bottom: none;
}

.md-table tbody tr:hover {
    background-color: #f9fafb;
}

.md-table tbody tr:nth-child(even) {
    background-color: #f8f9fa;
}

.md-table td {
    padding: 5px 8px;
    color: #374151;
    font-size: 11px;
}

/* Highlight numeric values in tables */
.md-table td:has(strong) {
    font-weight: 600;
}

/* Lists */
.md-list {
    margin: 12px 0;
    padding-left: 24px;
}

.md-list li {
    margin: 6px 0;
    line-height: 1.6;
}

/* Dividers */
.md-divider {
    border: none;
    border-top: 2px solid #e5e7eb;
    margin: 20px 0;
}

/* Headings */
.md-h1, .md-h2, .md-h3, .md-h4, .md-h5, .md-h6 {
    margin-top: 20px;
    margin-bottom: 12px;
    font-weight: 600;
    color: #111827;
}

.md-h1 { font-size: 24px; }
.md-h2 { font-size: 20px; }
.md-h3 { font-size: 18px; }
.md-h4 { font-size: 16px; }
.md-h5 { font-size: 14px; }
.md-h6 { font-size: 13px; }

/* Code blocks */
.md-code {
    background: #1f2937;
    color: #e5e7eb;
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    overflow-y: auto;
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.5;
    margin: 12px 0;
}

.md-inline {
    background: #f3f4f6;
    color: #ef4444;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
}

/* Message text content */
.message-text p {
    margin: 8px 0;
    line-height: 1.6;
}

.message-text p:first-child {
    margin-top: 0;
}

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

/* Ensure tables are responsive */
@media (max-width: 768px) {
    .md-table {
        font-size: 12px;
    }
    
    .md-table th,
    .md-table td {
        padding: 8px 12px;
    }
}

/* === CHANGE PROPOSAL BUTTONS === */

.approval-btn {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%) !important;
    color: white !important;
    border: none !important;
    padding: 6px 12px !important;
    font-weight: 600 !important;
    font-size: 12px !important;
    border-radius: 6px !important;
}

.approval-btn:hover {
    background: linear-gradient(135deg, #059669 0%, #047857 100%) !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.reject-btn {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%) !important;
    color: white !important;
    border: none !important;
    padding: 6px 12px !important;
    font-weight: 600 !important;
    font-size: 12px !important;
    border-radius: 6px !important;
}

.reject-btn:hover {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%) !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.approval-btn svg,
.reject-btn svg {
    stroke-width: 2px;
}

/* === TABLE CONTAINER & ACTIONS === */

.md-table-container {
    max-height: 300px;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: auto;
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    margin: 8px 0;
}

.table-actions {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
    margin-bottom: 16px;
    align-items: center;
    justify-content: center;
    width: 100%;
}

/* === ADD TO SHEET BUTTON === */

.add-to-sheet-btn {
    background: #7F65EB !important;
    color: white !important;
    border: none !important;
    padding: 8px 16px !important;
    font-weight: 600 !important;
    font-size: 12px !important;
    border-radius: 6px !important;
    cursor: pointer !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    transition: all 0.2s ease !important;
    line-height: 1 !important;
    height: auto !important;
    min-height: unset !important;
    white-space: nowrap !important;
    width: auto !important;
    max-width: fit-content !important;
    flex-shrink: 0 !important;
    box-shadow: 0 2px 8px rgba(112, 85, 226, 0.25) !important;
}

.add-to-sheet-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #461FC5 0%, #6b46c1 100%) !important;
    transform: translateY(-2px) scale(1.02) !important;
    box-shadow: 0 6px 20px rgba(112, 85, 226, 0.4) !important;
}

.add-to-sheet-btn:active:not(:disabled) {
    transform: translateY(0) scale(0.98) !important;
    box-shadow: 0 2px 8px rgba(112, 85, 226, 0.3) !important;
}

.add-to-sheet-btn:disabled {
    background: linear-gradient(135deg, #4CAF50, #45a049) !important;
    cursor: not-allowed !important;
    opacity: 1 !important;
}

.add-to-sheet-btn svg {
    width: 16px !important;
    height: 16px !important;
    flex-shrink: 0 !important;
    display: inline-block !important;
}

.add-to-sheet-btn span {
    display: inline-block !important;
    line-height: 1 !important;
}

/* === REMOVE FROM SHEET BUTTON === */

.remove-from-sheet-btn {
    background: #f44336 !important;
    color: white !important;
    border: none !important;
    padding: 6px 12px !important;
    font-weight: 600 !important;
    font-size: 11px !important;
    border-radius: 5px !important;
    cursor: pointer !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
    transition: all 0.2s ease !important;
    line-height: 1 !important;
    height: auto !important;
    min-height: unset !important;
    white-space: nowrap !important;
    max-width: fit-content !important;
}

.remove-from-sheet-btn:hover {
    background: #d32f2f !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(244, 67, 54, 0.3);
}

.remove-from-sheet-btn svg {
    width: 14px !important;
    height: 14px !important;
    flex-shrink: 0 !important;
    display: inline-block !important;
}

.remove-from-sheet-btn span {
    display: inline-block !important;
    line-height: 1 !important;
}

/* === FORMULA PROPOSAL UI === */

.formula-display {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 12px;
    margin: 12px 0;
    font-family: 'Courier New', Consolas, Monaco, monospace;
    overflow-x: auto;
    overflow-y: auto;
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.formula-display code {
    color: #d73a49;
    font-size: 13px;
    font-weight: 600;
}

.formula-details {
    margin: 12px 0;
    padding: 12px;
    background: #f8f9fa;
    border-left: 3px solid #7055E2;
    border-radius: 4px;
}

.formula-details p {
    margin: 6px 0;
    font-size: 12px;
    line-height: 1.5;
}

.formula-details strong {
    color: #374151;
    font-weight: 600;
}

.formula-details code {
    background: #e9ecef;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    color: #7055E2;
}

.formula-explanation {
    margin: 12px 0;
    padding: 10px;
    background: #eef2ff;
    border-radius: 6px;
    font-size: 12px;
    color: #4b5563;
    line-height: 1.6;
}

.confidence-high {
    color: #059669 !important;
}

.confidence-medium {
    color: #f59e0b !important;
}

.confidence-low {
    color: #ef4444 !important;
}

/* ===================================== */
/* MODEL BUILDER CONFIRMATION MODAL */
/* ===================================== */

.model-confirmation-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0.2s ease;
}

.confirmation-content {
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    width: 90%;
    padding: 0;
    animation: slideUp 0.3s ease;
}

.confirmation-header {
    background: #7F65EB;
    color: white;
    padding: 20px 24px;
    border-radius: 12px 12px 0 0;
}

.confirmation-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.confirmation-body {
    padding: 24px;
    color: #374151;
    line-height: 1.6;
    white-space: pre-wrap;
}

.confirmation-actions {
    padding: 16px 24px 24px;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.btn-primary,
.btn-secondary {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary {
    background: #7F65EB;
    color: white;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(112, 85, 226, 0.4);
}

.btn-secondary {
    background: #e5e7eb;
    color: #374151;
}

.btn-secondary:hover {
    background: #d1d5db;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

/* ---------- Auth overlay ---------- */
.auth-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 16px;
}

.auth-card {
    width: 100%;
    max-width: 460px;
    max-height: 90vh;
    overflow-y: auto;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    padding: 32px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    color: #0f172a;
}

/* Minimalistic scrollbar for auth card */
.auth-card::-webkit-scrollbar {
    width: 4px;
}

.auth-card::-webkit-scrollbar-track {
    background: transparent;
}

.auth-card::-webkit-scrollbar-thumb {
    background: rgba(112, 85, 226, 0.3);
    border-radius: 2px;
}

.auth-card::-webkit-scrollbar-thumb:hover {
    background: rgba(112, 85, 226, 0.5);
}

.auth-logo {
    text-align: center;
    margin-bottom: 16px;
}

.auth-logo-text {
    font-size: 32px;
    font-weight: 700;
    background: #7F65EB;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 0;
    letter-spacing: -0.02em;
}

.auth-info-text {
    text-align: center;
    color: #6b7280;
    font-size: 14px;
    margin: 0 0 24px;
    line-height: 1.5;
}

.auth-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 18px;
}

.auth-eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 12px;
    color: #6b7280;
    margin: 0 0 4px;
}

.auth-subtext {
    margin: 4px 0 0;
    color: #6b7280;
    font-size: 14px;
}

.auth-toggle {
    display: flex;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 4px;
    gap: 4px;
    margin: 0 0 24px;
    width: 100%;
}

.auth-toggle-btn {
    border: none;
    background: transparent;
    color: #374151;
    padding: 8px 14px;
    white-space: nowrap;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s ease, color 0.2s ease;
    flex: 1;
    text-align: center;
}

.auth-toggle-btn.active {
    background: #7F65EB;
    color: #ffffff;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 12px;
}

.auth-label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: #111827;
    font-size: 14px;
}

.auth-input {
    background: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    padding: 12px;
    color: #111827;
    font-size: 14px;
}

.auth-input:focus {
    outline: 2px solid #7055E2;
    border-color: #7055E2;
}

.auth-submit {
    margin-top: 8px;
    padding: 12px;
    background: #7F65EB;
    color: #ffffff;
    white-space: nowrap;
    text-align: center;
    border: none;
    border-radius: 10px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.auth-submit:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 30px rgba(112, 85, 226, 0.25);
}

.auth-privacy-text {
    text-align: center;
    font-size: 12px;
    color: #6b7280;
    margin: 12px 0 0;
    line-height: 1.5;
}

.auth-privacy-link {
    color: #7055E2;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

.auth-privacy-link:hover {
    color: #703DC1;
    text-decoration: underline;
}

.auth-checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 13px;
    color: #374151;
    line-height: 1.5;
    cursor: pointer;
    margin: 4px 0;
}

.auth-checkbox {
    margin-top: 2px;
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: #7055E2;
    flex-shrink: 0;
}

.auth-checkbox-label span {
    flex: 1;
}

.auth-label-text {
    display: inline;
    font-size: 14px;
    font-weight: 500;
    color: #374151;
}

.auth-required {
    color: #ef4444;
    font-weight: 600;
    margin-left: 2px;
}

/* Auth Input Wrapper for password toggle */
.auth-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.auth-input-wrapper .auth-input {
    padding-right: 44px;
}

.auth-input-icon {
    position: absolute;
    right: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    cursor: pointer;
    transition: color 0.2s ease;
    user-select: none;
}

.auth-input-icon svg {
    width: 18px;
    height: 18px;
}

.auth-input-icon:hover {
    color: #7055E2;
}

/* Password Strength Indicator */
.password-strength-container {
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.password-strength-bar {
    flex: 1;
    height: 4px;
    background: #e5e7eb;
    border-radius: 2px;
    overflow: hidden;
}

.password-strength-fill {
    height: 100%;
    width: 0%;
    border-radius: 2px;
    transition: width 0.3s ease, background-color 0.3s ease;
}

.password-strength-fill.weak {
    width: 25%;
    background: #ef4444;
}

.password-strength-fill.fair {
    width: 50%;
    background: #f59e0b;
}

.password-strength-fill.good {
    width: 75%;
    background: #10b981;
}

.password-strength-fill.strong {
    width: 100%;
    background: #059669;
}

.password-strength-text {
    font-size: 11px;
    color: #6b7280;
    white-space: nowrap;
    min-width: 80px;
}

.password-strength-text.weak {
    color: #ef4444;
}

.password-strength-text.fair {
    color: #f59e0b;
}

.password-strength-text.good {
    color: #10b981;
}

.password-strength-text.strong {
    color: #059669;
}

.auth-message {
    min-height: 18px;
    color: #16a34a;
    font-size: 14px;
    margin-top: 4px;
}

.auth-message.error {
    color: #ef4444;
}

.auth-setting-actions {
    display: flex;
    justify-content: flex-start;
    align-items: center;
}

.hidden {
    display: none !important;
}

.auth-locked .content-new {
    filter: blur(2px);
    pointer-events: none;
    user-select: none;
}

/* ===========================================
   PHASE 7: Chat History Sidebar
   Like ChatGPT/Claude conversation sidebar
   =========================================== */

.chat-history-toggle {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 32px;
    height: 32px;
    border: none;
    background: var(--color-bg-secondary);
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-secondary);
    transition: all 0.2s;
    z-index: 10;
}

.chat-history-toggle:hover {
    background: var(--color-primary-light);
    color: var(--color-primary);
}

.chat-history-sidebar {
    position: fixed;
    top: 76px; /* Below header (40px) + tabs (36px) */
    left: 0;
    width: 280px;
    height: calc(100vh - 76px);
    background: var(--color-bg-primary);
    border-right: 1px solid var(--color-border);
    z-index: 100;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    transform: translateX(0);
    transition: transform 0.3s ease;
}

.chat-history-sidebar.hidden {
    transform: translateX(-100%);
    display: flex !important;
    pointer-events: none;
}

.chat-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-secondary);
}

.chat-history-header h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-primary);
}

.close-sidebar-btn {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
}

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

.chat-history-search {
    padding: 12px;
    border-bottom: 1px solid var(--color-border);
}

.chat-history-search input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
}

.chat-history-search input:focus {
    border-color: var(--color-primary);
}

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

.conversation-item {
    padding: 12px;
    margin-bottom: 4px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.2s;
}

.conversation-item:hover {
    background: var(--color-bg-secondary);
}

.conversation-item.active {
    background: var(--color-primary-light);
    border-left: 3px solid var(--color-primary);
}

.conv-workbook {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-primary);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.conv-workbook::before {
    content: '';
    width: 8px;
    height: 8px;
    background: var(--color-success);
    border-radius: 50%;
}

.conv-preview {
    font-size: 12px;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.conv-date {
    font-size: 11px;
    color: var(--color-text-muted);
}

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

.new-conversation-btn {
    margin: 8px;
    padding: 10px;
    background: linear-gradient(135deg, var(--color-gradient-start), var(--color-gradient-end));
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.new-conversation-btn:hover {
    opacity: 0.9;
}

/* ===========================================
   Phase 10.16: Graceful Failure Handling UI
   Enhanced to match chat message styling
   =========================================== */

/* Clarification Prompt Styles - Matches chat bubble design */
.clarification-prompt {
    background: transparent;
    border: none;
    padding: 0;
    margin: 4px 0;
    line-height: 1.6;
}

.clarification-message {
    font-size: 14px;
    color: var(--color-text-primary);
    margin: 0 0 16px 0;
    font-weight: 400;
    line-height: 1.6;
}

.clarification-options {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 12px;
}

.clarification-btn {
    padding: 10px 18px;
    background: linear-gradient(135deg, var(--color-bg-primary), var(--color-bg-secondary));
    border: 1px solid var(--color-border);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-primary);
    cursor: pointer;
    text-align: center;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    white-space: nowrap;
}

.clarification-btn:hover {
    background: linear-gradient(135deg, var(--color-primary-light), var(--color-primary));
    border-color: var(--color-primary);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(var(--color-primary-rgb), 0.25);
}

.clarification-btn:active {
    transform: translateY(0) scale(0.98);
}

/* Rate Limit Message Styles - Inline with chat */
.rate-limit-message {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: linear-gradient(135deg, #fff8e1, #ffecb3);
    border: 1px solid #ffc107;
    border-radius: 12px;
    padding: 12px 16px;
    color: #856404;
    font-size: 14px;
    line-height: 1.5;
    box-shadow: 0 2px 4px rgba(255, 193, 7, 0.15);
}

.rate-limit-icon {
    font-size: 18px;
    flex-shrink: 0;
}

/* Fallback Message Styles - Inline with chat */
.fallback-message {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: linear-gradient(135deg, #f5f5f5, #eeeeee);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 12px 16px;
    color: var(--color-text-secondary);
    font-size: 14px;
    line-height: 1.5;
}

.fallback-icon {
    font-size: 18px;
    flex-shrink: 0;
}

/* Retry button in error states */
.error-retry-btn {
    margin-left: 12px;
    padding: 6px 14px;
    background: var(--color-primary);
    border: none;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
    color: white;
    cursor: pointer;
    transition: all 0.15s ease;
}

.error-retry-btn:hover {
    background: var(--color-primary-dark);
    transform: scale(1.02);
}

/* ===========================================
   AI Genius Progress Bar
   Phase 12: Progress indicator for chunked operations
   =========================================== */

.genius-progress-container {
    background: var(--color-bg-secondary, #f9fafb);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: var(--radius-lg, 12px);
    padding: 12px 16px;
    margin: 8px 0;
    animation: fadeIn 0.2s ease;
}

.genius-progress-container .progress-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 13px;
}

.genius-progress-container .progress-message {
    color: var(--color-text-primary, #1f2937);
    font-weight: 500;
}

.genius-progress-container .progress-details {
    color: var(--color-text-secondary, #6b7280);
    font-size: 12px;
}

.genius-progress-container .progress-bar-track {
    background: var(--color-border, #e5e7eb);
    border-radius: var(--radius-sm, 6px);
    height: 8px;
    overflow: hidden;
}

.genius-progress-container .progress-bar-fill {
    background: linear-gradient(90deg, var(--color-gradient-start, #7055E2), var(--color-gradient-end, #703DC1));
    height: 100%;
    width: 0%;
    transition: width 0.3s ease;
    border-radius: var(--radius-sm, 6px);
}

/* ===========================================
   PHASE 13.0.1: PERSISTENT ERROR MESSAGES
   Error messages displayed in chat (not toasts)
   =========================================== */

.message.error-message {
    max-width: 85%;
}

.error-bubble {
    background: linear-gradient(135deg, #fff5f5 0%, #fee2e2 100%);
    border: 1px solid #fecaca;
    border-left: 4px solid #ef4444;
    border-radius: 12px;
    padding: 12px 16px;
}

.error-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.error-icon {
    font-size: 16px;
}

.error-title {
    font-weight: 600;
    color: #b91c1c;
    font-size: 14px;
}

.error-content {
    margin-bottom: 12px;
}

.error-text {
    color: #7f1d1d;
    font-size: 13px;
    margin: 0 0 8px 0;
    line-height: 1.5;
    word-break: break-word;
}

.error-suggestion {
    color: #92400e;
    font-size: 12px;
    margin: 8px 0 0 0;
    padding: 8px 10px;
    background: rgba(251, 191, 36, 0.15);
    border-radius: 6px;
    border-left: 3px solid #f59e0b;
}

.error-actions {
    display: flex;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid #fecaca;
}

.copy-error-btn {
    padding: 6px 12px;
    background: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    cursor: pointer;
    color: #374151;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s;
}

.copy-error-btn:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}