:root {
  --bg: #0f1117;
  --panel: #171a23;
  --border: #262b38;
  --accent: #76b900;      /* verde NVIDIA */
  --user: #1f6feb;
  --text: #e6e8ee;
  --muted: #8b93a7;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  height: 100vh;
  max-width: 100%;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
}
header .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #555; transition: background .3s;
}
header .dot.on { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
header h1 { font-size: 16px; margin: 0; font-weight: 600; }
header small { color: var(--muted); font-weight: 400; }
header .spacer { flex: 1; }
#geo { white-space: nowrap; }
header .back-link { color: var(--muted); text-decoration: none; font-size: 14px; }
header .back-link:hover { color: var(--text); }

/* ---- menú ---- */
.menu { position: relative; }
#menu-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}
#menu-btn:hover { border-color: var(--accent); }
.menu-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  min-width: 160px;
  padding: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  z-index: 20;
}
.menu-dropdown.open { display: block; }
.menu-dropdown a {
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
}
.menu-dropdown a:hover { background: var(--bg); color: var(--accent); }

/* ---- página de sesiones ---- */
#sessions-wrap { flex: 1; overflow: auto; padding: 20px; }
#sessions-table { width: 100%; border-collapse: collapse; font-size: .92em; }
#sessions-table th, #sessions-table td {
  border: 1px solid var(--border);
  padding: 10px 12px;
  text-align: left;
  white-space: nowrap;
}
#sessions-table thead th { background: var(--panel); color: #fff; font-weight: 600; }
.session-row { cursor: pointer; }
.session-row:hover td { background: rgba(255, 255, 255, .04); }
.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.pill.on { background: rgba(118, 185, 0, .15); color: var(--accent); }
.pill.off { background: rgba(139, 147, 167, .15); color: var(--muted); }
#sessions-empty { color: var(--muted); padding: 0 20px; }

/* ---- modal de historial ---- */
#history-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
#history-overlay.open { display: flex; }
#history-panel {
  width: 100%;
  max-width: 720px;
  max-height: 85vh;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#history-panel header { padding: 14px 18px; }
#history-panel h1 { font-size: 15px; }
#history-close {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 4px 10px;
  cursor: pointer;
}
#history-close:hover { color: var(--text); border-color: var(--accent); }
#history-chat {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#history-chat .muted { color: var(--muted); }

#chat {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.msg { max-width: min(780px, 100%); width: fit-content; padding: 12px 16px; border-radius: 14px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; min-width: 0; }
.msg.user { align-self: flex-end; background: var(--user); border-bottom-right-radius: 4px; }
.msg.bot  { align-self: flex-start; background: var(--panel); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.err  { align-self: flex-start; background: #3a1a1a; border: 1px solid #6b2b2b; color: #ffb4b4; }
.msg .role { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 4px; }
.msg .role .time { text-transform: none; letter-spacing: normal; font-weight: 400; opacity: .75; margin-left: 6px; }
.cursor .content::after { content: "▋"; animation: blink 1s steps(2) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

/* ---- markdown ---- */
.msg.bot .content { white-space: normal; }
.content strong { color: var(--accent); font-weight: 700; }
.content em { color: #c9a3ff; font-style: italic; }
.content h1, .content h2, .content h3 { color: #fff; margin: .6em 0 .3em; line-height: 1.25; }
.content h1 { font-size: 1.3em; } .content h2 { font-size: 1.18em; } .content h3 { font-size: 1.05em; }
.content a { color: #58a6ff; }
.content ul, .content ol { margin: .4em 0; padding-left: 1.4em; }
.content li { margin: .2em 0; }
.content p { margin: .5em 0; }
.content p:first-child { margin-top: 0; }
.content p:last-child { margin-bottom: 0; }
.content code {
  background: #0b0d13; color: #ff9e64;
  padding: 2px 6px; border-radius: 5px;
  font-family: "SFMono-Regular", Consolas, monospace; font-size: .9em;
}
.content pre {
  background: #0b0d13; border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 14px; overflow-x: auto; margin: .6em 0;
  max-width: 100%;
}
.content pre code { background: none; color: #d5d9e0; padding: 0; white-space: pre; overflow-wrap: normal; word-break: normal; }
.content code { overflow-wrap: anywhere; }
.content blockquote {
  margin: .5em 0; padding: 2px 12px;
  border-left: 3px solid var(--accent); color: var(--muted);
}
.content hr { border: none; border-top: 1px solid var(--border); margin: .8em 0; }
.content .table-wrap { overflow-x: auto; margin: .6em 0; max-width: 100%; }
.content table { border-collapse: collapse; width: 100%; font-size: .92em; }
.content th, .content td { border: 1px solid var(--border); padding: 7px 11px; text-align: left; }
.content thead th { background: #0b0d13; color: #fff; font-weight: 600; }
.content tbody tr:nth-child(even) { background: rgba(255, 255, 255, .03); }

footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  gap: 10px;
}
#input {
  flex: 1;
  resize: none;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  max-height: 160px;
}
#input:focus { outline: none; border-color: var(--accent); }
#send {
  background: var(--accent);
  color: #0f1117;
  border: none;
  border-radius: 10px;
  padding: 0 22px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
#send:disabled { opacity: .5; cursor: not-allowed; }

/* ---- responsive móvil ---- */
@media (max-width: 640px) {
  header { padding: 10px 14px; }
  header h1 { font-size: 15px; }
  header small { display: block; font-size: 11px; word-break: break-all; }

  #chat { padding: 14px; gap: 10px; }
  .msg { max-width: 100%; padding: 10px 13px; font-size: 15px; }

  footer { padding: 10px 12px; gap: 8px; }
  #input { padding: 10px 12px; font-size: 16px; } /* 16px evita el zoom en iOS */
  #send { padding: 0 16px; }
}
