#hdai-chat-root,
#hdai-chat-root * {
    box-sizing: border-box;
}

#hdai-chat-root {
    --hdai-green: #26382f;
    --hdai-green-soft: #3f594b;
    --hdai-cream: #f7f4ec;
    --hdai-paper: #ffffff;
    --hdai-gold: #c7a45e;
    --hdai-text: #202721;
    --hdai-muted: #687169;
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
    font-size: 15px;
    line-height: 1.55;
    color: var(--hdai-text);
}

.hdai-launcher {
    position: fixed;
    right: 20px;
    bottom: max(20px, env(safe-area-inset-bottom));
    z-index: 99998;
    width: 72px;
    height: 72px;
    border: 0;
    border-radius: 50%;
    background: var(--hdai-green);
    color: #fff;
    box-shadow: 0 8px 28px rgba(16, 31, 22, .28);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    transition: transform .18s ease, background .18s ease;
}

.hdai-launcher:hover,
.hdai-launcher:focus-visible {
    transform: translateY(-2px);
    background: var(--hdai-green-soft);
}

.hdai-launcher.is-open {
    transform: scale(.92);
}

.hdai-launcher-icon {
    color: var(--hdai-gold);
    font-size: 19px;
    line-height: 1;
}

.hdai-launcher-text {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .04em;
}

.hdai-panel {
    position: fixed;
    right: 20px;
    bottom: 104px;
    z-index: 99999;
    width: min(390px, calc(100vw - 32px));
    height: min(650px, calc(100vh - 132px));
    background: var(--hdai-paper);
    border: 1px solid rgba(38, 56, 47, .14);
    border-radius: 18px;
    box-shadow: 0 18px 54px rgba(16, 31, 22, .25);
    overflow: hidden;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto auto;
    animation: hdai-enter .2s ease-out;
}

.hdai-panel[hidden] {
    display: none;
}

.hdai-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 14px 13px 16px;
    background: var(--hdai-green);
    color: #fff;
}

.hdai-identity {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.hdai-avatar {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--hdai-cream);
    border: 2px solid var(--hdai-gold);
    color: var(--hdai-green);
    font-family: Georgia, serif;
    font-size: 18px;
    font-weight: 700;
}

.hdai-title-wrap {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.hdai-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 15px;
}

.hdai-status {
    color: rgba(255, 255, 255, .72);
    font-size: 11px;
}

.hdai-close {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #fff;
    cursor: pointer;
    font-size: 27px;
    line-height: 1;
}

.hdai-close:hover,
.hdai-close:focus-visible {
    background: rgba(255, 255, 255, .12);
}

.hdai-messages {
    overflow-y: auto;
    padding: 18px 14px 12px;
    background:
        linear-gradient(rgba(247, 244, 236, .92), rgba(247, 244, 236, .92)),
        repeating-linear-gradient(0deg, transparent, transparent 23px, rgba(38, 56, 47, .035) 24px);
    scroll-behavior: smooth;
}

.hdai-message {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    margin: 0 0 13px;
}

.hdai-message.hdai-user {
    align-items: flex-end;
}

.hdai-bubble {
    max-width: 88%;
    padding: 11px 13px;
    border-radius: 14px 14px 14px 4px;
    background: #fff;
    border: 1px solid rgba(38, 56, 47, .12);
    box-shadow: 0 2px 8px rgba(38, 56, 47, .06);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.hdai-user .hdai-bubble {
    border: 0;
    border-radius: 14px 14px 4px 14px;
    background: var(--hdai-green-soft);
    color: #fff;
}

.hdai-bubble a {
    color: #1f5f4a;
    text-decoration: underline;
    overflow-wrap: anywhere;
}

.hdai-error .hdai-bubble {
    border-color: #b85745;
    color: #8f2d1f;
}

.hdai-typing .hdai-bubble {
    color: var(--hdai-muted);
    animation: hdai-pulse 1.2s infinite;
}

.hdai-sources {
    width: 88%;
    margin-top: 7px;
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(255, 255, 255, .74);
    color: var(--hdai-muted);
    font-size: 12px;
}

.hdai-sources summary {
    color: var(--hdai-green);
    cursor: pointer;
    font-weight: 700;
}

.hdai-sources ul {
    margin: 7px 0 0;
    padding-left: 18px;
}

.hdai-sources li {
    margin: 5px 0;
}

.hdai-sources a {
    color: var(--hdai-green);
    text-decoration: underline;
}

.hdai-source-date {
    display: block;
    font-size: 10px;
}

.hdai-disclaimer {
    width: 88%;
    margin: 6px 0 0;
    color: #775b27;
    font-size: 10px;
    line-height: 1.45;
}

.hdai-feedback {
    display: flex;
    gap: 6px;
    margin-top: 7px;
    color: var(--hdai-muted);
    font-size: 11px;
}

.hdai-feedback button {
    border: 1px solid rgba(38, 56, 47, .24);
    border-radius: 999px;
    background: #fff;
    color: var(--hdai-green);
    padding: 4px 8px;
    cursor: pointer;
    font-size: 11px;
}

.hdai-quick {
    display: flex;
    gap: 7px;
    overflow-x: auto;
    padding: 9px 12px 5px;
    background: #fff;
    scrollbar-width: none;
}

.hdai-quick::-webkit-scrollbar {
    display: none;
}

.hdai-chip {
    flex: 0 0 auto;
    border: 1px solid rgba(38, 56, 47, .25);
    border-radius: 999px;
    background: var(--hdai-cream);
    color: var(--hdai-green);
    padding: 6px 10px;
    cursor: pointer;
    font-size: 12px;
}

.hdai-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: end;
    padding: 8px 12px 7px;
    background: #fff;
}

.hdai-input {
    width: 100%;
    min-height: 42px;
    max-height: 108px;
    resize: vertical;
    border: 1px solid rgba(38, 56, 47, .28);
    border-radius: 10px;
    padding: 9px 10px;
    color: var(--hdai-text);
    background: #fff;
    font: inherit;
}

.hdai-input:focus {
    outline: 2px solid rgba(199, 164, 94, .55);
    outline-offset: 1px;
    border-color: var(--hdai-gold);
}

.hdai-send {
    min-height: 42px;
    border: 0;
    border-radius: 10px;
    padding: 0 14px;
    background: var(--hdai-green);
    color: #fff;
    cursor: pointer;
    font-weight: 700;
}

.hdai-send:disabled {
    opacity: .55;
    cursor: wait;
}

.hdai-privacy {
    margin: 0;
    padding: 0 12px 6px;
    color: var(--hdai-muted);
    background: #fff;
    font-size: 9px;
    line-height: 1.35;
}

.hdai-footer-links {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    padding: 6px 12px 10px;
    background: #fff;
    border-top: 1px solid rgba(38, 56, 47, .08);
    font-size: 11px;
}

.hdai-footer-links a {
    color: var(--hdai-green);
    text-decoration: underline;
}

@keyframes hdai-enter {
    from { opacity: 0; transform: translateY(10px) scale(.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes hdai-pulse {
    0%, 100% { opacity: .55; }
    50% { opacity: 1; }
}

@media (max-width: 640px) {
    .hdai-launcher {
        right: 14px;
        bottom: max(14px, env(safe-area-inset-bottom));
        width: 66px;
        height: 66px;
    }

    .hdai-panel {
        inset: 0;
        width: 100%;
        height: 100%;
        max-width: none;
        max-height: none;
        border: 0;
        border-radius: 0;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .hdai-header {
        padding-top: max(13px, env(safe-area-inset-top));
    }

    .hdai-bubble,
    .hdai-sources,
    .hdai-disclaimer {
        max-width: 92%;
        width: 92%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .hdai-panel,
    .hdai-launcher,
    .hdai-typing .hdai-bubble {
        animation: none;
        transition: none;
    }
}
