/* =====================================================================
   ACE GROUP FM CRM :: DESIGN SYSTEM
   ---------------------------------------------------------------------
   Layered on top of Bootstrap 5. Everything is driven by CSS custom
   properties so the whole panel can be re-themed from :root.

   Layout: fixed dark sidebar (264px) + sticky white topbar + light grey
   content canvas with white elevated cards.
   ===================================================================== */

/* =====================================================================
   1. TOKENS
   ===================================================================== */
:root {
    /* --- Brand ------------------------------------------------------ */
    --ace-primary:        #2563eb;
    --ace-primary-dark:   #1d4ed8;
    --ace-primary-light:  #3b82f6;
    --ace-primary-soft:   rgba(37, 99, 235, .10);

    --ace-accent:         #f59e0b;
    --ace-success:        #10b981;
    --ace-warning:        #f59e0b;
    --ace-danger:         #ef4444;
    --ace-info:           #06b6d4;
    --ace-purple:         #8b5cf6;
    --ace-pink:           #ec4899;
    --ace-teal:           #14b8a6;

    /* --- Sidebar (dark) --------------------------------------------- */
    --ace-sidebar-bg:       #0f172a;
    --ace-sidebar-bg-alt:   #131f38;
    --ace-sidebar-border:   rgba(255, 255, 255, .06);
    --ace-sidebar-text:     #94a3b8;
    --ace-sidebar-text-hi:  #f1f5f9;
    --ace-sidebar-active:   #3b82f6;
    --ace-sidebar-hover:    rgba(255, 255, 255, .05);
    --ace-sidebar-width:    264px;
    --ace-sidebar-collapsed: 78px;

    /* --- Surfaces ---------------------------------------------------- */
    --ace-body-bg:      #f1f5f9;
    --ace-card-bg:      #ffffff;
    --ace-topbar-bg:    #ffffff;
    --ace-border:       #e2e8f0;
    --ace-border-soft:  #eef2f7;

    /* --- Type -------------------------------------------------------- */
    --ace-text:         #0f172a;
    --ace-text-muted:   #64748b;
    --ace-text-light:   #94a3b8;
    --ace-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

    /* --- Elevation ---------------------------------------------------- */
    --ace-shadow-xs: 0 1px 2px rgba(15, 23, 42, .04);
    --ace-shadow-sm: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
    --ace-shadow:    0 4px 12px rgba(15, 23, 42, .07);
    --ace-shadow-lg: 0 12px 32px rgba(15, 23, 42, .10);

    /* --- Geometry ------------------------------------------------------ */
    --ace-radius-sm: 8px;
    --ace-radius:    12px;
    --ace-radius-lg: 16px;
    --ace-topbar-h:  66px;
    --ace-transition: all .22s cubic-bezier(.4, 0, .2, 1);
}

/* =====================================================================
   2. BASE
   ===================================================================== */
* { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
    font-family: var(--ace-font);
    background: var(--ace-body-bg);
    color: var(--ace-text);
    font-size: .875rem;
    line-height: 1.6;
    overflow-x: hidden;
}

a { text-decoration: none; color: var(--ace-primary); }
a:hover { color: var(--ace-primary-dark); }

h1, h2, h3, h4, h5, h6 { font-weight: 600; color: var(--ace-text); letter-spacing: -.01em; }

.text-muted { color: var(--ace-text-muted) !important; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* Keyboard focus stays visible - accessibility, not decoration. */
:focus-visible {
    outline: 2px solid var(--ace-primary);
    outline-offset: 2px;
}

/* =====================================================================
   3. SIDEBAR  (dark)
   ===================================================================== */
.ace-sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--ace-sidebar-width);
    background: var(--ace-sidebar-bg);
    display: flex;
    flex-direction: column;
    z-index: 1040;
    transition: var(--ace-transition);
    border-right: 1px solid var(--ace-sidebar-border);
}

/* --- Brand block --------------------------------------------------- */
.ace-sidebar__brand {
    height: var(--ace-topbar-h);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: .3rem;
    padding: 0 1.25rem;
    border-bottom: 1px solid var(--ace-sidebar-border);
    flex-shrink: 0;
}

.ace-sidebar__logo {
    width: 38px; height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--ace-primary) 0%, var(--ace-purple) 100%);
    display: grid;
    place-items: center;
    color: #fff;
    font-weight: 800;
    font-size: .95rem;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(37, 99, 235, .35);
}

/* Brand wordmark image. Sits on a white chip so its dark lettering stays
   legible on the dark sidebar / login panel. */
.ace-brand-logo {
    height: 34px;
    width: auto;
    max-width: 100%;
    display: block;
    padding: 4px 8px;
    background: #fff;
    border-radius: 9px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .18);
    flex-shrink: 0;
}
/* Collapsed rail: shrink so the wordmark fits the narrow column. */
body.sidebar-collapsed .ace-brand-logo { height: auto; max-width: 56px; padding: 3px 4px; }

.ace-sidebar__title { color: var(--ace-sidebar-text-hi); font-weight: 700; font-size: .95rem; line-height: 1.2; }
.ace-sidebar__subtitle { color: var(--ace-sidebar-text); font-size: .7rem; letter-spacing: .04em; text-transform: uppercase; }

/* --- Navigation ------------------------------------------------------ */
.ace-sidebar__nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem .75rem 2rem;
}
.ace-sidebar__nav::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .12); }

.ace-nav-heading {
    color: #475569;
    font-size: .66rem;
    font-weight: 700;
    letter-spacing: .09em;
    text-transform: uppercase;
    padding: 1.1rem .85rem .45rem;
    white-space: nowrap;
}

.ace-nav-link {
    display: flex;
    align-items: center;
    gap: .8rem;
    padding: .62rem .85rem;
    margin-bottom: 2px;
    border-radius: var(--ace-radius-sm);
    color: var(--ace-sidebar-text);
    font-size: .845rem;
    font-weight: 500;
    transition: var(--ace-transition);
    position: relative;
    white-space: nowrap;
}

.ace-nav-link i:first-child {
    width: 20px;
    text-align: center;
    font-size: .95rem;
    flex-shrink: 0;
}

.ace-nav-link:hover {
    background: var(--ace-sidebar-hover);
    color: var(--ace-sidebar-text-hi);
}

.ace-nav-link.active {
    background: linear-gradient(90deg, rgba(59, 130, 246, .18) 0%, rgba(59, 130, 246, .04) 100%);
    color: #fff;
    font-weight: 600;
}

/* Left accent bar on the active item. */
.ace-nav-link.active::before {
    content: '';
    position: absolute;
    left: -.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 22px;
    border-radius: 0 3px 3px 0;
    background: var(--ace-sidebar-active);
}

.ace-nav-link .badge { margin-left: auto; font-size: .65rem; padding: .22em .5em; }

/* Disabled links for modules that are not built yet. */
.ace-nav-link.is-disabled { opacity: .38; cursor: not-allowed; pointer-events: none; }
.ace-nav-link .soon {
    margin-left: auto;
    font-size: .58rem;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: #475569;
    border: 1px solid #334155;
    border-radius: 4px;
    padding: .08rem .3rem;
}

/* --- Sidebar footer ---------------------------------------------------- */
.ace-sidebar__footer {
    padding: .85rem;
    border-top: 1px solid var(--ace-sidebar-border);
    flex-shrink: 0;
}

.ace-sidebar__user {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .6rem;
    border-radius: var(--ace-radius-sm);
    background: var(--ace-sidebar-bg-alt);
}

.ace-sidebar__user-name { color: var(--ace-sidebar-text-hi); font-size: .8rem; font-weight: 600; line-height: 1.2; }
.ace-sidebar__user-role { color: var(--ace-sidebar-text); font-size: .7rem; }

/* --- Collapsed state (desktop) ------------------------------------------- */
@media (min-width: 992px) {
    body.sidebar-collapsed .ace-sidebar { width: var(--ace-sidebar-collapsed); }
    body.sidebar-collapsed .ace-main    { margin-left: var(--ace-sidebar-collapsed); }

    body.sidebar-collapsed .ace-sidebar__title,
    body.sidebar-collapsed .ace-sidebar__subtitle,
    body.sidebar-collapsed .ace-nav-heading,
    body.sidebar-collapsed .ace-nav-link span,
    body.sidebar-collapsed .ace-nav-link .badge,
    body.sidebar-collapsed .ace-nav-link .soon,
    body.sidebar-collapsed .ace-sidebar__user > div:not(.ace-avatar) { display: none; }

    body.sidebar-collapsed .ace-sidebar__brand,
    body.sidebar-collapsed .ace-nav-link,
    body.sidebar-collapsed .ace-sidebar__user { justify-content: center; padding-left: 0; padding-right: 0; }
    /* Brand is a vertical stack, so centre the shrunk logo on the cross axis. */
    body.sidebar-collapsed .ace-sidebar__brand { align-items: center; }

    body.sidebar-collapsed .ace-nav-heading {
        display: block;
        height: 1px;
        padding: 0;
        margin: .75rem .5rem;
        background: var(--ace-sidebar-border);
        overflow: hidden;
        text-indent: -9999px;
    }
}

/* --- Mobile off-canvas behaviour -------------------------------------------- */
@media (max-width: 991.98px) {
    .ace-sidebar { transform: translateX(-100%); box-shadow: var(--ace-shadow-lg); }
    body.sidebar-open .ace-sidebar { transform: translateX(0); }

    .ace-sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, .5);
        backdrop-filter: blur(2px);
        z-index: 1035;
        opacity: 0;
        visibility: hidden;
        transition: var(--ace-transition);
    }
    body.sidebar-open .ace-sidebar-backdrop { opacity: 1; visibility: visible; }
}

/* =====================================================================
   4. MAIN AREA + TOPBAR
   ===================================================================== */
.ace-main {
    margin-left: var(--ace-sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: var(--ace-transition);
}

@media (max-width: 991.98px) { .ace-main { margin-left: 0; } }

.ace-topbar {
    height: var(--ace-topbar-h);
    background: var(--ace-topbar-bg);
    border-bottom: 1px solid var(--ace-border);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1030;
}

.ace-topbar__toggle {
    width: 38px; height: 38px;
    border: 1px solid var(--ace-border);
    background: #fff;
    border-radius: var(--ace-radius-sm);
    color: var(--ace-text-muted);
    display: grid;
    place-items: center;
    transition: var(--ace-transition);
}
.ace-topbar__toggle:hover { background: var(--ace-body-bg); color: var(--ace-primary); }

.ace-topbar__search {
    position: relative;
    max-width: 340px;
    flex: 1;
}
.ace-topbar__search i {
    position: absolute;
    left: .85rem; top: 50%;
    transform: translateY(-50%);
    color: var(--ace-text-light);
    font-size: .8rem;
}
.ace-topbar__search input {
    width: 100%;
    height: 38px;
    padding: 0 .9rem 0 2.3rem;
    border: 1px solid var(--ace-border);
    border-radius: var(--ace-radius-sm);
    background: var(--ace-body-bg);
    font-size: .82rem;
    transition: var(--ace-transition);
}
.ace-topbar__search input:focus {
    outline: none;
    background: #fff;
    border-color: var(--ace-primary-light);
    box-shadow: 0 0 0 3px var(--ace-primary-soft);
}

.ace-topbar__action {
    width: 38px; height: 38px;
    border: 1px solid var(--ace-border);
    background: #fff;
    border-radius: var(--ace-radius-sm);
    color: var(--ace-text-muted);
    display: grid;
    place-items: center;
    position: relative;
    transition: var(--ace-transition);
}
.ace-topbar__action:hover { background: var(--ace-body-bg); color: var(--ace-primary); }

.ace-topbar__badge {
    position: absolute;
    top: -5px; right: -5px;
    min-width: 18px; height: 18px;
    padding: 0 4px;
    border-radius: 9px;
    background: var(--ace-danger);
    color: #fff;
    font-size: .62rem;
    font-weight: 700;
    display: grid;
    place-items: center;
    border: 2px solid #fff;
}

.ace-content { flex: 1; padding: 1.5rem; }
@media (max-width: 575.98px) { .ace-content, .ace-topbar { padding-left: 1rem; padding-right: 1rem; } }

.ace-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--ace-border);
    background: #fff;
    color: var(--ace-text-muted);
    font-size: .78rem;
}

/* =====================================================================
   5. AVATARS
   ===================================================================== */
.ace-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-weight: 600;
    font-size: .78rem;
    color: #fff;
    background: linear-gradient(135deg, var(--ace-primary) 0%, var(--ace-purple) 100%);
    flex-shrink: 0;
    overflow: hidden;
}
.ace-avatar img { width: 100%; height: 100%; object-fit: cover; }
.ace-avatar--sm { width: 28px; height: 28px; font-size: .68rem; }
.ace-avatar--lg { width: 56px; height: 56px; font-size: 1.1rem; }
.ace-avatar--xl { width: 92px; height: 92px; font-size: 1.9rem; }

/* =====================================================================
   6. PAGE HEADER + BREADCRUMB
   ===================================================================== */
.ace-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.35rem;
}
.ace-page-header h1 { font-size: 1.4rem; font-weight: 700; margin: 0 0 .2rem; }
.ace-page-header .subtitle { color: var(--ace-text-muted); font-size: .82rem; margin: 0; }

.ace-breadcrumb {
    display: flex;
    align-items: center;
    gap: .45rem;
    font-size: .76rem;
    color: var(--ace-text-light);
    margin-bottom: .35rem;
}
.ace-breadcrumb a { color: var(--ace-text-muted); }
.ace-breadcrumb a:hover { color: var(--ace-primary); }
.ace-breadcrumb .sep { opacity: .5; font-size: .6rem; }

/* =====================================================================
   7. CARDS
   ===================================================================== */
.ace-card {
    background: var(--ace-card-bg);
    border: 1px solid var(--ace-border);
    border-radius: var(--ace-radius);
    box-shadow: var(--ace-shadow-xs);
    transition: var(--ace-transition);
}
.ace-card:hover { box-shadow: var(--ace-shadow-sm); }

/* Stretch to equal height ONLY when a card is the sole occupant of its grid
   column (dashboard KPI/chart rows). When several cards are stacked in one
   column—forms, detail pages—they stay content-height so a short section no
   longer leaves a tall empty gap below it. Opt in explicitly with .ace-card--fill. */
[class*="col-"] > .ace-card:only-child,
.ace-card--fill { height: 100%; }

.ace-card__header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--ace-border-soft);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    flex-wrap: wrap;
}
.ace-card__title { font-size: .92rem; font-weight: 650; margin: 0; display: flex; align-items: center; gap: .5rem; }
.ace-card__title i { color: var(--ace-primary); }
.ace-card__subtitle { font-size: .74rem; color: var(--ace-text-muted); margin: .15rem 0 0; }
.ace-card__body { padding: 1.25rem; }
.ace-card__body--flush { padding: 0; }
.ace-card__footer {
    padding: .75rem 1.25rem;
    border-top: 1px solid var(--ace-border-soft);
    background: #fbfcfe;
    border-radius: 0 0 var(--ace-radius) var(--ace-radius);
    font-size: .78rem;
}

/* =====================================================================
   8. STAT (KPI) CARDS
   ===================================================================== */
.ace-stat {
    background: var(--ace-card-bg);
    border: 1px solid var(--ace-border);
    border-radius: var(--ace-radius);
    padding: 1.15rem 1.25rem;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    position: relative;
    overflow: hidden;
    transition: var(--ace-transition);
    height: 100%;
}
.ace-stat:hover { box-shadow: var(--ace-shadow); transform: translateY(-2px); }

/* Coloured wash in the top-right corner, tinted per variant. */
.ace-stat::after {
    content: '';
    position: absolute;
    top: -42px; right: -42px;
    width: 110px; height: 110px;
    border-radius: 50%;
    background: var(--stat-color, var(--ace-primary));
    opacity: .06;
}

.ace-stat__icon {
    width: 46px; height: 46px;
    border-radius: var(--ace-radius-sm);
    display: grid;
    place-items: center;
    font-size: 1.15rem;
    color: var(--stat-color, var(--ace-primary));
    background: color-mix(in srgb, var(--stat-color, var(--ace-primary)) 12%, transparent);
    flex-shrink: 0;
}

.ace-stat__label {
    font-size: .74rem;
    font-weight: 600;
    color: var(--ace-text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin: 0 0 .3rem;
}
.ace-stat__value {
    font-size: 1.62rem;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -.02em;
    margin: 0;
    color: var(--ace-text);
}
.ace-stat__meta { font-size: .74rem; color: var(--ace-text-muted); margin: .3rem 0 0; }

/* Report KPI tiles pack six across and carry large numbers ("1,208,925 kWh").
   Stack the icon above the content so the value gets the card's full width
   instead of being squeezed (and clipped) beside the icon. */
#reportKpis .ace-stat {
    flex-direction: column;
    align-items: flex-start;
    gap: .65rem;
}
#reportKpis .ace-stat > .min-w-0 { width: 100%; }

/* Number stays prominent; the unit drops to a smaller muted token on the
   same baseline instead of wrapping at full size. */
#reportKpis .ace-stat__value {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: .15rem .3rem;
    font-size: 1.5rem;
    overflow-wrap: anywhere;   /* last-resort break for extreme values */
}
#reportKpis .ace-stat__unit {
    font-size: .82rem;
    font-weight: 600;
    letter-spacing: 0;
    color: var(--ace-text-muted);
}

.ace-stat__trend {
    display: inline-flex;
    align-items: center;
    gap: .22rem;
    font-size: .72rem;
    font-weight: 600;
    padding: .1rem .4rem;
    border-radius: 5px;
}
.ace-stat__trend--up   { color: var(--ace-danger);  background: rgba(239, 68, 68, .1); }
.ace-stat__trend--down { color: var(--ace-success); background: rgba(16, 185, 129, .1); }
.ace-stat__trend--flat { color: var(--ace-text-muted); background: rgba(100, 116, 139, .1); }

/* Variant colours consumed by --stat-color. */
.stat-primary { --stat-color: var(--ace-primary); }
.stat-success { --stat-color: var(--ace-success); }
.stat-warning { --stat-color: var(--ace-warning); }
.stat-danger  { --stat-color: var(--ace-danger);  }
.stat-info    { --stat-color: var(--ace-info);    }
.stat-purple  { --stat-color: var(--ace-purple);  }
.stat-teal    { --stat-color: var(--ace-teal);    }
.stat-pink    { --stat-color: var(--ace-pink);    }

/* =====================================================================
   9. BADGES
   ===================================================================== */
.badge {
    font-weight: 600;
    font-size: .7rem;
    padding: .32em .62em;
    border-radius: 6px;
    letter-spacing: .01em;
}

/* Soft (tinted) badges - the default across the panel. */
.badge-soft-primary   { background: rgba(37, 99, 235, .11);  color: #1d4ed8; }
.badge-soft-success   { background: rgba(16, 185, 129, .12); color: #047857; }
.badge-soft-warning   { background: rgba(245, 158, 11, .13); color: #b45309; }
.badge-soft-danger    { background: rgba(239, 68, 68, .11);  color: #b91c1c; }
.badge-soft-info      { background: rgba(6, 182, 212, .12);  color: #0e7490; }
.badge-soft-secondary { background: rgba(100, 116, 139, .12);color: #475569; }
.badge-soft-dark      { background: rgba(15, 23, 42, .09);   color: #1e293b; }
.badge-soft-purple    { background: rgba(139, 92, 246, .12); color: #6d28d9; }

/* =====================================================================
   10. TABLES
   ===================================================================== */
.ace-table { width: 100%; margin: 0; font-size: .82rem; }

.ace-table thead th {
    background: #f8fafc;
    border-bottom: 1px solid var(--ace-border);
    border-top: none;
    color: var(--ace-text-muted);
    font-weight: 650;
    font-size: .71rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    padding: .72rem 1rem;
    white-space: nowrap;
    vertical-align: middle;
}

.ace-table tbody td {
    padding: .78rem 1rem;
    border-bottom: 1px solid var(--ace-border-soft);
    vertical-align: middle;
    color: var(--ace-text);
}

.ace-table tbody tr:last-child td { border-bottom: none; }
.ace-table tbody tr { transition: background .15s ease; }
.ace-table tbody tr:hover { background: #f8fafc; }

.ace-table .cell-primary { font-weight: 600; color: var(--ace-text); }
.ace-table .cell-muted   { color: var(--ace-text-muted); font-size: .78rem; }
.ace-table .cell-number  { font-variant-numeric: tabular-nums; text-align: right; }

/* DataTables integration */
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
    border: 1px solid var(--ace-border);
    border-radius: var(--ace-radius-sm);
    padding: .35rem .65rem;
    font-size: .8rem;
}
/* The length menu is a <select>; keep its right padding wide enough that
   the chevron never overlaps the row count (e.g. "25"). */
.dataTables_wrapper .dataTables_length select { padding-right: 1.9rem; }
.dataTables_wrapper .dataTables_filter input:focus,
.dataTables_wrapper .dataTables_length select:focus {
    outline: none;
    border-color: var(--ace-primary-light);
    box-shadow: 0 0 0 3px var(--ace-primary-soft);
}
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter { font-size: .78rem; color: var(--ace-text-muted); padding: .75rem 1rem; }
.dataTables_wrapper .dataTables_paginate { padding: .75rem 1rem; }
.page-link { border-radius: var(--ace-radius-sm) !important; margin: 0 2px; border-color: var(--ace-border); font-size: .8rem; color: var(--ace-text-muted); }
.page-item.active .page-link { background: var(--ace-primary); border-color: var(--ace-primary); }

/* Row-expand control (DataTables Responsive). Replaces the plugin's plain
   triangle with a branded chevron chip that flips down when the row opens.
   !important is needed to beat the plugin's higher-specificity selectors. */
table.dataTable td.dtr-control { cursor: pointer; }
table.dataTable td.dtr-control:before {
    content: '\f054' !important;            /* fa chevron-right */
    font-family: 'Font Awesome 6 Free' !important;
    font-weight: 900 !important;
    font-size: .62rem;
    color: #b7212c;
    background: rgba(183, 33, 44, .10);
    border: none !important;
    box-shadow: none !important;
    position: static !important;
    top: auto !important;
    left: auto !important;
    transform: none !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 19px; height: 19px;
    margin: 0 .5rem 0 0 !important;
    border-radius: 6px;
    line-height: 1;
    vertical-align: middle;
    transition: background .18s ease, color .18s ease;
}
table.dataTable td.dtr-control:hover:before { background: rgba(183, 33, 44, .2); }
table.dataTable tr.dtr-expanded > td.dtr-control:before,
table.dataTable tr.parent    > td.dtr-control:before,
table.dataTable tr.shown     > td.dtr-control:before {
    content: '\f078' !important;            /* fa chevron-down */
    background: #b7212c;
    color: #fff;
}

/* =====================================================================
   11. FORMS
   ===================================================================== */
.form-label {
    font-size: .78rem;
    font-weight: 600;
    color: var(--ace-text);
    margin-bottom: .35rem;
}
.form-label .required { color: var(--ace-danger); margin-left: 2px; }

.form-control, .form-select {
    border: 1px solid var(--ace-border);
    border-radius: var(--ace-radius-sm);
    padding: .52rem .8rem;
    font-size: .84rem;
    color: var(--ace-text);
    transition: var(--ace-transition);
}
/* A .form-select draws its chevron as a background image sitting in the
   right padding, so it needs extra room there or the value slides under
   the arrow. The shared rule above trims padding for inputs; add the
   clearance back for selects only. */
.form-select { padding-right: 2.25rem; }
.form-select-sm { padding-right: 2rem; }
.form-control:focus, .form-select:focus {
    border-color: var(--ace-primary-light);
    box-shadow: 0 0 0 3px var(--ace-primary-soft);
}
.form-control::placeholder { color: var(--ace-text-light); }
.form-control:disabled, .form-select:disabled { background: #f8fafc; }
/* Purchase-order line-item picker: long item names should ellipsize instead of clipping mid-word. */
.js-po-item { text-overflow: ellipsis; }
/* PO line-item number columns are narrow (qty/rate/disc%/gst%); the native spinner
   arrows eat 20-30px of that, clipping the value itself. Drop the spinner so the
   full column width goes to the digits. */
.js-po-qty, .js-po-rate, .js-po-disc, .js-po-gst { -moz-appearance: textfield; }
.js-po-qty::-webkit-inner-spin-button, .js-po-qty::-webkit-outer-spin-button,
.js-po-rate::-webkit-inner-spin-button, .js-po-rate::-webkit-outer-spin-button,
.js-po-disc::-webkit-inner-spin-button, .js-po-disc::-webkit-outer-spin-button,
.js-po-gst::-webkit-inner-spin-button, .js-po-gst::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.form-control.is-invalid, .form-select.is-invalid { border-color: var(--ace-danger); }
.invalid-feedback { font-size: .74rem; }
.form-text { font-size: .73rem; color: var(--ace-text-muted); }

.input-group-text {
    background: #f8fafc;
    border-color: var(--ace-border);
    color: var(--ace-text-muted);
    font-size: .82rem;
}

/* =====================================================================
   12. BUTTONS
   ===================================================================== */
.btn {
    font-size: .82rem;
    font-weight: 600;
    padding: .5rem 1rem;
    border-radius: var(--ace-radius-sm);
    transition: var(--ace-transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .45rem;
}
.btn-sm { font-size: .76rem; padding: .34rem .7rem; }
.btn-lg { font-size: .9rem;  padding: .68rem 1.35rem; }

.btn-primary {
    background: #b7212c;
    border-color: #b7212c;
    box-shadow: 0 1px 2px rgba(183, 33, 44, .2);
}
.btn-primary:hover, .btn-primary:focus,
.btn-primary:active, .btn-primary.active,
.btn-primary:first-child:active,
.btn-check:checked + .btn-primary {
    background: #9a1b24;
    border-color: #9a1b24;
    box-shadow: 0 4px 12px rgba(183, 33, 44, .3);
}
/* Keyboard focus ring in the brand red instead of Bootstrap's blue. */
.btn-primary:focus-visible {
    box-shadow: 0 0 0 3px rgba(183, 33, 44, .35);
}

.btn-light {
    background: #fff;
    border-color: var(--ace-border);
    color: var(--ace-text-muted);
}
.btn-light:hover { background: var(--ace-body-bg); color: var(--ace-text); border-color: var(--ace-border); }

/* Icon-only action button used in table rows. */
.btn-icon {
    width: 30px; height: 30px;
    padding: 0;
    border-radius: 7px;
    display: inline-grid;
    place-items: center;
    font-size: .78rem;
}

/* =====================================================================
   13. CHARTS
   ===================================================================== */
.ace-chart {
    position: relative;
    width: 100%;
}
.ace-chart--sm  { height: 220px; }
.ace-chart--md  { height: 290px; }
.ace-chart--lg  { height: 340px; }

/* Loading shimmer shown until the AJAX payload arrives. */
.ace-chart__loading {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background: #fff;
    border-radius: var(--ace-radius-sm);
    z-index: 2;
}

.ace-legend { display: flex; flex-wrap: wrap; gap: .9rem; font-size: .75rem; color: var(--ace-text-muted); }
.ace-legend__item { display: inline-flex; align-items: center; gap: .35rem; }
.ace-legend__dot { width: 9px; height: 9px; border-radius: 3px; flex-shrink: 0; }

/* =====================================================================
   14. ACTIVITY FEED
   ===================================================================== */
.ace-feed { list-style: none; margin: 0; padding: 0; position: relative; }

.ace-feed__item {
    display: flex;
    gap: .85rem;
    padding: .8rem 1.25rem;
    border-bottom: 1px solid var(--ace-border-soft);
    transition: background .15s ease;
}
.ace-feed__item:last-child { border-bottom: none; }
.ace-feed__item:hover { background: #f8fafc; }

.ace-feed__icon {
    width: 34px; height: 34px;
    border-radius: 9px;
    display: grid;
    place-items: center;
    font-size: .8rem;
    flex-shrink: 0;
    background: var(--ace-primary-soft);
    color: var(--ace-primary);
}

.ace-feed__title { font-size: .82rem; font-weight: 600; margin: 0; color: var(--ace-text); }
.ace-feed__desc  { font-size: .76rem; color: var(--ace-text-muted); margin: .1rem 0 0; }
.ace-feed__meta  { font-size: .7rem;  color: var(--ace-text-light); margin: .22rem 0 0; display: flex; gap: .6rem; flex-wrap: wrap; }

/* =====================================================================
   15. ATTENTION LIST
   ===================================================================== */
.ace-attention__item {
    display: flex;
    align-items: center;
    gap: .85rem;
    padding: .78rem 1.25rem;
    border-bottom: 1px solid var(--ace-border-soft);
    border-left: 3px solid transparent;
    transition: var(--ace-transition);
}
.ace-attention__item:last-child { border-bottom: none; }
.ace-attention__item:hover { background: #f8fafc; }

.ace-attention__item[data-severity="critical"] { border-left-color: var(--ace-danger); }
.ace-attention__item[data-severity="high"]     { border-left-color: var(--ace-warning); }
.ace-attention__item[data-severity="medium"]   { border-left-color: var(--ace-info); }
.ace-attention__item[data-severity="low"]      { border-left-color: var(--ace-text-light); }

.ace-attention__icon {
    width: 32px; height: 32px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    font-size: .78rem;
    flex-shrink: 0;
}
[data-severity="critical"] .ace-attention__icon { background: rgba(239, 68, 68, .1);  color: var(--ace-danger); }
[data-severity="high"]     .ace-attention__icon { background: rgba(245, 158, 11, .12);color: var(--ace-warning); }
[data-severity="medium"]   .ace-attention__icon { background: rgba(6, 182, 212, .12); color: var(--ace-info); }
[data-severity="low"]      .ace-attention__icon { background: rgba(100,116,139,.1);   color: var(--ace-text-muted); }

/* =====================================================================
   16. PROGRESS
   ===================================================================== */
.progress { height: 6px; border-radius: 3px; background: #eef2f7; }
.progress-bar { border-radius: 3px; }
.progress--thin { height: 4px; }

/* =====================================================================
   17. RATING STARS
   ===================================================================== */
.rating-stars { color: var(--ace-accent); font-size: .74rem; letter-spacing: .5px; white-space: nowrap; }
.rating-stars .fa-regular { color: #d8dee9; }

/* =====================================================================
   18. DROPDOWNS
   ===================================================================== */
.dropdown-menu {
    border: 1px solid var(--ace-border);
    border-radius: var(--ace-radius);
    box-shadow: var(--ace-shadow-lg);
    padding: .4rem;
    font-size: .83rem;
    min-width: 200px;
}
.dropdown-item { border-radius: var(--ace-radius-sm); padding: .48rem .7rem; display: flex; align-items: center; gap: .6rem; }
.dropdown-item:hover { background: var(--ace-body-bg); }
.dropdown-item i { width: 16px; text-align: center; color: var(--ace-text-muted); }
.dropdown-header { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--ace-text-light); padding: .5rem .7rem .3rem; }
.dropdown-divider { margin: .3rem 0; border-color: var(--ace-border-soft); }

/* Notification dropdown */
.ace-notif-dropdown { width: 370px; max-width: calc(100vw - 2rem); padding: 0; }
.ace-notif-dropdown__header {
    padding: .8rem 1rem;
    border-bottom: 1px solid var(--ace-border-soft);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.ace-notif-dropdown__list { max-height: 380px; overflow-y: auto; }
.ace-notif-item {
    display: flex;
    gap: .75rem;
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--ace-border-soft);
    transition: background .15s ease;
}
.ace-notif-item:hover { background: #f8fafc; }
.ace-notif-item__icon {
    width: 32px; height: 32px;
    border-radius: 8px;
    display: grid; place-items: center;
    font-size: .78rem;
    flex-shrink: 0;
}
.ace-notif-item__title { font-size: .8rem; font-weight: 600; margin: 0; }
.ace-notif-item__text  { font-size: .74rem; color: var(--ace-text-muted); margin: .1rem 0 0; }
.ace-notif-item__time  { font-size: .68rem; color: var(--ace-text-light); margin: .2rem 0 0; }

/* =====================================================================
   19. MODALS & OFFCANVAS
   ===================================================================== */
.modal-content { border: none; border-radius: var(--ace-radius-lg); box-shadow: var(--ace-shadow-lg); }
.modal-header { border-bottom: 1px solid var(--ace-border-soft); padding: 1.1rem 1.35rem; }
.modal-title { font-size: 1rem; font-weight: 650; }
.modal-body { padding: 1.35rem; }
.modal-footer { border-top: 1px solid var(--ace-border-soft); padding: .9rem 1.35rem; }

.offcanvas { border: none; box-shadow: var(--ace-shadow-lg); }
.offcanvas-header { border-bottom: 1px solid var(--ace-border-soft); padding: 1.1rem 1.35rem; }
.offcanvas-title { font-size: 1rem; font-weight: 650; }
.offcanvas-body { padding: 1.35rem; }

/* =====================================================================
   20. EMPTY / LOADING STATES
   ===================================================================== */
.ace-empty { padding: 2.75rem 1.5rem; text-align: center; }
.ace-empty__icon {
    width: 62px; height: 62px;
    margin: 0 auto 1rem;
    border-radius: 50%;
    background: var(--ace-body-bg);
    display: grid; place-items: center;
    font-size: 1.4rem;
    color: var(--ace-text-light);
}
.ace-empty__title { font-size: .9rem; font-weight: 600; margin: 0 0 .25rem; }
.ace-empty__text  { font-size: .8rem; color: var(--ace-text-muted); margin: 0; }

.ace-skeleton {
    background: linear-gradient(90deg, #eef2f7 25%, #f8fafc 50%, #eef2f7 75%);
    background-size: 200% 100%;
    animation: ace-shimmer 1.4s ease-in-out infinite;
    border-radius: 6px;
}
@keyframes ace-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* =====================================================================
   21. AUTH PAGES
   ===================================================================== */
.ace-auth {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr;
    background: var(--ace-body-bg);
}
@media (min-width: 992px) { .ace-auth { grid-template-columns: 1.05fr 1fr; } }

.ace-auth__brand {
    display: none;
    position: relative;
    padding: 3.5rem;
    background: linear-gradient(145deg, #0f172a 0%, #1e293b 55%, #1d4ed8 140%);
    color: #fff;
    overflow: hidden;
    flex-direction: column;
    justify-content: space-between;
}
@media (min-width: 992px) { .ace-auth__brand { display: flex; } }

/* Decorative blurred orbs. */
.ace-auth__brand::before,
.ace-auth__brand::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    filter: blur(72px);
}
.ace-auth__brand::before { width: 340px; height: 340px; background: rgba(59, 130, 246, .3);  top: -80px; right: -90px; }
.ace-auth__brand::after  { width: 300px; height: 300px; background: rgba(139, 92, 246, .22); bottom: -90px; left: -70px; }

.ace-auth__brand > * { position: relative; z-index: 1; }

.ace-auth__headline { font-size: 2.1rem; font-weight: 700; line-height: 1.2; color: #fff; letter-spacing: -.02em; }
.ace-auth__lead { color: #cbd5e1; font-size: .92rem; max-width: 42ch; }

.ace-auth__feature { display: flex; align-items: flex-start; gap: .85rem; margin-bottom: 1.1rem; }
.ace-auth__feature-icon {
    width: 38px; height: 38px;
    border-radius: 10px;
    background: rgba(255, 255, 255, .1);
    border: 1px solid rgba(255, 255, 255, .12);
    display: grid; place-items: center;
    font-size: .88rem;
    color: #93c5fd;
    flex-shrink: 0;
}
.ace-auth__feature h6 { color: #fff; font-size: .85rem; margin: 0 0 .1rem; }
.ace-auth__feature p  { color: #94a3b8; font-size: .78rem; margin: 0; }

.ace-auth__form {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1.25rem;
}
.ace-auth__card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border: 1px solid var(--ace-border);
    border-radius: var(--ace-radius-lg);
    box-shadow: var(--ace-shadow);
    padding: 2.25rem;
}
@media (max-width: 575.98px) { .ace-auth__card { padding: 1.5rem; box-shadow: none; border: none; background: transparent; } }

.ace-auth__logo {
    width: 54px; height: 54px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--ace-primary) 0%, var(--ace-purple) 100%);
    display: grid; place-items: center;
    color: #fff; font-weight: 800; font-size: 1.15rem;
    margin-bottom: 1.25rem;
    box-shadow: 0 8px 20px rgba(37, 99, 235, .3);
}

.ace-password-toggle {
    position: absolute;
    right: .6rem; top: 50%;
    transform: translateY(-50%);
    background: none; border: none;
    color: var(--ace-text-light);
    padding: .25rem .4rem;
    font-size: .82rem;
    z-index: 5;
}
.ace-password-toggle:hover { color: var(--ace-text-muted); }

/* Demo credential chips on the login page. */
.ace-demo-chip {
    border: 1px solid var(--ace-border);
    border-radius: var(--ace-radius-sm);
    padding: .45rem .6rem;
    font-size: .72rem;
    background: #fff;
    cursor: pointer;
    transition: var(--ace-transition);
    text-align: left;
    width: 100%;
}
.ace-demo-chip:hover { border-color: var(--ace-primary-light); background: var(--ace-primary-soft); }
.ace-demo-chip strong { display: block; color: var(--ace-text); font-size: .74rem; }
.ace-demo-chip span   { color: var(--ace-text-muted); }

/* =====================================================================
   22. ERROR PAGES
   ===================================================================== */
.ace-error {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 2rem 1.25rem;
    text-align: center;
}
.ace-error__code {
    font-size: clamp(4rem, 16vw, 7.5rem);
    font-weight: 800;
    line-height: 1;
    letter-spacing: -.04em;
    background: linear-gradient(135deg, var(--ace-primary) 0%, var(--ace-purple) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.ace-error__title { font-size: 1.4rem; font-weight: 700; margin: .5rem 0 .4rem; }
.ace-error__text  { color: var(--ace-text-muted); max-width: 46ch; margin: 0 auto 1.75rem; }
.ace-error__trace {
    text-align: left;
    background: #0f172a;
    color: #cbd5e1;
    border-radius: var(--ace-radius);
    padding: 1.1rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .72rem;
    line-height: 1.6;
    max-height: 340px;
    overflow: auto;
    margin-top: 2rem;
}

/* =====================================================================
   23. UTILITIES
   ===================================================================== */
.fs-xs { font-size: .72rem !important; }
.fs-sm { font-size: .8rem  !important; }
.fw-650 { font-weight: 650 !important; }
.text-tabular { font-variant-numeric: tabular-nums; }
.cursor-pointer { cursor: pointer; }
.min-w-0 { min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.divider-v { width: 1px; height: 26px; background: var(--ace-border); }

.hover-lift { transition: var(--ace-transition); }
.hover-lift:hover { transform: translateY(-2px); box-shadow: var(--ace-shadow); }

/* Print: drop the chrome, keep the content. */
@media print {
    .ace-sidebar, .ace-topbar, .ace-footer, .no-print, .btn { display: none !important; }
    .ace-main { margin-left: 0 !important; }
    .ace-card { border: 1px solid #ddd !important; box-shadow: none !important; break-inside: avoid; }
    body { background: #fff; }
}

/* Respect reduced-motion preferences. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}

/* =====================================================================
   23. RESIDENT PORTAL
   ===================================================================== */
.ace-portal { background: var(--ace-body-bg); min-height: 100vh; }

.ace-portal__bar {
    background: #fff;
    border-bottom: 1px solid var(--ace-border);
    position: sticky; top: 0; z-index: 1030;
}
.ace-portal__inner {
    max-width: 860px;
    margin: 0 auto;
    padding: .7rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}
.ace-portal__brand { display: inline-flex; align-items: center; }
.ace-portal__brand .ace-brand-logo { box-shadow: none; padding: 0; background: transparent; height: 30px; }

.ace-portal__nav { display: flex; gap: .25rem; margin-left: auto; }
.ace-portal__link {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .4rem .7rem;
    border-radius: var(--ace-radius-sm);
    font-size: .82rem; font-weight: 600;
    color: var(--ace-text-muted);
}
.ace-portal__link:hover { background: var(--ace-body-bg); color: var(--ace-text); }
.ace-portal__link.is-active { background: var(--ace-primary-soft); color: var(--ace-primary); }

.ace-portal__main { padding: 1.5rem 1.25rem 3rem; }
.ace-portal__content { max-width: 860px; margin: 0 auto; }

/* Category glyph on the complaint cards. */
.ace-portal__cat-icon {
    width: 42px; height: 42px;
    border-radius: 11px;
    display: grid; place-items: center;
    flex-shrink: 0;
    background: var(--ace-primary-soft);
    color: var(--ace-primary);
    font-size: 1rem;
}

/* Profile avatar. */
.ace-portal__avatar {
    width: 52px; height: 52px;
    border-radius: 50%;
    display: grid; place-items: center;
    background: linear-gradient(135deg, var(--ace-primary) 0%, var(--ace-purple) 100%);
    color: #fff; font-weight: 700;
    flex-shrink: 0;
}

/* Star-rating picker. */
.ace-portal__stars { display: inline-flex; gap: .2rem; }
.ace-portal__star {
    background: none; border: none; padding: .1rem;
    font-size: 1.4rem; line-height: 1;
    color: var(--ace-warning, #f59e0b);
    cursor: pointer;
}
.ace-portal__star i.fa-regular { color: var(--ace-text-light); }

/* =====================================================================
   AI ASSISTANT :: floating chat widget
   ===================================================================== */
.ace-ai {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1080;
    font-family: var(--ace-font);
}

/* Launcher button */
.ace-ai-launcher {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: none;
    cursor: pointer;
    padding: 12px 18px;
    border-radius: 999px;
    color: #fff;
    background: linear-gradient(135deg, var(--ace-primary), var(--ace-purple, #8b5cf6));
    box-shadow: var(--ace-shadow-lg, 0 12px 30px rgba(37, 99, 235, .35));
    font-weight: 600;
    font-size: 14px;
    transition: transform .18s ease, box-shadow .18s ease;
}
.ace-ai-launcher:hover { transform: translateY(-2px); }
.ace-ai-launcher i { font-size: 16px; }
.ace-ai.is-open .ace-ai-launcher { display: none; }

/* "Save as PDF" action under an assistant message */
.ace-ai-msg-actions {
    display: flex;
    justify-content: flex-start;
    width: 100%;               /* drop onto its own line, below the bubble */
    margin: 2px 0 6px 6px;
}
.ace-ai-pdf-btn {
    border: 1px solid var(--ace-border, #d7dce5);
    background: #fff;
    color: var(--ace-primary, #2563eb);
    border-radius: 999px;
    padding: 3px 10px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: background .15s ease, color .15s ease;
}
.ace-ai-pdf-btn:hover { background: var(--ace-primary, #2563eb); color: #fff; }

/* Print-to-PDF: a dedicated container shown only while printing */
#ace-ai-print { display: none; }
@media print {
    body.ace-ai-printing > * { display: none !important; }
    body.ace-ai-printing #ace-ai-print { display: block !important; }
    @page { margin: 16mm; }
}
#ace-ai-print, #ace-ai-print * { color: #000 !important; }
.ace-ai-print-head { border-bottom: 2px solid #333; margin-bottom: 16px; padding-bottom: 8px; }
.ace-ai-print-brand { font-size: 18px; font-weight: 700; }
.ace-ai-print-title { font-size: 15px; margin-top: 2px; }
.ace-ai-print-meta  { font-size: 11px; color: #555 !important; margin-top: 2px; }
.ace-ai-print-body  { font-size: 13px; line-height: 1.5; }
.ace-ai-print-body h3, .ace-ai-print-body h4, .ace-ai-print-body h5 { margin: 14px 0 6px; }
.ace-ai-print-body ul { margin: 6px 0; padding-left: 20px; }
.ace-ai-print-body table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.ace-ai-print-body th, .ace-ai-print-body td { border: 1px solid #999; padding: 6px 8px; text-align: left; font-size: 12px; }
.ace-ai-print-body .ace-ai-table-wrap { overflow: visible; }

/* Reminder count badge on the launcher */
.ace-ai-launcher { position: relative; }
.ace-ai-badge {
    position: absolute;
    top: -6px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: #f59e0b;               /* amber = has reminders */
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
    box-shadow: 0 0 0 2px #fff;
    animation: ace-ai-badge-pop .25s ease;
}
.ace-ai-badge.is-critical {
    background: #ef4444;               /* red = something overdue / SLA breached */
    animation: ace-ai-badge-pop .25s ease, ace-ai-badge-pulse 1.8s ease-in-out infinite;
}
@keyframes ace-ai-badge-pop {
    from { transform: scale(0); }
    to   { transform: scale(1); }
}
@keyframes ace-ai-badge-pulse {
    0%, 100% { box-shadow: 0 0 0 2px #fff, 0 0 0 0 rgba(239, 68, 68, .5); }
    50%      { box-shadow: 0 0 0 2px #fff, 0 0 0 6px rgba(239, 68, 68, 0); }
}
@media (max-width: 480px) {
    .ace-ai-launcher-label { display: none; }
    .ace-ai-launcher { padding: 14px; }
}

/* Panel */
.ace-ai-panel {
    width: 384px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
    background: var(--ace-card-bg, #fff);
    border: 1px solid var(--ace-border, #e5e7eb);
    border-radius: var(--ace-radius-lg, 18px);
    box-shadow: var(--ace-shadow-lg, 0 24px 60px rgba(15, 23, 42, .25));
    overflow: hidden;
    animation: aceAiIn .18s ease;
}
@keyframes aceAiIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Header */
.ace-ai-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    color: #fff;
    background: linear-gradient(135deg, var(--ace-primary), var(--ace-purple, #8b5cf6));
}
.ace-ai-head-title { display: flex; align-items: center; gap: 10px; }
.ace-ai-head-title strong { display: block; font-size: 15px; line-height: 1.1; }
.ace-ai-head-title small { font-size: 11.5px; opacity: .85; }
.ace-ai-avatar {
    width: 34px; height: 34px;
    display: grid; place-items: center;
    border-radius: 10px;
    background: rgba(255, 255, 255, .18);
    font-size: 16px;
}
.ace-ai-head-actions { display: flex; gap: 4px; }
.ace-ai-icon-btn {
    border: none; background: transparent; color: #fff;
    width: 30px; height: 30px; border-radius: 8px; cursor: pointer;
    opacity: .85; transition: background .15s, opacity .15s;
}
.ace-ai-icon-btn:hover { background: rgba(255, 255, 255, .18); opacity: 1; }

/* Quick chips */
.ace-ai-quick {
    display: flex; gap: 8px; flex-wrap: wrap;
    padding: 10px 12px;
    border-bottom: 1px solid var(--ace-border-soft, #f1f5f9);
    background: var(--ace-body-bg, #f8fafc);
}
.ace-ai-chip {
    border: 1px solid var(--ace-border, #e5e7eb);
    background: #fff;
    color: var(--ace-text, #1e293b);
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex; align-items: center; gap: 6px;
    transition: border-color .15s, color .15s, background .15s;
}
.ace-ai-chip i { color: var(--ace-primary); font-size: 12px; }
.ace-ai-chip:hover:not(:disabled) { border-color: var(--ace-primary); color: var(--ace-primary); }
.ace-ai-chip:disabled { opacity: .5; cursor: default; }

/* Log */
.ace-ai-log {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--ace-body-bg, #f8fafc);
}
.ace-ai-msg { display: flex; flex-wrap: wrap; }
.ace-ai-msg-user { justify-content: flex-end; }
.ace-ai-bubble {
    max-width: 86%;
    padding: 10px 13px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.5;
    box-shadow: var(--ace-shadow-xs, 0 1px 2px rgba(15, 23, 42, .06));
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
.ace-ai-msg-assistant .ace-ai-bubble {
    background: #fff;
    color: var(--ace-text, #1e293b);
    border: 1px solid var(--ace-border-soft, #eef2f7);
    border-bottom-left-radius: 4px;
}
.ace-ai-msg-user .ace-ai-bubble {
    background: var(--ace-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.ace-ai-bubble h4, .ace-ai-bubble h5, .ace-ai-bubble h6 {
    margin: 2px 0 6px; font-size: 14px; font-weight: 700;
}
.ace-ai-bubble p { margin: 0 0 8px; }
.ace-ai-bubble p:last-child { margin-bottom: 0; }
.ace-ai-bubble ul { margin: 4px 0; padding-left: 18px; }
.ace-ai-bubble li { margin: 2px 0; }
.ace-ai-bubble code {
    background: rgba(148, 163, 184, .18);
    padding: 1px 5px; border-radius: 5px;
    font-size: 12px;
}
.ace-ai-msg-user .ace-ai-bubble code { background: rgba(255, 255, 255, .22); }

/* Tables inside answers */
.ace-ai-table-wrap { overflow-x: auto; margin: 6px 0; }
.ace-ai-table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.ace-ai-table th, .ace-ai-table td {
    border: 1px solid var(--ace-border, #e5e7eb);
    padding: 5px 8px; text-align: left;
}
.ace-ai-table th { background: var(--ace-body-bg, #f1f5f9); font-weight: 600; }

/* Typing indicator */
.ace-ai-typing .ace-ai-bubble { display: inline-flex; gap: 4px; align-items: center; padding: 12px 14px; }
.ace-ai-dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--ace-text-muted, #94a3b8);
    animation: aceAiBlink 1.2s infinite ease-in-out;
}
.ace-ai-dot:nth-child(2) { animation-delay: .2s; }
.ace-ai-dot:nth-child(3) { animation-delay: .4s; }
@keyframes aceAiBlink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }

/* Composer */
.ace-ai-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--ace-border-soft, #f1f5f9);
    background: #fff;
}
.ace-ai-input {
    flex: 1;
    resize: none;
    border: 1px solid var(--ace-border, #e5e7eb);
    border-radius: 12px;
    padding: 9px 12px;
    font-family: inherit;
    font-size: 13.5px;
    line-height: 1.4;
    max-height: 120px;
    color: var(--ace-text, #1e293b);
    outline: none;
    transition: border-color .15s;
}
.ace-ai-input:focus { border-color: var(--ace-primary); }
.ace-ai-input:disabled { background: var(--ace-body-bg, #f8fafc); }
.ace-ai-send {
    border: none;
    cursor: pointer;
    width: 40px; height: 40px;
    flex: 0 0 40px;
    border-radius: 12px;
    color: #fff;
    background: var(--ace-primary);
    display: grid; place-items: center;
    transition: opacity .15s, transform .12s;
}
.ace-ai-send:hover:not(:disabled) { transform: translateY(-1px); }
.ace-ai-send:disabled { opacity: .5; cursor: default; }

/* Voice-to-text mic button */
.ace-ai-mic {
    border: 1px solid var(--ace-border, #e5e7eb);
    cursor: pointer;
    width: 40px; height: 40px;
    flex: 0 0 40px;
    border-radius: 12px;
    color: var(--ace-text-muted, #64748b);
    background: #fff;
    display: grid; place-items: center;
    transition: background .15s, color .15s, transform .12s, box-shadow .15s;
}
.ace-ai-mic:hover:not(:disabled) { color: var(--ace-primary); border-color: var(--ace-primary); }
.ace-ai-mic:disabled { opacity: .5; cursor: default; }
.ace-ai-mic.is-listening {
    color: #fff; background: #ef4444; border-color: #ef4444;
    animation: ace-ai-mic-pulse 1.2s ease-in-out infinite;
}
@keyframes ace-ai-mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, .5); }
    50%      { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

@media (max-width: 480px) {
    .ace-ai { right: 12px; bottom: 12px; }
    .ace-ai-panel { height: calc(100vh - 24px); }
}

/* AI assistant :: provider switcher */
.ace-ai-provider {
    appearance: none;
    -webkit-appearance: none;
    border: 1px solid rgba(255, 255, 255, .35);
    background: rgba(255, 255, 255, .16);
    color: #fff;
    font-size: 11.5px;
    font-weight: 600;
    padding: 4px 22px 4px 9px;
    border-radius: 8px;
    cursor: pointer;
    margin-right: 4px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 7px center;
    outline: none;
}
.ace-ai-provider option { color: var(--ace-text, #1e293b); }

/* AI assistant :: per-reply provider caption */
.ace-ai-caption {
    font-size: 10.5px;
    color: var(--ace-text-muted, #94a3b8);
    width: 100%;               /* own line, below the bubble */
    margin: 3px 2px 0 4px;
    font-style: italic;
}

/* =====================================================================
   GLOBAL SEARCH :: Ctrl+K / Cmd+K command palette
   ===================================================================== */
.ace-topbar__search { cursor: pointer; }
.ace-topbar__search input { cursor: pointer; }
.ace-topbar__search-kbd {
    position: absolute; right: .6rem; top: 50%; transform: translateY(-50%);
    font-size: .68rem; font-family: var(--ace-font); color: var(--ace-text-light);
    background: #fff; border: 1px solid var(--ace-border); border-radius: 5px;
    padding: 1px 6px; line-height: 1.5; pointer-events: none;
}

.ace-palette {
    position: fixed; inset: 0; z-index: 1090;
    display: flex; align-items: flex-start; justify-content: center;
    padding-top: 12vh;
}
.ace-palette[hidden] { display: none; }
.ace-palette__backdrop {
    position: absolute; inset: 0; background: rgba(15, 23, 42, .45);
}
.ace-palette__box {
    position: relative; width: 100%; max-width: 620px; margin: 0 16px;
    background: #fff; border-radius: var(--ace-radius-lg);
    box-shadow: var(--ace-shadow-lg);
    overflow: hidden; display: flex; flex-direction: column; max-height: 70vh;
}
.ace-palette__input-wrap {
    position: relative; flex-shrink: 0;
    border-bottom: 1px solid var(--ace-border-soft);
}
.ace-palette__input-wrap i {
    position: absolute; left: 1.1rem; top: 50%; transform: translateY(-50%);
    color: var(--ace-text-light); font-size: .95rem;
}
.ace-palette__input {
    width: 100%; height: 56px; border: none; outline: none;
    padding: 0 4.2rem 0 2.9rem; font-size: 1rem; color: var(--ace-text);
    background: transparent;
}
.ace-palette__esc {
    position: absolute; right: 1rem; top: 50%; transform: translateY(-50%);
    font-size: .68rem; font-family: var(--ace-font); color: var(--ace-text-light);
    background: var(--ace-body-bg); border: 1px solid var(--ace-border); border-radius: 5px;
    padding: 2px 7px; line-height: 1.5;
}
.ace-palette__results {
    overflow-y: auto; padding: 8px;
}
.ace-palette__hint, .ace-palette__empty {
    padding: 28px 16px; text-align: center; color: var(--ace-text-light); font-size: .85rem;
}
.ace-palette__group-label {
    font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
    color: var(--ace-text-light); padding: 10px 10px 4px;
}
.ace-palette__item {
    display: flex; align-items: center; gap: 12px;
    padding: 9px 10px; border-radius: var(--ace-radius-sm);
    cursor: pointer; text-decoration: none; color: var(--ace-text);
}
.ace-palette__item:hover, .ace-palette__item.is-active {
    background: var(--ace-primary-soft); color: var(--ace-text);
}
.ace-palette__item-icon {
    width: 32px; height: 32px; flex-shrink: 0; border-radius: 8px;
    display: grid; place-items: center; background: var(--ace-body-bg);
    color: var(--ace-primary); font-size: .82rem;
}
.ace-palette__item-body { min-width: 0; flex: 1; }
.ace-palette__item-title {
    font-size: .86rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ace-palette__item-subtitle {
    font-size: .74rem; color: var(--ace-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
