:root {
  --bg: #080b12;
  --bg-soft: #0e1422;
  --panel: #141c2e;
  --panel-2: #182236;
  --accent: #36d3ff;
  --accent-2: #4f8cff;
  --accent-dim: #1c7fa0;
  --text: #eaf1fb;
  --text-dim: #8b97ad;
  --user-grad: linear-gradient(135deg, #2f7bff, #36d3ff);
  --jarvis-border: #233150;
  --radius: 18px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

/* Fondo con halo */
.bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(60% 38% at 50% -4%, rgba(54, 211, 255, 0.16), transparent 70%),
    radial-gradient(50% 30% at 100% 100%, rgba(79, 140, 255, 0.10), transparent 70%);
  z-index: 0;
}

/* Topbar */
.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) 16px 12px;
  background: linear-gradient(180deg, rgba(14, 20, 34, 0.92), rgba(8, 11, 18, 0.4));
  backdrop-filter: blur(14px);
  border-bottom: 1px solid #1a2236;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-avatar {
  position: relative;
  width: 42px; height: 42px;
  border-radius: 50%;
  padding: 2px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 14px rgba(54, 211, 255, 0.45);
}
.brand-avatar img { width: 100%; height: 100%; border-radius: 50%; display: block; object-fit: cover; }
.status-dot {
  position: absolute; right: -1px; bottom: -1px;
  width: 12px; height: 12px; border-radius: 50%;
  background: #2bdc8a; border: 2px solid var(--bg-soft);
  box-shadow: 0 0 6px #2bdc8a; transition: background .2s, box-shadow .2s;
}
.status-dot.off { background: #e0556b; box-shadow: 0 0 6px #e0556b; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; gap: 2px; }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: 0.3px; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: none; border: none; color: var(--text); cursor: pointer; padding: 0; text-align: left; }
.mode-chip {
  align-self: flex-start;
  background: rgba(54, 211, 255, 0.12); color: var(--accent);
  border: 1px solid rgba(54, 211, 255, 0.3); border-radius: 999px;
  font-size: 11px; padding: 1px 9px; cursor: pointer; font-weight: 600;
}

.icon-btn {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; padding: 8px; border-radius: 12px; display: grid; place-items: center;
  transition: color .15s, background .15s;
}
.icon-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }

/* Chat */
.chat {
  position: relative;
  z-index: 1;
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}
.chat::-webkit-scrollbar { width: 7px; }
.chat::-webkit-scrollbar-thumb { background: #1f2942; border-radius: 4px; }

.msg { display: flex; align-items: flex-end; gap: 9px; animation: rise .28s ease both; }
.msg.user { justify-content: flex-end; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.avatar {
  flex: 0 0 30px; width: 30px; height: 30px;
  border-radius: 50%; overflow: hidden;
  border: 1px solid var(--jarvis-border);
  box-shadow: 0 0 8px rgba(54, 211, 255, 0.25);
  align-self: flex-start;
  margin-top: 2px;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.msg.user .avatar { display: none; }

.bubble {
  max-width: 78%;
  padding: 11px 15px;
  border-radius: var(--radius);
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  font-size: 15px;
  box-shadow: var(--shadow);
}
.msg.jarvis .bubble {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--jarvis-border);
  border-bottom-left-radius: 5px;
}
.msg.user .bubble {
  background: var(--user-grad);
  color: #04121f;
  font-weight: 500;
  border-bottom-right-radius: 5px;
}
.msg.error .bubble { background: #3a1620; border: 1px solid #7a2638; color: #ffb3bf; }
.col { display: flex; flex-direction: column; max-width: 78%; }
.col .bubble { max-width: 100%; }
.msg.user .col { align-items: flex-end; }
.aborted { color: var(--text-dim); font-style: italic; font-size: 13px; }

/* Acciones por mensaje (copiar/leer/regenerar) */
.actions { display: flex; gap: 4px; margin: 4px 2px 0; opacity: .55; transition: opacity .15s; }
.actions:hover { opacity: 1; }
.msg.user .actions, .msg.error .actions { display: none; }
.act { background: none; border: none; color: var(--text-dim); cursor: pointer; padding: 4px 6px; border-radius: 8px; display: grid; place-items: center; }
.act:hover { color: var(--accent); background: rgba(54,211,255,.1); }

/* Sugerencias */
.suggest { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 6px; }
.chip { background: var(--panel); border: 1px solid #25304a; color: var(--text); border-radius: 999px; padding: 8px 14px; font-size: 13px; cursor: pointer; transition: border-color .15s, background .15s; }
.chip:hover { border-color: var(--accent-dim); background: var(--panel-2); }

/* Stop */
.send-btn.stop { background: linear-gradient(135deg, #e0556b, #ff7a5c); box-shadow: 0 4px 14px rgba(224,85,107,.4); }
.hidden { display: none !important; }

/* Editar chat */
.edit-row { display: flex; gap: 12px; }
.edit-row .emoji { width: 70px; }
.edit-row .emoji input { text-align: center; font-size: 20px; }
.settings textarea { width: 100%; margin-top: 7px; padding: 10px 12px; border-radius: 11px; border: 1px solid #2a3450; background: var(--bg); color: var(--text); font-size: 14px; font-family: inherit; resize: vertical; }
.settings select { width: 100%; margin-top: 7px; padding: 11px 13px; border-radius: 11px; border: 1px solid #2a3450; background: var(--bg); color: var(--text); font-size: 14px; }
.settings input[type=range] { width: 100%; accent-color: var(--accent); }

/* Tools del drawer */
.drawer-tools { display: flex; gap: 8px; margin-top: 10px; }
.ghost.sm { flex: 1; padding: 8px; border-radius: 10px; border: 1px solid #25304a; background: transparent; color: var(--text-dim); cursor: pointer; font-size: 13px; }
.ghost.sm:hover { color: var(--text); border-color: var(--accent-dim); }
.bubble a { color: var(--accent); }

.bubble code {
  background: rgba(0, 0, 0, 0.35); padding: 1px 6px; border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
}
.bubble pre {
  background: #060a12; padding: 11px 13px; border-radius: 12px;
  overflow-x: auto; margin: 7px 0; border: 1px solid #1a2236;
}
.bubble pre code { background: none; padding: 0; }

/* Empty / welcome state */
.welcome {
  margin: auto;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 24px;
  animation: rise .4s ease both;
}
.welcome img {
  width: 96px; height: 96px; border-radius: 50%;
  border: 2px solid transparent;
  background: linear-gradient(var(--bg), var(--bg)) padding-box,
              linear-gradient(135deg, var(--accent), var(--accent-2)) border-box;
  box-shadow: 0 0 28px rgba(54, 211, 255, 0.35);
}
.welcome h1 { margin: 0; font-size: 22px; font-weight: 700; }
.welcome p { margin: 0; color: var(--text-dim); font-size: 14px; max-width: 280px; }

/* Typing indicator (como burbuja de Jarvis) */
.typing-bubble { display: flex; gap: 5px; align-items: center; padding: 14px 16px !important; }
.typing-bubble span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  animation: blink 1.2s infinite both;
}
.typing-bubble span:nth-child(2) { animation-delay: .2s; }
.typing-bubble span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100% { opacity: .25; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }

/* Composer */
.composer {
  position: relative; z-index: 2;
  padding: 10px 12px max(10px, env(safe-area-inset-bottom));
  background: linear-gradient(0deg, var(--bg-soft), transparent);
}
.composer-inner {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--panel);
  border: 1px solid #25304a;
  border-radius: 26px;
  padding: 5px 5px 5px 6px;
  transition: border-color .18s, box-shadow .18s;
}
.composer-inner:focus-within {
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px rgba(54, 211, 255, 0.12);
}
#input {
  flex: 1;
  resize: none;
  max-height: 140px;
  padding: 9px 8px 9px 12px;
  border: none; background: transparent;
  color: var(--text); font-size: 15px; font-family: inherit;
  line-height: 1.4;
}
#input:focus { outline: none; }
#input::placeholder { color: #5b6680; }
.send-btn {
  width: 42px; height: 42px; flex: 0 0 42px;
  border-radius: 50%; border: none; cursor: pointer;
  background: var(--user-grad); color: #04121f;
  display: grid; place-items: center;
  box-shadow: 0 4px 14px rgba(54, 211, 255, 0.35);
  transition: transform .12s, opacity .15s;
}
.send-btn:active { transform: scale(0.92); }
.send-btn:disabled { opacity: .4; cursor: default; box-shadow: none; }

/* Botones de voz (mic + modo conversación) */
.mic-btn {
  width: 40px; height: 40px; flex: 0 0 40px;
  border-radius: 50%; border: none; cursor: pointer;
  background: transparent; color: var(--text-dim);
  display: grid; place-items: center; transition: color .15s, background .15s, transform .12s;
}
.mic-btn:hover { color: var(--text); background: rgba(255,255,255,.05); }
.mic-btn.active { color: #04121f; background: var(--accent); box-shadow: 0 0 14px rgba(54,211,255,.5); animation: micpulse 1.3s infinite; }
@keyframes micpulse { 0%,100% { box-shadow: 0 0 10px rgba(54,211,255,.4); } 50% { box-shadow: 0 0 20px rgba(54,211,255,.8); } }
.tool-status { color: var(--accent); font-size: 14px; }

/* Pantalla de conversación por voz (full screen, estilo ChatGPT) */
.voice-screen {
  position: fixed; inset: 0; z-index: 40;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 26px;
  background:
    radial-gradient(60% 50% at 50% 38%, rgba(20,40,70,.5), transparent 70%),
    radial-gradient(circle at 50% 42%, rgba(10,14,22,.94), rgba(6,9,15,.98));
  backdrop-filter: blur(10px);
  padding: 24px;
}
.voice-screen.hidden { display: none; }
.voice-close {
  position: absolute; top: max(16px, env(safe-area-inset-top)); right: 18px;
  background: rgba(255,255,255,.06); border: none; color: var(--text-dim);
  width: 44px; height: 44px; border-radius: 50%; cursor: pointer; display: grid; place-items: center;
}
.voice-close:hover { color: var(--text); background: rgba(255,255,255,.12); }

.orb {
  position: relative; width: 168px; height: 168px; cursor: pointer;
  display: grid; place-items: center;
}
.orb img {
  width: 150px; height: 150px; border-radius: 50%; z-index: 2;
  box-shadow: 0 0 44px rgba(54,211,255,.55);
  transition: transform .25s, box-shadow .25s;
}
.orb-ring {
  position: absolute; inset: 0; margin: auto; width: 150px; height: 150px;
  border-radius: 50%; border: 2px solid var(--accent); opacity: 0;
}

/* Estado: escuchando -> anillos expandiéndose */
.orb[data-state="listening"] .orb-ring { animation: ring 1.8s ease-out infinite; }
.orb[data-state="listening"] .orb-ring.r2 { animation-delay: .6s; }
.orb[data-state="listening"] .orb-ring.r3 { animation-delay: 1.2s; }
@keyframes ring { 0% { transform: scale(1); opacity: .7; } 100% { transform: scale(2.1); opacity: 0; } }

/* Estado: pensando -> giro suave + atenuado */
.orb[data-state="thinking"] img { box-shadow: 0 0 30px rgba(54,211,255,.3); animation: breathe 1.4s ease-in-out infinite; }
@keyframes breathe { 0%,100% { transform: scale(.97); } 50% { transform: scale(1.02); } }

/* Estado: hablando -> pulso luminoso */
.orb[data-state="speaking"] img { animation: glow 0.7s ease-in-out infinite; }
@keyframes glow { 0%,100% { box-shadow: 0 0 40px rgba(54,211,255,.5); transform: scale(1); } 50% { box-shadow: 0 0 70px rgba(54,211,255,.95); transform: scale(1.04); } }

.voice-statelabel { color: var(--text); font-size: 18px; font-weight: 600; margin: 0; letter-spacing: .3px; }
.voice-caption { color: var(--text-dim); font-size: 15px; line-height: 1.5; text-align: center; max-width: 520px; min-height: 44px; margin: 0; }
.voice-hint { position: absolute; bottom: max(22px, env(safe-area-inset-bottom)); color: #5b6680; font-size: 12px; }

/* Drawer de chats */
.drawer { position: fixed; inset: 0; z-index: 25; }
.drawer.hidden { display: none; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); backdrop-filter: blur(2px); animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.drawer-panel {
  position: absolute; top: 0; left: 0; bottom: 0; width: min(82vw, 330px);
  background: var(--bg-soft); border-right: 1px solid #1e2740;
  display: flex; flex-direction: column; padding: max(16px, env(safe-area-inset-top)) 14px 16px;
  box-shadow: 8px 0 30px rgba(0,0,0,.5); animation: slidein .22s ease;
}
@keyframes slidein { from { transform: translateX(-100%); } to { transform: none; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.drawer-head h2 { margin: 0; font-size: 18px; }
.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.chat-item {
  display: flex; align-items: center; gap: 11px; padding: 11px 12px;
  border-radius: 12px; cursor: pointer; border: 1px solid transparent; transition: background .12s;
}
.chat-item:hover { background: rgba(255,255,255,.04); }
.chat-item.active { background: rgba(54,211,255,.1); border-color: rgba(54,211,255,.28); }
.ci-icon { font-size: 20px; }
.ci-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.ci-title { font-size: 14.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-sub { font-size: 11.5px; color: var(--text-dim); }
.ci-del { background: none; border: none; color: #5b6680; cursor: pointer; font-size: 14px; padding: 4px 6px; border-radius: 8px; }
.ci-del:hover { color: #ffb3bf; background: rgba(255,80,100,.1); }
.drawer-foot { font-size: 11.5px; color: var(--text-dim); margin: 12px 4px 0; }
.primary.sm { padding: 7px 13px; font-size: 13px; border-radius: 10px; border: none; background: var(--user-grad); color: #04121f; font-weight: 600; cursor: pointer; }

/* Switch row en ajustes */
.switch-row { display: flex; align-items: center; justify-content: space-between; color: var(--text); font-size: 14px; }
.switch-row input { width: auto; margin: 0; transform: scale(1.3); accent-color: var(--accent); }

/* Settings dialog */
.settings {
  border: 1px solid #25304a; border-radius: 18px;
  background: var(--panel); color: var(--text);
  padding: 24px; width: min(92vw, 430px); box-shadow: var(--shadow);
}
.settings::backdrop { background: rgba(0, 0, 0, 0.65); backdrop-filter: blur(3px); }
.settings h2 { margin: 0 0 18px; font-size: 19px; }
.settings label { display: block; margin-bottom: 15px; font-size: 12.5px; color: var(--text-dim); }
.settings input {
  width: 100%; margin-top: 7px; padding: 11px 13px;
  border-radius: 11px; border: 1px solid #2a3450; background: var(--bg);
  color: var(--text); font-size: 15px;
}
.settings input:focus { outline: none; border-color: var(--accent-dim); }
.hint { font-size: 12px; color: var(--text-dim); }
.row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 10px; }
.settings button { padding: 10px 18px; border-radius: 11px; border: none; cursor: pointer; font-size: 14px; }
.settings .primary { background: var(--user-grad); color: #04121f; font-weight: 600; }
.settings .ghost { background: transparent; color: var(--text-dim); }
