/* ── Reset & Base ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #252525;
    --surface: #2a2a2a;
    --border: #333;
    --text: #e8e8e8;
    --text-secondary: #999;
    --text-muted: #666;
    --accent: #6c5ce7;
    --accent-light: #a29bfe;
    --accent-glow: rgba(108, 92, 231, 0.15);
    --success: #00b894;
    --warning: #fdcb6e;
    --danger: #e17055;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --sidebar-w: 280px;
    --header-h: 56px;
}

/* Light theme overrides */
[data-theme="light"] {
    --bg: #ffffff;
    --bg-secondary: #f7f7f9;
    --bg-tertiary: #eef0f2;
    --surface: #ffffff;
    --border: #e1e3e8;
    --text: #121212;
    --text-secondary: #444;
    --text-muted: #667085;
    --accent: #6c5ce7;
    --accent-light: #584ae0;
    --accent-glow: rgba(88, 74, 224, 0.12);
    --shadow: 0 2px 10px rgba(16, 24, 40, 0.06);
}

html, body { height: 100%; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.6;
    overflow: auto;
}

button { cursor: pointer; border: none; background: none; color: inherit; font: inherit; }
a { color: var(--accent-light); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Theme toggle button */
.theme-toggle {
    position: fixed;
    left: 14px;
    bottom: 14px;
    z-index: 400;
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text);
    box-shadow: var(--shadow);
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.theme-toggle:hover { background: var(--surface); }
.theme-toggle svg { width: 18px; height: 18px; }

/* Site header */
.site-header {
    position: sticky;
    top: 0;
    z-index: 120;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}
.site-header-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
}
.site-brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; }
.site-brand:hover { text-decoration: none; }
.site-dot { color: var(--accent); }
.site-nav a { margin-left: 12px; color: var(--text-secondary); text-decoration: none; padding: 6px 10px; border-radius: var(--radius-sm); }
.site-nav a:hover { background: var(--surface); color: var(--text); }

/* ── Layout ───────────────────────────────────────────────────── */
#app {
    display: flex;
    height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────────── */
#sidebar {
    width: var(--sidebar-w);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: margin-left 0.25s ease;
}
#sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-w));
}
#sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 90;
}
#sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}
.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 18px;
}
.logo-icon {
    color: var(--accent);
    font-size: 22px;
}
.sidebar-header button {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
}
.sidebar-header button:hover { background: var(--surface); }
.sidebar-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
#btn-close-sidebar {
    display: none;
}

#conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.conv-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text-secondary);
    transition: background 0.15s;
    margin-bottom: 2px;
}
.conv-item:hover, .conv-item.active { background: var(--surface); color: var(--text); }
.sidebar-empty { padding: 20px 12px; color: var(--text-muted); font-size: 13px; }

.sidebar-footer {
    padding: 14px 16px;
    border-top: 1px solid var(--border);
}
.powered-by { font-size: 11px; color: var(--text-muted); }

/* ── Main Chat ────────────────────────────────────────────────── */
#chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

#chat-header {
    height: var(--header-h);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
#chat-header h1 { font-size: 16px; font-weight: 600; }
#btn-toggle-sidebar {
    height: 36px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
}
#btn-toggle-sidebar:hover { background: var(--surface); }
.toggle-label {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ── Messages ─────────────────────────────────────────────────── */
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

.message {
    max-width: 720px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    gap: 12px;
}
.message.user { flex-direction: row-reverse; }

.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}
.message.assistant .msg-avatar { background: var(--accent); color: #fff; }
.message.user .msg-avatar { background: var(--surface); color: var(--text-secondary); }

.msg-bubble {
    padding: 12px 16px;
    border-radius: var(--radius);
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
}
.message.assistant .msg-bubble {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
}
.message.user .msg-bubble {
    background: var(--accent);
    color: #fff;
    border: none;
}

/* ── Welcome ──────────────────────────────────────────────────── */
.welcome-message {
    max-width: 540px;
    margin: auto;
    text-align: center;
    padding: 40px 20px;
}
.welcome-icon {
    font-size: 48px;
    color: var(--accent);
    margin-bottom: 16px;
}
.welcome-message h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}
.welcome-message p {
    color: var(--text-secondary);
    margin-bottom: 24px;
}
.suggestions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}
.suggestion {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 13px;
    color: var(--text-secondary);
    transition: all 0.15s;
}
.suggestion:hover {
    border-color: var(--accent);
    color: var(--accent-light);
    background: var(--accent-glow);
}

/* ── Product Cards ────────────────────────────────────────────── */
.product-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.product-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
}
.product-card:hover {
    border-color: var(--accent);
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.card-img-wrap {
    position: relative;
    overflow: hidden;
    background: var(--bg-tertiary);
}
.card-img-wrap img {
    width: 100%;
    height: 180px;
    object-fit: cover;
    display: block;
    transition: transform 0.3s;
}
.product-card:hover .card-img-wrap img { transform: scale(1.05); }

.card-stock {
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 10px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.card-stock.in-stock { background: rgba(0, 184, 148, 0.9); color: #fff; }
.card-stock.out-stock { background: rgba(225, 112, 85, 0.9); color: #fff; }

.product-card .card-body {
    padding: 14px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.card-top { flex: 1; }

.product-card .card-brand {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--accent-light);
    margin-bottom: 4px;
}

.product-card .card-name {
    font-weight: 600;
    font-size: 14px;
    line-height: 1.4;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-card .card-desc {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 10px;
}

.card-bottom { margin-top: auto; }

.card-price-row {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 8px;
}
.product-card .card-price {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent-light);
}

.card-store-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 10px;
}
.card-store-logo {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    object-fit: cover;
}
.card-store-name {
    font-size: 11px;
    color: var(--text-muted);
}

.product-card .card-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    padding: 9px 12px;
    background: var(--accent);
    color: #fff;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    transition: background 0.15s;
    text-decoration: none;
}
.product-card .card-btn:hover {
    background: var(--accent-light);
    color: var(--bg);
    text-decoration: none;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 500;
}
.modal-overlay.active { display: flex; }
.modal-panel {
    width: 96%;
    max-width: 920px;
    max-height: 88vh;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: grid;
    grid-template-rows: auto 1fr auto;
    overflow: hidden;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-close {
    width: 34px; height: 34px; display: grid; place-items: center;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
}
.modal-close:hover { background: var(--surface); color: var(--text); }
.modal-body {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 16px;
    padding: 16px;
    overflow: auto;
}
@media (max-width: 900px) {
    .modal-body { grid-template-columns: 1fr; }
}
.modal-gallery {
    position: relative;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 320px;
}
.modal-gallery img {
    width: 100%;
    height: 100%;
    max-height: 540px;
    object-fit: contain;
    background: var(--bg-tertiary);
}
.modal-nav {
    position: absolute; top: 50%; left: 0; right: 0;
    display: flex; justify-content: space-between;
    transform: translateY(-50%);
    pointer-events: none;
}
.modal-nav button {
    pointer-events: auto;
    width: 36px; height: 36px; border-radius: 50%;
    display: grid; place-items: center;
    background: rgba(0,0,0,0.35);
    color: #fff;
}
.modal-thumbs {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
    gap: 6px; margin-top: 8px;
}
.modal-thumbs img {
    width: 100%; height: 56px; object-fit: cover; border-radius: 6px;
    border: 1px solid var(--border); cursor: pointer;
}
.modal-info {
    display: flex; flex-direction: column; gap: 10px;
}
.modal-meta { font-size: 12px; color: var(--text-secondary); }
.modal-actions { display: flex; gap: 8px; margin-top: 6px; }
.modal-footer {
    padding: 12px 16px; border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: 8px;
}
.modal-chips .chip {
    display:inline-block; font-size:11px; padding:4px 8px; border:1px solid var(--border);
    border-radius: 999px; color: var(--text-secondary); background: var(--bg);
}
.modal-header .modal-head-right { color: var(--accent-light); }
.modal-thumbs img.thumb-active { outline: 2px solid var(--accent); }

/* ── Input Area ───────────────────────────────────────────────── */
#chat-form {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.input-wrapper {
    max-width: 720px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    transition: border-color 0.15s;
}
.input-wrapper:focus-within { border-color: var(--accent); }
#btn-attach-image {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: var(--text-secondary);
    flex-shrink: 0;
}
#btn-attach-image:hover {
    background: var(--surface);
    color: var(--accent-light);
}

#chat-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    resize: none;
    max-height: 150px;
    outline: none;
}
#chat-input::placeholder { color: var(--text-muted); }

#btn-send {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    transition: opacity 0.15s;
    flex-shrink: 0;
}
#btn-send:disabled { opacity: 0.3; cursor: default; }
#btn-send:not(:disabled):hover { background: var(--accent-light); color: var(--bg); }

.disclaimer {
    max-width: 720px;
    margin: 6px auto 0;
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
}
.image-chip {
    width: 58px;
    height: 58px;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    background: transparent;
    flex-shrink: 0;
}
.image-chip-thumb {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
}
#image-chip-preview {
    width: 56px;
    height: 56px;
    object-fit: cover;
}
#btn-remove-image {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
    font-size: 14px;
    line-height: 1;
    display: grid;
    place-items: center;
    padding: 0;
}

/* ── Cart Icon in Header ──────────────────────────────────────── */
.cart-icon-btn {
    margin-left: auto;
    position: relative;
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: background 0.15s, color 0.15s;
}
.cart-icon-btn:hover {
    background: var(--surface);
    color: var(--accent-light);
}
.cart-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    display: grid;
    place-items: center;
    padding: 0 4px;
    line-height: 1;
}

/* ── Cart Drawer ─────────────────────────────────────────────── */
.cart-drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 200;
}
.cart-drawer-overlay.active {
    opacity: 1;
    pointer-events: auto;
}
.cart-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 380px;
    max-width: 100vw;
    height: 100vh;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    z-index: 210;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.25s ease;
}
.cart-drawer.open {
    transform: translateX(0);
}
.cart-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.cart-drawer-header h2 {
    font-size: 16px;
    font-weight: 600;
}
.cart-drawer-header h2 span {
    color: var(--text-muted);
    font-weight: 400;
}
.cart-drawer-header button {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
}
.cart-drawer-header button:hover { background: var(--surface); }

.cart-drawer-items {
    flex: 1;
    overflow-y: auto;
    padding: 12px 20px;
}
.cart-drawer-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 0;
    font-size: 14px;
}

.cart-drawer-item {
    display: flex;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    align-items: center;
}
.cart-drawer-item-img {
    width: 52px;
    height: 52px;
    border-radius: 6px;
    object-fit: cover;
    background: var(--bg-tertiary);
    flex-shrink: 0;
}
.cart-drawer-item-info {
    flex: 1;
    min-width: 0;
}
.cart-drawer-item-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cart-drawer-item-meta {
    font-size: 11px;
    color: var(--text-muted);
}
.cart-drawer-item-price {
    font-size: 14px;
    font-weight: 700;
    color: var(--accent-light);
    white-space: nowrap;
}
.cart-drawer-item-remove {
    color: var(--text-muted);
    padding: 4px;
    transition: color 0.15s;
}
.cart-drawer-item-remove:hover { color: var(--danger); }

.cart-drawer-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}
.cart-drawer-total {
    display: flex;
    justify-content: space-between;
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 16px;
}
.btn-full {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.15s;
}
.btn.btn-primary { background: var(--accent); color: #fff; }
.btn.btn-primary:hover { background: var(--accent-light); color: var(--bg); text-decoration: none; }
.btn.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn.btn-secondary:hover { background: var(--bg-tertiary); text-decoration: none; }

/* ── Add to Cart button on product cards ─────────────────────── */
.card-add-cart {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    padding: 9px 12px;
    background: var(--success);
    color: #fff;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    transition: background 0.15s;
    cursor: pointer;
    margin-top: 6px;
    border: none;
}
.card-add-cart:hover {
    background: #00d9a7;
}
.card-add-cart.added {
    background: var(--surface);
    color: var(--success);
}

/* ── Typing indicator ─────────────────────────────────────────── */
.typing-indicator { display: flex; gap: 4px; padding: 8px 0; }
.typing-indicator span {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: blink 1.4s infinite both;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }

/* ── Scrollbar ────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 1024px) {
    #sidebar {
        position: fixed;
        z-index: 100;
        height: 100%;
        top: 0;
        left: 0;
        margin-left: 0;
        transition: transform 0.25s ease;
    }
    #sidebar.collapsed {
        margin-left: 0;
        transform: translateX(calc(-1 * var(--sidebar-w)));
    }
    #btn-close-sidebar {
        display: grid;
        place-items: center;
    }
    .product-cards { grid-template-columns: 1fr; }
}
