:root {
    --bg: #f7f8fa;
    --surface: #ffffff;
    --border: #e3e5e9;
    --text: #1d2129;
    --text-muted: #5f6571;
    --primary: #2563eb;
    --primary-hover: #1d4fd8;
    --bubble-human: #dcf8c6;
    --bubble-ai: #f1f0f0;
    --badge-lead-bg: #dcfce7;
    --badge-lead-fg: #166534;
    --badge-complaint-bg: #fee2e2;
    --badge-complaint-fg: #991b1b;
    --badge-none-bg: #e5e7eb;
    --badge-none-fg: #4b5563;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }
html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.container { max-width: 1200px; margin: 0 auto; padding: 24px; }

/* topnav */
.topnav { background: var(--surface); border-bottom: 1px solid var(--border); }
.topnav-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 10px 24px;
    display: flex;
    align-items: center;
    gap: 24px;
}
.brand { font-weight: 600; color: var(--text); text-decoration: none; font-size: 15px; }
.topnav-links { display: flex; gap: 18px; flex: 1; }
.topnav-links a { color: var(--text-muted); text-decoration: none; font-weight: 500; }
.topnav-links a:hover { color: var(--text); }
.topnav-logout { margin: 0; }

/* buttons */
.btn {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    padding: 7px 14px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    font-weight: 500;
}
.btn:hover { background: #f0f1f4; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: #f0f1f4; color: var(--text); }

/* headings */
.page-title { margin: 0 0 16px 0; font-size: 22px; font-weight: 600; }

/* card */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    box-shadow: var(--shadow);
}
.card-title { margin: 0 0 12px 0; font-size: 15px; font-weight: 600; }

/* login */
.login-wrap { min-height: 70vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 340px; }
.login-title { margin: 0; font-size: 18px; font-weight: 600; }
.login-sub { margin: 4px 0 18px 0; color: var(--text-muted); font-size: 13px; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-muted); }
.login-form input {
    padding: 8px 10px;
    font-size: 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
}
.login-form input:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }

.alert { padding: 8px 12px; border-radius: 6px; font-size: 13px; margin-bottom: 12px; }
.alert-error { background: #fee2e2; color: #991b1b; }

/* tiles */
.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}
.tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px 18px;
    box-shadow: var(--shadow);
}
.tile-label { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.tile-value { font-size: 26px; font-weight: 600; margin-top: 4px; }
.tile-sub { color: var(--text-muted); font-size: 11px; margin-top: 2px; }
.tile-lead .tile-value { color: var(--badge-lead-fg); }
.tile-complaint .tile-value { color: var(--badge-complaint-fg); }

/* charts */
.chart-card { margin-bottom: 24px; }
.volume-chart { display: block; max-width: 100%; }
.chart-bar { fill: var(--primary); }
.chart-bar:hover { fill: var(--primary-hover); }
.chart-grid { stroke: #eef0f3; stroke-width: 1; }
.chart-axis { stroke: #c8ccd2; stroke-width: 1; }
.chart-tick { fill: var(--text-muted); font-size: 10px; }
.chart-tick-x { font-size: 10px; }

/* products */
.product-list { margin: 0; padding-left: 22px; }
.product-list li { padding: 4px 0; display: flex; justify-content: space-between; gap: 12px; }
.product-name { flex: 1; }
.product-count {
    background: #eef2f7;
    color: var(--text-muted);
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
}

/* filter bar */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}
.filter-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-muted); min-width: 140px; flex: 1; }
.filter-field input, .filter-field select {
    padding: 6px 8px;
    font-size: 13px;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: var(--surface);
    color: var(--text);
}

/* table */
.results-meta { color: var(--text-muted); font-size: 12px; margin-bottom: 8px; }
.conversations-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
}
.conversations-table th, .conversations-table td {
    padding: 9px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    vertical-align: top;
}
.conversations-table th { background: #fafbfc; font-weight: 600; color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.conversations-table tr:last-child td { border-bottom: none; }
.col-session { font-family: ui-monospace, SFMono-Regular, monospace; font-size: 12px; white-space: nowrap; }
.col-session a { color: var(--primary); text-decoration: none; }
.col-session a:hover { text-decoration: underline; }
.col-preview { color: var(--text-muted); }
.col-msgs { width: 60px; text-align: right; }
.col-last { white-space: nowrap; color: var(--text-muted); width: 140px; }
.col-outcome { width: 110px; }

/* pagination */
.pagination { display: flex; justify-content: center; align-items: center; gap: 16px; margin: 16px 0; font-size: 13px; }
.pg-link { color: var(--primary); text-decoration: none; padding: 4px 10px; border-radius: 5px; }
.pg-link:hover { background: #eef2f7; }
.pg-disabled { color: var(--text-muted); cursor: default; }
.pg-disabled:hover { background: transparent; }
.pg-info { color: var(--text-muted); }

/* badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.badge-lead { background: var(--badge-lead-bg); color: var(--badge-lead-fg); }
.badge-complaint { background: var(--badge-complaint-bg); color: var(--badge-complaint-fg); }
.badge-none { background: var(--badge-none-bg); color: var(--badge-none-fg); }

/* detail */
.detail-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
.back-link { color: var(--text-muted); text-decoration: none; font-size: 12px; }
.back-link:hover { color: var(--text); }
.session-id { display: inline-block; margin-top: 4px; color: var(--text-muted); font-size: 11px; }
.detail-meta { display: flex; align-items: center; gap: 12px; }
.meta-item { color: var(--text-muted); font-size: 12px; }

.transcript {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    box-shadow: var(--shadow);
}
.bubble-row { display: flex; }
.bubble-human { justify-content: flex-end; }
.bubble-ai, .bubble-tool, .bubble-unknown { justify-content: flex-start; }
.bubble {
    max-width: 72%;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--bubble-ai);
    border: 1px solid var(--border);
}
.bubble-human .bubble { background: var(--bubble-human); border-color: #c4e8a8; }
.bubble-meta { display: flex; justify-content: space-between; gap: 12px; font-size: 10px; color: var(--text-muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.04em; }
.bubble-content { white-space: pre-wrap; word-break: break-word; font-size: 13px; }
.bubble-tools { margin-top: 8px; font-size: 12px; }
.bubble-tools summary { cursor: pointer; color: var(--text-muted); }
.tool-call { margin-top: 6px; padding: 6px 8px; background: rgba(0,0,0,0.04); border-radius: 5px; }
.tool-name { font-family: ui-monospace, SFMono-Regular, monospace; font-size: 11px; font-weight: 600; }
.tool-args { margin: 4px 0 0 0; font-size: 11px; white-space: pre-wrap; word-break: break-word; }

/* empty states */
.empty-state { padding: 24px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* cards spacing */
.products-card { margin-bottom: 24px; }

/* ── Dashboard time-window switcher ── */
.page-header {
    display: flex; justify-content: space-between; align-items: center;
    gap: 16px; flex-wrap: wrap; margin-bottom: 16px;
}
.page-header .page-title { margin: 0; }
.window-switch {
    display: inline-flex; gap: 0; background: var(--surface);
    border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
    box-shadow: var(--shadow);
}
.window-btn {
    padding: 8px 14px; font-size: 13px; color: var(--text-muted);
    text-decoration: none; background: transparent;
    border-right: 1px solid var(--border); transition: background 0.12s ease;
}
.window-btn:last-child { border-right: none; }
.window-btn:hover { background: #f4f5f7; color: var(--text); }
.window-btn-active {
    background: var(--primary); color: #fff !important; font-weight: 500;
}

/* ── Rendered bot-message HTML (markdown) ── */
.bubble-content p { margin: 0 0 8px; }
.bubble-content p:last-child { margin-bottom: 0; }
.bubble-content ul, .bubble-content ol { margin: 4px 0 8px 20px; padding: 0; }
.bubble-content li { margin: 2px 0; }
.bubble-content strong { font-weight: 600; }
.bubble-content em { font-style: italic; }
.bubble-content code {
    background: rgba(0,0,0,0.06); padding: 1px 5px; border-radius: 4px;
    font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.9em;
}
.bubble-content pre {
    background: rgba(0,0,0,0.06); padding: 8px 10px; border-radius: 6px;
    overflow-x: auto; font-size: 12px; margin: 6px 0;
}
.bubble-content a {
    color: #FF702C; text-decoration: none;
    border-bottom: 1px solid rgba(255,112,44,0.35);
}
.bubble-content a:hover { border-bottom-color: #FF702C; }

/* ── Product cards in transcript (no image) ── */
.bubble-products {
    display: flex; flex-direction: column; gap: 8px;
    margin-top: 10px;
}
.product-card {
    border: 1px solid var(--border); border-left: 3px solid #FF702C;
    border-radius: 8px; padding: 10px 12px; background: #fafafa;
}
.product-card-title {
    font-weight: 600; font-size: 14px; color: var(--text);
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.product-card-badge {
    font-size: 11px; font-weight: 600; color: #b35a00;
    background: #fff3e6; border: 1px solid #ffcf9a;
    border-radius: 999px; padding: 1px 8px; letter-spacing: 0.02em;
}
.product-card-price {
    font-size: 13px; color: var(--text-muted); margin-top: 2px;
}
.product-card-links {
    display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px;
}
.product-card-link {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 10px; border: 1px solid #FF702C; color: #FF702C;
    border-radius: 16px; text-decoration: none; font-size: 12px;
    background: #fff5f0; transition: all 0.12s ease;
}
.product-card-link:hover { background: #FF702C; color: #fff; }

/* ── Option chips (extracted from [OPTIONS_JSON]) ── */
.bubble-options {
    display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px;
}
.option-chip {
    padding: 4px 12px; border: 1px solid #FF702C; color: #FF702C;
    background: #fff5f0; border-radius: 16px; font-size: 12px;
    font-weight: 500; display: inline-block;
}
.option-chip-link {
    background: #FF702C; color: #fff; text-decoration: none;
}
.option-chip-link:hover { background: #e5611f; }
