/* modules/addons/cm_ai_support/assets/css/cm_ai.css */
/* CM AI Support Assistant — CloudMinister Technologies */

/* ═══════════════════════════════════════════════════════════════
   Layout
═══════════════════════════════════════════════════════════════ */

.cm-ai-layout {
    margin-top: 0;
}

.cm-ai-sidebar-col {
    padding-right: 0;
}

.cm-ai-main-col {
    padding-left: 20px;
}

.cm-ai-sidebar {
    border-radius: 6px;
    overflow: hidden;
    position: sticky;
    top: 20px;
}

.cm-ai-sidebar .list-group-item {
    border-left: 3px solid transparent;
    font-size: 0.875rem;
    padding: 10px 14px;
    transition: background 0.15s, border-color 0.15s;
}

.cm-ai-sidebar .list-group-item.active {
    background-color: #4e73df;
    border-left-color: #2e59d9;
    border-color: transparent;
}

.cm-ai-sidebar .list-group-item:not(.active):hover {
    background-color: #f8f9fc;
    border-left-color: #4e73df;
}

/* ═══════════════════════════════════════════════════════════════
   Stat cards (dashboard)
═══════════════════════════════════════════════════════════════ */

.cm-ai-stat-card {
    border: none;
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.cm-ai-stat-card.border-left-primary  { border-left: 4px solid #4e73df !important; }
.cm-ai-stat-card.border-left-success  { border-left: 4px solid #1cc88a !important; }
.cm-ai-stat-card.border-left-info     { border-left: 4px solid #36b9cc !important; }
.cm-ai-stat-card.border-left-warning  { border-left: 4px solid #f6c23e !important; }
.cm-ai-stat-card.border-left-danger   { border-left: 4px solid #e74a3b !important; }

.cm-ai-stat-card .card-body {
    padding: 14px 18px;
}

.text-xs {
    font-size: 0.7rem;
    letter-spacing: 0.05em;
}

/* ═══════════════════════════════════════════════════════════════
   Provider logos / badges
═══════════════════════════════════════════════════════════════ */

.cm-ai-provider-logo {
    display: inline-block;
    width: 20px;
    height: 20px;
    border-radius: 3px;
    margin-right: 6px;
    vertical-align: middle;
    font-size: 0;
}

.cm-ai-logo-openai     { background: #10a37f; }
.cm-ai-logo-anthropic  { background: #c96442; }
.cm-ai-logo-gemini     { background: #4285f4; }
.cm-ai-logo-groq       { background: #f55036; }
.cm-ai-logo-mistral    { background: #ff7000; }
.cm-ai-logo-cohere     { background: #39a7aa; }
.cm-ai-logo-ollama     { background: #333333; }
.cm-ai-logo-cloudflare { background: #f38020; }

/* ═══════════════════════════════════════════════════════════════
   Progress bars
═══════════════════════════════════════════════════════════════ */

.cm-ai-progress-sm {
    height: 6px;
    border-radius: 3px;
    margin-bottom: 2px;
}

/* ═══════════════════════════════════════════════════════════════
   Response mode cards (settings)
═══════════════════════════════════════════════════════════════ */

.cm-ai-mode-card {
    cursor: pointer;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    transition: border-color 0.2s, box-shadow 0.2s;
    user-select: none;
}

.cm-ai-mode-card:hover {
    border-color: #4e73df;
    box-shadow: 0 2px 8px rgba(78,115,223,0.15);
}

.cm-ai-mode-card.selected {
    border-color: #4e73df;
    background-color: #f0f4ff;
    box-shadow: 0 2px 8px rgba(78,115,223,0.2);
}

/* ═══════════════════════════════════════════════════════════════
   AI Ticket Toolbar (injected into ticket reply page)
═══════════════════════════════════════════════════════════════ */

#cm-ai-toolbar {
    background: #f8f9fc;
    border: 1px solid #d1d3e2;
    border-radius: 6px;
    padding: 10px 14px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

#cm-ai-toolbar .cm-ai-toolbar-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: #5a5c69;
    margin-right: 6px;
    white-space: nowrap;
}

#cm-ai-toolbar .btn {
    font-size: 0.78rem;
    padding: 4px 10px;
}

#cm-ai-generate-btn {
    background: linear-gradient(135deg, #4e73df, #224abe);
    border: none;
    color: #fff;
    font-weight: 600;
}

#cm-ai-generate-btn:hover {
    background: linear-gradient(135deg, #224abe, #1a3a96);
}

#cm-ai-enhance-dropdown .dropdown-item {
    font-size: 0.82rem;
    padding: 6px 14px;
}

/* Provider + model selector row */
#cm-ai-provider-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #dee2e6;
    width: 100%;
}

#cm-ai-provider-row select {
    font-size: 0.78rem;
    padding: 3px 8px;
    height: auto;
}

/* AI response panel (suggest mode) */
#cm-ai-response-panel {
    background: #fff;
    border: 1px solid #d1d3e2;
    border-left: 4px solid #4e73df;
    border-radius: 6px;
    padding: 14px 16px;
    margin-top: 12px;
    display: none;
    position: relative;
}

#cm-ai-response-panel.visible {
    display: block;
}

#cm-ai-response-panel .cm-ai-response-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

#cm-ai-response-panel .cm-ai-response-header span {
    font-size: 0.78rem;
    font-weight: 600;
    color: #4e73df;
}

#cm-ai-response-text {
    white-space: pre-wrap;
    font-size: 0.875rem;
    line-height: 1.6;
    color: #3a3b45;
    max-height: 300px;
    overflow-y: auto;
}

#cm-ai-apply-btn {
    margin-top: 10px;
}

/* Loading spinner overlay */
.cm-ai-loading {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(78,115,223,0.3);
    border-top-color: #4e73df;
    border-radius: 50%;
    animation: cm-ai-spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

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

/* Custom prompt input */
#cm-ai-custom-prompt-row {
    width: 100%;
    margin-top: 8px;
    display: none;
}

#cm-ai-custom-prompt-row.visible {
    display: flex;
    gap: 6px;
}

#cm-ai-custom-prompt {
    font-size: 0.82rem;
}

/* ═══════════════════════════════════════════════════════════════
   Triage badges
═══════════════════════════════════════════════════════════════ */

.cm-ai-sentiment-positive   { color: #1cc88a; font-weight: 600; }
.cm-ai-sentiment-neutral    { color: #858796; }
.cm-ai-sentiment-frustrated { color: #f6c23e; font-weight: 600; }
.cm-ai-sentiment-angry      { color: #e74a3b; font-weight: 700; }

.cm-ai-urgency-critical { background: #e74a3b; color: #fff; }
.cm-ai-urgency-high     { background: #f6c23e; color: #fff; }
.cm-ai-urgency-medium   { background: #36b9cc; color: #fff; }
.cm-ai-urgency-low      { background: #1cc88a; color: #fff; }

.cm-ai-urgency-badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* ═══════════════════════════════════════════════════════════════
   Queue / review cards
═══════════════════════════════════════════════════════════════ */

.cm-ai-queue-card {
    border-left: 4px solid #f6c23e;
    margin-bottom: 16px;
}

.cm-ai-queue-card .cm-ai-response-preview {
    background: #f8f9fc;
    border-radius: 4px;
    padding: 10px 14px;
    font-size: 0.85rem;
    max-height: 120px;
    overflow-y: auto;
    margin: 10px 0;
    white-space: pre-wrap;
}

/* ═══════════════════════════════════════════════════════════════
   Analytics charts placeholders
═══════════════════════════════════════════════════════════════ */

.cm-ai-chart-placeholder {
    background: #f8f9fc;
    border: 1px dashed #d1d3e2;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    min-height: 200px;
    color: #b7b9cc;
    font-size: 0.9rem;
}

/* ═══════════════════════════════════════════════════════════════
   General utilities
═══════════════════════════════════════════════════════════════ */

.cm-ai-card-table table {
    margin-bottom: 0;
}

.cm-ai-kbd {
    display: inline-block;
    padding: 1px 5px;
    background: #eaecf4;
    border: 1px solid #c5c7d4;
    border-radius: 3px;
    font-size: 0.75rem;
    font-family: monospace;
}

/* Ensure cards don't overflow on small screens */
@media (max-width: 768px) {
    .cm-ai-sidebar-col {
        display: none;
    }
    .cm-ai-main-col {
        padding-left: 15px;
    }
    #cm-ai-toolbar {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* ============================================================
   Phase 11 — Client Area Widgets
   ============================================================ */

/* KB Suggestion Panel (ticket submit page) */
.cmai-kb-panel {
    border: 1px solid #dee2e6;
    border-radius: 4px;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,.1);
    margin-top: 4px;
    max-height: 280px;
    overflow-y: auto;
}

.cmai-kb-header {
    padding: 8px 12px;
    font-size: 11px;
    font-weight: bold;
    color: #6c757d;
    border-bottom: 1px solid #eee;
    background: #f8f9fa;
    border-radius: 4px 4px 0 0;
}

.cmai-kb-item {
    display: block;
    padding: 8px 12px;
    text-decoration: none;
    color: #212529;
    border-bottom: 1px solid #f8f9fa;
    transition: background .15s;
}

.cmai-kb-item:hover {
    background: #f8f9fa;
    color: #212529;
    text-decoration: none;
}

.cmai-kb-item-title {
    font-size: 13px;
    font-weight: 500;
}

.cmai-kb-item-excerpt {
    font-size: 11px;
    color: #6c757d;
    margin-top: 2px;
}

/* Chat Widget — floating bubble + panel */
.cmai-chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: #4e73df;
    color: #fff;
    border: none;
    box-shadow: 0 4px 12px rgba(78,115,223,.5);
    cursor: pointer;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: transform .2s, box-shadow .2s;
}

.cmai-chat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 18px rgba(78,115,223,.6);
}

.cmai-chat-panel {
    position: fixed;
    bottom: 88px;
    right: 24px;
    width: 340px;
    max-height: 480px;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 8px 32px rgba(0,0,0,.18);
    z-index: 9998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity .2s, transform .2s;
}

.cmai-chat-panel.cmai-hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(16px);
}

.cmai-chat-header {
    background: #4e73df;
    color: #fff;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.cmai-chat-close {
    background: none;
    border: none;
    color: rgba(255,255,255,.8);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 0;
}

.cmai-chat-close:hover {
    color: #fff;
}

.cmai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.cmai-msg {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.4;
}

.cmai-msg-bot {
    background: #f1f3f4;
    color: #212529;
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}

.cmai-msg-user {
    background: #4e73df;
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

.cmai-chat-kb-results {
    padding: 0 4px;
}

.cmai-chat-kb-link {
    display: block;
    padding: 6px 8px;
    font-size: 12px;
    color: #4e73df;
    text-decoration: none;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    margin-bottom: 4px;
    transition: background .15s;
}

.cmai-chat-kb-link:hover {
    background: #f1f5ff;
    text-decoration: none;
}

.cmai-chat-input-row {
    display: flex;
    border-top: 1px solid #dee2e6;
    padding: 8px;
    gap: 6px;
    flex-shrink: 0;
}

.cmai-chat-input {
    flex: 1;
    border: 1px solid #dee2e6;
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 13px;
    outline: none;
}

.cmai-chat-input:focus {
    border-color: #4e73df;
}

.cmai-chat-send {
    background: #4e73df;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 34px;
    height: 34px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.cmai-chat-send:hover {
    background: #3a5ec8;
}

/* Satisfaction Rating Widget */
.cmai-rating-widget {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 12px 16px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.cmai-rating-label {
    font-size: 13px;
    font-weight: 600;
    color: #495057;
    flex-shrink: 0;
}

.cmai-rating-stars {
    display: flex;
    gap: 4px;
}

.cmai-star {
    font-size: 22px;
    cursor: pointer;
    color: #dee2e6;
    transition: color .1s;
    line-height: 1;
}

.cmai-star.active,
.cmai-star.hover {
    color: #f6c23e;
}

.cmai-rating-thanks {
    font-size: 12px;
    color: #1cc88a;
    font-weight: 600;
}

/* KB Search Page (client area) */
.cmai-kb-search-page {
    padding: 24px 0;
}

.cmai-kb-result-card {
    background: #fff;
    border: 1px solid #e3e6f0;
    border-radius: 6px;
    padding: 16px;
    margin-bottom: 12px;
    transition: box-shadow .15s;
}

.cmai-kb-result-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,.1);
}

.cmai-kb-result-title {
    font-size: 15px;
    font-weight: 600;
    color: #4e73df;
    text-decoration: none;
}

.cmai-kb-result-title:hover {
    text-decoration: underline;
}

.cmai-kb-result-excerpt {
    font-size: 13px;
    color: #6c757d;
    margin-top: 4px;
}

@media (max-width: 576px) {
    .cmai-chat-panel {
        width: calc(100vw - 32px);
        right: 16px;
        bottom: 80px;
    }
    .cmai-chat-bubble {
        right: 16px;
        bottom: 16px;
    }
}

/* ============================================================
   Phase 12 — Polish & Harden
   ============================================================ */

/* Toolbar buttons: clear disabled state when AI is working */
#cm-ai-toolbar .btn:disabled,
#cm-ai-toolbar .btn[disabled] {
    opacity: .5;
    pointer-events: none;
    cursor: not-allowed;
}

/* Smooth colour transition on analytics stat-card figures */
.border-left-primary .h5,
.border-left-success .h5,
.border-left-info .h5,
.border-left-warning .h5,
.border-left-danger .h5 {
    transition: color .25s ease;
}

/* Log table row hover */
#logs-table tbody tr:hover td,
.table-hover tbody tr:hover td {
    background-color: rgba(78, 115, 223, .04);
}

/* Pulse animation for critical urgency badge */
.badge-urgency-critical {
    animation: cmai-pulse 2s ease-in-out infinite;
}

@keyframes cmai-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(220, 53, 69, .55); }
    70%  { box-shadow: 0 0 0 7px rgba(220, 53, 69, 0); }
    100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0); }
}

/* Queue card entering viewport */
.cm-ai-queue-card {
    transition: box-shadow .2s ease, transform .2s ease;
}

.cm-ai-queue-card:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, .1) !important;
    transform: translateY(-1px);
}

/* Improved focus ring on admin forms */
.form-control:focus {
    border-color: #4e73df;
    box-shadow: 0 0 0 .15rem rgba(78, 115, 223, .25);
}

/* Inline success/error flash messages */
.cm-ai-flash {
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 13px;
    margin-top: 6px;
    animation: cmai-fadein .2s ease;
}

@keyframes cmai-fadein {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ─── Floating AI FAB (fallback when form injection fails) ─── */

#cm-ai-float-btn {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 99999;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4e73df 0%, #224abe 100%);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    box-shadow: 0 4px 20px rgba(78, 115, 223, 0.55);
    transition: transform .2s cubic-bezier(.34,1.56,.64,1), box-shadow .2s;
    user-select: none;
    border: 3px solid rgba(255,255,255,0.2);
}

#cm-ai-float-btn:hover {
    transform: scale(1.12);
    box-shadow: 0 6px 28px rgba(78, 115, 223, 0.7);
}

#cm-ai-float-btn:active {
    transform: scale(0.94);
}

/* Tooltip */
#cm-ai-float-btn::before {
    content: 'AI Assistant';
    position: absolute;
    right: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%) translateX(4px);
    background: rgba(33, 35, 50, 0.9);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.03em;
    padding: 5px 10px;
    border-radius: 5px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s, transform .18s;
}

#cm-ai-float-btn:hover::before {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

/* Pulse ring */
#cm-ai-float-btn::after {
    content: '';
    position: absolute;
    inset: -5px;
    border-radius: 50%;
    border: 2px solid rgba(78, 115, 223, 0.45);
    animation: cmai-fab-ring 2.4s ease-out infinite;
    pointer-events: none;
}

@keyframes cmai-fab-ring {
    0%   { opacity: 1; transform: scale(1);   }
    70%  { opacity: 0; transform: scale(1.4); }
    100% { opacity: 0; transform: scale(1.4); }
}

/* ─── Floating AI slide-up panel ─── */

#cm-ai-float-panel {
    position: fixed;
    bottom: 96px;
    right: 20px;
    width: 560px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 12px 48px rgba(0,0,0,0.2), 0 2px 8px rgba(0,0,0,0.08);
    z-index: 99998;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: opacity .22s ease, transform .22s cubic-bezier(.34,1.56,.64,1);
}

#cm-ai-float-panel.cmai-panel-hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(16px) scale(0.96);
}

#cm-ai-float-panel.cmai-panel-visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

#cm-ai-float-panel-header {
    background: linear-gradient(135deg, #4e73df, #224abe);
    color: #fff;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

#cm-ai-float-panel-header .cmai-panel-title {
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: 0.02em;
}

#cm-ai-float-panel-header .cmai-panel-close {
    background: none;
    border: none;
    color: rgba(255,255,255,0.75);
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    padding: 4px 7px;
    border-radius: 4px;
    transition: background .15s, color .15s;
}

#cm-ai-float-panel-header .cmai-panel-close:hover {
    background: rgba(255,255,255,0.18);
    color: #fff;
}

#cm-ai-float-panel-body {
    overflow-y: auto;
    padding: 14px 16px;
    flex: 1;
}

#cm-ai-float-panel #cm-ai-toolbar {
    margin-bottom: 0;
    border-radius: 6px;
}

/* Print styles — hide UI chrome when printing analytics */
@media print {
    .cm-ai-sidebar,
    #cm-ai-toolbar,
    .btn,
    .card-footer,
    .pagination {
        display: none !important;
    }
    .card {
        box-shadow: none !important;
        border: 1px solid #dee2e6 !important;
        break-inside: avoid;
    }
    canvas {
        max-width: 100% !important;
    }
}
