:root {
    color-scheme: dark;
    --bg-color: #10151e;
    --card-bg: #19212e;
    --glass-border: #303d50;
    --primary-accent: #8bb5ff;
    --secondary-accent: #9faef5;
    --text-main: #e7edf7;
    --text-muted: #a8b6ca;
    --success: #83dcb2;
    --error: #ff9d9d;
    --bs-body-color: var(--text-main);
    --bs-body-bg: var(--bg-color);
    --bs-border-color: var(--glass-border);
    --bs-secondary-color: var(--text-muted);
    --bs-link-color: var(--primary-accent);
    --bs-link-hover-color: #bed4ff;
}
body { margin: 0; background: var(--bg-color); color: var(--text-main); font-family: system-ui, -apple-system, 'Segoe UI', 'Microsoft JhengHei', sans-serif; min-height: 100vh; line-height: 1.65; }
h1, h2, h3, h4, h5, h6 { color: #f2f5fa; font-family: inherit; font-weight: 650; line-height: 1.35; }
h1 { font-size: clamp(1.5rem, 2.2vw, 2rem); letter-spacing: -.025em; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1.05rem; }
a { color: var(--primary-accent); text-underline-offset: .2em; }
.text-muted { color: var(--text-muted) !important; }
.text-info, .text-accent { color: #98c7ff !important; }
.text-success { color: var(--success) !important; }
.text-warning { color: #efc784 !important; }
.text-danger { color: var(--error) !important; }
.app-shell { max-width: 1480px; padding-left: 32px; padding-right: 32px; }
.app-header { background: #151c28; border-bottom: 1px solid var(--glass-border); }
.navbar { min-height: 80px; padding: 12px 0; }
.navbar-brand { color: var(--text-main) !important; font-weight: 700; font-size: 1rem; margin-right: 32px; line-height: 1.4; }
.navbar-brand small { display: block; color: var(--text-muted); font-size: .6rem; letter-spacing: .16em; font-weight: 500; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; background: #8bb5ff; color: #172238; font-size: 1.4rem; }
.navbar .nav-link { color: #b7c4d7; font-size: .9rem; padding: .6rem .8rem; border-radius: 8px; }
.navbar .nav-link:hover, .navbar .nav-link[aria-current='page'] { color: #dbe8ff; background: #283b57; }
.dropdown-item[aria-current='page'] { background: #283b57; }
.skip-link { position: fixed; top: -100px; left: 16px; z-index: 2000; padding: 12px 20px; border-radius: 8px; background: #e7edf7; color: #10151e; }
.skip-link:focus { top: 12px; }
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible { outline: 3px solid #b0ceff; outline-offset: 3px; }
.glass-panel, .card { background: var(--card-bg); border: 1px solid var(--glass-border); border-radius: 14px; color: var(--text-main); box-shadow: 0 4px 16px #00000012; }
.card-body { padding: 24px; }
.card-footer { padding: 16px 24px 24px; }
.card-title, .card-text { overflow-wrap: anywhere; }
.btn { border-radius: 8px; font-weight: 600; padding: .6rem 1rem; transition: background-color .15s, border-color .15s; line-height: 1.5; }
.btn-sm { font-size: .8rem; padding: .45rem .7rem; }
.btn-primary, .btn-info { --bs-btn-color: #10203c; --bs-btn-bg: #8bb5ff; --bs-btn-border-color: #8bb5ff; --bs-btn-hover-color: #10203c; --bs-btn-hover-bg: #aecbff; --bs-btn-hover-border-color: #aecbff; --bs-btn-active-bg: #aecbff; --bs-btn-active-color: #10203c; --bs-btn-disabled-bg: #8bb5ff; --bs-btn-disabled-color: #10203c; }
.btn-secondary, .btn-outline-secondary { --bs-btn-color: #c3cede; --bs-btn-border-color: #526078; --bs-btn-bg: transparent; --bs-btn-hover-color: #fff; --bs-btn-hover-bg: #344257; --bs-btn-hover-border-color: #73839b; --bs-btn-disabled-color: #a8b6ca; --bs-btn-disabled-border-color: #526078; }
.btn-outline-primary, .btn-outline-info { --bs-btn-color: #a8caff; --bs-btn-border-color: #526f96; --bs-btn-hover-bg: #283e5e; --bs-btn-hover-color: #dceaff; --bs-btn-hover-border-color: #8bb5ff; }
.btn-outline-warning { --bs-btn-color: #efc784; --bs-btn-border-color: #7c6544; --bs-btn-hover-bg: #433825; --bs-btn-hover-color: #ffe0ac; }
.btn-outline-danger { --bs-btn-color: #ffabab; --bs-btn-border-color: #835353; --bs-btn-hover-bg: #4b2f35; --bs-btn-hover-color: #ffd5d5; }
.form-label { font-size: .85rem; font-weight: 600; margin-bottom: 8px; }
.form-control, .form-select { min-height: 44px; color: var(--text-main); background-color: #111a27; border: 1px solid #435168; border-radius: 8px; }
.form-control::placeholder { color: #91a1b8; opacity: 1; }
.form-control:focus, .form-select:focus { color: #fff; background-color: #111a27; border-color: #8bb5ff; box-shadow: 0 0 0 3px #8bb5ff26; }
.form-check-input { width: 1.1rem; height: 1.1rem; cursor: pointer; background-color: #131d2b; border-color: #6e7e96; }
.form-check-input:checked { background-color: #5888d5; border-color: #8bb5ff; }
.form-check-input:disabled { cursor: not-allowed; }
.table { --bs-table-bg: transparent; --bs-table-color: var(--text-main); --bs-table-border-color: #303d50; --bs-table-hover-bg: #233044; --bs-table-hover-color: #f2f5fa; }
.table > :not(caption) > * > * { padding: 16px; }
.table thead { font-size: .78rem; background: #141e2c; color: var(--text-muted); }
.table thead th { font-weight: 600; white-space: nowrap; }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin: 8px 0 32px; }
.eyebrow { color: #9cacbf; font-size: .75rem; font-weight: 600; margin-bottom: 8px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.section-heading h2 { margin: 0; }
.metrics-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.metric-card { display: flex; flex-direction: column; align-items: flex-start; padding: 20px; border: 1px solid var(--glass-border); background: var(--card-bg); border-radius: 12px; text-decoration: none; color: var(--text-main); }
.metric-card > span { font-size: .8rem; color: #c2cddd; }
.metric-card > strong { font-size: clamp(1.6rem, 2.3vw, 2.15rem); font-weight: 650; line-height: 1.3; margin: 10px 0; font-variant-numeric: tabular-nums; }
.metric-card small { font-size: .72rem; color: var(--text-muted); }
.metric-card strong small { font-size: 1rem; margin-left: 3px; }
.metric-attention { border-color: #735055; background: #281f2a; }
.metric-attention:hover { background: #382733; border-color: #b5787e; }
.filter-panel { padding: 24px; }
.filter-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.results-toolbar, .results-footer { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 16px; padding: 20px 24px; }
.results-toolbar h2 { margin-bottom: 4px; }
.result-count { padding: 2px 8px; border-radius: 6px; background: #2c3a4e; color: #b5cff6; font-size: .8rem; margin-left: 6px; }
.results-footer { border-top: 1px solid var(--glass-border); }
.operations-table { max-height: 70vh; scrollbar-color: #526078 #19212e; }
.operations-table thead th { position: sticky; top: 0; z-index: 1; background: #141e2c; }
.operations-table.is-empty thead { display: none; }
.document-cell { min-width: 180px; max-width: 290px; overflow-wrap: anywhere; }
.document-cell strong { font-size: .85rem; font-weight: 600; }
.diagnostic-cell { min-width: 150px; max-width: 260px; overflow-wrap: anywhere; }
.diagnostic-cell summary { cursor: pointer; }
.attempt-list { padding-left: 18px; margin: 8px 0 0; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; min-width: 136px; }
.status-badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; border-radius: 6px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.status-badge::before { content: ''; width: 5px; height: 5px; background: currentColor; border-radius: 50%; }
.status-success { color: #9be1bf; background: #203d34; }
.status-danger { color: #ffb2b2; background: #4b2a33; }
.status-warning { color: #f6d396; background: #443a27; }
.status-info { color: #adceff; background: #293e5d; }
.status-neutral { color: #c1c9d8; background: #333c4c; }
.tabular-nums { font-variant-numeric: tabular-nums; }
.empty-state { text-align: center; padding: 48px 16px; }
.empty-symbol { display: grid; place-items: center; width: 48px; height: 48px; margin: 0 auto 16px; background: #29394f; border-radius: 12px; font-size: 1.8rem; color: #adcaff; }
.empty-state p { font-size: .9rem; }
.quick-links { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; }
.quick-link { padding: 28px; text-decoration: none; }
.quick-link:hover { border-color: #8bb5ff; background: #202c3e; }
.quick-link p { color: var(--text-muted); margin-bottom: 24px; }
[aria-busy='true'] { cursor: progress; }
@media (max-width: 1199.98px) {
    .metrics-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .navbar-collapse { padding-top: 16px; }
    .navbar-nav { gap: 4px; }
}
@media (max-width: 767.98px) {
    .app-shell { padding-left: 16px; padding-right: 16px; }
    .page-heading { align-items: flex-start; flex-direction: column; gap: 16px; margin-bottom: 24px; }
    .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .metric-card { padding: 16px; }
    .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .filter-panel, .results-toolbar, .results-footer { padding: 16px; }
    .section-heading { flex-wrap: wrap; gap: 8px; }
    .quick-links { grid-template-columns: 1fr; }
}
@media (max-width: 420px) {
    .filter-grid { grid-template-columns: 1fr; }
    .results-footer nav { width: 100%; justify-content: space-between; }
}
/* Chat Overflows */
.chat-layout {
    min-height: 80vh;
}

.chat-store-selector {
    padding: 0.75rem 1rem;
}

.chat-store-selector .form-select[multiple] {
    min-height: 8rem;
}

.chat-input-group {
    align-items: flex-end;
    gap: 0.5rem;
}

.chat-input {
    resize: none;
    min-height: 2.5rem;
    max-height: 35vh;
    overflow-y: auto;
}

#chatHistory {
    max-height: 65vh;
    min-height: 65vh;
    scrollbar-width: thin;
    scrollbar-color: var(--glass-border) transparent;
}

@media (max-width: 767.98px) {
    #chatHistory {
        max-height: 55vh;
        min-height: 55vh;
    }

    .chat-store-selector {
        position: sticky;
        top: 0;
        z-index: 2;
    }

    .store-list-mobile {
        max-height: 35vh;
        overflow-y: auto;
    }
}

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

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

#chatHistory::-webkit-scrollbar-thumb {
    background-color: var(--glass-border);
    border-radius: 20px;
}

.store-list-item {
    position: relative;
    transition: all 0.2s ease;
}

.store-list-item .store-check {
    color: var(--primary-accent);
    opacity: 0;
    transform: scale(0.6);
    transition: all 0.2s ease;
}

.store-list-item.store-selected {
    background: rgba(0, 240, 255, 0.18);
    border-color: rgba(0, 240, 255, 0.4);
    box-shadow: 0 0 12px rgba(0, 240, 255, 0.25);
}

.store-list-item.store-selected .store-check {
    opacity: 1;
    transform: scale(1);
}

.selected-store-badge {
    font-weight: 600;
}

.ai-thinking {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-family: 'Orbitron', 'Inter', sans-serif;
    letter-spacing: 0.04em;
}

.ai-thinking-core {
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(0, 240, 255, 0.9) 0%, rgba(0, 240, 255, 0.2) 55%, transparent 70%);
    box-shadow: 0 0 12px rgba(0, 240, 255, 0.6);
    animation: aiPulse 1.6s ease-in-out infinite;
}

.ai-thinking-dots {
    display: flex;
    gap: 0.35rem;
}

.ai-thinking-dots span {
    width: 0.4rem;
    height: 0.4rem;
    border-radius: 50%;
    background: linear-gradient(145deg, var(--primary-accent), var(--secondary-accent));
    box-shadow: 0 0 10px rgba(112, 0, 255, 0.4);
    animation: aiDot 1.2s ease-in-out infinite;
}

.ai-thinking-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-thinking-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

.ai-thinking-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

@keyframes aiPulse {
    0%,
    100% {
        transform: scale(1);
        opacity: 0.85;
    }
    50% {
        transform: scale(1.2);
        opacity: 1;
    }
}

@keyframes aiDot {
    0%,
    100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    50% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* Keep chat selection and motion consistent with the shared interface. */
.store-list-item.store-selected { background: #283d59; border-color: #769dd3; box-shadow: none; }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
