/* Shared history controls also work before the full chat app is loaded. */
:root {
    --fuuvo-history-action-color: #65758c;
    --fuuvo-history-action-hover: #edf3fc;
    --fuuvo-history-action-active: #e5efff;
    --fuuvo-history-focus: #2563eb;
    --fuuvo-history-menu-bg: #ffffff;
    --fuuvo-history-menu-text: #273447;
    --fuuvo-history-menu-border: #dce4ef;
    --fuuvo-history-menu-shadow: 0 12px 36px rgba(24, 39, 62, .18);
    --fuuvo-history-danger: #c62535;
    --fuuvo-history-danger-hover: #fff0f1;
}

html[data-ui-theme="dark"],
body[data-ui-theme="dark"] {
    --fuuvo-history-action-color: #a8b8ce;
    --fuuvo-history-action-hover: #26364b;
    --fuuvo-history-action-active: #294365;
    --fuuvo-history-focus: #8fc1ff;
    --fuuvo-history-menu-bg: #1c2736;
    --fuuvo-history-menu-text: #e0e8f4;
    --fuuvo-history-menu-border: #3a485b;
    --fuuvo-history-menu-shadow: 0 12px 36px rgba(0, 0, 0, .4);
    --fuuvo-history-danger: #ff929a;
    --fuuvo-history-danger-hover: #422a36;
}

/* Later page styles must not make the action depend on hover. */
html body .fuuvo-history-more,
html body aside[data-fuuvo-shared-sidebar="1"] .fuuvo-history-more,
html body aside[data-fuuvo-shared-sidebar="1"] .conversation-more-btn {
    box-sizing: border-box !important;
    position: relative !important;
    width: 28px !important;
    height: 28px !important;
    min-width: 28px !important;
    min-height: 28px !important;
    max-width: 28px !important;
    max-height: 28px !important;
    margin: 0 !important;
    padding: 0 !important;
    display: inline-flex !important;
    flex: 0 0 28px !important;
    align-items: center !important;
    justify-content: center !important;
    border: 0 !important;
    border-radius: 8px !important;
    background: transparent !important;
    color: var(--fuuvo-history-action-color) !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    cursor: pointer !important;
    touch-action: manipulation;
}

html body .fuuvo-history-more svg,
html body aside[data-fuuvo-shared-sidebar="1"] .fuuvo-history-more svg {
    width: 18px !important;
    height: 18px !important;
    display: block !important;
    flex: 0 0 18px !important;
    pointer-events: none;
}

html body .fuuvo-history-more:is(:hover, :active, [aria-expanded="true"]),
html body aside[data-fuuvo-shared-sidebar="1"] .fuuvo-history-more:is(:hover, :active, [aria-expanded="true"]),
html body aside[data-fuuvo-shared-sidebar="1"] .conversation-more-btn:is(:hover, :active, [aria-expanded="true"]) {
    background: var(--fuuvo-history-action-hover) !important;
}

html body .fuuvo-history-more:focus-visible,
html body aside[data-fuuvo-shared-sidebar="1"] .fuuvo-history-more:focus-visible,
html body aside[data-fuuvo-shared-sidebar="1"] .conversation-more-btn:focus-visible {
    outline: 2px solid var(--fuuvo-history-focus) !important;
    outline-offset: 1px !important;
    background: var(--fuuvo-history-action-active) !important;
}

html body .fuuvo-history-more:disabled,
html body aside[data-fuuvo-shared-sidebar="1"] .fuuvo-history-more:disabled {
    cursor: wait !important;
    opacity: .6 !important;
}

/* The record link and its action are siblings, including search results. */
html body .fuuvo-shell-search-results .fuuvo-history-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 32px;
    align-items: center;
    gap: 4px;
    min-width: 0;
    padding-right: 6px;
    border-radius: 12px;
}

html body .fuuvo-shell-search-results .fuuvo-history-row > a {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    background: transparent !important;
}

html body .fuuvo-shell-search-results .fuuvo-history-row:is(:hover, :focus-within) {
    background: var(--fuuvo-history-action-hover);
}

html body aside[data-fuuvo-shared-sidebar="1"] .conversation-list .conversation-item.fuuvo-history-item {
    box-sizing: border-box !important;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) 28px !important;
    align-items: center !important;
    gap: 4px !important;
    padding: 2px 6px 2px 8px !important;
}

html body aside[data-fuuvo-shared-sidebar="1"] .conversation-item.fuuvo-history-item > .fuuvo-history-link {
    box-sizing: border-box !important;
    display: block !important;
    min-width: 0 !important;
    min-height: 32px !important;
    padding: 4px 0 !important;
    overflow: hidden !important;
    color: inherit !important;
    text-decoration: none !important;
    border: 0 !important;
    border-radius: 6px;
    background: transparent !important;
}

html body aside[data-fuuvo-shared-sidebar="1"] .conversation-item.fuuvo-history-item .conversation-head {
    display: grid !important;
    grid-template-columns: 20px minmax(0, 1fr) auto !important;
    align-items: center !important;
    gap: 7px !important;
    width: 100% !important;
    min-width: 0 !important;
}

html body aside[data-fuuvo-shared-sidebar="1"] .portal-recent-item > .fuuvo-history-more {
    margin-right: 6px !important;
}

/* Both native manual popovers and the body-level fallback use JS coordinates. */
html body .fuuvo-history-menu {
    box-sizing: border-box !important;
    position: fixed !important;
    inset: auto;
    z-index: 100001 !important;
    width: max-content;
    min-width: min(176px, calc(100vw - 16px));
    max-width: calc(100vw - 16px);
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
    margin: 0 !important;
    padding: 6px !important;
    display: grid;
    gap: 2px;
    overflow: auto;
    overscroll-behavior: contain;
    border: 1px solid var(--fuuvo-history-menu-border) !important;
    border-radius: 12px !important;
    background: var(--fuuvo-history-menu-bg) !important;
    color: var(--fuuvo-history-menu-text) !important;
    box-shadow: var(--fuuvo-history-menu-shadow) !important;
    font: inherit;
    line-height: 1.4;
    text-align: left;
    pointer-events: auto !important;
}

html body .fuuvo-history-menu[hidden] {
    display: none !important;
}

@supports selector(:popover-open) {
    html body .fuuvo-history-menu[popover]:not(:popover-open) {
        display: none !important;
    }
}

html body .fuuvo-history-menu::backdrop {
    background: transparent;
}

html body .fuuvo-history-menu [role="menuitem"] {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    min-width: 0;
    min-height: 36px;
    margin: 0;
    padding: 8px 11px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 14px;
    line-height: 1.4;
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
    cursor: pointer;
}

html body .fuuvo-history-menu [role="menuitem"] svg {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
}

html body .fuuvo-history-menu [role="menuitem"]:is(:hover, :focus-visible) {
    background: var(--fuuvo-history-action-hover);
}

html body .fuuvo-history-menu [role="menuitem"]:focus-visible {
    outline: 2px solid var(--fuuvo-history-focus);
    outline-offset: -2px;
}

html body .fuuvo-history-menu [role="menuitem"].is-danger {
    color: var(--fuuvo-history-danger);
}

html body .fuuvo-history-menu [role="menuitem"].is-danger:is(:hover, :focus-visible) {
    background: var(--fuuvo-history-danger-hover);
}

@media (max-width: 920px) {
    /* The full chat renderer keeps its action inside conversation-head.
     * Reserve that track independently of long titles and relative times. */
    html body aside#workspace-more-drawer[data-fuuvo-shared-sidebar="1"] .conversation-list .conversation-item:not(.fuuvo-history-item) .conversation-head {
        min-width: 0 !important;
        grid-template-columns: 24px minmax(0, 1fr) auto 36px !important;
    }

    html body aside#workspace-more-drawer[data-fuuvo-shared-sidebar="1"] .conversation-title-wrap {
        min-width: 0 !important;
        overflow: hidden !important;
    }

    html body aside#workspace-more-drawer[data-fuuvo-shared-sidebar="1"] .conversation-actions,
    html body aside#workspace-more-drawer[data-fuuvo-shared-sidebar="1"] .conversation-more-btn {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        min-height: 36px !important;
        max-width: 36px !important;
        max-height: 36px !important;
        display: inline-flex !important;
        flex: 0 0 36px !important;
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
    }

    html body .fuuvo-history-more,
    html body aside[data-fuuvo-shared-sidebar="1"] .fuuvo-history-more {
        width: 32px !important;
        height: 32px !important;
        min-width: 32px !important;
        min-height: 32px !important;
        max-width: 32px !important;
        max-height: 32px !important;
        flex-basis: 32px !important;
    }

    html body aside[data-fuuvo-shared-sidebar="1"] .conversation-list .conversation-item.fuuvo-history-item {
        grid-template-columns: minmax(0, 1fr) 32px !important;
    }

    html body .fuuvo-history-menu [role="menuitem"] {
        min-height: 40px;
    }
}
