/* Modern CSS Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    color: #1a202c;
    background: linear-gradient(135deg, #f7fafc 0%, #edf2f7 100%);
    min-height: 100vh;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header Styles */
.header {
    text-align: center;
    padding: 40px 0 30px;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

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

.logo svg {
    color: #4299e1;
}

.logo h1 {
    font-size: 2rem;
    font-weight: 700;
    color: #2d3748;
    margin: 0;
}

.language-selector {
    display: flex;
    align-items: center;
}

.language-dropdown {
    padding: 8px 12px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    background: white;
    font-size: 14px;
    color: #4a5568;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 140px;
}

.language-dropdown:focus {
    outline: none;
    border-color: #4299e1;
    box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.1);
}

.subtitle {
    color: #718096;
    font-size: 1.1rem;
    max-width: 600px;
    margin: 0 auto;
}

/* Main Content */
.main-content {
    display: grid;
    gap: 32px;
}

/* Input Section */
.input-section {
    background: white;
    border-radius: 16px;
    padding: 32px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    border: 1px solid #e2e8f0;
}

.input-group label {
    display: block;
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 12px;
    font-size: 1.1rem;
}

.input-wrapper {
    display: flex;
    gap: 12px;
    align-items: stretch;
}

.input-wrapper input {
    flex: 1;
    padding: 16px 20px;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    font-size: 16px;
    transition: all 0.2s ease;
    background: white;
}

.input-wrapper input:focus {
    outline: none;
    border-color: #4299e1;
    box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.1);
}

.input-wrapper input::placeholder {
    color: #a0aec0;
}

/* Button Styles */
.btn {
    padding: 16px 24px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

.btn-primary {
    background: linear-gradient(135deg, #4299e1 0%, #3182ce 100%);
    color: white;
    box-shadow: 0 4px 14px rgba(66, 153, 225, 0.3);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(66, 153, 225, 0.4);
}

.btn-success {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    color: white;
    box-shadow: 0 4px 14px rgba(72, 187, 120, 0.3);
}

.btn-success:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(72, 187, 120, 0.4);
}

.btn-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Preview Section */
.preview-section {
    background: white;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    border: 1px solid #e2e8f0;
    overflow: hidden;
}

.preview-header {
    padding: 24px 32px;
    border-bottom: 1px solid #e2e8f0;
    background: #f7fafc;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.preview-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.preview-header h3 {
    margin: 0;
    color: #2d3748;
    font-size: 1.25rem;
    font-weight: 600;
}

.preview-frame {
    height: 600px;
    overflow-y: auto;
    background: white;
}

/* Placeholder */
.placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 48px;
}

.placeholder-icon {
    color: #a0aec0;
    margin-bottom: 24px;
}

.placeholder h4 {
    color: #2d3748;
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.placeholder p {
    color: #718096;
    font-size: 1rem;
    max-width: 400px;
    line-height: 1.6;
}

/* Loading State */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 48px;
}

.loading .spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #e2e8f0;
    border-top: 4px solid #4299e1;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 24px;
}

.loading p {
    color: #718096;
    font-size: 1.1rem;
    margin: 0 0 20px 0;
}

.loading-steps {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 20px;
}

.loading-steps .step {
    font-size: 0.9rem;
    color: #a0aec0;
    opacity: 0.7;
    animation: pulse 2s ease-in-out infinite;
}

.loading-steps .step:nth-child(1) {
    animation-delay: 0s;
}

.loading-steps .step:nth-child(2) {
    animation-delay: 0.5s;
}

.loading-steps .step:nth-child(3) {
    animation-delay: 1s;
}

/* Chat Message Styles */
.extracted-root {
    padding: 32px;
    max-width: 800px;
    margin: 0 auto;
}

.extracted-root h2 {
    text-align: center;
    margin-bottom: 32px;
    color: #2d3748;
    font-size: 1.5rem;
    font-weight: 600;
}

.message-container {
    display: flex;
    margin-bottom: 24px;
    width: 100%;
}

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

.message-container.assistant {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 75%;
    padding: 16px 20px;
    border-radius: 20px;
    position: relative;
    word-wrap: break-word;
    overflow-wrap: break-word;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.message-container.user .message-bubble {
    background: linear-gradient(135deg, #ebf4ff 0%, #c3dafe 100%);
    color: #1e40af;
    border-bottom-left-radius: 6px;
}

.message-container.assistant .message-bubble {
    background: linear-gradient(135deg, #f7fafc 0%, #edf2f7 100%);
    color: #2d3748;
    border-bottom-right-radius: 6px;
}

.message-role {
    font-weight: 700;
    font-size: 12px;
    margin-bottom: 8px;
    opacity: 0.8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.message-text {
    line-height: 1.6;
    font-size: 15px;
}

/* Enhanced formatting for ChatGPT content */
.message-text p {
    margin-bottom: 12px;
}

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

.message-text pre {
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 16px;
    margin: 12px 0;
    overflow-x: auto;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 14px;
    line-height: 1.4;
}

.message-text code {
    background: #f1f5f9;
    color: #e53e3e;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 13px;
}

.message-text pre code {
    background: transparent;
    color: inherit;
    padding: 0;
}

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

.message-text li {
    margin-bottom: 6px;
}

.message-text blockquote {
    border-left: 4px solid #4299e1;
    padding-left: 16px;
    margin: 16px 0;
    color: #4a5568;
    font-style: italic;
}

.message-text strong {
    font-weight: 700;
    color: #2d3748;
}

.message-text em {
    font-style: italic;
    color: #4a5568;
}

.message-text h1,
.message-text h2,
.message-text h3,
.message-text h4,
.message-text h5,
.message-text h6 {
    margin: 16px 0 8px 0;
    color: #2d3748;
    font-weight: 600;
}

.message-text h1 { font-size: 1.5em; }
.message-text h2 { font-size: 1.4em; }
.message-text h3 { font-size: 1.3em; }
.message-text h4 { font-size: 1.2em; }
.message-text h5 { font-size: 1.1em; }

/* Animations */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 0 16px;
    }

    .header-content {
        flex-direction: column;
        gap: 20px;
    }

    .logo h1 {
        font-size: 1.75rem;
    }

    .subtitle {
        font-size: 1rem;
    }

    .input-section {
        padding: 24px;
    }

    .input-wrapper {
        flex-direction: column;
    }

    .input-wrapper input {
        margin-bottom: 12px;
    }

    .btn {
        justify-content: center;
    }

    .preview-header {
        flex-direction: column;
        gap: 16px;
        align-items: stretch;
        padding: 20px 24px;
    }

    .preview-frame {
        height: 500px;
    }

    .extracted-root {
        padding: 20px;
    }

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

    .message-text {
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .logo h1 {
        font-size: 1.5rem;
    }

    .input-section {
        padding: 20px;
    }

    .preview-header {
        padding: 16px 20px;
    }

    .extracted-root {
        padding: 16px;
    }

    .message-bubble {
        max-width: 95%;
    }
}

/* Print styles for PDF generation */
@media print {
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }

    body {
        background: white !important;
        margin: 0 !important;
        padding: 0 !important;
        font-size: 12pt !important;
        line-height: 1.4 !important;
    }


    /* SIMPLIFIED APPROACH: Show everything first, then hide specific elements */
    
    /* Hide only the UI elements we don't want */
    .header,
    .input-section,
    .preview-header,
    .placeholder,
    .loading,
    .btn,
    .feedback-section,
    .dev-footer {
        display: none !important;
    }

    /* Make sure the main content area is visible */
    .container {
        display: block !important;
        max-width: none !important;
        margin: 0 !important;
        padding: 20px !important;
        width: 100% !important;
    }

    .main-content {
        display: block !important;
        width: 100% !important;
    }

    .preview-section {
        display: block !important;
        background: white !important;
        border: none !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        height: auto !important;
    }

    .preview-frame {
        display: block !important;
        position: static !important;
        height: auto !important;
        overflow: visible !important;
        background: white !important;
        margin: 0 !important;
        padding: 20px !important;
        border: none !important;
        box-shadow: none !important;
        visibility: visible !important;
        opacity: 1 !important;
        width: 100% !important;
    }

    .extracted-root {
        display: block !important;
        padding: 0 !important;
        margin: 0 !important;
        max-width: none !important;
        background: white !important;
        width: 100% !important;
    }

    /* Ensure message bubbles are visible and styled */
    .message-container {
        display: flex !important;
        margin-bottom: 24px !important;
        width: 100% !important;
        page-break-inside: avoid !important;
    }

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

    .message-container.assistant {
        justify-content: flex-start !important;
    }

    .message-bubble {
        max-width: 75% !important;
        padding: 16px 20px !important;
        border-radius: 20px !important;
        position: relative !important;
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
        border: 1px solid #e2e8f0 !important;
    }

    .message-container.user .message-bubble {
        background-color: #ebf4ff !important;
        color: #1e40af !important;
        border-bottom-left-radius: 6px !important;
    }

    .message-container.assistant .message-bubble {
        background-color: #f7fafc !important;
        color: #2d3748 !important;
        border-bottom-right-radius: 6px !important;
    }

    .message-role {
        font-weight: 700 !important;
        font-size: 12px !important;
        margin-bottom: 8px !important;
        opacity: 0.8 !important;
        text-transform: uppercase !important;
        letter-spacing: 0.5px !important;
    }

    .message-text {
        line-height: 1.6 !important;
        font-size: 15px !important;
        font-family: Arial, 'Microsoft YaHei', 'SimSun', 'Hiragino Sans GB', sans-serif !important;
        -webkit-font-smoothing: antialiased !important;
        -moz-osx-font-smoothing: grayscale !important;
    }

    /* Ensure formatted content is visible */
    .message-text p {
        margin-bottom: 12px !important;
    }

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

    .message-text pre {
        background: #f7fafc !important;
        border: 1px solid #e2e8f0 !important;
        border-radius: 8px !important;
        padding: 16px !important;
        margin: 12px 0 !important;
        overflow-x: auto !important;
        font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace !important;
        font-size: 14px !important;
        line-height: 1.4 !important;
        white-space: pre-wrap !important;
        word-wrap: break-word !important;
    }

    .message-text code {
        background: #f1f5f9 !important;
        color: #e53e3e !important;
        padding: 2px 6px !important;
        border-radius: 4px !important;
        font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace !important;
        font-size: 13px !important;
    }

    .message-text pre code {
        background: transparent !important;
        color: inherit !important;
        padding: 0 !important;
    }

    .message-text ul,
    .message-text ol {
        margin: 12px 0 !important;
        padding-left: 24px !important;
    }

    .message-text li {
        margin-bottom: 6px !important;
    }

    .message-text blockquote {
        border-left: 4px solid #4299e1 !important;
        padding-left: 16px !important;
        margin: 16px 0 !important;
        color: #4a5568 !important;
        font-style: italic !important;
    }

    .message-text strong {
        font-weight: 700 !important;
        color: #2d3748 !important;
    }

    .message-text em {
        font-style: italic !important;
        color: #4a5568 !important;
    }

    .message-text h1,
    .message-text h2,
    .message-text h3,
    .message-text h4,
    .message-text h5,
    .message-text h6 {
        margin: 16px 0 8px 0 !important;
        color: #2d3748 !important;
        font-weight: 600 !important;
    }

    .message-text h1 { font-size: 1.5em !important; }
    .message-text h2 { font-size: 1.4em !important; }
    .message-text h3 { font-size: 1.3em !important; }
    .message-text h4 { font-size: 1.2em !important; }
    .message-text h5 { font-size: 1.1em !important; }

    /* Page break controls */
    .message-container {
        page-break-inside: avoid !important;
    }

    .extracted-root h2 {
        page-break-after: avoid !important;
    }

    /* Table styles for print */
    .message-text table {
        border-collapse: collapse !important;
        width: 100% !important;
        margin: 16px 0 !important;
        font-size: 14px !important;
        background: white !important;
    }

    .message-text th, 
    .message-text td {
        border: 1px solid #e2e8f0 !important;
        padding: 12px !important;
        text-align: left !important;
        vertical-align: top !important;
        background: white !important;
    }

    .message-text th {
        background-color: #f7fafc !important;
        font-weight: 600 !important;
        color: #2d3748 !important;
    }

    .message-text tr:nth-child(even) {
        background-color: #f8f9fa !important;
    }
}

/* Print ready class for better PDF generation */
.print-ready .extracted-root {
    display: block !important;
    position: static !important;
    background: white !important;
    margin: 0 !important;
    padding: 20px !important;
    width: 100% !important;
    max-width: none !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.print-ready .message-container {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.print-ready .message-bubble {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.print-ready .message-text {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* Table Styles */
table {
    border-collapse: collapse;
    width: 100%;
    margin: 16px 0;
    font-size: 14px;
}

th, td {
    border: 1px solid #e2e8f0;
    padding: 12px;
    text-align: left;
    vertical-align: top;
}

th {
    background-color: #f7fafc;
    font-weight: 600;
    color: #2d3748;
}

tr:nth-child(even) {
    background-color: #f8f9fa;
}

tr:hover {
    background-color: #edf2f7;
}

/* Feedback Section */
.feedback-section {
    margin-top: 40px;
    padding: 20px;
    background: transparent;
}

.feedback-container {
    max-width: 600px;
    margin: 0 auto;
    text-align: center;
}

.feedback-container h4 {
    color: #2d3748;
    margin-bottom: 20px;
    font-size: 1.1rem;
    font-weight: 600;
}

.feedback-buttons {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-bottom: 20px;
}

.feedback-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 24px;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    background: white;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    color: #4a5568;
    min-width: 120px;
    flex: 1;
}

.feedback-btn:hover {
    border-color: #cbd5e0;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.feedback-btn span:first-child {
    font-size: 1.5rem;
}

.like-btn.selected {
    border-color: #48bb78;
    background: #f0fff4;
    color: #2f855a;
}

.dislike-btn.selected {
    border-color: #f56565;
    background: #fff5f5;
    color: #c53030;
}

.feedback-form {
    background: white;
    padding: 24px;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    margin-top: 20px;
    text-align: left;
}

.feedback-form h5 {
    color: #2d3748;
    margin-bottom: 16px;
    font-size: 1rem;
    font-weight: 600;
}

.feedback-form textarea {
    width: 100%;
    min-height: 100px;
    padding: 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    resize: vertical;
    margin-bottom: 16px;
}

.feedback-form textarea:focus {
    outline: none;
    border-color: #4299e1;
    box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.1);
}

.feedback-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.feedback-thanks {
    background: #f0fff4;
    border: 1px solid #9ae6b4;
    border-radius: 8px;
    padding: 16px;
    margin-top: 20px;
}

.feedback-thanks p {
    color: #2f855a;
    margin: 0;
    font-weight: 500;
}

/* Development Footer */
.dev-footer {
    text-align: center;
    padding: 20px;
    margin-top: 0;
    background: rgba(255, 193, 7, 0.1);
    border-top: 1px solid rgba(255, 193, 7, 0.3);
    color: #856404;
    font-size: 14px;
    font-weight: 500;
}

.dev-footer p {
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}