:root,
html[data-theme="dark"] {
  --bg0: #070b14;
  --bg1: #10182a;
  --panel: rgba(255, 255, 255, 0.045);
  --line: rgba(255, 255, 255, 0.09);
  --text: #eef3ff;
  --muted: #9eacc9;
  --accent: #2dd4bf;
  --assistant: rgba(21, 32, 51, 0.92);
  --sidebar: rgba(8, 12, 22, 0.92);
  --user-bubble: linear-gradient(135deg, #1e3a8a, #2563eb);
  --glow-a: #16384a;
  --glow-b: #2a1848;
  --font: "Source Sans 3", "Segoe UI", "IBM Plex Sans", system-ui, sans-serif;
  color-scheme: dark;
}

html[data-theme="eureka"] {
  --bg0: #071221;
  --bg1: #0c1c36;
  --panel: rgba(255, 255, 255, 0.05);
  --line: rgba(107, 143, 240, 0.22);
  --text: #f4f7fc;
  --muted: #9db0cb;
  --accent: #6b8ff0;
  --assistant: rgba(12, 28, 54, 0.95);
  --sidebar: rgba(7, 18, 33, 0.94);
  --user-bubble: linear-gradient(135deg, #1b3665, #547ce9);
  --glow-a: #132848;
  --glow-b: #1a355c;
  color-scheme: dark;
}

html[data-theme="claro"] {
  --bg0: #f1f5f9;
  --bg1: #e8edf4;
  --panel: rgba(15, 23, 42, 0.04);
  --line: rgba(15, 23, 42, 0.12);
  --text: #0f172a;
  --muted: #475569;
  --accent: #0f766e;
  --assistant: #ffffff;
  --sidebar: #ffffff;
  --user-bubble: linear-gradient(135deg, #334155, #475569);
  --glow-a: #cbd5e1;
  --glow-b: #e2e8f0;
  color-scheme: light;
}

html[data-theme="pastel"] {
  --bg0: #f6f1f8;
  --bg1: #eef6fb;
  --panel: rgba(91, 124, 153, 0.08);
  --line: rgba(91, 124, 153, 0.2);
  --text: #3d5a73;
  --muted: #6b8aa3;
  --accent: #7eb6d9;
  --assistant: rgba(255, 255, 255, 0.88);
  --sidebar: rgba(255, 255, 255, 0.92);
  --user-bubble: linear-gradient(135deg, #7eb6d9, #b8a9c9);
  --glow-a: #d9ecf7;
  --glow-b: #eadff0;
  color-scheme: light;
}

html[data-theme="contraste"] {
  --bg0: #000000;
  --bg1: #0a0a0a;
  --panel: rgba(255, 255, 255, 0.08);
  --line: #ffffff;
  --text: #ffffff;
  --muted: #e5e5e5;
  --accent: #ffff00;
  --assistant: #111111;
  --sidebar: #000000;
  --user-bubble: linear-gradient(135deg, #000000, #333333);
  --glow-a: #222222;
  --glow-b: #111111;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1000px 520px at 8% -8%, var(--glow-a) 0%, transparent 55%),
    radial-gradient(800px 420px at 92% 0%, var(--glow-b) 0%, transparent 50%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
  overflow: hidden;
  transition: background .25s ease, color .25s ease;
}

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

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--sidebar);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  max-height: 100vh;
  padding: .85rem .7rem;
  overflow: hidden;
}
.sidebar-top {
  display: flex;
  flex-direction: column;
  gap: .65rem;
  margin-bottom: .75rem;
  flex-shrink: 0;
}
.sidebar-brand {
  font-weight: 700;
  font-size: .95rem;
  color: #ccfbf1;
  letter-spacing: .02em;
}
.btn-new {
  border: 1px solid rgba(45, 212, 191, 0.45);
  background: rgba(45, 212, 191, 0.12);
  color: #99f6e4;
  border-radius: 10px;
  padding: .55rem .7rem;
  font-weight: 650;
  cursor: pointer;
  text-align: left;
}
.btn-new:hover {
  background: rgba(45, 212, 191, 0.22);
  border-color: var(--accent);
}
.chat-list {
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: .35rem;
  min-height: 0;
  flex: 1;
  padding-right: .15rem;
  -webkit-overflow-scrolling: touch;
}
.chat-item-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .2rem;
  align-items: stretch;
  border-radius: 10px;
  border: 1px solid transparent;
}
.chat-item-row:hover {
  background: rgba(255,255,255,0.04);
}
.chat-item-row.active {
  background: rgba(45, 212, 191, 0.12);
  border-color: rgba(45, 212, 191, 0.3);
}
.chat-item {
  border: 0;
  background: transparent;
  color: var(--text);
  border-radius: 10px;
  padding: .55rem .55rem .55rem .65rem;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: .2rem;
  min-width: 0;
}
.chat-item-del {
  border: 0;
  background: transparent;
  color: var(--muted);
  width: 30px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.15rem;
  line-height: 1;
  opacity: .55;
}
.chat-item-del:hover {
  opacity: 1;
  color: #fda4af;
  background: rgba(251, 113, 133, 0.12);
}
.chat-item-title {
  font-size: .84rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item-meta {
  font-size: .72rem;
  color: var(--muted);
}
.chat-empty {
  color: var(--muted);
  font-size: .82rem;
  padding: .5rem .35rem;
}

.app {
  max-width: none;
  width: 100%;
  margin: 0;
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  padding: 1rem 1.25rem 0;
  min-width: 0;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: .6rem 0 .9rem;
  border-bottom: 1px solid var(--line);
}
.brand {
  font-size: 1.55rem;
  font-weight: 750;
  letter-spacing: .01em;
}
.brand span { color: var(--accent); }
.tagline { color: var(--muted); font-size: .88rem; margin-top: .15rem; }
.controls {
  display: flex;
  gap: .75rem;
  align-items: flex-end;
  color: var(--muted);
  font-size: .82rem;
}
.btn-ghost {
  display: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  padding: .4rem .55rem;
  cursor: pointer;
  height: fit-content;
}
select {
  display: block;
  margin-top: .25rem;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .35rem .5rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  padding: .85rem 0 .2rem;
}
.chips button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 999px;
  padding: .35rem .75rem;
  font-size: .8rem;
  cursor: pointer;
}
.chips button:hover { border-color: var(--accent); color: var(--accent); }

.thread {
  overflow-y: auto;
  padding: 1rem 0 1.4rem;
  display: flex;
  flex-direction: column;
  gap: .85rem;
  min-height: 0;
}

.msg {
  max-width: min(1100px, 96%);
  padding: .9rem 1.05rem;
  border-radius: 16px;
  line-height: 1.55;
  border: 1px solid var(--line);
  animation: rise .22s ease;
}
.msg.user {
  align-self: flex-end;
  background: var(--user-bubble);
  white-space: pre-wrap;
  color: #fff;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--assistant);
}
.msg.meta {
  align-self: center;
  color: var(--muted);
  background: transparent;
  border: none;
  font-size: .85rem;
}

/* Typing indicator (igual que Eureka IA v1) */
.msg.typing-msg {
  display: flex;
  align-items: flex-start;
  gap: .65rem;
  max-width: 220px;
  padding: .35rem .45rem;
  background: transparent;
  border: none;
  box-shadow: none;
}
.msg.typing-msg .message-avatar {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(45, 212, 191, 0.14);
  color: var(--accent);
  font-size: .95rem;
  flex-shrink: 0;
  margin-top: .35rem;
}
.msg.typing-msg .message-body {
  min-width: 0;
}
.msg.typing-msg .message-content.typing {
  display: flex;
  gap: 4px;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--assistant);
}
.typing span {
  width: 7px;
  height: 7px;
  background: var(--muted);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

.msg h2, .msg h3 {
  margin: .1rem 0 .55rem;
  font-size: 1.08rem;
  font-weight: 700;
  color: #f0fdfa;
  letter-spacing: .01em;
}
.msg em, .msg i { color: var(--muted); font-style: normal; font-size: .9em; }
.msg strong { color: #5eead4; font-weight: 700; }
.msg ul { margin: .35rem 0 .35rem 1.1rem; padding: 0; }

.msg .table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: .75rem 0 1rem;
  border: 1px solid rgba(45, 212, 191, 0.28);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.28);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}
.msg .table-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: .4rem;
  padding: .45rem .55rem;
  border-bottom: 1px solid rgba(45, 212, 191, 0.18);
  background: rgba(15, 61, 58, 0.35);
  position: sticky;
  left: 0;
}
.msg .msg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  margin-top: .75rem;
  padding-top: .65rem;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.chart-wrap {
  margin: .85rem 0 1rem;
  padding: .75rem .85rem 1rem;
  border: 1px solid rgba(45, 212, 191, 0.28);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.28);
}
.chart-title {
  font-weight: 700;
  color: #99f6e4;
  font-size: .92rem;
  margin-bottom: .55rem;
}
.chart-canvas-box {
  position: relative;
  height: 260px;
  width: 100%;
}
.chart-fallback {
  color: var(--muted);
  font-size: .85rem;
  padding: .5rem 0;
}
.heatmap-scroll {
  overflow-x: auto;
}
.heatmap-table {
  border-collapse: collapse;
  font-size: .78rem;
  min-width: 280px;
}
.heatmap-table th,
.heatmap-table td {
  border: 1px solid rgba(255,255,255,0.08);
  padding: .4rem .45rem;
  text-align: center;
  white-space: nowrap;
}
.heatmap-table thead th,
.heatmap-table tbody th {
  background: #0f3d3a;
  color: #99f6e4;
  font-weight: 650;
}
.btn-export {
  border: 1px solid rgba(45, 212, 191, 0.4);
  background: rgba(45, 212, 191, 0.1);
  color: #99f6e4;
  border-radius: 8px;
  padding: .3rem .65rem;
  font-size: .76rem;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
}
.btn-export:hover {
  background: rgba(45, 212, 191, 0.22);
  border-color: var(--accent);
}
.btn-export-pdf {
  background: rgba(37, 99, 235, 0.16);
  border-color: rgba(96, 165, 250, 0.45);
  color: #bfdbfe;
}
.btn-export-pdf:hover {
  background: rgba(37, 99, 235, 0.28);
  border-color: #93c5fd;
}
.portal-gate {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(4, 8, 16, 0.72);
  backdrop-filter: blur(8px);
}
.portal-gate[hidden] { display: none !important; }
.portal-gate-card {
  max-width: 420px;
  padding: 1.4rem 1.5rem;
  border-radius: 16px;
  border: 1px solid rgba(45, 212, 191, 0.35);
  background: linear-gradient(145deg, #152033, #0f3d3a);
}
.portal-gate-card h2 { margin: 0 0 .6rem; font-size: 1.15rem; }
.portal-gate-card p { margin: 0 0 .55rem; color: var(--muted); line-height: 1.45; }
.portal-gate-note { font-size: .85rem; }
.shell.portal-blocked { filter: blur(2px); pointer-events: none; }
.tenant-locked {
  font-size: .82rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: .2rem;
}
.tenant-locked strong {
  color: #99f6e4;
  font-size: .95rem;
}
body.portal-embedded #tenantLabel,
body.portal-embedded #modeLabel,
html.portal-embedded-boot #tenantLabel,
html.portal-embedded-boot #modeLabel {
  display: none !important;
}
body.portal-embedded .tagline::after {
  content: " · portal";
  color: var(--accent);
}
.msg table.data-table {
  width: 100%;
  min-width: 280px;
  border-collapse: collapse;
  font-size: .88rem;
  margin: 0;
}
.msg table.data-table thead th {
  position: sticky;
  top: 0;
  background: #0f3d3a;
  color: #99f6e4;
  font-weight: 700;
  text-align: left;
  padding: .65rem .75rem;
  border-bottom: 1px solid rgba(45, 212, 191, 0.35);
  white-space: nowrap;
}
.msg table.data-table td {
  padding: .55rem .75rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  color: var(--text);
  vertical-align: middle;
}
.msg table.data-table tr.alt td {
  background: rgba(255,255,255,0.03);
}
.msg table.data-table tbody tr:hover td {
  background: rgba(45, 212, 191, 0.08);
}
.msg table.data-table th.num,
.msg table.data-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}
.msg pre {
  overflow: auto;
  background: rgba(0,0,0,.25);
  padding: .6rem;
  border-radius: 8px;
}
.msg .tools {
  margin-top: .65rem;
  font-size: .78rem;
  color: var(--muted);
}
.msg a { color: var(--accent); }

.msg .report-followup {
  margin-top: .85rem;
  padding-top: .75rem;
  border-top: 1px dashed rgba(255,255,255,0.12);
  color: var(--muted);
  font-size: .92rem;
}
.msg .report-followup strong { color: #99f6e4; }

.export-modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.export-modal[hidden] { display: none !important; }
.export-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 8, 16, 0.62);
  backdrop-filter: blur(8px);
}
.export-modal-card {
  position: relative;
  z-index: 1;
  width: min(360px, 100%);
  padding: 1.25rem 1.3rem 1.1rem;
  border-radius: 16px;
  border: 1px solid rgba(45, 212, 191, 0.3);
  background: linear-gradient(145deg, #152033, #0f3d3a);
  box-shadow: 0 20px 50px rgba(0,0,0,.45);
}
.export-modal-card h2 {
  margin: 0 0 .45rem;
  font-size: 1.1rem;
  color: #f0fdfa;
}
.export-modal-card p {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: .9rem;
}
.export-modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .55rem;
  margin-bottom: .75rem;
}
.btn-export-choice {
  border: 1px solid rgba(45, 212, 191, 0.4);
  background: rgba(45, 212, 191, 0.14);
  color: #ccfbf1;
  border-radius: 10px;
  padding: .7rem .6rem;
  font-weight: 700;
  cursor: pointer;
}
.btn-export-choice:hover {
  background: rgba(45, 212, 191, 0.28);
  border-color: var(--accent);
}
.btn-export-cancel {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: .45rem;
  cursor: pointer;
  border-radius: 8px;
}
.btn-export-cancel:hover {
  color: var(--text);
  background: rgba(255,255,255,0.05);
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .6rem;
  padding: .85rem 0 1.1rem;
  border-top: 1px solid var(--line);
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, transparent, rgba(0,0,0,.35) 30%);
}
textarea {
  resize: none;
  min-height: 48px;
  max-height: 160px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.045);
  color: var(--text);
  padding: .85rem 1rem;
  font: inherit;
}
button#send {
  border: 0;
  border-radius: 14px;
  padding: 0 1.25rem;
  background: var(--accent);
  color: #042f2e;
  font-weight: 750;
  cursor: pointer;
  min-width: 92px;
}
button#send:disabled { opacity: .55; cursor: wait; }

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(280px, 86vw);
    z-index: 40;
    transform: translateX(-105%);
    transition: transform .2s ease;
    box-shadow: 12px 0 40px rgba(0,0,0,.35);
  }
  .sidebar.open { transform: none; }
  .btn-ghost { display: inline-block; }
  .msg { max-width: 96%; }
  .controls { flex-wrap: wrap; justify-content: flex-end; }
}
