/* ═══════════════════════════════════════
   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 TRACE ═══ */
.pipeline-trace {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.pipe-step {
    position: relative;
    padding: 10px 12px 10px 32px;
    border-radius: 8px;
    background: var(--background);
    border: 1px solid var(--border);
    margin-bottom: 2px;
    animation: pipeIn 0.35s ease-out;
    animation-fill-mode: backwards;
}

.pipe-step:nth-child(2) { animation-delay: 0.08s; }
.pipe-step:nth-child(3) { animation-delay: 0.16s; }
.pipe-step:nth-child(4) { animation-delay: 0.24s; }
.pipe-step:nth-child(5) { animation-delay: 0.32s; }
.pipe-step:nth-child(6) { animation-delay: 0.40s; }

@keyframes pipeIn {
    from { opacity: 0; transform: translateX(-8px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* Vertical connector line */
.pipe-step::before {
    content: '';
    position: absolute;
    left: 16px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border);
}

.pipe-step:first-child::before { top: 50%; }
.pipe-step:last-child::before  { bottom: 50%; }

/* Dot on the timeline */
.pipe-step::after {
    content: '';
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--card);
    z-index: 1;
}

.pipe-step.step-user::after              { border-color: #6b7280; background: #6b7280; }
.pipe-step.step-classifier::after        { border-color: #f59e0b; background: #f59e0b; }
.pipe-step.step-responder::after         { border-color: #3b82f6; background: #3b82f6; }
.pipe-step.step-stylist::after           { border-color: #3b82f6; background: #3b82f6; }
.pipe-step.step-stylist_tool_call::after { border-color: #f97316; background: #f97316; }
.pipe-step.step-tool_result::after       { border-color: #10b981; background: #10b981; }

.pipe-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.pipe-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--foreground);
}

.pipe-time {
    font-size: 9px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 10px;
    background: rgba(59,130,246,0.12);
    color: #3b82f6;
    font-variant-numeric: tabular-nums;
}

.pipe-content {
    font-size: 11px;
    color: var(--secondary-fg);
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}

.pipe-raw-toggle {
    font-size: 10px;
    color: var(--muted-fg);
    cursor: pointer;
    margin-top: 4px;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    user-select: none;
    transition: color 0.15s;
}

.pipe-raw-toggle:hover { color: var(--foreground); }

.pipe-raw {
    display: none;
    margin-top: 6px;
    padding: 8px 10px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 10px;
    font-family: 'SF Mono', 'Consolas', monospace;
    color: var(--muted-fg);
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 180px;
    overflow-y: auto;
}

.pipe-raw.open { display: block; }

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