/**
 * EnergyAI Frontend Chat Widget Stylesheet
 * Premium, accessible chat interface.
 *
 * @package EnergyAI
 */

/* ========================================================================
   CUSTOM PROPERTIES
   ======================================================================== */
.eai-widget {
    --eai-bg:        #080c14;
    --eai-surface:   #0d1420;
    --eai-border:    #1a2540;
    --eai-accent:    #00e5ff;
    --eai-accent2:   #7b2fff;
    --eai-text:      #c8d8f0;
    --eai-muted:     #4a6080;
    --eai-user-bg:   linear-gradient(135deg, #7b2fff, #00e5ff);
    --eai-bot-bg:    #111825;
    --eai-radius:    12px;
    --eai-radius-sm: 6px;
    --eai-shadow:    0 24px 80px rgba(0,0,0,0.6), 0 0 0 1px rgba(0,229,255,0.1);
    --eai-font:      -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --eai-font-mono: 'SFMono-Regular', Consolas, monospace;
}

/* Light theme override */
.eai-widget--light {
    --eai-bg:      #f4f6fb;
    --eai-surface: #ffffff;
    --eai-border:  #e0e6f0;
    --eai-text:    #1a2540;
    --eai-muted:   #7080a0;
    --eai-bot-bg:  #eef2f8;
    --eai-shadow:  0 24px 80px rgba(0,0,0,0.15), 0 0 0 1px rgba(0,229,255,0.15);
}

/* ========================================================================
   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 {
    box-sizing: border-box;
}

/* 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: linear-gradient(135deg, var(--eai-accent2), var(--eai-accent));
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    box-shadow: 0 4px 20px rgba(123,47,255,0.5), 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.08);
    box-shadow: 0 8px 30px rgba(123,47,255,0.6), 0 0 0 4px rgba(0,229,255,0.15);
}

.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);
}

/* When panel is open */
.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);
}

/* ========================================================================
   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);
    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;
    transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275),
                opacity 0.2s ease;
}

/* Position adjustments for left-side widgets */
.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;
}

/* Open state */
.eai-widget[data-closed="false"] .eai-panel {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: all;
}

/* ---- Panel Header ---- */
.eai-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    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;
}

.eai-panel__title {
    font-size: 14px;
    font-weight: 700;
    color: var(--eai-text);
}

.eai-panel__actions {
    display: flex;
    gap: 4px;
}

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

.eai-panel__action-btn:hover {
    background: rgba(255,255,255,0.06);
    color: var(--eai-text);
}

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

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

/* ---- Message Bubbles ---- */
.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: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--eai-surface);
    border: 1px solid var(--eai-border);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    align-self: flex-end;
}

.eai-msg--user .eai-msg__avatar {
    background: linear-gradient(135deg, var(--eai-accent2), var(--eai-accent));
    border: none;
}

.eai-msg--user .eai-msg__avatar svg { display: none; }
.eai-msg--user .eai-msg__avatar::after {
    content: '👤';
    font-size: 12px;
}

.eai-msg__content {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: var(--eai-radius);
    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: var(--eai-radius) var(--eai-radius) var(--eai-radius) 4px;
    color: var(--eai-text);
}

.eai-msg--user .eai-msg__content {
    background: linear-gradient(135deg, var(--eai-accent2), #5050ff);
    color: #ffffff;
    border-radius: var(--eai-radius) var(--eai-radius) 4px var(--eai-radius);
}

.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: 600; }
.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;
}

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

/* Error state */
.eai-msg--error .eai-msg__content {
    background: rgba(255,71,87,0.1);
    border-color: rgba(255,71,87,0.3);
    color: #ff8090;
}

/* ---- 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; }
}

/* ---- Input Area ---- */
.eai-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 12px 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);
    color: var(--eai-text);
    padding: 9px 12px;
    border-radius: 8px;
    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: 8px;
    background: linear-gradient(135deg, var(--eai-accent2), var(--eai-accent));
    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: 6px 0 8px;
    margin: 0;
    border-top: 1px solid var(--eai-border);
    background: var(--eai-surface);
    letter-spacing: 0.5px;
}

/* ========================================================================
   RESPONSIVE
   ======================================================================== */
/* =========================================================================
   MOBILE — Full-screen bottom-sheet on phones (≤ 600px)
   The launcher stays fixed bottom-right. The panel takes the full screen
   so nothing is clipped or half-visible.
   ========================================================================= */
@media ( max-width: 600px ) {

    /* Always anchor widget to bottom-right on mobile regardless of setting */
    .eai-widget {
        bottom: 16px  !important;
        right:  16px  !important;
        left:   auto  !important;
        top:    auto  !important;
    }

    /* Panel becomes a full-viewport bottom sheet */
    .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;
    }

    /* Open state — slide up from bottom */
    .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,
    .eai-panel {
        transform: translateY(100%) !important;
        opacity: 0;
        pointer-events: none;
    }
    /* Override the scale animation — use slide only on mobile */
    .eai-panel {
        transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1),
                    opacity 0.2s ease !important;
    }

    /* Hide resize handle on mobile — not needed */
    #eai-resize-handle { display: none !important; }

    /* Messages area fills available space */
    .eai-messages {
        flex: 1;
        min-height: 0;
    }

    /* Larger tap targets for input area */
    .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;
    }

    /* Token bar text slightly smaller to fit */
    .eai-token-val  { font-size: 10px !important; }
    .eai-token-sub  { display: none; }

    /* Mode buttons — compact */
    .eai-mode-btn { padding: 4px 8px !important; font-size: 11px !important; }

    /* Humanifier selectors stack vertically */
    .eai-human-row { flex-direction: column; }
    .eai-human-field { min-width: 0; }
}

/* ========================================================================
   WIDGET VISIBILITY GUARANTEE (v1.1 fix)
   Ensures the launcher button is always visible regardless of theme.
   ======================================================================== */

/* Force launcher always visible — overrides any theme interference */
#eai-widget {
    position: fixed !important;
    z-index: 2147483647 !important; /* Maximum z-index */
}

#eai-launcher {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: all !important;
}

/* Panel slides up from launcher */
#eai-panel {
    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[data-closed="false"] #eai-panel {
    visibility: visible;
    transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275),
                opacity 0.2s ease,
                visibility 0s linear 0s;
}

/* Unread indicator pulse 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: #00ff88;
    border: 2px solid var(--eai-bg, #080c14);
    animation: eai-pulse-dot 2s infinite;
}

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

/* =========================================================================
   EnergyAI — Tabs, Token Bar, History Pane, Image Pane additions
   ========================================================================= */

/* Token bar in header */
.eai-panel__header {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.eai-panel__title-wrap { flex: 1; }
.eai-token-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(255,255,255,.06);
    border: 1px solid rgba(203,166,247,.2);
    border-radius: 20px;
    padding: 3px 9px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.eai-token-val { color: var(--eai-tc, #cba6f7); }

/* Tabs */
.eai-tabs {
    display: flex;
    border-bottom: 1px solid rgba(255,255,255,.08);
    background: rgba(0,0,0,.15);
}
.eai-tab {
    flex: 1;
    background: none;
    border: none;
    color: rgba(255,255,255,.5);
    font-size: 12px;
    font-weight: 600;
    padding: 9px 4px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color .2s, border-color .2s;
}
.eai-tab:hover  { color: rgba(255,255,255,.8); }
.eai-tab--active {
    color: #cba6f7;
    border-bottom-color: #cba6f7;
}

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

/* Image pane */
.eai-image-intro {
    padding: 16px 16px 8px;
    font-size: 13px;
    opacity: .7;
    text-align: center;
}
.eai-send-btn--image { background: linear-gradient(135deg, #7b2fff, #f38ba8); }

/* Typing — image variant */
.eai-typing--image {
    display: flex;
    align-items: center;
    padding: 10px 16px;
}

/* 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: .6; text-align: center; padding: 20px; }

.eai-history__item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,.05);
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 8px;
    padding: 10px 12px;
    transition: background .2s;
}
.eai-history__item:hover { background: rgba(255,255,255,.09); }
.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: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 6px;
    color: inherit;
    font-size: 11px;
    padding: 4px 8px;
    cursor: pointer;
    transition: background .15s;
    white-space: nowrap;
}
.eai-history__resume:hover { background: rgba(166,227,161,.2); color: #a6e3a1; }
.eai-history__delete:hover  { background: rgba(243,139,168,.2); color: #f38ba8; }

/* Footer — multiple footers: hide the image one if redundant */
.eai-panel__footer--main {
    text-align: center;
    font-size: 10px;
    opacity: .4;
    padding: 6px 0;
    margin: 0;
}

/* =========================================================================
   Resize handle & size controls
   ========================================================================= */

/* Drag-to-resize handle — top-left corner of panel */
.eai-resize-handle {
    position: absolute;
    top: 0;
    left: 0;
    width: 18px;
    height: 18px;
    cursor: nw-resize;
    z-index: 10;
    border-radius: 8px 0 0 0;
}
.eai-resize-handle::before {
    content: '';
    position: absolute;
    top: 4px;
    left: 4px;
    width: 8px;
    height: 8px;
    border-top: 2px solid rgba(255,255,255,.25);
    border-left: 2px solid rgba(255,255,255,.25);
    border-radius: 2px 0 0 0;
    transition: border-color .2s;
}
.eai-resize-handle:hover::before { border-color: rgba(203,166,247,.7); }
.eai-panel--resizing { user-select: none; }

/* Size preset buttons */
.eai-size-controls {
    display: flex;
    gap: 4px;
    margin-left: auto;
    align-items: center;
}
.eai-size-btn {
    background: rgba(255,255,255,.07);
    border: 1px solid rgba(255,255,255,.1);
    color: rgba(255,255,255,.55);
    border-radius: 5px;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    cursor: pointer;
    line-height: 1.4;
    transition: background .15s, color .15s;
    white-space: nowrap;
}
.eai-size-btn:hover,
.eai-size-btn--active {
    background: rgba(203,166,247,.18);
    color: #cba6f7;
    border-color: rgba(203,166,247,.35);
}

/* Panel is expanding — smooth transition only when NOT dragging */
.eai-panel--animated {
    transition: width .25s ease, height .25s ease;
}

/* =========================================================================
   Mode Bar — Normal / Advanced toggle
   ========================================================================= */

.eai-mode-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px 6px;
    background: rgba(0,0,0,.15);
    border-bottom: 1px solid rgba(255,255,255,.06);
    flex-shrink: 0;
}
.eai-mode-bar__label {
    font-size: 11px;
    opacity: .5;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-right: 2px;
}
.eai-mode-btn {
    background: rgba(255,255,255,.07);
    border: 1px solid rgba(255,255,255,.1);
    border-radius: 20px;
    color: rgba(255,255,255,.55);
    font-size: 12px;
    font-weight: 600;
    padding: 4px 11px;
    cursor: pointer;
    transition: all .18s;
    white-space: nowrap;
}
.eai-mode-btn:hover { background: rgba(255,255,255,.12); color: rgba(255,255,255,.85); }
.eai-mode-btn--active {
    background: rgba(203,166,247,.18);
    border-color: rgba(203,166,247,.45);
    color: #cba6f7;
}
.eai-mode-cost {
    margin-left: auto;
    font-size: 10px;
    opacity: .45;
    font-weight: 600;
    white-space: nowrap;
}

/* =========================================================================
   Humanifier Bar
   ========================================================================= */

.eai-human-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: rgba(0,0,0,.1);
    border-bottom: 1px solid rgba(255,255,255,.05);
    flex-shrink: 0;
}
.eai-human-bar__toggle-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}
.eai-human-toggle-cb { display: none; }

/* Custom toggle switch */
.eai-human-toggle-track {
    position: relative;
    display: inline-block;
    width: 34px;
    height: 18px;
    background: rgba(255,255,255,.12);
    border-radius: 9px;
    border: 1px solid rgba(255,255,255,.15);
    transition: background .2s, border-color .2s;
    flex-shrink: 0;
}
.eai-human-toggle-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    background: rgba(255,255,255,.45);
    border-radius: 50%;
    transition: transform .2s, background .2s;
}
.eai-human-toggle-cb:checked + .eai-human-toggle-track {
    background: rgba(203,166,247,.35);
    border-color: rgba(203,166,247,.6);
}
.eai-human-toggle-cb:checked + .eai-human-toggle-track .eai-human-toggle-knob {
    transform: translateX(16px);
    background: #cba6f7;
}
.eai-human-bar__label {
    font-size: 12px;
    font-weight: 600;
    color: rgba(255,255,255,.7);
    transition: color .2s;
}
.eai-human-toggle-cb:checked ~ .eai-human-bar__label { color: #cba6f7; }

/* =========================================================================
   Humanifier Settings Panel
   ========================================================================= */

.eai-human-panel {
    background: rgba(203,166,247,.06);
    border-bottom: 1px solid rgba(203,166,247,.15);
    padding: 10px 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: 3px;
    flex: 1;
    min-width: 80px;
}
.eai-human-field > span {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    opacity: .55;
}
.eai-human-select {
    background: rgba(255,255,255,.07);
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 6px;
    color: rgba(255,255,255,.85);
    font-size: 12px;
    padding: 5px 7px;
    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='rgba(255,255,255,.3)'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 7px center;
    padding-right: 22px;
}
.eai-human-select:focus { border-color: rgba(203,166,247,.5); }
.eai-human-select option { background: #1e1e2e; color: #cdd6f4; }

/* =========================================================================
   Response mode/humanifier badge
   ========================================================================= */

.eai-msg-badge {
    display: inline-block;
    margin-top: 6px;
    font-size: 10px;
    font-weight: 600;
    color: rgba(203,166,247,.6);
    background: rgba(203,166,247,.08);
    border: 1px solid rgba(203,166,247,.15);
    border-radius: 20px;
    padding: 2px 8px;
    letter-spacing: .03em;
}

/* =========================================================================
   Two-pool token bar
   ========================================================================= */

.eai-token-bar {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 4px 8px;
    background: rgba(0,0,0,.18);
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,.07);
    min-width: 100px;
    flex-shrink: 0;
}

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

.eai-token-val {
    font-size: 11px;
    font-weight: 700;
    color: var(--eai-tc, #cba6f7);
    white-space: nowrap;
}

.eai-token-sub {
    font-size: 9px;
    opacity: .55;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
    line-height: 1.2;
    color: #cdd6f4;
}

/* Daily pool progress bar */
.eai-daily-bar {
    height: 3px;
    background: rgba(255,255,255,.1);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 1px;
}

.eai-daily-bar__fill {
    height: 100%;
    border-radius: 2px;
    transition: width .4s ease, background .4s ease;
    background: #cba6f7;
}

/* =========================================================================
   Mobile-only / Desktop-only visibility helpers
   ========================================================================= */
.eai-mobile-close {
    display: none; /* shown only on mobile via media query */
}

@media ( max-width: 600px ) {
    /* Show the dedicated close ✕ button */
    .eai-mobile-close {
        display: flex !important;
        width:  40px !important;
        height: 40px !important;
        flex-shrink: 0;
        color: rgba(255,255,255,.7);
    }
    .eai-mobile-close:hover {
        color: #f38ba8;
        background: rgba(243,139,168,.12) !important;
    }

    /* Hide desktop-only size preset buttons */
    .eai-desktop-only,
    .eai-size-controls {
        display: none !important;
    }

    /* Safe-area padding (iPhone X+ notch / home bar) */
    .eai-panel {
        padding-bottom: env(safe-area-inset-bottom, 0) !important;
    }
    .eai-input-area {
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0)) !important;
    }

    /* Tabs slightly bigger tap targets on mobile */
    .eai-tab {
        padding: 10px 12px !important;
        font-size: 13px !important;
    }

    /* Larger message bubbles */
    .eai-msg__content {
        font-size: 14px !important;
    }

    /* Humanifier panel full-width */
    .eai-human-panel {
        padding: 10px 12px;
    }

    /* Mode bar slightly bigger text */
    .eai-mode-bar {
        padding: 8px 12px;
    }
}

/* =========================================================================
   PAGE MODE — inline embedded chat panel (shortcode [energyai_chat])
   ========================================================================= */

/* =========================================================================
   PAGE MODE — inline embedded chat via [energyai_chat] shortcode
   ========================================================================= */

.eai-page-chat {
    /* Must be flex column so children (panel) can stretch to 100% height */
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    border-radius: var(--eai-radius, 16px);
    box-shadow: var(--eai-shadow, 0 20px 60px rgba(0,0,0,.5));
    font-family: var(--eai-font, system-ui, -apple-system, sans-serif);
    font-size: 14px;
    line-height: 1.5;
    /* Inherit theme variables from .eai-widget (set below) */
    color: var(--eai-text, #cdd6f4);
    background: var(--eai-bg, #1e1e2e);
    border: 1px solid var(--eai-border, rgba(203,166,247,.15));
    /* Size set by shortcode attrs via inline style — these are fallbacks */
    width: 100%;
    height: 600px;
    min-height: 400px;
    min-width: 280px;
    box-sizing: border-box;
}

/* Theme: dark (default) */
.eai-page-chat.eai-theme--dark,
.eai-page-chat {
    --eai-bg:       #1e1e2e;
    --eai-surface:  #181825;
    --eai-text:     #cdd6f4;
    --eai-border:   rgba(203,166,247,.15);
    --eai-accent:   #cba6f7;
    --eai-radius:   16px;
    --eai-shadow:   0 20px 60px rgba(0,0,0,.5);
}

/* Theme: light */
.eai-page-chat.eai-theme--light {
    --eai-bg:      #ffffff;
    --eai-surface: #f5f5f7;
    --eai-text:    #1a1a2e;
    --eai-border:  rgba(0,0,0,.12);
    --eai-accent:  #7b2fff;
}

/* The panel inside page mode fills the wrapper completely */
.eai-page-chat .eai-panel--page {
    position: relative !important;
    transform: none    !important;
    opacity: 1         !important;
    pointer-events: all !important;
    flex: 1            !important;  /* stretch to fill parent height */
    width: 100%        !important;
    height: 100%       !important;
    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;
}

/* Mobile: page mode fills full width, height stays as set */
@media ( max-width: 600px ) {
    .eai-page-chat {
        border-radius: 0 !important;
        min-height: 100svh;
        height: 100svh !important;
    }
}
