:root {
  --fondo: #f6f4ef;
  --superficie: #ffffff;
  --superficie-2: #efece5;
  --borde: #ddd8cc;
  --texto: #1f2328;
  --texto-suave: #5f6368;
  --acento: #1e3a5f;
  --acento-texto: #ffffff;
  --acento-suave: #e3eaf3;
  --enlace: #1d4f91;
  --error: #b42318;
  --radio: 10px;
  --sombra: 0 1px 3px rgba(0, 0, 0, 0.08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #16181c;
    --superficie: #1f2227;
    --superficie-2: #2a2e35;
    --borde: #363b44;
    --texto: #e8e6e3;
    --texto-suave: #a0a4ab;
    --acento: #7fa6d9;
    --acento-texto: #10151c;
    --acento-suave: #25303f;
    --enlace: #8fb6ea;
    --error: #f97066;
    --sombra: none;
    color-scheme: dark;
  }
}

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

.boton-principal {
  background: var(--acento);
  color: var(--acento-texto);
  border: 0;
  border-radius: var(--radio);
  padding: 10px 16px;
  font-weight: 600;
}
.boton-principal:disabled { opacity: 0.5; cursor: default; }
.boton-principal.ancho { width: 100%; }
.icono {
  background: none;
  border: 0;
  font-size: 20px;
  padding: 6px 8px;
  border-radius: 8px;
  color: var(--texto);
  cursor: pointer;
}
.icono:hover { background: var(--superficie-2); }
.enlace { background: none; border: 0; color: var(--enlace); padding: 0; }
.error { color: var(--error); margin: 0; }

/* Ingreso */
.ingreso { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.tarjeta-ingreso {
  width: 100%;
  max-width: 380px;
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: 16px;
  padding: 32px 28px;
  display: grid;
  gap: 14px;
  box-shadow: var(--sombra);
}
.tarjeta-ingreso h1 { margin: 0; text-align: center; }
.marca-grande { font-size: 40px; text-align: center; }
.sub { margin: 0 0 8px; text-align: center; color: var(--texto-suave); font-size: 14px; }
.tarjeta-ingreso label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; }
.tarjeta-ingreso input {
  padding: 10px 12px;
  border: 1px solid var(--borde);
  border-radius: 8px;
  background: var(--fondo);
  font-weight: 400;
}

/* Aplicación */
.app { display: grid; grid-template-columns: 280px 1fr; height: 100%; }
.lateral {
  background: var(--superficie);
  border-right: 1px solid var(--borde);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 12px;
  min-height: 0;
}
.lateral-cabecera { display: flex; justify-content: space-between; align-items: center; padding: 0 4px; }
.marca { font-weight: 700; font-size: 18px; }
.lista { flex: 1; overflow-y: auto; display: grid; align-content: start; gap: 2px; }
.item-conversacion {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 8px;
}
.item-conversacion a {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  color: var(--texto);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14px;
}
.item-conversacion:hover, .item-conversacion.activa { background: var(--superficie-2); }
.item-conversacion .borrar { visibility: hidden; font-size: 14px; color: var(--texto-suave); }
.item-conversacion:hover .borrar { visibility: visible; }
.lateral-pie {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--borde);
  padding: 12px 4px 0;
  font-size: 14px;
  color: var(--texto-suave);
}

.principal { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; }
.barra {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--borde);
  background: var(--superficie);
}
.barra h2 { margin: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.solo-movil { display: none; }

.mensajes { flex: 1; overflow-y: auto; padding: 24px 20px; }
.mensajes > * { max-width: 820px; margin-left: auto; margin-right: auto; }

.bienvenida { padding-top: 6vh; text-align: center; }
.bienvenida h1 { margin: 0 0 8px; font-size: 28px; }
.bienvenida > p { color: var(--texto-suave); max-width: 560px; margin: 0 auto; }
.atajos { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 28px auto; max-width: 600px; }
.atajos button {
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: 14px;
  text-align: left;
  color: var(--texto);
  font-weight: 600;
  display: grid;
  gap: 2px;
}
.atajos button:hover { border-color: var(--acento); }
.atajos small { font-weight: 400; color: var(--texto-suave); }
.nota { font-size: 13px; color: var(--texto-suave); }

.mensaje { margin-bottom: 20px; }
.mensaje.usuario { display: flex; flex-direction: column; align-items: flex-end; }
.mensaje.usuario .burbuja {
  background: var(--acento-suave);
  border-radius: 14px 14px 4px 14px;
  padding: 10px 14px;
  max-width: 85%;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.chip {
  font-size: 13px;
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: 999px;
  padding: 2px 10px;
}
.chip button { background: none; border: 0; padding: 0 0 0 6px; color: var(--texto-suave); }

.mensaje.eduardito .contenido {
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: 14px;
  padding: 14px 18px;
  overflow-wrap: anywhere;
  box-shadow: var(--sombra);
}
.pasos { font-size: 13px; color: var(--texto-suave); margin-bottom: 8px; }
.pasos summary { cursor: pointer; }
.pasos ul { margin: 6px 0 0; padding-left: 18px; }
.estado { font-size: 14px; color: var(--texto-suave); display: flex; align-items: center; gap: 8px; }
.estado::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--acento);
  animation: latido 1s ease-in-out infinite;
}
@keyframes latido { 50% { opacity: 0.25; } }
.acciones-mensaje { display: flex; gap: 12px; margin-top: 6px; font-size: 13px; }
.mensaje-error { color: var(--error); }

.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.3; margin: 1.2em 0 0.5em; }
.md h1 { font-size: 1.3em; }
.md h2 { font-size: 1.15em; }
.md h3 { font-size: 1.05em; }
.md pre {
  background: var(--superficie-2);
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 13px;
}
.md code { font-family: ui-monospace, Consolas, monospace; font-size: 0.92em; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--borde); padding: 6px 10px; text-align: left; vertical-align: top; }
.md blockquote { margin: 0; padding-left: 12px; border-left: 3px solid var(--borde); color: var(--texto-suave); }
.md a, a.ficha { color: var(--enlace); }
a.ficha { font-weight: 600; text-decoration: underline dotted; cursor: pointer; }

.compositor {
  border-top: 1px solid var(--borde);
  background: var(--superficie);
  padding: 12px 20px 16px;
}
.compositor > * { max-width: 820px; margin: 0 auto; }
.fila-compositor { display: flex; gap: 8px; align-items: flex-end; }
.adjuntar { align-self: center; }
.adjuntos:empty { display: none; }
.adjuntos { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
#texto {
  flex: 1;
  resize: none;
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: 10px 12px;
  background: var(--fondo);
  max-height: 40vh;
  min-height: 44px;
}

/* Visor de fichas */
.visor {
  width: min(900px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  border: 1px solid var(--borde);
  border-radius: 14px;
  padding: 0;
  background: var(--superficie);
  color: var(--texto);
}
.visor::backdrop { background: rgba(0, 0, 0, 0.45); }
.visor-cabecera {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  background: var(--superficie);
  border-bottom: 1px solid var(--borde);
}
.visor-cabecera h3 { margin: 0; font-size: 16px; }
.visor-cuerpo { padding: 16px 18px 24px; }
.visor-cuerpo dl { display: grid; grid-template-columns: 180px 1fr; gap: 6px 14px; margin: 0 0 16px; font-size: 14px; }
.visor-cuerpo dt { color: var(--texto-suave); }
.visor-cuerpo dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.visor-cuerpo h4 { margin: 18px 0 8px; }
.texto-voto {
  white-space: pre-wrap;
  font-size: 14px;
  background: var(--fondo);
  border: 1px solid var(--borde);
  border-radius: 8px;
  padding: 12px;
  overflow-wrap: anywhere;
}

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .lateral {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(300px, 85vw);
    z-index: 10;
    transform: translateX(-100%);
    transition: transform 0.2s;
    box-shadow: 0 0 24px rgba(0, 0, 0, 0.25);
  }
  .lateral.abierto { transform: none; }
  .solo-movil { display: inline-block; }
  .barra, .mensajes, .compositor { padding-left: 16px; padding-right: 16px; }
  .atajos { grid-template-columns: 1fr; }
  .visor-cuerpo dl { grid-template-columns: 1fr; }
  .visor-cuerpo dd { margin-bottom: 8px; }
}
