﻿/* ===================================== */
/*            DESIGN TOKENS              */
/* ===================================== */

:root {
    --bg: #0f172a;
    --bg-2: #111827;
    --muted: #64748b;
    --border: #e5e7eb;
    --card: #ffffff;
    --text: #0f172a;
    --brand: #3f71b5;
    --brand-2: #65a8e9;
    --accent: #22c55e;
    --warn: #f59e0b;
    --danger: #ef4444;
    --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.08);
    --radius: 12px;
    --topbar-h: 56px;
    /* AI palette (for chat) */
    --ai-gradient-1: #1454f0;
    --ai-gradient-2: #2088ff;
    --ai-gradient-3: #3fd2ff;
    --ai-gradient-4: #a855f7;
    --ai-gradient-5: #f29ad8;
    --ai-bg-soft: #f5f7fc;
    --ai-border-soft: rgba(148, 163, 184, 0.22);
    --ai-text-main: var(--text);
    --ai-text-muted: var(--muted);
}

/* Explicit light theme */
html[data-theme="light"] {
    --bg: #0f172a;
    --bg-2: #111827;
    --muted: #64748b;
    --border: #e5e7eb;
    --card: #ffffff;
    --body: #f8fafc;
    --text: #0f172a;
    --brand: #3f71b5;
    --brand-2: #65a8e9;
    --accent: #22c55e;
    --warn: #f59e0b;
    --danger: #ef4444;
    --side-bg: #ffffff;
    --side-text: #0f172a;
    --side-label: #475569;
    --side-pill-bg: #e2e8f0;
    --side-pill-text: #0f172a;
    --side-hover: rgba(2,6,23,.06);
    --side-border: #e5e7eb;
    --ai-text-main: var(--text);
    --ai-text-muted: var(--muted);
}

/* Explicit dark theme */
html[data-theme="dark"] {
    --bg: #0b1220;
    --bg-2: #0b1220;
    --muted: #9aa4b2;
    --border: #253047;
    --card: #151d32;
    --body: #181f2c;
    --text: #e5ecf4;
    --brand: #3f71b5;
    --brand-2: #29445e;
    --accent: #34d399;
    --warn: #f59e0b;
    --danger: #ef4444;
    --shadow: 0 0 0 rgba(0,0,0,0);
    --side-bg: #0b1220;
    --side-text: #e5ecf4;
    --side-label: #aab4c3;
    --side-pill-bg: rgba(255,255,255,.16);
    --side-pill-text: #e8eef6;
    --side-hover: rgba(255,255,255,.06);
    --side-border: #1d2840;
    --ai-gradient-1: #1d4ed8;
    --ai-gradient-2: #1e40af;
    --ai-gradient-3: #22c1c3;
    --ai-gradient-4: #7c3aed;
    --ai-gradient-5: #f472b6;
    --ai-bg-soft: #020617;
    --ai-border-soft: rgba(148, 163, 184, 0.35);
    --ai-text-main: var(--text);
    --ai-text-muted: var(--muted);
}

/* Follow system pref if no explicit theme */
@media (prefers-color-scheme: dark) {
    html:not([data-theme]) {
        --bg: #0b1220;
        --bg-2: #0b1220;
        --muted: #9aa4b2;
        --border: #253047;
        --card: #0f172a;
        --body: #0b1020;
        --text: #e5ecf4;
        --brand: #3b82f6;
        --brand-2: #2563eb;
        --accent: #34d399;
        --warn: #f59e0b;
        --danger: #ef4444;
        --shadow: 0 0 0 rgba(0,0,0,0);
        --side-bg: #0b1220;
        --side-text: #e5ecf4;
        --side-label: #aab4c3;
        --side-pill-bg: rgba(255,255,255,.16);
        --side-pill-text: #e8eef6;
        --side-hover: rgba(255,255,255,.06);
        --side-border: #1d2840;
        --ai-text-main: var(--text);
        --ai-text-muted: var(--muted);
    }
}

/* ===================================== */
/*         GLOBAL RESETS / BASE          */
/* ===================================== */

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

body {
    font-family: 'Inter', 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, system-ui, sans-serif;
    font-size: 16px;
    font-weight: 400;
    letter-spacing: 0.01em;
    color: var(--text);
    margin: 0;
    background: var(--body, #f8fafc);
}

html[data-theme="dark"] body {
    background: var(--body);
}

/* ===================================== */
/*            MAIN APP LAYOUT           */
/* ===================================== */

.app {
    display: grid;
    grid-template-columns: 260px 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
    grid-template-areas:
        "topbar topbar"
        "sidebar main";
    min-height: 100dvh;
    transition: grid-template-columns .25s ease;
}

    /* Collapsed rail width (desktop only) */
    .app.collapsed {
        grid-template-columns: 72px 1fr;
    }

/* Topbar */
.topbar {
    grid-area: topbar;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    position: sticky;
    top: 0;
    z-index: 1000;
    height: var(--topbar-h);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

/* Sidebar */
.sidebar {
    grid-area: sidebar;
    background: var(--side-bg, var(--bg)) !important;
    color: var(--side-text, #e2e8f0) !important;
    position: sticky;
    top: var(--topbar-h);
    height: 100dvh;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--side-border, rgba(255,255,255,.06));
    width: 260px;
    transition: width .25s ease, transform .25s ease;
    will-change: width;
    z-index: 900;
    overflow: hidden;
    box-shadow: none;
}

/* Collapsed sidebar width */
.app.collapsed .sidebar {
    width: 72px;
}

/* Main content */
.main {
    grid-area: main;
    padding: 20px;
    min-width: 0;
    position: relative;
    z-index: 1;
    width: 100%;
}

/* ===================================== */
/*             TOPBAR CONTENT            */
/* ===================================== */

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    margin-right: 8px;
}

.brand-badge {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    color: #ffffff;
    font-weight: 700;
    font-size: 14px;
    box-shadow: var(--shadow);
    background: var(--brand);
}

.brand-name {
    font-weight: 700;
    color: var(--text);
}

.divider {
    width: 1px;
    height: 28px;
    background: var(--border);
    margin: 0 8px;
}

.icon-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    cursor: pointer;
}

    .icon-btn:hover {
        background: #f1f5f9;
    }

.search {
    flex: 1;
    max-width: 560px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--body);
    border: 1px solid var(--border);
    padding: 8px 10px;
    border-radius: 12px;
}

    .search input {
        border: none;
        outline: none;
        background: transparent;
        width: 100%;
        color: var(--text);
    }

.top-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg,#f97316,#ef4444);
    color: #ffffff;
    display: grid;
    place-items: center;
    font-size: 14px;
    font-weight: 700;
}

/* Dropdown menu */

.dropdown {
    position: relative;
}

.menu {
    position: absolute;
    right: 0;
    top: 44px;
    min-width: 220px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 8px;
    display: none;
}

    .menu.open {
        display: block;
    }

    .menu a,
    .menu button {
        display: flex;
        align-items: center;
        gap: 10px;
        width: 100%;
        background: transparent;
        border: none;
        text-align: left;
        cursor: pointer;
        padding: 10px 12px;
        border-radius: 10px;
        color: var(--text);
    }

        .menu a:hover,
        .menu button:hover {
            background: #f8fafc;
        }

    .menu .menu-meta {
        padding: 8px 10px;
        font-size: 12px;
        color: var(--muted);
    }

/* Dark adjustments */

html[data-theme="dark"] .topbar {
    border-bottom-color: #1d2840;
}

html[data-theme="dark"] .panel {
    border-color: #1d2840;
}

html[data-theme="dark"] .nav-link:hover {
    background: rgba(255,255,255,.06);
}

/* ===================================== */
/*              SIDEBAR NAV              */
/* ===================================== */

.side-head {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255,255,255,.06);
}

.side-title {
    font-weight: 700;
    letter-spacing: .3px;
    color: var(--side-title-color, #fff);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.collapse-btn {
    color: #cbd5e1;
    background: transparent;
    border: none;
    cursor: pointer;
}

.side-scroll {
    overflow: auto;
    padding: 8px;
}

.nav-section {
    margin: 8px 0 12px;
}

.nav-label {
    color: var(--side-label, #94a3b8);
    font-size: 12px;
    letter-spacing: .6px;
    padding: 8px 10px;
    text-transform: uppercase;
    white-space: nowrap;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-link {
    position: relative;
    background: transparent;
    border: none;
    color: var(--side-text, #e2e8f0);
    text-align: left;
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    transition: background .15s ease, color .15s ease;
}

    .nav-link:hover {
        background: var(--side-hover, rgba(148,163,184,0.16));
        color: var(--side-text, #e2e8f0);
    }

.nav .active {
    background: rgba(37,99,235,0.18);
    color: #ffffff;
}

.nav .pill {
    margin-left: auto;
    background: rgba(255,255,255,.12);
    color: var(--side-pill-text, #e2e8f0);
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
}

.nav .ico {
    width: 22px;
    display: inline-block;
    text-align: center;
}

.nav .label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Sidebar theme override */

.sidebar[data-side-theme="light"] {
    --side-bg: #ffffff;
    --side-text: #1e293b;
    --side-label: #64748b;
    --side-pill-bg: #e2e8f0;
    --side-pill-text: #2563eb;
    --side-hover: rgba(2,6,23,.05);
    --side-border: #e5e7eb;
}

.sidebar[data-side-theme="dark"] {
    --side-bg: #0b1220;
    --side-text: #e0e7ef;
    --side-label: #aab4c3;
    --side-pill-bg: rgba(255,255,255,.16);
    --side-pill-text: #aab4c3;
    --side-hover: rgba(255,255,255,.06);
    --side-border: #1d2840;
}

.sidebar[data-side-theme] {
    background: var(--side-bg) !important;
    color: var(--side-text) !important;
    border-right-color: var(--side-border) !important;
}

    .sidebar[data-side-theme] .nav-link,
    .sidebar[data-side-theme] .nav .label,
    .sidebar[data-side-theme] .nav-child {
        color: var(--side-text) !important;
    }

    .sidebar[data-side-theme] .nav-label {
        color: var(--side-label) !important;
    }

    .sidebar[data-side-theme] .nav .pill {
        background: var(--side-pill-bg) !important;
        color: var(--side-pill-text) !important;
    }

    .sidebar[data-side-theme] .has-children .chev {
        color: var(--side-label) !important;
    }

/* Strong light-mode text */

html[data-theme="light"] .nav-link,
html[data-theme="light"] .nav .label,
html[data-theme="light"] .nav-child {
    color: #0f172a !important;
}

html[data-theme="light"] .nav-label {
    color: #475569 !important;
}

html[data-theme="light"] .nav .pill {
    background: #e2e8f0 !important;
    color: #0f172a !important;
}

html[data-theme="light"] .nav-link:hover,
html[data-theme="light"] .nav-child:hover {
    background: rgba(2,6,23,.06) !important;
}

html[data-theme="light"] .has-children .chev {
    color: #64748b !important;
}

.sidebar .nav,
.sidebar .nav * {
    opacity: 1 !important;
}

/* ===================================== */
/*     COLLAPSIBLE TREE (SIDEBAR)        */
/* ===================================== */

.nav-item {
    display: block;
}

.nav-parent {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: flex-start;
}

.has-children .chev {
    margin-left: auto;
    color: var(--muted);
    transition: transform .2s ease;
}

.nav-children {
    overflow: hidden;
    max-height: 0;
    transition: max-height .25s ease;
    padding-top: 6px;
}

.nav-item.open > .nav-children {
    max-height: 800px;
}

/* child link */

.nav-child {
    display: block;
    text-decoration: none;
    padding: 8px 12px 8px 38px;
    border-radius: 10px;
    color: var(--side-text, var(--text));
    position: relative;
    margin-top: 4px;
    transition: background .15s ease, color .15s ease;
}

    .nav-child:hover {
        background: var(--side-hover, rgba(148,163,184,0.16));
        color: var(--side-text, var(--text));
    }

.nav-item.nested .nav-child {
    padding-left: 54px;
}

/* ===================================== */
/*   COLLAPSED BEHAVIOR (DESKTOP ONLY)   */
/* ===================================== */

/* hide labels when collapsed */
.app.collapsed .side-title,
.app.collapsed .nav-label,
.app.collapsed .nav .label,
.app.collapsed .nav .pill {
    display: none;
}

/* on desktop hover, expand rail */
@media (min-width: 721px) {
    .app.collapsed .sidebar:hover {
        width: 260px;
    }

        .app.collapsed .sidebar:hover .side-title,
        .app.collapsed .sidebar:hover .nav-label,
        .app.collapsed .sidebar:hover .nav .label,
        .app.collapsed .sidebar:hover .nav .pill {
            display: inline;
        }

        .app.collapsed .sidebar:hover .nav-item.open > .nav-children {
            display: block;
            max-height: none;
            pointer-events: auto;
        }
}

/* Children closed in collapsed state */
.app.collapsed .nav-children {
    display: none;
    max-height: 0;
}

/* ===================================== */
/*            PANEL / CARDS              */
/* ===================================== */

.panel {
    background: var(--card) !important;
    border: 1px solid var(--border) !important;
    border-radius: 10px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

.panel-default {
    border-color: var(--border) !important;
}

.panel-heading {
    color: #ffffff !important;
    border-bottom: 1px solid var(--border) !important;
    background: var(--brand) !important;
    padding: 10px 16px;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
}

html[data-theme="dark"] .panel-heading {
    background: #1f2937 !important;
    color: #e5ecf4 !important;
    border-bottom-color: #1d2840 !important;
}

.panel-body {
    background: var(--card) !important;
    color: var(--text) !important;
    padding: 16px;
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
    overflow-x: auto;
}

.panel-heading .fa,
.panel-heading .mdi {
    margin-right: 6px;
}

.panel-body .e-grid,
.panel-body .e-control {
    background: transparent !important;
    color: inherit !important;
}

/* Popups / z-order */

.e-popup,
.e-dialog,
.e-tooltip-wrap,
.e-contextmenu,
.e-dropdown-popup,
.e-filter-popup {
    z-index: 1200 !important;
    max-width: min(96vw, 680px);
}

.panel,
.panel-body,
.main,
.side-scroll {
    overflow: visible;
}

/* ===================================== */
/*       LEGACY GRID (ROW/COLS)          */
/* ===================================== */

.row {
    display: flex;
    flex-wrap: wrap;
    margin-left: -12px;
    margin-right: -12px;
}

[class*="col-"] {
    padding-left: 12px;
    padding-right: 12px;
}

/* 100% width columns by default (mobile-first) */
.col-lg-12,
.col-md-12,
.col-sm-12,
.col-xs-12 {
    width: 100%;
}

/* ===================================== */
/*     BUTTONS / INPUTS / TOOLBARS       */
/* ===================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    border: 1px solid var(--border);
    background: var(--brand-2);
    border-radius: 8px;
    color: var(--text);
    cursor: pointer;
}

    .btn:hover {
        background: var(--brand);
        color: #ffffff;
    }

    .btn.primary {
        background: var(--brand);
        color: #ffffff;
        border-color: var(--brand);
    }

input[type="text"],
input[type="search"],
input[type="date"],
select,
textarea {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    background: var(--body);
    color: var(--text);
}

/* Content scaffolding */

.crumb {
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 8px;
}

.page-title {
    font-size: 20px;
    font-weight: 800;
    margin-bottom: 16px;
}

/* KPI cards */

.cards {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 16px;
    margin-bottom: 16px;
}

.card {
    grid-column: span 3;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    min-width: 0;
    width: 100%;
}

    .card h4 {
        margin: 0 0 4px;
        font-size: 13px;
        color: var(--muted);
        font-weight: 600;
    }

    .card .big {
        font-size: 24px;
        font-weight: 800;
    }

.kpi.up {
    color: var(--accent);
    font-weight: 700;
}

.kpi.down {
    color: var(--danger);
    font-weight: 700;
}

/* Panel head row */

.panel-head {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--border);
}

    .panel-head h3 {
        margin: 0;
        font-size: 16px;
        font-weight: 800;
    }

.panel-body .table-wrap {
    width: 100%;
    overflow: auto;
}

/* Inline toolbar */

.toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

    .toolbar .btn {
        padding: 8px 12px;
        border: 1px solid var(--border);
        background: #ffffff;
        border-radius: 10px;
        cursor: pointer;
    }

        .toolbar .btn.primary {
            background: var(--brand);
            color: #ffffff;
            border-color: var(--brand);
        }

/* ===================================== */
/*                TABLES                 */
/* ===================================== */

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    font-size: 14px;
}

th {
    background: #f8fafc;
    font-weight: 700;
}

html[data-theme="dark"] th {
    background: #111a2e !important;
    color: var(--text) !important;
}

tr:hover td {
    background: #fafafa;
}

/* ===================================== */
/*  MOBILE/TABLET SIDEBAR OVERLAY        */
/* ===================================== */

.sidebar-backdrop {
    position: fixed;
    left: 0;
    right: 0;
    top: var(--topbar-h);
    bottom: 0;
    background: rgba(0,0,0,0.40);
    z-index: 1090;
    opacity: 0;
    visibility: hidden;
    transition: opacity .28s ease, visibility .28s;
    will-change: opacity;
}

    .sidebar-backdrop.open {
        opacity: 1;
        visibility: visible;
    }

body.sidebar-open {
    overflow: hidden;
    touch-action: none;
}

/* ===================================== */
/*   RESPONSIVE: TABLET & MOBILE         */
/* ===================================== */

@media (max-width: 1024px) {
    .app {
        grid-template-columns: 1fr;
        grid-template-areas:
            "topbar"
            "main";
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: var(--topbar-h);
        height: calc(100dvh - var(--topbar-h));
        width: 280px;
        min-width: 260px;
        transform: translateX(-110%);
        box-shadow: 0 18px 40px rgba(2,6,23,0.28);
        border-right: 0;
        z-index: 1100;
        will-change: transform;
        max-width: 90vw;
    }

        .sidebar.open {
            transform: translateX(0);
        }

    .main {
        position: relative;
        z-index: 1;
        padding: 16px;
    }

    .search {
        display: none;
    }

    .cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .card {
        grid-column: span 1;
    }

    .sidebar .side-head {
        padding: 12px 14px;
    }

    .sidebar .nav {
        padding: 8px 6px 16px 6px;
    }

    .nav-child {
        padding: 10px 16px 10px 34px;
    }

    .nav-link {
        padding: 10px 12px;
    }
}

@media (max-width: 720px) {
    .topbar {
        padding: 0 10px;
        gap: 8px;
    }

    .brand {
        margin-right: 0;
    }

    .top-actions {
        gap: 6px;
    }

    .main {
        padding: 12px;
    }

    .cards {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .card {
        grid-column: span 1;
    }

    .sidebar {
        width: 260px;
    }

    .page-title {
        font-size: 18px;
    }
}

/* ===================================== */
/*               HELPERS                 */
/* ===================================== */

.table-wrap,
.panel-body .table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

ul {
    list-style: none;
    padding-left: 0;
}

.m-b-0 {
    margin-bottom: 0 !important;
}

.m-b-10 {
    margin-bottom: 10px !important;
}

.m-b-15 {
    margin-bottom: 15px !important;
}

.m-b-20 {
    margin-bottom: 20px !important;
}

.p-0 {
    padding: 0 !important;
}

.p-10 {
    padding: 10px !important;
}

.p-15 {
    padding: 15px !important;
}

.p-20 {
    padding: 20px !important;
}

/* ===================================== */
/*       DIALOG / POPUP Z-INDEX          */
/* ===================================== */

.e-dlg-container,
.e-dlg-overlay {
    z-index: 2000000 !important;
}

.e-dialog,
.e-popup,
.e-popup-open,
.e-ddl.e-popup {
    z-index: 2000001 !important;
}

/* ===================================== */
/*         SYNCFUSION EJ2 GRID           */
/* ===================================== */

.e-grid,
.e-grid .e-rowcell,
.e-grid .e-headercell,
.e-grid .e-headercontent,
.e-grid .e-pager,
.e-grid .e-toolbar {
    font-family: 'Nunito', 'Poppins', 'Roboto', Arial, sans-serif !important;
    font-size: 12.5px !important;
    font-weight: 500;
    letter-spacing: 0.01em;
    background: var(--card);
    color: var(--text);
}

    .e-grid .e-rowcell {
        padding: 7px 10px !important;
        border-bottom: 1px solid var(--border);
        background: var(--card);
    }

    .e-grid .e-headercell,
    .e-grid .e-headercell.e-active .e-groupdroparea {
        font-weight: 700;
        font-size: 13px;
        border-bottom: 2px solid var(--brand-2);
        padding: 8px 10px 7px;
        letter-spacing: 0.02em;
    }

    .e-grid .e-table {
        border-radius: 7px;
        overflow: hidden;
        box-shadow: 0 1.5px 7px rgba(37,99,235,0.07);
    }

        .e-grid .e-table td,
        .e-grid .e-table th {
            border-color: var(--border) !important;
        }

    .e-grid .e-pager,
    .e-grid .e-toolbar {
        background: var(--card);
        font-size: 12px;
        box-shadow: none;
        border: none;
        font-weight: 500;
    }

    .e-grid .e-headercell .e-sortfilterdiv,
    .e-grid .e-headercell .e-sortfilterdiv .e-icons {
        color: var(--brand) !important;
        opacity: 0.80;
        font-size: 13px;
    }

    .e-grid .e-row.e-selectionbackground,
    .e-grid .e-row.e-active {
        background: color-mix(in srgb, var(--brand) 14%, var(--card)) !important;
        color: #ffffff !important;
        font-weight: 700;
    }

.panel-body .e-grid,
.panel-body .e-grid .e-table {
    background: transparent !important;
}

/* Smaller grid on narrow widths */
@media (max-width: 900px) {
    .e-grid .e-rowcell,
    .e-grid .e-headercell {
        font-size: 11.4px !important;
        padding: 6px 5px !important;
    }
}

/* Dark mode for grid */

html[data-theme="dark"] .e-grid,
html[data-theme="dark"] .e-rowcell,
html[data-theme="dark"] .e-headercell,
html[data-theme="dark"] .e-headercontent,
html[data-theme="dark"] .e-gridheader,
html[data-theme="dark"] .e-table {
    background: #151d32 !important;
    color: #e2eaf4 !important;
    border-color: #253047 !important;
}

html[data-theme="dark"] .e-row.e-altrow {
    background: #1a233c !important;
}

html[data-theme="dark"] .e-headercell,
html[data-theme="dark"] .e-headercell.e-active {
    background: #1c2540 !important;
    color: #4f83ff !important;
    border-bottom: 2px solid #2563eb !important;
}

html[data-theme="dark"] .e-row.e-selectionbackground,
html[data-theme="dark"] .e-row.e-active {
    background: #1a2750 !important;
    color: #ffffff !important;
}

/* ===================================== */
/*          AI HEADER / PANELS           */
/* (simplified, no heavy animations)     */
/* ===================================== */

.sf-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: #e1ecfa;
    box-shadow: 0 2px 6px rgba(101,175,255,0.18);
    padding: 10px 20px;
    font-size: 16px;
    font-weight: 700;
    color: #2563eb;
    letter-spacing: 0.03em;
    border-bottom: 1.5px solid #e6ecf9;
    border-radius: 0 0 12px 12px;
    min-height: 36px;
    display: flex;
    align-items: center;
}

.sf-panel-full {
    box-sizing: border-box;
    padding: 28px 18px 22px 18px;
    width: 100%;
    background: var(--card);
    box-shadow: 0 6px 16px rgba(15,23,42,0.08);
    border-radius: 26px 26px 12px 12px;
    margin-bottom: 18px;
    color: var(--text);
}

.sf-panel-header {
    position: relative;
    padding: 9px 18px;
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    border-radius: 10px 10px 8px 8px;
    margin-bottom: 10px;
    min-height: 50px;
    display: flex;
    align-items: center;
    background: var(--brand-2);
    box-shadow: 0 2px 8px rgb(5 5 10 / 92%)
}

html[data-theme="dark"] .sf-panel-header {
    color: var(--text);
    background: var(--brand-2);
    box-shadow: 0 4px 14px rgb(167 174 191 / 30%);
}

/* ===================================== */
/*               AI CHAT UI              */
/* (kept with animations/patterns)       */
/* ===================================== */

/* gradient flow animations */
@keyframes aiGradientFlow {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

@keyframes aiGlowSoft {
    0% {
        box-shadow: 0 10px 30px rgba(79, 70, 229, 0.18);
    }

    50% {
        box-shadow: 0 18px 60px rgba(14, 165, 233, 0.35);
    }

    100% {
        box-shadow: 0 10px 30px rgba(79, 70, 229, 0.18);
    }
}

@keyframes aiBorderPulse {
    0% {
        border-color: rgba(129, 140, 248, 0.4);
    }

    50% {
        border-color: rgba(45, 212, 191, 0.7);
    }

    100% {
        border-color: rgba(129, 140, 248, 0.4);
    }
}

/* Chat page container */
.ai-chat-page {
    display: flex;
    justify-content: center;
    padding: 24px;
    gap: 24px;
    box-sizing: border-box;
}

/* main chat card */
.chat-card {
    width: min(980px, 100%);
    max-width: 980px;
    height: calc(100dvh - 140px);
    background: linear-gradient( 120deg, rgba(79,70,229,0.10), rgba(6,182,212,0.10), rgba(34,197,94,0.10), rgba(234,179,8,0.10), rgba(236,72,153,0.10) );
    background-size: 260% 260%;
    border-radius: 18px;
    padding: 1px;
    animation: aiGradientFlow 14s ease-in-out infinite;
    box-shadow: 0 22px 65px rgba(15, 23, 42, 0.26), 0 0 40px rgba(56, 189, 248, 0.25);
    display: grid;
    grid-template-rows: auto 1fr auto;
    overflow: hidden;
}

    /* inner surfaces */
    .chat-card > * {
        background: var(--card);
        backdrop-filter: blur(24px);
    }

/* chat header */
.chat-header {
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.25);
    background: linear-gradient( 120deg, rgba(15,23,42,0.02), rgba(129,140,248,0.08), rgba(45,212,191,0.06), rgba(236,72,153,0.08) );
    background-size: 220% 220%;
    animation: aiGradientFlow 18s ease-in-out infinite;
}

    .chat-header .title {
        font-weight: 800;
        font-size: 16px;
        letter-spacing: 0.03em;
        color: var(--ai-text-main);
    }

    .chat-header .subtitle {
        margin-left: 8px;
        color: var(--ai-text-muted);
        font-size: 13px;
    }

/* header controls */
.chat-controls {
    display: flex;
    gap: 12px;
    margin-left: auto;
    align-items: center;
}

/* model selector */
.model-select {
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 13px;
    color: var(--ai-text-muted);
}

    .model-select select {
        padding: 6px 10px;
        border-radius: 999px;
        border: 1px solid rgba(148, 163, 184, 0.55);
        background: radial-gradient(circle at top left, rgba(255,255,255,0.85), rgba(226,232,240,0.85));
        color: var(--ai-text-main);
        box-shadow: 0 4px 14px rgba(15,23,42,0.06);
    }

        .model-select select:focus {
            outline: none;
            border-color: rgba(59,130,246,0.9);
        }

/* conversation scroll area */
.conversation {
    padding: 18px;
    overflow-y: auto;
    background: radial-gradient(circle at top, rgba(129,140,248,0.10), transparent 60%), radial-gradient(circle at bottom, rgba(34,197,94,0.10), transparent 60%), var(--card);
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* message bubble base */
.msg {
    max-width: 84%;
    padding: 12px 14px;
    border-radius: 16px;
    line-height: 1.45;
    font-size: 14.5px;
    box-shadow: 0 10px 26px rgba(15, 23, 42, 0.12);
    position: relative;
    word-break: break-word;
}

    /* user bubble */
    .msg.user {
        margin-left: auto;
        color: #ffffff;
        border-bottom-right-radius: 8px;
        background: linear-gradient( 135deg, var(--ai-gradient-5), var(--ai-gradient-1), var(--ai-gradient-2), var(--ai-gradient-3) );
        background-size: 260% 260%;
        animation: aiGradientFlow 10s ease-in-out infinite;
        box-shadow: 0 14px 40px rgba(79,70,229,0.55), 0 0 22px rgba(236,72,153,0.55);
    }

    /* AI bubble */
    .msg.ai {
        background: radial-gradient(circle at top left, rgba(248,250,252,0.96), rgba(241,245,249,0.98));
        color: var(--ai-text-main);
        border-radius: 16px;
        border: 1px solid rgba(148, 163, 184, 0.35);
        border-bottom-left-radius: 8px;
    }

        .msg.ai::before {
            content: "";
            position: absolute;
            inset: -1px;
            border-radius: inherit;
            padding: 1px;
            background: conic-gradient( from 0deg, rgba(79,70,229,0.65), rgba(6,182,212,0.65), rgba(34,197,94,0.65), rgba(234,179,8,0.65), rgba(236,72,153,0.9), rgba(79,70,229,0.65) );
            -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
            -webkit-mask-composite: xor;
            mask-composite: exclude;
            animation: aiGradientFlow 20s linear infinite;
            opacity: 0.70;
            pointer-events: none;
        }

        .msg.ai > * {
            position: relative;
            z-index: 1;
        }

    /* meta row */
    .msg .meta {
        display: flex;
        gap: 8px;
        margin-top: 8px;
        align-items: center;
        font-size: 12px;
        color: var(--ai-text-muted);
    }

/* small pill button */
.pill-btn {
    background: linear-gradient(135deg, rgba(15,23,42,0.02), rgba(148,163,184,0.16));
    border: 1px solid rgba(148, 163, 184, 0.40);
    padding: 6px 10px;
    border-radius: 999px;
    cursor: pointer;
    font-weight: 600;
    font-size: 12px;
    color: var(--ai-text-main);
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease, background .15s ease;
}

    .pill-btn:hover {
        background: linear-gradient(135deg, rgba(59,130,246,0.16), rgba(45,212,191,0.12));
        border-color: rgba(59,130,246,0.7);
        box-shadow: 0 8px 20px rgba(37, 99, 235, 0.24);
        transform: translateY(-1px);
    }

/* typing indicator */
.typing {
    display: inline-flex;
    gap: 6px;
    align-items: center;
}

    .typing .dot {
        width: 8px;
        height: 8px;
        background: radial-gradient(circle, #e5e7eb, #94a3b8);
        border-radius: 50%;
        opacity: 0.7;
        transform: translateY(0);
        animation: typing 0.9s infinite;
        box-shadow: 0 0 10px rgba(148, 163, 184, 0.6);
    }

        .typing .dot:nth-child(2) {
            animation-delay: .12s;
        }

        .typing .dot:nth-child(3) {
            animation-delay: .24s;
        }

@keyframes typing {
    0% {
        transform: translateY(0);
        opacity: 0.4;
    }

    50% {
        transform: translateY(-6px);
        opacity: 1;
    }

    100% {
        transform: translateY(0);
        opacity: 0.4;
    }
}

/* Input row at bottom */
.chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid rgba(148, 163, 184, 0.28);
    display: flex;
    gap: 12px;
    align-items: center;
    background: var(--card);
}

/* input shell */
.chat-input {
    flex: 1;
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 8px 10px;
    background: var(--card);
    border-radius: 14px;
    border: 1px solid rgba(148, 163, 184, 0.55);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.09), inset 0 0 0 1px rgba(255,255,255,0.45);
    position: relative;
    overflow: visible;
}

    .chat-input textarea {
        width: 100%;
        min-height: 44px;
        max-height: 120px;
        resize: none;
        border: none;
        outline: none;
        background: transparent;
        font-size: 14px;
        padding: 8px 6px;
        color: var(--ai-text-main);
    }

    .chat-input:focus-within {
        box-shadow: 0 10px 30px rgba(37, 99, 235, 0.24), 0 0 0 1px rgba(59, 130, 246, 0.65);
        border-color: rgba(59, 130, 246, 0.9);
    }

/* send button */
.send-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 999px;
    border: none;
    cursor: pointer;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #0f172a;
    background: linear-gradient( 135deg, var(--ai-gradient-5), var(--ai-gradient-1), var(--ai-gradient-2), var(--ai-gradient-3) );
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12), 0 0 0 1px rgba(148,163,184,0.35);
    overflow: hidden;
    transition: transform .18s ease, box-shadow .24s ease, opacity .18s ease;
}

    .send-btn::before {
        content: "";
        position: absolute;
        inset: 0;
        padding: 1px;
        border-radius: inherit;
        background: linear-gradient( 120deg, var(--ai-gradient-1), var(--ai-gradient-2), var(--ai-gradient-4), var(--ai-gradient-5), var(--ai-gradient-1) );
        background-size: 260% 260%;
        animation: askBorderFlow 9s linear infinite;
        -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
        -webkit-mask-composite: xor;
        mask-composite: exclude;
        pointer-events: none;
        z-index: 0;
    }

    .send-btn > * {
        position: relative;
        z-index: 1;
    }

    .send-btn:hover {
        transform: translateY(-1px) scale(1.01);
        box-shadow: 0 12px 26px rgba(15, 23, 42, 0.16), 0 0 0 1px rgba(59,130,246,0.55);
    }

    .send-btn:active {
        transform: translateY(0) scale(.97);
        box-shadow: 0 6px 18px rgba(15, 23, 42, 0.18), 0 0 0 1px rgba(59,130,246,0.45);
    }

    .send-btn .icon-send {
        font-size: 13px;
        opacity: 0.9;
        transform: translateY(0) translateX(0);
        transition: transform .20s ease, opacity .20s ease;
    }

    .send-btn:hover .icon-send {
        transform: translateY(-1px) translateX(2px);
        opacity: 1;
    }

@keyframes askBorderFlow {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

@keyframes askBreathSoft {
    0% {
        transform: translateY(0) scale(1);
    }

    50% {
        transform: translateY(-1px) scale(1.015);
    }

    100% {
        transform: translateY(0) scale(1);
    }
}

.send-btn.sending,
.send-btn.ai-animate {
    animation: askBorderFlow 9s linear infinite, askBreathSoft 2.2s ease-in-out infinite;
}

    .send-btn.sending.ai-animate {
        animation: askBorderFlow 9s linear infinite, askBreathSoft 1.8s ease-in-out infinite;
    }

.send-btn[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Quick reply chips */
.sample-chips {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.chip {
    padding: 6px 10px;
    background: linear-gradient(135deg, rgba(248,250,252,0.9), rgba(226,232,240,0.95));
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.50);
    cursor: pointer;
    font-size: 13px;
    color: var(--ai-text-main);
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s.ease, background 0.15s ease;
}

    .chip:hover {
        transform: translateY(-2px);
        box-shadow: 0 10px 24px rgba(37, 99, 235, 0.22);
        border-color: rgba(59,130,246,0.9);
        background: linear-gradient(135deg, rgba(239,246,255,0.96), rgba(219,234,254,0.96));
    }

/* Generated SQL box */
.generated-sql {
    margin-top: 10px;
    background: #020617;
    color: #e5f0ff;
    padding: 10px;
    border-radius: 10px;
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 13px;
    white-space: pre-wrap;
    border: 1px solid rgba(148, 163, 184, 0.6);
    box-shadow: 0 14px 40px rgba(15,23,42,0.6);
}

/* Right history column */
.right-col {
    width: 320px;
    max-height: calc(100dvh - 140px);
    overflow-y: auto;
    background: transparent;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.right-panel {
    background: var(--card);
    border-radius: 14px;
    padding: 12px;
    border: 1px solid rgba(148, 163, 184, 0.35);
    box-shadow: 0 10px 30px rgba(15,23,42,0.10);
}

/* history items */
.history-item {
    padding: 8px;
    border-radius: 10px;
    background: linear-gradient(135deg, rgba(248,250,252,0.98), rgba(226,232,240,0.98));
    cursor: pointer;
    border: 1px solid rgba(148, 163, 184, 0.35);
    font-size: 13px;
    transition: transform .12s ease, box-shadow .15s.ease, border-color .15s ease, background .15s ease;
}

    .history-item:hover {
        background: linear-gradient(135deg, rgba(239,246,255,0.98), rgba(219,234,254,0.98));
        border-color: rgba(59,130,246,0.85);
        box-shadow: 0 10px 24px rgba(59,130,246,0.20);
        transform: translateY(-2px);
    }

/* reveal animation for AI content */
.msg.ai .reveal {
    display: inline-block;
    opacity: 0;
    transform: translateY(3px);
    transition: opacity .18s ease, transform .22s ease;
}

    .msg.ai .reveal.visible {
        opacity: 1;
        transform: translateY(0);
    }

/* responsive: hide right history on narrower screens */
@media (max-width: 1100px) {
    .chat-card {
        max-width: 860px;
    }

    .right-col {
        display: none;
    }
}

/* responsive: small mobiles for chat card */
@media (max-width: 720px) {
    .ai-chat-page {
        padding: 16px 10px;
        gap: 12px;
    }

    .chat-card {
        width: 100%;
        height: calc(100dvh - 120px);
    }

    .chat-header {
        padding: 10px 12px;
        gap: 8px;
    }

        .chat-header .title {
            font-size: 14px;
        }

        .chat-header .subtitle {
            display: none;
        }

    .chat-input-area {
        padding: 10px 12px;
        gap: 8px;
    }

    .chat-input textarea {
        min-height: 40px;
    }

    .msg {
        max-width: 100%;
        font-size: 14px;
    }
}

/* Dark mode refinements for AI chat */

html[data-theme="dark"] .conversation {
    background: radial-gradient(circle at top, rgba(30,64,175,0.18), transparent 60%), radial-gradient(circle at bottom, rgba(5,150,105,0.18), transparent 60%), var(--card);
}

html[data-theme="dark"] .msg.ai {
    background: #020617;
    color: var(--text);
    border-color: rgba(148,163,184,0.45);
}

html[data-theme="dark"] .msg.user {
    box-shadow: 0 14px 40px rgba(15,23,42,0.9), 0 0 22px rgba(59,130,246,0.7);
}

html[data-theme="dark"] .right-panel {
    background: var(--card);
    border-color: rgba(148,163,184,0.45);
    box-shadow: 0 18px 40px rgba(15,23,42,0.85);
}

html[data-theme="dark"] .history-item {
    background: color-mix(in srgb, var(--card) 80%, #020617 20%);
    border-color: rgba(148,163,184,0.45);
}

    html[data-theme="dark"] .history-item:hover {
        background: color-mix(in srgb, var(--card) 60%, #020617 40%);
    }

html[data-theme="dark"] .chip {
    background: color-mix(in srgb, var(--card) 85%, #020617 15%);
    border-color: rgba(148,163,184,0.45);
    color: var(--text);
}

    html[data-theme="dark"] .chip:hover {
        background: color-mix(in srgb, var(--card) 70%, #020617 30%);
    }

html[data-theme="dark"] .model-select select {
    background: radial-gradient(circle at top left, rgba(15,23,42,0.95), rgba(15,23,42,0.98));
    color: var(--text);
    border-color: rgba(148,163,184,0.55);
    box-shadow: 0 4px 14px rgba(15,23,42,0.6);
}

/* Animated glow state when AI is ready for input */
@keyframes inputGlow {
    0% {
        box-shadow: 0 6px 30px rgba(59,130,246,0.00), inset 0 0 0 rgba(0,0,0,0);
        border-color: rgba(59,130,246,0.16);
    }

    50% {
        box-shadow: 0 13px 34px rgba(59,130,246,0.20), inset 0 0 20px rgba(59,130,246,0.06);
        border-color: rgba(45,212,191,0.65);
    }

    100% {
        box-shadow: 0 6px 30px rgba(59,130,246,0.00), inset 0 0 0 rgba(0,0,0,0);
        border-color: rgba(59,130,246,0.16);
    }
}

.chat-input.ai-animate {
    animation: inputGlow 2.8s ease-in-out infinite;
}

    .chat-input.ai-animate::before {
        content: "";
        position: absolute;
        left: 0;
        top: 8px;
        bottom: 8px;
        width: 4px;
        border-radius: 999px;
        background: linear-gradient( 180deg, var(--ai-gradient-1), var(--ai-gradient-2), var(--ai-gradient-3), var(--ai-gradient-5) );
        opacity: 0.95;
        transform: translateX(-4px);
        box-shadow: 0 10px 26px rgba(59,130,246,0.55);
    }

/* Brand badge in topbar for AI theme */
.brand-badge {
    background: conic-gradient( from 200deg, var(--ai-gradient-1), var(--ai-gradient-2), var(--ai-gradient-3), var(--ai-gradient-4), var(--ai-gradient-5), var(--ai-gradient-1) ) !important;
    background-size: 200% 200%;
    animation: aiGradientFlow 12s linear infinite;
    box-shadow: 0 12px 28px rgba(59,130,246,0.35), 0 0 24px rgba(236,72,153,0.75);
}

/* ========================================================= */
/*   RESPONSIVE NORMALIZATION LAYER                         */
/* ========================================================= */

.main {
    width: 100%;
    min-width: 0;
}

/* Panels & cards width */
.panel,
.sf-panel-full,
.panel-body,
.panel-heading {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* Chat fixed window with internal scroll */
.chat-card {
    display: flex;
    flex-direction: column;
    height: calc(100dvh - var(--topbar-h) - 74px);
    max-height: calc(100dvh - var(--topbar-h) - 74px);
    overflow: hidden;
}

.conversation {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 12px;
    scroll-behavior: smooth;
}

.msg {
    max-width: 100%;
}

.chat-input-area {
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    z-index: 10;
    background: inherit;
}

/* Hide right column on smaller screens (already above) */

@media (max-width: 720px) {
    .chat-card {
        height: calc(100dvh - var(--topbar-h) - 12px);
    }
}

/* Tablet */
@media (max-width: 1024px) {
    .cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .main {
        padding: 16px;
    }
}

/* Mobile */
@media (max-width: 720px) {
    .topbar {
        padding: 0 10px;
    }

    .search {
        display: none;
    }

    .main {
        padding: 12px;
    }

    .cards {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .panel-body,
    .sf-panel-full {
        padding: 12px;
    }

    .chat-card {
        width: 100%;
        min-height: calc(100dvh - var(--topbar-h) - 16px);
        border-radius: 14px;
    }

    .chat-header {
        padding: 10px 12px;
    }

        .chat-header .subtitle {
            display: none;
        }

    .chat-input-area {
        padding: 10px;
        gap: 8px;
    }

    .chat-input textarea {
        font-size: 14px;
    }

    .sidebar {
        width: 260px;
    }
}

/* Very small devices */
@media (max-width: 420px) {
    .page-title {
        font-size: 16px;
    }

    .btn,
    .send-btn {
        font-size: 13px;
        padding: 8px 12px;
    }

    .msg {
        font-size: 13.5px;
    }
}

/* Accessibility & touch */
@media (pointer: coarse) {
    button,
    .btn,
    .nav-link,
    .nav-child {
        min-height: 40px;
    }
}

/* ========================================================= */
/*   AI CHAT FLOATING POPUP (kept)                           */
/* ========================================================= */

.ai-chat-fab {
    position: fixed;
    right: 22px;
    bottom: 22px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    z-index: 3000;
    display: grid;
    place-items: center;
    font-size: 20px;
    color: #fff;
    background: linear-gradient( 135deg, var(--ai-gradient-1, #3b82f6), var(--ai-gradient-4, #a855f7) );
    box-shadow: 0 14px 40px rgba(59,130,246,0.45), 0 0 0 1px rgba(255,255,255,0.25);
    transition: transform .2s.ease, box-shadow .2s ease;
}

    .ai-chat-fab:hover {
        transform: translateY(-3px) scale(1.05);
        box-shadow: 0 18px 48px rgba(59,130,246,0.55), 0 0 0 1px rgba(255,255,255,0.35);
    }

/* Overlay */
.ai-chat-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2,6,23,0.55);
    backdrop-filter: blur(6px);
    z-index: 2999;
    opacity: 0;
    visibility: hidden;
    transition: opacity .25s ease, visibility .25s ease;
}

    .ai-chat-overlay.open {
        opacity: 1;
        visibility: visible;
    }

/* Popup panel */
.ai-chat-popup {
    position: absolute;
    right: 20px;
    bottom: 90px;
    width: min(720px, 94vw);
    height: min(640px, 86vh);
    background: rgba(255,255,255,0.75);
    backdrop-filter: blur(20px);
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 24px 70px rgba(15,23,42,0.55), 0 0 0 1px rgba(255,255,255,0.35);
    transform: translateY(40px) scale(.96);
    opacity: 0;
    transition: transform .3s ease, opacity .3s ease;
}

.ai-chat-overlay.open .ai-chat-popup {
    transform: translateY(0) scale(1);
    opacity: 1;
}

/* Header */
.ai-chat-popup-header {
    height: 48px;
    padding: 0 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 700;
    border-bottom: 1px solid rgba(148,163,184,0.35);
}

/* Close button */
.ai-chat-close {
    background: transparent;
    border: none;
    font-size: 18px;
    cursor: pointer;
    opacity: .7;
}

    .ai-chat-close:hover {
        opacity: 1;
    }

/* Iframe */
.ai-chat-popup iframe {
    width: 100%;
    height: calc(100% - 48px);
    border: none;
    background: transparent;
}

/* Mobile full-screen */
@media (max-width: 720px) {
    .ai-chat-popup {
        inset: 10px;
        width: auto;
        height: auto;
        right: 10px;
        bottom: 10px;
    }
}

/* ========================================================= */
/*   HUEB AI BUTTON (simplified but kept)                    */
/* ========================================================= */

.hueb-ai-wide {
    width: 140px;
    min-width: 140px;
}

.hueb-ai-btn {
    position: relative;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    padding: 10px 18px;
    border-radius: 14px;
    border: 1px solid rgba(255,255,255,0.35);
    background: linear-gradient( 135deg, var(--ai-gradient-1), var(--ai-gradient-2), var(--ai-gradient-4), var(--ai-gradient-5) );
    background-size: 280% 280%;
    animation: huebAIFlow 12s ease-in-out infinite;
    color: #ffffff;
    font-size: 14px;
    font-weight: 800;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    cursor: pointer;
    backdrop-filter: blur(16px);
    box-shadow: 0 16px 42px rgba(59,130,246,0.45), inset 0 0 0 1px rgba(255,255,255,0.25);
    transition: transform .2s ease, box-shadow .3s ease, filter .25s ease;
}

    .hueb-ai-btn:hover {
        transform: translateY(-1px);
        box-shadow: 0 22px 60px rgba(79,70,229,0.65), 0 0 28px rgba(236,72,153,0.6);
    }

    .hueb-ai-btn:active {
        transform: scale(.97);
    }

@keyframes huebAIFlow {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}
