* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: #f4f6f8;
  color: #1c1f24;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
}

header {
  background: #1c2733;
  color: #fff;
  padding: 10px 0;
  border-bottom: 3px solid #2563eb;
}
header h1 { margin: 0; font-size: 1.15rem; }
.container { max-width: 1280px; margin: 0 auto; padding: 8px 16px; }
.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 16px;
}
.muted { color: #c8d1dc; }
.badges { display: flex; gap: 6px; }
.badge {
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  border: 1px solid transparent;
}
.badge-on  { background: #14532d; color: #d1fae5; border-color: #166534; }
.badge-off { background: #3a3a3a; color: #cbd5e1; border-color: #4b5563; }

/* ---------- Layout chat ---------- */
.chat-shell {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 16px;
  min-height: 0;
}
.chat-side {
  background: #fff;
  border-radius: 10px;
  padding: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  height: 100%;
  overflow: auto;
}
.chat-side details { margin-bottom: 8px; }
.chat-side summary { font-weight: 600; cursor: pointer; padding: 4px 0; color: #1e3a8a; }
.actions-col { display: flex; flex-direction: column; gap: 8px; padding: 8px 0; }
.switch { display: flex; align-items: center; gap: 6px; font-size: 0.9rem; cursor: pointer; }
.switch input { transform: scale(1.2); }
.ghost {
  background: transparent;
  color: #1e3a8a;
  border: 1px solid #93c5fd;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.ghost:hover { background: #eff6ff; }

.chat-main {
  background: #fff;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  min-height: 0;
}

.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.composer {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid #e2e8f0;
}
.composer input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 1rem;
}
.composer button {
  background: #2563eb;
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 0.95rem;
  cursor: pointer;
}
.composer button:hover { background: #1d4ed8; }
.composer button:disabled { background: #9ca3af; cursor: not-allowed; }

/* ---------- Burbujas ---------- */
.bubble {
  max-width: 92%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
}
.bubble.user {
  align-self: flex-end;
  background: #2563eb;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.bubble.bot {
  align-self: flex-start;
  background: #f1f5f9;
  color: #0f172a;
  border-bottom-left-radius: 4px;
  width: 100%;
}
.bubble.bot.error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #7f1d1d;
}
.bubble.bot .meta {
  display: block;
  font-size: 0.72rem;
  color: #64748b;
  margin-top: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.loader {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid #cbd5e1;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Examples ---------- */
.example-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.example {
  background: #eef2ff;
  color: #1e3a8a;
  border: 1px solid #c7d2fe;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  cursor: pointer;
}
.example:hover { background: #e0e7ff; }

/* ---------- Tabla / chart ---------- */
.bubble .table-wrap {
  margin-top: 10px;
  overflow: auto;
  max-height: 360px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
}
.bubble table { width: 100%; border-collapse: collapse; font-size: 0.82rem; background: #fff; }
.bubble th, .bubble td {
  padding: 5px 9px;
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
  white-space: nowrap;
}
.bubble thead th { background: #f1f5f9; position: sticky; top: 0; z-index: 1; }
.bubble tbody tr:hover { background: #f8fafc; }
.chart-wrap { margin-top: 10px; padding: 8px; background: #fff; border-radius: 8px; border: 1px solid #e2e8f0; }
.chart-wrap canvas { max-height: 320px; }
.chart-host { margin-top: 10px; }
.chart-error { margin-top: 10px; padding: 10px 12px; background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; border-radius: 8px; font-size: 13px; }

.debug-block {
  margin-top: 8px;
  background: #0f172a;
  color: #e2e8f0;
  padding: 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.debug-block pre { background: transparent; color: inherit; padding: 0; margin: 0; max-height: 240px; overflow: auto; }
.debug-block.hidden { display: none; }

@media (max-width: 800px) {
  .chat-shell { grid-template-columns: 1fr; }
  .chat-side { order: 2; }
}
