/* ============================================================================
   Ziggy — the AI assistant widget of patuco.pt (floating button + chat panel).
   Markup: resources/views/components/ziggy-panel.blade.php · logic: public/js/ziggy.js
   Palette: patuco (lime #D0D828, sage #809870, dark green #587058) for the panel;
   the Ziggy gradient (#A585FF → #5C68E2) only on the avatar/button ring.
   ============================================================================ */

:root {
    --ziggy-a: #D0D828;   /* patuco's Ziggy is a dog: lime/sage ring instead of the touchIT violet */
    --ziggy-b: #809870;
    --ziggy-green: #587058;
    --ziggy-green-dark: #3F5240;
    --ziggy-sage: #809870;
    --ziggy-lime: #D0D828;
    --ziggy-cream: #F4F6EE;
    --ziggy-paper: #FFFEF6;
    --ziggy-ink: #2F3D30;
    --ziggy-text: #5B665C;
    --ziggy-line: rgba(47, 61, 48, 0.12);
}

/* --- root: closed sits under the sticky header (z 100) so an open mobile menu covers the button;
       open it rises above everything except the preloader (z 1000) ------------------------------ */
.ziggy {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 90;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    color: var(--ziggy-ink);
}
.ziggy.is-open { z-index: 950; }
.ziggy[hidden] { display: none; }

/* --- floating button --------------------------------------------------------------------------- */
.ziggy-toggle {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    border: 0;
    border-radius: 100px;
    background: var(--ziggy-green);
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    padding: 6px 18px 6px 6px;
    box-shadow: 0 10px 28px rgba(47, 61, 48, 0.28);
    cursor: pointer;
    transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
}
.ziggy-toggle:hover {
    background: var(--ziggy-green-dark);
    transform: translateY(-2px);
    box-shadow: 0 14px 32px rgba(47, 61, 48, 0.32);
}
.ziggy-toggle:focus-visible { outline: 3px solid var(--ziggy-lime); outline-offset: 2px; }
.ziggy-toggle-avatar {
    display: inline-flex;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    padding: 2px;
    background: linear-gradient(135deg, var(--ziggy-a), var(--ziggy-b));
    flex: none;
}
.ziggy-toggle-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: #fff;
    display: block;
    object-fit: cover;
}
.ziggy-toggle-label { white-space: nowrap; }
.ziggy.is-open .ziggy-toggle { display: none; }

/* --- panel ------------------------------------------------------------------------------------- */
.ziggy-panel {
    position: absolute;
    right: 0;
    bottom: 0;
    width: min(400px, calc(100vw - 40px));
    height: min(600px, calc(100vh - 40px));
    display: flex;
    flex-direction: column;
    background: var(--ziggy-paper);
    border-radius: 22px;
    box-shadow: 0 18px 50px rgba(47, 61, 48, 0.28);
    overflow: hidden;
    border: 1px solid var(--ziggy-line);
}
.ziggy-panel[hidden] { display: none; }

.ziggy-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--ziggy-green);
    color: #fff;
}
.ziggy-avatar {
    width: 40px;
    height: 40px;
    flex: none;
    border-radius: 50%;
    background: #fff;
    padding: 2px;
    box-shadow: 0 0 0 2px var(--ziggy-a), 0 0 0 4px rgba(255, 255, 255, 0.25);
}
.ziggy-head-text { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.ziggy-head-text strong { font-size: 15px; line-height: 1.2; color: #fff; }
.ziggy-head-text span { font-size: 11px; line-height: 1.25; color: rgba(255, 255, 255, 0.75); overflow: hidden; text-overflow: ellipsis; }
.ziggy-restart,
.ziggy-close {
    flex: none;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}
.ziggy-restart:hover,
.ziggy-close:hover { background: rgba(255, 255, 255, 0.25); }

/* --- messages ---------------------------------------------------------------------------------- */
.ziggy-log {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--ziggy-cream);
    overscroll-behavior: contain;
}
.ziggy-msg {
    max-width: 88%;
    padding: 9px 13px;
    border-radius: 16px;
    line-height: 1.5;
    font-size: 14px;
    word-wrap: break-word;
}
.ziggy-msg p { margin: 0 0 5px; color: inherit; font-size: inherit; line-height: inherit; }
.ziggy-msg p:last-child { margin-bottom: 0; }
.ziggy-msg ul { margin: 3px 0 5px 18px; padding: 0; list-style: disc; }
.ziggy-msg li { margin: 0; line-height: inherit; }
.ziggy-msg a { color: var(--ziggy-green); text-decoration: underline; text-underline-offset: 2px; }
.ziggy-msg.is-bot {
    align-self: flex-start;
    background: #fff;
    border: 1px solid var(--ziggy-line);
    border-bottom-left-radius: 5px;
    color: var(--ziggy-ink);
}
.ziggy-msg.is-user {
    align-self: flex-end;
    background: var(--ziggy-green);
    color: #fff;
    border-bottom-right-radius: 5px;
}
.ziggy-msg.is-user a { color: #fff; }
.ziggy-msg.is-error { border-color: rgba(192, 57, 43, 0.35); color: #8a2a20; }

/* "Ziggy is typing…" */
.ziggy-msg.is-typing {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 13px;
    color: var(--ziggy-text);
    font-size: 12px;
}
.ziggy-dots { display: inline-flex; gap: 4px; }
.ziggy-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ziggy-sage);
    animation: ziggy-blink 1.2s infinite;
}
.ziggy-dots span:nth-child(2) { animation-delay: 0.2s; }
.ziggy-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ziggy-blink {
    0%, 80%, 100% { opacity: 0.3; }
    40% { opacity: 1; }
}

/* action links returned by the tools */
.ziggy-action {
    display: inline-block;
    margin: 7px 6px 0 0;
    padding: 7px 14px;
    border-radius: 100px;
    background: var(--ziggy-lime);
    color: var(--ziggy-green-dark) !important;
    font-weight: 600;
    font-size: 13px;
    text-decoration: none !important;
    transition: background 0.2s, color 0.2s;
}
.ziggy-action:hover { background: var(--ziggy-green-dark); color: #fff !important; }

/* suggested questions */
.ziggy-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ziggy-chips button {
    border: 1px solid var(--ziggy-sage);
    background: #fff;
    color: var(--ziggy-green);
    border-radius: 100px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}
.ziggy-chips button:hover { background: var(--ziggy-green); color: #fff; }

/* --- input ------------------------------------------------------------------------------------- */
.ziggy-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--ziggy-line);
    background: #fff;
}
.ziggy-form textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--ziggy-line);
    border-radius: 14px;
    padding: 9px 12px;
    font: inherit;
    font-size: 14px;
    line-height: 1.4;
    max-height: 120px;
    color: var(--ziggy-ink);
    background: var(--ziggy-paper);
}
.ziggy-form textarea:focus { outline: 2px solid var(--ziggy-sage); outline-offset: 0; border-color: transparent; }
.ziggy-form button {
    flex: none;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: var(--ziggy-green);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 15px;
    transition: background 0.2s;
}
.ziggy-form button:hover { background: var(--ziggy-green-dark); }
.ziggy-form.is-busy button { opacity: 0.5; pointer-events: none; }

.ziggy-note {
    margin: 0;
    padding: 7px 14px 10px;
    font-size: 10.5px;
    line-height: 1.4;
    color: var(--ziggy-text);
    background: #fff;
}
.ziggy-note a { color: inherit; text-decoration: underline; }

/* --- phones: the panel takes the whole screen ------------------------------------------------- */
@media (max-width: 575px) {
    .ziggy { right: 12px; bottom: 12px; }
    .ziggy-toggle { padding: 4px; }
    .ziggy-toggle-label { display: none; }
    .ziggy.is-open { inset: 0; right: 0; bottom: 0; }
    .ziggy-panel {
        position: fixed;
        inset: 0;
        width: 100vw;
        width: 100dvw;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        border: 0;
    }
    .ziggy-head { padding-top: max(12px, env(safe-area-inset-top)); }
    .ziggy-note { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
    html.ziggy-open, html.ziggy-open body { overflow: hidden; }
}

@media print {
    .ziggy { display: none !important; }
}
