/* ═══════════════════════════════════════════════════════════════
   LDD AI Chat Widget — v1.0.0
   Palette: --sand #CB9C73 · --sage #6A8F70 · --dark #1A1817 · --cream #FAF8F5
   ═══════════════════════════════════════════════════════════════ */

:root {
    --ldd-c-sand:         #CB9C73;
    --ldd-c-sand-light:   #DDB896;
    --ldd-c-sand-dark:    #A87A52;
    --ldd-c-sage:         #6A8F70;
    --ldd-c-sage-dark:    #4A6B50;
    --ldd-c-dark:         #1A1817;
    --ldd-c-dark-80:      rgba(26,24,23,.8);
    --ldd-c-cream:        #FAF8F5;
    --ldd-c-cream-2:      #F2EDE6;
    --ldd-c-muted:        #8A8070;
    --ldd-c-border:       #E4DDD4;
    --ldd-c-white:        #ffffff;
    --ldd-c-user-bg:      #CB9C73;
    --ldd-c-user-text:    #ffffff;
    --ldd-c-ai-bg:        #F2EDE6;
    --ldd-c-ai-text:      #1A1817;
    --ldd-shadow-sm:      0 2px 8px rgba(26,24,23,.10);
    --ldd-shadow-md:      0 8px 32px rgba(26,24,23,.14);
    --ldd-shadow-lg:      0 16px 56px rgba(26,24,23,.18);
    --ldd-radius:         16px;
    --ldd-radius-msg:     14px;
    --ldd-z:              99998;
}

/* ── Wrap ──────────────────────────────────────────────────────────────── */
#ldd-chat-wrap {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: var(--ldd-z);
    font-family: 'Montserrat', 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
}

/* ── Bubble button ─────────────────────────────────────────────────────── */
#ldd-chat-bubble {
    position: relative;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: var(--ldd-c-sand);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--ldd-shadow-md);
    transition: transform .25s cubic-bezier(.34,1.56,.64,1),
                box-shadow .25s ease,
                background .2s ease;
    outline: none;
}

#ldd-chat-bubble:hover {
    background: var(--ldd-c-sand-dark);
    box-shadow: var(--ldd-shadow-lg);
    transform: scale(1.07);
}

#ldd-chat-bubble:focus-visible {
    outline: 3px solid var(--ldd-c-sage);
    outline-offset: 3px;
}

.ldd-chat-bubble-icon {
    position: absolute;
    color: var(--ldd-c-white);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity .2s ease, transform .2s ease;
}

.ldd-chat-bubble-icon svg {
    width: 24px;
    height: 24px;
}

.ldd-chat-bubble-icon--close {
    opacity: 0;
    transform: rotate(-90deg) scale(.7);
}

#ldd-chat-wrap.is-open .ldd-chat-bubble-icon--open {
    opacity: 0;
    transform: rotate(90deg) scale(.7);
}

#ldd-chat-wrap.is-open .ldd-chat-bubble-icon--close {
    opacity: 1;
    transform: rotate(0) scale(1);
}

/* ── Notification dot ──────────────────────────────────────────────────── */
.ldd-chat-notif {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: var(--ldd-c-sage);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
    letter-spacing: 0;
    box-shadow: 0 2px 6px rgba(0,0,0,.2);
    transition: transform .3s cubic-bezier(.34,1.56,.64,1), opacity .3s ease;
}

.ldd-chat-notif.is-hidden {
    opacity: 0;
    transform: scale(0);
    pointer-events: none;
}

/* ── Panel ─────────────────────────────────────────────────────────────── */
#ldd-chat-panel {
    position: absolute;
    bottom: 74px;
    right: 0;
    width: 360px;
    max-height: 540px;
    background: var(--ldd-c-cream);
    border: 1px solid var(--ldd-c-border);
    border-radius: var(--ldd-radius);
    box-shadow: var(--ldd-shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transform: scale(.92) translateY(8px);
    opacity: 0;
    pointer-events: none;
    transition: transform .28s cubic-bezier(.34,1.2,.64,1),
                opacity .22s ease;
}

#ldd-chat-wrap.is-open #ldd-chat-panel {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: all;
}

/* ── Header ────────────────────────────────────────────────────────────── */
.ldd-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--ldd-c-dark);
    flex-shrink: 0;
}

.ldd-chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ldd-chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,.08);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ldd-chat-avatar svg {
    width: 36px;
    height: 36px;
}

.ldd-chat-header-title {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: 17px;
    font-weight: 600;
    color: var(--ldd-c-sand-light);
    line-height: 1.2;
    letter-spacing: .01em;
}

.ldd-chat-header-sub {
    font-size: 10px;
    color: rgba(255,255,255,.45);
    letter-spacing: .05em;
    text-transform: uppercase;
    margin-top: 2px;
}

.ldd-chat-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255,255,255,.08);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,.6);
    transition: background .2s, color .2s;
    flex-shrink: 0;
}

.ldd-chat-close:hover {
    background: rgba(255,255,255,.15);
    color: #fff;
}

.ldd-chat-close svg {
    width: 16px;
    height: 16px;
}

/* ── Messages ──────────────────────────────────────────────────────────── */
.ldd-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

.ldd-chat-messages::-webkit-scrollbar {
    width: 4px;
}
.ldd-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.ldd-chat-messages::-webkit-scrollbar-thumb {
    background: var(--ldd-c-border);
    border-radius: 4px;
}

/* Message bubble */
.ldd-msg {
    max-width: 88%;
    padding: 10px 13px;
    border-radius: var(--ldd-radius-msg);
    line-height: 1.55;
    font-size: 13.5px;
    word-break: break-word;
    animation: lddMsgIn .22s ease forwards;
    opacity: 0;
}

@keyframes lddMsgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.ldd-msg--user {
    background: var(--ldd-c-user-bg);
    color: var(--ldd-c-user-text);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.ldd-msg--ai {
    background: var(--ldd-c-white);
    color: var(--ldd-c-ai-text);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border: 1px solid var(--ldd-c-border);
    box-shadow: var(--ldd-shadow-sm);
}

/* Links in AI messages */
.ldd-msg--ai a {
    color: var(--ldd-c-sage-dark);
    text-decoration: underline;
    text-underline-offset: 2px;
    font-weight: 500;
}
.ldd-msg--ai a:hover {
    color: var(--ldd-c-dark);
}

/* Welcome message */
.ldd-msg--welcome {
    background: linear-gradient(135deg, var(--ldd-c-cream-2), var(--ldd-c-cream));
    border: 1px solid var(--ldd-c-border);
    border-left: 3px solid var(--ldd-c-sand);
    border-radius: var(--ldd-radius-msg);
    border-bottom-left-radius: 4px;
    box-shadow: none;
}

/* Typing indicator */
.ldd-msg--typing {
    background: var(--ldd-c-white);
    border: 1px solid var(--ldd-c-border);
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    padding: 12px 16px;
}

.ldd-typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}

.ldd-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ldd-c-sand);
    animation: lddDot 1.2s ease infinite;
}
.ldd-typing-dots span:nth-child(2) { animation-delay: .18s; }
.ldd-typing-dots span:nth-child(3) { animation-delay: .36s; }

@keyframes lddDot {
    0%, 80%, 100% { transform: scale(.7); opacity: .4; }
    40%           { transform: scale(1);  opacity: 1; }
}

/* Limit banner */
.ldd-chat-limit {
    text-align: center;
    font-size: 12px;
    color: var(--ldd-c-muted);
    padding: 8px 12px;
    background: var(--ldd-c-cream-2);
    border-radius: 8px;
    border: 1px solid var(--ldd-c-border);
    align-self: center;
    max-width: 100%;
}

/* ── Footer / Input ────────────────────────────────────────────────────── */
.ldd-chat-footer {
    padding: 12px 14px 10px;
    background: var(--ldd-c-white);
    border-top: 1px solid var(--ldd-c-border);
    flex-shrink: 0;
}

.ldd-chat-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--ldd-c-cream);
    border: 1px solid var(--ldd-c-border);
    border-radius: 12px;
    padding: 8px 8px 8px 12px;
    transition: border-color .2s, box-shadow .2s;
}

.ldd-chat-input-wrap:focus-within {
    border-color: var(--ldd-c-sand);
    box-shadow: 0 0 0 3px rgba(203,156,115,.12);
}

.ldd-chat-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-family: inherit;
    font-size: 13.5px;
    color: var(--ldd-c-dark);
    line-height: 1.5;
    max-height: 96px;
    outline: none;
    padding: 0;
}

.ldd-chat-input::placeholder {
    color: var(--ldd-c-muted);
}

.ldd-chat-send {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: var(--ldd-c-sage);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
    transition: background .2s ease, transform .15s ease, opacity .2s;
}

.ldd-chat-send:hover:not(:disabled) {
    background: var(--ldd-c-sage-dark);
    transform: scale(1.05);
}

.ldd-chat-send:disabled {
    opacity: .4;
    cursor: default;
}

.ldd-chat-send svg {
    width: 16px;
    height: 16px;
}

.ldd-chat-hint {
    font-size: 10px;
    color: var(--ldd-c-muted);
    text-align: center;
    letter-spacing: .04em;
    margin-top: 7px;
    text-transform: uppercase;
}

/* ── Mobile ────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    #ldd-chat-wrap {
        bottom: 16px;
        right: 16px;
    }

    #ldd-chat-panel {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-height: 88dvh;
        border-radius: var(--ldd-radius) var(--ldd-radius) 0 0;
        transform-origin: bottom center;
    }
}

/* ── Reduced motion ────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    #ldd-chat-panel,
    #ldd-chat-bubble,
    .ldd-msg,
    .ldd-typing-dots span {
        transition: none;
        animation: none;
    }
    .ldd-msg { opacity: 1; }
}

/* ── Bottom row (transcript toggle + hint) ─────────────────────────────── */
.ldd-chat-bottom-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
}

/* ── Transcript toggle button ──────────────────────────────────────────── */
.ldd-transcript-toggle {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
    color: var(--ldd-c-sage-dark);
    letter-spacing: .04em;
    text-transform: uppercase;
    padding: 2px 0;
    transition: color .2s;
}

.ldd-transcript-toggle:hover {
    color: var(--ldd-c-dark);
}

.ldd-transcript-toggle svg {
    width: 13px;
    height: 13px;
    flex-shrink: 0;
}

/* ── Transcript form ───────────────────────────────────────────────────── */
.ldd-chat-transcript-form {
    background: var(--ldd-c-cream-2);
    border: 1px solid var(--ldd-c-border);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 10px;
    animation: lddMsgIn .2s ease forwards;
}

.ldd-transcript-intro {
    font-size: 12.5px;
    color: var(--ldd-c-dark);
    font-weight: 600;
    margin: 0 0 8px;
}

.ldd-transcript-input {
    display: block;
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--ldd-c-border);
    border-radius: 7px;
    background: var(--ldd-c-white);
    padding: 7px 10px;
    font-family: inherit;
    font-size: 13px;
    color: var(--ldd-c-dark);
    outline: none;
    margin-bottom: 6px;
    transition: border-color .2s;
}

.ldd-transcript-input:focus {
    border-color: var(--ldd-c-sand);
}

.ldd-transcript-actions {
    display: flex;
    gap: 6px;
    margin-top: 4px;
}

.ldd-transcript-send-btn {
    flex: 1;
    padding: 7px 10px;
    background: var(--ldd-c-sage);
    color: #fff;
    border: none;
    border-radius: 7px;
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s;
}

.ldd-transcript-send-btn:hover:not(:disabled) {
    background: var(--ldd-c-sage-dark);
}

.ldd-transcript-send-btn:disabled {
    opacity: .5;
    cursor: default;
}

.ldd-transcript-cancel-btn {
    padding: 7px 10px;
    background: transparent;
    border: 1px solid var(--ldd-c-border);
    border-radius: 7px;
    font-family: inherit;
    font-size: 12px;
    color: var(--ldd-c-muted);
    cursor: pointer;
    transition: border-color .2s, color .2s;
}

.ldd-transcript-cancel-btn:hover {
    border-color: var(--ldd-c-dark);
    color: var(--ldd-c-dark);
}

.ldd-transcript-feedback {
    margin-top: 8px;
    font-size: 12px;
    padding: 6px 8px;
    border-radius: 6px;
    text-align: center;
}

.ldd-transcript-feedback.is-success {
    background: rgba(106,143,112,.12);
    color: var(--ldd-c-sage-dark);
}

.ldd-transcript-feedback.is-error {
    background: rgba(180,60,60,.08);
    color: #b43c3c;
}

/* ── Transcript form — row layout per date ─────────────────────────────── */
.ldd-transcript-row {
    display: flex;
    gap: 6px;
}

.ldd-transcript-row .ldd-transcript-input {
    flex: 1;
    min-width: 0;
}

.ldd-transcript-textarea {
    resize: none;
    line-height: 1.4;
}
