/**
 * Prompt-to-TikZ Generation Section
 *
 * CSS Foundation System compliant
 * WCAG AAA accessibility (contrast >= 6.2:1)
 * Mobile-first responsive design
 */

/* ============================================
   SECTION CONTAINER
   ============================================ */

.tikz-app .prompt-to-tikz-section {
    background: var(--prompt-bg);
    backdrop-filter: var(--glass-blur-medium);
    -webkit-backdrop-filter: var(--glass-blur-medium);
    border-radius: var(--prompt-border-radius);
    padding: var(--spacing-12);
    margin-top: var(--spacing-16);
    margin-bottom: var(--spacing-16);
    box-shadow: var(--prompt-shadow);
    border: var(--prompt-border-width) solid var(--prompt-border);
}

.tikz-app .prompt-to-tikz-section .index-title {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--text-header-glass);
    margin-bottom: var(--spacing-4);
    display: flex;
    align-items: center;
    gap: var(--spacing-4);
}

.tikz-app .prompt-to-tikz-section .index-title .title-icon {
    font-size: 1.5rem;
    line-height: 1;
}

.tikz-app .prompt-to-tikz-section .section-description {
    font-size: 1rem;
    color: var(--text-on-glass);
    margin-bottom: var(--spacing-16);
    line-height: 1.6;
}

/* ============================================
   PROMPT INPUT
   ============================================ */

.tikz-app .prompt-input-container {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-4);
}

.tikz-app .prompt-label {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-header-glass);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-2);
}

.tikz-app .prompt-hint {
    font-size: var(--prompt-hint-size);
    font-weight: 400;
    color: rgba(45, 52, 54, 0.7);
    font-style: italic;
}

.tikz-app .prompt-textarea {
    width: 100%;
    padding: var(--spacing-8);
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-on-glass);
    background: rgba(255, 255, 255, 0.5);
    border: var(--prompt-border-width) solid var(--prompt-border);
    border-radius: var(--prompt-border-radius);
    resize: vertical;
    min-height: 120px;
    transition: var(--prompt-transition);
}

.tikz-app .prompt-textarea:focus {
    outline: none;
    border-color: var(--prompt-focus);
    box-shadow: var(--prompt-focus-shadow);
    background: rgba(255, 255, 255, 0.8);
}

.tikz-app .prompt-textarea::placeholder {
    color: rgba(45, 52, 54, 0.5);
}

/* ============================================
   PROMPT FOOTER
   ============================================ */

.tikz-app .prompt-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--spacing-4);
}

.tikz-app .prompt-char-count {
    font-size: var(--prompt-hint-size);
    color: rgba(45, 52, 54, 0.7);
}

.tikz-app .prompt-char-count #char-current {
    font-weight: 600;
    color: var(--text-on-glass);
}

/* Warning when near limit */
.tikz-app .prompt-char-count.warning #char-current {
    color: #ff9800;
}

/* Error when at limit */
.tikz-app .prompt-char-count.error #char-current {
    color: var(--prompt-error);
}

.tikz-app .show-examples-btn {
    display: flex;
    align-items: center;
    gap: var(--spacing-4);
    padding: var(--spacing-4) var(--spacing-8);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--primary-color);
    background: transparent;
    border: 1px solid var(--primary-color);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--prompt-transition);
}

.tikz-app .show-examples-btn:hover {
    background: rgba(25, 118, 210, 0.1);
}

.tikz-app .show-examples-btn:focus {
    outline: 2px solid var(--prompt-focus);
    outline-offset: 2px;
}

/* ============================================
   EXAMPLE PROMPTS
   ============================================ */

.tikz-app .prompt-examples {
    margin-top: var(--spacing-8);
    padding: var(--spacing-8);
    background: rgba(25, 118, 210, 0.05);
    border-left: 3px solid var(--primary-color);
    border-radius: 8px;
}

.tikz-app .prompt-examples .examples-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-header-glass);
    margin-bottom: var(--spacing-8);
}

.tikz-app .examples-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-4);
}

.tikz-app .example-item {
    margin: 0;
}

.tikz-app .example-btn {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-6);
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(31, 38, 135, 0.1);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--prompt-transition);
    text-align: left;
}

.tikz-app .example-btn:hover {
    background: rgba(255, 255, 255, 0.9);
    border-color: var(--primary-color);
    transform: translateX(4px);
}

.tikz-app .example-btn:focus {
    outline: 2px solid var(--prompt-focus);
    outline-offset: 2px;
}

.tikz-app .example-text {
    font-size: 0.9375rem;
    color: var(--text-on-glass);
    line-height: 1.5;
}

.tikz-app .example-action {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--primary-color);
    white-space: nowrap;
}

/* ============================================
   GENERATE BUTTON & ACTIONS
   ============================================ */

.tikz-app .prompt-actions {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-4);
    margin-top: var(--spacing-8);
}

.tikz-app .generate-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-4);
    padding: var(--spacing-8) var(--spacing-12);
    font-size: 1.125rem;
    font-weight: 600;
    color: white;
    background: linear-gradient(135deg, var(--primary-color), #1565c0);
    border: none;
    border-radius: var(--prompt-border-radius);
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(25, 118, 210, 0.3);
    transition: var(--prompt-transition);
}

.tikz-app .generate-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(25, 118, 210, 0.4);
}

.tikz-app .generate-btn:active:not(:disabled) {
    transform: translateY(0);
}

.tikz-app .generate-btn:disabled {
    background: rgba(45, 52, 54, 0.3);
    color: rgba(45, 52, 54, 0.5);
    cursor: not-allowed;
    box-shadow: none;
}

.tikz-app .generate-btn:focus {
    outline: 2px solid var(--prompt-focus);
    outline-offset: 2px;
}

.tikz-app .btn-icon {
    font-size: 1.25rem;
    line-height: 1;
}

.tikz-app .login-hint {
    font-size: 0.875rem;
    color: rgba(45, 52, 54, 0.7);
    text-align: center;
    margin: 0;
}

.tikz-app .login-link {
    color: var(--primary-color);
    font-weight: 600;
    text-decoration: none;
    transition: var(--prompt-transition);
}

.tikz-app .login-link:hover {
    text-decoration: underline;
}

/* ============================================
   LOADING STATE
   ============================================ */

.tikz-app .generation-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-8);
    padding: var(--spacing-16);
    margin-top: var(--spacing-12);
    background: rgba(255, 255, 255, 0.7);
    border-radius: var(--prompt-border-radius);
    border: 1px dashed var(--primary-color);
}

.tikz-app .loading-spinner {
    width: var(--spinner-size);
    height: var(--spinner-size);
    border: var(--spinner-border) solid rgba(25, 118, 210, 0.2);
    border-top-color: var(--spinner-color);
    border-radius: 50%;
    animation: spinner-rotate 1s linear infinite;
}

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

.tikz-app .loading-text {
    font-size: 1.125rem;
    font-weight: 500;
    color: var(--text-header-glass);
    margin: 0;
}

.tikz-app .loading-subtext {
    font-size: 0.875rem;
    color: rgba(45, 52, 54, 0.7);
    margin: 0;
}

/* ============================================
   ERROR DISPLAY
   ============================================ */

.tikz-app .generation-error {
    display: flex;
    gap: var(--spacing-8);
    padding: var(--spacing-12);
    margin-top: var(--spacing-12);
    background: rgba(220, 53, 69, 0.1);
    border-left: 4px solid var(--prompt-error);
    border-radius: var(--prompt-border-radius);
}

.tikz-app .generation-error .error-icon {
    font-size: 2rem;
    line-height: 1;
    flex-shrink: 0;
}

.tikz-app .generation-error .error-content {
    flex: 1;
}

.tikz-app .generation-error .error-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--prompt-error);
    margin: 0 0 var(--spacing-4) 0;
}

.tikz-app .generation-error .error-message {
    font-size: 1rem;
    color: var(--text-on-glass);
    margin: 0 0 var(--spacing-8) 0;
    line-height: 1.5;
}

.tikz-app .generation-error .error-retry-btn {
    padding: var(--spacing-4) var(--spacing-8);
    font-size: 0.9375rem;
    font-weight: 500;
    color: white;
    background: var(--prompt-error);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--prompt-transition);
}

.tikz-app .generation-error .error-retry-btn:hover {
    background: #c82333;
}

/* ============================================
   GENERATED CODE DISPLAY
   ============================================ */

.tikz-app .generated-code-container {
    margin-top: var(--spacing-16);
    padding: var(--spacing-12);
    background: rgba(40, 167, 69, 0.05);
    border: 1px solid rgba(40, 167, 69, 0.3);
    border-radius: var(--prompt-border-radius);
}

.tikz-app .generated-code-container .generated-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--spacing-4);
    margin-bottom: var(--spacing-8);
}

.tikz-app .generated-code-container .generated-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-header-glass);
    margin: 0;
    display: flex;
    align-items: center;
    gap: var(--spacing-4);
}

.tikz-app .generated-code-container .generated-meta {
    display: flex;
    gap: var(--spacing-4);
    align-items: center;
}

.tikz-app .generated-code-container .diagram-type-badge {
    padding: var(--spacing-2) var(--spacing-6);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: white;
    background: var(--primary-color);
    border-radius: 12px;
}

.tikz-app .generated-code-container .generation-time {
    font-size: 0.875rem;
    color: rgba(45, 52, 54, 0.7);
}

/* CodeMirror wrapper */
.tikz-app .generated-code-container .generated-code-editor {
    margin-bottom: var(--spacing-4);
    border-radius: 8px;
    overflow: visible;
    background: var(--input-bg, #ffffff);
}

.tikz-app .generated-code-container .generated-code-editor .CodeMirror {
    height: auto;
    min-height: 60px;
    max-height: 400px;
    font-size: 0.9375rem;
    border: none;
}

.tikz-app .generated-code-container .generated-code-editor .CodeMirror .CodeMirror-scroll {
    max-height: 400px;
    overflow-y: auto;
    overflow-x: auto;
}

/* Textarea fallback styling - HIGH SPECIFICITY (no !important) */
.tikz-app .generated-code-container .generated-code-editor textarea.tikz-textarea-fallback,
.tikz-app .generated-code-container .generated-code-editor textarea:not(.cm-initialized) {
    width: 100%;
    min-height: 60px;
    max-height: 400px;
    font-family: 'Courier New', monospace;
    font-size: 0.9375rem;
    line-height: 1.5;
    border: none;
    border-radius: 0;
    padding: var(--spacing-3);
    background: var(--input-bg, #ffffff);
    color: var(--text-primary, #1a1a1a);
    resize: vertical;
    display: block;
    outline: none;
    box-shadow: none;
}

/* Fallback state with higher specificity for CodeMirror overrides */
.tikz-app .prompt-to-tikz-section .generated-code-container .generated-code-editor textarea.tikz-fallback {
    /* Highest specificity selector: (0,0,5,0) = 50 > CodeMirror (0,0,2,0) = 20 */
    width: 100%;
    min-height: 60px;
    max-height: 400px;
    font-family: 'Courier New', monospace;
    font-size: 0.9375rem;
    line-height: 1.5;
    border: none;
    border-radius: 0;
    padding: var(--spacing-3);
    background: var(--input-bg, #ffffff);
    color: var(--text-primary, #1a1a1a);
    resize: vertical;
    display: block;
    outline: none;
    box-shadow: none;
}

/* Content state - increased min-height when textarea has content */
.tikz-app .prompt-to-tikz-section .generated-code-container .generated-code-editor textarea.tikz-fallback.has-content,
.tikz-app .generated-code-container .generated-code-editor textarea.tikz-textarea-fallback.has-content {
    min-height: 150px;
}

/* Placeholder state - minimal height when empty */
.tikz-app .generated-code-container .generated-code-editor textarea.tikz-textarea-fallback:empty,
.tikz-app .generated-code-container .generated-code-editor textarea.tikz-textarea-fallback:placeholder-shown,
.tikz-app .generated-code-container .generated-code-editor textarea:not(.cm-initialized):empty,
.tikz-app .generated-code-container .generated-code-editor textarea:not(.cm-initialized):placeholder-shown {
    min-height: 30px;
}

/* Hide border conflicts with high specificity */
.tikz-app .prompt-to-tikz-section .generated-code-container .generated-code-editor textarea.tikz-fallback:focus {
    border-color: transparent;
    box-shadow: none;
}

/* Compact state when no content is present */
.tikz-app .generated-code-container .generated-code-editor.empty-state {
    min-height: 60px;
}

.tikz-app .generated-code-container .generated-code-editor.empty-state .CodeMirror {
    min-height: 60px;
    max-height: 60px;
    overflow: hidden;
}

.tikz-app .generated-code-container .generated-code-editor.empty-state .CodeMirror-scroll {
    max-height: 60px;
    overflow: hidden;
}

.tikz-app .generated-code-container .generated-code-editor.empty-state textarea {
    min-height: 60px;
    max-height: 60px;
}

/* ============================================
   PACKAGES INFO
   ============================================ */

.tikz-app .generated-code-container .packages-info {
    margin-bottom: var(--spacing-8);
    padding: var(--spacing-8);
    background: rgba(255, 255, 255, 0.5);
    border-radius: 8px;
}

.tikz-app .generated-code-container .packages-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-header-glass);
    margin: 0 0 var(--spacing-4) 0;
}

.tikz-app .generated-code-container .packages-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-4);
}

.tikz-app .generated-code-container .package-item {
    padding: var(--spacing-2) var(--spacing-6);
    font-size: 0.875rem;
    font-family: 'Courier New', monospace;
    color: var(--text-on-glass);
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(31, 38, 135, 0.15);
    border-radius: 6px;
}

/* ============================================
   ACTION BUTTONS
   ============================================ */

.tikz-app .generated-code-container .generated-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-4);
}

.tikz-app .generated-code-container .action-btn {
    display: flex;
    align-items: center;
    gap: var(--spacing-4);
    padding: var(--spacing-6) var(--spacing-12);
    font-size: 1rem;
    font-weight: 500;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--prompt-transition);
}

.tikz-app .generated-code-container .copy-btn {
    color: white;
    background: var(--primary-color);
}

.tikz-app .generated-code-container .copy-btn:hover {
    background: #1565c0;
    transform: translateY(-1px);
}

.tikz-app .generated-code-container .use-btn {
    color: white;
    background: var(--prompt-success);
}

.tikz-app .generated-code-container .use-btn:hover {
    background: #218838;
    transform: translateY(-1px);
}

.tikz-app .generated-code-container .clear-btn {
    color: var(--text-on-glass);
    background: rgba(45, 52, 54, 0.1);
    border: 1px solid rgba(45, 52, 54, 0.2);
}

.tikz-app .generated-code-container .clear-btn:hover {
    background: rgba(45, 52, 54, 0.2);
}

.tikz-app .generated-code-container .action-btn:focus {
    outline: 2px solid var(--prompt-focus);
    outline-offset: 2px;
}

/* ============================================
   COPY SUCCESS TOAST
   ============================================ */

.tikz-app .copy-success-toast {
    position: fixed;
    bottom: var(--spacing-12);
    right: var(--spacing-12);
    padding: var(--spacing-8) var(--spacing-12);
    font-size: 1rem;
    font-weight: 500;
    color: white;
    background: var(--prompt-success);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    animation: toast-slide-in 0.3s ease-out;
    z-index: 9999;
}

@keyframes toast-slide-in {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ============================================
   HISTORY (Optional)
   ============================================ */

.tikz-app .generation-history {
    margin-top: var(--spacing-16);
    position: relative;
}

.tikz-app .show-history-btn {
    display: flex;
    align-items: center;
    gap: var(--spacing-4);
    padding: var(--spacing-6) var(--spacing-12);
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-on-glass);
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(31, 38, 135, 0.15);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--prompt-transition);
}

.tikz-app .show-history-btn:hover {
    background: rgba(255, 255, 255, 0.9);
    border-color: var(--primary-color);
}

.tikz-app .history-count {
    padding: var(--spacing-1) var(--spacing-4);
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
    background: var(--primary-color);
    border-radius: 12px;
}

.tikz-app .history-dropdown {
    position: absolute;
    top: calc(100% + var(--spacing-4));
    left: 0;
    right: 0;
    max-width: 600px;
    max-height: 400px;
    overflow-y: auto;
    background: var(--glass-bg-strong);
    backdrop-filter: var(--glass-blur-medium);
    -webkit-backdrop-filter: var(--glass-blur-medium);
    border: 1px solid rgba(31, 38, 135, 0.15);
    border-radius: var(--prompt-border-radius);
    box-shadow: var(--glass-shadow);
    z-index: 100;
}

.tikz-app .history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-8);
    border-bottom: 1px solid rgba(31, 38, 135, 0.1);
}

.tikz-app .history-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-header-glass);
    margin: 0;
}

.tikz-app .history-close-btn {
    font-size: 1.5rem;
    color: rgba(45, 52, 54, 0.5);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: var(--prompt-transition);
}

.tikz-app .history-close-btn:hover {
    color: var(--text-on-glass);
}

.tikz-app .history-list {
    padding: var(--spacing-4);
}

.tikz-app .history-empty {
    padding: var(--spacing-16);
    text-align: center;
    color: rgba(45, 52, 54, 0.5);
}

/* ============================================
   HISTORY ITEMS (populated by JS)
   ============================================ */

.tikz-app .history-item {
    padding: var(--spacing-8);
    margin-bottom: var(--spacing-4);
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(31, 38, 135, 0.1);
    border-radius: 8px;
    transition: var(--prompt-transition);
}

.tikz-app .history-item:hover {
    background: rgba(255, 255, 255, 0.9);
    border-color: var(--primary-color);
}

.tikz-app .history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-4);
}

.tikz-app .history-item-time {
    font-size: 0.875rem;
    color: rgba(45, 52, 54, 0.7);
}

.tikz-app .history-item-type {
    padding: var(--spacing-1) var(--spacing-4);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: white;
    background: var(--primary-color);
    border-radius: 8px;
}

.tikz-app .history-item-prompt {
    font-size: 0.9375rem;
    color: var(--text-on-glass);
    margin: 0 0 var(--spacing-6) 0;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tikz-app .history-item-use-btn {
    width: 100%;
    padding: var(--spacing-4) var(--spacing-8);
    font-size: 0.9375rem;
    font-weight: 500;
    color: white;
    background: var(--primary-color);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--prompt-transition);
}

.tikz-app .history-item-use-btn:hover {
    background: #1565c0;
}

.tikz-app .history-empty {
    padding: var(--spacing-16);
    text-align: center;
    color: rgba(45, 52, 54, 0.5);
    font-style: italic;
}

/* History items populated by JavaScript */

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

@media (max-width: 768px) {
    .tikz-app .prompt-to-tikz-section {
        padding: var(--spacing-8);
    }

    .tikz-app .prompt-to-tikz-section .index-title {
        font-size: 1.5rem;
    }

    .tikz-app .prompt-textarea {
        font-size: 0.9375rem;
    }

    .tikz-app .generated-code-container .generated-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .tikz-app .generated-code-container .generated-actions {
        flex-direction: column;
        width: 100%;
    }

    .tikz-app .generated-code-container .action-btn {
        width: 100%;
        justify-content: center;
    }

    .tikz-app .history-dropdown {
        max-width: 100%;
    }

    .tikz-app .copy-success-toast {
        bottom: var(--spacing-8);
        right: var(--spacing-8);
        left: var(--spacing-8);
        text-align: center;
    }
}

/* ============================================
   FOCUS STATES & ACCESSIBILITY
   ============================================ */

.tikz-app .prompt-textarea:focus-visible {
    outline: 2px solid var(--prompt-focus);
    outline-offset: 2px;
}

.tikz-app .generate-btn:focus-visible,
.tikz-app .action-btn:focus-visible,
.tikz-app .example-btn:focus-visible,
.tikz-app .show-examples-btn:focus-visible {
    outline: 2px solid var(--prompt-focus);
    outline-offset: 2px;
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .tikz-app .prompt-to-tikz-section {
        page-break-inside: avoid;
    }

    .tikz-app .generation-loading,
    .tikz-app .generation-error,
    .tikz-app .prompt-actions,
    .tikz-app .generated-actions,
    .tikz-app .generation-history {
        display: none;
    }
}