/* ═══════════════════════════════════════
   Lead Flow — Lead Stage AI Experiment
   ═══════════════════════════════════════ */

html { height: 100%; margin: 0; padding: 0; }
body { margin:0; height:100%; overflow:hidden; display:flex; flex-direction:column; background:var(--background); font-family:var(--font-sans); color:var(--foreground); }

/* ═══ STAGE PROGRESS BAR ═══ */
.stage-bar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 12px 20px;
    z-index: 50;
    flex-shrink: 0;
}

.stage-bar-inner {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
}

.stage-bar .logo {
    font-weight: 800;
    font-size: 13px;
    color: var(--error, #dc2626);
    letter-spacing: 1.5px;
    margin-right: 16px;
    white-space: nowrap;
}

.stage-node {
    display: flex;
    align-items: center;
    gap: 5px;
    flex: 1;
}

.stage-dot {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    border: 2px solid var(--border);
    background: var(--card);
    color: var(--muted-fg);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
}

.stage-dot.active {
    transform: scale(1.1);
    box-shadow: var(--shadow-md);
}

.history-select {
    margin-left: 10px;
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
    outline: none;
    font-size: 13px;
    background: var(--card);
    color: var(--fg);
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.history-select:hover {
    border-color: #bbb;
}


.stage-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--muted-fg);
    transition: color 0.3s;
    white-space: nowrap;
}

.stage-connector {
    flex: 1;
    height: 2px;
    background: var(--border);
    min-width: 16px;
    position: relative;
    overflow: hidden;
}

.stage-connector .fill {
    position: absolute;
    inset: 0;
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.stage-connector.passed .fill { transform: scaleX(1); }

/* Stage colors */
.stage-1 .stage-dot.active { border-color: #3b82f6; color: #3b82f6; background: #eff6ff; }
.stage-1 .stage-label.active-label { color: #3b82f6; }
.stage-2 .stage-dot.active { border-color: #10b981; color: #10b981; background: #ecfdf5; }
.stage-2 .stage-label.active-label { color: #10b981; }
.stage-3 .stage-dot.active { border-color: #f59e0b; color: #f59e0b; background: #fffbeb; }
.stage-3 .stage-label.active-label { color: #f59e0b; }
.stage-4 .stage-dot.active { border-color: #ec4899; color: #ec4899; background: #fdf2f8; }
.stage-4 .stage-label.active-label { color: #ec4899; }
.stage-5 .stage-dot.active { border-color: #8b5cf6; color: #8b5cf6; background: #f5f3ff; }
.stage-5 .stage-label.active-label { color: #8b5cf6; }

.conn-1 .fill { background: #3b82f6; }
.conn-2 .fill { background: #10b981; }
.conn-3 .fill { background: #f59e0b; }
.conn-4 .fill { background: #ec4899; }

/* ═══ MAIN LAYOUT ═══ */
.app-container {
    flex: 1;
    min-height: 0;
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 340px;
    grid-template-rows: 1fr;
    gap: 0;
    max-width: 1100px;
    margin: 0 auto;
    overflow: hidden;
}

/* ═══ CHAT PANEL ═══ */
.chat-panel {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--card);
    min-height: 0;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.msg {
    max-width: 76%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.65;
    animation: msgIn 0.3s ease-out;
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.msg.human {
    align-self: flex-end;
    background: var(--foreground);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.msg.ai {
    align-self: flex-start;
    background: var(--background);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.msg.ai .stage-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

/* ── Markdown rendering inside AI messages ── */
.msg.ai .msg-text {
    line-height: 1.7;
}
.msg.ai .msg-text p { margin: 0 0 8px 0; }
.msg.ai .msg-text p:last-child { margin-bottom: 0; }
.msg.ai .msg-text ul,
.msg.ai .msg-text ol { margin: 4px 0 8px 0; padding-left: 20px; }
.msg.ai .msg-text li { margin-bottom: 3px; }
.msg.ai .msg-text strong { font-weight: 700; }
.msg.ai .msg-text em { font-style: italic; }
.msg.ai .msg-text code {
    background: var(--muted);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 12px;
    font-family: 'SF Mono', 'Consolas', monospace;
}
.msg.ai .msg-text pre {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px;
    overflow-x: auto;
    font-size: 11px;
    margin: 6px 0;
}
.msg.ai .msg-text a {
    color: var(--primary);
    text-decoration: underline;
}
.msg.ai .msg-text h1,
.msg.ai .msg-text h2,
.msg.ai .msg-text h3,
.msg.ai .msg-text h4 {
    margin: 10px 0 4px 0;
    font-size: 13px;
    font-weight: 700;
}
.msg.ai .msg-text blockquote {
    border-left: 3px solid var(--border);
    margin: 6px 0;
    padding: 4px 10px;
    color: var(--muted-fg);
    font-style: italic;
}
.msg.ai .msg-text hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 8px 0;
}

.typing-indicator {
    align-self: flex-start;
    display: none;
    gap: 5px;
    padding: 14px 20px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 16px;
}

.typing-indicator.show { display: flex; }

.typing-indicator span {
    width: 6px; height: 6px;
    background: var(--muted-fg);
    border-radius: 50%;
    animation: blink 1.4s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
    0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
    30% { opacity: 1; transform: scale(1); }
}

/* ═══ INPUT BAR ═══ */
.chat-input-bar {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    background: var(--card);
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--foreground);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,89,152,0.08); }
.chat-input::placeholder { color: var(--muted-fg); }

.send-btn {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
}

.send-btn:hover { background: var(--primary-hover); transform: scale(1.04); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ═══ DEBUG PANEL ═══ */
.debug-panel {
    background: var(--background);
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
}

.debug-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--muted-fg);
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.debug-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
}

.debug-card h4 {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted-fg);
    margin-bottom: 10px;
}

.debug-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    font-size: 12px;
}

.debug-row .label { color: var(--muted-fg); }
.debug-row .value { font-weight: 600; font-variant-numeric: tabular-nums; }

.debug-hints {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.debug-hint {
    font-size: 11px;
    color: var(--secondary-fg);
    padding: 6px 10px;
    background: var(--background);
    border-radius: 6px;
    border-left: 3px solid var(--border);
}

.debug-reasoning {
    font-size: 11px;
    color: var(--secondary-fg);
    line-height: 1.6;
    padding: 10px;
    background: var(--background);
    border-radius: 6px;
    font-style: italic;
}

.timing-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
}

.timing-cell {
    text-align: center;
    padding: 10px 4px;
    background: var(--background);
    border-radius: 8px;
}

.timing-cell .t-value {
    font-size: 18px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--foreground);
}

.timing-cell .t-label {
    font-size: 9px;
    color: var(--muted-fg);
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.confidence-bar-outer {
    width: 100%;
    height: 5px;
    background: var(--muted);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 6px;
}

.confidence-bar-inner {
    height: 100%;
    border-radius: 3px;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ═══ PIPELINE FLOW DIAGRAM (DAG) ═══ */
.flow-diagram {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    padding: 8px 0;
}

.flow-node {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-radius: 12px;
    border: 2px solid var(--border);
    background: var(--card);
    width: 100%;
    max-width: 260px;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.flow-node:hover { border-color: rgba(255,255,255,0.15); }

.flow-node.active {
    border-color: #10b981;
    background: rgba(16, 185, 129, 0.06);
    box-shadow: 0 0 16px rgba(16, 185, 129, 0.25), inset 0 0 20px rgba(16, 185, 129, 0.03);
}

.flow-node.processing {
    border-color: #f59e0b;
    background: rgba(245, 158, 11, 0.05);
    animation: nodePulse 1.5s ease-in-out infinite;
}

@keyframes nodePulse {
    0%, 100% { box-shadow: 0 0 8px rgba(245, 158, 11, 0.2); }
    50% { box-shadow: 0 0 20px rgba(245, 158, 11, 0.4); }
}

.flow-dot {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    background: var(--background);
    border: 1px solid var(--border);
    flex-shrink: 0;
    transition: all 0.3s;
}

.flow-node.active .flow-dot {
    background: rgba(16, 185, 129, 0.12);
    border-color: #10b981;
    transform: scale(1.05);
}

.flow-node.processing .flow-dot {
    background: rgba(245, 158, 11, 0.12);
    border-color: #f59e0b;
}

.flow-node-info {
    flex: 1;
    min-width: 0;
}

.flow-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--foreground);
    transition: color 0.3s;
}

.flow-node.active .flow-label { color: #10b981; }
.flow-node.processing .flow-label { color: #f59e0b; }

.flow-sublabel {
    font-size: 9px;
    color: var(--muted-fg);
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.flow-time {
    font-size: 10px;
    font-weight: 700;
    color: #3b82f6;
    font-variant-numeric: tabular-nums;
    padding: 2px 8px;
    border-radius: 8px;
    background: rgba(59, 130, 246, 0.1);
    flex-shrink: 0;
    min-height: 0;
}

.flow-time:empty { display: none; }

/* ── Connector lines between nodes ── */
.flow-connector {
    width: 2px;
    height: 18px;
    background: var(--border);
    transition: background 0.4s, box-shadow 0.4s;
    position: relative;
}

.flow-connector.lit {
    background: #10b981;
    box-shadow: 0 0 6px rgba(16, 185, 129, 0.4);
}

.flow-connector::after {
    content: '';
    position: absolute;
    bottom: -3px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid var(--border);
    transition: border-top-color 0.4s;
}

.flow-connector.lit::after {
    border-top-color: #10b981;
}

/* ── Flow Detail Panels ── */
.flow-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 10px;
    width: 100%;
}

.flow-detail-section {
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
    animation: fdIn 0.3s ease-out;
}

@keyframes fdIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.flow-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 7px 10px;
    background: var(--background);
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    color: var(--foreground);
    transition: background 0.15s;
    user-select: none;
}

.flow-detail-header:hover { background: rgba(255,255,255,0.03); }

.flow-toggle {
    font-size: 10px;
    color: var(--muted-fg);
    transition: transform 0.2s;
}

.flow-detail-section.collapsed .flow-toggle { transform: rotate(-90deg); }
.flow-detail-section.collapsed .flow-detail-body { display: none; }

.flow-detail-body {
    padding: 8px 10px;
    font-size: 10px;
    font-family: 'SF Mono', 'Consolas', monospace;
    color: var(--secondary-fg);
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 200px;
    overflow-y: auto;
    background: var(--card);
    border-top: 1px solid var(--border);
}

.flow-detail-body .fd-row {
    display: flex;
    gap: 6px;
    padding: 2px 0;
}

.flow-detail-body .fd-key {
    color: var(--muted-fg);
    min-width: 65px;
    flex-shrink: 0;
    font-weight: 600;
}

.flow-detail-body .fd-val {
    color: var(--foreground);
    word-break: break-word;
}

.flow-detail-body .fd-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 9px;
    font-weight: 700;
}

.fd-badge.tier1 { background: rgba(16,185,129,0.15); color: #10b981; }
.fd-badge.tier2 { background: rgba(59,130,246,0.15); color: #3b82f6; }
.fd-badge.tier3 { background: rgba(245,158,11,0.15); color: #f59e0b; }

/* ═══ HISTORY LOG ═══ */
.stage-history {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.history-entry {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    padding: 5px 8px;
    background: var(--background);
    border-radius: 6px;
}

.history-entry .h-turn {
    font-weight: 700;
    color: var(--muted-fg);
    min-width: 28px;
}

.history-entry .h-stage {
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 9px;
    text-transform: uppercase;
}

.history-entry .h-query {
    flex: 1;
    color: var(--secondary-fg);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ═══ EMPTY STATE ═══ */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 12px;
    color: var(--muted-fg);
}

.empty-state .icon { font-size: 40px; opacity: 0.25; }

.empty-state h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--foreground);
}

.empty-state p {
    font-size: 13px;
    max-width: 300px;
    text-align: center;
    line-height: 1.6;
}

.quick-prompts {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
    justify-content: center;
}

.quick-prompt {
    padding: 7px 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--secondary-fg);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

.quick-prompt:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

/* ═══ PRODUCT CARDS ═══ */
.product-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    margin-top: 10px;
    max-width: 90%;
    align-self: flex-start;
    animation: msgIn 0.35s ease-out;
}

.product-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    transition: all 0.2s ease;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
}

.product-card:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
    transform: translateY(-2px);
}

.product-card-img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    background: var(--muted);
    display: block;
}

.product-card-img.error {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    color: var(--muted-fg);
    background: var(--background);
}

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

.product-card-name {
    font-size: 11px;
    font-weight: 600;
    color: var(--foreground);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-card-sku {
    font-size: 9px;
    color: var(--muted-fg);
    font-family: 'SF Mono', 'Consolas', monospace;
    letter-spacing: 0.3px;
}

.product-card-price {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: auto;
}

.product-card-price .sale {
    font-size: 12px;
    font-weight: 700;
    color: var(--error, #dc2626);
}

.product-card-price .original {
    font-size: 10px;
    color: var(--muted-fg);
    text-decoration: line-through;
}

.product-card-discount {
    position: absolute;
    top: 6px;
    right: 6px;
    background: var(--error, #dc2626);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    padding: 2px 5px;
    border-radius: 4px;
    line-height: 1;
}

.product-card {
    position: relative;
}

.product-card-meta {
    font-size: 9px;
    color: var(--muted-fg);
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.product-card-meta span {
    background: var(--background);
    padding: 1px 5px;
    border-radius: 3px;
}

/* ═══ RESPONSIVE ═══ */
@media (max-width: 900px) {
    .app-container { grid-template-columns: 1fr; }
    .debug-panel { display: none; }
    .product-cards { grid-template-columns: repeat(2, 1fr); }
}
