/* ============================================================
   DG KNITTING — FABRIC ASSISTANT
   Conversational widget behind the floating WhatsApp button.
   Answers from the live catalogue, then hands off to WhatsApp.
   ============================================================ */

.dg-chat {
    position: fixed;
    right: 26px;
    bottom: 26px;
    z-index: 9998;
    font-family: Inter, system-ui, sans-serif;
}

/* ------------------------------------------------------ launcher */
.dg-chat-toggle {
    width: 60px;
    height: 60px;
    border: 0;
    border-radius: 50%;
    background: #25d366;
    color: #fff;
    box-shadow: 0 14px 34px rgba(37, 211, 102, .38);
    font-size: 1.85rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform .2s cubic-bezier(.4, 0, .2, 1), background .2s;
    position: relative;
}

.dg-chat-toggle:hover { background: #1ebe5d; transform: translateY(-2px) scale(1.03); }
.dg-chat-toggle:focus-visible { outline: 3px solid #2e2d2c; outline-offset: 3px; }

.dg-chat-toggle .close-ico { display: none; }
.dg-chat.open .dg-chat-toggle .open-ico { display: none; }
.dg-chat.open .dg-chat-toggle .close-ico { display: inline-flex; }
.dg-chat.open .dg-chat-toggle { background: #2e2d2c; box-shadow: 0 14px 34px rgba(0, 0, 0, .3); }

/* unread nudge */
.dg-chat-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 20px;
    height: 20px;
    border-radius: 999px;
    background: #df2229;
    color: #fff;
    font-size: .72rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
}

.dg-chat.open .dg-chat-badge,
.dg-chat-badge[hidden] { display: none; }

/* greeting bubble */
.dg-chat-nudge {
    position: absolute;
    right: 72px;
    bottom: 10px;
    width: max-content;
    max-width: 210px;
    background: #fff;
    color: #2e2d2c;
    border: 1px solid #e7e3df;
    border-radius: 14px 14px 2px 14px;
    padding: 9px 13px;
    font-size: .82rem;
    line-height: 1.45;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .12);
    animation: dgNudge .4s cubic-bezier(.4, 0, .2, 1);
}

.dg-chat-nudge button {
    position: absolute;
    top: -7px;
    right: -7px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid #e7e3df;
    background: #fff;
    color: #8b8580;
    font-size: .7rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}

.dg-chat.open .dg-chat-nudge,
.dg-chat-nudge[hidden] { display: none; }

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

/* --------------------------------------------------------- panel */
.dg-chat-panel {
    position: absolute;
    right: 0;
    bottom: 74px;
    width: min(384px, calc(100vw - 32px));
    height: min(560px, calc(100vh - 130px));
    background: #fff;
    border: 1px solid #e7e3df;
    border-radius: 18px;
    box-shadow: 0 26px 70px rgba(0, 0, 0, .2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px) scale(.98);
    transform-origin: bottom right;
    transition: opacity .2s ease, transform .22s cubic-bezier(.4, 0, .2, 1), visibility .22s;
}

.dg-chat.open .dg-chat-panel {
    opacity: 1;
    visibility: visible;
    transform: none;
}

.dg-chat-head {
    padding: 15px 18px;
    background: linear-gradient(135deg, #2e2d2c, #45403c);
    color: #fff;
    display: flex;
    align-items: center;
    gap: 11px;
    flex-shrink: 0;
}

.dg-chat-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #df2229;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.dg-chat-head strong { display: block; font-size: .97rem; line-height: 1.3; }

.dg-chat-head span {
    font-size: .78rem;
    opacity: .82;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.dg-chat-head span::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
}

/* ------------------------------------------------------- messages */
.dg-chat-log {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #faf8f6;
    scroll-behavior: smooth;
}

.dg-msg {
    max-width: 84%;
    padding: 10px 13px;
    border-radius: 14px;
    font-size: .875rem;
    line-height: 1.55;
    animation: dgIn .22s cubic-bezier(.4, 0, .2, 1);
    word-wrap: break-word;
}

@keyframes dgIn {
    from { opacity: 0; transform: translateY(5px); }
    to   { opacity: 1; transform: none; }
}

.dg-msg.bot {
    align-self: flex-start;
    background: #fff;
    color: #2e2d2c;
    border: 1px solid #e7e3df;
    border-bottom-left-radius: 4px;
}

.dg-msg.user {
    align-self: flex-end;
    background: #df2229;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.dg-msg strong { font-weight: 600; }
.dg-msg a { color: inherit; text-decoration: underline; }
.dg-msg.bot a { color: #df2229; }
.dg-msg ul { margin: 6px 0 0; padding-left: 18px; }
.dg-msg li { margin-bottom: 3px; }

/* fabric suggestion card */
.dg-fab {
    display: flex;
    gap: 10px;
    align-items: center;
    background: #fff;
    border: 1px solid #e7e3df;
    border-radius: 11px;
    padding: 8px;
    margin-top: 7px;
    text-decoration: none;
    color: inherit;
    transition: border-color .18s, transform .18s;
}

.dg-fab:hover { border-color: #e18c94; transform: translateX(2px); color: inherit; }

.dg-fab img {
    width: 46px;
    height: 46px;
    border-radius: 7px;
    object-fit: cover;
    flex-shrink: 0;
    background: #faf8f6;
}

.dg-fab b { display: block; font-size: .82rem; color: #2e2d2c; }
.dg-fab small { font-size: .74rem; color: #8b8580; }

/* typing indicator */
.dg-typing {
    align-self: flex-start;
    background: #fff;
    border: 1px solid #e7e3df;
    border-radius: 14px 14px 14px 4px;
    padding: 12px 14px;
    display: flex;
    gap: 4px;
}

.dg-typing i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #b3aca6;
    animation: dgBounce 1.1s infinite;
}

.dg-typing i:nth-child(2) { animation-delay: .15s; }
.dg-typing i:nth-child(3) { animation-delay: .3s; }

@keyframes dgBounce {
    0%, 60%, 100% { transform: none; opacity: .5; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* --------------------------------------------------- quick replies */
.dg-chat-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 16px 10px;
    background: #faf8f6;
    flex-shrink: 0;
}

.dg-chat-quick button {
    background: #fff;
    border: 1px solid #e7e3df;
    color: #4a4a4a;
    border-radius: 999px;
    padding: 7px 13px;
    font-size: .79rem;
    cursor: pointer;
    transition: all .16s;
    font-family: inherit;
}

.dg-chat-quick button:hover {
    border-color: #df2229;
    color: #df2229;
    background: #fdf2f1;
}

.dg-chat-quick button.primary {
    background: #25d366;
    border-color: #25d366;
    color: #fff;
    font-weight: 600;
}

.dg-chat-quick button.primary:hover { background: #1ebe5d; color: #fff; }

/* ---------------------------------------------------------- input */
.dg-chat-form {
    display: flex;
    gap: 8px;
    padding: 11px 12px;
    border-top: 1px solid #e7e3df;
    background: #fff;
    flex-shrink: 0;
    align-items: center;
}

.dg-chat-form input {
    flex: 1;
    border: 1px solid #e7e3df;
    border-radius: 999px;
    padding: 10px 15px;
    font-size: .87rem;
    font-family: inherit;
    outline: none;
    min-width: 0;
    transition: border-color .18s;
}

.dg-chat-form input:focus { border-color: #e18c94; }

.dg-chat-form button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 0;
    background: #df2229;
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
    font-size: .9rem;
    transition: background .18s;
}

.dg-chat-form button:hover { background: #c31d23; }
.dg-chat-form button:disabled { background: #d9d3ce; cursor: not-allowed; }

.dg-chat-foot {
    font-size: .68rem;
    color: #a49d97;
    text-align: center;
    padding: 0 12px 9px;
    background: #fff;
    flex-shrink: 0;
}

.dg-chat-foot a { color: #8b8580; }

/* --------------------------------------------------------- mobile */
@media (max-width: 767px) {
    .dg-chat { right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
    .dg-chat-toggle { width: 54px; height: 54px; font-size: 1.65rem; }
    .dg-chat-nudge { max-width: 168px; font-size: .78rem; right: 64px; }

    .dg-chat-panel {
        position: fixed;
        right: 0;
        left: 0;
        bottom: 0;
        width: 100%;
        height: 88vh;
        border-radius: 18px 18px 0 0;
        transform: translateY(100%);
    }

    .dg-chat.open .dg-chat-panel { transform: none; }
    .dg-msg { max-width: 88%; }
}

@media (prefers-reduced-motion: reduce) {
    .dg-chat-panel, .dg-msg, .dg-chat-nudge, .dg-typing i { animation: none !important; transition: none !important; }
}
