/* =====================================================================
   AI ASSISTANT COMPONENTS — Base styles (hardcoded fallback for no-theme)
   ===================================================================== */

/* ---- Floating Widget (shared by Form Helper + Table Helper) ---- */
.ai-floating-widget {
    position: fixed;
    bottom: 60px;
    right: 20px;
    z-index: 9990;
    width: 420px;
    max-width: calc(100vw - 40px);
    min-width: 320px;
    height: 600px;
    min-height: 320px;
    max-height: calc(100vh - 80px);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
    font-family: inherit;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box;
    transition: transform 0.3s ease, opacity 0.3s ease;
    transform: translateY(20px);
    opacity: 0;
}
.ai-floating-widget.ai-open {
    transform: translateY(0px);
    opacity: 1;
}
.ai-floating-widget.ai-resizable {
    overflow: visible;
}
.ai-resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 16px;
    height: 16px;
    cursor: nwse-resize;
}

/* ---- Header ---- */
.ai-header {
    background: #495057;
    color: #fff;
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: grab;
    border-radius: 12px 12px 0 0;
    flex-shrink: 0;
    user-select: none;
}
.ai-header-title {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
}
.ai-header-subtitle {
    font-size: 11px;
    opacity: 0.75;
    margin-top: 2px;
    font-weight: 400;
}
.ai-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.ai-header-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
    padding: 0;
    line-height: 1;
}
.ai-header-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}
.ai-header-btn.ai-close-btn {
    font-size: 20px;
}

/* ---- Console Layout ---- */
.ai-console-layout {
    display: flex;
    height: calc(100vh - 60px);
    font-family: inherit;
}
.ai-console-layout .ai-header {
    border-radius: 8px 8px 0 0;
}
.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;
}
.ai-console-window {
    position: fixed;
    z-index: 9980;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.ai-console-iframe {
    width: 100%;
    flex: 1;
    border: none;
}

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

/* ---- Chat Messages ---- */
.ai-msg {
    padding: 10px 14px;
    border-radius: 8px;
    max-width: 85%;
    line-height: 1.5;
    font-size: 13px;
    overflow-wrap: break-word;
    word-break: break-word;
}
.ai-msg a { color: #667eea; font-weight: 500; }
.ai-msg strong { font-weight: 600; }
.ai-msg-user {
    background: #1976D2;
    color: #fff;
    border-radius: 12px 12px 4px 12px;
    align-self: flex-end;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.25);
    max-width: 80%;
}
.ai-msg-agent {
    background: #f8f9fa;
    border-left: 4px solid #667eea;
    align-self: flex-start;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.ai-msg-system {
    background: #fff3cd;
    border-left: 4px solid #ffc107;
    align-self: center;
    font-size: 13px;
    color: #212529;
    max-width: 90%;
}
.ai-msg-error {
    background: #f8d7da;
    border-left: 4px solid #dc3545;
    align-self: flex-start;
    color: #721c24;
    max-width: 90%;
}
.ai-msg-loading {
    background: #fff;
    border-left: 4px solid #ffc107;
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 10px;
    font-style: italic;
    color: #666;
}

/* ---- Input Area ---- */
.ai-input-area {
    padding: 10px 12px;
    background: #fff;
    border-top: 1px solid #dee2e6;
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}
.ai-input {
    flex: 1;
    border: 1px solid #ced4da;
    border-radius: 8px;
    padding: 10px 12px;
    resize: none;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s ease;
    min-height: 44px;
    max-height: 120px;
    line-height: 1.4;
}
.ai-input:focus {
    border-color: #667eea;
}
.ai-input::placeholder { color: #999; }
.ai-send-btn {
    background: #1976D2;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    transition: opacity 0.15s ease;
    font-size: 18px;
}
.ai-send-btn:hover { opacity: 0.9; }
.ai-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.ai-send-disabled {
    background-color: #ccc !important;
    cursor: not-allowed;
}

/* ---- Chips ---- */
.ai-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 0;
    align-self: flex-start;
    max-width: 80%;
}
.ai-chip {
    background: #f0f2ff;
    border: 1px solid #d0d5f7;
    border-radius: 16px;
    padding: 6px 14px;
    cursor: pointer;
    font-size: 12px;
    color: #667eea;
    font-weight: 500;
    transition: all 0.15s ease;
    white-space: nowrap;
    font-family: inherit;
}
.ai-chip:hover {
    background: #667eea;
    color: #fff;
    border-color: #667eea;
}
.ai-chip.ai-chip-active {
    background: #667eea;
    color: #fff;
    border-color: #667eea;
}
.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; }

/* ---- 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; }

/* ---- Step Status Colors ---- */
.ai-status-done    { color: #28a745; }
.ai-status-pending { color: #6c757d; }
.ai-status-skipped { color: #ffc107; }
.ai-status-error   { color: #e74c3c; }

/* ---- 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 {
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #667eea;
    border-radius: 50%;
    animation: ai-spin 1s linear infinite;
}
@keyframes ai-spin {
    to { transform: rotate(360deg); }
}

/* ---- Queue Empty / Filter Confirm ---- */
.ai-queue-empty {
    text-align: center;
    padding: 30px;
    color: #6c757d;
    font-size: 13px;
}
.ai-filter-confirm {
    padding: 10px;
    color: #666;
    font-size: 14px;
}

/* ---- Close Button (standalone, not in header) ---- */
.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;
}

/* Override: close button inside ai-header should not be absolute */
.ai-header .ai-close-btn {
    position: static;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    font-size: 20px;
}
.ai-header .ai-close-btn:hover {
    background: rgba(255, 255, 255, 0.35);
    color: #fff;
}

/* ---- 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: #495057;
    color: #fff;
    border-radius: 12px 12px 0 0;
}
.ai-companion-header .ai-close-btn {
    position: static;
    background: rgba(255,255,255,0.15);
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 18px;
}
.ai-companion-header .ai-close-btn:hover {
    background: rgba(255,255,255,0.3);
    color: #fff;
}
.ai-companion-title {
    font-size: 14px;
    font-weight: 600;
}
.ai-companion-close {
    background: rgba(255,255,255,0.2);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ai-companion-close:hover { background: rgba(255,255,255,0.35); }
.ai-companion-messages {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}
.ai-companion-input-row {
    display: flex;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid #dee2e6;
}
.ai-companion-textarea {
    flex: 1;
    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: #667eea; }
.ai-companion-send {
    padding: 6px 16px;
    background: #1976D2;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
}
.ai-companion-send:disabled { opacity: 0.4; cursor: not-allowed; }
.ai-companion-send:hover { opacity: 0.9; }

/* ---- 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) ---- */
.ai-helper-btn {
    background: #1976D2;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
}

/* ---- Debug Messages ---- */
.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; }
