:root{
  /* América de Cali */
  --am-red:#D21217;
  --am-wine:#930A11;
  --am-white:#FFFFFF;
  --am-coal:#222222;

  /* UI neutrals */
  --bg:#0b0c0f;
  --panel:#11131a;
  --card:#151826;
  --card-2:#10131c;
  --border:rgba(255,255,255,.08);
  --border-2:rgba(255,255,255,.12);
  --text:#F5F7FF;
  --muted:rgba(245,247,255,.72);
  --muted-2:rgba(245,247,255,.55);
  --shadow: 0 18px 48px rgba(0,0,0,.45);
  --radius:14px;
  --radius-sm:12px;
  --ring: 0 0 0 3px rgba(210,18,23,.25);
}

*{box-sizing:border-box}
html,body{height:100%;margin:0}
body{
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background:
    radial-gradient(1200px 700px at 12% 8%, rgba(210,18,23,.28) 0%, rgba(210,18,23,0) 55%),
    radial-gradient(900px 600px at 92% 10%, rgba(147,10,17,.22) 0%, rgba(147,10,17,0) 52%),
    radial-gradient(700px 500px at 55% 85%, rgba(34,34,34,.35) 0%, rgba(34,34,34,0) 60%),
    linear-gradient(180deg, #07080a 0%, #0b0c0f 100%);
  color: var(--text);
}

a{color:inherit}

/* Toast */
.toast-root{
  position:fixed;
  right:16px;
  bottom:16px;
  display:flex;
  flex-direction:column;
  gap:10px;
  z-index:1000;
}
.toast{
  min-width: 260px;
  max-width: 380px;
  border: 1px solid var(--border);
  background: rgba(21,24,38,.88);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  border-radius: 14px;
  padding: 12px 12px;
  display:flex;
  gap:10px;
  align-items:flex-start;
}
.toast .toast-icon{
  width: 28px; height: 28px;
  border-radius: 10px;
  display:flex; align-items:center; justify-content:center;
  background: rgba(210,18,23,.16);
  border:1px solid rgba(210,18,23,.35);
  color: var(--am-white);
  flex: 0 0 auto;
}
.toast .toast-title{font-weight:800; letter-spacing:.2px; font-size:13px}
.toast .toast-msg{font-size:13px; color:var(--muted); margin-top:2px; line-height:1.35}
.toast.toast-ok .toast-icon{background:rgba(34,177,76,.18); border-color:rgba(34,177,76,.35)}
.toast.toast-warn .toast-icon{background:rgba(255,196,0,.18); border-color:rgba(255,196,0,.35)}
.toast.toast-err .toast-icon{background:rgba(210,18,23,.18); border-color:rgba(210,18,23,.4)}

/* App layout */
.app{
  height:100vh;
  display:grid;
  grid-template-columns: 340px 1fr;
  gap: 14px;
  padding: 14px;
}

.app.sidebar-collapsed{
  grid-template-columns: 88px 1fr;
}

.sidebar{
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(17,19,26,.92) 0%, rgba(15,17,25,.86) 100%);
  backdrop-filter: blur(10px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display:flex;
  flex-direction:column;
  overflow:hidden;
  transition: width .18s ease;
}

.brand{
  display:flex;
  gap:12px;
  align-items:center;
  padding: 16px 16px 14px;
  border-bottom: 1px solid var(--border);
}
.crest{
  width: 42px; height:42px;
  border-radius: 14px;
  background: linear-gradient(180deg, var(--am-red) 0%, var(--am-wine) 100%);
  box-shadow: 0 10px 28px rgba(210,18,23,.25);
  display:flex; align-items:center; justify-content:center;
  position:relative;
}
.crest:after{
  content:"";
  position:absolute;
  inset:2px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.18);
}
.crest-inner{
  font-weight: 900;
  letter-spacing: .2px;
}
.brand-text{display:flex;flex-direction:column;gap:2px}
.brand-title{font-size:14px;font-weight:900;letter-spacing:.4px}
.brand-subtitle{font-size:12px;color:var(--muted-2)}

.sidebar-actions{
  padding: 14px 16px 10px;
  display:flex;
  flex-direction:column;
  gap:10px;
}
.sidebar-section{padding: 6px 10px 10px; display:flex; flex-direction:column; gap:8px; overflow:hidden}
.sidebar-section-title{
  padding: 0 6px;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: .12em;
}

.threads{
  list-style:none;
  margin:0;
  padding:0 4px 6px;
  overflow:auto;
  display:flex;
  flex-direction:column;
  gap:8px;
}
.thread-item{
  border: 1px solid var(--border);
  background: rgba(16,19,28,.78);
  border-radius: 14px;
  padding: 10px 10px;
  cursor:pointer;
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
  display:flex;
  gap:10px;
}
.thread-item:hover{transform: translateY(-1px); border-color: rgba(255,255,255,.16); background: rgba(21,24,38,.86)}
.thread-item.active{
  border-color: rgba(210,18,23,.55);
  box-shadow: 0 0 0 3px rgba(210,18,23,.12);
}
.thread-avatar{
  width: 32px; height:32px;
  border-radius: 12px;
  background: rgba(210,18,23,.14);
  border:1px solid rgba(210,18,23,.28);
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight:900;
  flex: 0 0 auto;
}
.thread-main{min-width:0; display:flex; flex-direction:column; gap:2px}
.thread-title-row{display:flex; justify-content:space-between; gap:10px; align-items:center}
.thread-title-text{
  font-weight:800;
  font-size: 13px;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.thread-time{font-size:12px; color:var(--muted-2); flex: 0 0 auto}
.thread-meta{font-size:12px; color:var(--muted)}

.sidebar-footer{
  margin-top:auto;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}

.app.sidebar-collapsed .sidebar{
  width: 88px;
}
.app.sidebar-collapsed .brand-text,
.app.sidebar-collapsed .sidebar-actions,
.app.sidebar-collapsed .sidebar-section-title,
.app.sidebar-collapsed .thread-main,
.app.sidebar-collapsed .sidebar-footer{
  display:none;
}
.app.sidebar-collapsed .brand{
  justify-content:center;
}
.app.sidebar-collapsed .threads{
  padding: 6px 6px 10px;
  align-items:center;
}
.app.sidebar-collapsed .thread-item{
  justify-content:center;
  padding: 10px;
}
.pill{
  display:flex;
  align-items:center;
  gap:10px;
  border: 1px solid var(--border);
  background: rgba(16,19,28,.72);
  border-radius: 999px;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--muted);
}
.dot{
  width:10px;height:10px;border-radius:99px;background: rgba(210,18,23,.9);
  box-shadow: 0 0 0 3px rgba(210,18,23,.18);
}

.main{
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow:hidden;
  background: linear-gradient(180deg, rgba(17,19,26,.82) 0%, rgba(15,17,25,.76) 100%);
  backdrop-filter: blur(10px);
  display:flex;
  flex-direction:column;
}

.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(21,24,38,.84) 0%, rgba(16,19,28,.76) 100%);
}
.topbar-left{display:flex; align-items:center; gap:12px; min-width:0}
.topbar-right{display:flex; gap:10px; align-items:center; color:var(--muted-2)}
.link{
  color: var(--muted);
  text-decoration:none;
  font-weight:800;
  font-size: 12px;
  letter-spacing:.06em;
  text-transform:uppercase;
}
.link:hover{color:var(--am-white)}

.stat-cards{
  display:flex;
  gap:8px;
  align-items:center;
}
.stat-card{
  border: 1px solid var(--border);
  background: rgba(12,14,20,.55);
  border-radius: 12px;
  padding: 8px 10px;
  min-width: 110px;
}
.stat-label{
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted-2);
  font-weight: 800;
}
.stat-value{
  font-size: 13px;
  font-weight: 800;
  color: var(--am-white);
  margin-top: 4px;
}

.thread-head{display:flex; flex-direction:column; gap:4px; min-width:0}
.thread-title{
  width: min(640px, 62vw);
  min-width: 220px;
  background: rgba(12,14,20,.65);
  color: var(--am-white);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 900;
  letter-spacing: .2px;
  outline:none;
}
.thread-title:focus{box-shadow: var(--ring); border-color: rgba(210,18,23,.55)}
.thread-meta{
  font-size:12px;
  color: var(--muted-2);
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.messages{
  flex:1;
  overflow:auto;
  padding: 16px;
  display:flex;
  flex-direction:column;
  gap:12px;
  background:
    radial-gradient(900px 600px at 15% 0%, rgba(210,18,23,.10) 0%, rgba(210,18,23,0) 55%),
    radial-gradient(800px 500px at 90% 25%, rgba(147,10,17,.08) 0%, rgba(147,10,17,0) 55%),
    linear-gradient(180deg, rgba(10,11,15,.20) 0%, rgba(10,11,15,0) 22%, rgba(10,11,15,.24) 100%);
}
.empty{
  margin: auto;
  max-width: 560px;
  border: 1px dashed rgba(255,255,255,.16);
  border-radius: 16px;
  padding: 18px 16px;
  background: rgba(16,19,28,.55);
  color: var(--muted);
}
.empty h3{margin:0 0 6px; color: var(--am-white); font-size:16px}
.empty p{margin:0; line-height:1.45}

.message{
  max-width: 920px;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 14px;
  line-height: 1.55;
  background: rgba(16,19,28,.72);
}
.message .role{font-size:12px; color:var(--muted-2); margin-bottom:6px; letter-spacing:.05em; text-transform:uppercase; font-weight:900}
.message .content{font-size:15px; color: var(--am-white)}

.message.user{
  align-self:flex-end;
  background: linear-gradient(180deg, rgba(210,18,23,.22) 0%, rgba(147,10,17,.18) 100%);
  border-color: rgba(210,18,23,.35);
}
.message.assistant{
  align-self:flex-start;
  background: rgba(21,24,38,.78);
  border-color: rgba(255,255,255,.10);
}
.message.kapi-typing .content{
  color: var(--muted);
  display:flex;
  align-items:center;
  gap:10px;
}
.dots{display:inline-flex; gap:6px}
.dots span{
  width: 7px; height: 7px; border-radius: 99px;
  background: rgba(245,247,255,.55);
  animation: bounce 1.05s infinite ease-in-out;
}
.dots span:nth-child(2){animation-delay:.14s}
.dots span:nth-child(3){animation-delay:.28s}
@keyframes bounce{
  0%,80%,100%{ transform: translateY(0); opacity:.55 }
  40%{ transform: translateY(-4px); opacity:1 }
}

.message .content p{margin:.55em 0}
.message .content h1,.message .content h2,.message .content h3{margin:.6em 0 .35em}
.message .content h1{font-size:20px}
.message .content h2{font-size:18px}
.message .content h3{font-size:16px}
.message .content ul,.message .content ol{margin:.45em 0 .65em 1.1em}
.message .content code{
  background: rgba(0,0,0,.35);
  border: 1px solid rgba(255,255,255,.10);
  padding: 2px 6px;
  border-radius: 8px;
}
.message .content pre{
  background: rgba(0,0,0,.35);
  border: 1px solid rgba(255,255,255,.10);
  padding: 10px 12px;
  border-radius: 14px;
  overflow:auto;
}

.composer{
  padding: 12px 14px 12px;
  border-top: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(21,24,38,.82) 0%, rgba(16,19,28,.78) 100%);
}
.composer-inner{
  display:flex;
  gap:10px;
  align-items:flex-end;
}
.composer textarea{
  flex:1;
  resize:none;
  min-height: 44px;
  max-height: 180px;
  padding: 12px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(12,14,20,.55);
  color: var(--am-white);
  outline:none;
}
.composer textarea:focus{box-shadow: var(--ring); border-color: rgba(210,18,23,.55)}
.composer-hint{
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted-2);
}

/* Buttons / inputs */
.btn{
  border:none;
  border-radius: 14px;
  padding: 11px 14px;
  cursor:pointer;
  font-weight: 900;
  letter-spacing:.2px;
  color: var(--am-white);
  transition: transform .08s ease, filter .12s ease, box-shadow .12s ease;
}
.btn:active{transform: translateY(1px)}
.btn-primary{
  background: linear-gradient(180deg, var(--am-red) 0%, var(--am-wine) 100%);
  box-shadow: 0 10px 28px rgba(210,18,23,.18);
}
.btn-primary:hover{filter: brightness(1.05)}
.btn-primary:disabled{opacity:.55; cursor:not-allowed; filter:none}
.btn-block{width:100%}

.input{
  width:100%;
  padding: 11px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(12,14,20,.55);
  color: var(--am-white);
  outline:none;
}
.input:focus{box-shadow: var(--ring); border-color: rgba(210,18,23,.55)}
.input::placeholder{color: rgba(245,247,255,.45)}

.icon-btn{
  width: 42px;
  height: 42px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(12,14,20,.55);
  color: var(--am-white);
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
}
.icon-btn:hover{border-color: var(--border-2)}
.icon-btn:focus{outline:none; box-shadow: var(--ring)}
.icon-bars{
  width: 16px; height: 12px;
  position:relative;
}
.icon-bars:before,.icon-bars:after,.icon-bars span{
  content:"";
  position:absolute;
  left:0; right:0;
  height: 2px;
  background: rgba(245,247,255,.92);
  border-radius: 99px;
}
.icon-bars:before{top:0}
.icon-bars:after{bottom:0}
.icon-bars span{top:5px}

/* Mobile sidebar overlay */
.sidebar-overlay{
  position:fixed;
  inset:0;
  background: rgba(0,0,0,.55);
  z-index: 900;
}

/* Scrollbars */
*::-webkit-scrollbar{width:10px;height:10px}
*::-webkit-scrollbar-thumb{background:rgba(255,255,255,.14);border-radius:999px}
*::-webkit-scrollbar-thumb:hover{background:rgba(255,255,255,.20)}

@media (max-width: 980px){
  .app{grid-template-columns: 1fr; padding: 10px}
  .sidebar{
    position: fixed;
    top: 10px;
    bottom: 10px;
    left: 10px;
    width: min(380px, calc(100vw - 20px));
    transform: translateX(-110%);
    transition: transform .18s ease;
    z-index: 950;
  }
  .sidebar.open{transform: translateX(0)}
  .app.sidebar-collapsed{grid-template-columns: 1fr}
  .thread-title{width: min(520px, 58vw)}
  .stat-cards{display:none}
}