/* =====================================================================
   AI ASSISTANT COMPONENTS — Base styles (hardcoded fallback for no-theme)
   Theme-aware versions in css/themes/<theme>/ai.css use var(--*) refs.
   ===================================================================== */

/* ---- Floating Widget (shared by Form Helper + Table Helper) ---- */
.ai-floating-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9990;
    font-family: inherit;
}

.ai-resizable {
    resize: both;
    overflow: auto;
}

.ai-resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 16px;
    height: 16px;
    cursor: nwse-resize;
}

/* ---- Console Layout ---- */
.ai-console-layout {
    display: flex;
    height: calc(100vh - 60px);
    font-family: inherit;
}

.ai-console-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #fff;
}

.ai-console-sidebar {
    width: 320px;
    border-left: 1px solid #dee2e6;
    background-color: #f8f9fa;
    overflow-y: auto;
}

/* ---- Chat Messages ---- */
.ai-msg {
    padding: 10px 14px;
    margin: 4px 8px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.5;
    word-break: break-word;
}

.ai-msg-user {
    background-color: #e3f2fd;
    color: #212529;
    align-self: flex-end;
    margin-left: 40px;
}

.ai-msg-agent {
    background-color: #f8f9fa;
    color: #212529;
    align-self: flex-start;
    margin-right: 40px;
}

.ai-msg-system {
    background-color: #fff3cd;
    color: #856404;
    font-size: 12px;
    text-align: center;
    margin: 4px 40px;
}

.ai-msg-loading {
    background-color: #f8f9fa;
    color: #6c757d;
    font-style: italic;
}

/* ---- Chat Body & Input ---- */
.ai-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    display: flex;
    flex-direction: column;
}

.ai-input-area {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #dee2e6;
    background-color: #fff;
}

.ai-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ced4da;
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
}

.ai-input:focus {
    border-color: #86b7fe;
    box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.15);
}

.ai-send-btn {
    padding: 8px 18px;
    background-color: #2196F3;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
}

.ai-send-btn:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

/* ---- Chips (navigation / action pills) ---- */
.ai-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 8px;
}

.ai-chip {
    padding: 4px 12px;
    background-color: #e9ecef;
    color: #495057;
    border: 1px solid #dee2e6;
    border-radius: 16px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.15s, color 0.15s;
}

.ai-chip:hover {
    background-color: #dee2e6;
}

.ai-chip.ai-chip-active {
    background-color: #2196F3;
    color: #fff;
    border-color: #2196F3;
}

.ai-nav-chip {
    display: inline-block;
    padding: 6px 14px;
    background-color: #f8f9fa;
    color: #495057;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    text-decoration: none;
}

.ai-nav-chip:hover {
    background-color: #e9ecef;
}

/* ---- Header ---- */
.ai-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background-color: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}

.ai-header-title {
    font-size: 15px;
    font-weight: 600;
    color: #212529;
}

.ai-header-subtitle {
    font-size: 11px;
    color: #6c757d;
}

.ai-header-actions {
    display: flex;
    gap: 6px;
}

.ai-header-btn {
    padding: 4px 10px;
    background-color: transparent;
    color: #495057;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.ai-header-btn:hover {
    background-color: #e9ecef;
}

/* ---- AI Buttons ---- */
.ai-btn-apply {
    padding: 6px 14px;
    background-color: #198754;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
}

.ai-btn-apply:hover {
    background-color: #157347;
}

.ai-btn-continue {
    padding: 6px 14px;
    background-color: #2196F3;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.ai-btn-reload {
    padding: 6px 14px;
    background-color: #6c757d;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

/* ---- Plan Steps ---- */
.ai-plan {
    margin: 8px;
    padding: 10px;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
}

.ai-plan-header {
    margin-bottom: 6px;
}

.ai-plan-title {
    font-size: 13px;
    font-weight: 600;
    color: #212529;
}

.ai-plan-steps {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ai-plan-step {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    padding: 2px 0;
}

.ai-plan-visible {
    display: block;
}

/* ---- Action Badges ---- */
.ai-action-badge-comment {
    background-color: #e3f2fd;
    color: #1565c0;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
}

.ai-action-badge-task {
    background-color: #fff3e0;
    color: #e65100;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
}

.ai-action-badge-update {
    background-color: #e8f5e9;
    color: #2e7d32;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
}

.ai-action-badge-unknown {
    background-color: #f5f5f5;
    color: #616161;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
}

/* ---- Spinner ---- */
.ai-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #e9ecef;
    border-top-color: #2196F3;
    border-radius: 50%;
    animation: ai-spin 0.8s linear infinite;
}

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

/* ---- Queue Empty State ---- */
.ai-queue-empty {
    text-align: center;
    padding: 30px;
    color: #6c757d;
    font-size: 13px;
}

/* ---- Filter Confirm Dialog ---- */
.ai-filter-confirm {
    padding: 10px;
    color: #666;
    font-size: 14px;
}

/* ---- Close Button ---- */
.ai-close-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: #6c757d;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.ai-close-btn:hover {
    background-color: #e9ecef;
    color: #212529;
}

/* ---- Companion Dialog ---- */
.ai-companion-dialog {
    position: fixed;
    bottom: 80px;
    right: 20px;
    width: 380px;
    max-height: 500px;
    background-color: #fff;
    border: 1px solid #dee2e6;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
    z-index: 9990;
    display: flex;
    flex-direction: column;
    font-family: inherit;
}

.ai-companion-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid #dee2e6;
    background-color: #f8f9fa;
    border-radius: 12px 12px 0 0;
}

.ai-companion-title {
    font-size: 14px;
    font-weight: 600;
    color: #212529;
}

.ai-companion-messages {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.ai-companion-textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ced4da;
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    resize: none;
    outline: none;
    min-height: 40px;
}

.ai-companion-textarea:focus {
    border-color: #86b7fe;
}

.ai-companion-send {
    padding: 6px 16px;
    background-color: #2196F3;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
}

/* ---- Step Status Colors (used by plan steps + debug) ---- */
.ai-status-done {
    color: #28a745;
}

.ai-status-pending {
    color: #6c757d;
}

.ai-status-skipped {
    color: #ffc107;
}

.ai-status-error {
    color: #e74c3c;
}

/* ---- Suggestion Cards (Form Helper) ---- */
.ai-suggestion-card {
    background-color: #f0f2ff;
    border: 1px solid #d0d5f7;
    border-radius: 8px;
    padding: 10px;
    margin: 4px 0;
}

.ai-suggestion-header {
    font-size: 13px;
    font-weight: 600;
    color: #667eea;
    margin-bottom: 6px;
}

.ai-suggestion-value {
    color: #555;
}

.ai-suggestion-confidence-high {
    color: #27ae60;
}

.ai-suggestion-confidence-medium {
    color: #f39c12;
}

.ai-suggestion-confidence-low {
    color: #95a5a6;
}

.ai-suggestion-accept {
    background-color: #27ae60;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 4px 12px;
    cursor: pointer;
    font-size: 12px;
}

.ai-suggestion-reject {
    background-color: #e74c3c;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 4px 12px;
    cursor: pointer;
    font-size: 12px;
}

.ai-suggestion-apply-all {
    background-color: #27ae60;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 6px 14px;
    cursor: pointer;
    font-size: 12px;
}

/* ---- AI Helper Button (Table3 gradient button) ---- */
.ai-helper-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
}

/* ---- Debug Messages (from processAi.php) ---- */
.ai-debug-proxy {
    color: #2563eb;
    background-color: #fff;
}

.ai-debug-raw {
    color: #7c3aed;
    background-color: #fff;
}

.ai-debug-extract {
    color: #7c3aed;
    background-color: #fff;
}

.ai-debug-cloud {
    color: #059669;
    background-color: #fff;
}

.ai-debug-db {
    color: #d97706;
    background-color: #fff;
}

/* Disabled send button state */
.ai-send-disabled {
    background-color: #ccc !important;
    cursor: not-allowed;
}
