:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --lateral: #eef1f6;
  --texto: #1b2230;
  --suave: #5d6878;
  --borde: #dde2ea;
  --acento: #1f5fd1;
  --acento-texto: #ffffff;
  --burbuja-user: #e3ecfc;
  --codigo: #f0f2f5;
  --error: #b42318;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171c;
    --panel: #1b1f26;
    --lateral: #111418;
    --texto: #e6e9ef;
    --suave: #9aa4b2;
    --borde: #2c323c;
    --acento: #5b8def;
    --burbuja-user: #24324d;
    --codigo: #232830;
    --error: #f97066;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--texto);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }

.logo {
  width: 48px; height: 48px; border-radius: 12px;
  background: var(--acento); color: var(--acento-texto);
  display: grid; place-items: center; font-weight: 700; font-size: 24px;
  margin: 0 auto 12px;
}

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  background: var(--panel); border: 1px solid var(--borde); border-radius: 16px;
  padding: 32px 28px; max-width: 400px; width: 100%; text-align: center;
}
.login-card h1 { margin: 0 0 8px; font-size: 26px; }
.login-card p { color: var(--suave); margin: 0 0 24px; }
.btn-primario {
  width: 100%; padding: 12px; border: 0; border-radius: 10px;
  background: var(--acento); color: var(--acento-texto); font-weight: 600;
}
.error, .login-card .error { color: var(--error); margin-top: 16px !important; margin-bottom: 0; }

/* Layout chat */
.app { display: flex; height: 100%; }
.lateral {
  width: 290px; flex-shrink: 0; background: var(--lateral); border-right: 1px solid var(--borde);
  display: flex; flex-direction: column; padding: 12px;
}
.btn-nueva {
  padding: 10px; border-radius: 10px; border: 1px solid var(--borde);
  background: var(--panel); color: var(--texto); font-weight: 600; text-align: left;
}
.buscar {
  margin-top: 10px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--borde);
  background: var(--panel); color: var(--texto); font: inherit; font-size: 14px;
}
.buscar:focus { outline: 2px solid var(--acento); outline-offset: -1px; }
.lista { flex: 1; overflow-y: auto; margin: 8px -4px 12px; }
.grupo {
  font-size: 12px; font-weight: 600; color: var(--suave); text-transform: uppercase; letter-spacing: 0.03em;
  padding: 12px 10px 4px;
}
.lista-vacia { font-size: 13px; color: var(--suave); padding: 8px 10px; margin: 0; }
.item { display: flex; align-items: center; border-radius: 8px; }
.item:hover { background: var(--borde); }
.item.activo { background: var(--panel); }
.item-titulo {
  flex: 1; min-width: 0; text-align: left; padding: 7px 10px; border: 0; background: transparent;
  color: var(--texto); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.item.activo .item-titulo { font-weight: 600; }
.item-pendiente {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--acento);
  margin-right: 6px; vertical-align: middle; animation: latido 1s ease-in-out infinite;
}
.item-accion {
  flex-shrink: 0; width: 26px; height: 26px; border: 0; border-radius: 6px; background: transparent;
  color: var(--suave); font-size: 13px; padding: 0; opacity: 0;
}
.item:hover .item-accion, .item.activo .item-accion, .item-accion:focus-visible { opacity: 1; }
.item-accion:hover { background: var(--bg); color: var(--texto); }
.item-input {
  flex: 1; min-width: 0; margin: 2px; padding: 5px 8px; border-radius: 6px; border: 1px solid var(--acento);
  background: var(--panel); color: var(--texto); font: inherit; font-size: 14px;
}
.consumo { font-size: 12px; color: var(--suave); padding: 0 2px 8px; }
.consumo:empty { display: none; }
.usuario {
  border-top: 1px solid var(--borde); padding-top: 10px; font-size: 13px; color: var(--suave);
  display: flex; justify-content: space-between; gap: 8px; align-items: center;
}
.usuario span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-link { background: none; border: 0; color: var(--acento); padding: 0; }

.principal { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.barra { display: none; }
.mensajes { flex: 1; overflow-y: auto; padding: 24px 16px; }
.mensajes > * { max-width: 780px; margin-left: auto; margin-right: auto; }

.bienvenida { text-align: center; padding-top: 10vh; }
.bienvenida h2 { font-size: 22px; margin: 0 0 24px; }
.sugerencias { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sugerencia {
  padding: 12px; border: 1px solid var(--borde); border-radius: 12px; background: var(--panel);
  color: var(--texto); text-align: left;
}
.sugerencia:hover { border-color: var(--acento); }

.msg { margin-bottom: 20px; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .cuerpo {
  background: var(--burbuja-user); padding: 10px 14px; border-radius: 14px 14px 4px 14px;
  max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.bot .cuerpo { overflow-wrap: anywhere; }
.msg.bot .cuerpo :first-child { margin-top: 0; }
.msg.bot .cuerpo pre, .msg.bot .cuerpo code { background: var(--codigo); border-radius: 6px; }
.msg.bot .cuerpo code { padding: 1px 4px; font-size: 0.92em; }
.msg.bot .cuerpo pre { padding: 10px; overflow-x: auto; }
.msg.bot .cuerpo pre code { padding: 0; }
.msg.bot .cuerpo table { border-collapse: collapse; display: block; overflow-x: auto; }
.msg.bot .cuerpo th, .msg.bot .cuerpo td { border: 1px solid var(--borde); padding: 4px 8px; }
.msg.bot .cuerpo a { color: var(--acento); }
.estado { color: var(--suave); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.estado::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--acento);
  animation: latido 1s ease-in-out infinite;
}
@keyframes latido { 50% { opacity: 0.25; } }
.msg .aviso { color: var(--error); font-size: 14px; }
.acciones { margin-top: 6px; }
.acciones button { background: none; border: 0; color: var(--suave); font-size: 13px; padding: 0; }

.composer { padding: 0 16px; max-width: 812px; width: 100%; margin: 0 auto; }
/* Caja única como en Claude: [+] texto [enviar] */
.composer-fila {
  display: flex; gap: 4px; align-items: flex-end; padding: 6px;
  border: 1px solid var(--borde); border-radius: 16px; background: var(--panel);
}
.composer-fila:focus-within { border-color: var(--acento); box-shadow: 0 0 0 1px var(--acento); }
.mas { position: relative; flex-shrink: 0; }
.btn-mas {
  width: 36px; height: 36px; border-radius: 10px; border: 0; background: transparent; color: var(--suave);
  display: grid; place-items: center; padding: 0;
}
.btn-mas:hover, .btn-mas[aria-expanded="true"] { background: var(--codigo); color: var(--texto); }
.menu-mas {
  position: absolute; bottom: calc(100% + 10px); left: -6px; z-index: 12; width: 300px; max-width: calc(100vw - 32px);
  background: var(--panel); border: 1px solid var(--borde); border-radius: 12px; padding: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}
.menu-mas button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 8px;
  background: transparent; color: var(--texto); text-align: left;
}
.menu-mas button:hover, .menu-mas button:focus-visible { background: var(--codigo); outline: none; }
.menu-mas button span { flex: 1; }
.menu-mas kbd { font: inherit; font-size: 12px; color: var(--suave); }
.menu-ayuda { margin: 4px 10px 4px; font-size: 12px; color: var(--suave); }
.adjuntos { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.miniatura { position: relative; }
.miniatura img, .msg-imagenes img {
  width: 72px; height: 72px; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--borde); display: block; cursor: zoom-in;
}
.miniatura button {
  position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%;
  border: 0; background: var(--texto); color: var(--bg); font-size: 13px; line-height: 22px; padding: 0;
}
.msg-imagenes { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; margin-bottom: 6px; }
.msg.user { flex-direction: column; align-items: flex-end; }
.visor {
  position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.8);
  display: grid; place-items: center; padding: 16px; cursor: zoom-out;
}
.visor img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.soltar {
  position: fixed; inset: 12px; z-index: 15; border: 3px dashed var(--acento); border-radius: 16px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  display: grid; place-items: center; font-size: 18px; font-weight: 600; color: var(--acento); pointer-events: none;
}
.aviso-larga {
  max-width: 780px; width: calc(100% - 32px); margin: 0 auto 8px; padding: 8px 12px; border-radius: 10px;
  background: var(--codigo); color: var(--suave); font-size: 13px;
}
.composer textarea {
  flex: 1; resize: none; max-height: 200px; overflow-y: hidden; min-height: 36px; padding: 7px 6px;
  border: 0; background: transparent; color: var(--texto); font: inherit;
}
.composer textarea:focus { outline: none; }
.btn-enviar {
  width: 36px; height: 36px; border-radius: 10px; border: 0; flex-shrink: 0;
  background: var(--acento); color: var(--acento-texto); display: grid; place-items: center; padding: 0;
}
.btn-enviar:disabled { opacity: 0.5; cursor: default; }
.pie { text-align: center; color: var(--suave); font-size: 12px; margin: 8px 16px 12px; }

@media (max-width: 760px) {
  .lateral {
    position: fixed; inset: 0 auto 0 0; z-index: 10; transform: translateX(-100%);
    transition: transform 0.2s; box-shadow: 0 0 24px rgba(0, 0, 0, 0.2);
  }
  .lateral.abierto { transform: none; }
  .barra {
    display: flex; align-items: center; gap: 12px; padding: 10px 16px;
    border-bottom: 1px solid var(--borde); background: var(--panel);
  }
  .barra-titulo { font-weight: 600; }
  .btn-menu { background: none; border: 0; color: var(--texto); font-size: 20px; padding: 0; }
  .sugerencias { grid-template-columns: 1fr; }
  .item-accion { opacity: 1; }
  .atajos { display: none; }
  .bienvenida { padding-top: 4vh; }
}
