/* ============================================================
   AI Data Analysis Tool — style.css
   Design: Clean Enterprise Dark
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ─── Design Tokens ─────────────────────────────────────── */
:root {
  --bg-base:        #0F172A;
  --bg-surface:     #1E293B;
  --bg-elevated:    #263348;
  --bg-input:       #162032;

  --accent-primary: #4F8EF7;
  --accent-hover:   #6BA3F9;
  --accent-glow:    rgba(79, 142, 247, 0.18);
  --accent-success: #34D399;
  --accent-warning: #FBBF24;
  --accent-error:   #F87171;

  --text-primary:   #E2E8F0;
  --text-secondary: #94A3B8;
  --text-muted:     #4B5563;
  --text-code:      #7DD3FC;

  --border-subtle:  rgba(79, 142, 247, 0.12);
  --border-default: rgba(79, 142, 247, 0.24);
  --border-focus:   rgba(79, 142, 247, 0.6);

  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  16px;
  --radius-xl:  22px;

  --shadow-md:  0 4px 24px rgba(0,0,0,0.4);
  --shadow-lg:  0 8px 40px rgba(0,0,0,0.6);
  --shadow-glow: 0 0 20px rgba(79, 142, 247, 0.25);

  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --font-sans:  'Inter', system-ui, sans-serif;
  --font-mono:  'JetBrains Mono', monospace;

  --header-h:  62px;
  --panel-gap: 14px;
}

/* ─── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ─── Scrollbar ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-primary); }

/* ─── Header ─────────────────────────────────────────────── */
.header {
  height: var(--header-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-logo {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent-primary), #7C3AED);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  box-shadow: var(--shadow-glow);
}

.header-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
  background: linear-gradient(90deg, var(--text-primary), var(--accent-primary));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent-success);
  box-shadow: 0 0 8px var(--accent-success);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.85); }
}

/* ─── Session Badge ──────────────────────────────────────── */
.session-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  font-size: 12px;
  color: var(--text-secondary);
}

.session-badge .session-name {
  color: var(--accent-primary);
  font-weight: 600;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── App Shell & Layout ─────────────────────────────────── */
.app-shell {
  display: flex;
  flex-direction: row;
  height: 100vh;
  padding-top: var(--header-h);
  gap: var(--panel-gap);
  padding: var(--header-h) var(--panel-gap) var(--panel-gap);
  overflow: hidden;
}

.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.sidebar {
  width: 320px;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-subtle);
  background: rgba(0,0,0,0.1);
  margin-top: auto;
}

.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ─── Tabs ───────────────────────────────────────────────── */
.tabs-header {
  display: flex;
  gap: 8px;
  padding: 12px 20px 0;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all var(--transition);
  opacity: 0.7;
}

.tab-btn:hover {
  opacity: 1;
  color: var(--text-primary);
}

.tab-btn.active {
  opacity: 1;
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
}

.tab-content {
  flex: 1;
  display: none;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.tab-content.active {
  display: flex;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-title-icon {
  width: 22px; height: 22px;
  border-radius: var(--radius-sm);
  background: var(--accent-glow);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
}

/* ─── Upload Zone ────────────────────────────────────────── */
.upload-zone {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 40px;
  border: 2px dashed var(--border-default);
  border-radius: var(--radius-lg);
  margin: 20px;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--accent-primary);
  background: var(--accent-glow);
  box-shadow: var(--shadow-glow);
}

.upload-icon { font-size: 48px; opacity: 0.7; }

.upload-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.upload-hint {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.8;
}

.upload-formats {
  display: flex;
  gap: 8px;
}

.format-badge {
  padding: 3px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--accent-primary);
  font-weight: 600;
}

#upload-input { display: none; }

/* ─── Prompt Bar ─────────────────────────────────────────── */
.prompt-bar {
  display: flex;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  flex-shrink: 0;
}

.prompt-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  resize: none;
}

.prompt-input::placeholder { color: var(--text-muted); }

.prompt-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ─── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  outline: none;
  transition: all var(--transition);
  white-space: nowrap;
  letter-spacing: 0.2px;
}

.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

.btn-primary {
  background: var(--accent-primary);
  color: #fff;
  box-shadow: 0 2px 12px rgba(79, 142, 247, 0.35);
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 20px rgba(79, 142, 247, 0.55);
  transform: translateY(-1px);
}

.btn-primary:active { transform: translateY(0); }

.btn-ghost {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

.btn-ghost:hover {
  background: var(--accent-glow);
  color: var(--accent-primary);
  border-color: var(--border-focus);
}

.btn-danger {
  background: rgba(248, 113, 113, 0.12);
  color: var(--accent-error);
  border: 1px solid rgba(248, 113, 113, 0.25);
}
.btn-danger:hover { background: rgba(248, 113, 113, 0.22); }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-icon { padding: 8px; min-width: 36px; height: 36px; }

/* ─── Chart Panel Body ───────────────────────────────────── */
.chart-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

#chart-container {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.chart-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-muted);
  padding: 40px;
  text-align: center;
}

.chart-placeholder-icon { font-size: 56px; opacity: 0.35; }
.chart-placeholder-text { font-size: 14px; line-height: 1.7; }

/* ─── Loading Spinner ────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid rgba(255,255,255,0.15);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Schema Panel ───────────────────────────────────────── */
.schema-preview {
  padding: 0 20px 14px;
  flex-shrink: 0;
  max-height: 380px; /* Increased height */
  overflow-y: auto;
}

.schema-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.schema-table th {
  color: var(--text-muted);
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border-subtle);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.schema-table td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}
.schema-table td:first-child { color: var(--text-primary); font-weight: 500; }
.dtype-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-code);
  background: rgba(125, 211, 252, 0.08);
  padding: 2px 5px;
  border-radius: 4px;
}

/* ─── Dataset Cards (Catalog) ────────────────────────────── */
.dataset-catalog {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 4px;
}

.dataset-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color var(--transition);
  margin-bottom: 8px;
}

.dataset-card:hover {
  border-color: var(--border-default);
}

.dataset-card-header {
  padding: 8px 12px;
  background: rgba(255,255,255,0.03);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.dataset-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.dataset-card-var {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-code);
  opacity: 0.8;
}

.dataset-card-body {
  padding: 0 12px 12px;
  display: none;
}

.dataset-card.open .dataset-card-body {
  display: block;
}

.suggestions-box {
  padding: 12px 20px;
  background: rgba(79, 142, 247, 0.05);
  border-top: 1px dashed var(--border-default);
}

.suggestion-chip {
  display: inline-block;
  padding: 4px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
  margin: 4px 4px 4px 0;
  cursor: pointer;
  transition: all var(--transition);
}

.suggestion-chip:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  background: var(--accent-glow);
}

/* ─── Chat Panel ─────────────────────────────────────────── */
.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}

.msg {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: msgIn 0.25s ease;
}

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

.msg-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  margin-top: 2px;
}

.msg.user .msg-avatar {
  background: linear-gradient(135deg, var(--accent-primary), #7C3AED);
}
.msg.assistant .msg-avatar {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
}

.msg-bubble {
  flex: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--text-primary);
  overflow-wrap: break-word;
}

.msg-bubble a {
  color: #60a5fa;
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color var(--transition);
}
.msg-bubble a:hover {
  color: #93c5fd;
}

.msg.user .msg-bubble {
  background: rgba(79, 142, 247, 0.12);
  border-color: rgba(79, 142, 247, 0.25);
}

.msg-bubble pre {
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-code);
  margin: 8px 0;
}
.msg-bubble code {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-code);
  background: var(--bg-base);
  padding: 2px 5px;
  border-radius: 4px;
}
.msg-bubble p { margin-bottom: 6px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble h3, .msg-bubble h4 { margin: 8px 0 4px; color: var(--accent-primary); }
.msg-bubble ul, .msg-bubble ol { padding-left: 20px; }
.msg-bubble li { margin-bottom: 3px; }
.msg-bubble strong { color: var(--text-primary); }

/* Typing indicator */
.typing-indicator .msg-bubble {
  padding: 14px;
  width: 60px;
  display: flex; align-items: center; gap: 5px;
}
.typing-indicator .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: blink 1.2s infinite;
}
.typing-indicator .dot:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.85); }
  40%           { opacity: 1;    transform: scale(1); }
}

/* ─── Chat Input ─────────────────────────────────────────── */
.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-textarea {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13.5px;
  outline: none;
  resize: none;
  min-height: 44px;
  max-height: 130px;
  line-height: 1.5;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.chat-textarea::placeholder { color: var(--text-muted); }
.chat-textarea:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ─── API Key Input ──────────────────────────────────────── */
.api-key-bar {
  display: flex;
  gap: 8px;
  align-items: center;
}

.api-key-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 12px;
  outline: none;
  transition: border-color var(--transition);
}
.api-key-input::placeholder { color: var(--text-muted); }
.api-key-input:focus {
  border-color: var(--accent-primary);
  color: var(--text-primary);
}

.api-key-label {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  display: flex; align-items: center; gap: 4px;
}

/* ─── Toast Notifications ────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 999;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  color: var(--text-primary);
  animation: toastIn 0.3s ease;
  max-width: 360px;
}

.toast.success { border-left: 3px solid var(--accent-success); }
.toast.error   { border-left: 3px solid var(--accent-error); }
.toast.info    { border-left: 3px solid var(--accent-primary); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(20px); }
}

/* ─── Code viewer ────────────────────────────────────────── */
.code-viewer {
  display: none;
  background: var(--bg-base);
  border-top: 1px solid var(--border-subtle);
  padding: 12px 18px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-code);
  max-height: 160px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.code-viewer.visible { display: block; }

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 900px) {
  .app-shell {
    flex-direction: column;
    overflow-y: auto;
    padding-bottom: 0;
  }
  .sidebar { width: 100%; min-height: 300px; flex-shrink: 0; }
  .main-area { min-height: 600px; }
  html, body { overflow: auto; }
}
