/* Code Editor Styles */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

/* Container and Layout */
.container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 25px 30px;
    text-align: center;
}

.header h1 {
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 10px;
}

.header p {
    opacity: 0.9;
    font-size: 14px;
}

/* Main Content */
.main-content {
    padding: 30px;
}

.editor-section {
    margin-bottom: 30px;
}

.preview-section {
    margin-top: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
}

.section-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 15px;
    color: #333;
}

.section-title-group .section-title {
    margin-bottom: 0;
}

/* Code Input Section */
.code-section {
    display: none;
}

.code-section.active {
    display: block;
}

.code-toggle {
    margin-bottom: 10px;
    padding: 8px 16px;
    background: #6c757d;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.3s;
}

.code-toggle:hover {
    background: #5a6268;
}

/* Code Input */
.code-input {
    width: 100%;
    height: 350px;
    padding: 15px;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 13px;
    resize: vertical;
    transition: border-color 0.3s;
}

.code-input:focus {
    outline: none;
    border-color: #667eea;
}

/* Prompt Section */
.prompt-section {
    margin-top: 20px;
}

.prompt-input {
    width: 100%;
    padding: 12px;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    font-size: 14px;
    resize: vertical;
    min-height: 80px;
    transition: border-color 0.3s;
}

.prompt-input:focus {
    outline: none;
    border-color: #667eea;
}

/* Mode Selector */
.mode-selector {
    margin-top: 15px;
    display: flex;
    align-items: center;
    gap: 15px;
}

.mode-selector label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    font-size: 14px;
}

.mode-selector input[type="radio"] {
    cursor: pointer;
}

/* Section Header for Preview */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.section-title-group {
    display: flex;
    align-items: center;
    gap: 15px;
}

.btn-save-theme {
    padding: 10px 24px;
    background: #28a745;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 2px 4px rgba(40, 167, 69, 0.2);
}

.btn-save-theme:hover {
    background: #218838;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(40, 167, 69, 0.3);
}

/* Revision Info */
.revision-info {
    font-size: 13px;
    color: #495057;
    display: flex;
    gap: 15px;
    align-items: center;
}

.revision-counter {
    font-weight: 600;
    color: #667eea;
}

.history-buttons {
    display: none;
    gap: 8px;
}

.history-buttons.has-history {
    display: flex;
}

.btn-history {
    padding: 6px 12px;
    background: white;
    color: #667eea;
    border: 1px solid #667eea;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-history:hover:not(:disabled) {
    background: #667eea;
    color: white;
}

.btn-history:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Action Buttons */
.action-buttons {
    margin-top: 20px;
    display: flex;
    gap: 10px;
}


.btn {
    padding: 12px 30px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 14px;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}

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

.btn-secondary {
    background: #e9ecef;
    color: #495057;
}

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

/* Preview Toggle */
.preview-toggle {
    margin-bottom: 15px;
    padding: 10px 20px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.preview-toggle:hover {
    background: #5a67d8;
}

.preview-content {
    display: none;
}

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

/* Preview Frame */
.preview-frame {
    width: 100%;
    max-width: 800px;
    min-height: 400px;
    height: 400px; /* Starting height, can be overridden by resize messages */
    border: 2px solid #dee2e6;
    border-radius: 8px;
    background: white;
    transition: height 0.3s ease, width 0.3s ease;
    overflow: auto; /* Allow scrolling if content is larger */
    box-sizing: content-box; /* Ensure border is outside the dimensions */
}

/* Status Messages */
.status-message {
    padding: 12px;
    border-radius: 6px;
    margin-top: 15px;
    font-size: 14px;
    display: none;
}

.status-message.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
    display: block;
}

.status-message.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    display: block;
}

.status-message.info {
    background: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
    display: block;
}

/* Loading Spinner */
.loading {
    display: none;
    align-items: center;
    gap: 10px;
    margin-top: 15px;
}

.loading.active {
    display: flex;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Debug Section */
.debug-section {
    margin-top: 20px;
    padding: 15px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    display: none;
}

.debug-section.active {
    display: block;
}

/* Data section for displaying salesInvoiceViewData */
.data-section {
    margin-top: 20px;
    padding: 15px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    display: none;
}

.data-section.active {
    display: block;
}

.data-content {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    background: white;
    padding: 10px;
    border-radius: 4px;
    border: 1px solid #dee2e6;
    max-height: 400px;
    overflow-y: auto;
    color: #2d3748;
}

/* Debug container at the bottom */
.debug-container {
    margin-top: 20px;
    padding: 0 20px 20px;
}

/* Small debug toggle button */
.debug-toggle-small {
    padding: 4px 12px;
    background: #e0e0e0;
    color: #666;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
    opacity: 0.7;
    margin-right: 8px;
}

.debug-toggle-small:hover {
    background: #d0d0d0;
    opacity: 1;
}

/* Old debug toggle - kept for backwards compatibility */
.debug-toggle {
    margin-top: 10px;
    padding: 8px 16px;
    background: #6c757d;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.3s;
}

.debug-toggle:hover {
    background: #5a6268;
}

.debug-content {
    margin-top: 15px;
    padding: 12px;
    background: #282c34;
    color: #abb2bf;
    border-radius: 6px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 12px;
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.debug-label {
    font-weight: 600;
    color: #61dafb;
    margin-bottom: 8px;
    display: block;
}

/* Clarification Dialog */
.clarification-dialog {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    max-width: 500px;
    width: 90%;
}

.clarification-dialog.active {
    display: block;
}

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

.clarification-overlay.active {
    display: block;
}

.clarification-title {
    font-size: 18px;
    font-weight: 600;
    color: #333;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.clarification-icon {
    color: #667eea;
    font-size: 24px;
}

.clarification-question {
    font-size: 14px;
    color: #495057;
    margin-bottom: 20px;
    line-height: 1.5;
}

.clarification-suggestions {
    margin-bottom: 20px;
}

.suggestion-item {
    padding: 8px 12px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    margin-bottom: 8px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.suggestion-item:hover {
    background: #e9ecef;
    border-color: #667eea;
}

.clarification-input {
    width: 100%;
    padding: 10px;
    border: 2px solid #dee2e6;
    border-radius: 6px;
    font-size: 14px;
    margin-bottom: 15px;
    resize: vertical;
    min-height: 60px;
}

.clarification-input:focus {
    outline: none;
    border-color: #667eea;
}

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

.clarification-btn {
    padding: 8px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.clarification-submit {
    background: #667eea;
    color: white;
}

.clarification-submit:hover {
    background: #5a67d8;
}

.clarification-cancel {
    background: #e9ecef;
    color: #495057;
}

.clarification-cancel:hover {
    background: #dee2e6;
}

/* User Action Required Dialog */
.user-action-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

.user-action-overlay.active {
    display: block;
}

.user-action-dialog {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 1001;
    width: 90%;
    max-width: 550px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 25px;
}

.user-action-dialog.active {
    display: block;
}

.user-action-title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    font-size: 20px;
    font-weight: 600;
    color: #d97706;
    border-bottom: 2px solid #fed7aa;
    padding-bottom: 10px;
}

.user-action-icon {
    font-size: 28px;
}

.user-action-content {
    color: #4a5568;
    line-height: 1.6;
}

.user-action-needed {
    font-weight: 600;
    color: #2d3748;
    font-size: 16px;
    margin-bottom: 15px;
}

.user-action-reason {
    background: #fef3c7;
    border-left: 4px solid #f59e0b;
    padding: 10px 15px;
    margin-bottom: 20px;
    border-radius: 4px;
}

.user-action-steps {
    margin-bottom: 20px;
}

.user-action-steps h4 {
    color: #2d3748;
    margin-bottom: 10px;
    font-size: 15px;
}

.user-action-steps ol {
    margin-left: 20px;
}

.user-action-steps li {
    margin-bottom: 8px;
}

.user-action-alternatives {
    background: #e0e7ff;
    border-left: 4px solid #4f46e5;
    padding: 10px 15px;
    margin-bottom: 20px;
    border-radius: 4px;
}

.user-action-alternatives h4 {
    color: #312e81;
    margin-bottom: 8px;
    font-size: 14px;
}

.user-action-alternatives ul {
    margin: 0;
    padding-left: 20px;
}

.user-action-buttons {
    display: flex;
    justify-content: center;
    padding-top: 15px;
    border-top: 1px solid #e2e8f0;
}

.user-action-btn {
    padding: 10px 30px;
    background: #f59e0b;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
}

.user-action-btn:hover {
    background: #d97706;
    transform: translateY(-1px);
}

/* Save Theme Dialog */
.save-theme-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

.save-theme-overlay.active {
    display: block;
}

.save-theme-dialog {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 1001;
    width: 90%;
    max-width: 400px;
    padding: 25px;
}

.save-theme-dialog.active {
    display: block;
}

.save-theme-title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    font-size: 18px;
    font-weight: 600;
    color: #2d3748;
}

.save-theme-icon {
    font-size: 24px;
}

.save-theme-content {
    margin-bottom: 20px;
}

.save-theme-content label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #4a5568;
}

.theme-title-input {
    width: 100%;
    padding: 10px;
    border: 2px solid #dee2e6;
    border-radius: 6px;
    font-size: 14px;
}

.theme-title-input:focus {
    outline: none;
    border-color: #667eea;
}

.save-theme-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.save-theme-btn {
    padding: 8px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s;
}

.save-theme-btn.save-theme-cancel {
    background: #e2e8f0;
    color: #4a5568;
}

.save-theme-btn.save-theme-cancel:hover {
    background: #cbd5e0;
}

.save-theme-btn.save-theme-submit {
    background: #667eea;
    color: white;
}

.save-theme-btn.save-theme-submit:hover {
    background: #4c51bf;
}

/* Save Success Dialog */
.save-success-dialog {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 1001;
    padding: 30px;
    text-align: center;
    max-width: 350px;
}

.save-success-dialog.active {
    display: block;
}

.save-success-icon {
    font-size: 48px;
    margin-bottom: 15px;
}

.save-success-message h3 {
    margin: 0 0 10px;
    color: #2d3748;
}

.save-success-message p {
    margin: 0 0 20px;
    color: #718096;
    font-size: 14px;
}

.save-success-reload {
    padding: 10px 24px;
    background: #48bb78;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s;
}

.save-success-reload:hover {
    background: #38a169;
    transform: translateY(-1px);
}

/* Responsive Design */
@media (max-width: 768px) {
    .main-content {
        padding: 20px;
    }
    
    .container {
        margin: 10px;
    }
}