:root{
  --bg-page:#eef3fb;
  --panel:#ffffff;
  --border:#e8e8ee;
  --text:#111114;
  --text-dim:#8a8a92;
  --text-faint:#b6b6bf;
  --bubble-user:#1c1c1e;
  --bubble-agent:#f2f2f5;
  --search-bg:#eeeef2;
  --accent:#2563eb;
  --radius-panel:18px;
  --font:-apple-system,BlinkMacSystemFont,'Segoe UI','Inter',Roboto,sans-serif;
  box-sizing:border-box;
  padding-top:env(safe-area-inset-top,0px);
  padding-bottom:env(safe-area-inset-bottom,0px);
}
*{box-sizing:inherit;margin:0;padding:0;}
html,body{height:100%;}
html{scroll-padding-top:env(safe-area-inset-top,0px);}
body{
  font-family:var(--font);
  background:linear-gradient(160deg,#dbe7fb 0%,#eef3fb 45%,#e6eefc 100%);
  color:var(--text);
  -webkit-font-smoothing:antialiased;
  overflow:hidden;
}
.hidden{display:none !important;}

/* ---------- gate ---------- */
.gate{
  height:100%;
  display:flex;align-items:center;justify-content:center;
  padding:20px;
}
.gate-card{
  background:var(--panel);
  border:1px solid var(--border);
  border-radius:22px;
  padding:36px 32px;
  width:100%;max-width:360px;
  text-align:center;
  box-shadow:0 20px 60px rgba(30,50,90,.12);
}
.gate-logo{font-size:30px;margin-bottom:12px;}
.gate-card h1{font-size:19px;font-weight:700;margin-bottom:6px;}
.gate-card p{font-size:13.5px;color:var(--text-dim);margin-bottom:20px;line-height:1.5;}
.gate-card input{
  width:100%;
  font-family:var(--font);font-size:15px;
  padding:12px 14px;
  border:1px solid var(--border);border-radius:12px;
  outline:none;margin-bottom:12px;
  background:var(--search-bg);
}
.gate-card input:focus{border-color:var(--accent);background:#fff;}
.gate-card button{
  width:100%;
  font-family:var(--font);font-size:15px;font-weight:600;
  padding:12px;border:none;border-radius:12px;
  background:var(--text);color:#fff;cursor:pointer;
}
.gate-error{margin-top:12px;font-size:13px;color:#dc2626;}

/* ---------- layout ---------- */
.app{
  height:100%;
  display:flex;
  padding:22px;
  gap:0;
}
.sidebar{
  flex:0 0 320px;
  background:var(--panel);
  border:1px solid var(--border);
  border-right:none;
  border-radius:var(--radius-panel) 0 0 var(--radius-panel);
  display:flex;flex-direction:column;
  overflow:hidden;
}
.chat{
  flex:1;
  background:var(--panel);
  border:1px solid var(--border);
  border-radius:0 var(--radius-panel) var(--radius-panel) 0;
  display:flex;flex-direction:column;
  overflow:hidden;
  position:relative;
}

/* ---------- sidebar ---------- */
.sidebar-top{padding:20px 16px 12px;}
.sidebar-title{font-size:17px;font-weight:800;letter-spacing:-.01em;padding:0 4px 12px;}
.search{
  display:flex;align-items:center;gap:8px;
  background:var(--search-bg);
  border-radius:12px;
  padding:9px 12px;
  color:var(--text-dim);
}
.search svg{width:15px;height:15px;flex:0 0 auto;}
.search input{
  flex:1;border:none;outline:none;background:none;
  font-family:var(--font);font-size:14px;color:var(--text);
}
.search input::placeholder{color:var(--text-faint);}

.agent-list{flex:1;overflow-y:auto;padding:4px 8px;}
.agent-list::-webkit-scrollbar{width:8px;}
.agent-list::-webkit-scrollbar-thumb{background:var(--border);border-radius:8px;}

.agent-row{
  display:flex;align-items:center;gap:12px;
  padding:11px 10px;
  border-radius:14px;
  cursor:pointer;
  transition:background .12s ease;
  border:none;background:none;width:100%;
  font-family:var(--font);text-align:left;
}
.agent-row:hover{background:#f5f5f8;}
.agent-row.active{background:#ececf2;}
.agent-row:focus-visible{outline:2px solid var(--accent);outline-offset:-2px;}

.avatar{
  width:44px;height:44px;flex:0 0 auto;
  border-radius:46% 54% 52% 48% / 52% 46% 54% 48%;
  position:relative;
  overflow:hidden;
}
.avatar::after{
  content:'';
  position:absolute;top:14%;left:16%;
  width:34%;height:26%;
  background:rgba(255,255,255,.55);
  border-radius:50%;
  filter:blur(1px);
  transform:rotate(-18deg);
}
.avatar.sm{width:34px;height:34px;}

.agent-row-main{flex:1;min-width:0;}
.agent-row-top{display:flex;align-items:baseline;justify-content:space-between;gap:8px;}
.agent-name{font-size:14.5px;font-weight:600;color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.agent-time{font-size:11.5px;color:var(--text-faint);flex:0 0 auto;}
.agent-preview{
  font-size:12.5px;color:var(--text-dim);
  margin-top:2px;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
}

.sidebar-foot{
  padding:14px 20px;
  border-top:1px solid var(--border);
  font-size:12px;color:var(--text-dim);
  display:flex;align-items:center;gap:7px;
}
.foot-dot{width:7px;height:7px;border-radius:50%;background:#22c55e;}

/* ---------- chat vacío ---------- */
.chat-empty{
  flex:1;display:flex;flex-direction:column;
  align-items:center;justify-content:center;
  text-align:center;padding:30px;
}
.empty-mark{font-size:34px;margin-bottom:14px;opacity:.5;}
.empty-title{font-size:17px;font-weight:700;}
.empty-sub{font-size:13.5px;color:var(--text-dim);margin-top:8px;max-width:320px;line-height:1.5;}

/* ---------- chat activo ---------- */
.chat-active{flex:1;display:flex;flex-direction:column;min-height:0;}

.chat-header{
  display:flex;align-items:center;gap:12px;
  padding:14px 18px;
  border-bottom:1px solid var(--border);
}
.back-btn{
  display:none;
  border:none;background:none;cursor:pointer;
  color:var(--text);padding:4px;
}
.back-btn svg{width:20px;height:20px;}
.chat-header-agent{display:flex;align-items:center;gap:10px;flex:1;min-width:0;}
.chat-header-name{font-size:15px;font-weight:700;}
.chat-header-tag{font-size:12px;color:var(--text-dim);}
.clear-btn{
  border:none;background:none;cursor:pointer;
  color:var(--text-faint);padding:6px;border-radius:8px;
}
.clear-btn:hover{color:#dc2626;background:#fbf1f1;}
.clear-btn svg{width:18px;height:18px;}

.messages{
  flex:1;min-height:0;
  overflow-y:auto;
  padding:22px 22px 10px;
  display:flex;flex-direction:column;gap:10px;
}
.messages::-webkit-scrollbar{width:8px;}
.messages::-webkit-scrollbar-thumb{background:var(--border);border-radius:8px;}

.day-label{
  align-self:center;
  font-size:11.5px;color:var(--text-faint);
  margin:6px 0;
}
.bubble{
  max-width:72%;
  padding:11px 15px;
  border-radius:20px;
  font-size:14.5px;line-height:1.55;
  animation:pop-in .18s ease both;
  overflow-wrap:break-word;
}
@keyframes pop-in{from{opacity:0;transform:translateY(5px);}to{opacity:1;transform:translateY(0);}}
.bubble.user{
  align-self:flex-end;
  background:var(--bubble-user);color:#fff;
  border-bottom-right-radius:6px;
}
.bubble.agent{
  align-self:flex-start;
  background:var(--bubble-agent);color:var(--text);
  border-bottom-left-radius:6px;
}
.bubble p+p{margin-top:.6em;}
.bubble code{
  font-family:ui-monospace,SFMono-Regular,Menlo,monospace;
  font-size:.88em;
  background:rgba(0,0,0,.07);
  padding:1px 5px;border-radius:5px;
}
.bubble.user code{background:rgba(255,255,255,.18);}
.bubble pre{
  background:rgba(0,0,0,.06);
  border-radius:10px;padding:10px 12px;
  overflow-x:auto;margin:.5em 0;
}
.bubble.user pre{background:rgba(255,255,255,.14);}
.bubble pre code{background:none;padding:0;}
.bubble ul{margin:.35em 0 .35em 1.15em;}
.bubble li{margin:.2em 0;}
.bubble strong{font-weight:700;}

.handoff{
  align-self:center;
  display:flex;align-items:center;gap:7px;
  font-size:11.5px;color:var(--text-dim);
  background:var(--search-bg);
  padding:6px 13px;
  border-radius:999px;
  margin:2px 0;
  animation:pop-in .18s ease both;
  cursor:default;
}
.handoff-dot{width:6px;height:6px;border-radius:50%;background:var(--accent);flex:0 0 auto;}
.handoff strong{font-weight:600;color:var(--text);}
.handoff-in .handoff-dot{background:#22c55e;}
.handoff-routine{background:#fff7ed;}
.handoff-routine .handoff-dot{background:#f59e0b;}

.auto-badge{font-size:11px;filter:grayscale(0);}

.typing{
  align-self:flex-start;
  background:var(--bubble-agent);
  border-radius:20px;border-bottom-left-radius:6px;
  padding:14px 18px;
  display:flex;gap:5px;
}
.typing span{
  width:7px;height:7px;border-radius:50%;
  background:var(--text-faint);
  animation:typing-b 1.2s ease-in-out infinite;
}
.typing span:nth-child(2){animation-delay:.15s;}
.typing span:nth-child(3){animation-delay:.3s;}
@keyframes typing-b{0%,60%,100%{transform:translateY(0);opacity:.5;}30%{transform:translateY(-4px);opacity:1;}}

/* ---------- composer ---------- */
.composer-wrap{padding:12px 18px 18px;}
.composer{
  display:flex;align-items:flex-end;gap:10px;
  background:#fff;
  border:1px solid #dcdce3;
  border-radius:24px;
  padding:6px 6px 6px 18px;
  transition:border-color .15s ease, box-shadow .15s ease;
}
.composer:focus-within{
  border-color:var(--accent);
  box-shadow:0 0 0 3px rgba(37,99,235,.08);
}
.composer textarea{
  flex:1;border:none;outline:none;resize:none;background:none;
  font-family:var(--font);font-size:14.5px;line-height:1.5;
  color:var(--text);
  max-height:150px;
  padding:9px 0;
}
.composer textarea::placeholder{color:var(--text-faint);}
.send-btn{
  flex:0 0 auto;
  width:36px;height:36px;border-radius:50%;
  border:none;cursor:pointer;
  background:var(--text-faint);color:#fff;
  display:flex;align-items:center;justify-content:center;
  transition:background .15s ease, transform .1s ease;
}
.send-btn svg{width:16px;height:16px;}
.send-btn.ready{background:var(--accent);}
.send-btn.ready:hover{transform:scale(1.06);}

@media (prefers-reduced-motion:reduce){
  *{animation-duration:.001ms !important;}
}

/* ---------- móvil ---------- */
@media (max-width:760px){
  .app{padding:0;}
  .sidebar,.chat{border-radius:0;border:none;}
  .sidebar{flex:1 1 100%;}
  .chat{display:none;}
  .app.mobile-chat .sidebar{display:none;}
  .app.mobile-chat .chat{display:flex;flex:1 1 100%;}
  .back-btn{display:block;}
  .bubble{max-width:84%;}
}
