/* ═══════════════════════════════════════════════════════════
   AI SQL Trace — Page-Specific Styles
   Theme vars come from theme.css, components from components.css
   ═══════════════════════════════════════════════════════════ */
@import url('theme.css');
@import url('components.css');

/* ── Page-specific body override ── */
body {
    font-family: var(--font-sans);
    background: var(--background);
    color: var(--foreground);
    height: 100vh;
    display: flex;
    overflow: hidden;
    margin: 0; padding: 0;
}

/* ══════════════════════════════════
   LAYOUT: Two Pane
   ══════════════════════════════════ */
.layout-container { display: flex; width: 100%; height: 100%; }

/* ── LEFT PANE: Chat ── */
.left-pane {
    width: 420px;
    background: var(--card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: relative;
    flex-shrink: 0;
    z-index: 10;
}

.chat-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card);
}
.chat-header h2 {
    font-size: 14px;
    font-weight: 600;
    color: var(--foreground);
    letter-spacing: -0.01em;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--muted-fg);
    font-size: 15px;
    padding: 8px;
    border-radius: var(--radius);
    transition: all 0.15s;
}
.btn-icon:hover {
    background: var(--muted);
    color: var(--foreground);
}

/* ── Chat Messages ── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
}

.chat-msg {
    max-width: 92%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.6;
    animation: fadeIn 0.25s ease;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.user-msg {
    align-self: flex-end;
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}
.ai-msg {
    align-self: flex-start;
    background: var(--muted);
    color: var(--foreground);
    border-bottom-left-radius: 4px;
    width: 100%;
}

/* ── Agent Logs (dark terminal) ── */
.agent-logs {
    background: #1a1a2e;
    color: #a5b4cb;
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 10px;
    max-height: 200px;
    overflow-y: auto;
}
.agent-log-item {
    margin-bottom: 4px;
    padding-left: 10px;
    border-left: 2px solid #334155;
}
.agent-log-item.sql  { color: #818cf8; }
.agent-log-item.data { color: #34d399; }
.agent-log-item.think { color: #fbbf24; }

/* ── Chat Input ── */
.chat-input-area {
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    background: var(--card);
}
.chat-input-wrapper {
    position: relative;
    display: flex;
    align-items: flex-end;
    background: var(--background);
    border: 1px solid var(--input);
    border-radius: 14px;
    padding: 4px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.chat-input-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(59, 89, 152, 0.1);
}

.chat-input-wrapper textarea {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px 12px;
    max-height: 120px;
    min-height: 42px;
    resize: none;
    outline: none;
    font-family: inherit;
    font-size: 13px;
    color: var(--foreground);
}

.btn-send {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: none;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin: 3px;
    transition: all 0.15s;
}
.btn-send:hover { background: var(--primary-hover); transform: scale(1.04); }
.btn-send:disabled { background: var(--input); cursor: not-allowed; transform: none; }

/* ══════════════════════════════════
   HISTORY SIDEBAR (Slide-over)
   ══════════════════════════════════ */
.history-sidebar {
    position: absolute;
    top: 0; left: 0; bottom: 0;
    width: 100%;
    background: var(--card);
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}
.history-sidebar.open { transform: translateX(0); }

.history-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.conv-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.conv-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s;
}
.conv-item:hover { background: var(--muted); }
.conv-item.active { background: var(--primary-light); border-color: var(--primary); }
.conv-title { font-size: 13px; font-weight: 600; line-height: 1.4; margin-bottom: 3px; }
.conv-meta { font-size: 11px; color: var(--muted-fg); display: flex; gap: 8px; align-items: center; }

/* ── Pill badges ── */
.pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}
.pill.completed { background: #ecfdf5; color: var(--success); }
.pill.error     { background: #fef2f2; color: var(--error); }
.pill.running   { background: #eff6ff; color: #2563eb; }

/* ══════════════════════════════════
   RIGHT PANE: Data / Chart
   ══════════════════════════════════ */
.right-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--background);
    position: relative;
}

.doc-header {
    height: 52px;
    padding: 0 20px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.doc-title { font-weight: 600; font-size: 13px; color: var(--foreground); }
.doc-actions { display: flex; gap: 6px; }
.btn-action {
    padding: 6px 12px;
    border-radius: var(--radius);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--card);
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all 0.15s;
    color: var(--foreground);
}
.btn-action:hover { background: var(--muted); }

.doc-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    justify-content: center;
}
.doc-content {
    width: 100%;
    max-width: 920px;
}

/* ══════════════════════════════════
   TRACE CARDS (Memos card style)
   ══════════════════════════════════ */
.trace-card {
    background: var(--card);
    border-radius: 10px;
    padding: 18px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    animation: fadeIn 0.25s ease;
}
.trace-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
}
.trace-card-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.trace-card-title {
    font-size: 15px;
    font-weight: 700;
    margin-top: 3px;
    color: var(--foreground);
}
.trace-card-text {
    font-size: 13px;
    line-height: 1.7;
    color: var(--muted-fg);
    margin-top: 6px;
}

/* ── Summary Grid (Number Cards) ── */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-top: 12px;
}
.summary-block {
    padding: 12px;
    border-radius: 8px;
    background: var(--muted);
    border: 1px solid var(--border);
}
.summary-block .label {
    font-size: 10px;
    font-weight: 600;
    color: var(--muted-fg);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.summary-block .value {
    font-size: 22px;
    font-weight: 700;
    margin-top: 4px;
    color: var(--foreground);
}
.summary-block .meta {
    font-size: 11px;
    color: var(--muted-fg);
    margin-top: 3px;
}

/* ── SQL Block ── */
.sql-block {
    background: #1a1a2e;
    color: #d1d5db;
    border-radius: 8px;
    padding: 14px;
    margin-top: 10px;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ── Query Item ── */
.query-item {
    padding: 12px;
    border-radius: 8px;
    margin-top: 10px;
    background: var(--muted);
    border: 1px solid var(--border);
}
.query-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.query-item-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary);
    text-transform: uppercase;
}
.query-item-purpose {
    font-size: 12px;
    color: var(--muted-fg);
    margin-bottom: 8px;
}

/* ── Data Tables — clean minimal ── */
.preview-table-wrap,
.data-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-top: 10px;
}
.preview-table,
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}
.preview-table th,
.preview-table td,
.data-table th,
.data-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}
.preview-table th,
.data-table th {
    background: var(--muted);
    color: var(--muted-fg);
    font-weight: 600;
    font-size: 10px;
    text-transform: uppercase;
}
.preview-table tbody tr:hover,
.data-table tbody tr:hover {
    background: var(--primary-light);
}

/* ── Reflect Box ── */
.reflect-box {
    margin-top: 14px;
    padding: 12px;
    border-radius: 8px;
    background: #fefce8;
    border: 1px solid #fde68a;
}
.reflect-box .label { font-size: 11px; font-weight: 600; color: #a16207; text-transform: uppercase; }
.reflect-box p { font-size: 13px; color: #713f12; line-height: 1.6; margin-top: 4px; }
.reflect-box ul { font-size: 12px; color: #713f12; padding-left: 18px; margin-top: 4px; }

/* ── Empty State ── */
.empty-doc-state {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--muted-fg);
    text-align: center;
}
.empty-icon { font-size: 56px; margin-bottom: 20px; opacity: 0.25; }

/* ── Loading Dots ── */
.chat-typing { display: flex; gap: 4px; padding: 10px; align-items: center; }
.dot {
    width: 5px;
    height: 5px;
    background: var(--primary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
    opacity: 0.6;
}
.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

/* ══════════════════════════════════
   CHART CARDS
   ══════════════════════════════════ */
.chart-card {
    background: var(--card);
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}
.cc-header { margin-bottom: 10px; }
.cc-title { font-size: 14px; font-weight: 600; color: var(--foreground); }
.cc-desc { font-size: 12px; color: var(--muted-fg); margin-top: 3px; }
.cc-body { position: relative; }
.cc-canvas-wrap { position: relative; height: 280px; }
.cc-footer {
    font-size: 11px;
    color: var(--muted-fg);
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}
.cc-meta { display: flex; gap: 12px; font-size: 10px; color: var(--muted-fg); margin-top: 8px; }
.cc-trend { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.cc-trend.up   { color: var(--success); }
.cc-trend.down { color: var(--error); }
