/* static/css/ai_dashboard_styles.css */

/* --- Global Box Sizing (Good practice, your header file also includes this) --- */
*,
*::before,
*::after {
    box-sizing: border-box;
}

:root {
    /* --- Dashboard Specific Variables (Namespaced) --- */
    --dash-primary-bg: #1a1d24;
    --dash-secondary-bg: #252a33;
    --dash-tertiary-bg: #303641;
    --dash-accent-color: #00aaff;
    --dash-accent-hover: #0077cc;
    --dash-text-color: #f0f0f5;
    --dash-text-muted: #b0b8c0;
    --dash-border-color: #455060;
    --dash-success-color: #28a745;
    --dash-warning-color: #ffc107;
    --dash-danger-color: #dc3545;
    --dash-chart-grid-color: rgba(240, 240, 245, 0.12);
    --dash-font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --accent-purple: #8B5CF6;
    --ai-chat-user-bg: #692e9a; 
    --ai-chat-user-text: #ffffff;
    --ai-chat-ai-bg: #1d4892; 
   
    --ai-chat-ai-text: var(--dash-text-color); /* Updated to use dash prefix */
    --ai-chat-history-bg: #101f38;
    --ai-chat-input-area-bg: #101f38; /* #1e293b - for the input bar */
    --ai-chat-input-field-bg: #101f38; /* Input field itself */

    /* --- Height of the external sticky header - USER MUST ADJUST THIS VALUE --- */
    --external-header-height: 70px; /* Example: Adjust based on your header's actual height */

    /* Original non-dark chart colors (can be used directly or by JS) */
    --chart-color-1: #5dade2;
    --chart-color-2: #58d68d;
    --chart-color-3: #f7dc6f;
    --chart-color-4: #ec7063;
    --chart-color-5: #af7ac5;
    --chart-color-6: #48c9b0;
    --chart-color-7: #f5b041;
    --chart-color-8: #aab7b8;
    --chart-color-9: #f8c471;
    --chart-color-10: #76d7c4;
}

body {
    /* The external header file likely styles the body already.
       If needed, specific overrides for the dashboard's context can be applied
       to .dashboard-container or .main-content.
       This ensures global settings from the header are respected,
       while dashboard-specific overrides are applied where necessary. */
    font-family: var(--dash-font-family); /* Fallback if header doesn't set it, or to enforce */
    margin: 0; /* Usually set by header's global reset */
    padding: 0; /* Usually set by header's global reset */
    /* background-color and color are likely controlled by the external header's body style */
    line-height: 1.3; /* Usually set by header's body style */
    overflow-x: hidden; /* Good for preventing horizontal scroll issues */
}

.dashboard-container {
    display: flex;
    padding-top: var(--external-header-height); /* Push dashboard content below the external header */
    min-height: 100vh;
    background-color: var(--dash-primary-bg); /* Dashboard specific background */
    color: var(--dash-text-color); /* Dashboard specific default text color */
}

/* --- Sidebar --- */
.sidebar {
    width: 280px;
    background-color: var(--dash-secondary-bg);
    padding: 20px;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: var(--external-header-height); /* Start below external header */
    left: 0;
    height: calc(100vh - var(--external-header-height)); /* Fill remaining height */
    overflow-y: auto;
    z-index: 999; /* Below external header (1000), above main dashboard content if needed */
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background-color: var(--dash-tertiary-bg); border-radius: 3px; }

.logo { text-align: center; margin-bottom: 25px; color: var(--dash-accent-color); }
.logo i { font-size: 2.5em; margin-bottom: 5px; }
.logo h2 { margin: 0; font-size: 1.5em; letter-spacing: 1px; }

.filters h3 { font-size: 1.1em; margin-bottom: 15px; color: var(--dash-accent-color); border-bottom: 1px solid var(--dash-border-color); padding-bottom: 8px; }
.filters h3 i { margin-right: 8px; }

.filter-group { margin-bottom: 15px; }
.filter-group label { display: block; font-size: 0.9em; margin-bottom: 5px; color: var(--dash-text-muted); }

.filter-input, .filter-select {
    width: 100%; padding: 8px 10px;
    background-color: var(--dash-tertiary-bg);
    border: 1px solid var(--dash-border-color);
    border-radius: 4px; color: var(--dash-text-color); font-size: 0.9em;
}
.filter-input::placeholder { color: var(--dash-text-muted); opacity: 0.7; }
.filter-input:focus, .filter-select:focus { outline: none; border-color: var(--dash-accent-color); box-shadow: 0 0 0 2px rgba(0, 170, 255, 0.3); }

/* Select2 Dark Theme Adjustments using dashboard variables */
.select2-container--bootstrap-5 .select2-dropdown { background-color: var(--dash-secondary-bg); border-color: var(--dash-border-color); z-index: 1056; }
.select2-container--bootstrap-5 .select2-results__option { color: var(--dash-text-color); background-color: var(--dash-secondary-bg); }
.select2-container--bootstrap-5 .select2-results__option--highlighted { background-color: var(--dash-accent-color) !important; color: var(--dash-primary-bg) !important; }
.select2-container--bootstrap-5 .select2-selection { background-color: var(--dash-tertiary-bg); border: 1px solid var(--dash-border-color); color: var(--dash-text-color); }
.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__choice { background-color: var(--dash-accent-color); border: none; color: var(--dash-primary-bg); padding: 3px 6px; font-weight: 500; }
.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__choice__remove { color: var(--dash-primary-bg); margin-right: 5px; }
.select2-container--bootstrap-5 .select2-search--dropdown .select2-search__field { background-color: var(--dash-tertiary-bg); border-color: var(--dash-border-color); color: var(--dash-text-color); }

.btn-apply-filters, .btn-reset-filters { width: 100%; padding: 10px; margin-top: 10px; border: none; border-radius: 4px; color: #fff; font-size: 0.95em; cursor: pointer; transition: background-color 0.3s ease; }
.btn-apply-filters i, .btn-reset-filters i { margin-right: 8px; }
.btn-apply-filters { background-color: var(--dash-accent-color); }
.btn-apply-filters:hover { background-color: var(--dash-accent-hover); }
.btn-reset-filters { background-color: var(--dash-tertiary-bg); border: 1px solid var(--dash-border-color); }
.btn-reset-filters:hover { background-color: #4a5260; }

.sidebar-footer { margin-top: auto; padding-top: 20px; border-top: 1px solid var(--dash-border-color); font-size: 0.85em; color: var(--dash-text-muted); }
.sidebar-footer p { margin: 5px 0; }

/* --- Main Content (inside .dashboard-container) --- */
.main-content {
    flex-grow: 1;
    margin-left: 280px; /* Offset for the fixed .sidebar */
    padding: 20px;
    /* background-color: var(--dash-primary-bg); -- Inherited from .dashboard-container */
    color: var(--dash-text-color); /* Ensure text color for this section */
    position: relative; /* For potential z-index context if needed, though usually not */
    z-index: 1; /* Lower than sidebar and external header */
}

.header { /* This is the dashboard's own header, inside .main-content */
    margin-bottom: 25px; display: flex; justify-content: space-between; align-items: center;
    flex-wrap: wrap; gap: 15px;
    border-bottom: 1px solid var(--dash-border-color); padding-bottom: 15px;
}
.header h1 { margin: 0; font-size: 1.8em; color: var(--dash-text-color); word-break: break-word; }

.header-stats { display: flex; gap: 15px; flex-wrap: wrap; }
.stat-card { background-color: var(--dash-secondary-bg); padding: 10px 15px; border-radius: 5px; text-align: center; min-width: 150px; border: 1px solid var(--dash-border-color); }
.stat-card h4 { margin: 0 0 5px 0; font-size: 0.9em; color: var(--dash-text-muted); }
.stat-card p { margin: 0; font-size: 1.2em; font-weight: bold; color: var(--dash-accent-color); }
#ai-prediction-snippet { font-size: 0.85em; color: var(--dash-text-color); font-weight: normal; max-width: 250px; white-space: normal; line-height: 1.3; }

/* --- Grid System & Cards --- */
.grid-container { display: grid; grid-template-columns: repeat(auto-fit, minmax(350px, 1fr)); gap: 20px; }

.card {
    background-color: var(--dash-secondary-bg);
    border-radius: 6px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    display: flex; flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--dash-border-color);
}
.card:not(.chart-container):not(.map-container) { padding: 20px; } /* General cards padding */

.card-header {
    padding: 12px 20px; font-size: 1.1em; font-weight: 600;
    background-color: var(--dash-tertiary-bg);
    border-bottom: 1px solid var(--dash-border-color);
    flex-shrink: 0; color: var(--dash-text-color);
}
.card-header i { margin-right: 8px; color: var(--dash-accent-color); }

.map-container.card { min-height: 450px; height: 480px; padding: 0; }
.map-container.card > .card-header { border-top-left-radius: 6px; border-top-right-radius: 6px;}
#incident-map { width: 100%; flex-grow: 1; border-bottom-left-radius: 6px; border-bottom-right-radius: 6px; background-color: var(--dash-tertiary-bg); }

.chart-container.card { height: 380px; padding: 0; }
.chart-container.card > .card-header { padding: 12px 20px; margin: 0; border-bottom: 1px solid var(--dash-border-color); border-top-left-radius: 6px; border-top-right-radius: 6px; position: relative; z-index: 1; }
.chart-container.card > canvas { display: block; flex-grow: 1; padding: 15px; max-width: 100%; max-height: 100%; } /* box-sizing is global */

#keywordCloudContainer { width:100%; position: relative; flex-grow: 1; display: flex; align-items: center; justify-content: center; padding: 10px; min-height: 200px; } /* box-sizing is global */
#keywordCloudContainer canvas { max-width: 100%; max-height: 100%;}

.full-width { grid-column: 1 / -1; }

/* --- Incident Table --- */
.pattern-analysis-container.card { padding: 20px; }
.table-controls { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 0.9em; }
#items-per-page-select { background-color: var(--dash-tertiary-bg); color: var(--dash-text-color); border: 1px solid var(--dash-border-color); padding: 5px; border-radius: 3px; }
#incident-table-container { overflow-x: auto; max-height: 500px; }
#incident-table { width: 100%; border-collapse: collapse; }
#incident-table th, #incident-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--dash-border-color); font-size: 0.9em; }
#incident-table th { background-color: var(--dash-tertiary-bg); color: var(--dash-text-muted); cursor: pointer; }
#incident-table th i { margin-left: 5px; color: var(--dash-text-muted); }
#incident-table th:hover { color: var(--dash-text-color); }
#incident-table tbody tr:hover { background-color: #2c313a; }
#incident-table td .action-btn { padding: 5px 8px; margin-right: 5px; border: 1px solid var(--dash-accent-color); background: transparent; color: var(--dash-accent-color); border-radius: 3px; cursor: pointer; font-size: 0.85em; }
#incident-table td .action-btn:hover { background-color: var(--dash-accent-color); color: var(--dash-primary-bg); }
.report-text-cell { max-width: 300px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: help; }

/* --- Pagination --- */
.pagination { display: flex; justify-content: flex-end; align-items: center; margin-top: 15px; padding: 10px 0; }
.pagination button { background-color: var(--dash-tertiary-bg); color: var(--dash-text-color); border: 1px solid var(--dash-border-color); padding: 6px 12px; margin: 0 3px; border-radius: 3px; cursor: pointer; transition: background-color 0.2s; }
.pagination button:hover:not(:disabled) { background-color: var(--dash-accent-color); color: var(--dash-primary-bg); }
.pagination button:disabled { opacity: 0.5; cursor: not-allowed; }
.pagination #page-info { margin: 0 10px; font-size: 0.9em; }

/* --- Modal --- */
.modal { display: none; position: fixed; z-index: 1055; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0,0,0,0.7); }
.modal-content { background-color: var(--dash-secondary-bg); margin: 10% auto; padding: 25px; border: 1px solid var(--dash-border-color); border-radius: 8px; width: 60%; max-width: 700px; box-shadow: 0 5px 15px rgba(0,0,0,0.5); color: var(--dash-text-color); }
.close-button { color: var(--dash-text-muted); float: right; font-size: 28px; font-weight: bold; }
.close-button:hover, .close-button:focus { color: var(--dash-accent-color); text-decoration: none; cursor: pointer; }
#modal-incident-id { color: var(--dash-accent-color); margin-top: 0; }
#modal-body p { margin: 8px 0; line-height: 1.7; word-wrap: break-word; }
#modal-body strong { color: var(--dash-text-muted); min-width: 120px; display: inline-block; }
#modal-body div { word-wrap: break-word; overflow-wrap: break-word; }

/* --- Loading Spinner --- */
.spinner-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.7); display: flex; flex-direction: column; justify-content: center; align-items: center; z-index: 9999; color: var(--dash-text-color); }
.spinner { border: 6px solid var(--dash-tertiary-bg); border-top: 6px solid var(--dash-accent-color); border-radius: 50%; width: 50px; height: 50px; animation: spin 1s linear infinite; margin-bottom: 15px; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Responsive Adjustments */
@media (max-width: 1200px) { .grid-container { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); } }
@media (max-width: 768px) {
    .sidebar { width: 100%; height: auto; position: relative; z-index: 999; /* Still high, but relative */ top: 0; /* Reset top when not fixed */ height: auto; overflow-y: visible; }
    .main-content { margin-left: 0; padding: 15px; width: 100%; margin-top: 0; /* Reset margin-top if sidebar isn't pushing .dashboard-container down */ }
    .dashboard-container { padding-top: var(--external-header-height); /* This still applies to push below global header*/ }
    /* If the global header is ALSO hidden or becomes part of the flow on mobile, then .dashboard-container padding-top might need to be 0 */
    /* For now, assuming global header is always sticky */
    .header { flex-direction: column; align-items: flex-start; }
    .header-stats { flex-wrap: wrap; margin-top: 10px; }
    .stat-card { min-width: 120px; flex-grow: 1; }
    .grid-container { grid-template-columns: 1fr; }
    .modal-content { width: 90%; }
}

/* Dashboard specific links */
.dashboard-container a { color: var(--dash-accent-color); text-decoration: none; }
.dashboard-container a:hover { color: var(--dash-accent-hover); text-decoration: underline; }

/* Ensure Chart.js text elements use dashboard text color if not overridden by options */
/* This is mostly handled by JS now, but good to have a fallback */
.chartjs-render-monitor {
    color: var(--dash-text-color) !important; /* General chart text */
}

/* AI Chat Controls Area (Model Selector) */
.ai-chat-controls-incident {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 1rem; /* Space below controls */
    padding: 0.75rem 1rem; /* Adjusted padding */
    background-color: var(--ai-chat-input-area-bg); /* Match input area bg */
    border-radius: 8px; /* Slightly more rounded */
    flex-shrink: 0; /* Prevent shrinking */
}
.ai-chat-controls-incident label {
    font-size: 0.9em;
    color: var(--dash-text-muted); /* Updated to use dash prefix */
    font-weight: 500;
}
#ai-incident-model-selector {
    padding: 0.6rem 0.8rem;
    background-color: var(--ai-chat-input-field-bg);
    color: var(--dash-text-color); /* Updated to use dash prefix */
    border: 1px solid var(--dash-border-color); /* Updated to use dash prefix */
    border-radius: 6px; /* Consistent rounding */
    font-size: 0.9em;
    flex-grow: 1;
}

/* Base styling for all message bubbles in this specific chat */
.message-bubble-incident {
    padding: 0.8rem 1.2rem; /* Slightly more padding */
    border-radius: 18px; /* More rounded, "pill" like */
    max-width: 75%; /* Slightly narrower for better readability */
    line-height: 1.55;
    word-wrap: break-word; /* Should be word-break: break-word; */
    word-break: break-word; 
    box-shadow: 0 2px 4px rgba(0,0,0,0.15); /* Subtle shadow */
    position: relative; /* For potential future pseudo-elements like tails */
}

.user-message-bubble-incident {
    background-color: var(--ai-chat-user-bg);
    color: var(--ai-chat-user-text);
    align-self: flex-end;
    border-bottom-right-radius: 6px; /* "Tail" effect */
}

/* Enhanced AI message bubble with better spacing */
.ai-message-bubble-incident {
    background-color: var(--dash-tertiary-bg);
    color: var(--dash-text-color);
    margin-right: auto;
    padding: 8px 12px; /* Reduced from 24px 28px */
    border-left: 4px solid var(--dash-accent-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    line-height: 1.2; /* Reduced from 1.8 */
    font-size: 0.95em;
    white-space: pre-wrap;
    border-bottom-left-radius: 6px;
}


.ai-message-bubble-incident.error-incident {
    background-color: rgba(239, 68, 68, 0.1); /* Use RGB for alpha */
    border-left: 3px solid var(--dash-danger-color); /* Updated to use dash prefix */
    color: #f8d7da; /* Define --danger-text-color or use fallback */
    box-shadow: none; /* Errors might not need a shadow */
}

/* Code Styling within AI messages */
.ai-message-bubble-incident code {
    background-color: rgba(0,0,0,0.3); /* Darker, distinct from bubble */
    padding: 0.2em 0.4em;
    border-radius: 4px;
    font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
    font-size: 0.875em; /* Slightly smaller than bubble text */
    border: 1px solid rgba(255,255,255,0.1);
}

/* Enhanced code blocks */
.ai-message-bubble-incident pre {
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.6));
    padding: 8px 12px; /* Reduced from 20px 24px */
    border-radius: 8px; /* Reduced from 10px */
    overflow-x: auto;
    margin: 8px 0; /* Reduced from 24px 0 */
    border: 1px solid rgba(0, 170, 255, 0.3);
    position: relative;
}
.ai-message-bubble-incident pre::before {
    content: "CODE";
    position: absolute;
    top: 6px;
    right: 12px;
    font-size: 0.7em;
    color: var(--dash-accent-color);
    font-weight: 600;
    letter-spacing: 1px;
}

.ai-message-bubble-incident pre code {
    background-color: transparent;
    padding: 0;
    border: none;
    font-size: 1em; /* Inherit pre's font size */
}

/* Optional: Dark scrollbar for chat history (WebKit browsers) */
#ai-incident-chat-history::-webkit-scrollbar {
    width: 8px;
}
#ai-incident-chat-history::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.1); /* Transparent or very dark track */
    border-radius: 10px;
}
#ai-incident-chat-history::-webkit-scrollbar-thumb {
    background-color: var(--dash-border-color); /* Updated to use dash prefix */
    border-radius: 10px;
    border: 2px solid var(--ai-chat-history-bg); /* Creates padding around thumb */
}
#ai-incident-chat-history::-webkit-scrollbar-thumb:hover {
    background-color: var(--dash-text-muted); /* Updated to use dash prefix */
}

/* Headers with improved spacing and visual hierarchy */
.ai-response-h3 {
    background: linear-gradient(135deg, var(--dash-accent-color), var(--accent-purple));
    color: white;
    font-size: 1.3em; /* Reduced from 1.4em */
    margin: 16px -16px 16px -16px; /* Reduced from 36px -24px 28px -24px */
    padding: 6px 10px; /* Reduced from 18px 32px */
    border-radius: 6px;
    font-weight: 600;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 7px; /* Reduced from 14px */
    letter-spacing: 0.3px; /* Reduced from 0.5px */
}

.ai-response-h4 {
    color: var(--dash-accent-color);
    font-size: 1.15em; /* Reduced from 1.25em */
    margin: 12px 8px 0; /* Reduced from 32px 0 20px 0 */
    padding: 6px 0; /* Reduced from 14px 0 */
    border-bottom: 2px solid rgba(0, 170, 255, 0.3);
    font-weight: 600;
    position: relative;
    letter-spacing: 0.2px; /* Reduced from 0.3px */
}

.ai-response-h4::before {
    content: "▸";
    color: var(--accent-purple);
    margin-right: 12px;
    font-size: 1.2em;
}

/* Improved paragraph spacing */
.ai-message-bubble-incident p {
     margin: 0.75em 0; /* Reduces space between paragraphs */
    line-height: 1.2;
}

/* Enhanced tables with better spacing */
.ai-response-table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0; /* Reduced from 24px 0 */
    border-radius: 6px; /* Reduced from 10px */
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); /* Reduced from 3px 10px */
}

.ai-response-table th {
    background: linear-gradient(135deg, var(--dash-accent-color), var(--accent-purple));
    color: white;
    padding: 8px 12px; /* Reduced from 14px 18px */
    text-align: left;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.8em; /* Reduced from 0.85em */
    letter-spacing: 0.6px; /* Reduced from 0.8px */
}


.ai-response-table td {
    padding: 6px 12px; /* Reduced from 12px 18px */
    border-bottom: 1px solid var(--dash-border-color);
    background-color: var(--dash-secondary-bg);
}
.ai-response-table tr:nth-child(even) td {
    background-color: rgba(255, 255, 255, 0.02);
}

.ai-response-table tr:hover td {
    background-color: rgba(0, 170, 255, 0.1);
    transition: background-color 0.2s;
}

/* Enhanced bullet lists with better spacing and hierarchy */
.ai-message-bubble-incident ul {
    margin: 16px 0; /* Reduced from 24px 0 */
    padding-left: 0;
    list-style: none;
}

.ai-message-bubble-incident ul li {
    position: relative;
    padding-left: 8px; /* Reduced from 36px */
    margin: 2px 0; /* Reduced from 14px 0 */
    line-height: 1.2; /* Reduced from 1.8 */
}

.ai-message-bubble-incident ul li::before {
    content: "▪";
    position: absolute;
    left: 0;
    color: var(--dash-accent-color);
    font-size: 1.2em; /* Reduced from 1.4em */
    top: -1px; /* Adjusted from -2px */
}
.ai-message-bubble-incident ul ul {
    margin-top: 3px; /* Reduced from 10px */
    margin-bottom: 3px; /* Reduced from 10px */
}

.ai-message-bubble-incident ul ul li {
    padding-left: 12px; /* Reduced from 28px */
}

.ai-message-bubble-incident ul ul li::before {
    content: "◦";
    color: var(--accent-purple);
    font-size: 1.1em;
}

.analysis-summary.ai-styled {
    background: linear-gradient(135deg, rgba(0, 170, 255, 0.1), rgba(139, 92, 246, 0.1));
    padding: 8px 12px; /* Reduced from 28px 32px */
    border-radius: 8px; /* Reduced from 14px */
    margin: 8px 0; /* Reduced from 28px 0 */
    border-left: 4px solid var(--dash-accent-color); /* Reduced from 5px */
    position: relative;
    overflow: hidden;
    line-height: 1.2; /* Reduced from 1.8 */
}

.analysis-summary.ai-styled::before {
    content: "📊";
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 2.5em;
    opacity: 0.15;
}


.insight-box.ai-styled {
    background: linear-gradient(to right, rgba(93, 173, 226, 0.15), rgba(93, 173, 226, 0.05));
    padding: 16px 20px 16px 48px; /* Reduced from 22px 26px 22px 56px */
    border-radius: 10px; /* Reduced from 12px */
    margin: 8px 0; /* Reduced from 20px 0 */
    border: 1px solid #5dade2;
    border-left-width: 4px;
    position: relative;
    line-height: 1.2; /* Reduced from 1.8 */
}

.insight-box.ai-styled::before {
    content: "💡";
    position: absolute;
    left: 8px; /* Reduced from 18px */
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.5em; /* Reduced from 1.8em */
}

.prediction-card.ai-styled {
    background: linear-gradient(135deg, rgba(175, 122, 197, 0.15), rgba(175, 122, 197, 0.05));
    padding: 8px 12px; /* Reduced from 24px 28px */
    border-radius: 8px; /* Reduced from 12px */
    margin: 12px 0; /* Reduced from 20px 0 */
    border: 1px solid #af7ac5;
    box-shadow: 0 3px 8px rgba(175, 122, 197, 0.2); /* Reduced from 4px 10px */
    line-height: 1.2; /* Reduced from 1.8 */
}

.pattern-alert.ai-styled {
    background: linear-gradient(to right, rgba(253, 126, 20, 0.15), rgba(253, 126, 20, 0.05));
    padding: 8px 12px; /* Reduced from 20px 26px */
    border-radius: 10px; /* Reduced from 12px */
    margin: 16px 0; /* Reduced from 24px 0 */
    border: 1px solid #fd7e14;
    border-left-width: 4px;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.01); }
}

.stats-grid.ai-styled {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); /* Reduced from 220px */
    gap: 8px; /* Reduced from 20px */
    margin: 8px 0; /* Reduced from 28px 0 */
}

.stat-box {
    background: linear-gradient(135deg, var(--dash-secondary-bg), var(--dash-tertiary-bg));
    padding: 8px; /* Reduced from 24px */
    border-radius: 10px; /* Reduced from 12px */
    border: 1px solid var(--dash-border-color);
    text-align: center;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    overflow: hidden;
}

.stat-box:hover {
    transform: translateY(-3px); /* Reduced from -4px */
    box-shadow: 0 4px 15px rgba(0, 170, 255, 0.3); /* Reduced from 6px 20px */
}

.stat-box strong {
    display: block;
    color: var(--dash-text-muted);
    font-size: 0.85em; /* Reduced from 0.9em */
    margin-bottom: 6px; /* Reduced from 12px */
    text-transform: uppercase;
    letter-spacing: 0.6px; /* Reduced from 0.8px */
}

.stat-box .stat-value {
    font-size: 1.6em; /* Reduced from 2em */
    font-weight: 700;
    color: var(--dash-accent-color);
    margin: 6px 0; /* Reduced from 8px 0 */
}

.severity-bar {
    height: 6px; /* Reduced from 8px */
    background: linear-gradient(to right, var(--dash-accent-color), var(--accent-purple));
    margin-top: 8px; /* Reduced from 14px */
    border-radius: 3px; /* Reduced from 4px */
    transition: width 0.5s ease;
    box-shadow: 0 2px 4px rgba(0, 170, 255, 0.3); /* Reduced from 6px */
}

.trend-up, .trend-down, .trend-stable {
    display: inline-flex;
    align-items: center;
    gap: 4px; /* Reduced from 8px */
    padding: 4px 12px; /* Reduced from 6px 16px */
    border-radius: 12px; /* Reduced from 24px */
    font-size: 0.9em; /* Reduced from 0.95em */
    font-weight: 600;
    margin: 3px; /* Reduced from 4px */
}
.trend-up {
    background-color: rgba(40, 167, 69, 0.2);
    color: #28a745;
}

.trend-down {
    background-color: rgba(220, 53, 69, 0.2);
    color: #dc3545;
}

.trend-stable {
    background-color: rgba(255, 193, 7, 0.2);
    color: #ffc107;
}

/* Enhanced emphasis styles with spacing */
.ai-message-bubble-incident strong {
    color: var(--dash-accent-color);
    font-weight: 600;
    padding: 0 2px;
}

.ai-message-bubble-incident em {
    color: var(--accent-purple);
    font-style: italic;
    padding: 0 2px;
}

/* Key-value pairs with better layout */
.key-value-pair {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0; /* Reduced from 12px 0 */
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.key-value-pair:last-child {
    border-bottom: none;
}

.key-value-pair .key {
    color: var(--dash-text-muted);
    font-size: 0.9em; /* Reduced from 0.95em */
}

.key-value-pair .value {
    color: var(--dash-accent-color);
    font-weight: 600;
    text-align: right;
}

/* Progress indicators */
.progress-container {
    background-color: var(--dash-tertiary-bg);
    border-radius: 10px; /* Reduced from 12px */
    padding: 3px; /* Reduced from 4px */
    margin: 6px 0; /* Reduced from 16px 0 */
}
.progress-bar {
    height: 12px; /* Reduced from 24px */
    background: linear-gradient(to right, var(--dash-accent-color), var(--accent-purple));
    border-radius: 6px; /* Reduced from 10px */
    text-align: center;
    color: white;
    font-size: 0.6em; /* Reduced from 0.9em */
    font-weight: 600;
    line-height: 10px;
    transition: width 0.5s ease;
}

/* Additional spacing utilities */
.trend-analysis {
    background-color: var(--dash-tertiary-bg);
    padding: 6px 12px; /* Reduced from 20px 24px */
    border-radius: 8px; /* Reduced from 10px */
    margin: 8px 0; /* Reduced from 20px 0 */
    line-height: 1.2; /* Reduced from 1.8 */
}

.correlations {
    background-color: var(--dash-secondary-bg);
    padding: 6px 10px; /* Reduced from 20px 24px */
    border-radius: 6px; /* Reduced from 10px */
    margin: 8px 0; /* Reduced from 20px 0 */
    line-height: 1.3; /* Reduced from 1.8 */
}

.predictions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); /* Reduced from 280px */
    gap: 8px; /* Reduced from 20px */
    margin: 8px 0; /* Reduced from 24px 0 */
}

/* Floating Modal Styles - FIXED */
.floating-modal {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10000;
    width: 500px;
    height: 600px;
    min-width: 350px;
    min-height: 400px;
    max-width: 90vw;
    max-height: 90vh;
}

.floating-modal-content {
    background-color: var(--dash-secondary-bg);
    border-radius: 12px;
    box-shadow: 
        0 10px 40px rgba(0, 0, 0, 0.5),
        0 0 20px rgba(0, 170, 255, 0.4),
        0 0 40px rgba(0, 170, 255, 0.2),
        0 0 60px rgba(0, 170, 255, 0.1);
    display: flex;
    flex-direction: column;
    height: 100%;
    border: 1px solid var(--dash-border-color);
    position: relative;
    overflow: hidden;
}

.floating-modal-header {
    background-color: var(--dash-tertiary-bg); /* Fixed */
    padding: 15px 20px;
    border-radius: 12px 12px 0 0;
    cursor: move;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--dash-accent-color); /* Fixed */
    user-select: none;
}

.modal-title-section {
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-title-section i {
    color: var(--dash-accent-color); /* Fixed */
    font-size: 1.5em;
}

#ai-incident-chat-modal-title {
    margin: 0;
    color: var(--dash-text-color); /* Fixed */
    font-size: 1.2em;
}

.modal-controls {
    display: flex;
    gap: 8px;
}

.modal-controls button {
    background: none;
    border: none;
    color: var(--dash-text-color); /* Fixed */
    cursor: pointer;
    padding: 5px 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.modal-controls button:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.modal-minimize-btn, .modal-maximize-btn, .modal-close-btn {
    font-size: 1em;
}

.modal-close-btn:hover {
    color: var(--dash-danger-color); /* Fixed */
}

.floating-modal-body {
    flex: 1;
    padding: 20px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Resize Handle */
.resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 20px;
    height: 20px;
    cursor: nwse-resize;
    background: linear-gradient(135deg, transparent 50%, var(--dash-border-color) 50%); /* Fixed */
    border-radius: 0 0 12px 0;
}

/* Chat History Styles */
#ai-incident-chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    margin: 10px 0;
    background-color: var(--dash-tertiary-bg); /* Fixed */
    border-radius: 8px;
    border: 1px solid var(--dash-border-color); /* Fixed */
}

/* Input Area Styles */
#ai-incident-chat-input-area {
    display: flex;
    gap: 10px;
    padding: 10px 0;
    border-top: 1px solid var(--dash-border-color); /* Fixed */
}

#ai-incident-chat-input {
    flex: 1;
    padding: 10px 15px;
    border: 1px solid var(--dash-border-color); /* Fixed */
    border-radius: 25px;
    background-color: var(--dash-tertiary-bg); /* Fixed */
    color: var(--dash-text-color); /* Fixed */
    font-size: 0.95em;
}

#ai-incident-send-button {
    padding: 10px 20px;
    background-color: var(--dash-accent-color); /* Fixed */
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    transition: background-color 0.2s;
}

#ai-incident-send-button:hover:not(:disabled) {
    background-color: var(--dash-accent-hover); /* Fixed */
}

#ai-incident-send-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Minimized State */
.floating-modal.minimized {
    height: auto !important;
    width: 300px !important;
}

.floating-modal.minimized .floating-modal-body,
.floating-modal.minimized .resize-handle {
    display: none;
}

/* Maximized State */
.floating-modal.maximized {
    width: 95vw !important;
    height: 95vh !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
}

/* Enhanced Message Bubbles */
.message-bubble-incident {
    margin: 10px 0;
    padding: 12px 16px;
    border-radius: 12px;
    max-width: 85%;
    word-wrap: break-word;
    animation: fadeIn 0.3s ease-in;
}

.user-message-bubble-incident {
    background-color: var(--dash-accent-color); /* Fixed */
    color: white;
    margin-left: auto;
    text-align: right;
}

.ai-message-bubble-incident-start {
    background-color: var(--dash-tertiary-bg); /* Fixed */
    color: var(--dash-text-color); /* Fixed */
    padding: 8px 12px;
    border-radius: 8px;
    margin: 6px 0;
}

/* AI Chat Spinner */
#ai-incident-chat-spinner {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-radius: 6px;
}

#ai-incident-chat-spinner .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--dash-accent-color); /* Fixed */
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

#ai-incident-chat-spinner p {
    color: white;
    margin-top: 10px;
    font-size: 0.95em;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

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