/* ════════════════════════════════════════════════════════════════════
   AI Product Finder — consolidated stylesheet (v3.3)
   One source of truth. Glass instrument-panel design.
   Config flows through CSS variables set by applyConfig() in widget.js:
   --apf-primary --apf-text-color --apf-border-radius --apf-w --apf-h
   --apf-bubble --apf-gradient
   ════════════════════════════════════════════════════════════════════ */

/* ── 1. Root ── */
#apf-widget-root {
    --apf-color: var(--apf-primary, #2563eb);
    --apf-text: var(--apf-text-color, #ffffff);
    --apf-radius: var(--apf-border-radius, 16px);
    --apf-width: var(--apf-w, 380px);
    --apf-height: var(--apf-h, 520px);
    --apf-ink: #0f172a;
    --apf-muted: #64748b;
    --apf-hairline: rgba(15, 23, 42, .08);
    position: fixed !important;
    z-index: 99999 !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}
#apf-widget-root *, #apf-widget-root *::before, #apf-widget-root *::after { box-sizing: border-box; }

/* ── 2. Toggle bubble ── */
.apf-toggle-wrap { position: relative; display: inline-block; }
.apf-toggle {
    width: var(--apf-bubble, 60px);
    height: var(--apf-bubble, 60px);
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, .45);
    background: var(--apf-gradient, linear-gradient(135deg, var(--apf-color), color-mix(in srgb, var(--apf-color) 72%, #0b1220)));
    color: var(--apf-text);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 18px rgba(0, 0, 0, .26);
    transition: transform .2s ease, box-shadow .2s ease;
}
.apf-toggle:hover { transform: scale(1.06); box-shadow: 0 7px 26px rgba(0, 0, 0, .32); }
.apf-toggle svg { width: 46%; height: 46%; fill: currentColor; }
.apf-toggle img { width: 56%; height: 56%; border-radius: 50%; object-fit: cover; }
.apf-badge {
    position: absolute; top: -5px; right: -5px;
    background: #16a34a; color: #fff;
    font-size: 10px; font-weight: 700; letter-spacing: .5px;
    padding: 2px 7px; border-radius: 10px; border: 2px solid #fff;
    pointer-events: none; box-shadow: 0 1px 4px rgba(0, 0, 0, .2);
}
.apf-toggle--pill {
    width: auto; min-width: 48px; height: 48px;
    border-radius: 24px; padding: 0 18px; gap: 8px;
}
.apf-toggle--pill .apf-toggle-text { font-size: 14px; font-weight: 600; color: var(--apf-text); white-space: nowrap; }

/* ── 3. Teaser ── */
.apf-teaser {
    position: absolute;
    background: rgba(255, 255, 255, .92);
    -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
    color: var(--apf-ink); border: 1px solid rgba(255, 255, 255, .6);
    border-radius: 12px; padding: 10px 32px 10px 14px;
    font-size: 13px; line-height: 1.4; max-width: 230px;
    box-shadow: 0 4px 20px rgba(15, 23, 42, .14); cursor: pointer;
    opacity: 0; transform: translateY(8px);
    animation: apf-teaser-in .35s ease forwards;
}
@keyframes apf-teaser-in { to { opacity: 1; transform: translateY(0); } }
.apf-teaser-close {
    position: absolute; top: 4px; right: 6px; background: none; border: none;
    cursor: pointer; color: var(--apf-muted); font-size: 14px; line-height: 1; padding: 2px;
}
.apf-teaser-close:hover { color: var(--apf-ink); }

/* ── 4. Panel: frosted glass instrument ── */
.apf-panel {
    position: relative;
    width: var(--apf-width); height: var(--apf-height);
    max-height: calc(100vh - 100px); max-width: calc(100vw - 32px);
    background: rgba(255, 255, 255, .78);
    -webkit-backdrop-filter: blur(24px) saturate(1.7);
    backdrop-filter: blur(24px) saturate(1.7);
    border: 1px solid rgba(255, 255, 255, .55);
    border-radius: var(--apf-radius);
    box-shadow: 0 12px 40px rgba(15, 23, 42, .22), 0 2px 10px rgba(15, 23, 42, .10);
    display: flex; flex-direction: column; overflow: hidden;
    opacity: 0; transform: scale(.92) translateY(18px);
    transition: opacity .25s ease, transform .25s ease;
    pointer-events: none;
}
.apf-panel.apf-open { opacity: 1; transform: none; pointer-events: auto; }
@supports not (backdrop-filter: blur(1px)) {
    .apf-panel { background: rgba(255, 255, 255, .98); }
}

/* Signature: the activity hairline */
.apf-statusline {
    position: absolute; top: 0; left: 0; right: 0; height: 2.5px; z-index: 60;
    background: linear-gradient(90deg, transparent, var(--apf-color), transparent);
    background-size: 200% 100%; opacity: .25; pointer-events: none;
}
.apf-panel.apf-busy .apf-statusline { opacity: 1; animation: apf-scan 1.1s linear infinite; }
@keyframes apf-scan { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ── 5. Header ── */
.apf-header {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 12px 12px 14px; flex-shrink: 0;
    background: var(--apf-gradient, linear-gradient(135deg, var(--apf-color), color-mix(in srgb, var(--apf-color) 72%, #0b1220)));
    color: var(--apf-text);
    cursor: grab; user-select: none;
}
.apf-header.dragging { cursor: grabbing; }
.apf-header-avatar {
    width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
    background: rgba(255, 255, 255, .18);
    display: flex; align-items: center; justify-content: center;
}
.apf-header-avatar svg { width: 19px; height: 19px; }
.apf-header-avatar img { width: 100%; height: 100%; border-radius: 10px; object-fit: cover; }
.apf-header-info { flex: 1; min-width: 0; }
.apf-header-name {
    font-size: 14.5px; font-weight: 700; letter-spacing: -.01em;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.apf-header-status {
    font-size: 11.5px; opacity: .85; display: flex; align-items: center; gap: 5px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.apf-status-dot {
    width: 7px; height: 7px; border-radius: 50%; background: #4ade80; flex-shrink: 0;
    box-shadow: 0 0 6px rgba(74, 222, 128, .9);
}
.apf-header-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.apf-header-actions button, .apf-header-action {
    width: 30px; height: 30px; margin: 0; padding: 0; border: 0; border-radius: 9px;
    background: rgba(255, 255, 255, .14); color: inherit; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 15px; line-height: 1;
    transition: background .15s ease;
}
.apf-header-actions button svg, .apf-header-action svg { width: 15px; height: 15px; fill: currentColor; stroke: currentColor; }
.apf-header-actions button:hover, .apf-header-action:hover { background: rgba(255, 255, 255, .3); }

/* ── 6. Messages ── */
.apf-messages {
    flex: 1; overflow-y: auto; padding: 16px;
    display: flex; flex-direction: column; gap: 12px;
    scroll-behavior: smooth; background: transparent;
}
.apf-msg {
    max-width: 85%; padding: 10px 14px; border-radius: 14px;
    word-break: break-word; animation: apf-fadein .2s ease;
}
@keyframes apf-fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.apf-msg-bot {
    background: rgba(255, 255, 255, .85);
    border: 1px solid var(--apf-hairline);
    box-shadow: 0 1px 4px rgba(15, 23, 42, .05);
    color: var(--apf-ink);
    align-self: flex-start; border-bottom-left-radius: 5px;
}
.apf-msg-bot a { color: var(--apf-color); font-weight: 600; }
.apf-msg-user {
    background: linear-gradient(135deg, var(--apf-color), color-mix(in srgb, var(--apf-color) 78%, #0b1220));
    color: var(--apf-text);
    box-shadow: 0 2px 8px color-mix(in srgb, var(--apf-color) 30%, transparent);
    align-self: flex-end; border-bottom-right-radius: 5px;
}
.apf-img-msg { max-width: 60%; align-self: flex-end; border-radius: 12px; overflow: hidden; border: 1px solid var(--apf-hairline); }
.apf-img-msg img { width: 100%; display: block; }

.apf-typing { display: flex; gap: 4px; padding: 10px 14px; align-self: flex-start; }
.apf-typing span {
    width: 8px; height: 8px; background: var(--apf-muted); border-radius: 50%;
    animation: apf-bounce 1.4s ease-in-out infinite;
}
.apf-typing span:nth-child(2) { animation-delay: .2s; }
.apf-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes apf-bounce { 0%, 60%, 100% { transform: none; } 30% { transform: translateY(-6px); } }

.apf-msg-feedback { display: flex; gap: 4px; align-self: flex-start; margin-top: -6px; opacity: .6; }
.apf-msg-feedback button { background: none; border: none; cursor: pointer; font-size: 12px; padding: 2px 4px; border-radius: 4px; }
.apf-msg-feedback button:hover { background: rgba(15, 23, 42, .06); }
.apf-msg-feedback button.done { opacity: .4; cursor: default; }

/* ── 7. Chips (quick replies + AI suggestions) ── */
.apf-chips { display: flex; flex-wrap: wrap; gap: 7px; align-self: flex-start; max-width: 95%; }
.apf-chip {
    background: rgba(255, 255, 255, .75);
    border: 1px solid color-mix(in srgb, var(--apf-color) 50%, transparent);
    color: var(--apf-color);
    border-radius: 16px; padding: 7px 14px;
    font-size: 12.5px; font-weight: 500; cursor: pointer; font-family: inherit;
    transition: all .15s ease;
}
.apf-chip:hover { background: var(--apf-color); color: var(--apf-text); }

/* ── 8. Product cards / alternatives / comparison ── */
.apf-product-card {
    background: rgba(255, 255, 255, .88);
    border: 1px solid var(--apf-hairline); border-radius: 12px;
    padding: 12px 14px; margin-top: 8px; font-size: 13px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, .06);
    max-width: 95%; align-self: flex-start; width: 100%;
}
.apf-product-card-name { font-weight: 600; font-size: 13.5px; color: var(--apf-ink); margin-bottom: 4px; }
.apf-product-card-specs { font-size: 12px; color: var(--apf-muted); line-height: 1.5; margin-bottom: 6px; }
.apf-product-card-specs span { display: block; }
.apf-product-card-price { font-weight: 700; color: var(--apf-color); font-size: 14px; margin-bottom: 6px; }
.apf-product-card-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.apf-product-card-actions a, .apf-product-card-actions button {
    padding: 7px 12px; border-radius: 8px; font-size: 12px; font-weight: 600;
    border: 1px solid var(--apf-color); cursor: pointer; text-decoration: none;
    background: rgba(255, 255, 255, .9); color: var(--apf-color);
    transition: filter .15s ease; font-family: inherit;
}
.apf-product-card-actions a:first-child,
.apf-product-card-actions .apf-btn-quote { background: var(--apf-color); color: var(--apf-text); }
.apf-product-card-actions a:hover, .apf-product-card-actions button:hover { filter: brightness(.93); }

.apf-alt-card {
    background: rgba(250, 250, 250, .9); border: 1px solid var(--apf-hairline);
    border-radius: 8px; padding: 8px 12px; margin-top: 6px;
    display: flex; align-items: center; justify-content: space-between; font-size: 12px;
    max-width: 95%; align-self: flex-start; width: 100%;
}
.apf-alt-card-label { color: var(--apf-muted); font-size: 11px; }
.apf-alt-card a { color: var(--apf-color); text-decoration: none; font-weight: 500; }

.apf-compare-wrap { max-width: 95%; align-self: flex-start; overflow-x: auto; }
.apf-compare {
    border-collapse: collapse; font-size: 11px; width: 100%;
    background: rgba(255, 255, 255, .92); border: 1px solid var(--apf-hairline); border-radius: 8px;
}
.apf-compare th, .apf-compare td { padding: 6px 8px; border-bottom: 1px solid rgba(15, 23, 42, .05); text-align: left; vertical-align: top; }
.apf-compare th { background: rgba(249, 250, 251, .9); font-weight: 600; white-space: nowrap; }
.apf-compare td:first-child { color: var(--apf-muted); white-space: nowrap; }
.apf-compare .apf-cmp-price { font-weight: 700; color: var(--apf-color); }

/* ── 9. Forms in chat (quote / review / email transcript) ── */
.apf-quote-form, .apf-email-form {
    padding: 12px; background: rgba(249, 250, 251, .92);
    border: 1px solid var(--apf-hairline); border-radius: 10px; margin-top: 8px;
    max-width: 95%; align-self: flex-start; width: 100%;
}
.apf-quote-form input, .apf-quote-form textarea, .apf-email-form input {
    width: 100%; padding: 8px 10px; border: 1px solid rgba(15, 23, 42, .14);
    border-radius: 8px; font-size: 13px; margin-bottom: 8px; font-family: inherit; background: #fff;
}
.apf-quote-form button, .apf-email-form button, .apf-submit-review {
    width: 100%; padding: 10px; background: var(--apf-color); color: var(--apf-text);
    border: none; border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 13px; font-family: inherit;
}
.apf-stars { display: flex; gap: 4px; font-size: 20px; cursor: pointer; margin: 4px 0 8px; }

/* ── 10. Input area ── */
.apf-input-area {
    display: flex; gap: 8px; align-items: center; flex-shrink: 0;
    padding: 10px 12px;
    background: rgba(255, 255, 255, .65);
    -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
    border-top: 1px solid rgba(255, 255, 255, .5);
}
.apf-input-area input[type="text"] {
    flex: 1; padding: 10px 14px; font-size: 13.5px; font-family: inherit;
    background: rgba(255, 255, 255, .9);
    border: 1px solid rgba(15, 23, 42, .1); border-radius: 12px; outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.apf-input-area input[type="text"]:focus {
    border-color: var(--apf-color);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--apf-color) 18%, transparent);
}
.apf-input-area > button {
    width: 40px; height: 40px; border-radius: 11px; border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    transition: opacity .15s ease, background .15s ease;
}
.apf-input-area > button svg { width: 18px; height: 18px; fill: currentColor; }
#apf-send { background: var(--apf-color); color: var(--apf-text); }
#apf-send:disabled { opacity: .5; cursor: default; }
.apf-attach-btn { background: rgba(255, 255, 255, .8); color: var(--apf-muted); border: 1px solid rgba(15, 23, 42, .08) !important; }
.apf-attach-btn:hover { background: #eef0f3; }

/* ── 11. Footer ── */
.apf-footer { padding: 6px 16px; text-align: center; font-size: 10px; color: var(--apf-muted); flex-shrink: 0; }
.apf-footer .apf-email-link, .apf-tr-email { color: var(--apf-color); cursor: pointer; text-decoration: underline; }

/* ── 12. Overlays: product page + history (full-panel slide-overs) ── */
.apf-overlay {
    position: absolute; inset: 0; z-index: 50;
    background: rgba(255, 255, 255, .92);
    -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
    display: flex; flex-direction: column;
    border-radius: var(--apf-radius);
    animation: apf-slide-in .22s ease;
}
@keyframes apf-slide-in { from { transform: translateX(28px); opacity: 0; } to { transform: none; opacity: 1; } }
.apf-overlay-header {
    display: flex; align-items: center; gap: 10px; padding: 12px 14px; flex-shrink: 0;
    background: rgba(255, 255, 255, .7); border-bottom: 1px solid var(--apf-hairline);
    border-radius: var(--apf-radius) var(--apf-radius) 0 0;
}
.apf-overlay-header strong { font-size: 14px; color: var(--apf-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.apf-overlay-back {
    width: 32px; height: 32px; border: 0; border-radius: 8px; background: rgba(15, 23, 42, .06);
    font-size: 20px; line-height: 1; cursor: pointer; flex-shrink: 0; color: var(--apf-ink);
}
.apf-overlay-back:hover { background: rgba(15, 23, 42, .12); }
.apf-overlay-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.apf-overlay-spinner {
    width: 28px; height: 28px; margin: 40px auto; border: 3px solid rgba(15, 23, 42, .1);
    border-top-color: var(--apf-color); border-radius: 50%;
    animation: apf-spin .8s linear infinite;
}
@keyframes apf-spin { to { transform: rotate(360deg); } }

.apf-ov-hero { background: rgba(248, 250, 252, .8); display: flex; justify-content: center; padding: 14px; }
.apf-ov-hero img { max-width: 100%; max-height: 170px; object-fit: contain; }
.apf-ov-thumbs { display: flex; gap: 8px; padding: 0 14px 10px; overflow-x: auto; }
.apf-ov-thumbs img {
    width: 48px; height: 48px; object-fit: cover; border-radius: 8px;
    border: 2px solid transparent; cursor: pointer; flex-shrink: 0;
}
.apf-ov-thumbs img.active { border-color: var(--apf-color); }
.apf-ov-main { padding: 14px; }
.apf-ov-brand { font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--apf-muted); }
.apf-ov-name { font-size: 16px; font-weight: 700; color: var(--apf-ink); margin: 4px 0 6px; line-height: 1.3; }
.apf-ov-price { font-size: 20px; font-weight: 800; color: var(--apf-color); }
.apf-ov-price span { font-size: 12px; font-weight: 500; color: var(--apf-muted); }
.apf-ov-stock { font-size: 12.5px; font-weight: 600; margin-top: 4px; }
.apf-ov-stock.in { color: #15803d; }
.apf-ov-stock.out { color: #6366f1; }
.apf-ov-desc { font-size: 13px; color: #374151; line-height: 1.55; margin-top: 10px; }
.apf-ov-section { padding: 0 14px 14px; }
.apf-ov-section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--apf-muted); margin: 8px 0 6px; }
.apf-ov-specs { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.apf-ov-specs td { padding: 6px 4px; border-bottom: 1px solid rgba(15, 23, 42, .05); }
.apf-ov-specs td:first-child { color: var(--apf-muted); width: 45%; }
.apf-ov-sheet { display: block; font-size: 13px; color: var(--apf-color); padding: 5px 0; text-decoration: none; }
.apf-ov-related {
    display: flex; justify-content: space-between; align-items: center; width: 100%;
    padding: 10px 12px; margin-bottom: 6px; border: 1px solid var(--apf-hairline); border-radius: 10px;
    background: rgba(255, 255, 255, .9); cursor: pointer; font-size: 13px; text-align: left; font-family: inherit;
}
.apf-ov-related:hover { border-color: var(--apf-color); }
.apf-ov-actions {
    position: absolute; bottom: 0; left: 0; right: 0; display: flex; gap: 8px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, .85);
    -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
    border-top: 1px solid var(--apf-hairline);
    border-radius: 0 0 var(--apf-radius) var(--apf-radius);
}
.apf-ov-btn {
    flex: 1; padding: 10px 8px; border-radius: 10px; font-size: 12.5px; font-weight: 700;
    border: 1px solid var(--apf-color); color: var(--apf-color);
    background: rgba(255, 255, 255, .9); cursor: pointer; text-align: center; text-decoration: none; font-family: inherit;
}
.apf-ov-btn-primary { background: var(--apf-color); color: var(--apf-text); }
.apf-ov-btn:hover { filter: brightness(.94); }

.apf-history-item {
    display: flex; flex-direction: column; gap: 3px; width: calc(100% - 20px);
    margin: 8px 10px 0; padding: 11px 13px; border: 1px solid var(--apf-hairline); border-radius: 12px;
    background: rgba(255, 255, 255, .9); cursor: pointer; text-align: left; font-family: inherit;
}
.apf-history-item:hover { border-color: var(--apf-color); background: rgba(248, 250, 255, .95); }
.apf-history-preview { font-size: 13px; font-weight: 600; color: var(--apf-ink); }
.apf-history-meta { font-size: 11.5px; color: var(--apf-muted); }

/* ── 13. Responsive / a11y / fallbacks ── */
@media (max-width: 768px) {
    .apf-toggle--pill { padding: 0; width: var(--apf-bubble, 60px); border-radius: 50%; justify-content: center; }
    .apf-toggle--pill .apf-toggle-text { display: none; }
}
@media (max-width: 480px) {
    .apf-panel { width: calc(100vw - 16px) !important; height: calc(100vh - 90px) !important; border-radius: 16px 16px 0 0; }
}
@media (prefers-reduced-motion: reduce) {
    .apf-panel, .apf-msg, .apf-overlay, .apf-teaser { animation: none !important; transition: none !important; }
    .apf-panel.apf-busy .apf-statusline { animation: none; opacity: .8; }
}
#apf-widget-root button:focus-visible, #apf-widget-root a:focus-visible, #apf-widget-root input:focus-visible {
    outline: 2px solid var(--apf-color); outline-offset: 2px;
}
