/* Personal Stylist floating chat widget */

#stylist-chat-button {
    position: fixed;
    right: 1.5rem;
    bottom: calc(1.5rem + var(--sticky-bottom-offset, 0px));
    z-index: 1500;
    transition: transform 0.2s ease, box-shadow 0.2s ease, bottom 0.2s ease;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: #111111;
    color: #fff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
    cursor: pointer;
}

#stylist-chat-button:hover {
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.3);
}

#stylist-chat-button.is-hidden {
    display: none;
}

.stylist-chat-button-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ffb703;
    color: #111111;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.58rem;
    box-shadow: 0 0 0 2px #fff, 0 2px 6px rgba(0, 0, 0, 0.3);
}

#stylist-chat-panel {
    position: fixed;
    right: 1.5rem;
    bottom: 1.5rem;
    z-index: 1501;
    width: 392px;
    max-width: calc(100vw - 2rem);
    height: 580px;
    max-height: calc(100vh - 3rem);
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(17, 17, 17, 0.22), 0 2px 8px rgba(17, 17, 17, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    visibility: visible;
    transition: opacity 0.18s ease, transform 0.18s ease, visibility 0s linear 0s;
}

#stylist-chat-panel.is-hidden {
    opacity: 0;
    transform: scale(0.92) translateY(12px);
    pointer-events: none;
    visibility: hidden;
    transition: opacity 0.18s ease, transform 0.18s ease, visibility 0s linear 0.18s;
}

.stylist-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.1rem;
    background: #111111;
    color: #fff;
    flex-shrink: 0;
}

.stylist-chat-header-title {
    font-weight: 600;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.stylist-chat-header-icon {
    position: relative;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.stylist-chat-button-badge-sm {
    width: 14px;
    height: 14px;
    font-size: 0.42rem;
    top: -3px;
    right: -3px;
    box-shadow: 0 0 0 2px #111111, 0 2px 4px rgba(0, 0, 0, 0.3);
}

.stylist-chat-header-subtitle {
    display: block;
    font-weight: 400;
    font-size: 0.72rem;
    opacity: 0.65;
    margin-top: 0.1rem;
}

.stylist-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.stylist-chat-header-btn {
    background: transparent;
    border: none;
    color: #fff;
    opacity: 0.75;
    font-size: 1rem;
    cursor: pointer;
    line-height: 1;
    padding: 0.4rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s ease, background 0.15s ease;
}

.stylist-chat-header-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.12);
}

.stylist-chat-header-btn.is-active {
    opacity: 1;
    background: rgba(255, 255, 255, 0.18);
}

.stylist-chat-close {
    font-size: 1.05rem;
}

.stylist-chat-usage {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    padding: 0.45rem 1.1rem;
    background: #efeae3;
    border-bottom: 1px solid #e3ddd2;
    font-size: 0.7rem;
    color: #6b6459;
    flex-shrink: 0;
}

.stylist-chat-usage[hidden] {
    display: none;
}

.stylist-chat-usage-tier {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-size: 0.62rem;
    padding: 0.22rem 0.55rem;
    border-radius: 999px;
    background: #111111;
    color: #fff;
    flex-shrink: 0;
}

.stylist-chat-usage-tier i {
    font-size: 0.58rem;
}

.stylist-chat-usage-tier.is-paid {
    background: #b8860b;
}

.stylist-chat-usage-tier.is-unlimited {
    background: #1f7a3f;
}

.stylist-chat-usage-meter {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    min-width: 0;
    color: #6b6459;
    cursor: default;
}

.stylist-chat-usage-meter-icon {
    font-size: 0.68rem;
    opacity: 0.55;
    flex-shrink: 0;
}

.stylist-chat-usage-meter-text {
    font-size: 0.7rem;
    font-weight: 600;
    color: #45403a;
    white-space: nowrap;
}

.stylist-chat-usage-meter-text .stylist-chat-usage-meter-label {
    font-weight: 400;
    color: #8a8378;
    /* Logical property, not margin-left - this sits after the digits in
       both directions (LTR "3/40 this hour", RTL "٣/٤٠ هذه الساعة"), and a
       physical margin-left would only ever add space on the left, which is
       the wrong side once dir="rtl" reverses the reading order. */
    margin-inline-start: 0.3rem;
}

.stylist-chat-usage-meter-track {
    position: relative;
    width: 46px;
    height: 4px;
    border-radius: 999px;
    background: #e3ddd2;
    overflow: hidden;
    flex-shrink: 0;
}

.stylist-chat-usage-meter-fill {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 0%;
    border-radius: 999px;
    background: #111111;
    transition: width 0.3s ease;
}

.stylist-chat-usage-meter.is-near-limit .stylist-chat-usage-meter-text,
.stylist-chat-usage-meter.is-near-limit .stylist-chat-usage-meter-icon {
    color: #dc3545;
    opacity: 1;
}

.stylist-chat-usage-meter.is-near-limit .stylist-chat-usage-meter-fill {
    background: #dc3545;
}

.stylist-chat-usage-unlimited {
    font-size: 0.7rem;
    color: #8a8378;
    white-space: nowrap;
}

.stylist-chat-signed-out {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 0.5rem;
    padding: 2rem 1.75rem;
    background: #f7f6f4;
}

.stylist-chat-signed-out-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #111111;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    margin-bottom: 0.5rem;
}

.stylist-chat-signed-out-title {
    font-weight: 700;
    font-size: 1rem;
    color: #1c1c1c;
    margin: 0;
}

.stylist-chat-signed-out-text {
    font-size: 0.85rem;
    color: #6b6459;
    margin: 0;
    max-width: 26ch;
}

.stylist-chat-signed-out-btn {
    margin-top: 0.75rem;
    background: #111111;
    color: #fff;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.85rem;
    padding: 0.6rem 1.6rem;
    border-radius: 999px;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.stylist-chat-signed-out-btn:hover {
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(17, 17, 17, 0.25);
}

.stylist-chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    padding: 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    background: #f7f6f4;
}

.stylist-chat-messages.is-hidden {
    display: none;
}

.stylist-chat-history-panel {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    padding: 0.6rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    background: #f7f6f4;
}

.stylist-chat-history-panel.is-hidden {
    display: none;
}

.stylist-chat-history-item {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.4rem;
    width: 100%;
    background: #fff;
    border: 1px solid #e9e4db;
    border-radius: 12px;
    padding: 0.4rem 0.4rem 0.4rem 0.85rem;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.stylist-chat-history-item:hover {
    border-color: #c9c2b3;
    background: #faf9f7;
}

.stylist-chat-history-item.is-current {
    border-color: #111111;
    background: #fff;
}

.stylist-chat-history-item-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
    background: none;
    border: none;
    padding: 0.2rem 0;
    text-align: start;
    cursor: pointer;
}

.stylist-chat-history-item-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: #1c1c1c;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.stylist-chat-history-item-date {
    font-size: 0.72rem;
    color: #8a8378;
}

.stylist-chat-history-item-delete {
    flex-shrink: 0;
    background: transparent;
    border: none;
    color: #b0a99c;
    font-size: 0.85rem;
    padding: 0.5rem;
    border-radius: 8px;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
}

.stylist-chat-history-item-delete:hover {
    color: #c0392b;
    background: rgba(192, 57, 43, 0.08);
}

.stylist-chat-history-empty {
    margin: auto;
    font-size: 0.85rem;
    color: #8a8378;
    text-align: center;
    padding: 1.5rem;
}

.stylist-chat-bubble-row {
    display: flex;
    flex-direction: column;
    min-width: 0;
    animation: stylist-chat-fade-in 0.22s ease;
}

@keyframes stylist-chat-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.stylist-chat-bubble-row.is-user {
    align-items: flex-end;
}

.stylist-chat-bubble-row.is-assistant {
    align-items: flex-start;
}

.stylist-chat-bubble {
    max-width: 86%;
    padding: 0.6rem 0.9rem;
    border-radius: 16px;
    font-size: 0.88rem;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}

.stylist-chat-bubble-row.is-user .stylist-chat-bubble {
    background: #111111;
    color: #fff;
    border-bottom-right-radius: 5px;
}

.stylist-chat-bubble-row.is-assistant .stylist-chat-bubble {
    background: #fff;
    color: #262626;
    box-shadow: 0 1px 2px rgba(17, 17, 17, 0.06);
    border-bottom-left-radius: 5px;
}

.stylist-chat-bubble-row.is-system .stylist-chat-bubble {
    background: #efeae3;
    color: #6b6459;
    font-size: 0.78rem;
    text-align: center;
    max-width: 92%;
    margin: 0 auto;
    border-radius: 999px;
    padding: 0.4rem 0.9rem;
}

/* Grounded product recommendations — wide list rows, not a thumbnail scroll,
   so there's room for brand / title / type-color / price without truncating
   into nonsense. */
.stylist-chat-products {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.5rem;
    align-self: stretch;
    max-width: 100%;
    width: 100%;
}

.stylist-chat-product-card {
    display: flex;
    align-items: flex-start;
    gap: 0.7rem;
    padding: 0.5rem;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(17, 17, 17, 0.06);
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.stylist-chat-product-card:hover {
    box-shadow: 0 4px 14px rgba(17, 17, 17, 0.12);
    transform: translateY(-1px);
    color: inherit;
}

.stylist-chat-product-image-box {
    position: relative;
    width: 64px;
    height: 64px;
    flex-shrink: 0;
    overflow: hidden;
    border-radius: 10px;
    background: #f1f0ed;
}

.stylist-chat-product-image-box img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.stylist-chat-product-info {
    min-width: 0;
    flex: 1;
}

.stylist-chat-product-brand {
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #8a8377;
    margin-bottom: 0.1rem;
}

.stylist-chat-product-title {
    font-size: 0.83rem;
    line-height: 1.3;
    font-weight: 600;
    color: #1c1c1c;
    /* No truncation — full product name is always shown, wrapping onto
       as many lines as it needs. */
    word-break: break-word;
}

.stylist-chat-product-meta {
    font-size: 0.74rem;
    color: #837c70;
    margin-top: 0.15rem;
}

.stylist-chat-product-discount-badge {
    display: inline-block;
    background: #dc3545;
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    padding: 0.12rem 0.4rem;
    border-radius: 4px;
    margin-bottom: 0.25rem;
}

.stylist-chat-product-price-row {
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
    margin-top: 0.3rem;
}

.stylist-chat-product-price {
    font-size: 0.8rem;
    font-weight: 700;
    color: #111111;
}

.stylist-chat-product-price.is-discounted {
    color: #dc3545;
}

.stylist-chat-product-price-original {
    font-size: 0.72rem;
    color: #9a9384;
    text-decoration: line-through;
}

.stylist-chat-typing {
    display: inline-flex;
    gap: 0.22rem;
    padding: 0.2rem 0;
}

.stylist-chat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #c2bcb0;
    animation: stylist-chat-typing-bounce 1.2s infinite ease-in-out;
}

.stylist-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.stylist-chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes stylist-chat-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.6; }
    30% { transform: translateY(-4px); opacity: 1; }
}

.stylist-chat-form {
    flex-shrink: 0;
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.85rem;
    border-top: 1px solid #ece9e3;
    background: #fff;
}

.stylist-chat-input {
    flex: 1;
    resize: none;
    border: 1px solid #e3e0d9;
    background: #f7f6f4;
    border-radius: 12px;
    padding: 0.6rem 0.85rem;
    font-size: 0.88rem;
    max-height: 90px;
    line-height: 1.4;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.stylist-chat-input:focus {
    outline: none;
    border-color: #111111;
    background: #fff;
}

.stylist-chat-send {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #111111;
    color: #fff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.12s ease, opacity 0.12s ease;
}

.stylist-chat-send:hover:not(:disabled) {
    transform: scale(1.06);
}

.stylist-chat-send:disabled {
    opacity: 0.4;
    cursor: default;
}

@media (max-width: 480px) {
    #stylist-chat-panel {
        right: 0.75rem;
        bottom: 0.75rem;
        width: calc(100vw - 1.5rem);
        height: calc(100vh - 1.5rem);
        height: calc(100dvh - 1.5rem);
        max-height: none;
    }
}

@media (max-width: 767.98px) {
    /* The shopping-bag bar becomes a near-full-width bottom sheet on mobile
       (see external_shopping_bag_bar.css) — lift the launcher button above
       it exactly like back-to-top-fab already does, or the two overlap. */
    body.has-external-shopping-bag-bar #stylist-chat-button {
        bottom: max(5.75rem, calc(5rem + env(safe-area-inset-bottom)));
    }
}

@media (prefers-reduced-motion: reduce) {
    #stylist-chat-panel,
    .stylist-chat-bubble-row,
    #stylist-chat-button,
    .stylist-chat-product-card,
    .stylist-chat-usage-meter-fill {
        animation: none !important;
        transition: none !important;
    }
}
