/* =============================================================================
   AED Leader AI Chatbot — Widget Styles
   CSS variables are overridden by JS from config.
   ============================================================================= */

#aed-chatbot-root {
    --aed-primary: #0B5ED7;
    --aed-primary-dk: #0950b8;
    --aed-primary-light: rgba(11, 94, 215, 0.08);
    --aed-accent: #198754;
    --aed-accent-dk: #146c43;
    --aed-sale: #dc3545;
    --aed-sale-bg: rgba(220, 53, 69, 0.08);
    --aed-black: #1a1a1a;
    --aed-text: #1a1a1a;
    --aed-text-secondary: #555;
    --aed-muted: #6b7280;
    --aed-bg: #f5f6f8;
    --aed-bg-user: #0B5ED7;
    --aed-bg-bot: #ffffff;
    --aed-border: #e5e7eb;
    --aed-radius: 16px;
    --aed-radius-sm: 10px;
    --aed-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    --aed-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --aed-z: 9999;

    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: var(--aed-z);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    box-sizing: border-box;
}

#aed-chatbot-root.aed-pos-left {
    right: auto;
    left: 24px;
}

#aed-chatbot-root *,
#aed-chatbot-root *::before,
#aed-chatbot-root *::after {
    box-sizing: inherit;
}

/* ── Host-theme reset ────────────────────────────────────────────────────────
   WP / WooCommerce themes ship `body button { ... }` rules with specificity
   (0,0,1,1 = 11) that beats plain class selectors like `.aed-chip-btn`
   (0,0,1,0 = 10). They also commonly add `button::after { content: "›" }` to
   inject chevron icons into every button.

   This reset uses `#aed-chatbot-root` prefix to win on font/text and to
   nullify the chevron pseudo-elements. We DON'T reset background / border /
   color / padding here — that would clobber our own ID-styled buttons (e.g.
   `#aed-chat-toggle`). Class-selector buttons that need specificity above
   the theme are bumped to `#aed-chatbot-root .aed-*` individually below. */

#aed-chatbot-root button,
#aed-chatbot-root input,
#aed-chatbot-root textarea {
    font-family: inherit;
    font-size: inherit;
    font-weight: inherit;
    line-height: normal;
    letter-spacing: normal;
    text-transform: none;
    text-shadow: none;
    box-shadow: none;
    text-decoration: none;
}

#aed-chatbot-root button::before,
#aed-chatbot-root button::after {
    content: none !important;
    display: none !important;
}

#aed-chatbot-root svg {
    display: inline-block;
    vertical-align: middle;
    fill: currentColor;
}

/* ── Toggle button ──────────────────────────────────────────────────────────── */

#aed-chat-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: var(--aed-primary);
    color: #fff;
    border: none;
    border-radius: 50px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(11, 94, 215, 0.35);
    transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
    white-space: nowrap;
    font-family: inherit;
    position: relative;
}

#aed-chat-toggle:hover {
    background: var(--aed-primary-dk);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(11, 94, 215, 0.4);
}

#aed-chat-toggle:focus-visible {
    outline: 3px solid var(--aed-primary);
    outline-offset: 2px;
}

.aed-btn-label {
    letter-spacing: 0.01em;
}

/* When open — circle with X */
#aed-chat-toggle[aria-expanded="true"] {
    width: 52px;
    height: 52px;
    padding: 0;
    border-radius: 50%;
    justify-content: center;
}

#aed-chat-toggle[aria-expanded="true"] .aed-btn-label {
    display: none;
}

/* ── Chat panel ─────────────────────────────────────────────────────────────── */

#aed-chat-panel {
    position: absolute;
    bottom: 64px;
    right: 0;
    width: 400px;
    height: 600px;
    max-height: calc(100vh - 100px);
    background: var(--aed-bg);
    border-radius: var(--aed-radius);
    box-shadow: var(--aed-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--aed-border);
    animation: aed-slide-up 0.25s ease-out;
}

#aed-chat-panel[hidden] {
    display: none !important;
}

@keyframes aed-slide-up {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Left position */
#aed-chatbot-root.aed-pos-left #aed-chat-panel {
    right: auto;
    left: 0;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */

.aed-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--aed-primary);
    color: #fff;
    flex-shrink: 0;
}

.aed-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.aed-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.aed-header-avatar svg {
    opacity: 0.9;
}

.aed-header-name {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
}

.aed-header-status {
    font-size: 12px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 5px;
}

.aed-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    display: inline-block;
    animation: aed-pulse 2s infinite;
}

@keyframes aed-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

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

.aed-reset-btn,
.aed-header-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    opacity: 0.8;
    transition: opacity 0.15s, background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.aed-reset-btn:hover,
.aed-header-close:hover {
    opacity: 1;
    background: rgba(255,255,255,0.15);
}

.aed-reset-btn svg,
.aed-header-close svg,
#aed-chat-toggle svg {
    pointer-events: none;
}

#aed-reset {
    display: none;
}

#aed-reset.aed-visible {
    display: flex;
}

/* ── Messages area ──────────────────────────────────────────────────────────── */

.aed-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.aed-messages::-webkit-scrollbar {
    width: 5px;
}

.aed-messages::-webkit-scrollbar-track {
    background: transparent;
}

.aed-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

/* ── Message bubbles ────────────────────────────────────────────────────────── */

.aed-msg {
    display: flex;
    gap: 8px;
    max-width: 88%;
    animation: aed-msg-in 0.2s ease-out;
}

.aed-msg-bot {
    max-width: 95%;
}

@keyframes aed-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.aed-msg-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.aed-msg-bot {
    align-self: flex-start;
}

.aed-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--aed-primary-light);
    color: var(--aed-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.aed-msg-user .aed-msg-avatar {
    display: none;
}

.aed-msg-bubble {
    padding: 10px 14px;
    border-radius: var(--aed-radius-sm);
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
}

.aed-msg-user .aed-msg-bubble {
    background: var(--aed-bg-user);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.aed-msg-bot .aed-msg-bubble {
    background: var(--aed-bg-bot);
    color: var(--aed-text);
    border: 1px solid var(--aed-border);
    border-bottom-left-radius: 4px;
}

.aed-msg-content {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}

/* Markdown inside bot messages */
.aed-msg-bot .aed-msg-bubble strong {
    font-weight: 600;
}

.aed-msg-bot .aed-msg-bubble a {
    color: var(--aed-primary);
    text-decoration: underline;
    text-decoration-color: rgba(11, 94, 215, 0.3);
    transition: text-decoration-color 0.15s;
}

.aed-msg-bot .aed-msg-bubble a:hover {
    text-decoration-color: var(--aed-primary);
}

.aed-msg-bot .aed-msg-bubble ul,
.aed-msg-bot .aed-msg-bubble ol {
    margin: 6px 0;
    padding-left: 20px;
}

.aed-msg-bot .aed-msg-bubble li {
    margin-bottom: 3px;
}

/* ── Product cards ──────────────────────────────────────────────────────────── */

.aed-products-wrapper {
    position: relative;
    margin-top: 8px;
}

.aed-scroll-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 6px 0 2px;
}

.aed-scroll-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid var(--aed-border);
    background: #fff;
    color: #374151;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    padding: 0;
    transition: background 0.15s, border-color 0.15s;
}
.aed-scroll-btn:hover { background: var(--aed-bg); border-color: #9ca3af; }

.aed-products {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    scroll-behavior: smooth;
    padding: 10px 2px 6px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
}

.aed-products::-webkit-scrollbar {
    display: none;
}
.aed-products {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.aed-product-card {
    min-width: 190px;
    max-width: 210px;
    background: #fff;
    border: 1px solid var(--aed-border);
    border-radius: var(--aed-radius-sm);
    overflow: hidden;
    flex-shrink: 0;
    scroll-snap-align: start;
    transition: box-shadow 0.2s;
    display: flex;
    flex-direction: column;
}

.aed-product-card:hover {
    box-shadow: var(--aed-shadow-sm);
}

.aed-product-img {
    width: 100%;
    height: 110px;
    object-fit: contain;
    background: #fafafa;
    padding: 8px;
}

.aed-product-body {
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.aed-product-brand {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--aed-muted);
}

.aed-product-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--aed-text);
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.aed-product-price {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.aed-price-current {
    font-size: 16px;
    font-weight: 700;
    color: var(--aed-text);
}

.aed-price-original {
    font-size: 13px;
    color: var(--aed-muted);
    text-decoration: line-through;
}

.aed-badge-sale {
    font-size: 10px;
    font-weight: 700;
    background: var(--aed-sale-bg);
    color: var(--aed-sale);
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}


.aed-product-reason {
    font-size: 12px;
    color: var(--aed-text-secondary);
    font-style: italic;
    line-height: 1.35;
    margin-top: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.aed-product-actions {
    padding: 8px 12px 10px;
    display: flex;
    gap: 6px;
    margin-top: auto;
}

.aed-btn-view {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 7px 12px;
    font-size: 12px;
    font-weight: 600;
    color: #fff;
    background: var(--aed-primary);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
    font-family: inherit;
}

.aed-btn-view:hover {
    background: var(--aed-primary-dk);
}

/* ── Upsell section ─────────────────────────────────────────────────────────── */

.aed-upsell {
    margin-top: 8px;
    padding: 10px 12px;
    background: var(--aed-primary-light);
    border-radius: var(--aed-radius-sm);
    border: 1px solid rgba(11, 94, 215, 0.12);
}

.aed-upsell-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--aed-primary);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.aed-upsell .aed-products {
    padding: 0 0 4px;
}

.aed-upsell .aed-product-card {
    min-width: 200px;
    max-width: 210px;
}

.aed-upsell .aed-product-img {
    height: 90px;
}

/* ── Typing indicator ───────────────────────────────────────────────────────── */

.aed-typing {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px 8px;
}

.aed-typing[hidden] {
    display: none !important;
}

.aed-typing-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--aed-primary-light);
    color: var(--aed-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.aed-typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--aed-bg-bot);
    border: 1px solid var(--aed-border);
    padding: 8px 14px;
    border-radius: var(--aed-radius-sm);
    border-bottom-left-radius: 4px;
}

.aed-typing-dots span {
    width: 7px;
    height: 7px;
    background: #9ca3af;
    border-radius: 50%;
    animation: aed-bounce 1.2s infinite;
}

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

@keyframes aed-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-5px); }
}

/* ── Suggestion chips ───────────────────────────────────────────────────────── */

.aed-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 16px 10px;
    flex-shrink: 0;
}

.aed-chips.aed-hidden {
    display: none;
}

#aed-chatbot-root .aed-chip-btn {
    padding: 7px 14px;
    font-size: 13px;
    color: var(--aed-primary);
    background: #fff;
    border: 1px solid var(--aed-border);
    border-radius: 20px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    font-family: inherit;
    white-space: nowrap;
}

#aed-chatbot-root .aed-chip-btn:hover {
    background: var(--aed-primary-light);
    border-color: var(--aed-primary);
}

/* ── Info card (Support / Inquiry chip output) ──────────────────────────────── */
/* Rendered as a bot message bubble — same .aed-msg-content wrapper as text
   bubbles, but with structured content: title + body lines + optional CTA. */

.aed-info-card {
    background: var(--aed-bg-bot);
    border: 1px solid var(--aed-border);
    border-radius: var(--aed-radius-sm);
    border-bottom-left-radius: 4px;
    padding: 14px 16px;
    box-shadow: var(--aed-shadow-sm);
    max-width: 100%;
}

.aed-info-card-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--aed-text);
    margin-bottom: 8px;
}

.aed-info-card-body {
    font-size: 13.5px;
    color: var(--aed-text-secondary);
    line-height: 1.55;
}

.aed-info-card-line {
    margin-bottom: 4px;
}

.aed-info-card-line:last-child {
    margin-bottom: 0;
}

.aed-info-card-cta {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    padding: 8px 14px;
    background: var(--aed-primary);
    color: #fff;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.15s;
}

.aed-info-card-cta:hover {
    background: var(--aed-primary-dk);
}

.aed-info-card-cta svg {
    flex-shrink: 0;
}

/* ── Input area ─────────────────────────────────────────────────────────────── */

.aed-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid var(--aed-border);
    background: #fff;
    flex-shrink: 0;
}

.aed-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--aed-border);
    border-radius: 20px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
    resize: none;
    outline: none;
    max-height: 100px;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    transition: border-color 0.15s;
    background: var(--aed-bg);
    color: var(--aed-text);
}

.aed-input:focus {
    border-color: var(--aed-primary);
    background: #fff;
}

.aed-input::-webkit-scrollbar {
    display: none;
}

.aed-input::placeholder {
    color: #9ca3af;
}

#aed-chatbot-root .aed-send-btn {
    width: 38px;
    height: 38px;
    background: var(--aed-primary);
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.1s;
}

#aed-chatbot-root .aed-send-btn:hover {
    background: var(--aed-primary-dk);
}

#aed-chatbot-root .aed-send-btn:active {
    transform: scale(0.94);
}

#aed-chatbot-root .aed-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── Footer ─────────────────────────────────────────────────────────────────── */

.aed-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 14px 8px;
    font-size: 11px;
    color: var(--aed-muted);
    background: #fff;
    flex-shrink: 0;
}

.aed-footer strong {
    font-weight: 600;
}

.aed-debug-toggle {
    background: none;
    border: none;
    color: var(--aed-muted);
    cursor: pointer;
    padding: 2px;
    opacity: 0.5;
    transition: opacity 0.15s;
    display: flex;
    align-items: center;
}

.aed-debug-toggle:hover {
    opacity: 1;
}

.aed-debug-toggle.aed-active {
    opacity: 1;
    color: var(--aed-primary);
}

/* ── Debug panel ───────────────────────────────────────────────────────────── */

.aed-debug-panel {
    background: #1a1a2e;
    color: #e0e0e0;
    font-family: "SF Mono", "Fira Code", "Consolas", monospace;
    font-size: 11px;
    line-height: 1.5;
    max-height: 220px;
    overflow-y: auto;
    flex-shrink: 0;
    border-top: 2px solid #0B5ED7;
}

.aed-debug-panel[hidden] {
    display: none !important;
}

.aed-debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: #12122a;
    font-weight: 600;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #8888aa;
    position: sticky;
    top: 0;
}

.aed-debug-dim {
    font-weight: 400;
    color: #6b6b8a;
}

.aed-debug-content {
    padding: 6px 10px;
}

.aed-debug-empty {
    color: #6b6b8a;
    font-style: italic;
}

.aed-debug-turn {
    border-bottom: 1px solid #2a2a4a;
    padding: 6px 0;
}

.aed-debug-turn:last-child {
    border-bottom: none;
}

.aed-debug-turn-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.aed-debug-label {
    color: #8888aa;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.aed-debug-time {
    color: #4ade80;
    font-size: 10px;
}

.aed-debug-row {
    display: flex;
    gap: 6px;
    padding: 1px 0;
}

.aed-debug-key {
    color: #7c8aff;
    min-width: 80px;
    flex-shrink: 0;
}

.aed-debug-val {
    color: #e0e0e0;
    word-break: break-word;
}

.aed-debug-val.aed-intent {
    color: #fbbf24;
    font-weight: 600;
}

.aed-debug-val.aed-warn {
    color: #fb923c;
}

.aed-debug-val.aed-good {
    color: #4ade80;
}

.aed-debug-val.aed-bad {
    color: #f87171;
}

.aed-debug-filters {
    color: #c084fc;
}

/* ── Error message ──────────────────────────────────────────────────────────── */

.aed-error {
    padding: 10px 14px;
    background: var(--aed-sale-bg);
    border: 1px solid rgba(220, 53, 69, 0.2);
    border-radius: var(--aed-radius-sm);
    color: var(--aed-sale);
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.aed-error-retry {
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--aed-sale);
    background: #fff;
    border: 1px solid var(--aed-sale);
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
    transition: background 0.15s;
}

.aed-error-retry:hover {
    background: var(--aed-sale-bg);
}

/* ── Responsive — mobile full-screen ────────────────────────────────────────── */

@media (max-width: 480px) {
    #aed-chatbot-root {
        bottom: 16px;
        right: 16px;
    }

    #aed-chat-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        border: none;
    }

    .aed-header {
        border-radius: 0;
    }

    .aed-product-card {
        min-width: 190px;
        max-width: 210px;
    }
}

@media (max-width: 768px) and (min-width: 481px) {
    #aed-chat-panel {
        width: 360px;
        height: 550px;
    }
}
