/* UTOPYA Hyvä — Widget Maki IA. Porté de utopya-ux/_makia.scss, ré-habillé aux tokens Azur v1.3. */

#makia-chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    font-family: var(--font-body);
}

#makia-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    padding: 0;
    overflow: hidden;
}

#makia-toggle:hover {
    transform: scale(1.08);
}

#makia-toggle .makia-icon-chat {
    display: block;
    width: 60px;
    height: 60px;
}

#makia-toggle .makia-icon-chat img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Window */
#makia-window {
    display: none;
    position: absolute;
    bottom: 0;
    right: 0;
    width: 420px;
    height: 700px;
    background: #fff;
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
    flex-direction: column;
    overflow: hidden;
}

#makia-window.open {
    display: flex;
}

/* Header */
#makia-header {
    /* Dégradé identique au footer (u-footer) : navy → azur profond. */
    background: linear-gradient(150deg, var(--color-dark) 0%, #0F2742 62%, #123A6B 100%);
    color: #fff;
    padding: 8px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#makia-header .makia-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

#makia-header .makia-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: none;
    flex-shrink: 0;
    position: relative;
}

#makia-header .makia-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

#makia-header .makia-avatar::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: -1px;
    width: 9px;
    height: 9px;
    background: var(--color-stock-dot);
    border-radius: 50%;
    border: 2px solid #123a6b;
}

#makia-header .makia-header-title {
    font-size: 15px;
    font-family: var(--font-display);
    font-weight: 600;
}

#makia-header .makia-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

#makia-reset,
#makia-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    opacity: 0.7;
    padding: 2px;
    display: flex;
    align-items: center;
    transition: opacity 0.15s;
}

#makia-reset:hover,
#makia-close:hover {
    opacity: 1;
}

#makia-reset svg,
#makia-close svg {
    width: 12px;
    height: 12px;
}

#makia-close {
    font-size: 22px;
    line-height: 1;
    padding-top: 0px;
}

/* Messages */
#makia-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
}

/* Date separator */
.makia-date-sep {
    text-align: center;
    font-size: 12px;
    color: var(--color-ink-3);
    padding: 4px 0 2px;
}

/* Message row */
.makia-msg-row {
    display: flex;
    flex-direction: column;
}

.makia-msg-row.makia-user {
    align-items: flex-end;
}

.makia-msg-row.makia-bot {
    align-items: flex-start;
}

.makia-msg {
    max-width: 90%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.makia-msg.makia-user {
    background: #123a6b;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.makia-msg.makia-bot {
    background: var(--color-surface-2);
    color: #123a6b;
    border-bottom-left-radius: 4px;
}

.makia-msg a {
    color: inherit;
    text-decoration: underline;
    word-break: break-all;
}

.makia-msg a:hover {
    opacity: 0.8;
}

.makia-msg-files {
    margin-top: 6px;
    font-size: 12px;
    opacity: 0.85;
}

.makia-msg-files span {
    display: block;
}

/* Product cards */
.makia-products {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 8px 0 4px;
    max-width: 100%;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
}

.makia-products::-webkit-scrollbar {
    height: 4px;
}

.makia-products::-webkit-scrollbar-track {
    background: transparent;
}

.makia-products::-webkit-scrollbar-thumb {
    background: var(--color-line-2);
    border-radius: 2px;
}

.makia-product-card {
    flex: 0 0 140px;
    background: #fff;
    border: 1px solid var(--color-line);
    border-radius: 12px;
    overflow: hidden;
    scroll-snap-align: start;
    display: flex;
    flex-direction: column;
    transition: border-color 0.15s;
}

.makia-product-card:hover {
    border-color: #123a6b;
}

.makia-product-card .makia-product-visual {
    position: relative;
}

.makia-product-card .makia-product-qualite {
    position: absolute;
    top: 8px;
    left: 8px;
    background: #123a6b;
    color: #fff;
    font-size: 9px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 4px;
    z-index: 1;
    line-height: 1.4;
}

.makia-product-card .makia-product-img {
    width: 100%;
    height: 120px;
    object-fit: contain;
    background: #fff;
    display: block;
}

.makia-product-card .makia-product-noimg {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-surface-2);
}

.makia-product-card .makia-product-noimg span {
    font-size: 28px;
    font-weight: 700;
    color: #123a6b;
    opacity: 0.3;
}

.makia-product-card .makia-product-info {
    padding: 8px 10px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.makia-product-card .makia-name-wrap {
    position: relative;
}

.makia-product-card .makia-name-wrap:hover .makia-name-tooltip {
    opacity: 1;
    visibility: visible;
}

.makia-product-card .makia-product-name {
    font-size: 12px;
    font-weight: 500;
    color: #123a6b;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-decoration: none;
}

.makia-product-card .makia-product-name:hover {
    text-decoration: underline;
}

.makia-product-card .makia-name-tooltip {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    right: 0;
    background: #123a6b;
    color: #fff;
    font-size: 11px;
    font-weight: 400;
    padding: 6px 8px;
    border-radius: 6px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s, visibility 0.15s;
    pointer-events: none;
    display: -webkit-box;
    -webkit-line-clamp: unset;
    -webkit-box-orient: vertical;
    overflow: visible;
    white-space: normal;
    z-index: 3;
}

.makia-product-card .makia-name-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 12px;
    border: 4px solid transparent;
    border-top-color: #123a6b;
}

.makia-product-card .makia-product-prices {
    display: flex;
    align-items: baseline;
    gap: 4px;
    flex-wrap: wrap;
}

.makia-product-card .makia-product-price {
    font-size: 14px;
    font-weight: 700;
    color: var(--color-ink);
}

.makia-product-card .makia-product-oldprice {
    font-size: 11px;
    color: var(--color-ink-3);
    text-decoration: line-through;
}

.makia-product-card .makia-product-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    margin-top: auto;
}

.makia-product-card .makia-stock {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    font-weight: 600;
}

.makia-product-card .makia-stock.makia-stock-ok {
    color: var(--color-stock);
}

.makia-product-card .makia-stock.makia-stock-out {
    color: var(--color-error);
}

.makia-product-card .makia-stock-ok .makia-stock-dot {
    background: var(--color-stock);
}

.makia-product-card .makia-stock-out .makia-stock-dot {
    background: var(--color-error);
}

.makia-product-card .makia-stock-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    display: inline-block;
}

.makia-product-card .makia-add-cart {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    padding: 0;
    border: none;
    border-radius: 10px;
    background: #123a6b;
    color: #fff;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.makia-product-card .makia-add-cart:hover {
    background: color-mix(in srgb, #123a6b 92%, #000);
    transform: scale(1.05);
}

.makia-product-card .makia-add-cart:disabled:not(.added) {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.makia-product-card .makia-add-cart.added {
    background: var(--color-stock);
}

.makia-product-card .makia-add-cart.makia-oos {
    background: var(--color-surface-2);
    color: var(--color-ink-3);
    cursor: pointer;
}

.makia-product-card .makia-add-cart.makia-oos:hover {
    background: #123a6b;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='-0.45 -0.45 10 10' id='Alarm-Add-Bell-Notification--Streamline-Micro' height='10' width='10'%3E%3Cpath stroke='%23ffffff' stroke-linecap='round' stroke-linejoin='round' d='M3.185 8.645h1.82' stroke-width='0.9'%3E%3C/path%3E%3Cpath stroke='%23ffffff' stroke-linecap='round' stroke-linejoin='round' d='M4.641 0.5086900000000001a2.81372 2.81372 0 0 0 -3.29875 2.17126L0.45591000000000004 6.825h7.28l-0.2912 -1.3586300000000002' stroke-width='0.9'%3E%3C/path%3E%3Cpath stroke='%23ffffff' stroke-linecap='round' stroke-linejoin='round' d='m7.0525 0.455 0 1.5925m0 0 0 1.5925m0 -1.5925 1.5925 0m-1.5925 0L5.46 2.0475' stroke-width='0.9'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 18px;
    transform: scale(1.05);
}

.makia-product-card .makia-add-cart.makia-oos:hover svg {
    opacity: 0;
}

.makia-product-card .makia-cart-oos {
    position: relative;
}

.makia-product-card .makia-cart-oos:hover .makia-oos-tooltip {
    opacity: 1;
    visibility: visible;
}

.makia-product-card .makia-oos-tooltip {
    position: absolute;
    bottom: calc(100% + 6px);
    right: 0;
    background: #123a6b;
    color: #fff;
    font-size: 10px;
    font-weight: 500;
    padding: 5px 8px;
    border-radius: 6px;
    width: 120px;
    text-align: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s, visibility 0.15s;
    pointer-events: none;
}

.makia-product-card .makia-oos-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    right: 10px;
    border: 4px solid transparent;
    border-top-color: #123a6b;
}

/* Typing indicator */
.makia-typing {
    align-self: flex-start;
    background: var(--color-surface-2);
    padding: 12px 18px;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    display: flex;
    gap: 5px;
    align-items: center;
}

.makia-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-ink);
    animation: makiaBounce 1.4s infinite ease-in-out both;
}

.makia-dot:nth-child(1) {
    animation-delay: 0s;
}

.makia-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.makia-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes makiaBounce {
    0%, 80%, 100% {
        transform: scale(0.4);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Input area */
#makia-form {
    padding: 12px 14px 0;
}

#makia-input-wrapper {
    display: flex;
    align-items: center;
    background: var(--color-surface);
    border: 1px solid var(--color-line);
    border-radius: 24px;
    padding: 6px 6px 6px 12px;
    gap: 6px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

#makia-input-wrapper:focus-within {
    border-color: var(--color-line);
    box-shadow: 0 0 0 3px rgba(107, 120, 137, 0.15);
}

/* Approche de la limite : liseré bleu accentué */
#makia-input-wrapper.makia-warn {
    border-color: #123a6b;
}

/* Limite dépassée : liseré + fond ambre, envoi bloqué */
#makia-input-wrapper.makia-over,
#makia-input-wrapper.makia-over:focus-within {
    border-color: var(--color-warn);
    background: var(--color-warn-soft);
    box-shadow: none;
}

/* Ligne d'aide sous le champ (compteur / message de dépassement) */
#makia-hint {
    display: none;
    align-items: center;
    gap: 6px;
    margin: 8px 4px 0;
    font-size: 13px;
    line-height: 1.4;
}

#makia-hint #makia-hint-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    display: none;
}

#makia-hint #makia-hint-icon path {
    fill: currentColor;
}

/* Compteur "Encore X caractères" : discret, aligné à droite */
#makia-hint.makia-hint-near {
    justify-content: flex-end;
    color: var(--color-ink-3);
    font-weight: 500;
}

#makia-hint.makia-hint-amber {
    color: var(--color-warn);
}

/* Message de dépassement : icône + texte ambre, aligné à gauche */
#makia-hint.makia-hint-over {
    justify-content: flex-start;
    color: var(--color-warn);
    font-weight: 500;
}

#makia-hint.makia-hint-over #makia-hint-icon {
    display: block;
    color: var(--color-warn);
}

#makia-attach-btn {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--color-ink);
    border-radius: 50%;
    transition: color 0.15s, background 0.15s;
}

#makia-attach-btn:hover {
    color: #123a6b;
    background: rgba(0, 0, 0, 0.05);
}

#makia-attach-btn svg {
    width: 18px;
    height: 18px;
}

#makia-attach-btn input[type="file"] {
    display: none;
}

#makia-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 6px 4px;
    font-size: 14px;
    line-height: 20px;
    outline: none;
    font-family: var(--font-body);
    resize: none;
    max-height: 100px; /* ~5 lines */
    overflow-y: auto;
}

#makia-input::placeholder {
    color: var(--color-ink-3);
}

#makia-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: #123a6b;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, opacity 0.15s;
}

#makia-send svg {
    width: 16px;
    height: 16px;
}

#makia-send:hover {
    background: color-mix(in srgb, #123a6b 92%, #000);
}

#makia-send:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* Bouton micro (saisie vocale / Speech-to-Text) */
#makia-mic {
    position: relative;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--color-ink-3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}

#makia-mic svg {
    width: 18px;
    height: 18px;
    position: relative;
    z-index: 1;
}

#makia-mic:hover {
    background: rgba(12, 26, 43, 0.12);
    color: #123a6b;
}

/* Point rouge pulsant pendant l'enregistrement */
#makia-mic .makia-mic-rec {
    display: none;
    position: absolute;
    top: 6px;
    right: 6px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-error);
    z-index: 2;
}

#makia-mic.makia-recording {
    color: var(--color-error);
    background: rgba(229, 57, 53, 0.12);
}

#makia-mic.makia-recording .makia-mic-rec {
    display: block;
    animation: makia-mic-pulse 1.2s ease-out infinite;
}

#makia-mic.makia-mic-working {
    color: #123a6b;
}

#makia-mic.makia-mic-working svg {
    animation: makia-mic-spin 0.8s linear infinite;
    opacity: 0.7;
}

#makia-mic.makia-mic-off,
#makia-mic:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

@keyframes makia-mic-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(229, 57, 53, 0.55); }
    100% { box-shadow: 0 0 0 7px rgba(229, 57, 53, 0); }
}

@keyframes makia-mic-spin {
    to { transform: rotate(360deg); }
}

/* Pending file tags */
#makia-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0;
}

#makia-attachments:not(:empty) {
    padding: 8px 4px 0;
}

.makia-file-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--color-surface-2);
    border-radius: 8px;
    padding: 4px 8px;
    font-size: 12px;
    color: #123a6b;
}

.makia-file-tag .makia-file-name {
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.makia-file-tag button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    color: var(--color-ink);
    padding: 0 2px;
    line-height: 1;
}

.makia-file-tag button:hover {
    color: var(--color-error);
}

/* Powered by */
#makia-powered {
    text-align: center;
    padding: 12px 0;
    font-size: 9px;
    font-weight: 500;
    letter-spacing: 0.06em;
    color: var(--color-ink-3);
}

/* Mobile */
@media (max-width: 480px) {
    /* Launcher discret, enfoncé dans le coin bas-droit. */
    #makia-chat-widget {
        bottom: -8px;
        right: -6px;
    }

    #makia-toggle {
        width: 46px;
        height: 46px;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    }

    #makia-toggle .makia-icon-chat {
        width: 46px;
        height: 46px;
    }

    #makia-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    #makia-messages {
        max-height: none;
        flex: 1;
    }
}

/* =========================================================================
   MODE SOMBRE — override des valeurs codées en dur (light intact).
   Le header/dégradé + bulle user (#123a6b) restent tels quels (sur fonds colorés).
   ========================================================================= */
:root[data-theme="dark"] #makia-window,
:root:not([data-theme="light"]) #makia-window { background: var(--color-surface); }
:root[data-theme="dark"] .makia-msg.makia-bot,
:root:not([data-theme="light"]) .makia-msg.makia-bot { color: var(--color-ink); }
:root[data-theme="dark"] .makia-product-card,
:root:not([data-theme="light"]) .makia-product-card { background: var(--color-surface); }
:root[data-theme="dark"] .makia-product-name,
:root:not([data-theme="light"]) .makia-product-name,
:root[data-theme="dark"] .makia-product-noimg span,
:root:not([data-theme="light"]) .makia-product-noimg span { color: var(--color-ink); }
/* la vignette produit reste sur blanc (photos à fond blanc) */
:root[data-theme="dark"] .makia-product-card .makia-product-img,
:root:not([data-theme="light"]) .makia-product-card .makia-product-img { background: #fff; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) #makia-window { background: var(--color-surface); }
    :root:not([data-theme="light"]) .makia-msg.makia-bot { color: var(--color-ink); }
    :root:not([data-theme="light"]) .makia-product-card { background: var(--color-surface); }
    :root:not([data-theme="light"]) .makia-product-name,
    :root:not([data-theme="light"]) .makia-product-noimg span { color: var(--color-ink); }
    :root:not([data-theme="light"]) .makia-product-card .makia-product-img { background: #fff; }
}
