﻿/* =========================================================================
   ePurchase AI Assistant — global theme
   Single stylesheet, CSS custom properties, [data-theme="dark"] override.
   :root already IS the "white" (light) theme — no data-theme attribute, or
   data-theme="white", both resolve to these values by normal CSS fallthrough.
   ========================================================================= */

:root {
    --sidebar-bg: #17879B;
    --sidebar-bg-end: #0F6B7D;
    --sidebar-hover: #1E9EB4;
    /* Teal (the Visualize/Predict button colour) is the main theme accent everywhere. */
    --primary: #17879B;
    --primary-600: #0F6B7D;
    --teal: #17879B;
    --teal-dark: #0F6B7D;
    --success: #22C55E;
    --warning: #F59E0B;
    --danger: #EF4444;
    --star: #FBBF24;
    /* Warm accent reserved for elements that sit ON the teal sidebar (logo, New chat) — teal-on-teal
       would have no contrast, so these use the existing amber/gold tokens instead. */
    --sidebar-accent: var(--star);
    --sidebar-accent-dark: var(--warning);
    --sidebar-accent-text: #1A2E33;
    --app-bg: #F4F5F8;
    --card: #FFFFFF;
    --text: #2D3748;
    --text-muted: #6B7280;
    --border: #E5E8EF;
    --dark-header: #0F6B7D;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 2px 8px rgba(16, 24, 40, .06);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, .12);
    --transition: all .18s ease;

    --focus-ring: 0 0 0 3px rgba(23, 135, 155, .25);
    --scrollbar-track: transparent;
    --scrollbar-thumb: #C7CCDA;
}

:root[data-theme="dark"] {
    --app-bg: #10182B;
    --card: #182240;
    --text: #E5E8F0;
    --text-muted: #9AA3B8;
    --border: #2B3658;
    --sidebar-bg: #0B2E38;
    --sidebar-bg-end: #051A20;
    --sidebar-hover: #114552;
    --dark-header: #073039;
    --shadow: 0 2px 8px rgba(0, 0, 0, .35);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
    --scrollbar-thumb: #35406A;
}

/* ---------- Reset / base ---------- */
* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    overflow: hidden;
}

body {
    background: var(--app-bg);
    color: var(--text);
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14.5px;
    transition: background-color .25s ease, color .25s ease;
}

a { color: var(--primary); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--primary-600); text-decoration: none; }

h1, h2, h3, h4, h5, h6 { color: var(--text); font-weight: 700; }

/* ---------- Custom scrollbars, everywhere ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb) transparent; }

*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
    background-color: var(--scrollbar-thumb);
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background-color: var(--primary); background-clip: content-box; }

/* =========================================================================
   Bootstrap primitive overrides — buttons, forms, dropdowns, modals, tables
   ========================================================================= */

/* Buttons */
.btn {
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: .85rem;
    transition: var(--transition);
    border-width: 1px;
}
.btn:focus, .btn.focus { box-shadow: var(--focus-ring); }
.btn:active { transform: translateY(1px); }

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-600));
    border-color: var(--primary-600);
    color: #fff;
}
.btn-primary:hover, .btn-primary:focus {
    background: linear-gradient(135deg, var(--primary-600), var(--primary-600));
    border-color: var(--primary-600);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}
.btn-primary:disabled, .btn-primary.disabled { opacity: .55; transform: none; }

.btn-secondary {
    background: var(--teal);
    border-color: var(--teal-dark);
    color: #fff;
}
.btn-secondary:hover { background: var(--teal-dark); border-color: var(--teal-dark); color: #fff; transform: translateY(-1px); }

.btn-outline-secondary, .btn-outline-primary {
    color: var(--text);
    border-color: var(--border);
    background: var(--card);
}
.btn-outline-secondary:hover, .btn-outline-primary:hover {
    border-color: var(--primary);
    color: var(--primary-600);
    background: rgba(23, 135, 155, .06);
    transform: translateY(-1px);
}

.btn-danger { background: var(--danger); border-color: var(--danger); }
.btn-danger:hover { filter: brightness(0.92); }

.btn-sm { padding: .32rem .7rem; }

/* Links styled as buttons / icon-only buttons */
.btn-icon {
    width: 32px; height: 32px; padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm);
    background: transparent; border: 1px solid transparent; color: var(--text-muted);
}
.btn-icon:hover { background: var(--app-bg); color: var(--primary); border-color: var(--border); }

/* Badges / pills */
.badge {
    border-radius: 999px;
    font-weight: 600;
    padding: .35em .65em;
}
.badge-success, .pill-connected { background: rgba(34, 197, 94, .14); color: #15803D; }
.badge-warning { background: rgba(245, 158, 11, .14); color: #92400E; }
.badge-primary { background: rgba(23, 135, 155, .14); color: var(--primary-600); }

.status-pill {
    display: inline-flex; align-items: center; gap: .35rem;
    padding: .3rem .7rem; border-radius: 999px; font-size: .74rem; font-weight: 700;
}
.status-pill.rating { background: rgba(251, 191, 36, .16); color: #92650B; }
.status-pill.rating i { color: var(--star); }

/* Forms */
.form-control, select.form-control, textarea.form-control {
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius-sm);
    transition: var(--transition);
    box-shadow: 0 1px 2px rgba(16, 24, 40, .03);
}
.form-control:focus {
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
    background: var(--card);
    color: var(--text);
}
.form-control::placeholder { color: var(--text-muted); opacity: .8; }
.form-control:disabled, .form-control[readonly] { background: var(--app-bg); opacity: .7; }

select.form-control {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3e%3cpath fill='%236B7280' d='M1 1l5 5 5-5'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right .7rem center;
    background-size: 10px 7px;
    padding-right: 1.9rem;
    border-radius: 10px;
    cursor: pointer;
}
select.form-control:hover {
    border-color: #C9CEDC;
    box-shadow: var(--shadow);
}
select.form-control:not([multiple]) { height: 36px; }
select.form-control[multiple] { padding: .4rem .6rem; }

input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); }

input[type="file"] { color: var(--text-muted); }
input[type="file"]::file-selector-button {
    border: 1px solid var(--border);
    background: var(--app-bg);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: .3rem .7rem;
    margin-right: .6rem;
    transition: var(--transition);
    cursor: pointer;
}
input[type="file"]::file-selector-button:hover { border-color: var(--primary); color: var(--primary-600); }

/* Dropdowns */
.dropdown-menu {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    padding: .35rem;
}
.dropdown-item {
    border-radius: 6px;
    color: var(--text);
    font-size: .87rem;
    padding: .45rem .7rem;
    transition: var(--transition);
}
.dropdown-item:hover, .dropdown-item:focus { background: rgba(23, 135, 155, .08); color: var(--primary-600); }
.dropdown-divider { border-color: var(--border); }

/* Modern custom dropdown — used everywhere in Visualize/Predict that used to be a native <select>,
   whose open option list can't be restyled to match the app theme. Fully self-contained: no
   Bootstrap/Popper dependency, just a class toggle plus a document-level click-outside listener
   (see modernSelect.js), so its open/close behavior can never be broken by a positioning library. */
.modern-select { position: relative; }
.modern-select-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    gap: .55rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: .5rem .8rem;
    font-size: .87rem;
    color: var(--text);
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 1px 2px rgba(16, 24, 40, .03);
}
.modern-select-toggle:hover { border-color: #C9CEDC; box-shadow: var(--shadow); }
.modern-select-toggle:focus, .modern-select-toggle[aria-expanded="true"] {
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
    outline: none;
}
.modern-select-icon { color: var(--primary-600); font-size: .8rem; flex-shrink: 0; }
.modern-select-label { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modern-select-caret { font-size: .65rem; color: var(--text-muted); transition: transform .15s ease; flex-shrink: 0; }
.modern-select-toggle[aria-expanded="true"] .modern-select-caret { transform: rotate(180deg); }

.modern-select-menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 1000;
    width: 100%;
    max-height: 320px;
    overflow-y: auto;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    padding: .35rem;
}
/* Entrance animation — restarts every time (display:none -> block re-triggers it), ~150ms per spec. */
.modern-select.open .modern-select-menu { display: block; animation: modern-select-fade-in .15s ease; }
@keyframes modern-select-fade-in {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}
.modern-select-search {
    position: sticky;
    top: 0;
    margin-bottom: .3rem;
    padding: 0 .15rem .35rem;
    background: var(--card);
    border-bottom: 1px solid var(--border);
}
.modern-select-search input {
    width: 100%;
    background: var(--app-bg);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: .4rem .6rem;
    font-size: .83rem;
    color: var(--text);
}
.modern-select-search input:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus-ring); }
.modern-select-group-label {
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    padding: .5rem .7rem .3rem;
}
.modern-select-divider { height: 1px; margin: .3rem 0; background: var(--border); }
.modern-select-item {
    display: flex;
    align-items: center;
    gap: .55rem;
    width: 100%;
    background: none;
    border: none;
    border-radius: 6px;
    color: var(--text);
    font-size: .87rem;
    padding: .45rem .7rem;
    transition: var(--transition);
    cursor: pointer;
    text-align: left;
}
.modern-select-item:hover, .modern-select-item:focus, .modern-select-item.highlighted {
    background: rgba(23, 135, 155, .08); color: var(--primary-600); outline: none;
}
.modern-select-item i:not(.modern-select-check) { color: var(--text-muted); font-size: .8rem; width: 14px; flex-shrink: 0; text-align: center; }
.modern-select-item .modern-select-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modern-select-item .modern-select-item-meta { font-size: .72rem; color: var(--text-muted); flex-shrink: 0; padding-left: .5rem; }
.modern-select-item .modern-select-check { color: var(--primary); font-size: .78rem; flex-shrink: 0; visibility: hidden; }
.modern-select-item.active { background: rgba(23, 135, 155, .1); color: var(--primary-600); font-weight: 600; }
.modern-select-item.active i { color: var(--primary-600); }
.modern-select-item.active .modern-select-check { visibility: visible; }
.modern-select-empty { padding: .5rem .7rem; font-size: .82rem; color: var(--text-muted); }

/* Hides a native <select> while keeping it fully functional in JS (.value, change events, options) —
   the custom .modern-select UI built around it is the only thing actually shown/interacted with. */
.modern-select-native-proxy { display: none !important; }

/* Modals */
.modal-content {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}
.modal-header {
    background: var(--dark-header);
    color: #fff;
    border-radius: var(--radius) var(--radius) 0 0;
    border-bottom: none;
    padding: 1rem 1.25rem;
}
.modal-header .close { color: #fff; opacity: .85; text-shadow: none; }
.modal-header .close:hover { opacity: 1; }
.modal-title { font-weight: 700; }
.modal-footer { border-top: 1px solid var(--border); }
.modal-backdrop.show { opacity: .5; }

/* Tooltips / popovers */
.tooltip .tooltip-inner {
    background: var(--dark-header);
    color: #fff;
    border-radius: 6px;
    font-size: .78rem;
    padding: .4rem .65rem;
}
.bs-tooltip-top .arrow::before { border-top-color: var(--dark-header); }
.bs-tooltip-bottom .arrow::before { border-bottom-color: var(--dark-header); }
.bs-tooltip-left .arrow::before { border-left-color: var(--dark-header); }
.bs-tooltip-right .arrow::before { border-right-color: var(--dark-header); }

.popover {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
}
.popover-header { background: var(--dark-header); color: #fff; border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.popover-body { color: var(--text); }

/* Tables / DataTables */
.table-wrap {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
table.table {
    color: var(--text);
    margin-bottom: 0;
}
table.table thead th {
    background: var(--dark-header);
    color: #fff;
    border: none;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    font-weight: 700;
    padding: .75rem 1rem;
    vertical-align: middle;
}
table.table tbody td {
    border-color: var(--border);
    padding: .65rem 1rem;
    vertical-align: middle;
    font-size: .87rem;
}
table.table-striped tbody tr:nth-of-type(odd) { background: var(--app-bg); }
table.table tbody tr:hover { background: rgba(23, 135, 155, .05); }
table.dataTable { width: 100% !important; }

/* Cards */
.card-modern {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: var(--transition);
}

/* =========================================================================
   App shell
   ========================================================================= */

.chat-app { display: flex; height: 100vh; width: 100%; }

/* ---------- Sidebar ---------- */
.chat-list-sidebar {
    position: relative;
    width: 280px;
    min-width: 200px;
    max-width: 440px;
    flex-shrink: 0;
    background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-end) 100%);
    display: flex;
    flex-direction: column;
    padding: 1.1rem .9rem;
    color: #C7CCE0;
    transition: width .2s ease, min-width .2s ease, padding .2s ease, transform .25s ease;
}
.chat-list-sidebar.resizing { transition: none; }

/* Live-reproduced (2026-10-04): there was no way to close the sidebar on a normal desktop width at
   all — only a mobile off-canvas toggle existed — so .chat-main could never actually grow to use that
   reclaimed space the way a user closing the sidebar would expect. Collapsing to a true zero width
   (not just hiding content) lets .chat-main's own flex:1 naturally expand to fill the rest of the row;
   scoped to desktop widths only so it never fights the mobile off-canvas .open behavior below. */
@media (min-width: 761px) {
    .chat-list-sidebar.collapsed {
        width: 0 !important;
        min-width: 0;
        max-width: 0;
        padding-left: 0;
        padding-right: 0;
        overflow: hidden;
        border: none;
    }
}

/* Drag handle on the sidebar's right edge — resizes the sidebar, width persisted via cookie. */
.sidebar-resize-handle {
    position: absolute;
    top: 0;
    right: -3px;
    bottom: 0;
    width: 6px;
    cursor: col-resize;
    z-index: 20;
    background: transparent;
}
.sidebar-resize-handle:hover, .sidebar-resize-handle.active { background: rgba(255, 255, 255, .18); }

/* Fixed top (brand + actions + search) and fixed footer, with only the Recents list scrolling. */
.sidebar-top { flex-shrink: 0; }

.chat-list-brand {
    display: flex;
    align-items: center;
    gap: .65rem;
    font-weight: 700;
    font-size: 1.02rem;
    color: #fff;
    margin-bottom: 1rem;
    padding: 0 .2rem;
}

.sidebar-collapse-btn {
    margin-left: auto;
    display: inline-flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; border-radius: var(--radius-sm);
    border: none; background: transparent; color: #C7CCE0;
    cursor: pointer; flex-shrink: 0;
    transition: var(--transition);
}
.sidebar-collapse-btn:hover { background: var(--sidebar-hover); color: #fff; }
/* Mobile already has its own dedicated off-canvas toggle (see the max-width:760px block below) —
   this in-sidebar button is a desktop-only affordance. */
@media (max-width: 760px) {
    .sidebar-collapse-btn { display: none; }
}

.chat-list-brand .logo-dot {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    /* Warm accent, not teal — a teal tile on the teal sidebar would have no contrast. */
    background: linear-gradient(135deg, var(--sidebar-accent), var(--sidebar-accent-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: var(--sidebar-accent-text);
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(245, 158, 11, .35);
}

/* Top actions — "New chat" etc. — icon left, label right, comfortable hit area. */
.sidebar-actions { list-style: none; padding: 0; margin: 0 0 .85rem; }
.sidebar-action-item {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .62rem .7rem;
    border-radius: var(--radius-sm);
    font-size: .92rem;
    font-weight: 600;
    color: #fff;
    cursor: pointer;
    transition: var(--transition);
}
.sidebar-action-item:hover { background: var(--sidebar-hover); }
.sidebar-action-item i {
    color: var(--sidebar-accent);
    width: 16px;
    text-align: center;
    font-size: .88rem;
    flex-shrink: 0;
}

.chat-search {
    position: relative;
    margin-bottom: .5rem;
}
.chat-search i {
    position: absolute; left: .65rem; top: 50%; transform: translateY(-50%);
    color: #7C86A8; font-size: .78rem;
}
.chat-search input {
    width: 100%;
    background: rgba(255, 255, 255, .06);
    border: 1px solid rgba(255, 255, 255, .08);
    color: #E5E8F0;
    border-radius: var(--radius-sm);
    padding: .45rem .6rem .45rem 1.9rem;
    font-size: .82rem;
    transition: var(--transition);
}
.chat-search input:focus {
    outline: none;
    background: rgba(255, 255, 255, .1);
    border-color: var(--sidebar-accent);
}
.chat-search input::placeholder { color: #7C86A8; }

/* Scrollable middle section — only the Recents list scrolls; top actions and footer stay fixed. */
.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    margin: .25rem -.3rem 0;
    padding: 0 .3rem;
}

.sidebar-section-label {
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #8891AC;
    padding: 0 .5rem;
    margin: .5rem 0 .5rem;
}

#chatListItems { display: flex; flex-direction: column; }

.chat-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .4rem;
    padding: .6rem .75rem;
    border-radius: var(--radius-sm);
    font-size: .89rem;
    color: #AEB4CC;
    cursor: pointer;
    margin-bottom: 2px;
    transition: var(--transition);
}
.chat-item:hover { background: var(--sidebar-hover); color: #fff; }
.chat-item.active {
    /* A soft tint of the sidebar's own teal (white overlay lightens whatever sits beneath it) —
       matches the reference's rounded active-chat highlight without introducing a new colour. */
    background: rgba(255, 255, 255, .16);
    color: #fff;
    font-weight: 600;
}
.chat-item .chat-item-title {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0;
}
.chat-item .chat-item-actions {
    display: flex; gap: .15rem; opacity: 0; transition: opacity .15s ease; flex-shrink: 0;
}
.chat-item:hover .chat-item-actions { opacity: 1; }
.chat-item .chat-item-actions button {
    width: 22px; height: 22px; padding: 0;
    border: none; background: transparent; color: #AEB4CC;
    border-radius: 5px; font-size: .68rem;
    display: flex; align-items: center; justify-content: center;
}
.chat-item .chat-item-actions button:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.chat-item .chat-item-actions button.delete-btn:hover { color: #FCA5A5; }

.sidebar-footer {
    flex-shrink: 0;
    border-top: 1px solid rgba(255, 255, 255, .08);
    margin-top: .75rem;
    padding-top: .75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
}

#darkModeToggle, #learningAdminBtn, #logoutBtn, #adminPanelBtn {
    width: 32px; height: 32px; padding: 0; flex-shrink: 0;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, .06);
    border: 1px solid rgba(255, 255, 255, .1);
    color: #C7CCE0;
    display: flex; align-items: center; justify-content: center;
    transition: var(--transition);
}
#darkModeToggle:hover, #learningAdminBtn:hover, #adminPanelBtn:hover { background: rgba(255, 255, 255, .12); color: #fff; }
#logoutBtn:hover { background: rgba(239, 68, 68, .25); color: #fff; border-color: rgba(239, 68, 68, .4); }

/* ---------- Sidebar collapse (mobile) ---------- */
.sidebar-toggle-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--card); color: var(--text);
    cursor: pointer;
}
/* On desktop, closing is done via .sidebar-collapse-btn INSIDE the sidebar itself (avoids this
   fixed-position button sitting on top of the sidebar's own brand/logo while it's open) — this
   floating button is desktop-visible only once collapsed, to re-open. Mobile (≤760px, see its own
   media query below) always shows it instead, since the sidebar there is off-canvas by default. */
@media (min-width: 761px) {
    .sidebar-toggle-btn { display: none; }
    .chat-app:has(.chat-list-sidebar.collapsed) .sidebar-toggle-btn { display: inline-flex; }
}

/* ---------- Main chat column ---------- */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--app-bg);
    position: relative;
}

.chat-toolbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: .85rem 1.4rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .75rem;
    position: relative;
    z-index: 2;
    box-shadow: var(--shadow);
}
.chat-toolbar::after {
    content: "";
    position: absolute;
    left: 0; right: 0; bottom: -1px;
    height: 2px;
    background: linear-gradient(90deg, var(--teal), var(--teal-dark));
    opacity: .5;
}

.source-controls { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; font-size: .82rem; }

/* Source/file pickers in the toolbar — same modern-select component, just width-constrained to sit
   comfortably in a horizontal toolbar row instead of stretching to fill it. */
.source-controls .modern-select { min-width: 172px; max-width: 230px; }
#sourceFileGroup:not(.d-none) { display: contents; }

.upload-file-btn {
    display: inline-flex; align-items: center; gap: .4rem;
    border: 1.5px dashed var(--border);
    background: var(--card);
    color: var(--text);
    border-radius: 999px;
    padding: .38rem .9rem;
    font-size: .8rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}
.upload-file-btn:hover { border-color: var(--primary); color: var(--primary-600); background: rgba(23, 135, 155, .06); border-style: solid; transform: translateY(-1px); }
.upload-file-btn.drag-over { border-color: var(--teal); background: rgba(23, 135, 155, .08); color: var(--teal-dark); border-style: solid; }

.tool-buttons { display: flex; gap: .6rem; }

.tool-pill {
    display: inline-flex; align-items: center; gap: .45rem;
    border: none;
    border-radius: 999px;
    padding: .45rem 1rem;
    font-size: .82rem;
    font-weight: 700;
    color: #fff;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow);
}
.tool-pill.viz, .tool-pill.predict { background: linear-gradient(135deg, var(--teal), var(--teal-dark)); }
.tool-pill:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); filter: brightness(1.04); }
.tool-pill:active { transform: translateY(0); }

/* ---------- Messages ---------- */
/* Live-reproduced (2026-10-04): a flat 760px cap left a large, unused band of empty space on any
   normal-or-wider screen, especially painful for this app's own data-heavy table answers (several
   columns of PO/RC/PR data compressed/wrapped into a column barely wider than a phone). Widened
   substantially and left responsive (min() against the viewport) so it still never gets uncomfortably
   wide on an ultra-wide monitor, but genuinely uses the available width on anything ordinary — and,
   with .chat-list-sidebar.collapsed (see below), the full remaining width once the sidebar is closed.
   Chat area is the only other remaining ingredient. */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 1.5rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-width: min(1400px, 96%);
    width: 100%;
    margin: 0 auto;
    border: 2px dashed transparent;
    border-radius: var(--radius);
    transition: border-color .15s ease, background .15s ease, max-width .2s ease;
}
/* Dropping a chart/forecast card here (dragged from Visualize/Predict) pins it into the chat. */
.chat-messages.drop-target { border-color: var(--primary); background: rgba(23, 135, 155, .04); }

.chat-turn-separator {
    text-align: center;
    font-size: .72rem;
    color: var(--text-muted);
    margin: .25rem 0 -.5rem;
}

.chat-empty-state {
    margin: auto;
    text-align: center;
    max-width: 480px;
    color: var(--text-muted);
}
.chat-empty-state .empty-icon {
    width: 64px; height: 64px; border-radius: 18px;
    background: linear-gradient(135deg, rgba(23, 135, 155, .12), rgba(23, 135, 155, .12));
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto .9rem;
    font-size: 1.6rem;
    color: var(--primary);
}
.chat-empty-state h5 { color: var(--text); margin-bottom: .35rem; }

.suggested-chips {
    display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; margin-top: 1.1rem;
}
.suggested-chip {
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 999px;
    padding: .45rem .95rem;
    font-size: .8rem;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow);
}
.suggested-chip:hover { border-color: var(--primary); color: var(--primary-600); transform: translateY(-2px); box-shadow: var(--shadow-lg); }

/* User turns are right-aligned bubbles; assistant turns are plain flowing text at full column width. */
.ai-msg-row { display: flex; gap: .75rem; width: 100%; animation: msg-in .22s ease; }
.ai-msg-row.user { justify-content: flex-end; }
.ai-msg-row.assistant { justify-content: flex-start; align-items: flex-start; }

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

.ai-avatar {
    width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: .68rem; font-weight: 800; color: #fff;
    margin-top: 2px;
    background: linear-gradient(135deg, var(--teal), var(--teal-dark));
}

.ai-msg {
    font-size: 16px;
    line-height: 1.75;
    position: relative;
    min-width: 0;
}

.ai-msg-row.user .ai-msg {
    max-width: 75%;
    padding: .7rem 1.05rem;
    border-radius: 18px;
    border-top-right-radius: 5px;
    background: linear-gradient(135deg, rgba(23, 135, 155, .14), rgba(23, 135, 155, .1));
    color: var(--text);
    border: 1px solid rgba(23, 135, 155, .18);
}

.ai-msg-row.assistant .ai-msg {
    flex: 1;
    min-width: 0;
    /* Plain flowing text — no bubble, no card. */
    background: none;
    border: none;
    box-shadow: none;
    padding: 0;
    border-radius: 0;
    color: var(--text);
}

.ai-msg .msg-body p { margin: 0 0 1rem; }
.ai-msg .msg-body :first-child { margin-top: 0; }
.ai-msg .msg-body :last-child { margin-bottom: 0; }
.ai-msg .msg-body ul, .ai-msg .msg-body ol {
    margin: 0 0 1rem;
    padding-left: 1.5rem;
}
.ai-msg .msg-body ul { list-style: disc; }
.ai-msg .msg-body ol { list-style: decimal; }
.ai-msg .msg-body li { margin-bottom: .4rem; }
.ai-msg .msg-body li:last-child { margin-bottom: 0; }
.ai-msg .msg-body strong { font-weight: 700; }
.ai-msg .msg-body pre {
    background: var(--dark-header);
    color: #E5E8F0;
    border-radius: var(--radius-sm);
    padding: .75rem .9rem;
    overflow-x: auto;
    font-size: .85rem;
    margin: 0 0 1rem;
}
.ai-msg .msg-body code {
    background: rgba(23, 135, 155, .1);
    color: var(--primary-600);
    border-radius: 4px;
    padding: .1em .35em;
    font-size: .87em;
}
.ai-msg .msg-body pre code { background: none; color: inherit; padding: 0; }

/* Result tables inside a chat answer (marked.js renders a bare, unstyled <table> — chat.js wraps each
   one in .msg-table-scroll and adds the .msg-table class right after sanitizing; see renderMarkdown).
   Clear column separation via light dividers + row striping, comfortable padding, a bold header, and a
   horizontal-scroll container so a wide result keeps every column at a readable width instead of being
   squeezed to fit — long cell values (GUIDs, titles) wrap within their own column instead of bleeding
   into the next one. Reuses the exact same theme tokens as every other themed table (see table-wrap above). */
.ai-msg .msg-table-scroll {
    overflow-x: auto;
    margin: 0 0 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card);
}
/* A "show all" listing (up to 200 rows) also scrolls vertically inside a capped-height box, with a
   sticky header, instead of stretching the whole chat message that long — keeps the page itself light
   to scroll while still showing every row (see TALL_TABLE_ROW_THRESHOLD in chat.js). */
.ai-msg .msg-table-scroll-tall {
    max-height: 420px;
    overflow-y: auto;
}
.ai-msg .msg-table-scroll-tall table.msg-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
}
.ai-msg .msg-body table.msg-table {
    width: 100%;
    min-width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: .85rem;
    color: var(--text);
}
.ai-msg .msg-body table.msg-table th,
.ai-msg .msg-body table.msg-table td {
    padding: .6rem .9rem;
    text-align: left;
    vertical-align: top;
    max-width: 260px;
    overflow-wrap: anywhere;
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
}
.ai-msg .msg-body table.msg-table th:last-child,
.ai-msg .msg-body table.msg-table td:last-child {
    border-right: none;
}
.ai-msg .msg-body table.msg-table tr:last-child td { border-bottom: none; }
.ai-msg .msg-body table.msg-table thead th {
    background: var(--dark-header);
    color: #fff;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    font-weight: 700;
    white-space: nowrap;
}
.ai-msg .msg-body table.msg-table tbody tr:nth-of-type(odd) { background: var(--app-bg); }
.ai-msg .msg-body table.msg-table tbody tr:hover { background: rgba(23, 135, 155, .06); }
/* Right-aligned, non-wrapping numeric columns (see chat.js's isNumericColumn) — tabular-nums keeps
   digits lined up column to column. */
.ai-msg .msg-body table.msg-table td.msg-table-num,
.ai-msg .msg-body table.msg-table th.msg-table-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.ai-msg .msg-copy {
    position: absolute;
    top: -9px;
    right: 8px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: .66rem;
    padding: 1px 7px;
    cursor: pointer;
    opacity: 0;
    transition: opacity .15s ease;
    color: var(--text-muted);
}
.ai-msg-row.assistant .ai-msg .msg-copy { top: -6px; right: 0; }
.ai-msg:hover .msg-copy { opacity: 1; }
.ai-msg .msg-copy:hover { color: var(--primary-600); border-color: var(--primary); }

.ai-msg-row.rtl .ai-msg { direction: rtl; text-align: right; }
.ai-msg-row.assistant.rtl .ai-msg .msg-copy { right: auto; left: 0; }

.citation-chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .55rem; }
.citation-chip {
    display: inline-flex; align-items: center; gap: .3rem;
    background: rgba(23, 135, 155, .1);
    color: var(--teal-dark);
    border: 1px solid rgba(23, 135, 155, .2);
    border-radius: 999px;
    font-size: .68rem;
    padding: .18rem .6rem;
    cursor: default;
}
.citation-chip i { font-size: .6rem; }

.sql-query-toggle { margin-top: .55rem; }
.sql-query-toggle-link {
    display: inline-flex; align-items: center; gap: .35rem;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 999px;
    font-size: .68rem;
    padding: .18rem .6rem;
    cursor: pointer;
}
.sql-query-toggle-link:hover { color: var(--primary-600); border-color: var(--primary); }
.sql-query-toggle-link i { font-size: .6rem; }
.sql-query-block {
    margin: .5rem 0 0;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: .6rem .75rem;
    font-size: .74rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text);
    max-height: 260px;
    overflow-y: auto;
}
.sql-query-block code { color: inherit; background: none; padding: 0; }

/* ---------- Feedback (thumbs up/down + correction) — drives the safe learning layer ---------- */
.msg-feedback-row { display: flex; align-items: center; gap: .3rem; margin-top: .55rem; }
.feedback-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 26px; height: 26px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 999px;
    font-size: .72rem;
    cursor: pointer;
    transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.feedback-btn:hover { color: var(--primary-600); border-color: var(--primary); }
.feedback-btn.active.up { color: #fff; background: #22C55E; border-color: #22C55E; }
.feedback-btn.active.down { color: #fff; background: #EF4444; border-color: #EF4444; }
.feedback-learned-hint { font-size: .68rem; color: var(--text-muted); margin-left: .2rem; }

.feedback-correction-box { margin-top: .5rem; display: flex; flex-direction: column; gap: .4rem; max-width: 420px; }
.feedback-correction-box input,
.feedback-correction-box textarea {
    font-size: .78rem;
    padding: .35rem .6rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
}
.feedback-correction-box textarea.feedback-correction-sql {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: .74rem;
    resize: vertical;
    min-height: 4.2em;
}
.feedback-correction-box button {
    align-self: flex-end;
    font-size: .72rem;
    padding: .3rem .7rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--primary);
    background: var(--primary);
    color: #fff;
    cursor: pointer;
}

.ai-typing-row { align-self: flex-start; display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; }
.ai-typing {
    display: inline-flex; gap: 4px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    border-top-left-radius: 4px;
    padding: .65rem .9rem;
    box-shadow: var(--shadow);
}
.ai-typing span {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--primary);
    animation: typing-bounce 1.2s infinite ease-in-out;
}
.ai-typing span:nth-child(2) { animation-delay: .15s; }
.ai-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes typing-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }
/* Shown only after SLOW_QUERY_HINT_MS (chat.js) so an ordinary fast answer never flashes it. */
.ai-typing-hint {
    flex-basis: 100%;
    margin-left: calc(2rem + .6rem); /* aligns under the bubble, past the avatar */
    font-size: .78rem;
    color: var(--text-muted);
}

.scroll-to-bottom-btn {
    position: absolute;
    left: 50%;
    bottom: 6.75rem;
    transform: translateX(-50%);
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--primary);
    box-shadow: var(--shadow-lg);
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    z-index: 5;
}
.scroll-to-bottom-btn.show { display: flex; }
.scroll-to-bottom-btn:hover { transform: translateX(-50%) translateY(-2px); }

/* ---------- Input bar ---------- */
/* Floating pill, centered to the same readable column as the messages — not a full-width bar. */
.chat-input-bar {
    background: transparent;
    padding: 0 1.5rem 1.75rem;
}
.chat-input-col {
    max-width: 760px;
    width: 100%;
    margin: 0 auto;
}
.chat-input-inner {
    display: flex;
    gap: .55rem;
    align-items: center;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: .45rem .5rem .45rem .6rem;
    box-shadow: var(--shadow-lg);
    transition: var(--transition);
}
.chat-input-inner:focus-within { border-color: var(--primary); box-shadow: var(--focus-ring), var(--shadow-lg); }

.input-icon-btn {
    width: 36px; height: 36px; padding: 0;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--app-bg);
    color: var(--text-muted);
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}
.input-icon-btn:hover { border-color: var(--primary); color: var(--primary-600); background: rgba(23, 135, 155, .06); }

.chat-input-inner textarea {
    flex: 1;
    resize: none;
    border: none;
    background: transparent;
    padding: .6rem .2rem;
    font-size: 1rem;
    line-height: 1.5;
    max-height: 140px;
    color: var(--text);
}
.chat-input-inner textarea:focus { outline: none; }
.chat-input-inner textarea::placeholder { color: var(--text-muted); }

.ai-send-btn {
    background: linear-gradient(135deg, var(--primary), var(--primary-600));
    color: #fff;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 14px rgba(23, 135, 155, .35);
}
.ai-send-btn:hover { transform: translateY(-2px) scale(1.03); box-shadow: 0 6px 18px rgba(23, 135, 155, .45); }
.ai-send-btn:active { transform: translateY(0) scale(1); }
.ai-send-btn:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }
.ai-send-btn.stop-mode { background: #3a3a3a; box-shadow: 0 4px 14px rgba(0, 0, 0, .35); }
.ai-send-btn.stop-mode:hover { background: #4a4a4a; box-shadow: 0 6px 18px rgba(0, 0, 0, .45); }
.ai-send-btn.stop-mode i { font-size: .8em; }

.input-hint { text-align: center; font-size: .68rem; color: var(--text-muted); margin-top: .5rem; }
.input-hint kbd {
    background: var(--app-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0 .3rem;
    font-size: .65rem;
    color: var(--text-muted);
}

/* =========================================================================
   Tools panel (Visualize / Predict) — slides from the right, half screen
   ========================================================================= */

.tools-panel-backdrop {
    position: fixed; inset: 0;
    background: rgba(16, 24, 40, .35);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
    z-index: 1040;
}
.tools-panel-backdrop.show { opacity: 1; pointer-events: auto; }

.tools-panel {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: 50vw;
    background: var(--app-bg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform .32s cubic-bezier(.22, 1, .36, 1);
    z-index: 1045;
}

.tools-panel.open { transform: translateX(0); }

.tools-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .85rem 1.1rem;
    background: var(--dark-header);
    color: #fff;
}

.tools-tabs { display: flex; gap: .3rem; }

.tools-tab-btn {
    background: rgba(255, 255, 255, .08);
    border: none;
    color: #C7CCE0;
    border-radius: 999px;
    padding: .4rem .9rem;
    font-size: .82rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}
.tools-tab-btn:hover { background: rgba(255, 255, 255, .14); color: #fff; }
.tools-tab-btn.active { background: linear-gradient(135deg, var(--teal), var(--teal-dark)); color: #fff; }

.tools-panel-header .btn-icon { color: #C7CCE0; }
.tools-panel-header .btn-icon:hover { background: rgba(255, 255, 255, .12); color: #fff; }

.tools-panel-body { flex: 1; overflow-y: auto; padding: 1.1rem; }

.chart-type-pills { display: flex; flex-wrap: wrap; gap: .35rem; }
.chart-type-pill {
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    border-radius: 999px;
    padding: .3rem .8rem;
    font-size: .76rem;
    cursor: pointer;
    transition: var(--transition);
}
.chart-type-pill:hover { border-color: var(--primary); color: var(--primary-600); }
.chart-type-pill.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.viz-chart-card, .predict-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.15rem;
    margin-bottom: 1.1rem;
    box-shadow: var(--shadow);
    transition: box-shadow .18s ease, transform .18s ease, border-color .18s ease;
    cursor: grab;
}
.viz-chart-card:hover, .predict-card:hover { box-shadow: var(--shadow-lg); border-color: rgba(23, 135, 155, .3); }
.viz-chart-card:active, .predict-card:active { cursor: grabbing; }
.viz-chart-card.dragging, .predict-card.dragging { opacity: .5; }

.viz-chart-card .viz-chart-header, .predict-card .predict-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: .85rem;
    font-weight: 700;
    margin-bottom: .9rem;
    color: var(--text);
}
.chart-card-title { display: flex; align-items: center; gap: .55rem; min-width: 0; }
.chart-drag-handle { color: var(--text-muted); font-size: .8rem; cursor: grab; flex-shrink: 0; }
.chart-card-actions { display: flex; gap: .15rem; flex-shrink: 0; }
.chart-card-actions .btn-icon { width: 26px; height: 26px; font-size: .78rem; }

.predict-explanation {
    background: rgba(23, 135, 155, .06);
    border: 1px solid rgba(23, 135, 155, .15);
    border-radius: var(--radius-sm);
    padding: .7rem .85rem;
    margin-top: .7rem;
    font-size: .84rem;
    color: var(--text);
}

.chart-render-error { color: var(--text-muted); }

/* =========================================================================
   ApexCharts — right-side legend, modern tooltips, theme-adaptive chrome.
   Applies to every chart in the app (Visualize, Predict, pinned-in-chat) —
   these are global element/class selectors targeting ApexCharts' own
   generated markup, not app-specific containers.
   ========================================================================= */

.viz-chart-canvas, .predict-chart-canvas, .pinned-chart-canvas { min-height: 320px; }

/* The legend column: a clean vertical list beside the chart, not a wrapped block beneath it.
   Scrolls with the app's themed scrollbar (see the global *::-webkit-scrollbar rules) instead of
   growing the card when there are many series. */
.apexcharts-legend {
    max-width: 38%;
    max-height: 320px;
    overflow-y: auto;
    padding: .25rem .25rem .25rem .75rem !important;
}
.apexcharts-legend-series {
    display: flex !important;
    align-items: center !important;
    margin: .3rem 0 !important;
}
.apexcharts-legend-marker { border-radius: 3px !important; flex-shrink: 0; }
.apexcharts-legend-text {
    display: inline-block;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}

/* Themed tooltips (replaces ApexCharts' plain default box). */
.apexcharts-tooltip {
    background: var(--card) !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-sm) !important;
    box-shadow: var(--shadow-lg) !important;
    color: var(--text) !important;
    overflow: hidden;
}
.apexcharts-tooltip-title {
    background: var(--app-bg) !important;
    border-bottom: 1px solid var(--border) !important;
    font-weight: 700 !important;
    color: var(--text) !important;
}
.apexcharts-xaxistooltip, .apexcharts-yaxistooltip {
    background: var(--card) !important;
    border: 1px solid var(--border) !important;
    color: var(--text) !important;
}
.apexcharts-xaxistooltip-bottom:after, .apexcharts-xaxistooltip-bottom:before { border-bottom-color: var(--card) !important; }
.apexcharts-tooltip .apexcharts-tooltip-series-group { color: var(--text); }

/* Axis/gridline chrome in the muted theme colour rather than the library's hardcoded gray. */
.apexcharts-gridline { stroke: var(--border); }
.apexcharts-text, .apexcharts-yaxis-label, .apexcharts-xaxis-label, .apexcharts-datalabel-label { fill: var(--text-muted); }

/* Zoom/pan toolbar — enabled only on line/scatter (dense-data charts); themed to match instead of
   the library's plain gray default. */
.apexcharts-toolbar { gap: 2px; }
.apexcharts-toolbar svg { fill: var(--text-muted) !important; transition: fill .15s ease; }
.apexcharts-toolbar > div:hover svg, .apexcharts-selected svg { fill: var(--primary) !important; }
.apexcharts-menu {
    background: var(--card) !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-sm) !important;
    box-shadow: var(--shadow-lg) !important;
}
.apexcharts-menu-item { color: var(--text) !important; font-size: .8rem !important; }
.apexcharts-menu-item:hover { background: rgba(23, 135, 155, .08) !important; }

@media (max-width: 700px) {
    .apexcharts-legend { max-width: 100%; max-height: 160px; }
}

/* Internet speed pill — top-right corner of the chat toolbar and the admin top bar. */
.net-speed { margin-left: auto; display: flex; align-items: center; }
.net-speed-pill {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .2rem .55rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text-muted);
    font-size: .7rem;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
    cursor: pointer;
}
.net-speed-pill i { font-size: .7rem; }
.net-speed-pill:hover { border-color: var(--primary); }
.net-speed-pill.fast { color: #15803d; border-color: rgba(21, 128, 61, .35); background: rgba(34, 197, 94, .08); }
.net-speed-pill.medium { color: #b45309; border-color: rgba(180, 83, 9, .35); background: rgba(245, 158, 11, .10); }
.net-speed-pill.slow, .net-speed-pill.offline { color: #b91c1c; border-color: rgba(185, 28, 28, .35); background: rgba(239, 68, 68, .08); }
.net-speed-pill.checking i { animation: net-speed-pulse 1.2s ease-in-out infinite; }
@keyframes net-speed-pulse { 50% { opacity: .35; } }
[data-theme="dark"] .net-speed-pill.fast { color: #4ade80; }
[data-theme="dark"] .net-speed-pill.medium { color: #fbbf24; }
[data-theme="dark"] .net-speed-pill.slow, [data-theme="dark"] .net-speed-pill.offline { color: #f87171; }

/* The table/summary a chart request also asked for, shown under the chart. */
.ai-msg.pinned-chart-msg .chart-followup-text {
    margin-top: .9rem;
    padding-top: .8rem;
    border-top: 1px solid var(--border);
}

/* A chart/forecast pinned inline into the chat (drag-and-drop from Visualize/Predict). */
.ai-msg.pinned-chart-msg {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .9rem;
    box-shadow: var(--shadow);
    max-width: 100%;
    width: 100%;
}
.pinned-chart-title {
    font-size: .85rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: .6rem;
    display: flex;
    align-items: center;
    gap: .45rem;
}
.pinned-chart-title i { color: var(--primary); }

/* =========================================================================
   File library modal / drag-drop
   ========================================================================= */

.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
    color: var(--text-muted);
    transition: var(--transition);
    cursor: pointer;
    background: var(--app-bg);
}
.dropzone.drag-over { border-color: var(--primary); background: rgba(23, 135, 155, .06); color: var(--primary-600); }
.dropzone i { font-size: 1.6rem; margin-bottom: .5rem; display: block; color: var(--primary); }

.file-row-actions { display: flex; gap: .35rem; }

/* =========================================================================
   Toasts (top-right)
   ========================================================================= */

.toast-stack {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1100;
    display: flex;
    flex-direction: column;
    gap: .6rem;
    max-width: 320px;
}
.epurchase-toast {
    background: var(--card);
    color: var(--text);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    padding: .7rem .9rem;
    font-size: .84rem;
    border-left: 4px solid var(--primary);
    opacity: 0;
    transform: translateX(12px);
    transition: opacity .2s ease, transform .2s ease;
}
.epurchase-toast.show { opacity: 1; transform: translateX(0); }

/* =========================================================================
   Skeleton loaders
   ========================================================================= */

.skeleton {
    background: linear-gradient(90deg, var(--border) 25%, rgba(255, 255, 255, .65) 37%, var(--border) 63%);
    background-size: 400% 100%;
    animation: skeleton-shimmer 1.4s ease infinite;
    border-radius: 6px;
}
:root[data-theme="dark"] .skeleton {
    background: linear-gradient(90deg, var(--border) 25%, rgba(255, 255, 255, .08) 37%, var(--border) 63%);
    background-size: 400% 100%;
}
@keyframes skeleton-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* =========================================================================
   Responsive
   ========================================================================= */

@media (max-width: 900px) {
    .tools-panel { width: 100vw; }
}

@media (max-width: 760px) {
    .chat-list-sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 1050;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }
    .chat-list-sidebar.open { transform: translateX(0); }
    .chat-messages { padding-left: 1rem; padding-right: 1rem; }
    .ai-msg-row.user .ai-msg { max-width: 88%; }
}
