.essayfi-widget-dock {
    position: fixed;
    z-index: 150;
    right: 22px;
    bottom: 22px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.essayfi-theme-toggle,
.essayfi-chat-launcher {
    min-height: 50px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    background: var(--bg-elevated);
    color: var(--text-primary);
    box-shadow: 0 10px 28px rgb(32 33 36 / 16%);
    cursor: pointer;
    transition: transform 160ms ease, background 160ms ease, color 160ms ease;
}

.essayfi-theme-toggle:hover,
.essayfi-chat-launcher:hover {
    transform: translateY(-2px);
}

.essayfi-theme-toggle {
    width: 50px;
    padding: 0;
}

.essayfi-theme-toggle svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.essayfi-theme-toggle__moon,
html[data-theme="dark"] .essayfi-theme-toggle__sun {
    display: none;
}

html[data-theme="dark"] .essayfi-theme-toggle__moon {
    display: block;
}

.essayfi-chat-launcher {
    padding: 0 19px;
    border-color: var(--essayfi-teal);
    background: var(--essayfi-teal);
    color: #FFFFFF;
    font-size: 0.86rem;
    font-weight: 800;
}

.essayfi-chat-launcher:hover {
    background: #075E6B;
}

.essayfi-chat-launcher svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.essayfi-chat-launcher[aria-expanded="true"] {
    background: var(--essayfi-ink);
    border-color: var(--essayfi-ink);
}

.essayfi-chat-panel {
    position: fixed;
    z-index: 149;
    right: 22px;
    bottom: 84px;
    width: min(400px, calc(100vw - 28px));
    height: min(620px, calc(100dvh - 120px));
    min-height: 360px;
    overflow: hidden;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    border: 1px solid var(--border-strong);
    border-radius: 16px;
    background: var(--bg-primary);
    color: var(--text-primary);
    box-shadow: 0 24px 80px rgb(21 19 17 / 25%);
    opacity: 1;
    transform: translateY(0) scale(1);
    transform-origin: right bottom;
    transition: opacity 180ms ease, transform 180ms ease;
}

.essayfi-chat-panel[hidden] {
    display: none;
}

.essayfi-chat-panel__header {
    min-height: 72px;
    padding: 13px 17px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    background: var(--essayfi-ink);
    color: var(--essayfi-ivory);
}

.essayfi-chat-panel__identity {
    display: flex;
    align-items: center;
    gap: 11px;
}

.essayfi-chat-panel__identity strong,
.essayfi-chat-panel__identity small {
    display: block;
}

.essayfi-chat-panel__identity strong {
    font-size: 0.96rem;
}

.essayfi-chat-panel__identity small {
    margin-top: 3px;
    color: rgb(247 243 234 / 73%);
    font-size: 0.7rem;
}

.essayfi-chat-panel__identity small i {
    width: 7px;
    height: 7px;
    margin-right: 4px;
    display: inline-block;
    border-radius: 50%;
    background: #9DC58A;
}

.essayfi-chat-panel__avatar {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--essayfi-teal);
    color: #FFFFFF;
    font-family: "Cabin Condensed", sans-serif;
    font-size: 1.55rem;
    font-weight: 700;
}

.essayfi-chat-panel__close {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border: 1px solid rgb(247 243 234 / 25%);
    border-radius: 50%;
    background: transparent;
    color: var(--essayfi-ivory);
    font-size: 1.45rem;
    cursor: pointer;
}

.essayfi-chat-panel__close:hover {
    background: rgb(247 243 234 / 12%);
}

.essayfi-chat-panel__body {
    min-height: 0;
    overflow: auto;
    padding: 18px;
}

.essayfi-chat-welcome {
    padding: 17px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-elevated);
}

.essayfi-chat-welcome__eyebrow {
    color: var(--essayfi-teal);
    font-size: 0.6rem;
    font-weight: 800;
    letter-spacing: 0.1em;
}

.essayfi-chat-welcome h2 {
    margin: 8px 0;
    font-size: 1.14rem;
    letter-spacing: -0.04em;
}

.essayfi-chat-welcome p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.79rem;
    line-height: 1.6;
}

.essayfi-chat-status {
    margin: 13px 2px 0;
    color: var(--text-muted);
    font-size: 0.75rem;
}

.essayfi-chat-status:empty {
    display: none;
}

.essayfi-chat-status.is-error {
    padding: 11px 12px;
    border: 1px solid rgb(8 127 140 / 28%);
    border-radius: 7px;
    background: rgb(8 127 140 / 7%);
    color: var(--text-primary);
    line-height: 1.55;
}

.essayfi-chat-status a {
    color: var(--essayfi-teal);
    font-weight: 800;
}

.essayfi-chat-messages {
    margin-top: 14px;
    display: grid;
    align-content: end;
    gap: 9px;
}

.essayfi-chat-message {
    max-width: 86%;
    justify-self: start;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px 12px 12px;
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-size: 0.82rem;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.essayfi-chat-message.is-outgoing {
    justify-self: end;
    border-color: var(--essayfi-teal);
    border-radius: 12px 4px 12px 12px;
    background: var(--essayfi-teal);
    color: #FFFFFF;
}

.essayfi-chat-message__time {
    margin-top: 5px;
    display: block;
    color: var(--text-muted);
    font-size: 0.61rem;
    text-align: right;
}

.essayfi-chat-message.is-outgoing .essayfi-chat-message__time {
    color: rgb(255 255 255 / 78%);
}

.essayfi-chat-composer {
    position: relative;
    padding: 12px 14px 29px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 42px;
    align-items: end;
    gap: 9px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-elevated);
}

.essayfi-chat-composer > label.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
    clip-path: inset(50%);
}

.essayfi-chat-composer textarea {
    grid-column: 1;
    grid-row: 1;
    width: 100%;
    min-width: 0;
    max-height: 112px;
    min-height: 42px;
    padding: 11px 12px;
    resize: none;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    outline: 0;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.81rem;
    line-height: 1.45;
}

.essayfi-chat-composer > button {
    grid-column: 2;
    grid-row: 1;
}

.essayfi-chat-composer textarea:focus {
    border-color: var(--essayfi-teal);
    box-shadow: 0 0 0 3px rgb(8 127 140 / 10%);
}

.essayfi-chat-composer button {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 8px;
    background: var(--essayfi-teal);
    color: #FFFFFF;
    cursor: pointer;
}

.essayfi-chat-composer button:disabled {
    background: #A7A19B;
    cursor: not-allowed;
}

.essayfi-chat-composer button svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.essayfi-chat-composer__hint {
    position: absolute;
    bottom: 8px;
    left: 17px;
    color: var(--text-muted);
    font-size: 0.59rem;
}

html[data-theme="dark"] .essayfi-chat-panel {
    border-color: #4B4C51;
}

html[data-theme="dark"] .essayfi-chat-panel__header {
    background: #17181A;
    color: #F7F3EA;
}

html[data-theme="dark"] .site-header {
    background: rgb(32 33 36 / 96%);
    border-color: var(--border-color);
}

html[data-theme="dark"] .site-header__announcement {
    background: #17181A;
    color: #F7F3EA;
}

html[data-theme="dark"] .site-nav__link {
    color: var(--text-primary);
}

html[data-theme="dark"] .site-nav {
    border-color: var(--border-color);
    background: var(--bg-primary);
}

html[data-theme="dark"] .site-menu-toggle {
    border-color: var(--border-color);
    background: var(--bg-elevated);
}

html[data-theme="dark"] .site-menu-toggle__line {
    background: var(--text-primary);
}

html[data-theme="dark"] .site-header .site-brand,
html[data-theme="dark"] .site-header .brand-name,
html[data-theme="dark"] .site-footer .site-brand,
html[data-theme="dark"] .site-footer .brand-name {
    color: var(--text-primary);
}

html[data-theme="dark"] .site-header .brand-fi,
html[data-theme="dark"] .site-footer .brand-fi {
    color: #20B8C5;
}

html[data-theme="dark"] .brand-fi::before {
    background: #20B8C5;
}

html[data-theme="dark"] .brand-fi::after {
    background: var(--text-primary);
}

html[data-theme="dark"] .site-footer {
    border-color: var(--border-color);
    background: #252629;
    color: var(--text-primary);
}

html[data-theme="dark"] .site-footer__description,
html[data-theme="dark"] .site-footer__open-access,
html[data-theme="dark"] .site-footer__links a,
html[data-theme="dark"] .site-footer__contact > p,
html[data-theme="dark"] .site-footer__bottom-inner {
    color: var(--text-muted);
}

html[data-theme="dark"] .site-nav__link[aria-current="location"],
html[data-theme="dark"] .site-footer__links a[aria-current="location"] {
    color: var(--essayfi-teal);
}

html[data-theme="dark"] .site-footer__heading,
html[data-theme="dark"] .site-footer__email,
html[data-theme="dark"] .site-footer__back-to-top {
    color: var(--text-primary);
}

html[data-theme="dark"] .site-footer__bottom,
html[data-theme="dark"] .site-footer__email-icon {
    border-color: var(--border-color);
}

html[data-theme="dark"] .site-footer .btn-secondary {
    color: var(--text-primary);
}

html[data-theme="dark"] .site-footer .btn-secondary:hover {
    background: var(--bg-elevated);
}

@media (max-width: 520px) {
    .essayfi-widget-dock {
        right: 14px;
        bottom: 14px;
        gap: 8px;
    }

    .essayfi-theme-toggle {
        width: 46px;
        min-height: 46px;
    }

    .essayfi-chat-launcher {
        min-height: 46px;
        padding: 0 14px;
        font-size: 0.78rem;
    }

    .essayfi-chat-panel {
        right: 10px;
        bottom: 70px;
        width: calc(100vw - 20px);
        height: min(640px, calc(100dvh - 84px));
        min-height: 340px;
        border-radius: 13px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .essayfi-theme-toggle,
    .essayfi-chat-launcher,
    .essayfi-chat-panel {
        transition: none;
    }
}
