/* (c) Michael Baker International. */
/* SpatialAgent - Perplexity-style AI Chat interface */
/* Uses app theme: base-color #32404e, toolbar-bg #F7F9F8, blue accent #0159C5 */
/* CSS class prefix: sa- (SpatialAgent) */

/* ============================================
   Main panel
   ============================================ */
.sa-panel {
    background-color: #F7F9F8;
}

.sa-panel > .x-panel-bodyWrap {
    height: 100%;
}

.sa-panel > .x-panel-bodyWrap > .x-panel-body {
    overflow: hidden;
    height: 100%;
}

/* ============================================
   Messages area (scrollable)
   ============================================ */
.sa-messages-area {
    background-color: #F7F9F8;
    padding: 24px 32px;
}

/* ============================================
   Welcome card (Perplexity style)
   ============================================ */
.sa-welcome {
    padding: 20px;
}

.sa-welcome-inner {
    max-width: 640px;
    margin: 48px auto 24px;
    text-align: center;
}

.sa-welcome-logo {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    background: linear-gradient(135deg, #0159C5, #32404e);
    margin: 0 auto 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(1, 89, 197, 0.25);
}

.sa-welcome-logo .x-fa {
    font-size: 28px;
    color: #ffffff;
}

.sa-welcome-title {
    margin: 0 0 6px;
    color: #32404e;
    font-size: 26px;
    font-weight: 700;
    font-family: 'Open Sans', 'Helvetica Neue', helvetica, arial, verdana, sans-serif;
    letter-spacing: -0.3px;
}

.sa-welcome-sub {
    margin: 0 0 32px;
    color: #5f6b7a;
    font-size: 14px;
    line-height: 1.5;
}

/* Suggestion cards (2x2 grid) */
.sa-suggestions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
    max-width: 480px;
    margin: 0 auto;
}

.sa-suggestion-card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 14px 16px;
    cursor: pointer;
    text-align: left;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.sa-suggestion-card:hover {
    border-color: #0159C5;
    box-shadow: 0 2px 8px rgba(1, 89, 197, 0.1);
}

.sa-suggestion-card:focus-visible {
    outline: 2px solid #0159C5;
    outline-offset: 2px;
}

.sa-suggestion-icon {
    font-size: 15px;
    color: #0159C5;
    margin-bottom: 6px;
    display: block;
}

.sa-suggestion-text {
    margin: 0;
    font-size: 12px;
    color: #374151;
    line-height: 1.45;
}

/* ============================================
   Chat rows (user and bot)
   ============================================ */
.sa-row {
    margin: 0 0 16px;
    animation: sa-fadeIn 0.25s ease-out;
}

.sa-row-user {
    display: flex;
    justify-content: flex-end;
    padding: 0 8px;
}

.sa-user-msg {
    max-width: 70%;
    background-color: #0159C5;
    color: #ffffff;
    padding: 10px 16px;
    border-radius: 18px 18px 4px 18px;
    font-size: 13px;
    line-height: 1.55;
    overflow-wrap: break-word;
}

.sa-row-bot {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 0 8px;
}

.sa-bot-icon {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    background: linear-gradient(135deg, #0159C5, #32404e);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.sa-bot-icon .x-fa {
    font-size: 13px;
    color: #ffffff;
}

.sa-bot-icon-error {
    background: #dc2626;
}

.sa-bot-content {
    flex: 1;
    min-width: 0;
    max-width: calc(100% - 44px);
}

/* ============================================
   Bot response text — typography
   ============================================ */
.sa-bot-text {
    font-size: 13px;
    line-height: 1.55;
    color: #1f2937;
    overflow-wrap: break-word;
}

/* Paragraphs inside bot response */
.sa-bot-text p {
    margin: 0 0 8px;
}

.sa-bot-text p:last-child {
    margin-bottom: 0;
}

.sa-bot-text strong {
    font-weight: 600;
    color: #111827;
}

.sa-bot-text code {
    background: #f3f4f6;
    padding: 1px 5px;
    border-radius: 3px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 12px;
    color: #0159C5;
}

/* Lists in bot response */
.sa-bot-text ul.sa-md-ul,
.sa-bot-text ol.sa-md-ol {
    margin: 4px 0 8px;
    padding-left: 20px;
}

.sa-bot-text ul.sa-md-ul {
    list-style: disc;
}

.sa-bot-text ol.sa-md-ol {
    list-style: decimal;
}

.sa-bot-text li {
    margin: 2px 0;
    line-height: 1.5;
}

/* Headings in bot response */
h3.sa-md-h {
    font-size: 15px;
    font-weight: 600;
    color: #1f2937;
    margin: 12px 0 4px;
}

h3.sa-md-h:first-child {
    margin-top: 0;
}

h4.sa-md-h {
    font-size: 14px;
    font-weight: 600;
    color: #1f2937;
    margin: 10px 0 3px;
}

h4.sa-md-h:first-child {
    margin-top: 0;
}

h5.sa-md-h {
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    margin: 8px 0 2px;
}

/* Horizontal rule */
hr.sa-md-hr {
    border: none;
    border-top: 1px solid #e5e7eb;
    margin: 10px 0;
}

/* Markdown table inside bot response */
.sa-md-table-wrap {
    overflow-x: auto;
    margin: 8px 0;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
}

.sa-md-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.sa-md-table th {
    background: #f3f4f6;
    padding: 6px 10px;
    text-align: left;
    font-weight: 600;
    color: #374151;
    border-bottom: 2px solid #e5e7eb;
    white-space: nowrap;
    font-size: 11px;
}

.sa-md-table td {
    padding: 5px 10px;
    border-bottom: 1px solid #f3f4f6;
    color: #4b5563;
    white-space: nowrap;
}

.sa-md-table tbody tr:hover td {
    background-color: #f9fafb;
}

.sa-error-text {
    color: #dc2626;
}

/* ============================================
   Collapsible source sections
   ============================================ */
.sa-sources {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sa-source-row {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
    background: #ffffff;
}

.sa-source-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    color: #374151;
    user-select: none;
    transition: background-color 0.15s;
}

.sa-source-toggle:hover {
    background-color: #f9fafb;
}

.sa-source-toggle:focus-visible {
    outline: 2px solid #0159C5;
    outline-offset: -2px;
}

.sa-source-icon {
    font-size: 13px;
    color: #6b7280;
    width: 16px;
    text-align: center;
}

.sa-source-icon-table {
    color: #0159C5;
}

.sa-source-icon-map {
    color: #16a34a;
}

.sa-chevron {
    margin-left: auto;
    font-size: 10px;
    color: #9ca3af;
    transition: transform 0.2s;
}

/* Collapsible content */
.sa-collapsible {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.sa-collapsible.sa-expanded {
    max-height: 600px;
    overflow: auto;
}

/* Rotate chevron when expanded — toggled via JS class on parent row */
.sa-row-expanded .sa-chevron {
    transform: rotate(90deg);
}

/* ============================================
   Results table (from query results)
   ============================================ */
.sa-table-scroll {
    overflow-x: auto;
    padding: 0 0 4px;
}

.sa-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.sa-table th {
    background: #f3f4f6;
    padding: 7px 10px;
    text-align: left;
    font-weight: 600;
    color: #374151;
    border-bottom: 2px solid #e5e7eb;
    white-space: nowrap;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.sa-table td {
    padding: 6px 10px;
    border-bottom: 1px solid #f3f4f6;
    color: #4b5563;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sa-table tbody tr:hover td {
    background-color: #f9fafb;
}

.sa-null {
    color: #9ca3af;
    font-style: italic;
}

.sa-table-footer {
    padding: 6px 12px;
    font-size: 11px;
    color: #9ca3af;
    text-align: center;
    border-top: 1px solid #f3f4f6;
}

/* ============================================
   Inline map (iframe)
   ============================================ */
.sa-map-container {
    width: 100%;
    height: 320px;
}

.sa-map-iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.sa-map-block.sa-expanded {
    max-height: 340px;
}

/* ============================================
   Thinking / analyzing animation
   ============================================ */
.sa-thinking {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 4px 0;
    color: #6b7280;
    font-size: 13px;
}

.sa-think-text {
    margin-right: 2px;
}

.sa-think-dots span {
    animation: sa-dotBounce 1.4s ease-in-out infinite;
    display: inline-block;
}

.sa-think-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.sa-think-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes sa-dotBounce {
    0%, 80%, 100% {
        opacity: 0.3;
    }
    40% {
        opacity: 1;
    }
}

@keyframes sa-fadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   Input bar — consistent pill/rounded design
   ============================================ */
.sa-input-bar {
    background-color: #ffffff !important;
    border-top: 1px solid #e5e7eb;
}

/* Strip ExtJS wrapper borders — let the inner input own the pill shape */
.sa-input-field .x-form-trigger-wrap {
    border: none !important;
    border-radius: 20px;
    background: transparent;
}

.sa-input-field .x-form-text-wrap {
    border: none !important;
    border-radius: 20px;
    background: transparent;
}

.sa-input-field .x-form-text {
    font-size: 13px;
    border-radius: 20px;
    padding: 6px 14px;
    border: 1px solid #e5e7eb;
    background-color: #f9fafb;
    transition: border-color 0.2s, background-color 0.2s, box-shadow 0.2s;
}

.sa-input-field .x-form-text:focus {
    background-color: #ffffff;
    border-color: #0159C5;
    box-shadow: 0 0 0 3px rgba(1, 89, 197, 0.1);
}

/* Send button — circular to match pill input */
.sa-send-btn {
    border-radius: 50% !important;
    border: none !important;
    background-color: #0159C5 !important;
    min-width: 0 !important;
    padding: 0 !important;
    transition: background-color 0.15s, transform 0.1s;
}

.sa-send-btn:hover {
    background-color: #014ba8 !important;
    transform: scale(1.05);
}

.sa-send-btn:active {
    transform: scale(0.95);
}

.sa-send-btn.x-btn-disabled {
    background-color: #d1d5db !important;
    opacity: 1;
    transform: none;
}

.sa-send-btn .x-btn-inner {
    display: none;
}

.sa-send-btn .x-btn-icon-el {
    color: #ffffff;
    font-size: 14px;
}

.sa-send-btn .x-btn-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================
   Footer (disclaimer + clear chat)
   ============================================ */
.sa-footer {
    background-color: #ffffff;
    border-top: 1px solid #f3f4f6;
    padding: 6px 16px;
}

.sa-footer-inner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.sa-footer-text {
    font-size: 11px;
    color: #9ca3af;
}

.sa-clear-link {
    font-size: 11px;
    color: #6b7280;
    text-decoration: none;
    cursor: pointer;
    transition: color 0.15s;
}

.sa-clear-link:hover {
    color: #0159C5;
    text-decoration: underline;
}

.sa-clear-link:focus-visible {
    outline: 2px solid #0159C5;
    outline-offset: 1px;
}

/* ============================================
   RAG — citations panel, fix-it card, grounding badge
   ============================================ */
.sa-rag-citations {
    margin-top: 10px;
    padding: 10px 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}
.sa-rag-citations-label {
    font-size: 11px;
    font-weight: 600;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.sa-rag-citations-list {
    margin: 0;
    padding-left: 22px;
    font-size: 12px;
    color: #1f2937;
}
.sa-rag-citation { margin-bottom: 8px; line-height: 1.45; }
.sa-rag-citation:last-child { margin-bottom: 0; }
.sa-rag-citation-badge {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    margin-right: 6px;
    background: #e0f2fe;
    color: #0369a1;
}
.sa-rag-citation-nena { background: #fef3c7; color: #92400e; }
.sa-rag-citation-title { font-weight: 600; color: #0159C5; text-decoration: none; }
.sa-rag-citation-title:hover { text-decoration: underline; }
.sa-rag-citation-snippet {
    color: #4b5563;
    font-size: 11.5px;
    margin-top: 2px;
    line-height: 1.4;
}

/* Fix-it card */
.sa-rag-fix-card {
    margin-bottom: 12px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-left: 3px solid #0159C5;
    border-radius: 8px;
    padding: 10px 14px;
}
.sa-rag-fix-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}
.sa-rag-fix-code {
    font-weight: 700;
    font-size: 13px;
    color: #0159C5;
    background: #e0f2fe;
    padding: 2px 8px;
    border-radius: 12px;
}
.sa-rag-fix-severity {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 2px 7px;
    border-radius: 10px;
    background: #f3f4f6;
    color: #6b7280;
}
.sa-rag-fix-sev-critical { background: #fee2e2; color: #b91c1c; }
.sa-rag-fix-sev-high { background: #fee2e2; color: #b91c1c; }
.sa-rag-fix-sev-medium { background: #fef3c7; color: #92400e; }
.sa-rag-fix-sev-low { background: #dbeafe; color: #1e40af; }
.sa-rag-source-chip {
    font-size: 10px;
    background: #f3f4f6;
    color: #4b5563;
    padding: 2px 7px;
    border-radius: 10px;
    margin-right: 4px;
}
.sa-rag-fix-sources-label {
    font-size: 10.5px;
    color: #6b7280;
    margin-left: 2px;
}
.sa-rag-fix-title {
    margin: 8px 0 4px;
    font-size: 14px;
    font-weight: 600;
    color: #111827;
    line-height: 1.35;
}
.sa-rag-fix-fallback {
    margin: 6px 0 10px;
    padding: 7px 10px;
    background: #eff6ff;
    border-left: 2px solid #93c5fd;
    border-radius: 4px;
    font-size: 11.5px;
    color: #1e3a8a;
}
.sa-rag-fix-fallback .x-fa { margin-right: 6px; opacity: 0.8; }
.sa-rag-fix-section {
    font-size: 12.5px;
    color: #1f2937;
    margin: 8px 0;
    line-height: 1.5;
}
.sa-rag-fix-section-label {
    display: block;
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #6b7280;
    margin-bottom: 3px;
}
.sa-rag-fix-section-body { display: block; }
.sa-rag-fix-section ul,
.sa-rag-fix-steps {
    margin: 4px 0 0;
    padding-left: 22px;
}
.sa-rag-fix-steps { list-style: decimal; }
.sa-rag-fix-section ul { list-style: disc; }
.sa-rag-fix-section li,
.sa-rag-fix-steps li { margin: 4px 0; }
.sa-rag-fix-muted { color: #9ca3af; font-style: italic; font-size: 11.5px; }

/* Grounding warning badge */
.sa-rag-grounding-badge {
    margin-bottom: 10px;
    padding: 6px 10px;
    background: #fef3c7;
    border: 1px solid #fde68a;
    border-radius: 6px;
    font-size: 11.5px;
    color: #92400e;
    cursor: help;
}
.sa-rag-grounding-badge .x-fa { margin-right: 4px; }
