/*
        Design System Variables - Why These Values Enable Aurora's Premium Chat Experience:

        Gradient Theme: Purple-to-blue gradient creates AI-native sophistication while maintaining
        accessibility and visual appeal (crisp contrast ratios, avoid harsh colors)

        Shadow System: Layered shadows create depth and containment without being overwhelming,
        establishing clear content boundaries in a mostly-flat interface

        Color Palette: Carefully chosen grays ensure readability while maintaining modern aesthetic
        - Text hierarchy uses progressive darkening for easy scanning
        - Input backgrounds are consciously lighter to maintain focus states
        */
        :root {
            --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            --user-message-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            --ai-message-bg: #ffffff;
            --input-bg: #f8fafc;
            --border-color: #e2e8f0;
            --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
            --text-primary: #1a202c;
            --text-secondary: #4a5568;
        }

        /*
        Global Reset - Why Strip Default Styling:
        Ensure consistent rendering across browsers by eliminating unpredictable default margins,
        padding, and box-sizing behaviors that could break layout or cause responsive issues
        */
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        /*
        Page Layout Foundation - Why This Structure:
        Full-viewport gradient background creates immersive AI experience without being distracting.
        Inter font stack prioritizes technical content readability (crisp, clean, terminal-like).
        Fallbacks ensure graceful degradation while maintaining usability.
        */
        body {
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            margin: 0;
            padding: 0;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
            line-height: 1.6;
        }

        .container {
            max-width: 1100px;
            margin: 0 auto;
            padding: 20px;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            transition: all 0.6s ease-out;
        }

        .container.initial-state {
            justify-content: center;
            align-items: center;
            padding: 40px;
            text-align: center;
        }

        .container.initial-state .header {
            margin-bottom: 40px;
        }

        .container.initial-state .chat-container {
            display: none;
        }

        .container.initial-state .header {
            position: relative;
            top: 0;
        }

        .container.chat-started .header {
            margin-bottom: 30px;
            padding: 20px 0;
        }

        .container.chat-started .initial-prompt {
            display: none;
        }

        .initial-prompt {
            width: 100%;
            background: rgba(255, 255, 255, 0.95);
            border-radius: 20px;
            box-shadow: var(--shadow);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.2);
            margin-bottom: 20px;
        }

        .container.initial-state .initial-prompt .controls {
            border-top: none;
            background: transparent;
            backdrop-filter: none;
        }

        .container.initial-state .initial-prompt .mode-toggle {
            margin-bottom: 16px;
        }

        .container.initial-state .input-container {
            max-width: 600px;
            width: 100%;
        }

        .container.initial-state .input-container textarea {
            min-height: 56px;
            max-height: 400px;
        }

        .container.initial-state .chat-container {
            opacity: 0;
        }

        .container.chat-started .chat-container {
            opacity: 1;
            transition: opacity 0.4s ease-out 0.2s;
        }

        .header {
            text-align: center;
            margin-bottom: 30px;
            padding: 20px 0;
            position: relative;
        }

        .logo {
            position: absolute;
            top: 20px;
            left: 10px;
            height: 40px;
            cursor: pointer;
            transition: opacity 0.2s ease;
            opacity: 0.9;
        }

        .logo:hover {
            opacity: 1;
        }

        .header h1 {
            background: var(--primary-gradient);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-size: 3rem;
            font-weight: 700;
            margin-bottom: 10px;
            letter-spacing: -0.025em;
        }

        .header .subtitle {
            color: var(--text-secondary);
            font-size: 1.1rem;
            font-weight: 400;
        }

        .chat-container {
            flex: 1;
            display: flex;
            flex-direction: column;
            background: rgba(255, 255, 255, 0.95);
            border-radius: 20px;
            box-shadow: var(--shadow);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.2);
            overflow: hidden;
            margin-bottom: 20px;
        }

        .chat {
            flex: 1;
            padding: 24px;
            overflow-y: auto;
            scroll-behavior: smooth;
            background: transparent;
        }

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

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

        .chat::-webkit-scrollbar-thumb {
            background: rgba(0, 0, 0, 0.2);
            border-radius: 3px;
        }

        .message {
            margin-bottom: 35px;
            padding-bottom: 28px;
            display: flex;
            align-items: flex-start;
            animation: slideIn 0.3s ease-out;
            position: relative;
        }

        .message.user {
            justify-content: flex-end;
        }

        .message.ai {
            justify-content: flex-start;
        }

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

        .message-bubble {
            max-width: 70%;
            padding: 16px 16px;
            border-radius: 18px;
            font-size: 15px;
            line-height: 1.5;
            word-wrap: break-word;
            position: relative;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }

        .message.user .message-bubble {
            background: var(--user-message-bg);
            color: white;
            border-bottom-right-radius: 4px;
        }

        .message.ai .message-bubble {
            background: var(--ai-message-bg);
            color: var(--text-primary);
            border-bottom-left-radius: 4px;
            border: 1px solid var(--border-color);
        }

        /*
        Markdown Content Formatting - Why These Rules Prevent Overflow:
        
        When marked.parse() converts markdown to HTML, it creates list elements (<ul>, <ol>, <li>)
        with browser-default styling that can cause content to overflow the message bubble.
        
        padding-left on lists: Creates space inside the bubble for bullets/numbers, preventing them
        from appearing outside the bubble's left edge. 24px provides comfortable reading space.
        
        Margin control: Ensures consistent spacing between paragraphs and lists without creating
        excessive whitespace that would break the chat bubble's visual cohesion.
        
        Nested list handling: Reduces indentation for nested lists to prevent them from pushing
        too far right while maintaining visual hierarchy for readability.
        */
        .message-bubble ul,
        .message-bubble ol {
            margin: 8px 0;
            padding-left: 24px;
        }

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

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

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

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

        /* Prevent nested lists from having excessive indentation that pushes content too far right */
        .message-bubble ul ul,
        .message-bubble ol ol,
        .message-bubble ul ol,
        .message-bubble ol ul {
            margin: 4px 0;
            padding-left: 20px;
        }

        .avatar {
            width: 36px;
            height: 36px;
            border-radius: 50%;
            margin: 0 12px;
            flex-shrink: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 16px;
            font-weight: 600;
        }

        .message.user .avatar {
            background: rgba(255, 255, 255, 0.2);
            color: white;
            order: 2;
        }

        .message.ai .avatar {
            background: var(--primary-gradient);
            color: white;
        }

        .message.ai .message-content {
            align-items: flex-start;
        }

        .message-content {
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: flex-end;
        }

        .message-controls {
            display: none;
            position: absolute;
            gap: 8px;
            flex-direction: row;
        }

        .message:hover .message-controls {
            display: flex;
        }
       

        .message.user .message-controls {
            bottom: -5px;
            right: 35px;
        }

        .message.ai .message-controls {
            bottom: -5px;
            left: 35px;
        }

        .control-btn {
            padding: 6px 12px;
            border: none;
            border-radius: 20px;
            font-size: 12px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.2s ease;
            opacity: 0.8;
        }

        .control-btn.copy-btn {
            background: rgba(44, 53, 57, 0.1);
            color: #2C3539;
        }

.control-btn.copy-btn:hover {
    background: rgba(44, 53, 57, 0.2);
}

.control-btn.refresh-btn {
    background: rgba(44, 53, 57, 0.1);
    color: #2C3539;
}

.control-btn.refresh-btn:hover {
    background: rgba(44, 53, 57, 0.2);
}

.control-btn.delete-btn {
            background: rgba(44, 53, 57, 0.1);
            color: #2C3539;
        }

        .control-btn.delete-btn:hover {
            background: rgba(44, 53, 57, 0.2);
        }

        .control-btn.edit-btn {
            background: rgba(44, 53, 57, 0.1);
            color: #2C3539;
        }

        .control-btn.edit-btn:hover {
            background: rgba(44, 53, 57, 0.2);
        }

        .edit-input {
            width: 100%;
            padding: 12px 16px;
            border: 1px solid var(--border-color);
            border-radius: 16px;
            font-size: 14px;
            font-family: inherit;
            outline: none;
            background: var(--input-bg);
        }

        .edit-input:focus {
            border-color: #667eea;
            box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
        }

        .edit-controls {
            display: flex;
            gap: 8px;
            justify-content: flex-end;
            margin-top: 8px;
        }

        .edit-controls button {
            padding: 6px 16px;
            border: none;
            border-radius: 16px;
            font-size: 12px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.2s ease;
        }

        .edit-controls .ok-btn {
            background: var(--primary-gradient);
            color: white;
        }

        .edit-controls .ok-btn:hover {
            transform: translateY(-1px);
            box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
        }

        .edit-controls .cancel-btn {
            background: rgba(107, 114, 128, 0.1);
            color: #6b7280;
        }

        .edit-controls .cancel-btn:hover {
            background: rgba(107, 114, 128, 0.2);
        }

        /* Legacy typing indicator - kept for backward compatibility */
        .typing-indicator {
            display: flex;
            align-items: center;
            padding: 8px 0;
            color: var(--text-secondary);
            font-style: italic;
        }

        .typing-dots {
            display: inline-flex;
            margin-left: 8px;
        }

        .typing-dots span {
            width: 4px;
            height: 4px;
            border-radius: 50%;
            background: var(--text-secondary);
            margin: 0 2px;
            animation: typing 1.4s infinite ease-in-out;
        }

        .typing-dots span:nth-child(1) { animation-delay: -0.32s; }
        .typing-dots span:nth-child(2) { animation-delay: -0.16s; }

        @keyframes typing {
            0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
            40% { transform: scale(1); opacity: 1; }
        }

        /* New advanced thinking display styles */
        .thinking-message {
            opacity: 0.95;
        }

        .thinking-indicator {
            flex: 1;
            padding: 12px 0;
        }

        .thinking-content {
            border: 1px solid var(--border-color);
            border-radius: 12px;
            background: var(--ai-message-bg);
            overflow: hidden;
            transition: all 0.3s ease;
        }

        .thinking-content.collapsed {
            max-height: 50px;
        }

        .thinking-content.expanded {
            max-height: 800px;
        }

        .thinking-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 12px 16px;
            background: rgba(103, 126, 234, 0.1);
            border-bottom: 1px solid var(--border-color);
            cursor: pointer;
        }

        .thinking-header:hover {
            background: rgba(103, 126, 234, 0.15);
        }

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

        .thinking-toggle {
            background: none;
            border: none;
            color: var(--text-secondary);
            font-size: 14px;
            cursor: pointer;
            padding: 4px 8px;
            border-radius: 4px;
            transition: all 0.2s ease;
            width: 24px;
            height: 24px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .thinking-toggle:hover {
            background: rgba(0, 0, 0, 0.1);
            color: var(--text-primary);
        }

        .thinking-details {
            padding: 0;
            max-height: 0;
            overflow: hidden;
            transition: max-height 0.3s ease;
        }

        .thinking-content.expanded .thinking-details {
            max-height: 750px;
            padding: 16px;
        }

        .thinking-section {
            margin-bottom: 16px;
        }

        .thinking-section:last-child {
            margin-bottom: 0;
        }

        .thinking-section h4 {
            margin: 0 0 8px 0;
            color: var(--text-primary);
            font-size: 14px;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .plan-text {
            color: var(--text-primary);
            line-height: 1.4;
        }

        .plan-text p {
            margin: 0 0 8px 0;
        }

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

        .subtasks-list {
            margin: 0;
            padding-left: 20px;
        }

        .subtasks-list li {
            color: var(--text-primary);
            margin-bottom: 4px;
            line-height: 1.4;
        }

        .subtasks-list li:last-child {
            margin-bottom: 0;
        }

        .summaries-container {
            display: flex;
            flex-direction: column;
            gap: 12px;
        }

        .summary-item {
            padding: 12px;
            background: rgba(103, 126, 234, 0.05);
            border-left: 3px solid var(--primary-gradient);
            border-radius: 8px;
            color: var(--text-primary);
            line-height: 1.4;
        }

        .summary-item p {
            margin: 0 0 6px 0;
        }

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

        .controls {
            padding: 20px 24px;
            background: rgba(255, 255, 255, 0.9);
            border-top: 1px solid var(--border-color);
            backdrop-filter: blur(10px);
        }

        .mode-toggle {
            display: flex;
            align-items: center;
            justify-content: center;
            margin-bottom: 16px;
            gap: 12px;
        }

        .mode-toggle label {
            display: flex;
            align-items: center;
            cursor: pointer;
            font-weight: 500;
            color: var(--text-primary);
            transition: color 0.2s ease;
        }

        .mode-toggle input[type="checkbox"] {
            display: none;
        }

        .mode-toggle .toggle-switch {
            position: relative;
            width: 50px;
            height: 24px;
            background: #e2e8f0;
            border-radius: 12px;
            margin-right: 12px;
            transition: background-color 0.3s ease;
        }

        .mode-toggle input:checked + .toggle-switch {
            background: var(--primary-gradient);
        }

        .mode-toggle .toggle-slider {
            position: absolute;
            top: 2px;
            left: 2px;
            width: 20px;
            height: 20px;
            background: white;
            border-radius: 50%;
            transition: transform 0.3s ease;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
        }

        .mode-toggle input:checked + .toggle-switch .toggle-slider {
            transform: translateX(26px);
        }

        .mode-description {
            font-size: 14px;
            color: var(--text-secondary);
            font-weight: 400;
        }

        .input-form {
            display: flex;
            gap: 12px;
            align-items: center;
        }

        .input-container {
            flex: 1;
            position: relative;
        }

        .input-container input {
            width: 100%;
            padding: 16px 20px;
            border: 2px solid var(--border-color);
            border-radius: 16px;
            font-size: 16px;
            font-family: inherit;
            background: var(--input-bg);
            transition: all 0.3s ease;
            outline: none;
        }

.input-container input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.input-container input::placeholder {
    color: var(--text-secondary);
}

.input-container textarea {
    width: 100%;
    padding: 16px 20px;
    border: 2px solid var(--border-color);
    border-radius: 16px;
    font-size: 16px;
    font-family: inherit;
    background: var(--input-bg);
    transition: all 0.3s ease;
    outline: none;
    resize: none;
    min-height: 56px;
    max-height: 400px;
    overflow-y: auto;
}

.input-container textarea:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.input-container textarea::placeholder {
    color: var(--text-secondary);
}

        .send-button {
            padding: 16px 24px;
            background: var(--primary-gradient);
            color: white;
            border: none;
            border-radius: 16px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            gap: 8px;
            min-width: 100px;
            justify-content: center;
        }

        .send-button:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
        }

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

        .send-button:disabled {
            opacity: 0.6;
            cursor: not-allowed;
            transform: none;
        }

        @media (max-width: 768px) {
            .container {
                padding: 10px;
            }

            .header h1 {
                font-size: 2.5rem;
            }

            .logo {
                height: 30px;
                top: 15px;
                left: 5px;
            }

            .message-bubble {
                max-width: 85%;
                padding: 12px 16px;
            }

            .input-form {
                gap: 8px;
            }

            .controls {
                padding: 16px 20px;
            }
        }

        /* Copy button styles */
        pre {
            position: relative;
        }

        pre .copy-btn {
            position: absolute;
            top: 8px;
            right: 8px;
            background: rgba(255, 255, 255, 0.9);
            border: 1px solid rgba(0, 0, 0, 0.1);
            border-radius: 4px;
            padding: 4px 8px;
            font-size: 12px;
            cursor: pointer;
            opacity: 0;
            transition: all 0.2s ease;
            font-family: inherit;
        }

        pre:hover .copy-btn {
            opacity: 1;
        }

        pre .copy-btn:hover {
            background: rgba(255, 255, 255, 1);
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }

        pre .copy-btn:active {
            transform: scale(0.95);
        }

        .message.error .message-bubble {
            background: #dc2626;
            color: white;
            border: 1px solid #dc2626;
        }

        .control-btn.retry-btn {
            background: rgba(34, 197, 94, 0.1);
            color: #16a34a;
        }

        .control-btn.retry-btn:hover {
            background: rgba(34, 197, 94, 0.2);
        }
