/*
 * analysis.css
 * AI-powered analysis and knowledge base styles.
 * Contains: analysis tab bar and cards, knowledge base sidebar
 * (hamburger menu), KB search results and article display.
 */

/* ═══════════════════════════════════════════════════════════════════════════
   ANALYSIS TAB - AI-powered customer analysis
   ═══════════════════════════════════════════════════════════════════════════ */

.analysis-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
}

.analysis-search-wrapper {
    display: flex;
    flex: 1;
    gap: 8px;
}

.analysis-input {
    flex: 1;
    padding: 10px 14px;
    font-size: 13px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.analysis-input:focus {
    border-color: var(--hawx-teal);
    box-shadow: 0 0 0 3px rgba(99, 118, 117, 0.15);
}

.analysis-input::placeholder {
    color: var(--gray-400);
}

.analysis-quick-queries {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 16px;
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
}

.quick-query-btn {
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--gray-700);
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.15s;
}

.quick-query-btn:hover {
    background: var(--hawx-teal-light);
    border-color: var(--hawx-teal);
    color: var(--hawx-teal-dark);
}

.quick-query-btn:active {
    transform: scale(0.98);
}

.analysis-results {
    padding: 16px;
}

.analysis-placeholder {
    text-align: center;
    padding: 40px 20px;
    color: var(--gray-500);
}

.analysis-placeholder p {
    margin: 0 0 8px 0;
}

.analysis-placeholder .hint {
    font-size: 12px;
    color: var(--gray-400);
}

.analysis-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    gap: 12px;
    color: var(--gray-500);
}

.analysis-loading .loading {
    width: 32px;
    height: 32px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--hawx-teal);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.analysis-error {
    padding: 20px;
    text-align: center;
}

/* Analysis status (streaming loading state) */
.analysis-status {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    color: var(--gray-600);
    background: var(--white, #fff);
}

.analysis-status .loading {
    width: 20px;
    height: 20px;
    border: 2px solid var(--gray-200);
    border-top-color: var(--hawx-teal);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

#analysis-status-text {
    color: var(--gray-600);
    font-size: 14px;
}

.analysis-result {
    background: var(--white, #fff);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    overflow: hidden;
}

.analysis-query {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
}

.query-label {
    font-weight: 600;
    color: var(--hawx-teal);
    flex-shrink: 0;
}

.query-text {
    color: var(--gray-700);
}

.analysis-answer {
    display: flex;
    gap: 8px;
    padding: 16px;
    background: var(--white, #fff);
    border-radius: 0;
    border: none;
}

.answer-label {
    font-weight: 600;
    color: var(--success);
    flex-shrink: 0;
}

.answer-text {
    color: var(--gray-800);
    line-height: 1.6;
    flex: 1;
}

.answer-text strong {
    color: var(--gray-900);
}

.answer-text em {
    color: var(--gray-500);
}

/* Dark theme for analysis results */
[data-theme="dark"] .analysis-results {
    background: transparent;
}

[data-theme="dark"] .analysis-placeholder {
    color: var(--gray-400);
}

[data-theme="dark"] .analysis-placeholder .hint {
    color: var(--gray-500);
}

[data-theme="dark"] .analysis-loading {
    color: var(--gray-400);
}

[data-theme="dark"] .analysis-loading .loading {
    border-color: var(--gray-600);
    border-top-color: var(--hawx-teal);
}

[data-theme="dark"] .analysis-error {
    color: var(--gray-300);
}

[data-theme="dark"] .analysis-status {
    color: var(--text-muted);
    background: var(--card-bg);
}

[data-theme="dark"] .analysis-status .loading {
    border-color: var(--border-color);
    border-top-color: var(--hawx-teal);
}

[data-theme="dark"] #analysis-status-text {
    color: var(--text-muted);
}

[data-theme="dark"] .analysis-result {
    background: var(--card-bg);
    border-color: var(--border-color);
}

[data-theme="dark"] .analysis-query {
    background: var(--bg-tertiary);
    border-bottom-color: var(--border-color);
}

[data-theme="dark"] .query-text {
    color: var(--text-secondary);
}

[data-theme="dark"] .query-label {
    color: var(--hawx-teal);
}

[data-theme="dark"] .analysis-answer {
    background: var(--card-bg);
    border-color: var(--border-color);
}

[data-theme="dark"] .answer-label {
    color: var(--success-light);
}

[data-theme="dark"] .answer-text {
    color: var(--text-primary);
}

[data-theme="dark"] .answer-text strong {
    color: var(--white);
}

[data-theme="dark"] .answer-text em {
    color: var(--gray-400);
}

/* Markdown elements - headings */
.answer-text h1,
.answer-text h2,
.answer-text h3,
.answer-text h4,
.answer-text h5,
.answer-text h6 {
    color: var(--gray-900);
    margin: 16px 0 8px 0;
    font-weight: 600;
    line-height: 1.3;
}

.answer-text h1 { font-size: 1.5em; }
.answer-text h2 { font-size: 1.3em; }
.answer-text h3 { font-size: 1.15em; }
.answer-text h4 { font-size: 1em; }

.answer-text h1:first-child,
.answer-text h2:first-child,
.answer-text h3:first-child {
    margin-top: 0;
}

/* Markdown elements - code */
.answer-text code {
    background: var(--gray-100);
    color: var(--gray-800);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9em;
}

.answer-text pre {
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    padding: 12px 16px;
    overflow-x: auto;
    margin: 12px 0;
}

.answer-text pre code {
    background: transparent;
    padding: 0;
    border-radius: 0;
}

/* Markdown elements - blockquote */
.answer-text blockquote {
    border-left: 3px solid var(--hawx-teal);
    margin: 12px 0;
    padding: 8px 16px;
    background: var(--gray-50);
    color: var(--gray-700);
}

.answer-text blockquote p {
    margin: 0;
}

/* Markdown elements - tables */
.answer-text table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 0.95em;
}

.answer-text th,
.answer-text td {
    border: 1px solid var(--gray-200);
    padding: 8px 12px;
    text-align: left;
}

.answer-text th {
    background: var(--gray-100);
    font-weight: 600;
    color: var(--gray-800);
}

.answer-text tr:nth-child(even) {
    background: var(--gray-50);
}

/* Markdown elements - horizontal rule */
.answer-text hr {
    border: none;
    border-top: 1px solid var(--gray-200);
    margin: 16px 0;
}

/* Dark theme - markdown headings */
[data-theme="dark"] .answer-text h1,
[data-theme="dark"] .answer-text h2,
[data-theme="dark"] .answer-text h3,
[data-theme="dark"] .answer-text h4,
[data-theme="dark"] .answer-text h5,
[data-theme="dark"] .answer-text h6 {
    color: var(--white);
}

/* Dark theme - markdown code */
[data-theme="dark"] .answer-text code {
    background: var(--gray-700);
    color: var(--gray-100);
}

[data-theme="dark"] .answer-text pre {
    background: var(--gray-800);
    border-color: var(--gray-600);
}

/* Dark theme - blockquote */
[data-theme="dark"] .answer-text blockquote {
    background: var(--gray-800);
    border-left-color: var(--hawx-teal);
    color: var(--gray-300);
}

/* Dark theme - tables */
[data-theme="dark"] .answer-text th,
[data-theme="dark"] .answer-text td {
    border-color: var(--gray-600);
}

[data-theme="dark"] .answer-text th {
    background: var(--gray-700);
    color: var(--gray-100);
}

[data-theme="dark"] .answer-text tr:nth-child(even) {
    background: var(--gray-800);
}

[data-theme="dark"] .answer-text tr:nth-child(odd) {
    background: var(--gray-850, #1a1a1a);
}

/* Dark theme - horizontal rule */
[data-theme="dark"] .answer-text hr {
    border-top-color: var(--gray-600);
}

/* Dark theme - links */
[data-theme="dark"] .answer-text a {
    color: var(--hawx-teal-light, #4fd1c5);
}

[data-theme="dark"] .answer-text a:hover {
    color: var(--hawx-teal);
}

/* Dark theme - lists */
[data-theme="dark"] .answer-text ul,
[data-theme="dark"] .answer-text ol {
    color: var(--text-primary);
}

[data-theme="dark"] .answer-text li {
    color: var(--text-primary);
}

.answer-text p {
    margin: 0 0 12px 0;
}

.answer-text p:last-child {
    margin-bottom: 0;
}

.answer-text ul,
.answer-text ol {
    margin: 8px 0;
    padding-left: 20px;
}

.answer-text li {
    margin-bottom: 4px;
}

.answer-text a {
    color: var(--primary-light);
    text-decoration: underline;
}

.answer-text a:hover {
    color: var(--primary);
}


/* ═══════════════════════════════════════════════════════════════════════════
   KNOWLEDGE BASE SIDEBAR (Hamburger Menu)
   ═══════════════════════════════════════════════════════════════════════════ */

/* Hamburger Menu Button */
.hamburger-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: transparent;
    color: var(--gray-600);
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.hamburger-menu-btn:hover {
    background: var(--gray-100);
    border-color: var(--gray-300);
    color: var(--hawx-teal);
}

.hamburger-menu-btn svg {
    width: 20px;
    height: 20px;
}

/* Overlay */
.kb-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 998;
}

.kb-overlay.visible {
    opacity: 1;
    visibility: visible;
}

/* Sidebar - slides from LEFT */
.kb-sidebar {
    position: fixed;
    top: 0;
    left: -450px;
    width: 450px;
    height: 100vh;
    background: var(--gray-50);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    z-index: 999;
    display: flex;
    flex-direction: column;
    transition: left 0.3s ease;
}

.kb-sidebar.open {
    left: 0;
}

body.kb-sidebar-open {
    overflow: hidden;
}

/* Sidebar Header */
.kb-sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--hawx-teal), var(--hawx-teal-dark));
    color: white;
}

.kb-sidebar-header h3 {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 600;
}

.kb-sidebar-header h3 svg {
    width: 20px;
    height: 20px;
}

.kb-close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 24px;
    line-height: 1;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.kb-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Sidebar Sections (Collapsible) */
.sidebar-section {
    border-bottom: 1px solid var(--gray-200);
}

.sidebar-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    background: white;
    cursor: pointer;
    transition: background 0.2s ease;
}

.sidebar-section-header:hover {
    background: var(--gray-50);
}

.sidebar-section-header h4 {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-700);
}

.sidebar-section-header h4 svg {
    width: 18px;
    height: 18px;
    color: var(--hawx-teal);
}

.sidebar-section-header .section-toggle {
    width: 18px;
    height: 18px;
    color: var(--gray-400);
    transition: transform 0.2s ease;
}

.sidebar-section-header.collapsed .section-toggle {
    transform: rotate(-90deg);
}

.sidebar-section-content {
    padding: 0 20px 16px;
    background: white;
}

.sidebar-section-header.collapsed + .sidebar-section-content {
    display: none;
}

/* Zip Code Checker */
.zip-code-input-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.zip-code-input-wrapper:focus-within {
    border-color: var(--hawx-teal);
    box-shadow: 0 0 0 3px rgba(99, 118, 117, 0.1);
}

.zip-code-input-wrapper input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 14px;
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: 2px;
    color: var(--gray-700);
    outline: none;
    min-width: 0;
}

.zip-code-input-wrapper input::placeholder {
    color: var(--gray-400);
    letter-spacing: normal;
    font-family: 'DM Sans', sans-serif;
}

#zip-code-result {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

#zip-code-result svg {
    width: 24px;
    height: 24px;
}

#zip-code-result .loading {
    width: 20px;
    height: 20px;
    border: 2px solid var(--gray-200);
    border-top-color: var(--hawx-teal);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#zip-code-branch {
    margin-top: 10px;
    font-size: 13px;
    color: var(--gray-600);
    font-weight: 500;
    min-height: 20px;
}

#zip-code-branch:not(:empty) {
    padding: 8px 12px;
    background: rgba(75, 181, 67, 0.1);
    border-radius: 6px;
    color: #2d8a25;
}

/* Search Section (Legacy - keeping for backward compatibility) */
.kb-search-section {
    padding: 16px 20px;
    background: white;
    border-bottom: 1px solid var(--gray-200);
}

.kb-search-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.kb-search-input-wrapper:focus-within {
    border-color: var(--hawx-teal);
    box-shadow: 0 0 0 3px rgba(99, 118, 117, 0.1);
}

.kb-search-icon {
    width: 18px;
    height: 18px;
    color: var(--gray-400);
    flex-shrink: 0;
}

.kb-search-input-wrapper input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 13px;
    color: var(--gray-700);
    outline: none;
}

.kb-search-input-wrapper input::placeholder {
    color: var(--gray-400);
}

.kb-search-btn {
    padding: 6px 10px;
    background: var(--hawx-teal);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kb-search-btn:hover {
    background: var(--hawx-teal-dark);
}

.kb-search-btn svg {
    width: 16px;
    height: 16px;
}

/* Empty State */
.kb-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: var(--gray-400);
}

.kb-empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.kb-empty-state p {
    margin: 0;
    font-size: 14px;
    line-height: 1.6;
    max-width: 280px;
}

/* Results Wrapper */
.kb-results-wrapper {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* Answer Section */
.kb-answer-section {
    padding: 16px 20px;
    background: white;
    border-bottom: 1px solid var(--gray-200);
}

.kb-section-header {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray-500);
    margin: 0 0 12px 0;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--gray-100);
}

.kb-answer-content {
    font-size: 13px;
    line-height: 1.7;
    color: var(--gray-700);
}

.kb-answer-content p {
    margin: 0 0 12px 0;
}

.kb-answer-content p:last-child {
    margin-bottom: 0;
}

.kb-answer-content ul,
.kb-answer-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.kb-answer-content li {
    margin-bottom: 4px;
}

.kb-answer-content code {
    background: var(--gray-100);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--mono);
    font-size: 12px;
}

.kb-answer-content strong {
    color: var(--gray-800);
}

.kb-citation-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    background: var(--hawx-teal-light);
    color: var(--hawx-teal-dark);
    font-size: 10px;
    font-weight: 600;
    text-decoration: none;
    border-radius: 4px;
    margin: 0 2px;
    transition: background 0.2s ease;
}

.kb-citation-link:hover {
    background: var(--hawx-teal);
    color: white;
}

/* Sources Section */
.kb-sources-section {
    padding: 16px 20px;
    flex: 1;
}

/* Individual Source Result */
.knowledge-search-result {
    padding: 12px 14px;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.knowledge-search-result:hover {
    border-color: var(--hawx-teal);
    box-shadow: 0 2px 8px rgba(99, 118, 117, 0.15);
    transform: translateY(-1px);
}

.knowledge-search-result:last-child {
    margin-bottom: 0;
}

.knowledge-search-result h3 {
    margin: 0 0 6px 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-800);
    line-height: 1.4;
}

.knowledge-search-result h3 a {
    color: var(--hawx-teal-dark);
    text-decoration: none;
}

.knowledge-search-result h3 a:hover {
    text-decoration: underline;
}

.knowledge-search-result p {
    margin: 0;
    font-size: 12px;
    color: var(--gray-500);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Loading States */
.kb-loading-state {
    padding: 20px;
    text-align: center;
}

.kb-loading-state h3 {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 0;
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-500);
}

.kb-error-state {
    padding: 16px;
    background: var(--error-bg);
    color: var(--error-dark);
    border-radius: 8px;
    font-size: 13px;
    text-align: center;
}

/* ─────────────────────────────────────────────────────────────────────────────
Settings Section Styles
───────────────────────────────────────────────────────────────────────────── */
.settings-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
}

.settings-item:not(:last-child) {
    border-bottom: 1px solid var(--gray-200);
}

.settings-item-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-700);
}

.settings-item-label svg {
    width: 18px;
    height: 18px;
    color: var(--hawx-teal);
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--gray-300);
    transition: 0.3s;
    border-radius: 24px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 1px;
    bottom: 2px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--hawx-teal);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(20px);
}

.toggle-switch input:focus + .toggle-slider {
    box-shadow: 0 0 0 2px rgba(99, 118, 117, 0.2);
}

/* Dark mode toggle icon animation */
[data-theme="dark"] .settings-item-label svg {
    color: var(--hawx-gold);
}

/* Settings Link (clickable item like Config page) */
a.settings-link {
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    border-radius: 6px;
    margin: 0 -8px;
    padding: 12px 8px;
    transition: background-color 0.15s ease;
}

a.settings-link:hover {
    background-color: var(--gray-100);
}

[data-theme="dark"] a.settings-link:hover {
    background-color: var(--gray-200);
}

[data-theme="dark"] .settings-item:not(:last-child) {
    border-bottom-color: var(--gray-700);
}

[data-theme="dark"] .settings-item-label {
    color: var(--text-secondary);
}

[data-theme="dark"] .settings-link-arrow {
    color: var(--gray-500);
}

[data-theme="dark"] a.settings-link:hover .settings-link-arrow {
    color: var(--hawx-gold);
}

.settings-link-arrow {
    width: 16px;
    height: 16px;
    color: var(--gray-400);
    transition: transform 0.15s ease, color 0.15s ease;
}

a.settings-link:hover .settings-link-arrow {
    transform: translateX(2px);
    color: var(--hawx-teal);
}

/* Responsive - make sidebar full width on small screens */
@media (max-width: 500px) {
    .kb-sidebar {
        width: 100%;
        left: -100%;
    }
}

