/* SkySwitch — Lead Intelligence UI (SIA Design System) */

:root {
    --bg-primary: #FAFAF8;
    --bg-chat: #F4F2EE;
    --bg-secondary: #F7F6F3;
    --bg-tertiary: #EFEEE9;
    --bg-card: #FFFFFF;
    --text-primary: #1A1A1A;
    --text-secondary: #6B6B6B;
    --text-muted: #A3A09A;
    --accent: #7C5CFC;
    --accent-hover: #6A48E8;
    --accent-glow: rgba(124, 92, 252, 0.08);
    --red: #DC4A3D;
    --orange: #E88D2A;
    --green: #3DA06B;
    --border: #E8E5DF;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06);
    --font: 'Inter', -apple-system, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ── Top Bar ─────────────────────────────── */

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    height: 52px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 20px; font-weight: 700; }
.subtitle { font-size: 13px; color: var(--text-secondary); font-weight: 400; }

.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-email { font-size: 13px; color: var(--text-secondary); font-weight: 500; }
.status-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 6px var(--green);
}
.status-dot.error { background: var(--red); box-shadow: 0 0 6px var(--red); }

.btn-icon {
    background: none; border: none; color: var(--text-secondary);
    font-size: 18px; cursor: pointer; padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
}
.btn-icon:hover { background: var(--bg-tertiary); color: var(--text-primary); }

/* ── Main Content ────────────────────────── */

.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.panel { display: flex; flex-direction: column; overflow: hidden; }

.chat-panel {
    width: 33.3%;
    min-width: 320px;
    border-right: 1px solid var(--border);
    background: var(--bg-chat);
}

.dashboard-panel {
    flex: 1;
    min-width: 400px;
    background: var(--bg-primary);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}
.panel-header h2 { font-size: 15px; font-weight: 600; }
.data-period { font-size: 11px; color: var(--text-muted); margin-left: 12px; }

.btn-small {
    font-size: 12px; padding: 4px 12px;
    background: var(--accent); color: white;
    border: none; border-radius: var(--radius-sm);
    cursor: pointer; font-weight: 500;
    transition: background 0.15s;
}
.btn-small:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }

/* ── Chat Messages ───────────────────────── */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.welcome-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    box-shadow: var(--shadow);
}
.welcome-card h3 { margin-bottom: 8px; font-size: 18px; }
.welcome-card p { color: var(--text-secondary); font-size: 14px; margin-bottom: 16px; }

.example-queries { display: flex; flex-direction: column; gap: 8px; }
.example-btn {
    background: var(--bg-chat);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    text-align: left;
    transition: all 0.15s;
    font-family: var(--font);
}
.example-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-glow);
}

.msg { max-width: 90%; padding: 12px 16px; border-radius: var(--radius); font-size: 14px; line-height: 1.6; flex-shrink: 0; }
.msg-user {
    align-self: flex-end;
    background: var(--accent);
    color: white;
    border-bottom-right-radius: 4px;
}
.msg-ai {
    align-self: flex-start;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow);
    color: var(--text-primary);
}
.msg-ai pre {
    background: var(--bg-tertiary);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    font-size: 12px;
    margin: 8px 0;
}
.msg-ai table {
    border-collapse: collapse;
    width: 100%;
    font-size: 12px;
    margin: 8px 0;
}
.msg-ai th, .msg-ai td {
    border: 1px solid var(--border);
    padding: 4px 8px;
    text-align: left;
}
.msg-ai th { background: var(--bg-tertiary); font-weight: 600; color: var(--text-secondary); }
.msg-system {
    align-self: center;
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    padding: 8px 16px;
    background: var(--bg-tertiary);
    border-radius: 20px;
}

/* ── Status Log ──────────────────────────── */

.status-log {
    align-self: flex-start;
    display: flex; flex-direction: column; gap: 4px;
    padding: 12px 0; font-size: 12px;
    color: var(--text-muted);
}
.spinner {
    width: 14px; height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Chat Input ──────────────────────────── */

.chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

.input-row { display: flex; gap: 8px; align-items: flex-end; }
#chatInput {
    flex: 1;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 10px 14px;
    font-size: 14px;
    font-family: var(--font);
    resize: none;
    max-height: 120px;
    outline: none;
    transition: border-color 0.15s;
}
#chatInput:focus { border-color: var(--accent); }

.btn-send {
    background: var(--accent);
    border: none;
    color: white;
    width: 40px; height: 40px;
    border-radius: var(--radius-sm);
    font-size: 18px;
    cursor: pointer;
    transition: background 0.15s;
    flex-shrink: 0;
}
.btn-send:hover { background: var(--accent-hover); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Resize Handle ───────────────────────── */

.resize-handle {
    width: 5px;
    cursor: col-resize;
    background: var(--border);
    transition: background 0.15s;
    flex-shrink: 0;
}
.resize-handle:hover, .resize-handle.active { background: var(--accent); }

/* ── Dashboard ───────────────────────────── */

.dashboard-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.kpi-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}
.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    box-shadow: var(--shadow);
    transition: border-color 0.15s;
}
.kpi-card:hover { border-color: var(--accent); }
.kpi-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 500; }
.kpi-value { font-size: 24px; font-weight: 700; color: var(--text-primary); }

.widget-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-top: 16px;
}

.widget {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
.widget-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}
.widget-header h3 { font-size: 13px; font-weight: 600; flex: 1; }
.widget-title-group { flex: 1; }
.widget-title-group h3 { flex: none; }
.widget-subtitle { display: block; font-size: 10px; color: var(--text-muted); font-weight: 400; margin-top: 2px; }
.widget-icon { font-size: 14px; }

.widget-body {
    padding: 12px 16px;
    min-height: 60px;
    max-height: 280px;
    overflow-y: auto;
    font-size: 13px;
}
.widget-empty { color: var(--text-muted); font-style: italic; text-align: center; padding: 16px; }

.widget-body table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.widget-body th, .widget-body td {
    border: 1px solid var(--border);
    padding: 6px 8px;
    text-align: left;
}
.widget-body th { background: var(--bg-secondary); font-weight: 600; color: var(--text-secondary); }

/* ── Pipeline Progress ───────────────────── */

.pipeline-stage {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 0;
    border-bottom: 1px solid var(--bg-tertiary);
}
.pipeline-stage:last-child { border-bottom: none; }
.pipeline-icon { font-size: 16px; width: 24px; text-align: center; }
.pipeline-info { flex: 1; }
.pipeline-name { font-size: 13px; font-weight: 500; }
.pipeline-detail { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.pipeline-bar {
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    margin-top: 4px;
    overflow: hidden;
}
.pipeline-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s ease;
}
.pipeline-bar-fill.done { background: var(--green); }

/* ── Upload Modal ────────────────────────── */

.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    display: none; align-items: center; justify-content: center;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.2s;
}
.modal-overlay.show { display: flex; opacity: 1; }

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: min(750px, 90vw);
    max-height: 85vh;
    display: flex; flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.12);
}
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 600; margin: 0; }
.modal-close {
    background: none; border: none; color: var(--text-muted);
    font-size: 24px; cursor: pointer; padding: 0 4px;
    line-height: 1;
}
.modal-close:hover { color: var(--text-primary); }
.modal-body {
    padding: 20px;
    overflow-y: auto;
    font-size: 14px;
    line-height: 1.6;
}

.upload-dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-secondary);
}
.upload-dropzone:hover {
    border-color: var(--accent);
    background: var(--accent-glow);
}
.upload-icon { font-size: 36px; margin-bottom: 12px; }
.upload-hint { font-size: 12px; color: var(--text-muted); display: block; margin-top: 8px; }

.preview-section {
    margin-top: 20px;
    padding: 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}
.preview-section h4 { font-size: 14px; margin-bottom: 12px; color: var(--text-primary); }

.mapping-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.mapping-table th, .mapping-table td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.mapping-table th { color: var(--text-muted); font-size: 11px; text-transform: uppercase; font-weight: 500; }
.mapping-mapped { color: var(--green); font-weight: 500; }
.mapping-unmapped { color: var(--text-muted); font-style: italic; }
.mapping-warning {
    margin-top: 12px;
    padding: 10px 14px;
    background: rgba(232, 141, 42, 0.08);
    border: 1px solid rgba(232, 141, 42, 0.2);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--orange);
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
    justify-content: flex-end;
}
.btn-primary { padding: 8px 20px; font-size: 13px; }

/* ── Session Sidebar ─────────────────────── */

.sidebar {
    position: fixed;
    right: -400px;
    top: 0;
    width: 360px;
    height: 100vh;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    box-shadow: -4px 0 24px rgba(0,0,0,0.08);
    z-index: 100;
    transition: right 0.25s ease;
    display: flex;
    flex-direction: column;
}
.sidebar.open { right: 0; }

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}
.sidebar-header h3 { font-size: 15px; font-weight: 600; }

.sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.session-item {
    padding: 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin-bottom: 4px;
    transition: background 0.15s;
}
.session-item:hover { background: var(--bg-tertiary); }
.session-title { font-size: 14px; font-weight: 500; margin-bottom: 4px; }
.session-meta { font-size: 11px; color: var(--text-muted); }

/* ── 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: 768px) {
    .main-content { flex-direction: column; }
    .chat-panel { width: 100%; min-width: unset; height: 50%; border-right: none; border-bottom: 1px solid var(--border); }
    .dashboard-panel { min-width: unset; }
    .resize-handle { display: none; }
    .kpi-bar { grid-template-columns: repeat(2, 1fr); }
    .widget-grid { grid-template-columns: 1fr; }
}

/* Upload zone (matches SIA) */
.upload-zone { display:flex; align-items:center; gap:8px; margin-bottom:8px; }
.upload-btn { font-size:20px; background:none; border:none; cursor:pointer; padding:4px; }
.upload-name { font-size:12px; color:var(--text-muted,#64748b); }

/* ── SSE streaming status (from SIA) ──── */
.status-log {
    align-self: flex-start;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 0;
    font-size: 12px;
    color: var(--text-muted, #64748b);
    transition: opacity 1s ease;
    max-width: 100%;
    overflow: hidden;
}
.status-log.fade { opacity: 0.5; }
.status-step {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 0;
    transition: opacity 0.3s;
}
.status-step-active { color: var(--text-secondary, #94a3b8); }
.status-step-done { color: var(--text-muted, #64748b); }
.status-check {
    color: var(--green, #22c55e);
    font-size: 12px;
    font-weight: 600;
    width: 14px;
    text-align: center;
    flex-shrink: 0;
}
.thinking-block {
    padding: 2px 0 2px 20px;
    font-size: 11px;
    color: var(--text-muted, #64748b);
    font-style: italic;
    line-height: 1.4;
    overflow: hidden;
    cursor: pointer;
    white-space: pre-wrap;
    word-break: break-word;
    max-width: 100%;
}
.thinking-block.collapsed {
    max-height: 1.4em;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.widget-row {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}
.widget-row .widget {
    min-width: 0;
}
@media (max-width: 768px) {
    .widget-row { flex-direction: column; }
}

/* Pipeline completion banners */
.pipeline-banner {
    padding: 10px 16px;
    border-radius: 8px;
    margin-bottom: 12px;
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.pipeline-banner-done {
    background: linear-gradient(135deg, #e8f5e9, #c8e6c9);
    color: #2e7d32;
    border: 1px solid #a5d6a7;
}
.pipeline-banner-running {
    background: linear-gradient(135deg, #e3f2fd, #bbdefb);
    color: #1565c0;
    border: 1px solid #90caf9;
}
.pipeline-banner-failed {
    background: linear-gradient(135deg, #fce4ec, #f8bbd0);
    color: #c62828;
    border: 1px solid #ef9a9a;
}
.pipeline-overall {
    margin-bottom: 12px;
}
.pipeline-overall .pipeline-bar {
    height: 8px;
    border-radius: 4px;
}
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
.spin {
    display: inline-block;
    animation: spin 1.5s linear infinite;
}
