.acla-chat-widget {
    --acla-chat-ink: #141413;
    --acla-chat-surface: #faf9f6;
    --acla-chat-paper: #fffdf8;
    --acla-chat-muted: #5f5a52;
    --acla-chat-line: #d8d2c8;
    --acla-chat-accent: #a94f2c;
    --acla-chat-success: #17643a;
    --acla-chat-danger: #a12d2d;
    color: var(--acla-chat-ink);
    font: inherit;
}
.acla-chat-widget,
.acla-chat-widget * { box-sizing: border-box; }
.acla-chat-widget [hidden] { display: none !important; }
.acla-chat-widget .screen-reader-text { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.acla-chat-launcher {
    position: fixed;
    right: max(24px, env(safe-area-inset-right));
    bottom: max(24px, env(safe-area-inset-bottom));
    z-index: 9998;
    display: inline-flex;
    min-height: 52px;
    align-items: center;
    gap: 10px;
    padding: 0 18px;
    border: 1px solid var(--acla-chat-ink);
    border-radius: 0 0 16px 16px;
    background: var(--acla-chat-ink);
    color: var(--acla-chat-surface);
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
}
.acla-chat-launcher:hover { background: #2b2b29; color: var(--acla-chat-surface); text-decoration: underline; text-underline-offset: 3px; }
.acla-chat-launcher:focus-visible,
.acla-chat-close:focus-visible,
.acla-chat-form textarea:focus-visible,
.acla-chat-send:focus-visible,
.acla-chat-retry:focus-visible,
.acla-message-system a:focus-visible { outline: 3px solid var(--acla-chat-accent); outline-offset: 2px; }
.acla-chat-launcher-icon { width: 22px; height: 22px; flex: 0 0 auto; }
.acla-chat-launcher.is-working .acla-chat-launcher-icon { opacity: .3; }
.acla-chat-launcher.is-working::before {
    position: absolute;
    left: 19px;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(250, 249, 246, .35);
    border-top-color: var(--acla-chat-surface);
    border-radius: 50%;
    content: "";
    animation: acla-spin .8s linear infinite;
}
.acla-chat-launcher.is-error { background: var(--acla-chat-danger); }
.acla-chat-unread { width: 9px; height: 9px; border: 2px solid var(--acla-chat-ink); border-radius: 50%; background: var(--acla-chat-accent); }
.acla-chat-panel {
    position: fixed;
    right: max(24px, env(safe-area-inset-right));
    bottom: calc(88px + env(safe-area-inset-bottom));
    z-index: 9997;
    display: flex;
    width: min(400px, calc(100vw - 32px));
    max-height: calc(100vh - 104px);
    max-height: calc(100dvh - 104px);
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--acla-chat-ink);
    background: var(--acla-chat-surface);
}
.acla-chat-header { display: flex; min-height: 72px; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 16px 12px 20px; background: var(--acla-chat-ink); color: var(--acla-chat-surface); }
.acla-chat-header h2 { margin: 0; color: inherit; font: inherit; font-size: 18px; font-weight: 700; line-height: 1.2; }
.acla-chat-presence { display: flex; align-items: center; gap: 7px; margin: 5px 0 0; color: #d8d5ce; font-size: 12px; line-height: 1; }
.acla-chat-presence span { width: 7px; height: 7px; border-radius: 50%; background: #d79a78; }
.acla-chat-presence b { font: inherit; }
.acla-chat-presence.is-working span { background: #d79a78; }
.acla-chat-presence.is-error span { background: #ef8f8f; }
.acla-chat-presence:not(.is-working):not(.is-error) span { background: #72a989; }
.acla-chat-close { display: inline-grid; width: 44px; height: 44px; flex: 0 0 auto; place-items: center; padding: 0; border: 1px solid #4a4946; background: transparent; color: var(--acla-chat-surface); cursor: pointer; }
.acla-chat-close:hover { border-color: var(--acla-chat-surface); background: #2b2b29; color: var(--acla-chat-surface); }
.acla-chat-close svg { width: 22px; height: 22px; }
.acla-chat-log { display: flex; min-height: 180px; flex: 1 1 auto; flex-direction: column; gap: 12px; overflow-y: auto; overscroll-behavior: contain; padding: 16px; }
.acla-message { max-width: 86%; padding: 10px 12px; border: 1px solid var(--acla-chat-line); white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.45; }
.acla-message-user { align-self: flex-end; border-color: var(--acla-chat-ink); background: var(--acla-chat-ink); color: var(--acla-chat-surface); }
.acla-message-assistant { align-self: flex-start; background: var(--acla-chat-paper); color: var(--acla-chat-ink); }
.acla-message-system { align-self: stretch; max-width: none; border-color: #afd3bd; background: #eef8f1; color: var(--acla-chat-success); }
.acla-message-system a { display: block; width: fit-content; margin-top: 6px; color: var(--acla-chat-ink); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.acla-working { margin: 0; padding: 0 16px 10px; color: var(--acla-chat-muted); font-size: 13px; }
.acla-working::before { display: inline-block; width: 10px; height: 10px; margin-right: 7px; border: 2px solid var(--acla-chat-line); border-top-color: var(--acla-chat-accent); border-radius: 50%; content: ""; animation: acla-spin .8s linear infinite; }
.acla-chat-status { padding: 0 16px 10px; }
.acla-chat-status:empty { display: none; }
.acla-chat-info { margin: 0; color: var(--acla-chat-muted); font-size: 13px; }
.acla-chat-error { padding: 10px; border: 1px solid #d5aaa0; background: #fff7f4; color: var(--acla-chat-danger); font-size: 13px; line-height: 1.4; }
.acla-chat-error p { margin: 0 0 8px; }
.acla-chat-retry { min-height: 36px; padding: 6px 10px; border: 1px solid currentColor; background: transparent; color: inherit; font: inherit; font-weight: 700; cursor: pointer; }
.acla-chat-form { display: grid; flex: 0 0 auto; grid-template-columns: minmax(0, 1fr) 94px; gap: 8px; padding: 12px 16px 16px; border-top: 1px solid var(--acla-chat-line); background: var(--acla-chat-surface); }
.acla-chat-form textarea { width: 100%; min-height: 72px; max-height: 150px; resize: vertical; border: 1px solid #8c867e; border-radius: 0; background: var(--acla-chat-paper); color: var(--acla-chat-ink); font: inherit; font-size: 14px; line-height: 1.4; }
.acla-chat-form textarea::placeholder { color: #6c665e; opacity: 1; }
.acla-chat-form textarea:disabled { background: #eeeae2; color: var(--acla-chat-muted); }
.acla-chat-send { min-height: 44px; align-self: stretch; padding: 8px 14px; border: 1px solid var(--acla-chat-ink); border-radius: 0 0 12px 12px; background: var(--acla-chat-ink); color: var(--acla-chat-surface); font: inherit; font-size: 14px; font-weight: 700; cursor: pointer; }
.acla-chat-send:hover { background: #2b2b29; color: var(--acla-chat-surface); text-decoration: underline; text-underline-offset: 3px; }
.acla-chat-send:disabled { cursor: wait; opacity: .55; }
@keyframes acla-spin { to { transform: rotate(360deg); } }
@media (max-width: 640px) {
    .acla-chat-launcher { right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); }
    .acla-chat-panel { top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); bottom: calc(80px + env(safe-area-inset-bottom)); left: max(12px, env(safe-area-inset-left)); width: auto; max-height: none; }
    body.admin-bar .acla-chat-panel { top: calc(58px + env(safe-area-inset-top)); }
    .acla-chat-log { min-height: 0; padding: 14px; }
    .acla-chat-form { grid-template-columns: 1fr; padding: 10px 14px 14px; }
    .acla-chat-send { min-height: 46px; }
}
@media (prefers-reduced-motion: reduce) {
    .acla-chat-launcher.is-working::before,
    .acla-working::before { animation: none; }
}
@media (forced-colors: active) {
    .acla-chat-launcher,
    .acla-chat-panel,
    .acla-chat-close,
    .acla-chat-form textarea,
    .acla-chat-send,
    .acla-chat-retry { border: 1px solid CanvasText; }
}
