:root {
  --bg: #f4f5f7; --panel: #fff; --borde: #e3e5e9; --texto: #1d2129; --suave: #6b7280;
  --acento: #0f766e; --acento-2: #ccfbf1; --peligro: #b91c1c; --aviso: #b45309; --aviso-bg: #fef3c7;
  --cliente: #fff; --nuestro: #dcf8c6; --bot: #e0f2fe; --nota: #fef9c3; --sistema: #eef0f3;
  --radio: 10px; --sombra: 0 1px 2px rgba(0,0,0,.06);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; font-size: 14px; color: var(--texto);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); height: 100dvh; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--borde); background: var(--panel); border-radius: 8px; padding: 6px 12px; }
button:hover { background: #f9fafb; }
button.primario { background: var(--acento); color: #fff; border-color: var(--acento); }
button.primario:hover { filter: brightness(1.08); }
button.peligro { color: var(--peligro); }
button.chico { padding: 3px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { border: 1px solid var(--borde); border-radius: 8px; padding: 7px 10px; background: #fff; width: 100%; }
textarea { resize: vertical; }
label { display: block; font-size: 12px; color: var(--suave); margin: 10px 0 4px; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
.suave { color: var(--suave); }
.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; background: #eef0f3; font-size: 11px; white-space: nowrap; }
.chip.verde { background: var(--acento-2); color: var(--acento); }
.chip.ambar { background: var(--aviso-bg); color: var(--aviso); }
.chip.rojo { background: #fee2e2; color: var(--peligro); }
.fila { display: flex; gap: 8px; align-items: center; }
.fila.wrap { flex-wrap: wrap; }
.crece { flex: 1; min-width: 0; }

/* Login */
.login { max-width: 360px; margin: 12vh auto; background: var(--panel); padding: 28px; border-radius: 14px; box-shadow: var(--sombra); }
.login h1 { font-size: 20px; margin: 0 0 4px; }
.error { color: var(--peligro); font-size: 13px; margin-top: 8px; }

/* Layout */
.app { display: grid; grid-template-rows: 52px 1fr; height: 100dvh; }
.top { display: flex; align-items: center; gap: 12px; padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--borde); }
.top .marca { font-weight: 700; }
.top nav { display: flex; gap: 2px; overflow-x: auto; }
.top nav a { padding: 7px 11px; border-radius: 8px; color: var(--suave); text-decoration: none; white-space: nowrap; }
.top nav a.activo { background: var(--acento-2); color: var(--acento); font-weight: 600; }
.top select { width: auto; }
.contenido { overflow: hidden; }
.pagina { height: 100%; overflow: auto; padding: 18px; }

/* Chats */
.chats { display: grid; grid-template-columns: 200px 330px 1fr 300px; height: 100%; }
.bandejas { border-right: 1px solid var(--borde); background: var(--panel); overflow: auto; padding: 8px; }
.bandejas a { display: flex; justify-content: space-between; padding: 7px 10px; border-radius: 8px; color: var(--texto); text-decoration: none; }
.bandejas a.activo { background: var(--acento-2); color: var(--acento); font-weight: 600; }
.bandejas a .n { color: var(--suave); font-size: 12px; }
.lista { border-right: 1px solid var(--borde); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.lista .buscar { padding: 8px; border-bottom: 1px solid var(--borde); }
.lista .items { overflow: auto; flex: 1; }
.item { padding: 10px 12px; border-bottom: 1px solid #f0f1f3; cursor: pointer; }
.item:hover { background: #fafbfc; }
.item.activo { background: #eefbf8; }
.item .nombre { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item.no-leido .nombre::after { content: '●'; color: var(--acento); margin-left: 6px; font-size: 10px; }
.item .snip { color: var(--suave); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.item .meta { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.item .hora { font-size: 11px; color: var(--suave); white-space: nowrap; }
.item input[type=checkbox] { width: auto; margin-right: 6px; }

.chat { display: flex; flex-direction: column; min-height: 0; background: #efeae2; }
.chat .cab { background: var(--panel); padding: 8px 14px; border-bottom: 1px solid var(--borde); display: flex; align-items: center; gap: 10px; }
.chat .msgs { flex: 1; overflow: auto; padding: 14px 6%; display: flex; flex-direction: column; gap: 4px; }
.burbuja { max-width: 72%; padding: 7px 10px 5px; border-radius: 9px; box-shadow: var(--sombra); white-space: pre-wrap; word-wrap: break-word; line-height: 1.35; }
.burbuja .pie { font-size: 10.5px; color: var(--suave); text-align: right; margin-top: 2px; }
.burbuja .quien { font-size: 11px; font-weight: 600; color: var(--acento); margin-bottom: 2px; }
.burbuja.cliente { background: var(--cliente); align-self: flex-start; }
.burbuja.agente { background: var(--nuestro); align-self: flex-end; }
.burbuja.bot { background: var(--bot); align-self: flex-end; }
.burbuja.nota { background: var(--nota); align-self: center; max-width: 80%; font-size: 13px; }
.burbuja.fallido { outline: 1px solid var(--peligro); }
.sistema { align-self: center; background: var(--sistema); color: #4b5563; font-size: 12px; padding: 4px 10px; border-radius: 8px; max-width: 85%; text-align: center; }
.dia { align-self: center; font-size: 11px; color: var(--suave); background: #fff8; padding: 2px 10px; border-radius: 8px; margin: 6px 0; }
.composer { background: var(--panel); border-top: 1px solid var(--borde); padding: 8px 10px; }
.composer .aviso { background: var(--aviso-bg); color: var(--aviso); padding: 6px 10px; border-radius: 8px; font-size: 12.5px; margin-bottom: 6px; }
.composer textarea { min-height: 42px; max-height: 160px; }
.vacio { margin: auto; color: var(--suave); text-align: center; padding: 30px; }

.ficha { border-left: 1px solid var(--borde); background: var(--panel); overflow: auto; padding: 14px; }
.ficha .score { font-size: 28px; font-weight: 700; color: var(--acento); }
.ficha pre { white-space: pre-wrap; font-family: inherit; margin: 0; font-size: 13px; background: #f9fafb; padding: 8px; border-radius: 8px; }
.ficha .bloque { margin-bottom: 14px; }

/* Tablas y tarjetas */
.tarjeta { background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio); padding: 14px; margin-bottom: 12px; }
table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { text-align: left; padding: 7px 9px; border-bottom: 1px solid #eef0f3; vertical-align: top; }
th { font-size: 12px; color: var(--suave); font-weight: 600; position: sticky; top: 0; background: #fafbfc; }
.stock-grid td { padding: 3px; }
.stock-grid input { width: 56px; padding: 3px 5px; text-align: center; }
.stock-grid input.disp { background: var(--acento-2); }
.stock-grid input.agot { background: #fee2e2; }

/* Modal */
.velo { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; padding: 20px; width: 100%; max-width: 560px; max-height: 90dvh; overflow: auto; }
.modal .acciones { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.previa { background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 8px; padding: 10px; white-space: pre-wrap; font-size: 13px; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 9px 16px; border-radius: 10px; z-index: 60; font-size: 13px; }

/* Móvil */
.solo-movil { display: none; }
@media (max-width: 1100px) { .chats { grid-template-columns: 170px 290px 1fr; } .ficha { display: none; } .chats.con-ficha .ficha { display: block; position: fixed; right: 0; top: 52px; bottom: 0; width: 320px; z-index: 20; box-shadow: -4px 0 16px rgba(0,0,0,.1); } }
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .top { gap: 6px; padding: 0 8px; overflow: hidden; }
  .top nav { flex: 1; min-width: 0; }
  .top > .chip, .top > .crece, .top > strong { display: none; }
  .top select { max-width: 120px; }
  .chats { grid-template-columns: minmax(0, 1fr); }
  .bandejas { display: none; }
  .chats.abierto .lista { display: none; }
  .chats:not(.abierto) .chat { display: none; }
  .solo-movil { display: inline-block; }
  .chat .msgs { padding: 10px; }
  .burbuja { max-width: 88%; }
  .top .marca { display: none; }
  .chats.con-ficha .ficha { width: 100%; }
}
