/* ════════════════════════════════════════════════════════════════════
   Sapience Theme — Production Ticket Duplicate Detector
   Inspired by SapienceIQ dashboard design
   ════════════════════════════════════════════════════════════════════ */

:root {
    /* Brand */
    --sapience-blue:    #0078c8;
    --sapience-teal:    #00a5b5;
    --sapience-orange:  #f5841f;
    --sapience-red:     #e8501e;
    --sapience-dark:    #1a1f36;

    /* Sidebar */
    --sidebar-bg:       #0f1528;
    --sidebar-hover:    #1a2240;
    --sidebar-text:     #8892ab;
    --sidebar-active:   #ffffff;
    --sidebar-width:    240px;

    /* Accent */
    --accent:           #0078c8;
    --accent-hover:     #005fa3;
    --accent-light:     #e8f4fd;

    /* Content */
    --content-bg:       #f0f2f5;
    --card-bg:          #ffffff;
    --text-primary:     #1a1f36;
    --text-secondary:   #5a6178;
    --text-muted:       #9ca3af;
    --border:           #e2e5eb;
    --border-light:     #f5f6f8;

    /* Confidence */
    --conf-high-bg:     #dcfce7;
    --conf-high-text:   #166534;
    --conf-med-bg:      #fef3c7;
    --conf-med-text:    #92400e;
    --conf-low-bg:      #fee2e2;
    --conf-low-text:    #991b1b;

    /* Status Colors */
    --status-resolved:  #10b981;
    --status-testing:   #8b5cf6;
    --status-active:    #f59e0b;
    --status-open:      #3b82f6;
}

/* ── Reset & Base ─────────────────────────────────────────────────── */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--content-bg);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────────── */

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: fixed;
    z-index: 10;
}

.sidebar-logo {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    background: #ffffff;
}

.logo-img-wide {
    width: 160px;
    height: auto;
    object-fit: contain;
}

.sidebar-nav {
    padding: 16px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 16px;
    border: none;
    background: transparent;
    color: var(--sidebar-text);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: left;
}

.nav-btn:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-active);
}

.nav-btn.active {
    background: var(--accent);
    color: #fff;
}

.sidebar-info {
    padding: 14px 18px;
    border-top: 1px solid rgba(255,255,255,0.06);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.info-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.info-label {
    color: var(--sidebar-text);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-value {
    color: var(--sidebar-active);
    font-size: 13px;
    font-weight: 600;
}

.status-on  { color: var(--status-resolved); }
.status-off { color: var(--conf-low-text); }

/* ── Main Content ─────────────────────────────────────────────────── */

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    height: 100vh;
    overflow-y: auto;
    padding: 0;
    background: var(--content-bg);
}

/* Top accent bar like SapienceIQ */
.main-content::before {
    content: '';
    display: block;
    height: 3px;
    background: linear-gradient(90deg, var(--sapience-red), var(--sapience-orange), var(--sapience-teal), var(--sapience-blue));
}

.view {
    display: none;
    max-width: 960px;
    margin: 0 auto;
    padding: 28px 36px 60px;
    animation: fadeSlideIn 0.3s ease;
}

.view.active {
    display: block;
}

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

.view-header {
    margin-bottom: 24px;
}

.view-header h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ── Search Input Card ────────────────────────────────────────────── */

.search-input-card {
    background: var(--card-bg);
    border-radius: 10px;
    padding: 20px 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05), 0 1px 2px rgba(0,0,0,0.03);
    border: 1px solid var(--border);
    margin-bottom: 20px;
}

textarea {
    width: 100%;
    min-height: 120px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    font-family: inherit;
    font-size: 13.5px;
    line-height: 1.6;
    color: var(--text-primary);
    resize: vertical;
    transition: border-color 0.15s;
    background: var(--border-light);
}

textarea::placeholder {
    color: var(--text-muted);
}

textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
    background: #fff;
}

.search-actions {
    display: flex;
    gap: 10px;
    margin-top: 14px;
}

/* ── Buttons ──────────────────────────────────────────────────────── */

.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 22px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,120,200,0.25);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-secondary {
    padding: 10px 18px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-secondary:hover {
    background: var(--border-light);
    color: var(--text-primary);
}

/* Button spinner */
.btn-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
}

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

/* ── Thinking Animation — Brain Pulse ────────────────────────────── */

.thinking-container {
    background: var(--card-bg);
    border-radius: 10px;
    padding: 24px 28px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    border: 1px solid var(--border);
    margin-bottom: 20px;
    position: relative;
    overflow: hidden;
}

/* Animated gradient shimmer behind steps */
.thinking-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 200%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(0,120,200,0.03) 25%,
        rgba(0,165,181,0.05) 50%,
        rgba(0,120,200,0.03) 75%,
        transparent 100%
    );
    animation: shimmer 3s ease-in-out infinite;
}

@keyframes shimmer {
    0%   { transform: translateX(-50%); }
    100% { transform: translateX(50%); }
}

.thinking-stepper {
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1;
}

.step {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    opacity: 0.35;
    transition: all 0.4s ease;
    padding: 4px 0;
}

.step.active, .step.complete {
    opacity: 1;
}

.step-indicator {
    position: relative;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.step-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--border);
    z-index: 1;
    transition: all 0.4s;
}

.step.active .step-dot {
    background: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-light);
}

.step.complete .step-dot {
    background: var(--status-resolved);
}

.pulse-ring {
    position: absolute;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    opacity: 0;
}

.step.active .pulse-ring {
    animation: pulse-ring 1.8s ease-out infinite;
}

@keyframes pulse-ring {
    0%   { transform: scale(0.5); opacity: 0.35; }
    100% { transform: scale(1.6); opacity: 0; }
}

.step-check {
    display: none;
    color: var(--status-resolved);
    font-size: 15px;
    font-weight: 700;
    z-index: 2;
}

.step.complete .step-dot   { display: none; }
.step.complete .step-check { display: block; }
.step.complete .pulse-ring { display: none; }

.step-content {
    padding: 2px 0 0;
}

.step-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.step-detail {
    font-size: 12px;
    color: var(--text-secondary);
}

.step.active .step-title {
    color: var(--accent);
}

.step.active .step-detail::after {
    content: '';
    animation: ellipsis 1.5s steps(3) infinite;
}

@keyframes ellipsis {
    0%   { content: ''; }
    33%  { content: '.'; }
    66%  { content: '..'; }
    100% { content: '...'; }
}

.step-connector {
    width: 2px;
    height: 16px;
    background: var(--border);
    margin-left: 13px;
    transition: all 0.4s;
    border-radius: 1px;
}

.step-connector.done {
    background: var(--status-resolved);
}

/* ── Results ──────────────────────────────────────────────────────── */

.results-container {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.results-container > * {
    animation: cardSlideIn 0.4s ease backwards;
}
.results-container > *:nth-child(1) { animation-delay: 0s; }
.results-container > *:nth-child(2) { animation-delay: 0.08s; }
.results-container > *:nth-child(3) { animation-delay: 0.16s; }
.results-container > *:nth-child(4) { animation-delay: 0.24s; }
.results-container > *:nth-child(5) { animation-delay: 0.32s; }

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

/* Analysis Card */
.analysis-card {
    background: var(--card-bg);
    border-radius: 10px;
    padding: 18px 22px;
    border: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.analysis-card h3 {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 12px;
}

.analysis-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.analysis-item {
    display: flex;
    gap: 8px;
}

.analysis-label {
    font-size: 12px;
    color: var(--text-muted);
    min-width: 80px;
}

.analysis-value {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
}

/* Recommendation Banner */
.rec-banner {
    border-radius: 10px;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    font-size: 14px;
}

.rec-banner.duplicate {
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    color: #065f46;
}

.rec-banner.investigate {
    background: #fffbeb;
    border: 1px solid #fde68a;
    color: #78350f;
}

.rec-banner.create_new {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e40af;
}

.rec-icon { font-size: 20px; }

.rec-text { flex: 1; }

.rec-reasoning {
    font-weight: 400;
    font-size: 12px;
    margin-top: 3px;
    opacity: 0.8;
}

/* Recommendation colour variants */
.rec-new         { background:#eff6ff; border:1px solid #bfdbfe; color:#1e40af; }
.rec-link        { background:#ecfdf5; border:1px solid #a7f3d0; color:#065f46; }
.rec-investigate { background:#fffbeb; border:1px solid #fde68a; color:#78350f; }
.rec-new p, .rec-link p, .rec-investigate p { font-weight:400; font-size:12px; margin:6px 0 0; }

/* Track cards */
.track-card { margin-top:0; }
.track-header { display:flex; align-items:center; gap:10px; margin-bottom:14px; }
.badge { background:var(--border); border-radius:20px; padding:2px 8px; font-size:11px; font-weight:600; }

/* Match rows */
.match-row { padding:12px 0; border-top:1px solid var(--border); }
.match-row:first-of-type { border-top:none; }
.match-title a { font-weight:600; font-size:13px; color:var(--accent); text-decoration:none; }
.match-title a:hover { text-decoration:underline; }
.match-meta { display:flex; flex-wrap:wrap; gap:8px; margin-top:5px; }
.meta-item { font-size:12px; color:var(--text-muted); }
.state-pill { font-size:11px; font-weight:600; padding:2px 8px; border-radius:20px; }
.state-closed { background:#dcfce7; color:#166534; }
.state-open   { background:#dbeafe; color:#1e40af; }
.match-why  { font-size:12px; color:var(--text-muted); margin-top:6px; }
.match-fix  { font-size:12px; margin-top:5px; padding:8px 10px; background:#f8fafc; border-radius:6px; border-left:3px solid #16a34a; }
.sf-link    { font-size:12px; margin-top:5px; color:#7c3aed; }
.sf-link a  { color:#7c3aed; }
.steps-list { margin:4px 0 0 16px; padding:0; font-size:12px; }
.steps-list li { margin-bottom:3px; }

/* Tag pill */
.tag { font-size:11px; font-weight:700; background:var(--border); border-radius:4px; padding:2px 6px; margin-right:4px; }
.analysis-header { margin-bottom:8px; font-size:13px; }
.analysis-body   { font-size:13px; color:var(--text-primary); }

/* ── SF Case # input row ─────────────────────────────────────────── */
.sf-case-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 10px;
}
.sf-case-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    white-space: nowrap;
    min-width: 60px;
}
.sf-case-field {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 13px;
    font-family: inherit;
    background: var(--bg-primary);
    color: var(--text-primary);
    outline: none;
}
.sf-case-field:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(0,120,200,0.15);
}

/* ── Support Answer Card ─────────────────────────────────────────── */
.support-answer-card {
    border-radius: 12px;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.sa-header {
    display: flex;
    align-items: center;
    gap: 10px;
}
.sa-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.sa-label {
    font-size: 15px;
    font-weight: 700;
    flex: 1;
}
.sa-eta {
    font-size: 12px;
    color: var(--text-muted);
    background: rgba(0,0,0,0.06);
    padding: 2px 8px;
    border-radius: 20px;
}
.sa-situation {
    font-size: 13px;
    color: var(--text-primary);
    line-height: 1.5;
}
.sa-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.sa-section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}
.sa-steps {
    margin: 0 0 0 18px;
    padding: 0;
    font-size: 13px;
    line-height: 1.8;
    color: var(--text-primary);
}
.sa-customer-msg {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-primary);
    background: rgba(255,255,255,0.6);
    border-radius: 8px;
    padding: 12px 14px;
    white-space: pre-line;
}
.sa-internal {
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
}
.sa-escalate {
    font-size: 12px;
    font-weight: 600;
    color: #dc2626;
    background: #fee2e2;
    border-radius: 6px;
    padding: 8px 12px;
}
.copy-btn {
    font-size: 11px;
    font-weight: 600;
    background: rgba(0,0,0,0.08);
    border: none;
    border-radius: 4px;
    padding: 2px 8px;
    cursor: pointer;
    color: var(--text-primary);
}
.copy-btn:hover { background: rgba(0,0,0,0.15); }

/* ── Related Bugs collapsible ───────────────────────────────────── */
.bugs-details { margin-top: 0; }
.bugs-summary {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    padding: 10px 4px;
    user-select: none;
    list-style: none;
}
.bugs-summary::-webkit-details-marker { display: none; }
.bugs-summary::before { content: '▶'; font-size: 10px; transition: transform 0.2s; }
details[open] .bugs-summary::before { transform: rotate(90deg); }

/* Result Card */
.result-card {
    background: var(--card-bg);
    border-radius: 10px;
    padding: 20px 24px;
    border: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    transition: all 0.2s;
}

.result-card:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
    transform: translateY(-1px);
}

.result-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.confidence-badge {
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.3px;
}

.confidence-badge.high   { background: var(--conf-high-bg); color: var(--conf-high-text); }
.confidence-badge.medium { background: var(--conf-med-bg);  color: var(--conf-med-text); }
.confidence-badge.low    { background: var(--conf-low-bg);  color: var(--conf-low-text); }

.item-type-badge {
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 600;
    background: var(--border-light);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.result-id {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
}

.result-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text-primary);
    line-height: 1.4;
}

.result-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 12px;
    font-size: 12px;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 11px;
}

.status-badge.resolved  { background: #ecfdf5; color: #065f46; }
.status-badge.testing   { background: #f5f3ff; color: #5b21b6; }
.status-badge.active    { background: #fffbeb; color: #78350f; }
.status-badge.open      { background: #eff6ff; color: #1e40af; }

.meta-item {
    color: var(--text-secondary);
}

.meta-item strong {
    color: var(--text-primary);
    font-weight: 500;
}

/* Reasoning */
.result-reasoning {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    padding: 10px 14px;
    background: var(--border-light);
    border-radius: 8px;
    line-height: 1.5;
}

/* Fix Section — the key feature! */
.fix-section {
    border-left: 4px solid var(--status-resolved);
    background: linear-gradient(135deg, #f0fdf4, #ecfdf5);
    border-radius: 0 10px 10px 0;
    padding: 14px 18px;
    margin-bottom: 12px;
}

.fix-section h4 {
    font-size: 11px;
    font-weight: 700;
    color: #065f46;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.fix-text {
    font-size: 13px;
    color: #064e3b;
    line-height: 1.6;
    font-weight: 500;
}

.fix-meta {
    display: block;
    margin-top: 8px;
    font-size: 11px;
    color: #6b7280;
    font-weight: 400;
}

/* Azure Link */
.azure-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.15s;
}

.azure-link:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* No Results */
.section-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 16px 0 14px;
}
.section-divider::before,
.section-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* SF Link Banner — shown inside ADO cards when linked via past SF case */
.sf-link-banner {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    background: #faf5ff;
    border: 1.5px solid #d8b4fe;
    border-radius: 8px;
    padding: 8px 12px;
    margin: 8px 0;
    font-size: 12px;
    color: #374151;
}

.no-results {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

.no-results-icon { font-size: 44px; margin-bottom: 12px; }

.no-results h3 {
    font-size: 17px;
    color: var(--text-primary);
    margin-bottom: 6px;
}

/* ── Chat ─────────────────────────────────────────────────────────── */

.chat-container {
    background: var(--card-bg);
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    display: flex;
    flex-direction: column;
    height: calc(100vh - 180px);
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 28px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* ── Welcome card ───────────────────────────────────────────── */
.chat-welcome {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background: #f8faff;
    border: 1px solid #dbeafe;
    border-radius: 12px;
    padding: 16px 18px;
    margin-bottom: 8px;
}

.chat-welcome-icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-welcome-body { flex: 1; }

.chat-welcome-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 10px;
}

.chat-welcome-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chat-chip {
    background: #fff;
    border: 1px solid #c7d7f4;
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 12px;
    color: var(--accent);
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
}

.chat-chip:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* ── Message rows (avatar + bubble) ────────────────────────── */
.chat-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    animation: bubbleIn 0.2s ease;
}

.chat-row.user   { flex-direction: row-reverse; }
.chat-row.assistant { flex-direction: row; }

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

.chat-avatar {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-row.user     .chat-avatar { background: var(--accent);    color: #fff; }
.chat-row.assistant .chat-avatar { background: #e8f0fe; color: var(--accent); }

.chat-bubble {
    max-width: 72%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.65;
}

.chat-bubble.user {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-bubble.assistant {
    background: #f3f4f6;
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

/* Markdown rendering inside assistant bubbles */
.chat-bubble strong { font-weight: 700; }
.chat-bubble em     { font-style: italic; }

.chat-list-item {
    display: flex;
    gap: 6px;
    margin: 3px 0;
    align-items: flex-start;
}

.chat-list-num  { font-weight: 700; min-width: 18px; color: var(--accent); }
.chat-bubble.user .chat-list-num { color: rgba(255,255,255,0.85); }
.chat-bullet    { font-weight: 700; color: var(--accent); min-width: 12px; }
.chat-bubble.user .chat-bullet { color: rgba(255,255,255,0.85); }

/* ── Loading dots ───────────────────────────────────────────── */
.chat-bubble.loading {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 14px 18px;
    background: #f3f4f6;
    min-width: 60px;
}

.chat-bubble.loading .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #9ca3af;
    animation: chat-dot 1.4s infinite ease-in-out;
}

.chat-bubble.loading .dot:nth-child(2) { animation-delay: 0.2s; }
.chat-bubble.loading .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes chat-dot {
    0%, 60%, 100% { opacity: 0.3; transform: scale(0.85); }
    30%           { opacity: 1;   transform: scale(1.15); }
}

/* ── Input row ──────────────────────────────────────────────── */
.chat-input-row {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    background: #fafafa;
    border-radius: 0 0 12px 12px;
}

.chat-input-row input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 24px;
    font-family: inherit;
    font-size: 13px;
    color: var(--text-primary);
    transition: border-color 0.15s, box-shadow 0.15s;
    background: #fff;
}

.chat-input-row input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.chat-input-row input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ── Stats ────────────────────────────────────────────────────────── */

/* Summary metric cards like SapienceIQ */
.stats-summary-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 24px;
}

.stats-metric-card {
    background: linear-gradient(135deg, var(--sapience-blue), var(--sapience-teal));
    border-radius: 10px;
    padding: 18px 20px;
    color: #fff;
    text-align: center;
}

.stats-metric-card:nth-child(2) {
    background: linear-gradient(135deg, var(--status-resolved), #059669);
}

.stats-metric-card:nth-child(3) {
    background: linear-gradient(135deg, var(--sapience-orange), #f59e0b);
}

.stats-metric-card:nth-child(4) {
    background: linear-gradient(135deg, var(--sapience-red), var(--sapience-orange));
}

.metric-number {
    font-size: 32px;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 4px;
}

.metric-label {
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.9;
}

.stats-container {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.stats-section {
    background: var(--card-bg);
    border-radius: 10px;
    padding: 22px 26px;
    border: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.stats-section h3 {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 16px;
}

.stat-bar-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.stat-label {
    width: 120px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
    text-align: right;
    flex-shrink: 0;
}

.stat-bar-track {
    flex: 1;
    height: 24px;
    background: var(--border-light);
    border-radius: 6px;
    overflow: hidden;
}

.stat-bar-fill {
    height: 100%;
    border-radius: 6px;
    transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    min-width: 2px;
}

.stat-count {
    width: 45px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: right;
}

.stats-loading {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

/* ── Error ────────────────────────────────────────────────────────── */

.error-banner {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    padding: 12px 18px;
    border-radius: 10px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ── Scrollbar ───────────────────────────────────────────────────── */

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #c5c9d4;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a0a5b2;
}

/* ── Responsive ───────────────────────────────────────────────────── */

@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        flex-direction: row;
    }

    .sidebar-nav {
        flex-direction: row;
        padding: 6px;
    }

    .sidebar-logo { padding: 10px 14px; }
    .sidebar-info { display: none; }

    .main-content {
        margin-left: 0;
    }

    .view {
        padding: 16px;
    }

    .stats-summary-row {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ── Sidebar user block ─────────────────────────────────────────────────── */
.sidebar-user {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-user-name {
    font-size: 12px;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-email {
    font-size: 11px;
    color: var(--sidebar-text);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-logout {
    display: inline-block;
    margin-top: 8px;
    font-size: 11px;
    color: var(--sidebar-text);
    text-decoration: none;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 4px;
    padding: 3px 10px;
    transition: all 0.15s;
}

.sidebar-logout:hover {
    color: #fff;
    border-color: rgba(255,255,255,0.4);
}

/* ── Knowledge Base hit banner ──────────────────────────────────────────── */
.kb-hit-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
    border: 1.5px solid #6ee7b7;
    border-radius: 10px;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 700;
    color: #065f46;
    margin-bottom: 2px;
    flex-wrap: wrap;
}

.kb-hit-sub {
    font-weight: 400;
    font-size: 11px;
    color: #047857;
    margin-left: auto;
}
