* { box-sizing: border-box; }

:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #1f2937;
  background: #f4f6f8;
}

body { margin: 0; min-height: 100vh; }
button, textarea { font: inherit; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 280px 1fr; }

.sidebar {
  background: #111827; color: white; padding: 22px; display: flex;
  flex-direction: column; justify-content: space-between; min-height: 100vh; overflow: hidden;
}
.sidebar-top { min-height: 0; display: flex; flex-direction: column; }

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: white; color: #111827; font-weight: 800; font-size: 20px;
}
.brand h1 { margin: 0; font-size: 20px; }
.brand p { margin: 2px 0 0; color: #9ca3af; font-size: 13px; }

.secondary-btn {
  border: 1px solid #374151; background: #1f2937; color: white;
  border-radius: 10px; padding: 11px 14px; cursor: pointer;
}
.secondary-btn:hover:not(:disabled) { background: #273449; }
.secondary-btn:disabled { opacity: .45; cursor: not-allowed; }
.full-width { width: 100%; }

.history-section { margin-top: 22px; min-height: 0; display: flex; flex-direction: column; }
.history-title {
  color: #9ca3af; text-transform: uppercase; font-size: 11px;
  letter-spacing: .08em; margin-bottom: 10px;
}
.conversation-list {
  display: flex; flex-direction: column; gap: 6px; overflow-y: auto;
  max-height: calc(100vh - 245px); padding-right: 2px;
}
.conversation-item {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center;
  border-radius: 9px; padding: 9px 10px; cursor: pointer;
  color: #d1d5db; background: transparent; border: 1px solid transparent;
}
.conversation-item:hover { background: #1f2937; }
.conversation-item.active { background: #1f2937; border-color: #374151; color: white; }
.conversation-item.disabled { pointer-events: none; opacity: .55; }
.conversation-main { min-width: 0; }
.conversation-name { font-size: 13px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.conversation-date { margin-top: 3px; font-size: 10px; color: #6b7280; }
.conversation-delete {
  width: 24px; height: 24px; border: 0; border-radius: 6px;
  background: transparent; color: #6b7280; cursor: pointer;
}
.conversation-delete:hover:not(:disabled) { background: #374151; color: white; }

.sidebar-info {
  display: flex; align-items: center; gap: 8px; color: #9ca3af;
  font-size: 13px; padding-top: 16px;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; }

.chat-area { min-width: 0; display: flex; flex-direction: column; height: 100vh; }
.chat-header {
  background: white; border-bottom: 1px solid #e5e7eb; padding: 18px 28px;
  display: flex; align-items: center; justify-content: space-between;
}
.chat-header h2 { margin: 0; font-size: 18px; }
.chat-header p { margin: 4px 0 0; color: #6b7280; font-size: 13px; }
.conversation-pill {
  background: #f3f4f6; border-radius: 999px; padding: 7px 12px;
  font-size: 12px; color: #6b7280;
}
.conversation-pill strong { color: #111827; margin-left: 4px; }

.messages { flex: 1; overflow-y: auto; padding: 28px; }
.welcome-card { max-width: 760px; margin: 56px auto 0; text-align: center; }
.welcome-icon {
  width: 52px; height: 52px; margin: 0 auto 16px; border-radius: 16px;
  display: grid; place-items: center; background: #111827; color: white; font-size: 24px;
}
.welcome-card h3 { margin: 0; font-size: 24px; }
.welcome-card p { color: #6b7280; margin: 10px 0 26px; }
.suggestions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.suggestion {
  text-align: left; border: 1px solid #e5e7eb; background: white;
  border-radius: 12px; padding: 15px; cursor: pointer; color: #374151;
}
.suggestion:hover:not(:disabled) { border-color: #9ca3af; background: #fafafa; }
.suggestion:disabled { opacity: .45; cursor: not-allowed; }

.message-row { max-width: 900px; margin: 0 auto 18px; display: flex; }
.message-row.user { justify-content: flex-end; }
.message-row.assistant { justify-content: flex-start; }
.message-bubble {
  max-width: min(760px, 86%); border-radius: 16px; padding: 13px 16px;
  line-height: 1.5; white-space: pre-wrap;
}
.user .message-bubble { background: #111827; color: white; border-bottom-right-radius: 5px; }
.assistant .message-bubble {
  background: white; border: 1px solid #e5e7eb; color: #1f2937; border-bottom-left-radius: 5px;
}
.error-bubble {
  border-color: #fecaca !important; background: #fff7f7 !important; color: #991b1b !important;
}

.result-card {
  max-width: 900px; margin: -4px auto 20px; background: white;
  border: 1px solid #e5e7eb; border-radius: 16px; overflow: hidden;
}
.result-card-header {
  padding: 12px 16px; border-bottom: 1px solid #e5e7eb;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.result-card-header h4 { margin: 0; font-size: 14px; }
.result-card-body { padding: 16px; }
.result-toolbar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.result-btn {
  border: 1px solid #d1d5db; background: white; color: #374151;
  border-radius: 8px; padding: 7px 10px; cursor: pointer; font-size: 12px;
}
.result-btn:hover { background: #f9fafb; }
.result-btn.active { background: #111827; color: white; border-color: #111827; }
.result-btn:disabled { opacity: .45; cursor: not-allowed; }

.kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px;
}
.kpi-card { border: 1px solid #e5e7eb; border-radius: 12px; padding: 14px; background: #fafafa; }
.kpi-label { display: block; color: #6b7280; font-size: 12px; margin-bottom: 6px; }
.kpi-value { font-size: 22px; font-weight: 700; color: #111827; word-break: break-word; }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td {
  padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: left; vertical-align: top;
}
.data-table th { color: #4b5563; background: #f9fafb; font-weight: 600; white-space: nowrap; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table td.numeric { text-align: right; font-variant-numeric: tabular-nums; }

.chart-wrap {
  width: 100%; min-height: 340px; overflow-x: auto;
  border: 1px solid #e5e7eb; border-radius: 12px; background: #fff; padding: 12px;
}
.chart-svg { width: 100%; min-width: 620px; height: 340px; display: block; }
.chart-label { font-size: 11px; fill: #4b5563; }
.chart-value { font-size: 11px; fill: #111827; font-weight: 600; }
.chart-axis { stroke: #d1d5db; stroke-width: 1; }
.chart-grid { stroke: #f0f2f5; stroke-width: 1; }
.chart-bar { fill: #374151; }
.chart-line { fill: none; stroke: #111827; stroke-width: 3; }
.chart-point { fill: #111827; }
.chart-empty { color: #6b7280; font-size: 13px; padding: 24px; text-align: center; }

.result-note {
  margin-top: 12px; padding: 10px 12px; border-radius: 10px;
  background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412; font-size: 12px;
}
.result-meta { margin-top: 12px; color: #9ca3af; font-size: 11px; }
.message-meta { max-width: 900px; margin: -10px auto 18px; color: #9ca3af; font-size: 11px; }
.empty-state { color: #6b7280; font-size: 13px; }

.composer-wrap { background: white; border-top: 1px solid #e5e7eb; padding: 16px 28px 14px; }
.composer { max-width: 900px; margin: 0 auto; display: flex; align-items: flex-end; gap: 10px; }
textarea {
  flex: 1; resize: none; min-height: 48px; max-height: 160px; padding: 13px 14px;
  border: 1px solid #d1d5db; border-radius: 13px; outline: none; color: #111827;
}
textarea:focus { border-color: #6b7280; }
textarea:disabled { background: #f9fafb; cursor: not-allowed; }
.send-btn {
  min-height: 48px; border: 0; border-radius: 12px; padding: 0 20px;
  background: #111827; color: white; cursor: pointer; font-weight: 600;
}
.send-btn:disabled { opacity: .5; cursor: not-allowed; }
.footer-note { max-width: 900px; margin: 8px auto 0; color: #9ca3af; font-size: 11px; text-align: center; }

.thinking-card {
  max-width: 900px; margin: 0 auto 18px; display: flex; align-items: center;
  gap: 10px; color: #6b7280; font-size: 13px;
}
.thinking-icon {
  width: 30px; height: 30px; border-radius: 10px; background: #111827; color: white;
  display: grid; place-items: center; font-size: 15px; animation: thinkingPulse 1.4s ease-in-out infinite;
}
.thinking-dots { display: inline-flex; gap: 4px; margin-left: 4px; }
.thinking-dots span {
  width: 6px; height: 6px; border-radius: 50%; background: #9ca3af;
  animation: thinkingDot 1.2s infinite ease-in-out;
}
.thinking-dots span:nth-child(2) { animation-delay: .15s; }
.thinking-dots span:nth-child(3) { animation-delay: .3s; }

@keyframes thinkingPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(.92); opacity: .72; }
}
@keyframes thinkingDot {
  0%, 80%, 100% { transform: translateY(0); opacity: .35; }
  40% { transform: translateY(-4px); opacity: 1; }
}

@media (max-width: 800px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .chat-header { padding: 15px 16px; }
  .conversation-pill { display: none; }
  .messages { padding: 18px 14px; }
  .composer-wrap { padding: 12px; }
  .suggestions { grid-template-columns: 1fr; }
  .message-bubble { max-width: 94%; }
  .result-card { border-radius: 12px; }
}
