/* ═══════════════════════════════════════
   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-sm);
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.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 unified to primary theme */
.stage-node .stage-dot.active { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.stage-node .stage-label.active-label { color: var(--primary); }

.stage-connector .fill { background: var(--primary); }

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

/* ═══ CHAT PANEL ═══ */
.chat-panel {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: var(--card);
    box-shadow: var(--shadow-lg);
    min-height: 0;
    overflow: hidden;
    position: relative;
}

.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
    background: var(--background);
}

.msg {
    max-width: 80%;
    padding: 16px 20px;
    border-radius: 20px;
    font-size: 14.5px;
    line-height: 1.6;
    animation: msgIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: var(--shadow-sm);
}

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

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

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

.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: 18px 24px;
    border-top: 1px solid var(--border);
    background: var(--card);
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    gap: 12px;
    align-items: center;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 6px 6px 6px 20px;
    transition: all 0.2s;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}

.input-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.chat-input {
    flex: 1;
    padding: 8px 0;
    background: transparent;
    border: none;
    color: var(--foreground);
    font-size: 14.5px;
    font-family: inherit;
    outline: none;
}

.chat-input::placeholder { color: var(--muted-fg); }

.send-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.send-btn:hover { background: var(--primary-hover); transform: scale(1.08); box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

/* ═══ DEBUG PANEL ═══ */
.debug-panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 24px;
    box-shadow: var(--shadow-md);
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    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: var(--primary);
    background: var(--primary-light);
    box-shadow: var(--shadow-sm);
}

.flow-node.processing {
    border-color: var(--warn);
    background: var(--warn-light);
    animation: nodePulse 1.5s ease-in-out infinite;
}

@keyframes nodePulse {
    0%, 100% { box-shadow: 0 0 8px rgba(202, 138, 4, 0.2); }
    50% { box-shadow: 0 0 16px rgba(202, 138, 4, 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: var(--primary-light);
    border-color: var(--primary);
    transform: scale(1.05);
}

.flow-node.processing .flow-dot {
    background: var(--warn-light);
    border-color: var(--warn);
}

.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: var(--primary); }
.flow-node.processing .flow-label { color: var(--warn); }

.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: var(--primary);
    box-shadow: 0 0 6px rgba(59, 89, 152, 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: var(--primary);
}

/* ── 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); }
}
