/* TQRAR Demo Components - Light Theme (Jupyter Style) */
:root {
    --primary: #1337ec;
    --primary-light: #4d6bff;
    --secondary: #8b5cf6;
    --bg: #ffffff;
    --bg-secondary: #f7f7f7;
    --surface: #ffffff;
    --surface-secondary: #f5f5f5;
    --border: #e0e0e0;
    --border-light: #eeeeee;
    --text: #212121;
    --text-secondary: #616161;
    --text-muted: #9e9e9e;
    --success: #2e7d32;
    --warning: #f57c00;
    --error: #d32f2f;
    --code-bg: #f8f8f8;
    --jupyter-orange: #f37626;
    --cell-active: #1976d2;
    --cell-border: #1976d2;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { 
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; 
    background: var(--bg-secondary); 
    color: var(--text); 
    height: 100vh; 
    overflow: hidden; 
}
.app-container { display: flex; flex-direction: column; height: 100vh; }

/* ========== HEADER ========== */
.jupyter-header {
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 16px;
    flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 20px; }
.jupyter-logo { display: flex; align-items: center; }

.header-menu { display: flex; gap: 4px; font-size: 13px; }
.header-menu span { 
    padding: 6px 10px; 
    cursor: pointer; 
    color: var(--text-secondary);
    border-radius: 4px;
    transition: all 0.15s; 
}
.header-menu span:hover { background: var(--bg-secondary); color: var(--text); }
.header-center { 
    font-size: 14px; 
    font-weight: 500;
    color: var(--text); 
    position: absolute; 
    left: 50%; 
    transform: translateX(-50%); 
}
.header-right { display: flex; align-items: center; gap: 12px; }
.kernel-status { 
    display: flex; 
    align-items: center; 
    gap: 8px; 
    font-size: 12px; 
    color: var(--text-secondary);
    padding: 4px 12px;
    background: var(--bg-secondary);
    border-radius: 4px;
}
.kernel-dot { 
    width: 10px; 
    height: 10px; 
    border-radius: 50%; 
    background: var(--text-muted); 
    transition: all 0.3s; 
}
.kernel-dot.active { background: var(--success); }
.kernel-dot.busy { background: var(--warning); animation: pulse 1s infinite; }

/* ========== MAIN LAYOUT ========== */
.main-wrapper { display: flex; flex: 1; overflow: hidden; }

/* ========== LEFT SIDEBAR ========== */
.left-sidebar {
    width: 52px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 0;
    gap: 2px;
}
.sidebar-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.sidebar-btn:hover { background: var(--bg-secondary); color: var(--text-secondary); }
.sidebar-btn.active { background: var(--bg-secondary); color: var(--primary); }
.sidebar-spacer { flex: 1; }

/* ========== FILE BROWSER ========== */
.file-browser {
    width: 220px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}
.browser-header {
    padding: 12px 16px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
}
.browser-header .material-symbols-outlined { font-size: 18px; color: var(--jupyter-orange); }
.file-tree { padding: 8px; }
.file-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    font-size: 13px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.15s;
}
.file-item:hover { background: var(--bg-secondary); color: var(--text); }
.file-item.active { background: rgba(19, 55, 236, 0.08); color: var(--primary); font-weight: 500; }
.file-item .material-symbols-outlined { font-size: 18px; }

/* ========== NOTEBOOK AREA ========== */
.notebook-area { 
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    background: var(--bg-secondary); 
    min-width: 0; 
}
.notebook-toolbar {
    height: 40px;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.toolbar-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.toolbar-btn:hover { background: var(--bg-secondary); color: var(--text); }
.toolbar-btn .material-symbols-outlined { font-size: 20px; }
.toolbar-divider { width: 1px; height: 24px; background: var(--border); margin: 0 8px; }
.cell-type-select {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
}
.notebook-tabs {
    display: flex;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding-left: 8px;
}
.tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    font-size: 13px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    margin-right: 4px;
    color: var(--text-secondary);
}
.tab.active { 
    background: var(--bg-secondary); 
    border-bottom: 1px solid var(--bg-secondary);
    margin-bottom: -1px;
    color: var(--text);
    font-weight: 500;
}
.tab-close { font-size: 16px !important; color: var(--text-muted); margin-left: 4px; }
.notebook-content { 
    flex: 1; 
    overflow-y: auto; 
    padding: 24px 48px; 
    background: var(--bg-secondary);
}

/* ========== NOTEBOOK CELLS ========== */
.cell { 
    display: flex; 
    gap: 8px; 
    margin-bottom: 12px; 
    opacity: 0; 
    transform: translateY(10px); 
    transition: all 0.4s ease-out; 
}
.cell.visible { opacity: 1; transform: translateY(0); }
.cell.active .cell-content { 
    border-left: 3px solid var(--cell-border);
}
.cell-prompt { 
    width: 80px; 
    text-align: right; 
    font-family: 'JetBrains Mono', monospace; 
    font-size: 12px; 
    padding-top: 10px; 
    flex-shrink: 0;
    color: var(--text-muted);
}
.cell-prompt.in { color: var(--cell-active); font-weight: 600; }
.cell-prompt.out { color: var(--error); }
.cell-content { 
    flex: 1; 
    background: var(--surface); 
    border: 1px solid var(--border); 
    border-radius: 4px; 
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.cell-code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    line-height: 1.5;
    padding: 12px 16px;
    background: var(--code-bg);
    color: var(--text);
    white-space: pre-wrap;
    min-height: 20px;
    border-left: 3px solid transparent;
}
.cell.active .cell-code {
    border-left-color: var(--cell-border);
}
.cell-output { 
    padding: 12px 16px; 
    background: var(--surface); 
    border-top: 1px solid var(--border-light);
    font-size: 13px;
}
.cell-markdown { padding: 16px 20px; }
.cell-markdown h1 { font-size: 26px; margin-bottom: 8px; color: var(--text); font-weight: 600; }
.cell-markdown h2 { font-size: 22px; margin-bottom: 6px; color: var(--text); }
.cell-markdown p { color: var(--text-secondary); line-height: 1.7; }

/* ========== SYNTAX HIGHLIGHTING (Light Theme) ========== */
.kw { color: #008000; font-weight: 600; }  /* keywords - green */
.str { color: #ba2121; }                    /* strings - red */
.fn { color: #0000ff; }                     /* functions - blue */
.cm { color: #408080; font-style: italic; } /* comments - teal */
.num { color: #666666; }                    /* numbers - gray */
.var { color: #19177c; }                    /* variables - dark blue */
.op { color: #666666; }                     /* operators */

/* ========== DATA TABLE ========== */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { 
    background: var(--bg-secondary); 
    padding: 10px 14px; 
    text-align: left; 
    font-weight: 600; 
    border: 1px solid var(--border);
    color: var(--text);
}
.data-table td { 
    padding: 8px 14px; 
    border: 1px solid var(--border); 
    color: var(--text-secondary); 
}
.data-table tr:nth-child(even) { background: var(--bg-secondary); }
.data-table .num-cell { color: var(--success); font-family: 'JetBrains Mono', monospace; font-weight: 500; }

/* ========== TQRAR PANEL ========== */
.tqrar-panel {
    width: 400px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    box-shadow: -2px 0 8px rgba(0,0,0,0.04);
}
.tqrar-header {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.tqrar-title { display: flex; align-items: center; gap: 12px; }
.tqrar-logo {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    color: white;
    box-shadow: 0 2px 8px rgba(19, 55, 236, 0.25);
}
.tqrar-title h2 { font-size: 16px; font-weight: 600; color: var(--text); }
.tqrar-status { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.status-dot { 
    width: 8px; 
    height: 8px; 
    border-radius: 50%; 
    background: var(--text-muted); 
    transition: all 0.3s;
}
.status-dot.active { background: var(--success); }
.status-dot.working { background: var(--primary); animation: pulse 1s infinite; }
#tqrarStatus { 
    font-size: 11px; 
    color: var(--text-muted); 
    text-transform: uppercase; 
    letter-spacing: 0.5px;
    font-weight: 500;
}
.tqrar-actions { display: flex; gap: 4px; }
.icon-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.icon-btn:hover { background: var(--bg-secondary); color: var(--text-secondary); }

/* ========== CONNECTORS ========== */
.tqrar-connectors {
    display: flex;
    gap: 8px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    background: var(--bg-secondary);
}
.connector {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 12px;
    white-space: nowrap;
    transition: all 0.3s ease;
}
.connector .material-symbols-outlined { 
    font-size: 16px; 
    color: var(--text-muted);
    transition: all 0.3s ease;
}
.connector-status { 
    font-size: 10px; 
    color: var(--text-muted); 
    padding: 2px 8px; 
    background: var(--bg-secondary); 
    border-radius: 10px;
    font-weight: 500;
    transition: all 0.3s ease;
}
.connector-status.active { background: rgba(46, 125, 50, 0.1); color: var(--success); }

/* Connecting state */
.connector.connecting { 
    background: rgba(66, 133, 244, 0.08); 
    border-color: rgba(66, 133, 244, 0.3);
}
.connector.connecting .material-symbols-outlined { 
    color: #4285f4;
    animation: connectorIconPulse 1s ease-in-out infinite;
}
.connector.connecting .connector-status { 
    background: rgba(66, 133, 244, 0.1); 
    color: #4285f4;
}

/* Connected state */
.connector.connected { 
    background: rgba(19, 55, 236, 0.06); 
    border-color: rgba(19, 55, 236, 0.2);
    animation: connectorConnected 0.5s ease-out;
}
.connector.connected .material-symbols-outlined { color: var(--primary); }
.connector.connected .connector-status { background: rgba(46, 125, 50, 0.1); color: var(--success); }

/* Panel connector animations */
@keyframes connectorIconPulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.15); opacity: 0.7; }
}

@keyframes connectorConnected {
    0% { transform: scale(1); }
    30% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* ========== CHAT AREA ========== */
.tqrar-chat { 
    flex: 1; 
    overflow-y: auto; 
    padding: 20px; 
    display: flex; 
    flex-direction: column; 
    gap: 16px;
    background: var(--bg-secondary);
}
.chat-msg { 
    display: flex; 
    gap: 12px; 
    opacity: 0; 
    transform: translateY(10px); 
    animation: fadeIn 0.3s forwards; 
}
.chat-msg.user { flex-direction: row-reverse; }
.chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.chat-avatar.ai { background: linear-gradient(135deg, var(--primary), var(--secondary)); color: white; }
.chat-avatar.user { background: var(--bg-secondary); border: 1px solid var(--border); color: var(--text-secondary); }
.chat-avatar .material-symbols-outlined { font-size: 18px; }
.chat-bubble { 
    max-width: 85%; 
    padding: 12px 16px; 
    border-radius: 16px; 
    font-size: 14px; 
    line-height: 1.6; 
}
.chat-msg.ai .chat-bubble { 
    background: var(--surface); 
    border: 1px solid var(--border);
    border-radius: 16px 16px 16px 4px;
    color: var(--text);
}
.chat-msg.user .chat-bubble { 
    background: var(--primary); 
    color: white;
    border-radius: 16px 16px 4px 16px; 
}

/* ========== TOOL CALL CARDS ========== */
.tool-call-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-top: 10px;
    overflow: hidden;
}
.tool-call-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: rgba(19, 55, 236, 0.04);
}
.tool-call-header .material-symbols-outlined { font-size: 18px; color: var(--primary); }
.tool-call-header span { font-size: 13px; font-weight: 500; color: var(--primary); }
.tool-call-status { 
    margin-left: auto; 
    display: flex; 
    align-items: center; 
    gap: 6px; 
    font-size: 12px; 
}
.tool-call-status.running { color: var(--primary); }
.tool-call-status.done { color: var(--success); }

/* ========== INPUT AREA ========== */
.tqrar-input { padding: 16px 20px; border-top: 1px solid var(--border); background: var(--surface); }
.tqrar-input textarea {
    width: 100%;
    height: 70px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    resize: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.tqrar-input textarea:focus { 
    outline: none; 
    border-color: var(--primary); 
    box-shadow: 0 0 0 3px rgba(19, 55, 236, 0.1);
}
.tqrar-input textarea::placeholder { color: var(--text-muted); }
.input-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
.send-btn {
    background: var(--primary);
    border: none;
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
    font-size: 14px;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(19, 55, 236, 0.2);
}
.send-btn:hover { background: var(--primary-light); transform: translateY(-1px); }

/* ========== ANIMATIONS ========== */
@keyframes pulse { 
    0%, 100% { opacity: 1; } 
    50% { opacity: 0.5; } 
}
@keyframes fadeIn { 
    to { opacity: 1; transform: translateY(0); } 
}
@keyframes spin { 
    to { transform: rotate(360deg); } 
}
@keyframes blink { 
    0%, 50% { opacity: 1; } 
    51%, 100% { opacity: 0; } 
}

.typing::after { 
    content: '|'; 
    animation: blink 0.7s infinite; 
    color: var(--primary); 
    font-weight: 400;
}

.spinner { 
    width: 14px; 
    height: 14px; 
    border: 2px solid var(--border); 
    border-top-color: var(--primary); 
    border-radius: 50%; 
    animation: spin 0.8s linear infinite; 
}

/* ========== REPLAY BUTTON ========== */
.replay-btn {
    position: fixed;
    bottom: 56px;
    right: 24px;
    background: var(--primary);
    border: none;
    color: white;
    padding: 12px 24px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 16px rgba(19, 55, 236, 0.3);
    transition: all 0.2s;
    z-index: 1000;
}
.replay-btn:hover { 
    background: var(--primary-light); 
    transform: translateY(-2px); 
    box-shadow: 0 6px 20px rgba(19, 55, 236, 0.35);
}

/* ========== DEMO PROGRESS BAR ========== */
.demo-progress {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    z-index: 999;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

/* Add bottom padding to main content when progress bar is present */
body:has(.demo-progress) .app-container {
    padding-bottom: 40px;
}

/* Fallback for browsers that don't support :has() */
.app-container {
    padding-bottom: 40px;
}

.demo-progress-bar {
    flex: 1;
    height: 6px;
    background: var(--bg-secondary);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.demo-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    border-radius: 3px;
    width: 0%;
    transition: width 0.3s ease;
}

.demo-progress-time {
    font-size: 13px;
    color: var(--text-secondary);
    font-family: 'JetBrains Mono', monospace;
    min-width: 90px;
    text-align: right;
}

.demo-progress-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    min-width: 120px;
}

.demo-progress-status .status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}

.demo-progress-status.running .status-indicator {
    background: var(--primary);
    animation: pulse 1s infinite;
}

.demo-progress-status.complete .status-indicator {
    background: var(--success);
}

.demo-progress-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}


/* ========== TOOL CALL RESULTS (Inline in Chat) ========== */
.tool-call-result {
    padding: 12px 14px;
    background: var(--surface);
    border-top: 1px solid var(--border-light);
    font-size: 13px;
    max-height: 300px;
    overflow-y: auto;
}
.tool-call-result .data-table {
    font-size: 12px;
}
.tool-call-result .data-table th,
.tool-call-result .data-table td {
    padding: 6px 10px;
}
.tool-call-result pre {
    margin: 0;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
    color: var(--text-secondary);
}
.tool-call-result .result-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    font-weight: 500;
}

/* Schema/Table list styling */
.schema-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.schema-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-radius: 6px;
    font-size: 13px;
}
.schema-item .material-symbols-outlined {
    font-size: 18px;
    color: var(--primary);
}
.schema-item .table-name {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 500;
    color: var(--text);
}
.schema-item .table-info {
    margin-left: auto;
    font-size: 11px;
    color: var(--text-muted);
}


/* ========== EMBED MODE ========== */
/* Hide chrome when embedded (add ?embed=true to URL) */
body.embed-mode .jupyter-header,
body.embed-mode .left-sidebar,
body.embed-mode .file-browser,
body.embed-mode .notebook-toolbar,
body.embed-mode .notebook-tabs,
body.embed-mode .replay-btn,
body.embed-mode .demo-progress {
    display: none !important;
}

body.embed-mode .app-container {
    padding-bottom: 0;
}

body.embed-mode .main-wrapper {
    height: 100vh;
}

body.embed-mode .notebook-content {
    padding: 16px 24px;
}

body.embed-mode .tqrar-panel {
    width: 380px;
}
