/**
 * EnergyAI Frontend Chat Widget Stylesheet
 * Premium, accessible chat interface.
 *
 * Design system: one signature gradient (violet -> cyan) used consistently
 * across launcher, active states, badges and the token gauge. A single
 * "control strip" groups the mode switch + humanifier settings so the
 * header doesn't fragment into mismatched toolbars.
 *
 * @package EnergyAI
 */

/* ========================================================================
   DESIGN TOKENS
   ======================================================================== */
.eai-widget,
.eai-page-chat {
    --eai-bg:        #0a0e17;
    --eai-surface:   #111726;
    --eai-surface-2: #1a2235;
    --eai-border:    rgba(255,255,255,0.08);
    --eai-border-2:  rgba(255,255,255,0.13);

    --eai-accent:    #00e5ff;
    --eai-accent-2:  #7b2fff;
    --eai-gradient:  linear-gradient(135deg, var(--eai-accent-2), var(--eai-accent));

    --eai-good:      #00e5ff;
    --eai-warn:      #fbbf24;
    --eai-bad:       #fb7185;

    --eai-text:      #e7ecf8;
    --eai-muted:     #7e8aac;

    --eai-user-bg:   linear-gradient(135deg, var(--eai-accent-2), #5b4cff);
    --eai-bot-bg:    var(--eai-surface-2);

    --eai-radius:    16px;
    --eai-radius-sm: 9px;
    --eai-radius-pill: 999px;

    --eai-shadow:    0 24px 70px rgba(0,0,0,0.55), 0 0 0 1px rgba(255,255,255,0.04);
    --eai-font:      -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --eai-font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
}

/* Light theme override (covers both the floating widget and page-mode embed) */
.eai-widget--light,
.eai-page-chat.eai-theme--light {
    --eai-bg:        #f6f8fc;
    --eai-surface:   #ffffff;
    --eai-surface-2: #eef1f8;
    --eai-border:    rgba(15,23,55,0.09);
    --eai-border-2:  rgba(15,23,55,0.14);

    --eai-accent:    #0891b2;
    --eai-accent-2:  #6d28d9;
    --eai-gradient:  linear-gradient(135deg, var(--eai-accent-2), var(--eai-accent));

    --eai-good:      #0891b2;
    --eai-warn:      #b45309;
    --eai-bad:       #e11d48;

    --eai-text:      #161b2c;
    --eai-muted:     #6b7390;

    --eai-user-bg:   linear-gradient(135deg, var(--eai-accent-2), #6d28d9);
    --eai-bot-bg:    var(--eai-surface-2);

    --eai-shadow:    0 24px 70px rgba(20,30,60,0.16), 0 0 0 1px rgba(20,30,60,0.04);
}

/* ========================================================================
   WIDGET CONTAINER
   ======================================================================== */
.eai-widget {
    position: fixed;
    z-index: 99999;
    font-family: var(--eai-font);
    font-size: 14px;
    line-height: 1.5;
    box-sizing: border-box;
}

.eai-widget *,
.eai-widget *::before,
.eai-widget *::after,
.eai-page-chat *,
.eai-page-chat *::before,
.eai-page-chat *::after {
    box-sizing: border-box;
}

/* Visible keyboard focus everywhere inside the widget */
.eai-widget button:focus-visible,
.eai-widget textarea:focus-visible,
.eai-widget select:focus-visible,
.eai-page-chat button:focus-visible,
.eai-page-chat textarea:focus-visible,
.eai-page-chat select:focus-visible {
    outline: 2px solid var(--eai-accent);
    outline-offset: 2px;
}

/* Position variants */
.eai-widget--bottom-right { bottom: 24px; right: 24px; }
.eai-widget--bottom-left  { bottom: 24px; left: 24px; }
.eai-widget--top-right    { top: 80px; right: 24px; }
.eai-widget--top-left     { top: 80px; left: 24px; }

/* ========================================================================
   LAUNCHER BUTTON
   ======================================================================== */
.eai-launcher {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--eai-gradient);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    box-shadow: 0 6px 22px rgba(123,47,255,0.45), 0 0 0 0 rgba(0,229,255,0.4);
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    z-index: 2;
    animation: eai-launcher-in 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes eai-launcher-in {
    from { transform: scale(0); opacity: 0; }
    to   { transform: scale(1); opacity: 1; }
}

.eai-launcher:hover {
    transform: scale(1.07);
    box-shadow: 0 10px 30px rgba(123,47,255,0.55), 0 0 0 4px rgba(0,229,255,0.14);
}

.eai-launcher:active { transform: scale(0.95); }

.eai-launcher__icon {
    position: absolute;
    transition: opacity 0.2s, transform 0.2s;
}

.eai-launcher__icon--close {
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

.eai-widget[data-closed="false"] .eai-launcher__icon--open {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}

.eai-widget[data-closed="false"] .eai-launcher__icon--close {
    opacity: 1;
    transform: rotate(0) scale(1);
}

/* Unread pulse dot on launcher when closed */
#eai-widget[data-closed="true"] #eai-launcher::after {
    content: '';
    position: absolute;
    top: 2px;
    right: 2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #00e58a;
    border: 2px solid var(--eai-bg, #0a0e17);
    animation: eai-pulse-dot 2.4s infinite;
}

@keyframes eai-pulse-dot {
    0%, 100% { transform: scale(1); opacity: 1; }
    50%       { transform: scale(1.3); opacity: 0.7; }
}

/* ========================================================================
   CHAT PANEL
   ======================================================================== */
.eai-panel {
    position: absolute;
    bottom: 72px;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 120px);
    min-width: 280px;
    min-height: 360px;
    background: var(--eai-bg);
    color: var(--eai-text);
    border: 1px solid var(--eai-border);
    border-radius: var(--eai-radius);
    box-shadow: var(--eai-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transform: scale(0.8) translateY(20px);
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275),
                opacity 0.2s ease,
                visibility 0s linear 0.25s;
}

.eai-widget--bottom-left .eai-panel,
.eai-widget--top-left .eai-panel {
    right: auto;
    left: 0;
    transform-origin: bottom left;
}

.eai-widget--top-right .eai-panel,
.eai-widget--top-left .eai-panel {
    bottom: auto;
    top: 72px;
}

.eai-widget[data-closed="false"] .eai-panel,
#eai-page-wrap .eai-panel {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: all;
    visibility: visible;
    transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275),
                opacity 0.2s ease,
                visibility 0s linear 0s;
}

/* ---- Panel Header ---- */
.eai-panel__header {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 13px 14px;
    border-bottom: 1px solid var(--eai-border);
    background: var(--eai-surface);
    flex-shrink: 0;
}

.eai-panel__title-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.eai-panel__title-wrap svg { flex-shrink: 0; }

.eai-panel__title {
    font-size: 14px;
    font-weight: 700;
    color: var(--eai-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.eai-panel__action-btn {
    width: 30px;
    height: 30px;
    border-radius: var(--eai-radius-sm);
    background: transparent;
    border: none;
    color: var(--eai-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}

.eai-panel__action-btn:hover {
    background: var(--eai-surface-2);
    color: var(--eai-text);
}

/* ========================================================================
   TOKEN GAUGE — the signature element
   ======================================================================== */
.eai-token-bar {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 5px 10px;
    background: var(--eai-surface-2);
    border: 1px solid var(--eai-border-2);
    border-radius: var(--eai-radius-pill);
    min-width: 96px;
    flex-shrink: 0;
}

.eai-token-bar__top {
    display: flex;
    align-items: center;
    gap: 5px;
}

.eai-token-val {
    font-size: 11.5px;
    font-weight: 700;
    color: var(--eai-tc, var(--eai-good));
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.eai-token-sub {
    font-size: 9.5px;
    opacity: .6;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
    line-height: 1.2;
    color: var(--eai-text);
    font-variant-numeric: tabular-nums;
}

.eai-daily-bar {
    height: 3px;
    background: rgba(255,255,255,.1);
    border-radius: 2px;
    overflow: hidden;
}

.eai-widget--light .eai-daily-bar,
.eai-page-chat.eai-theme--light .eai-daily-bar {
    background: rgba(15,23,55,.1);
}

.eai-daily-bar__fill {
    height: 100%;
    border-radius: 2px;
    transition: width .4s ease, background .4s ease;
    background: var(--eai-good);
}

/* ---- Size preset controls ---- */
.eai-size-controls {
    display: flex;
    gap: 3px;
    align-items: center;
    flex-shrink: 0;
}

.eai-size-btn {
    background: transparent;
    border: 1px solid var(--eai-border-2);
    color: var(--eai-muted);
    border-radius: 6px;
    font-size: 10px;
    font-weight: 700;
    padding: 3px 7px;
    cursor: pointer;
    line-height: 1.4;
    transition: background .15s, color .15s, border-color .15s;
    white-space: nowrap;
}

.eai-size-btn:hover {
    color: var(--eai-text);
    border-color: var(--eai-border-2);
}

.eai-size-btn--active {
    background: rgba(0,229,255,.12);
    color: var(--eai-accent);
    border-color: rgba(0,229,255,.4);
}

.eai-widget--light .eai-size-btn--active,
.eai-page-chat.eai-theme--light .eai-size-btn--active {
    background: rgba(8,145,178,.1);
}

.eai-panel--animated { transition: width .25s ease, height .25s ease; }

/* ---- Fullscreen toggle ---- */
.eai-fullscreen-icon--collapse { display: none; }
#eai-fullscreen-btn[aria-pressed="true"] .eai-fullscreen-icon--expand   { display: none; }
#eai-fullscreen-btn[aria-pressed="true"] .eai-fullscreen-icon--collapse { display: block; }

.eai-panel--fs-transition {
    transition: top .25s ease, left .25s ease, right .25s ease, bottom .25s ease,
                width .25s ease, height .25s ease, max-width .25s ease, max-height .25s ease,
                border-radius .25s ease !important;
}

.eai-panel--fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    max-height: none !important;
    min-width: 0 !important;
    min-height: 0 !important;
    border-radius: 0 !important;
    transform: none !important;
    z-index: 2147483646 !important;
}

.eai-panel--fullscreen #eai-resize-handle,
.eai-panel--fullscreen .eai-size-controls { display: none !important; }

/* ---- Resize handle ---- */
.eai-resize-handle {
    position: absolute;
    top: 0;
    left: 0;
    width: 18px;
    height: 18px;
    cursor: nw-resize;
    z-index: 10;
    border-radius: var(--eai-radius) 0 0 0;
}
.eai-resize-handle::before {
    content: '';
    position: absolute;
    top: 5px;
    left: 5px;
    width: 7px;
    height: 7px;
    border-top: 2px solid var(--eai-border-2);
    border-left: 2px solid var(--eai-border-2);
    border-radius: 2px 0 0 0;
    transition: border-color .2s;
}
.eai-resize-handle:hover::before { border-color: var(--eai-accent); }
.eai-panel--resizing { user-select: none; }

/* ========================================================================
   CONTROL STRIP — Mode switch + Humanifier (one cohesive zone)
   ======================================================================== */
.eai-mode-bar,
.eai-human-bar {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 8px 14px;
    background: var(--eai-surface);
    border-bottom: 1px solid var(--eai-border);
    flex-shrink: 0;
}

.eai-mode-bar[hidden],
.eai-human-bar[hidden],
.eai-human-panel[hidden] {
    display: none;
}

.eai-mode-bar__label {
    font-size: 10.5px;
    opacity: .55;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-right: 1px;
    flex-shrink: 0;
}

.eai-mode-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--eai-surface-2);
    border: 1px solid var(--eai-border-2);
    border-radius: var(--eai-radius-pill);
    color: var(--eai-muted);
    font-size: 12px;
    font-weight: 600;
    padding: 5px 12px;
    cursor: pointer;
    transition: background .18s, border-color .18s, color .18s;
    white-space: nowrap;
}
.eai-mode-btn svg { flex-shrink: 0; opacity: .8; }
.eai-mode-btn:hover { color: var(--eai-text); border-color: var(--eai-border-2); }
.eai-mode-btn--active {
    background: rgba(0,229,255,.12);
    border-color: rgba(0,229,255,.45);
    color: var(--eai-good);
}
.eai-widget--light .eai-mode-btn--active,
.eai-page-chat.eai-theme--light .eai-mode-btn--active {
    background: rgba(8,145,178,.1);
}
.eai-mode-btn--active svg { opacity: 1; }

.eai-mode-cost {
    margin-left: auto;
    font-size: 10.5px;
    opacity: .55;
    font-weight: 600;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* ---- Humanifier toggle row ---- */
.eai-human-bar__toggle-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}
.eai-human-toggle-cb { display: none; }

.eai-human-toggle-track {
    position: relative;
    display: inline-block;
    width: 32px;
    height: 18px;
    background: var(--eai-surface-2);
    border-radius: var(--eai-radius-pill);
    border: 1px solid var(--eai-border-2);
    transition: background .2s, border-color .2s;
    flex-shrink: 0;
}
.eai-human-toggle-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    background: var(--eai-muted);
    border-radius: 50%;
    transition: transform .2s, background .2s;
}
.eai-human-toggle-cb:checked + .eai-human-toggle-track {
    background: rgba(123,47,255,.18);
    border-color: rgba(123,47,255,.5);
}
.eai-human-toggle-cb:checked + .eai-human-toggle-track .eai-human-toggle-knob {
    transform: translateX(14px);
    background: var(--eai-accent-2);
}
.eai-human-bar__label {
    font-size: 12px;
    font-weight: 600;
    color: var(--eai-muted);
    transition: color .2s;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.eai-human-bar__label svg { opacity: .75; flex-shrink: 0; }
.eai-human-toggle-cb:checked ~ .eai-human-bar__label { color: var(--eai-accent-2); }
.eai-human-toggle-cb:checked ~ .eai-human-bar__label svg { opacity: 1; }

/* ---- Humanifier settings panel ---- */
.eai-human-panel {
    background: var(--eai-surface);
    border-bottom: 1px solid var(--eai-border);
    padding: 4px 14px 12px;
    flex-shrink: 0;
    animation: eai-fade-in .2s ease;
}
@keyframes eai-fade-in { from { opacity:0; transform:translateY(-4px); } to { opacity:1; transform:none; } }

.eai-human-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.eai-human-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 84px;
}
.eai-human-field > span {
    font-size: 9.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    opacity: .5;
}
.eai-human-select {
    background: var(--eai-surface-2);
    border: 1px solid var(--eai-border-2);
    border-radius: 7px;
    color: var(--eai-text);
    font-size: 12px;
    padding: 6px 8px;
    cursor: pointer;
    outline: none;
    transition: border-color .15s;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%237e8aac'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 24px;
}
.eai-human-select:focus { border-color: var(--eai-accent-2); }
.eai-human-select option { background: var(--eai-surface); color: var(--eai-text); }

/* =========================================================================
   TABS
   ========================================================================= */
.eai-tabs {
    display: flex;
    border-bottom: 1px solid var(--eai-border);
    background: var(--eai-surface);
    flex-shrink: 0;
}
.eai-tab {
    flex: 1;
    background: none;
    border: none;
    color: var(--eai-muted);
    font-size: 12.5px;
    font-weight: 600;
    padding: 10px 4px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color .2s, border-color .2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.eai-tab svg { flex-shrink: 0; opacity: .75; }
.eai-tab:hover  { color: var(--eai-text); }
.eai-tab--active {
    color: var(--eai-accent);
    border-bottom-color: var(--eai-accent);
}
.eai-tab--active svg { opacity: 1; }

/* Panes */
.eai-pane {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    background: var(--eai-bg);
}
.eai-pane[hidden] { display: none !important; }

/* =========================================================================
   MESSAGES
   ========================================================================= */
.eai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.eai-messages::-webkit-scrollbar { width: 4px; }
.eai-messages::-webkit-scrollbar-track { background: transparent; }
.eai-messages::-webkit-scrollbar-thumb { background: var(--eai-border-2); border-radius: 2px; }

.eai-msg {
    display: flex;
    gap: 10px;
    animation: eai-msg-in 0.25s ease;
}

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

.eai-msg--user { flex-direction: row-reverse; }

.eai-msg__avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--eai-surface-2);
    border: 1px solid var(--eai-border-2);
    color: var(--eai-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    align-self: flex-end;
}

.eai-msg--user .eai-msg__avatar {
    background: var(--eai-gradient);
    border: none;
    color: #fff;
}
.eai-msg--user .eai-msg__avatar svg { display: none; }
.eai-msg--user .eai-msg__avatar::after {
    content: '';
    width: 12px;
    height: 12px;
    background-color: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='8' r='4'/%3E%3Cpath d='M4 20c0-4 3.6-7 8-7s8 3 8 7'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='8' r='4'/%3E%3Cpath d='M4 20c0-4 3.6-7 8-7s8 3 8 7'/%3E%3C/svg%3E") center / contain no-repeat;
}

.eai-msg__content {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: var(--eai-radius-sm);
    font-size: 13.5px;
    line-height: 1.6;
    word-break: break-word;
}

.eai-msg--assistant .eai-msg__content {
    background: var(--eai-bot-bg);
    border: 1px solid var(--eai-border);
    border-radius: 4px 14px 14px 14px;
    color: var(--eai-text);
}

.eai-msg--user .eai-msg__content {
    background: var(--eai-user-bg);
    color: #ffffff;
    border-radius: 14px 4px 14px 14px;
}

.eai-msg__content p { margin: 0 0 8px; }
.eai-msg__content p:last-child { margin-bottom: 0; }
.eai-msg__content strong { color: inherit; font-weight: 700; }
.eai-msg__content code {
    font-family: var(--eai-font-mono);
    font-size: 12px;
    background: rgba(255,255,255,0.1);
    padding: 1px 5px;
    border-radius: 3px;
}
.eai-msg--user .eai-msg__content code { background: rgba(255,255,255,0.18); }

.eai-msg__image {
    max-width: 260px;
    border-radius: var(--eai-radius-sm);
    display: block;
    margin-top: 8px;
    border: 1px solid var(--eai-border);
}

.eai-msg--error .eai-msg__content {
    background: rgba(251,113,133,0.1);
    border-color: rgba(251,113,133,0.3);
    color: #fb7185;
}
.eai-widget--light .eai-msg--error .eai-msg__content,
.eai-page-chat.eai-theme--light .eai-msg--error .eai-msg__content {
    color: #be123c;
}

/* ---- Response mode / humanifier badge ---- */
.eai-msg-badge {
    display: inline-block;
    margin-top: 6px;
    font-size: 10px;
    font-weight: 600;
    color: var(--eai-muted);
    background: var(--eai-surface-2);
    border: 1px solid var(--eai-border-2);
    border-radius: var(--eai-radius-pill);
    padding: 2px 9px;
    letter-spacing: .02em;
}

/* ---- Typing indicator ---- */
.eai-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 16px 0;
    flex-shrink: 0;
}
.eai-typing[hidden] { display: none; }
.eai-typing__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--eai-muted);
    animation: eai-bounce 1.2s infinite;
}
.eai-typing__dot:nth-child(2) { animation-delay: 0.2s; }
.eai-typing__dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes eai-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30%            { transform: translateY(-6px); opacity: 1; }
}
.eai-typing--image { padding: 10px 16px; }

/* =========================================================================
   IMAGE PANE
   ========================================================================= */
.eai-image-intro {
    padding: 16px 16px 8px;
    font-size: 13px;
    opacity: .65;
    text-align: center;
}
.eai-send-btn--image { background: linear-gradient(135deg, var(--eai-accent-2), #c026d3); }

/* =========================================================================
   HISTORY PANE
   ========================================================================= */
.eai-pane--history { overflow-y: auto; }
.eai-history-list  { padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.eai-history__loading,
.eai-history__empty { font-size: 13px; opacity: .55; text-align: center; padding: 20px; }

.eai-history__item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--eai-surface-2);
    border: 1px solid var(--eai-border);
    border-radius: var(--eai-radius-sm);
    padding: 10px 12px;
    transition: border-color .2s;
}
.eai-history__item:hover { border-color: var(--eai-border-2); }
.eai-history__body   { flex: 1; min-width: 0; }
.eai-history__preview {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.eai-history__meta { font-size: 11px; opacity: .55; margin-top: 2px; }
.eai-history__btns { display: flex; gap: 6px; flex-shrink: 0; }

.eai-history__resume,
.eai-history__delete {
    background: var(--eai-surface);
    border: 1px solid var(--eai-border-2);
    border-radius: 6px;
    color: inherit;
    font-size: 11px;
    padding: 4px 8px;
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
    white-space: nowrap;
}
.eai-history__resume:hover { border-color: rgba(0,229,255,.4); color: var(--eai-good); }
.eai-history__delete:hover  { border-color: rgba(251,113,133,.4); color: var(--eai-bad); }

/* =========================================================================
   PROFILE PANE
   ========================================================================= */
.eai-pane--profile   { overflow-y: auto; }
.eai-profile-content { padding: 16px; }

.eai-profile__header { display: flex; align-items: center; gap: 12px; }

.eai-profile__avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    flex-shrink: 0;
    overflow: hidden;
    background: var(--eai-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 0 1px var(--eai-border-2);
}
.eai-profile__avatar-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.eai-profile__avatar-fallback { font-size: 20px; font-weight: 700; color: #fff; }

.eai-profile__id   { min-width: 0; }
.eai-profile__name {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.eai-profile__meta { display: flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 11px; opacity: .65; }

.eai-profile__badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--eai-radius-pill);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.eai-profile__badge--member { background: rgba(0,229,255,.14); color: var(--eai-good); }
.eai-profile__badge--guest  { background: var(--eai-surface-2); color: var(--eai-muted); border: 1px solid var(--eai-border-2); }

.eai-profile__cta {
    display: block;
    margin-top: 14px;
    padding: 10px 12px;
    border-radius: var(--eai-radius-sm);
    background: var(--eai-surface-2);
    border: 1px solid var(--eai-border-2);
    color: var(--eai-accent);
    font-size: 12.5px;
    font-weight: 600;
    text-decoration: none;
    text-align: center;
    transition: border-color .15s, background .15s;
}
.eai-profile__cta:hover { border-color: var(--eai-accent); background: var(--eai-surface); }

.eai-profile__stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 16px;
}
.eai-profile__stat {
    background: var(--eai-surface-2);
    border: 1px solid var(--eai-border);
    border-radius: var(--eai-radius-sm);
    padding: 10px 8px;
    text-align: center;
}
.eai-profile__stat-val   { font-size: 15px; font-weight: 700; }
.eai-profile__stat-label { font-size: 10px; opacity: .6; margin-top: 2px; }

.eai-profile__section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    opacity: .55;
    margin: 20px 0 8px;
}

.eai-profile__convos { display: flex; flex-direction: column; gap: 6px; }

.eai-profile__convo-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    background: var(--eai-surface-2);
    border: 1px solid var(--eai-border);
    border-radius: var(--eai-radius-sm);
    padding: 9px 11px;
    font: inherit;
    color: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color .15s;
}
.eai-profile__convo-row:hover { border-color: var(--eai-border-2); }
.eai-profile__convo-preview {
    font-size: 12.5px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.eai-profile__convo-date { font-size: 10.5px; opacity: .55; flex-shrink: 0; }

.eai-profile__convo-more {
    background: none;
    border: none;
    color: var(--eai-accent);
    font-size: 12px;
    font-weight: 600;
    padding: 8px 2px;
    cursor: pointer;
    text-align: left;
}
.eai-profile__convo-more:hover { text-decoration: underline; }

/* =========================================================================
   INPUT AREA
   ========================================================================= */
.eai-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--eai-border);
    background: var(--eai-surface);
    flex-shrink: 0;
}

.eai-input-field {
    flex: 1;
    background: var(--eai-bg);
    border: 1px solid var(--eai-border-2);
    color: var(--eai-text);
    padding: 9px 12px;
    border-radius: var(--eai-radius-sm);
    font-size: 13.5px;
    font-family: var(--eai-font);
    resize: none;
    overflow: hidden;
    min-height: 38px;
    max-height: 120px;
    line-height: 1.5;
    transition: border-color 0.2s;
    outline: none;
}
.eai-input-field::placeholder { color: var(--eai-muted); }
.eai-input-field:focus { border-color: var(--eai-accent); }

.eai-send-btn {
    width: 38px;
    height: 38px;
    border-radius: var(--eai-radius-sm);
    background: var(--eai-gradient);
    border: none;
    cursor: pointer;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.2s, transform 0.1s;
}
.eai-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.eai-send-btn:not(:disabled):hover { opacity: 0.9; transform: scale(1.05); }
.eai-send-btn:active { transform: scale(0.95); }

/* =========================================================================
   FOOTER
   ========================================================================= */
.eai-panel__footer {
    text-align: center;
    font-size: 10px;
    color: var(--eai-muted);
    padding: 7px 0;
    margin: 0;
    border-top: 1px solid var(--eai-border);
    background: var(--eai-surface);
    letter-spacing: 0.4px;
    flex-shrink: 0;
}

/* =========================================================================
   MOBILE — full-screen bottom-sheet (<= 600px)
   ========================================================================= */
@media ( max-width: 600px ) {

    .eai-widget {
        bottom: 16px  !important;
        right:  16px  !important;
        left:   auto  !important;
        top:    auto  !important;
    }

    .eai-panel {
        position: fixed          !important;
        top:      0              !important;
        left:     0              !important;
        right:    0              !important;
        bottom:   0              !important;
        width:    100%           !important;
        height:   100%           !important;
        max-width:  none         !important;
        max-height: none         !important;
        min-width:  0            !important;
        min-height: 0            !important;
        border-radius: 0         !important;
        transform-origin: bottom center;
        z-index: 2147483646      !important;
        padding-bottom: env(safe-area-inset-bottom, 0) !important;
        transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1),
                    opacity 0.2s ease !important;
    }

    .eai-widget[data-closed="false"] .eai-panel {
        transform: translateY(0) !important;
        opacity: 1               !important;
        pointer-events: all      !important;
    }
    .eai-widget[data-closed="true"] .eai-panel {
        transform: translateY(100%) !important;
        opacity: 0;
        pointer-events: none;
    }

    #eai-resize-handle { display: none !important; }
    .eai-desktop-only,
    .eai-size-controls { display: none !important; }

    .eai-mobile-close {
        display: flex !important;
        width:  40px !important;
        height: 40px !important;
        flex-shrink: 0;
        color: var(--eai-muted);
    }
    .eai-mobile-close:hover {
        color: var(--eai-bad);
        background: rgba(251,113,133,.12) !important;
    }

    .eai-messages { flex: 1; min-height: 0; }

    .eai-input-field {
        font-size: 16px !important; /* prevents iOS zoom on focus */
        padding: 10px 12px !important;
    }
    .eai-send-btn { width: 44px !important; height: 44px !important; }

    .eai-input-area { padding-bottom: calc(8px + env(safe-area-inset-bottom, 0)) !important; }

    .eai-token-val  { font-size: 10px !important; }
    .eai-token-sub  { display: none; }

    .eai-mode-btn { padding: 5px 9px !important; font-size: 11px !important; }
    .eai-mode-bar { padding: 8px 12px; }

    .eai-human-row { flex-direction: column; }
    .eai-human-field { min-width: 0; }
    .eai-human-panel { padding: 4px 12px 12px; }

    .eai-tab { padding: 11px 8px !important; font-size: 13px !important; }
    .eai-msg__content { font-size: 14px !important; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .eai-launcher,
    .eai-panel,
    .eai-msg,
    .eai-typing__dot,
    #eai-widget[data-closed="true"] #eai-launcher::after {
        animation: none !important;
        transition: none !important;
    }
}

.eai-mobile-close { display: none; }

/* ========================================================================
   WIDGET VISIBILITY GUARANTEE
   Ensures the launcher button is always visible regardless of theme.
   ======================================================================== */
#eai-widget {
    position: fixed !important;
    z-index: 2147483647 !important;
}
#eai-launcher {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: all !important;
}

/* =========================================================================
   PAGE MODE — full-page app shell ([energyai_chat] shortcode)
   Sidebar (brand, new chat, history, Humanifier prefs) + main column.
   ========================================================================= */
.eai-page-chat {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    position: relative;
    overflow: hidden;
    border-radius: var(--eai-radius);
    box-shadow: var(--eai-shadow);
    font-family: var(--eai-font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--eai-text);
    background: var(--eai-bg);
    border: 1px solid var(--eai-border);
    width: 100%;
    height: 100vh;
    min-height: 480px;
    min-width: 280px;
}

/* ---- Sidebar ---- */
.eai-page-sidebar {
    width: 264px;
    flex-shrink: 0;
    background: var(--eai-surface);
    border-right: 1px solid var(--eai-border);
    display: flex;
    flex-direction: column;
    padding: 16px 12px;
    overflow-y: auto;
}

.eai-page-sidebar__brand {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 2px 6px 16px;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}
.eai-page-sidebar__title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.eai-page-newchat {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    background: var(--eai-gradient);
    color: #fff;
    border: none;
    border-radius: var(--eai-radius-sm);
    padding: 10px 12px;
    font-size: 13px;
    font-weight: 700;
    font-family: var(--eai-font);
    cursor: pointer;
    margin-bottom: 16px;
    flex-shrink: 0;
    transition: opacity .15s, transform .1s;
}
.eai-page-newchat:hover  { opacity: .9; }
.eai-page-newchat:active { transform: scale(.98); }

.eai-page-sidebar__label {
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    opacity: .45;
    padding: 2px 8px 8px;
    flex-shrink: 0;
}

.eai-history-list--sidebar {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 0;
    gap: 2px;
    min-height: 40px;
}
.eai-history-list--sidebar .eai-history__item {
    background: transparent;
    border: 1px solid transparent;
    padding: 8px;
}
.eai-history-list--sidebar .eai-history__item:hover {
    background: var(--eai-surface-2);
    border-color: var(--eai-border);
}
.eai-history-list--sidebar .eai-history__btns {
    opacity: 0;
    transition: opacity .15s;
}
.eai-history-list--sidebar .eai-history__item:hover .eai-history__btns,
.eai-history-list--sidebar .eai-history__item:focus-within .eai-history__btns {
    opacity: 1;
}

.eai-page-sidebar__spacer { flex: 0 0 10px; }

/* Humanifier as a standing sidebar preference, not a per-message toolbar */
.eai-human-bar--sidebar {
    background: transparent;
    border: none;
    border-top: 1px solid var(--eai-border);
    padding: 14px 6px 4px;
    flex-shrink: 0;
    justify-content: space-between;
}
.eai-human-panel--sidebar {
    background: transparent;
    border: none;
    padding: 0 6px 12px;
    flex-shrink: 0;
}
.eai-human-row--stacked { flex-direction: column; }
.eai-human-row--stacked .eai-human-field { min-width: 0; }

.eai-panel__footer--sidebar {
    border-top: none;
    padding-top: 8px;
    flex-shrink: 0;
}

/* ---- Mobile drawer toggle + scrim (hidden at desktop widths) ---- */
.eai-page-sidebar-toggle {
    display: none;
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 5;
    width: 34px;
    height: 34px;
    border-radius: var(--eai-radius-sm);
    background: var(--eai-surface);
    border: 1px solid var(--eai-border-2);
    color: var(--eai-text);
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.eai-page-sidebar-scrim {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 4;
    background: rgba(0,0,0,.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
}
.eai-page-sidebar-scrim--visible { opacity: 1; pointer-events: all; }

/* ---- Main column ---- */
.eai-page-chat .eai-panel--page {
    position: relative !important;
    transform: none     !important;
    opacity: 1          !important;
    visibility: visible !important;
    pointer-events: all !important;
    flex: 1 1 auto      !important;
    width: auto         !important;
    height: 100%        !important;
    min-width: 0;
    max-width: none     !important;
    max-height: none    !important;
    border: none        !important;
    border-radius: 0    !important;
    box-shadow: none    !important;
    display: flex       !important;
    flex-direction: column !important;
    overflow: hidden    !important;
}

.eai-panel__header--page {
    gap: 18px;
    padding: 13px 20px;
}

.eai-tabs--page {
    border-bottom: none;
    background: transparent;
    flex: 0 0 auto;
    width: auto;
}
.eai-tabs--page .eai-tab {
    flex: 0 0 auto;
    padding: 6px 4px;
}

.eai-mode-bar--page {
    border-bottom: 0;
    background: transparent;
    padding: 0;
    margin-left: auto;
}

.eai-messages--page {
    padding: 28px max(20px, calc(50% - 380px)) 14px;
}
.eai-messages--page .eai-msg__content { font-size: 14.5px; line-height: 1.65; }

.eai-input-area--page {
    padding: 14px max(20px, calc(50% - 380px)) 20px;
}

@media ( max-width: 880px ) {
    .eai-page-sidebar-toggle { display: flex; }
    .eai-page-sidebar-scrim  { display: block; }

    .eai-page-sidebar {
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        max-width: 82vw;
        z-index: 6;
        transform: translateX(-100%);
        transition: transform .25s cubic-bezier(0.32, 0.72, 0, 1);
        box-shadow: 10px 0 32px rgba(0,0,0,.35);
    }
    .eai-page-sidebar--open { transform: translateX(0); }

    .eai-panel__header--page { padding-left: 56px; }
}

@media ( max-width: 600px ) {
    .eai-page-chat {
        border-radius: 0 !important;
        min-height: 100svh;
        height: 100svh !important;
    }
    .eai-messages--page,
    .eai-input-area--page { padding-left: 16px !important; padding-right: 16px !important; }
    .eai-panel__header--page { flex-wrap: wrap; gap: 10px; }
    .eai-mode-bar--page { margin-left: 0; }
}
