/* ===================================
   CSS Variables & Theme
   =================================== */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --success-color: #22c55e;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --pdf-color: #dc2626;
    --word-color: #2563eb;
    --background: #f8fafc;
    --surface: #ffffff;
    --surface-hover: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --transition: all 0.2s ease;
}

/* ===================================
   Reset & Base Styles
   =================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* ===================================
   Layout
   =================================== */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.header-content h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.settings-btn {
    background: var(--surface-hover);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.5rem 1rem;
    font-size: 1.25rem;
    cursor: pointer;
    transition: var(--transition);
}

.settings-btn:hover {
    background: var(--border-color);
}

.main-content {
    flex: 1;
    padding: 2rem;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

.footer {
    background: var(--surface);
    border-top: 1px solid var(--border-color);
    padding: 1rem 2rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* ===================================
   Cards
   =================================== */
.card {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.card h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    color: var(--text-primary);
}

/* ===================================
   Form Elements
   =================================== */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

input[type="text"],
input[type="password"],
textarea,
select {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text-primary);
    transition: var(--transition);
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

textarea {
    resize: vertical;
    min-height: 80px;
}

select {
    cursor: pointer;
}

.help-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

.help-text a {
    color: var(--primary-color);
    text-decoration: none;
}

.help-text a:hover {
    text-decoration: underline;
}

.api-key-input-wrapper {
    display: flex;
    gap: 0.5rem;
}

.api-key-input-wrapper input {
    flex: 1;
}

.toggle-visibility {
    background: var(--surface-hover);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0 0.75rem;
    cursor: pointer;
    transition: var(--transition);
}

.toggle-visibility:hover {
    background: var(--border-color);
}

/* ===================================
   Buttons
   =================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--surface-hover);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-sm {
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    background: var(--surface-hover);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-sm:hover {
    background: var(--border-color);
}

.btn-sm.btn-pdf {
    border-color: var(--pdf-color);
    color: var(--pdf-color);
}

.btn-sm.btn-pdf:hover {
    background: var(--pdf-color);
    color: white;
}

.btn-sm.btn-word {
    border-color: var(--word-color);
    color: var(--word-color);
}

.btn-sm.btn-word:hover {
    background: var(--word-color);
    color: white;
}

.btn-generate {
    width: 100%;
    padding: 1rem;
    font-size: 1.1rem;
}

/* Loading Spinner */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ===================================
   API Warning
   =================================== */
.api-warning {
    background: #fef3c7;
    border: 1px solid #fbbf24;
    color: #92400e;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    margin-top: 1rem;
    font-size: 0.9rem;
}

/* ===================================
   Modal
   =================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    transform: scale(0.9);
    transition: var(--transition);
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    line-height: 1;
}

.close-btn:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

/* ===================================
   Output Section
   =================================== */
.output-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
}

.output-header h2 {
    margin-bottom: 0;
}

.output-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.output-content {
    background: var(--surface-hover);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    max-height: 600px;
    overflow-y: auto;
}

/* Markdown Content Styling */
.output-content h1,
.output-content h2,
.output-content h3,
.output-content h4,
.output-content h5,
.output-content h6 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    font-weight: 600;
    line-height: 1.3;
}

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

.output-content h1 { font-size: 1.75rem; }
.output-content h2 { font-size: 1.5rem; border-bottom: 1px solid var(--border-color); padding-bottom: 0.5rem; }
.output-content h3 { font-size: 1.25rem; }
.output-content h4 { font-size: 1.1rem; }

.output-content p {
    margin-bottom: 1rem;
}

.output-content ul,
.output-content ol {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

.output-content li {
    margin-bottom: 0.5rem;
}

.output-content code {
    background: #e2e8f0;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 0.9em;
}

.output-content pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 1rem;
    border-radius: var(--radius-md);
    overflow-x: auto;
    margin-bottom: 1rem;
}

.output-content pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.output-content blockquote {
    border-left: 4px solid var(--primary-color);
    padding-left: 1rem;
    margin: 1rem 0;
    color: var(--text-secondary);
    font-style: italic;
}

.output-content table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
}

.output-content th,
.output-content td {
    border: 1px solid var(--border-color);
    padding: 0.75rem;
    text-align: left;
}

.output-content th {
    background: var(--surface);
    font-weight: 600;
}

.output-content input[type="checkbox"] {
    margin-right: 0.5rem;
}

/* ===================================
   Toast Notification
   =================================== */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-primary);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    opacity: 0;
    transition: all 0.3s ease;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.success {
    background: var(--success-color);
}

.toast.error {
    background: var(--error-color);
}

/* ===================================
   PDF Render Container Styles
   =================================== */
#pdfRenderContainer {
    width: 800px;
    padding: 40px;
    background: white;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: #1e293b;
    line-height: 1.6;
}

#pdfRenderContainer h1 { font-size: 28px; margin-bottom: 16px; }
#pdfRenderContainer h2 { font-size: 22px; margin-top: 24px; margin-bottom: 12px; border-bottom: 1px solid #e2e8f0; padding-bottom: 8px; }
#pdfRenderContainer h3 { font-size: 18px; margin-top: 20px; margin-bottom: 10px; }
#pdfRenderContainer p { margin-bottom: 12px; }
#pdfRenderContainer ul, #pdfRenderContainer ol { margin-bottom: 12px; padding-left: 24px; }
#pdfRenderContainer li { margin-bottom: 6px; }
#pdfRenderContainer code { background: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-size: 14px; }
#pdfRenderContainer pre { background: #1e293b; color: #e2e8f0; padding: 16px; border-radius: 8px; overflow-x: auto; margin-bottom: 16px; }
#pdfRenderContainer pre code { background: none; padding: 0; color: inherit; }
#pdfRenderContainer table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
#pdfRenderContainer th, #pdfRenderContainer td { border: 1px solid #e2e8f0; padding: 10px; text-align: left; }
#pdfRenderContainer th { background: #f8fafc; font-weight: 600; }

/* ===================================
   Responsive Design
   =================================== */
@media (max-width: 768px) {
    .header {
        padding: 1rem;
    }

    .header-content h1 {
        font-size: 1.25rem;
    }

    .main-content {
        padding: 1rem;
    }

    .card {
        padding: 1rem;
    }

    .output-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .output-actions {
        width: 100%;
    }

    .output-actions .btn-sm {
        flex: 1;
        min-width: calc(50% - 0.25rem);
    }

    .modal-actions {
        flex-direction: column;
    }

    .modal-actions .btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .header-content h1 {
        font-size: 1.1rem;
    }

    .subtitle {
        display: none;
    }

    .btn-generate {
        font-size: 1rem;
    }

    .output-actions .btn-sm {
        font-size: 0.75rem;
        padding: 0.4rem 0.5rem;
    }
}

/* ===================================
   Demo Version Styles
   =================================== */

/* Demo Banner */
.demo-banner {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
    text-align: center;
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    position: sticky;
    top: 0;
    z-index: 200;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}

.demo-banner a {
    color: white;
    text-decoration: underline;
    font-weight: 600;
}

.demo-banner a:hover {
    text-decoration: none;
}

/* Demo Badge in Header */
.demo-badge {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    font-size: 0.65rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    margin-left: 0.5rem;
    vertical-align: middle;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.5px;
    animation: pulse 2s ease-in-out infinite;
}

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

/* Demo Disabled Buttons */
.btn-sm.demo-disabled {
    opacity: 0.6;
    cursor: not-allowed;
    position: relative;
}

.btn-sm.demo-disabled:hover {
    background: var(--surface-hover);
}

.btn-sm.demo-disabled.btn-pdf:hover {
    background: var(--surface-hover);
    color: var(--pdf-color);
}

.btn-sm.demo-disabled.btn-word:hover {
    background: var(--surface-hover);
    color: var(--word-color);
}

/* Output Content Wrapper with Watermark */
.output-content-wrapper {
    position: relative;
    overflow: hidden;
}

.demo-watermark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-30deg);
    font-size: 4rem;
    font-weight: 800;
    color: rgba(99, 102, 241, 0.08);
    text-transform: uppercase;
    pointer-events: none;
    z-index: 1;
    white-space: nowrap;
    user-select: none;
}

.output-content {
    position: relative;
    z-index: 2;
}

/* Demo Modal Styling */
.demo-modal {
    max-width: 450px;
}

.demo-modal-content {
    text-align: center;
}

.demo-modal-message {
    font-size: 1.1rem;
    margin-bottom: 1.25rem;
    color: var(--text-primary);
}

.demo-features-list {
    list-style: none;
    padding: 0;
    margin: 1rem 0;
    text-align: left;
}

.demo-features-list li {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.95rem;
}

.demo-features-list li:last-child {
    border-bottom: none;
}

.demo-features-list.pro-features li {
    color: var(--text-secondary);
}

/* Responsive adjustments for demo banner */
@media (max-width: 768px) {
    .demo-banner {
        font-size: 0.8rem;
        padding: 0.6rem;
    }
    
    .demo-badge {
        font-size: 0.55rem;
        padding: 0.15rem 0.4rem;
    }
    
    .demo-watermark {
        font-size: 2.5rem;
    }
}

@media (max-width: 480px) {
    .demo-badge {
        display: none;
    }
    
    .demo-watermark {
        font-size: 1.8rem;
    }
}