/* ==========================================================================
   HISTORA AI — Gemini-Inspired Interface
   Dark + Light themes, all selectors scoped under .histora-ai-body
   so the active WordPress theme cannot override them.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Theme tokens
   - Dark is the default
   - Light kicks in when the user picks it OR (no preference set + system is light)
   - Brand gradient is shared by both themes
   -------------------------------------------------------------------------- */
:root {
    /* Brand — shared across both themes */
    --gradient-gemini: linear-gradient(135deg, #4285F4, #9B59B6, #EA4335, #FBBC04);
    --gradient-text:   linear-gradient(90deg, #4285F4 0%, #9C27B0 50%, #EA4335 100%);
    --accent-blue:     #4285F4;
    --accent-purple:   #9C27B0;
    --accent-red:      #EA4335;
    --accent-yellow:   #FBBC04;

    /* Typography */
    --font-sans: 'Google Sans', 'Inter', 'Roboto', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, 'SFMono-Regular', Menlo, monospace;

    /* Spacing scale (8px base) */
    --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
    --space-5: 24px; --space-6: 32px; --space-7: 48px; --space-8: 64px; --space-9: 96px;

    /* Radii */
    --radius-pill: 24px;
    --radius-card: 16px;
    --radius-input: 28px;
    --radius-bubble-user: 20px 20px 4px 20px;
    --radius-bubble-ai:   4px 20px 20px 20px;
    --radius-sm: 8px;

    /* Layout */
    --sidebar-w: 280px;
    --sidebar-w-collapsed: 72px;
    --header-h: 56px;
    --content-max-w: 768px;

    /* Motion */
    --easing: cubic-bezier(0.4, 0, 0.2, 1);
    --dur-fast: 0.15s;
    --dur-base: 0.2s;
    --dur-slow: 0.3s;
}

/* ---------- LIGHT theme tokens (default) ----------
   Both `:root` and `:root[data-hai-theme="light"]` carry the light palette so
   the theme is well-defined whether or not the boot script has run yet. Light
   is the unconditional default for first-time visitors. */
:root,
:root[data-hai-theme="light"] {
    color-scheme: light;
    --bg-primary:    #FFFFFF;
    --bg-secondary:  #F0F4F9;     /* Gemini's signature sidebar tone */
    --bg-surface:    #F8F9FA;
    --bg-input:      #F0F4F9;
    --bg-elevated:   #FFFFFF;
    --bg-hover:      rgba(0, 0, 0, 0.05);
    --bg-active:     rgba(0, 0, 0, 0.08);
    --bg-overlay:    rgba(255, 255, 255, 0.78);

    --text-primary:   #1F1F1F;
    --text-secondary: #444746;
    --text-hint:      #80868B;
    --text-on-accent: #FFFFFF;

    --border-subtle: rgba(0, 0, 0, 0.10);
    --border-strong: rgba(0, 0, 0, 0.16);
    --border-focus:  rgba(26, 115, 232, 0.45);

    --user-bubble:    #E8F0FE;
    --code-text:      #C5221F;
    --code-bg:        #F1F3F4;

    --shadow-md: 0 2px 8px rgba(60, 64, 67, 0.10), 0 1px 3px rgba(60, 64, 67, 0.06);
    --shadow-lg: 0 6px 24px rgba(60, 64, 67, 0.18);
    --shadow-glow: 0 0 0 4px rgba(66, 133, 244, 0.18);
}

/* ---------- DARK theme tokens ---------- */
:root[data-hai-theme="dark"] {
    color-scheme: dark;

    --bg-primary:    #1B1C1D;
    --bg-secondary:  #1F1F1F;
    --bg-surface:    #282A2C;
    --bg-input:      #1E1F20;
    --bg-elevated:   #353638;
    --bg-hover:      rgba(255, 255, 255, 0.06);
    --bg-active:     rgba(255, 255, 255, 0.10);
    --bg-overlay:    rgba(27, 28, 29, 0.85);

    --text-primary:   #E3E3E3;
    --text-secondary: #C4C7C5;
    --text-hint:      #9AA0A6;
    --text-on-accent: #FFFFFF;

    --border-subtle: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.18);
    --border-focus:  rgba(138, 180, 248, 0.65);

    --user-bubble:    #333537;
    --code-text:      #F8B9B0;
    --code-bg:        #2D2F31;

    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 0 4px rgba(138, 180, 248, 0.18);
}

/* Light is the default — no auto-switch based on OS preference.
   Users can still flip to dark explicitly via the toggle in the header. */

/* --------------------------------------------------------------------------
   2. Reset — scoped + aggressive so the WP theme can't override our base.
   Critical body/app styles use `!important` to defeat themes that ship their
   own !important rules on the bare body or generic block elements.
   -------------------------------------------------------------------------- */
html { height: 100%; background: #FFFFFF; }
html[data-hai-theme="dark"] { background: #1B1C1D; }

body.histora-ai-body {
    margin: 0 !important;
    padding: 0 !important;
    height: 100%;
    background: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    font-family: var(--font-sans) !important;
    font-size: 16px;
    line-height: 1.6;
    letter-spacing: -0.011em;
    font-weight: 400;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
    text-rendering: optimizeLegibility;
}

/* Scoped reset — only inside our container, so we don't trample the WP admin bar */
.histora-ai-body .hai-app *,
.histora-ai-body .hai-app *::before,
.histora-ai-body .hai-app *::after {
    box-sizing: border-box;
}

/* Aggressive button reset — many WP themes ship their own button hover/focus
   styles (gradients, dark fills, text shadows) that bleed into our chips. */
.histora-ai-body .hai-app button {
    appearance: none;
    -webkit-appearance: none;
    background: none;
    background-color: transparent;
    background-image: none;
    border: 0;
    outline: none;
    color: inherit;
    font: inherit;
    text-transform: none;
    text-shadow: none;
    text-decoration: none;
    box-shadow: none;
    cursor: pointer;
    margin: 0;
    padding: 0;
    line-height: inherit;
}
.histora-ai-body .hai-app button:hover,
.histora-ai-body .hai-app button:focus,
.histora-ai-body .hai-app button:active {
    background-image: none;
    text-shadow: none;
    color: inherit;
}

.histora-ai-body .hai-app input,
.histora-ai-body .hai-app textarea,
.histora-ai-body .hai-app select {
    font-family: inherit;
    color: inherit;
    background: none;
    border: none;
    outline: none;
    margin: 0;
    padding: 0;
    box-shadow: none;
}

.histora-ai-body .hai-app a {
    color: var(--accent-blue);
    text-decoration: none;
    background: none;
    text-shadow: none;
}
.histora-ai-body .hai-app a:hover { text-decoration: underline; }

.histora-ai-body .hai-app h1,
.histora-ai-body .hai-app h2,
.histora-ai-body .hai-app h3,
.histora-ai-body .hai-app h4,
.histora-ai-body .hai-app h5,
.histora-ai-body .hai-app h6,
.histora-ai-body .hai-app p {
    margin: 0;
    padding: 0;
    color: inherit;
    background: none;
    text-shadow: none;
    text-decoration: none;
    font-weight: 400;
    -webkit-text-fill-color: currentColor;
}

.histora-ai-body .hai-app ul,
.histora-ai-body .hai-app ol {
    margin: 0;
    padding: 0;
    list-style: none;
}

.histora-ai-body ::selection { background: rgba(66, 133, 244, 0.35); color: #fff; }

/* WordPress admin bar offset (only when logged in) */
body.admin-bar.histora-ai-body .hai-app { height: calc(100vh - 32px); }
@media (max-width: 782px) {
    body.admin-bar.histora-ai-body .hai-app { height: calc(100vh - 46px); }
}

/* Scrollbars */
.histora-ai-body .hai-scroll::-webkit-scrollbar { width: 8px; height: 8px; }
.histora-ai-body .hai-scroll::-webkit-scrollbar-track { background: transparent; }
.histora-ai-body .hai-scroll::-webkit-scrollbar-thumb { background: var(--border-subtle); border-radius: 4px; }
.histora-ai-body .hai-scroll::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* --------------------------------------------------------------------------
   3. App shell
   -------------------------------------------------------------------------- */
.histora-ai-body .hai-app {
    display: flex;
    width: 100vw;
    height: 100vh;
    background: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    overflow: hidden;
    animation: hai-app-in 0.4s var(--easing) both;
    isolation: isolate; /* contain mix-blend & stacking from the WP theme */
}

@keyframes hai-app-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* --------------------------------------------------------------------------
   4. Sidebar
   -------------------------------------------------------------------------- */
.histora-ai-body .hai-sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--bg-secondary) !important;
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    transition: width var(--dur-slow) var(--easing),
                transform var(--dur-slow) var(--easing);
    position: relative;
    z-index: 30;
    color: var(--text-primary) !important;
    font-family: var(--font-sans) !important;
}

.histora-ai-body .hai-sidebar.is-collapsed {
    width: var(--sidebar-w-collapsed);
}

.histora-ai-body .hai-sidebar.is-collapsed .hai-sidebar__brand-text,
.histora-ai-body .hai-sidebar.is-collapsed .hai-sidebar__section-label,
.histora-ai-body .hai-sidebar.is-collapsed .hai-new-chat__label,
.histora-ai-body .hai-sidebar.is-collapsed .hai-chat-item,
.histora-ai-body .hai-sidebar.is-collapsed .hai-chat-list__empty,
.histora-ai-body .hai-sidebar.is-collapsed .hai-sidebar__footer-text {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

.histora-ai-body .hai-sidebar.is-collapsed .hai-new-chat {
    width: 44px;
    padding: 0;
    justify-content: center;
}

.histora-ai-body .hai-sidebar__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-3) 0 var(--space-4);
    height: var(--header-h);
    flex-shrink: 0;
}

.histora-ai-body .hai-sidebar__brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    overflow: hidden;
    min-width: 0;
}

.histora-ai-body .hai-sidebar__brand-icon {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.histora-ai-body .hai-sidebar__brand-text {
    font-family: var(--font-sans) !important;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.02em;
    background: var(--gradient-text);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    white-space: nowrap;
    transition: opacity var(--dur-fast) var(--easing);
}

.histora-ai-body .hai-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: background var(--dur-fast) var(--easing),
                color var(--dur-fast) var(--easing),
                transform var(--dur-fast) var(--easing);
    flex-shrink: 0;
}
.histora-ai-body .hai-icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.histora-ai-body .hai-icon-btn:active { transform: scale(0.95); }
.histora-ai-body .hai-icon-btn:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.histora-ai-body .hai-icon-btn svg { width: 20px; height: 20px; display: block; }

/* New Chat pill */
.histora-ai-body .hai-sidebar__new-chat-wrap {
    padding: var(--space-3) var(--space-4) var(--space-5);
}

.histora-ai-body .hai-new-chat {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 10px 18px 10px 14px;
    border-radius: var(--radius-pill);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    font-family: var(--font-sans) !important;
    font-size: 14px;
    font-weight: 500;
    transition: background var(--dur-base) var(--easing),
                border-color var(--dur-base) var(--easing),
                box-shadow var(--dur-base) var(--easing),
                transform var(--dur-fast) var(--easing);
}
.histora-ai-body .hai-new-chat:hover {
    background: var(--bg-active);
    border-color: var(--border-strong);
    box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.10);
}
.histora-ai-body .hai-new-chat:active { transform: scale(0.97); }
.histora-ai-body .hai-new-chat svg { width: 18px; height: 18px; }

/* History list */
.histora-ai-body .hai-sidebar__history {
    flex: 1;
    overflow-y: auto;
    padding: 0 var(--space-3);
    min-height: 0;
}

.histora-ai-body .hai-sidebar__section-label {
    font-family: var(--font-sans) !important;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    padding: var(--space-2) var(--space-3);
    margin: var(--space-3) 0 var(--space-1);
    transition: opacity var(--dur-fast) var(--easing);
}

.histora-ai-body .hai-chat-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.histora-ai-body .hai-chat-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 10px var(--space-3);
    border-radius: 10px;
    cursor: pointer;
    color: var(--text-primary);
    font-family: var(--font-sans) !important;
    font-size: 14px;
    line-height: 1.3;
    position: relative;
    transition: background var(--dur-fast) var(--easing);
}
.histora-ai-body .hai-chat-item:hover { background: var(--bg-hover); }
.histora-ai-body .hai-chat-item.is-active { background: var(--bg-active); }

.histora-ai-body .hai-chat-item__title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.histora-ai-body .hai-chat-item__menu {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    opacity: 0;
    transition: opacity var(--dur-fast) var(--easing),
                background var(--dur-fast) var(--easing);
}
.histora-ai-body .hai-chat-item:hover .hai-chat-item__menu { opacity: 1; }
.histora-ai-body .hai-chat-item__menu:hover { background: var(--bg-active); color: var(--text-primary); }
.histora-ai-body .hai-chat-item__menu svg { width: 16px; height: 16px; }

.histora-ai-body .hai-chat-list__empty {
    padding: var(--space-3);
    color: var(--text-hint);
    font-family: var(--font-sans) !important;
    font-size: 13px;
    line-height: 1.4;
}

/* Sidebar footer */
.histora-ai-body .hai-sidebar__footer {
    padding: var(--space-3);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-shrink: 0;
}

.histora-ai-body .hai-sidebar__footer-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 10px var(--space-3);
    border-radius: 10px;
    color: var(--text-primary);
    font-family: var(--font-sans) !important;
    font-size: 14px;
    transition: background var(--dur-fast) var(--easing);
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    cursor: pointer;
}
.histora-ai-body .hai-sidebar__footer-item:hover { background: var(--bg-hover); text-decoration: none; }
.histora-ai-body .hai-sidebar__footer-item svg { width: 20px; height: 20px; flex-shrink: 0; color: var(--text-secondary); }

.histora-ai-body .hai-sidebar__footer-text {
    font-family: var(--font-sans) !important;
    transition: opacity var(--dur-fast) var(--easing);
}

/* --------------------------------------------------------------------------
   5. Main column
   -------------------------------------------------------------------------- */
.histora-ai-body .hai-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    position: relative;
    overflow: hidden;
}

.histora-ai-body .hai-header {
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-4);
    background: var(--bg-overlay) !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-subtle);
    position: sticky;
    top: 0;
    z-index: 20;
    flex-shrink: 0;
    color: var(--text-primary) !important;
}

.histora-ai-body .hai-header__left {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
}

/* Header title — explicitly reset every property a WP theme might bleed in */
.histora-ai-body .hai-header__title {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary) !important;
    margin: 0;
    padding: 0;
    line-height: 1.3;
    background: none;
    text-shadow: none;
    text-decoration: none;
    -webkit-text-fill-color: var(--text-primary) !important;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}
.histora-ai-body .hai-header__title > span {
    color: inherit;
    background: none;
    -webkit-text-fill-color: inherit;
}

.histora-ai-body .hai-header__model {
    color: var(--text-secondary) !important;
    -webkit-text-fill-color: var(--text-secondary) !important;
    font-weight: 400;
    font-size: 13px;
    padding: 2px var(--space-2);
    border-radius: 6px;
    background: var(--bg-hover);
}

/* Version chip next to "HISTORA AI" wordmark — subtle accent so it reads as
   metadata, not as a separate brand element. */
.histora-ai-body .hai-header__version {
    font-family: var(--font-mono, ui-monospace, "JetBrains Mono", monospace);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    line-height: 1;
    padding: 3px 7px;
    border-radius: 999px;
    color: var(--accent-blue, #4285F4) !important;
    -webkit-text-fill-color: var(--accent-blue, #4285F4) !important;
    background: linear-gradient(135deg, rgba(66, 133, 244, 0.12), rgba(156, 39, 176, 0.10));
    border: 1px solid rgba(66, 133, 244, 0.22);
}

.histora-ai-body .hai-header__right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.histora-ai-body .hai-mobile-toggle { display: none; }

/* External nav button — links to the SIPURBA history portal. Pill shape consistent
   with the rest of the app's design language. */
.histora-ai-body .hai-sipurba-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 14px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border-subtle);
    background: var(--bg-surface);
    color: var(--text-primary) !important;
    -webkit-text-fill-color: var(--text-primary) !important;
    font-family: var(--font-sans) !important;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    text-decoration: none;
    line-height: 1;
    margin-right: var(--space-2);
    transition: background var(--dur-fast) var(--easing),
                border-color var(--dur-fast) var(--easing),
                box-shadow var(--dur-fast) var(--easing),
                transform var(--dur-fast) var(--easing);
}
.histora-ai-body .hai-sipurba-btn:hover {
    background: var(--bg-active);
    border-color: var(--border-strong);
    box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.18), var(--shadow-md);
    text-decoration: none;
}
.histora-ai-body .hai-sipurba-btn:active { transform: scale(0.97); }
.histora-ai-body .hai-sipurba-btn:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

/* Theme toggle: animated sun/moon swap.
   Both icons share the same grid cell so they stack and crossfade in place. */
.histora-ai-body .hai-theme-toggle {
    position: relative;
    display: inline-grid;
    place-items: center;
}
.histora-ai-body .hai-theme-toggle .hai-theme-toggle__sun,
.histora-ai-body .hai-theme-toggle .hai-theme-toggle__moon {
    grid-area: 1 / 1;
    width: 20px;
    height: 20px;
    transition: opacity var(--dur-base) var(--easing),
                transform var(--dur-base) var(--easing);
}
/* Default (light theme): show the sun glyph (the icon represents the active mode) */
.histora-ai-body .hai-theme-toggle .hai-theme-toggle__sun {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}
.histora-ai-body .hai-theme-toggle .hai-theme-toggle__moon {
    opacity: 0;
    transform: rotate(90deg) scale(0.6);
}
/* Explicit dark theme — show moon, hide sun */
:root[data-hai-theme="dark"] .histora-ai-body .hai-theme-toggle .hai-theme-toggle__sun {
    opacity: 0;
    transform: rotate(-90deg) scale(0.6);
}
:root[data-hai-theme="dark"] .histora-ai-body .hai-theme-toggle .hai-theme-toggle__moon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}
/* (No system-preference branch — light is the unconditional default.) */

/* --------------------------------------------------------------------------
   6. Chat area — welcome + messages
   -------------------------------------------------------------------------- */
.histora-ai-body .hai-chat {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    background: var(--bg-primary) !important;
    color: var(--text-primary) !important;
}

.histora-ai-body .hai-chat__inner {
    max-width: var(--content-max-w);
    margin: 0 auto;
    padding: var(--space-5) var(--space-5) var(--space-7);
    width: 100%;
}

.histora-ai-body .hai-welcome {
    min-height: calc(100vh - var(--header-h) - 220px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--space-7) var(--space-4);
    animation: hai-fade-in 0.5s var(--easing) both;
}

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

.histora-ai-body .hai-welcome__icon {
    width: 120px;
    height: 120px;
    margin-bottom: var(--space-5);
    display: flex;
    align-items: center;
    justify-content: center;
    perspective: 600px;
}
.histora-ai-body .hai-welcome__icon svg { width: 100%; height: 100%; }

/* ----------------------------------------------------------------------------
   hai-welcome_icon — Material Design hourglass
   ----------------------------------------------------------------------------
   Animations are scoped under the `.hai-hg-svg.is-animated` class so the
   static icon (sidebar brand, message avatars) stays calm while the welcome
   hero and "thinking" avatar get the full motion treatment.

   Notes on the design:
   • `transform-box: view-box` keeps all transform-origins in viewBox (user)
     coordinates, which is what the keyframes assume. Without it, some
     browsers default to fill-box where literal px origins land outside the
     element's bounding box and produce the "sand drifting out of the
     hourglass" artifact reported on earlier builds.
   • Breathe (4s) lives on the root SVG; flip (12s — one 180° half-turn every
     6s) lives on the body group. They target different elements so they
     don't overwrite each other's `transform` property.
   ---------------------------------------------------------------------------- */
.histora-ai-body .hai-hg-svg {
    overflow: visible;
    transform-box: view-box;
    transform-origin: 60px 60px;
    will-change: transform;
}

.histora-ai-body .hai-hg-svg .hai-hg__body,
.histora-ai-body .hai-hg-svg .hai-hg__glow,
.histora-ai-body .hai-hg-svg .hai-hg__drip,
.histora-ai-body .hai-hg-svg .hai-hg__sand-top,
.histora-ai-body .hai-hg-svg .hai-hg__sand-bot {
    transform-box: view-box;
}

.histora-ai-body .hai-hg-svg .hai-hg__body {
    transform-origin: 60px 60px;
}

/* Idle breathe — entire icon gently pulses 1.0 → 1.03 → 1.0 every 4s */
.histora-ai-body .hai-hg-svg.is-animated {
    animation: hai-hgsvg-breathe 4s ease-in-out infinite;
}

@keyframes hai-hgsvg-breathe {
    0%, 100% { transform: scale(1);    }
    50%      { transform: scale(1.03); }
}

/* Flip — body holds steady for ~5s then rotates 180° in ~1s. The 12s cycle
   contains two such flips so the keyframe loops back to its start angle
   (rotateX 0deg ↔ 360deg) without a visual jump. Effective flip rate: 6s. */
.histora-ai-body .hai-hg-svg.is-animated .hai-hg__body {
    animation: hai-hgsvg-flip 12s cubic-bezier(0.4, 0, 0.2, 1) infinite;
    will-change: transform;
}

@keyframes hai-hgsvg-flip {
    0%, 42%   { transform: rotateX(0deg);   }
    50%, 92%  { transform: rotateX(180deg); }
    100%      { transform: rotateX(360deg); }
}

/* Soft radial glow at the neck — opacity pulses 0.3 → 0.7 → 0.3 over 3s */
.histora-ai-body .hai-hg-svg .hai-hg__glow {
    transform-origin: 60px 60px;
    opacity: 0.4;
}
.histora-ai-body .hai-hg-svg.is-animated .hai-hg__glow {
    animation: hai-hgsvg-glow 3s ease-in-out infinite;
    will-change: opacity, transform;
}

@keyframes hai-hgsvg-glow {
    0%, 100% { opacity: 0.3; transform: scale(0.9);  }
    50%      { opacity: 0.7; transform: scale(1.15); }
}

/* Falling sand-stream particles — start at the neck, fall to just above the
   sand pile (so they stay clearly inside the bottom chamber, never bleeding
   past the bottom plate). Two dots offset by half-cycle for a continuous stream. */
.histora-ai-body .hai-hg-svg .hai-hg__drip {
    transform-origin: 60px 60px;
    opacity: 0;
}
.histora-ai-body .hai-hg-svg.is-animated .hai-hg__drip {
    will-change: transform, opacity;
}
.histora-ai-body .hai-hg-svg.is-animated .hai-hg__drip--1 {
    animation: hai-hgsvg-drip 3s ease-in-out 0s infinite;
}
.histora-ai-body .hai-hg-svg.is-animated .hai-hg__drip--2 {
    animation: hai-hgsvg-drip 3s ease-in-out 1.5s infinite;
}

@keyframes hai-hgsvg-drip {
    0%   { transform: translateY(0);    opacity: 0; }
    20%  { opacity: 1; }
    80%  { opacity: 1; }
    100% { transform: translateY(20px); opacity: 0; }
}

/* Sand levels stay static at a "mid-pour" look — animating the levels in
   sync with the flip introduced visual snaps each cycle, and the moving
   drip + glow already carry the sense of flow. */
.histora-ai-body .hai-hg-svg .hai-hg__sand-top { transform-origin: 60px 58px; }
.histora-ai-body .hai-hg-svg .hai-hg__sand-bot { transform-origin: 60px 99px; }

.histora-ai-body .hai-welcome__title {
    font-size: 2.5rem !important;
    font-weight: 500 !important;
    line-height: 1.2 !important;
    letter-spacing: -0.03em !important;
    margin: 0 0 var(--space-3) !important;
    /* Solid fallback so the title remains readable even if background-clip:text
       isn't supported or the gradient fails to paint (e.g. light WP themes that
       inject background-image into headings). */
    color: var(--text-primary) !important;
    -webkit-text-fill-color: var(--text-primary) !important;
    background: var(--gradient-text);
    -webkit-background-clip: text;
    background-clip: text;
    text-shadow: none !important;
}
@supports ((-webkit-background-clip: text) or (background-clip: text)) {
    .histora-ai-body .hai-welcome__title {
        -webkit-text-fill-color: transparent !important;
        color: transparent !important;
    }
}
/* Dark theme: brand gradient with high contrast for dark background */
:root[data-hai-theme="dark"] .histora-ai-body .hai-welcome__title {
    background: linear-gradient(90deg, #4285F4 0%, #A142F4 50%, #F44336 100%) !important;
    -webkit-background-clip: text !important;
    background-clip: text !important;
}

/* Light theme: switch to a darker brand gradient so the title keeps strong
   contrast against the white background. */
:root[data-hai-theme="light"] .histora-ai-body .hai-welcome__title {
    background: linear-gradient(90deg, #1A73E8 0%, #6A1B9A 50%, #C5221F 100%) !important;
    -webkit-background-clip: text !important;
    background-clip: text !important;
}

.histora-ai-body .hai-welcome__subtitle {
    font-size: 1.5rem !important;
    font-weight: 400 !important;
    line-height: 1.3 !important;
    letter-spacing: -0.02em !important;
    color: var(--text-secondary) !important;
    -webkit-text-fill-color: var(--text-secondary) !important;
    margin: 0 0 var(--space-7) !important;
    max-width: 540px;
}

/* ----------------------------------------------------------------------------
   Suggestion chips — modernized for a 6-card responsive grid.
   ----------------------------------------------------------------------------
   • Auto-fit columns: 3-col at ≥820px, 2-col mid widths, 1-col on phones
   • Tighter cards with a colored-icon badge on the left
   • Soft gradient hover-glow that hints at the brand palette without shouting
   ---------------------------------------------------------------------------- */
.histora-ai-body .hai-suggestions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    grid-auto-rows: 1fr;
    align-items: stretch;
    gap: var(--space-3);
    width: 100%;
    max-width: 880px;
}

/* Staggered chip entry so the welcome state feels alive, not static. */
.histora-ai-body .hai-suggestion {
    animation: hai-chip-in 0.55s var(--easing) both;
}
.histora-ai-body .hai-suggestion:nth-child(1) { animation-delay: 0.05s; }
.histora-ai-body .hai-suggestion:nth-child(2) { animation-delay: 0.12s; }
.histora-ai-body .hai-suggestion:nth-child(3) { animation-delay: 0.19s; }
.histora-ai-body .hai-suggestion:nth-child(4) { animation-delay: 0.26s; }
.histora-ai-body .hai-suggestion:nth-child(5) { animation-delay: 0.33s; }
.histora-ai-body .hai-suggestion:nth-child(6) { animation-delay: 0.40s; }

@keyframes hai-chip-in {
    from { opacity: 0; transform: translateY(14px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0)    scale(1); }
}

/* Card body — icon badge sits to the left of two-line text */
.histora-ai-body .hai-suggestion {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 14px 16px;
    background: var(--bg-surface) !important;
    background-image: none !important;
    border: 1px solid var(--border-subtle) !important;
    border-radius: 14px;
    text-align: left;
    color: var(--text-primary) !important;
    font-size: 14px;
    line-height: 1.45;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    transition: transform var(--dur-base) var(--easing),
                border-color var(--dur-base) var(--easing),
                background-color var(--dur-base) var(--easing),
                box-shadow var(--dur-base) var(--easing);
    min-height: 92px;
    height: 100%;
    text-shadow: none;
    overflow: hidden;
    isolation: isolate;
}

/* Subtle gradient highlight bar that only shows on hover */
.histora-ai-body .hai-suggestion::after {
    content: '';
    position: absolute;
    inset: auto 0 0 0;
    height: 2px;
    background: var(--gradient-gemini);
    opacity: 0;
    transition: opacity var(--dur-base) var(--easing);
    pointer-events: none;
}
.histora-ai-body .hai-suggestion:hover {
    transform: translateY(-3px);
    border-color: var(--border-strong) !important;
    background: var(--bg-elevated) !important;
    background-image: none !important;
    color: var(--text-primary) !important;
    box-shadow: var(--shadow-md) !important;
}
.histora-ai-body .hai-suggestion:hover::after { opacity: 0.85; }
.histora-ai-body .hai-suggestion:active { transform: translateY(-1px); }
.histora-ai-body .hai-suggestion:focus,
.histora-ai-body .hai-suggestion:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
    background: var(--bg-elevated) !important;
    color: var(--text-primary) !important;
}

/* Light theme: crisper outline + brighter elevated hover state */
:root[data-hai-theme="light"] .histora-ai-body .hai-suggestion,
:root:not([data-hai-theme="dark"]) .histora-ai-body .hai-suggestion {
    background: #FFFFFF !important;
    border-color: #E2E5EA !important;
    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.06);
}
:root[data-hai-theme="light"] .histora-ai-body .hai-suggestion:hover,
:root:not([data-hai-theme="dark"]) .histora-ai-body .hai-suggestion:hover {
    background: #F8FAFF !important;
    border-color: #BDC8DA !important;
    box-shadow: 0 6px 18px rgba(60, 64, 67, 0.10) !important;
}

/* Icon badge — colored square tinted to the accent for that suggestion */
.histora-ai-body .hai-suggestion__icon {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: rgba(66, 133, 244, 0.10);
    color: var(--accent-blue);
}
.histora-ai-body .hai-suggestion:nth-child(2) .hai-suggestion__icon { background: rgba(156, 39, 176, 0.10); color: var(--accent-purple); }
.histora-ai-body .hai-suggestion:nth-child(3) .hai-suggestion__icon { background: rgba(234, 67, 53, 0.10); color: var(--accent-red); }
.histora-ai-body .hai-suggestion:nth-child(4) .hai-suggestion__icon { background: rgba(52, 168, 83, 0.12); color: #1A8A4D; }
.histora-ai-body .hai-suggestion:nth-child(5) .hai-suggestion__icon { background: rgba(251, 188, 5, 0.14); color: #B98908; }
.histora-ai-body .hai-suggestion:nth-child(6) .hai-suggestion__icon { background: rgba(26, 115, 232, 0.10); color: #1A73E8; }
.histora-ai-body .hai-suggestion__icon svg { width: 18px; height: 18px; }

.histora-ai-body .hai-suggestion__text {
    flex: 1;
    color: var(--text-primary) !important;
    -webkit-text-fill-color: var(--text-primary) !important;
    font-weight: 500;
    font-size: 13.5px;
    line-height: 1.5;
    letter-spacing: -0.005em;
    text-wrap: balance;
    word-break: normal;
    overflow-wrap: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    align-self: center;
}

/* --------------------------------------------------------------------------
   7. Messages
   -------------------------------------------------------------------------- */
.histora-ai-body .hai-messages {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

.histora-ai-body .hai-message {
    animation: hai-message-in 0.3s var(--easing) both;
}

@keyframes hai-message-in {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

.histora-ai-body .hai-message--user {
    display: flex;
    justify-content: flex-end;
}

.histora-ai-body .hai-message--user .hai-message__bubble {
    background: var(--user-bubble);
    border-radius: var(--radius-bubble-user);
    padding: var(--space-3) var(--space-4);
    max-width: 80%;
    color: var(--text-primary);
    font-weight: 400;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.histora-ai-body .hai-message--ai {
    display: flex;
    gap: var(--space-3);
    align-items: flex-start;
}

.histora-ai-body .hai-message__avatar {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 2px;
}
.histora-ai-body .hai-message__avatar svg { width: 28px; height: 28px; display: block; }

.histora-ai-body .hai-message__body {
    flex: 1;
    min-width: 0;
}

.histora-ai-body .hai-message__content {
    color: var(--text-primary);
    font-size: 16px;
    line-height: 1.7;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.histora-ai-body .hai-message__content > *:first-child { margin-top: 0; }
.histora-ai-body .hai-message__content > *:last-child  { margin-bottom: 0; }

.histora-ai-body .hai-message__content h1,
.histora-ai-body .hai-message__content h2,
.histora-ai-body .hai-message__content h3,
.histora-ai-body .hai-message__content h4 {
    font-weight: 600;
    letter-spacing: -0.02em;
    margin: var(--space-5) 0 var(--space-2);
    line-height: 1.3;
    color: var(--text-primary);
}
.histora-ai-body .hai-message__content h1 { font-size: 1.5rem; }
.histora-ai-body .hai-message__content h2 { font-size: 1.25rem; }
.histora-ai-body .hai-message__content h3 { font-size: 1.1rem; }
.histora-ai-body .hai-message__content h4 { font-size: 1rem; }

.histora-ai-body .hai-message__content p { margin: 0 0 var(--space-3); }
.histora-ai-body .hai-message__content strong { font-weight: 600; color: var(--text-primary); }
.histora-ai-body .hai-message__content em { font-style: italic; }

.histora-ai-body .hai-message__content ul,
.histora-ai-body .hai-message__content ol {
    margin: 0 0 var(--space-3);
    padding-left: var(--space-5);
    list-style: revert;
}
.histora-ai-body .hai-message__content li { margin-bottom: var(--space-1); }

.histora-ai-body .hai-message__content code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    padding: 2px 6px;
    background: var(--code-bg);
    border-radius: 4px;
    color: var(--code-text);
}

.histora-ai-body .hai-message__content pre {
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: var(--space-4);
    margin: var(--space-3) 0;
    overflow-x: auto;
    position: relative;
}
.histora-ai-body .hai-message__content pre code {
    background: transparent;
    padding: 0;
    color: var(--text-primary);
    font-size: 13.5px;
    line-height: 1.6;
}

/* Academic blockquote — used for direct quotations from sources */
.histora-ai-body .hai-message__content blockquote {
    margin: var(--space-4) 0;
    padding: var(--space-3) var(--space-5);
    border-left: 3px solid var(--accent-blue, #1a73e8);
    background: var(--bg-secondary);
    border-radius: 0 8px 8px 0;
    color: var(--text-primary);
    font-family: var(--font-serif, Georgia, "Times New Roman", serif);
    font-style: italic;
    font-size: 0.97em;
    line-height: 1.75;
    quotes: "\201C" "\201D" "\2018" "\2019";
}
.histora-ai-body .hai-message__content blockquote > *:first-child { margin-top: 0; }
.histora-ai-body .hai-message__content blockquote > *:last-child  { margin-bottom: 0; }
.histora-ai-body .hai-message__content blockquote em { font-style: italic; }
.histora-ai-body .hai-message__content blockquote strong { font-style: normal; }

/* Subtle horizontal rule — kept ultra-low-key on purpose. The AI is
   instructed not to emit these, but we render them defensively. */
.histora-ai-body .hai-message__content hr {
    border: none;
    height: 1px;
    background: var(--border-subtle);
    margin: var(--space-4) 0;
    opacity: 0.6;
}

.histora-ai-body .hai-code-copy {
    position: absolute;
    top: var(--space-2);
    right: var(--space-2);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    transition: background var(--dur-fast) var(--easing),
                color var(--dur-fast) var(--easing);
}
.histora-ai-body .hai-code-copy:hover { background: var(--bg-active); color: var(--text-primary); }

/* Source citations */
.histora-ai-body .hai-sources {
    margin-top: var(--space-4);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    background: var(--bg-secondary);
}
.histora-ai-body .hai-sources__title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
    display: flex;
    align-items: center;
    gap: 6px;
}
.histora-ai-body .hai-sources__title > svg { width: 14px; height: 14px; }

/* "Salin referensi" button — sits at the right edge of the sources title row */
.histora-ai-body .hai-sources__copy {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 999px;
    font-family: var(--font-sans);
    font-size: 11.5px;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-hover);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background var(--dur-fast) var(--easing),
                color var(--dur-fast) var(--easing),
                border-color var(--dur-fast) var(--easing);
}
.histora-ai-body .hai-sources__copy:hover {
    background: var(--bg-active);
    color: var(--text-primary);
    border-color: var(--border-subtle);
}
.histora-ai-body .hai-sources__copy svg { width: 12px; height: 12px; }
.histora-ai-body .hai-sources__copy.is-active { color: var(--accent-blue); }
.histora-ai-body .hai-sources__copy-label { letter-spacing: 0.01em; }
.histora-ai-body .hai-sources__list {
    list-style: decimal;
    margin: 0;
    padding-left: var(--space-5);
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}
.histora-ai-body .hai-sources__list li { margin-bottom: 4px; }
.histora-ai-body .hai-sources__list em { color: var(--text-primary); }

/* AI message action row */
.histora-ai-body .hai-message__actions {
    display: flex;
    gap: 2px;
    margin-top: var(--space-2);
    opacity: 0;
    transition: opacity var(--dur-base) var(--easing);
}
.histora-ai-body .hai-message--ai:hover .hai-message__actions,
.histora-ai-body .hai-message--ai:focus-within .hai-message__actions { opacity: 1; }

.histora-ai-body .hai-action-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: background var(--dur-fast) var(--easing),
                color var(--dur-fast) var(--easing),
                transform var(--dur-fast) var(--easing);
}
.histora-ai-body .hai-action-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.histora-ai-body .hai-action-btn:active { transform: scale(0.92); }
.histora-ai-body .hai-action-btn.is-active { color: var(--accent-blue); }
.histora-ai-body .hai-action-btn svg { width: 16px; height: 16px; }

/* --------------------------------------------------------------------------
   8. Thinking indicator (modern shimmer + glowing sparkle)
   - Avatar sparkle pulses with a soft brand-colored glow
   - Label text has a moving highlight gradient ("shimmer")
   - Both animations only animate composited properties (transform/filter/
     background-position/opacity) so they stay smooth at 60fps
   -------------------------------------------------------------------------- */
.histora-ai-body .hai-thinking {
    display: flex;
    gap: var(--space-3);
    align-items: center;
    padding: var(--space-2) 0;
    animation: hai-message-in 0.25s var(--easing) both;
}

.histora-ai-body .hai-thinking__avatar {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    will-change: transform;
    animation: hai-think-pulse 1.6s var(--easing) infinite;
}
.histora-ai-body .hai-thinking__avatar svg { width: 30px; height: 30px; display: block; }

/* Softer brand-tinted halo behind the icon — much lower intensity now that
   the gradient glow had been overpowering during AI thinking. */
.histora-ai-body .hai-thinking__avatar::before {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    background: var(--gradient-gemini);
    opacity: 0.08;
    filter: blur(8px);
    z-index: -1;
    animation: hai-think-halo 1.6s var(--easing) infinite;
}

@keyframes hai-think-pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.08);
    }
}

@keyframes hai-think-halo {
    0%, 100% { opacity: 0.08; transform: scale(1);    }
    50%      { opacity: 0.18; transform: scale(1.18); }
}

/* Single-color shimmer (was a full rainbow band) — keeps the "loading" feel
   without flooding the label with brand-color light. */
.histora-ai-body .hai-thinking__label {
    font-size: 15px;
    font-weight: 500;
    letter-spacing: -0.005em;
    background: linear-gradient(
        100deg,
        var(--text-hint) 0%,
        var(--text-hint) 40%,
        var(--text-primary) 50%,
        var(--text-hint) 60%,
        var(--text-hint) 100%
    );
    background-size: 240% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    will-change: background-position;
    animation: hai-shimmer 2s linear infinite;
}

@keyframes hai-shimmer {
    0%   { background-position: 240% 0; }
    100% { background-position: -240% 0; }
}

/* --------------------------------------------------------------------------
   8b. Streaming caret (used while AI text is being progressively revealed)
   -------------------------------------------------------------------------- */
.histora-ai-body .hai-stream-caret {
    display: inline-block;
    width: 8px;
    height: 1em;
    margin-left: 3px;
    vertical-align: -2px;
    background: var(--gradient-gemini);
    border-radius: 2px;
    animation: hai-caret-blink 0.9s steps(2, end) infinite;
    will-change: opacity;
}

@keyframes hai-caret-blink {
    50% { opacity: 0; }
}

.histora-ai-body .hai-message__content--streaming {
    white-space: pre-wrap;
}

/* --------------------------------------------------------------------------
   9. Sticky input bar
   -------------------------------------------------------------------------- */
.histora-ai-body .hai-input-bar {
    flex-shrink: 0;
    padding: var(--space-3) var(--space-5) var(--space-4);
    background: var(--bg-overlay);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid transparent;
    position: relative;
    z-index: 10;
}

.histora-ai-body .hai-input-bar__inner {
    max-width: var(--content-max-w);
    margin: 0 auto;
    width: 100%;
}

/* 3-column grid: [attachments] [textarea (1fr)] [send].
   align-items: center reliably puts every column on the same vertical centerline. */
.histora-ai-body .hai-input-box {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    column-gap: var(--space-2);
    background: var(--bg-input) !important;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-input);
    padding: 8px 10px;
    transition: border-color var(--dur-base) var(--easing),
                box-shadow var(--dur-base) var(--easing),
                background var(--dur-base) var(--easing);
    min-height: 56px;
}
.histora-ai-body .hai-input-box:focus-within {
    border-color: var(--border-focus);
    box-shadow: var(--shadow-glow);
}
/* When the textarea grows past one line, anchor attachments + send to bottom. */
.histora-ai-body .hai-input-box.is-multiline {
    align-items: end;
    padding-bottom: 10px;
}
.histora-ai-body .hai-input-box.is-multiline .hai-attach-btn,
.histora-ai-body .hai-input-box.is-multiline .hai-mode-btn,
.histora-ai-body .hai-input-box.is-multiline .hai-send-btn {
    margin-bottom: 2px;
}

.histora-ai-body .hai-input-box__attachments {
    display: flex;
    align-items: center;
    gap: 2px;
}

.histora-ai-body .hai-attach-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: background var(--dur-fast) var(--easing),
                color var(--dur-fast) var(--easing);
}
.histora-ai-body .hai-attach-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.histora-ai-body .hai-attach-btn svg { width: 20px; height: 20px; }

/* Disabled state — used for the image button while the feature is in development. */
.histora-ai-body .hai-attach-btn:disabled,
.histora-ai-body .hai-attach-btn[disabled] {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: auto; /* keep tooltip discoverable on hover */
}
.histora-ai-body .hai-attach-btn:disabled:hover,
.histora-ai-body .hai-attach-btn[disabled]:hover {
    background: transparent;
    color: var(--text-secondary);
}

/* File attachment preview pill — sits between the input form and the disclaimer. */
.histora-ai-body .hai-attach-preview {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 8px 0 0;
    padding: 4px 6px 4px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-pill);
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--text-primary);
    max-width: 100%;
}
.histora-ai-body .hai-attach-preview[hidden] { display: none !important; }
.histora-ai-body .hai-attach-preview__icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--text-secondary);
}
.histora-ai-body .hai-attach-preview__name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 240px;
    line-height: 1.3;
}
.histora-ai-body .hai-attach-preview__remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    color: var(--text-secondary);
    transition: background var(--dur-fast) var(--easing),
                color var(--dur-fast) var(--easing);
}
.histora-ai-body .hai-attach-preview__remove:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.histora-ai-body .hai-attach-preview__remove svg { width: 14px; height: 14px; }

/* --------------------------------------------------------------------------
   Mode Histora picker — pill button + popover menu inside the input bar
   -------------------------------------------------------------------------- */
.histora-ai-body .hai-mode-picker {
    position: relative;
    display: inline-flex;
    align-items: center;
    /* Moved left by removing the 4px margin */
    margin-left: 0;
}

.histora-ai-body .hai-mode-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid transparent; /* Match attachment buttons style */
    background: transparent;
    color: var(--text-secondary); /* Match attachment buttons color */
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    line-height: 1;
    cursor: pointer;
    transition: background var(--dur-fast) var(--easing),
                border-color var(--dur-fast) var(--easing),
                box-shadow var(--dur-fast) var(--easing),
                color var(--dur-fast) var(--easing);
}
.histora-ai-body .hai-mode-btn:hover {
    background: var(--bg-active);
    border-color: var(--border-strong);
}
.histora-ai-body .hai-mode-btn:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}
.histora-ai-body .hai-mode-btn[aria-expanded="true"] {
    background: var(--bg-active);
    border-color: var(--border-focus);
    box-shadow: var(--shadow-glow);
}
.histora-ai-body .hai-mode-btn__icon {
    width: 20px; /* Matched to attachment icons (20px) */
    height: 20px;
    flex-shrink: 0;
    color: var(--accent-blue, #4285F4);
}
.histora-ai-body .hai-mode-btn__label {
    white-space: nowrap;
    /* Hide label on the trigger button — label is visible inside the dropdown only */
    display: none;
}
.histora-ai-body .hai-mode-btn__chevron {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    color: var(--text-secondary);
    transition: transform var(--dur-fast) var(--easing);
    /* Hide chevron — button is icon-only */
    display: none;
}
.histora-ai-body .hai-mode-btn[aria-expanded="true"] .hai-mode-btn__chevron {
    transform: rotate(180deg);
}

/* Popover menu — anchored above the trigger button. */
.histora-ai-body .hai-mode-menu {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 0;
    z-index: 30;
    min-width: 340px;
    max-width: calc(100vw - 32px);
    padding: 6px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    gap: 6px;
    transform-origin: bottom left;
    animation: hai-mode-menu-in 0.18s var(--easing);
}
.histora-ai-body .hai-mode-menu[hidden] { display: none !important; }

@keyframes hai-mode-menu-in {
    from { opacity: 0; transform: translateY(6px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0)   scale(1); }
}

.histora-ai-body .hai-mode-menu__title {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-hint);
    padding: 8px 10px 4px;
}

.histora-ai-body .hai-mode-option {
    display: grid;
    grid-template-columns: 28px 1fr 18px;
    align-items: center;
    column-gap: 10px;
    width: 100%;
    padding: 14px 12px;
    border: 0;
    background: transparent;
    border-radius: 10px;
    text-align: left;
    color: var(--text-primary);
    font-family: var(--font-sans);
    cursor: pointer;
    transition: background var(--dur-fast) var(--easing);
}
.histora-ai-body .hai-mode-option:hover { background: var(--bg-hover); }
.histora-ai-body .hai-mode-option:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}
.histora-ai-body .hai-mode-option.is-active { background: var(--bg-active); }

.histora-ai-body .hai-mode-option__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: var(--bg-surface);
    color: var(--accent-blue, #4285F4);
}
.histora-ai-body .hai-mode-option__icon svg { width: 16px; height: 16px; }

/* Per-mode accent tints — purely cosmetic, helps the user scan options at a glance. */
.histora-ai-body .hai-mode-option[data-mode="normal"]   .hai-mode-option__icon { color: #4285F4; }
.histora-ai-body .hai-mode-option[data-mode="akademis"] .hai-mode-option__icon { color: #34A853; }
.histora-ai-body .hai-mode-option[data-mode="gaul"]     .hai-mode-option__icon { color: #EA4335; }

.histora-ai-body .hai-mode-option__body {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}
.histora-ai-body .hai-mode-option__title {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    color: var(--text-primary);
}
.histora-ai-body .hai-mode-option__desc {
    font-size: 12px;
    line-height: 1.35;
    color: var(--text-secondary);
}

.histora-ai-body .hai-mode-option__check {
    width: 18px;
    height: 18px;
    color: var(--accent-blue, #4285F4);
    opacity: 0;
    transform: scale(0.7);
    transition: opacity var(--dur-fast) var(--easing),
                transform var(--dur-fast) var(--easing);
}
.histora-ai-body .hai-mode-option.is-active .hai-mode-option__check {
    opacity: 1;
    transform: scale(1);
}

/* Mobile — icon-only button is already the default; shrink the menu. */
@media (max-width: 480px) {
    .histora-ai-body .hai-mode-menu {
        min-width: calc(100vw - 48px);
    }
}

.histora-ai-body .hai-textarea {
    /* Sits in the 1fr middle grid column. align-items: center on the parent
       handles vertical alignment; we just need the textarea to render its single
       line of text on a baseline that matches the icon center. */
    display: block;
    width: 100%;
    min-height: 24px;
    max-height: 200px;
    padding: 0;
    margin: 0;
    resize: none;
    background: transparent !important;
    color: var(--text-primary) !important;
    -webkit-text-fill-color: var(--text-primary) !important;
    font-family: var(--font-sans) !important;
    font-size: 16px;
    line-height: 24px;
    overflow-y: auto;
    word-break: break-word;
    border: none;
    outline: none;
    box-shadow: none;
    vertical-align: middle;
    align-self: center;
}
.histora-ai-body .hai-textarea::placeholder {
    color: var(--text-hint);
    -webkit-text-fill-color: var(--text-hint);
    opacity: 1;
    font-weight: 400;
}

.histora-ai-body .hai-send-btn {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
    display: inline-grid;
    place-items: center;
    background: var(--bg-active);
    color: var(--text-hint);
    transition: background var(--dur-base) var(--easing),
                color var(--dur-base) var(--easing),
                transform var(--dur-fast) var(--easing),
                opacity var(--dur-base) var(--easing);
    align-self: center;
}
.histora-ai-body .hai-send-btn__icon {
    grid-area: 1 / 1;
    width: 18px;
    height: 18px;
    transition: opacity var(--dur-fast) var(--easing),
                transform var(--dur-fast) var(--easing);
}
/* Default: show the send arrow; hide the stop square */
.histora-ai-body .hai-send-btn__icon--send { opacity: 1; transform: scale(1); }
.histora-ai-body .hai-send-btn__icon--stop { opacity: 0; transform: scale(0.6); }

.histora-ai-body .hai-send-btn.is-active {
    background: var(--gradient-gemini);
    color: var(--text-on-accent);
}
.histora-ai-body .hai-send-btn.is-active:hover { transform: scale(1.05); }
.histora-ai-body .hai-send-btn.is-active:active { transform: scale(0.95); }
.histora-ai-body .hai-send-btn:disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

/* Stop state — swap to the square icon, switch to a calmer surface color */
.histora-ai-body .hai-send-btn.is-stop {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
    cursor: pointer;
    opacity: 1;
}
.histora-ai-body .hai-send-btn.is-stop:hover {
    background: var(--bg-active);
    transform: scale(1.05);
}
.histora-ai-body .hai-send-btn.is-stop .hai-send-btn__icon--send { opacity: 0; transform: scale(0.6); }
.histora-ai-body .hai-send-btn.is-stop .hai-send-btn__icon--stop { opacity: 1; transform: scale(1); }

.histora-ai-body .hai-disclaimer {
    text-align: center;
    color: var(--text-hint) !important;
    -webkit-text-fill-color: var(--text-hint) !important;
    font-size: 12px;
    line-height: 1.4;
    margin: var(--space-2) 0 0;
}

/* --------------------------------------------------------------------------
   10. Mobile sidebar overlay
   -------------------------------------------------------------------------- */
.histora-ai-body .hai-sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 25;
    opacity: 0;
    transition: opacity var(--dur-slow) var(--easing);
}
.histora-ai-body .hai-sidebar-backdrop.is-visible {
    display: block;
    opacity: 1;
}

/* --------------------------------------------------------------------------
   11. Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 1023px) {
    .histora-ai-body .hai-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }
    .histora-ai-body .hai-sidebar.is-mobile-open {
        transform: translateX(0);
    }
    body.admin-bar.histora-ai-body .hai-sidebar { top: 32px; height: calc(100vh - 32px); }
    .histora-ai-body .hai-mobile-toggle { display: inline-flex; }
}

@media (max-width: 767px) {
    .histora-ai-body .hai-suggestions {
        grid-template-columns: 1fr;
        gap: var(--space-2);
    }
    .histora-ai-body .hai-welcome__title { font-size: 2rem !important; }
    .histora-ai-body .hai-welcome__subtitle { font-size: 1.15rem !important; }
    .histora-ai-body .hai-welcome__icon { width: 96px; height: 96px; }

    .histora-ai-body .hai-chat__inner {
        padding: var(--space-4) var(--space-4) var(--space-5);
    }
    .histora-ai-body .hai-input-bar {
        padding: var(--space-2) var(--space-3) max(var(--space-3), env(safe-area-inset-bottom));
    }
    .histora-ai-body .hai-message--user .hai-message__bubble { max-width: 92%; }
    body.admin-bar.histora-ai-body .hai-sidebar { top: 46px; height: calc(100vh - 46px); }
}

/* --------------------------------------------------------------------------
   12. Toast (transient feedback for share / copy actions)
   -------------------------------------------------------------------------- */
.histora-ai-body .hai-toast {
    position: fixed;
    bottom: 96px;
    left: 50%;
    transform: translate(-50%, 12px);
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    padding: 10px 18px;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur-base) var(--easing),
                transform var(--dur-base) var(--easing);
    max-width: min(460px, calc(100vw - 48px));
    text-align: center;
}
.histora-ai-body .hai-toast.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* --------------------------------------------------------------------------
   13. "Developed by zaky" credit
   - Bottom-right corner of the input bar (so it never overlaps content)
   - Brand-gradient text with a slow shimmer + gentle float for idle motion
   -------------------------------------------------------------------------- */
.histora-ai-body .hai-credit {
    position: absolute;
    right: 18px;
    bottom: 6px;
    z-index: 5;
    pointer-events: none;
    user-select: none;
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: lowercase;
    line-height: 1;
    will-change: transform;
    animation: hai-credit-float 3.2s ease-in-out infinite;
}

.histora-ai-body .hai-credit__text {
    /* Neutral resting state in both light and dark modes. */
    color: var(--text-hint);
    -webkit-text-fill-color: var(--text-hint);
    will-change: transform, color;
    /* Stays idle most of the cycle, then fires a short cartoon attention burst.
       The wrapper's float keeps running on the parent, so the two compose without
       conflict (this animation only animates the child's own transform). */
    animation: hai-credit-burst 6.5s var(--easing) infinite;
    display: inline-block;
    transform-origin: center;
}

.histora-ai-body .hai-credit__dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--gradient-gemini);
    margin-right: 7px;
    vertical-align: 1px;
    box-shadow: 0 0 10px rgba(155, 89, 182, 0.7);
    animation: hai-credit-dot 1.6s var(--easing) infinite;
}

/* Cartoon attention burst — idle for the bulk of the cycle, then a quick
   shake → bounce → flip sequence cycling through the brand accents. The
   transform is on the child element so it composes with the parent's float. */
@keyframes hai-credit-burst {
    0%, 70% {
        transform: translate(0, 0) rotate(0deg) scale(1);
        color: var(--text-hint);
        -webkit-text-fill-color: var(--text-hint);
    }
    /* shake left-right with rotation */
    72% { transform: translate(-3px, 0) rotate(-10deg) scale(1);
          color: var(--accent-blue); -webkit-text-fill-color: var(--accent-blue); }
    74% { transform: translate( 3px, 0) rotate( 10deg) scale(1);
          color: var(--accent-purple); -webkit-text-fill-color: var(--accent-purple); }
    76% { transform: translate(-3px, 0) rotate(-8deg)  scale(1);
          color: var(--accent-red); -webkit-text-fill-color: var(--accent-red); }
    78% { transform: translate( 2px, 0) rotate( 6deg)  scale(1);
          color: var(--accent-yellow); -webkit-text-fill-color: var(--accent-yellow); }
    /* upward bounce with scale */
    82% { transform: translate(0, -8px) rotate(0deg) scale(1.18);
          color: var(--accent-blue); -webkit-text-fill-color: var(--accent-blue); }
    85% { transform: translate(0, 0)    rotate(0deg) scale(1);
          color: var(--accent-purple); -webkit-text-fill-color: var(--accent-purple); }
    /* horizontal flip / spin */
    89% { transform: translate(0, 0) rotateY(180deg) scale(1.05);
          color: var(--accent-red); -webkit-text-fill-color: var(--accent-red); }
    93% { transform: translate(0, 0) rotateY(360deg) scale(1);
          color: var(--accent-yellow); -webkit-text-fill-color: var(--accent-yellow); }
    /* settle back to the resting state */
    97%, 100% {
        transform: translate(0, 0) rotate(0deg) scale(1);
        color: var(--text-hint);
        -webkit-text-fill-color: var(--text-hint);
    }
}

@keyframes hai-credit-float {
    0%, 100% { transform: translateY(0)    rotate(-0.3deg); }
    50%      { transform: translateY(-4px) rotate( 0.3deg); }
}

@keyframes hai-credit-dot {
    0%, 100% {
        transform: scale(1);
        opacity: 0.85;
        box-shadow: 0 0 6px rgba(155, 89, 182, 0.5);
    }
    50% {
        transform: scale(1.6);
        opacity: 1;
        box-shadow: 0 0 14px rgba(234, 67, 53, 0.8);
    }
}

@media (max-width: 600px) {
    .histora-ai-body .hai-credit { right: 10px; bottom: 4px; font-size: 10px; }
    .histora-ai-body .hai-disclaimer { padding: 0 92px 0 0; }
    /* Hide the SIPURBA pill on narrow viewports — keeps the header from
       crowding next to the theme/share/options icons. */
    .histora-ai-body .hai-sipurba-btn { display: none; }
}

/* --------------------------------------------------------------------------
   14. Reduced motion
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    .histora-ai-body *,
    .histora-ai-body *::before,
    .histora-ai-body *::after {
        animation-duration: 0.001s !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001s !important;
        scroll-behavior: auto !important;
    }
    .histora-ai-body .hai-welcome__icon,
    .histora-ai-body .hai-thinking__avatar,
    .histora-ai-body .hai-thinking__label,
    .histora-ai-body .hai-credit,
    .histora-ai-body .hai-credit__text,
    .histora-ai-body .hai-credit__dot,
    .histora-ai-body .hai-stream-caret { animation: none !important; }
    .histora-ai-body .hai-credit__text { -webkit-text-fill-color: var(--text-hint); color: var(--text-hint); }
}
