/* Claude AI Editor CSS - Professional Writing Experience + NEW ERROR HANDLING */

/* Toast Notifications Container - DEPRECATED but kept for compatibility */
.toast-container {
    position: fixed;
    top: var(--space-6);
    right: var(--space-6);
    z-index: var(--z-tooltip);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    pointer-events: none;
    max-width: 400px;
}

.toast {
    background: white;
    border-radius: var(--radius-xl);
    padding: var(--space-4) var(--space-5);
    box-shadow: var(--shadow-xl);
    border-left: 4px solid;
    min-width: 300px;
    pointer-events: auto;
    transform: translateX(100%);
    opacity: 0;
    transition: all var(--transition-normal);
    font-size: var(--text-sm);
    line-height: var(--leading-normal);
    font-weight: var(--font-medium);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

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

.toast.error {
    border-left-color: var(--error-500);
    background: linear-gradient(135deg, var(--error-50) 0%, white 100%);
    color: var(--error-700);
}

.toast.success {
    border-left-color: var(--success-500);
    background: linear-gradient(135deg, var(--success-50) 0%, white 100%);
    color: var(--success-700);
}

.toast.progress {
    border-left-color: var(--blue-500);
    background: linear-gradient(135deg, var(--blue-50) 0%, white 100%);
    color: var(--blue-700);
}

.toast-content {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

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

.toast-message {
    flex: 1;
}

.toast-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: inherit;
    opacity: 0.6;
    transition: opacity var(--transition-normal);
    padding: 0;
    margin-left: var(--space-2);
}

.toast-close:hover {
    opacity: 1;
}

/* Studio Header */
.studio-header {
    padding: var(--space-6) var(--space-8);
    background: linear-gradient(135deg, var(--gray-25), var(--gray-50));
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.studio-header h2 {
    color: var(--gray-900);
    font-size: var(--text-xl);
    font-weight: var(--font-semibold);
    margin: 0;
}

.studio-stats {
    display: flex;
    gap: var(--space-4);
    font-size: var(--text-xs);
    color: var(--gray-600);
}

/* Response Container */
.response-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    background: white;
}

/* === NEW ENHANCED EDITOR PROGRESS SYSTEM === */
.editor-progress {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(8px);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn var(--transition-normal);
}

/* Progress State (existing) */
.editor-progress .progress-content {
    text-align: center;
    max-width: 400px;
    padding: var(--space-8);
}

.editor-progress .progress-spinner {
    width: 48px;
    height: 48px;
    margin: 0 auto var(--space-6);
    color: var(--orange-500);
}

.editor-progress .progress-spinner svg {
    animation: spin 1s linear infinite;
}

.editor-progress .progress-text h3 {
    color: var(--gray-900);
    font-size: var(--text-xl);
    font-weight: var(--font-semibold);
    margin-bottom: var(--space-3);
    line-height: var(--leading-tight);
}

.editor-progress .progress-text p {
    color: var(--gray-600);
    font-size: var(--text-sm);
    line-height: var(--leading-relaxed);
    margin-bottom: var(--space-4);
}

.editor-progress .progress-tips {
    background: var(--gray-100);
    border-radius: var(--radius-lg);
    padding: var(--space-3) var(--space-4);
    border-left: 3px solid var(--orange-500);
}

.editor-progress .progress-tips span {
    color: var(--gray-700);
    font-size: var(--text-xs);
    font-style: italic;
}

/* === NEW ERROR STATE === */
.editor-progress.error {
    background: rgba(254, 242, 242, 0.98); /* Subtle red tint */
}

.editor-progress.error .progress-content {
    text-align: center;
    max-width: 450px;
    padding: var(--space-8);
}

.editor-progress.error .error-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto var(--space-6);
    color: var(--error-500);
    animation: shake 0.5s ease-in-out;
}

.editor-progress.error .error-text h3 {
    color: var(--error-700);
    font-size: var(--text-xl);
    font-weight: var(--font-semibold);
    margin-bottom: var(--space-3);
    line-height: var(--leading-tight);
}

.editor-progress.error .error-text p {
    color: var(--error-600);
    font-size: var(--text-sm);
    line-height: var(--leading-relaxed);
    margin-bottom: var(--space-4);
}

.editor-progress.error .error-suggestions {
    background: var(--error-50);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    border-left: 3px solid var(--error-500);
    margin-bottom: var(--space-4);
    text-align: left;
}

.editor-progress.error .error-suggestions span {
    display: block;
    color: var(--error-700);
    font-size: var(--text-xs);
    margin-bottom: var(--space-2);
    line-height: var(--leading-relaxed);
}

.editor-progress.error .error-suggestions span:last-child {
    margin-bottom: 0;
}

.editor-progress.error .error-actions {
    display: flex;
    justify-content: center;
    gap: var(--space-3);
}

.editor-progress.error .retry-btn {
    background: var(--error-500);
    color: white;
    border: none;
    padding: var(--space-3) var(--space-6);
    border-radius: var(--radius-lg);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    cursor: pointer;
    transition: all var(--transition-normal);
    box-shadow: var(--shadow-sm);
}

.editor-progress.error .retry-btn:hover {
    background: var(--error-600);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* === NEW SUCCESS STATE === */
.editor-progress.success {
    background: rgba(240, 253, 244, 0.98); /* Subtle green tint */
}

.editor-progress.success .progress-content {
    text-align: center;
    max-width: 400px;
    padding: var(--space-6);
}

.editor-progress.success .success-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto var(--space-4);
    color: var(--success-500);
    animation: successPulse 0.6s ease-out;
}

.editor-progress.success .success-text h3 {
    color: var(--success-700);
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    margin-bottom: var(--space-2);
    line-height: var(--leading-tight);
}

.editor-progress.success .success-text p {
    color: var(--success-600);
    font-size: var(--text-sm);
    line-height: var(--leading-relaxed);
}

/* Editor Container - Fixed to fill available space */
.editor-container {
    background: white;
    border-radius: 0;
    border: none;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    flex: 1;
    position: relative;
    min-height: 400px; /* Ensure minimum height */
    height: 100%; /* Fill parent container */
}

#editor {
    flex: 1;
    min-height: 300px; /* Minimum height for editor */
    height: 100%; /* Fill available space */
    font-size: var(--text-base);
    line-height: var(--leading-relaxed);
    overflow: hidden;
}

/* Quill container adjustments */
.ql-container.ql-snow {
    border: none;
    font-family: var(--font-family);
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%; /* Fill available space */
}

.ql-editor {
    padding: var(--space-8);
    font-size: var(--text-base);
    line-height: var(--leading-relaxed);
    color: var(--gray-900);
    flex: 1;
    overflow-y: auto;
    min-height: 300px; /* Minimum height to prevent shrinking */
    height: 100%; /* Fill container */
}

/* Enhanced Quill Editor Styling */
.ql-toolbar.ql-snow {
    border: none;
    border-bottom: 1px solid var(--gray-200);
    padding: var(--space-4) var(--space-6);
    background: linear-gradient(135deg, var(--gray-25), var(--gray-50));
    flex-shrink: 0;
}

.ql-toolbar.ql-snow .ql-formats {
    margin-right: var(--space-4);
}

.ql-toolbar.ql-snow button {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    margin: var(--space-1);
    transition: all var(--transition-normal);
    border: 1px solid transparent;
    color: var(--gray-600);
}

.ql-toolbar.ql-snow button:hover {
    background: var(--orange-50);
    border-color: var(--orange-200);
    color: var(--orange-600);
}

.ql-toolbar.ql-snow button.ql-active {
    background: var(--orange-500);
    color: white;
    border-color: var(--orange-500);
}

.ql-toolbar.ql-snow .ql-picker {
    color: var(--gray-700);
}

.ql-toolbar.ql-snow .ql-picker:hover {
    color: var(--orange-600);
}

.ql-toolbar.ql-snow .ql-picker.ql-expanded {
    color: var(--orange-600);
}

.ql-toolbar.ql-snow .ql-picker-options {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    padding: var(--space-2);
}

.ql-toolbar.ql-snow .ql-picker-item:hover {
    background: var(--orange-50);
    color: var(--orange-600);
}

.ql-container.ql-snow {
    border: none;
    font-family: var(--font-family);
    flex: 1;
    display: flex;
    flex-direction: column;
}

.ql-editor {
    padding: var(--space-8);
    font-size: var(--text-base);
    line-height: var(--leading-relaxed);
    color: var(--gray-900);
    flex: 1;
    overflow-y: auto;
    max-height: none;
}

.ql-editor.ql-blank::before {
    color: var(--gray-500);
    font-style: italic;
    left: var(--space-8);
    right: var(--space-8);
    font-size: var(--text-base);
    line-height: var(--leading-relaxed);
}

/* Enhanced Typography in Editor */
.ql-editor h1 {
    font-size: var(--text-3xl);
    color: var(--gray-900);
    margin-top: var(--space-8);
    margin-bottom: var(--space-4);
    border-bottom: 2px solid var(--orange-200);
    padding-bottom: var(--space-2);
    font-weight: var(--font-bold);
    line-height: var(--leading-tight);
}

.ql-editor h2 {
    font-size: var(--text-2xl);
    color: var(--gray-800);
    margin-top: var(--space-6);
    margin-bottom: var(--space-3);
    font-weight: var(--font-semibold);
    line-height: var(--leading-tight);
}

.ql-editor h3 {
    font-size: var(--text-xl);
    color: var(--gray-800);
    margin-top: var(--space-5);
    margin-bottom: var(--space-3);
    font-weight: var(--font-semibold);
    line-height: var(--leading-snug);
}

.ql-editor blockquote {
    border-left: 4px solid var(--orange-300);
    padding-left: var(--space-4);
    margin: var(--space-6) 0;
    background: var(--orange-25, #fefaf8);
    padding: var(--space-5);
    border-radius: var(--radius-lg);
    font-style: italic;
    color: var(--gray-700);
    position: relative;
}

.ql-editor blockquote::before {
    content: '"';
    font-size: var(--text-4xl);
    color: var(--orange-300);
    position: absolute;
    top: var(--space-2);
    left: var(--space-4);
    line-height: 1;
}

.ql-editor ul,
.ql-editor ol {
    padding-left: var(--space-6);
    margin: var(--space-4) 0;
}

.ql-editor li {
    margin-bottom: var(--space-2);
    line-height: var(--leading-relaxed);
}

.ql-editor strong {
    color: var(--gray-900);
    font-weight: var(--font-semibold);
}

.ql-editor em {
    color: var(--gray-700);
    font-style: italic;
}

.ql-editor a {
    color: var(--orange-600);
    text-decoration: none;
    border-bottom: 1px solid var(--orange-300);
    transition: all var(--transition-normal);
}

.ql-editor a:hover {
    color: var(--orange-700);
    border-bottom-color: var(--orange-700);
}

.ql-editor p {
    margin-bottom: var(--space-4);
    line-height: var(--leading-relaxed);
}

.ql-editor code {
    background: var(--gray-100);
    color: var(--gray-800);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.9em;
}

.ql-editor pre {
    background: var(--gray-900);
    color: var(--gray-100);
    padding: var(--space-4);
    border-radius: var(--radius-lg);
    overflow-x: auto;
    font-family: var(--font-mono);
    line-height: var(--leading-normal);
    margin: var(--space-4) 0;
}

/* Editor Actions */
.editor-actions {
    padding: var(--space-4) var(--space-6);
    background: var(--gray-50);
    border-top: 1px solid var(--gray-200);
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
    align-items: center;
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    z-index: 5;
    min-height: 60px; /* Ensure minimum height for actions */
}

.editor-stats {
    margin-left: auto;
    display: flex;
    gap: var(--space-3);
    font-size: var(--text-xs);
    color: var(--gray-600);
    font-weight: var(--font-medium);
}

.editor-stats .counter-item {
    background: white;
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    gap: var(--space-1);
    font-weight: var(--font-medium);
}

/* === NEW ANIMATIONS === */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-3px); }
    20%, 40%, 60%, 80% { transform: translateX(3px); }
}

@keyframes successPulse {
    0% { 
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
    }
    70% { 
        transform: scale(1.05);
        box-shadow: 0 0 0 10px rgba(34, 197, 94, 0);
    }
    100% { 
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
    }
}

/* Responsive Design - Maintain consistent height */
@media (max-width: 1024px) {
    .studio-card {
        height: auto;
        max-height: none;
        min-height: 500px; /* Maintain minimum height on tablets */
    }
    
    .writing-studio {
        position: static;
        max-height: none;
    }
}

@media (max-width: 768px) {
    .studio-header {
        padding: var(--space-4) var(--space-6);
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
    }

    .studio-stats {
        align-self: stretch;
        justify-content: space-between;
    }

    .editor-actions {
        flex-direction: column;
        align-items: stretch;
        gap: var(--space-2);
        padding: var(--space-3) var(--space-4);
    }

    .editor-stats {
        margin-left: 0;
        justify-content: center;
        flex-wrap: wrap;
        order: -1;
    }

    .ql-toolbar.ql-snow {
        padding: var(--space-3) var(--space-4);
    }

    .ql-toolbar.ql-snow .ql-formats {
        margin-right: var(--space-3);
        margin-bottom: var(--space-2);
    }

    .ql-editor {
        padding: var(--space-6) var(--space-4);
        font-size: var(--text-sm);
        min-height: 250px; /* Smaller minimum on mobile but still consistent */
    }

    .ql-editor.ql-blank::before {
        left: var(--space-4);
        right: var(--space-4);
        font-size: var(--text-sm);
    }

    .studio-card {
        border-radius: var(--radius-xl);
        min-height: 450px; /* Consistent minimum height on mobile */
        height: auto; /* Allow auto height on mobile for better UX */
    }

    .writing-studio {
        position: static;
        top: auto;
        max-height: none;
    }
    
    /* Mobile error/success messages */
    .editor-progress .progress-content,
    .editor-progress.error .progress-content,
    .editor-progress.success .progress-content {
        padding: var(--space-6);
    }
    
    .editor-progress .progress-spinner,
    .editor-progress.error .error-icon,
    .editor-progress.success .success-icon {
        width: 40px;
        height: 40px;
        margin-bottom: var(--space-4);
    }
    
    .editor-progress .progress-text h3,
    .editor-progress.error .error-text h3,
    .editor-progress.success .success-text h3 {
        font-size: var(--text-lg);
    }
    
    .editor-progress .progress-text p,
    .editor-progress.error .error-text p,
    .editor-progress.success .success-text p {
        font-size: var(--text-xs);
    }
}

@media (max-width: 480px) {
    .ql-editor {
        padding: var(--space-4) var(--space-3);
        font-size: var(--text-sm);
    }
    
    .ql-toolbar.ql-snow {
        padding: var(--space-2) var(--space-3);
    }
    
    .editor-actions {
        padding: var(--space-3);
    }
    
    .studio-header {
        padding: var(--space-3) var(--space-4);
    }
    
    .studio-stats .counter-item {
        font-size: 11px;
        padding: var(--space-1) var(--space-2);
    }

    .editor-container {
        min-height: 350px;
    }
    
    .editor-progress .progress-content,
    .editor-progress.error .progress-content,
    .editor-progress.success .progress-content {
        padding: var(--space-4);
    }
    
    .editor-progress .progress-spinner,
    .editor-progress.error .error-icon,
    .editor-progress.success .success-icon {
        width: 32px;
        height: 32px;
    }
    
    .ql-editor h1 {
        font-size: var(--text-2xl);
    }
    
    .ql-editor h2 {
        font-size: var(--text-xl);
    }
    
    .ql-editor h3 {
        font-size: var(--text-lg);
    }
    
    /* Mobile error suggestions */
    .editor-progress.error .error-suggestions {
        padding: var(--space-3);
    }
    
    .editor-progress.error .error-suggestions span {
        font-size: 11px;
    }
    
    .editor-progress.error .retry-btn {
        padding: var(--space-2) var(--space-4);
        font-size: var(--text-xs);
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .editor-container,
    .studio-card {
        border: 2px solid var(--gray-800);
    }
    
    .ql-toolbar.ql-snow,
    .editor-actions {
        border-color: var(--gray-600);
    }
    
    .editor-progress.error {
        background: rgba(254, 226, 226, 0.98);
    }
    
    .editor-progress.success {
        background: rgba(220, 252, 231, 0.98);
    }
}

/* Print styles */
@media print {
    .studio-header,
    .editor-actions,
    .ql-toolbar,
    .toast-container,
    .editor-progress {
        display: none !important;
    }
    
    .editor-container {
        border: none;
        box-shadow: none;
    }
    
    .ql-editor {
        padding: 0;
        color: black;
    }
}