/* ===========================================================================
   WhatsApp Agents — sistema de diseño (tema claro, estilo Claude Console)
   =========================================================================== */
:root {
  /* Paleta cálida tipo papel */
  --bg:         #faf9f6;   /* fondo general (blanco cálido) */
  --surface:    #ffffff;   /* tarjetas */
  --surface-2:  #f5f3ee;   /* superficies secundarias / hover suave */
  --ink:        #1a1a19;   /* texto principal (casi negro) */
  --ink-soft:   #55524c;   /* texto secundario */
  --muted:      #8a867d;   /* texto terciario / placeholders */
  --border:     #e7e3da;   /* bordes suaves */
  --border-2:   #d9d4c8;   /* bordes con más contraste */
  --accent:     #c96442;   /* terracota Claude (acento mínimo) */
  --accent-soft:#f3e6df;   /* fondo del acento */
  --ok:         #3f9142;   /* estado conectado */
  --warn:       #c98a2b;   /* reconectando */
  --bad:        #c0392b;   /* desconectado */

  --radius:     12px;
  --radius-sm:  8px;
  --shadow:     0 1px 2px rgba(28,25,23,.04), 0 4px 16px rgba(28,25,23,.05);
  --shadow-lg:  0 8px 40px rgba(28,25,23,.10);

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-serif: "Fraunces", Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* Patrón de puntos sutil de fondo (como Claude Console) */
body::before {
  content: '';
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image: radial-gradient(circle, rgba(28,25,23,.045) 1px, transparent 1px);
  background-size: 22px 22px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,.5), transparent 60%);
}

/* ---------- Layout ---------- */
.app { position: relative; z-index: 1; display: grid; grid-template-columns: 244px 1fr; height: 100vh; }

/* Barra superior móvil (oculta en escritorio) */
.mobilebar { display: none; }
.mb-brand { display: flex; align-items: center; gap: 8px; font-family: var(--font-serif); font-size: 17px; font-weight: 600; padding-right: 6px; }
.mb-brand .logo { width: 26px; height: 26px; border-radius: 7px; background: var(--ink); color: #fff; display: grid; place-items: center; font-size: 14px; }
.mb-nav { display: flex; gap: 4px; overflow-x: auto; }
.mb-nav .nav-item { padding: 6px 12px; border-radius: 999px; white-space: nowrap; }
.mb-nav .nav-item.active { background: var(--ink); color: #fff; border-color: var(--ink); box-shadow: none; }

.sidebar {
  border-right: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 60%, #fff);
  padding: 20px 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 8px; background: var(--ink);
  color: #fff; display: grid; place-items: center; font-size: 16px;
}
.brand .name { font-family: var(--font-serif); font-size: 18px; font-weight: 600; letter-spacing: -.01em; }

.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: var(--radius-sm);
  color: var(--ink-soft); cursor: pointer; font-weight: 500;
  border: 1px solid transparent; transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--surface); color: var(--ink); border-color: var(--border); box-shadow: var(--shadow); }
.nav-item .ic { width: 18px; text-align: center; opacity: .8; }
.nav-sep { flex: 1; }
.sidebar .foot { padding: 10px; font-size: 12px; color: var(--muted); }
.userbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; padding: 8px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.userbar .uinfo { display: flex; flex-direction: column; min-width: 0; }
.userbar .uname { font-weight: 600; color: var(--ink); font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.userbar .urole { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.userbar .ulogout { font: inherit; font-size: 12px; font-weight: 550; padding: 5px 10px; border: 1px solid var(--border-2); background: var(--surface); border-radius: 7px; cursor: pointer; color: var(--ink-soft); }
.userbar .ulogout:hover { background: var(--surface-2); color: var(--bad); }
.status-line { display: flex; align-items: center; gap: 7px; }

/* ---------- Contenido ---------- */
.main { overflow-y: auto; position: relative; }
.view { max-width: 920px; margin: 0 auto; padding: 34px 40px 80px; }
.view-head { margin-bottom: 26px; }
.view-head h1 { font-family: var(--font-serif); font-size: 30px; font-weight: 600; letter-spacing: -.02em; margin: 0 0 6px; }
.view-head p { color: var(--ink-soft); margin: 0; max-width: 56ch; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  font: inherit; font-weight: 550; cursor: pointer;
  padding: 9px 15px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-2); background: var(--surface); color: var(--ink);
  transition: background .12s, border-color .12s, transform .04s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(.5px); }
.btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-primary:hover { background: #000; }
.btn-danger { color: var(--bad); border-color: #e6c9c4; background: #fff; }
.btn-danger:hover { background: #fbeeec; }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: default; }

/* ---------- Tarjetas / listas ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.list { display: flex; flex-direction: column; gap: 12px; }
.item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px; display: flex; align-items: center; gap: 16px;
  cursor: pointer; transition: border-color .12s, box-shadow .12s;
}
.item:hover { border-color: var(--border-2); box-shadow: var(--shadow-lg); }
.item .avatar {
  width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0;
  background: var(--surface-2); display: grid; place-items: center; font-size: 18px;
}
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 600; margin: 0 0 2px; }
.item .sub { color: var(--muted); font-size: 13px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { text-align: right; font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ---------- Badges / estados ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 550;
  background: var(--surface-2); color: var(--ink-soft); border: 1px solid var(--border);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: #ecd6cc; }

/* ---------- Formularios ---------- */
.field { margin-bottom: 18px; }
.field label { display: block; font-weight: 550; margin-bottom: 6px; font-size: 13px; }
.field .hint { color: var(--muted); font-size: 12px; margin-top: 5px; }
input[type=text], input[type=number], textarea, select {
  width: 100%; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border-2);
  border-radius: var(--radius-sm); padding: 10px 12px; transition: border-color .12s, box-shadow .12s;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; min-height: 120px; line-height: 1.6; font-family: var(--font-sans); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* Interruptor */
.switch { position: relative; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--border-2); border-radius: 24px; transition: .18s; cursor: pointer; }
.slider::before { content: ''; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .18s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .slider { background: var(--ink); }
.switch input:checked + .slider::before { transform: translateX(18px); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-top: 1px solid var(--border); }
.toggle-row:first-child { border-top: 0; }
.toggle-row .tl { font-weight: 550; }
.toggle-row .td { color: var(--muted); font-size: 12px; }

/* ---------- Empty / toast ---------- */
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty .big { font-size: 34px; margin-bottom: 10px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 12px; }
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 10px;
  box-shadow: var(--shadow-lg); opacity: 0; transition: .2s; z-index: 50; font-weight: 500;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(28,25,23,.32); display: none; z-index: 40; backdrop-filter: blur(2px); }
.overlay.show { display: grid; place-items: center; }
.modal { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); width: min(560px, 92vw); max-height: 88vh; overflow-y: auto; padding: 26px 28px; }
.modal h2 { font-family: var(--font-serif); font-size: 22px; margin: 0 0 18px; font-weight: 600; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

/* ---------- Chat de prueba ---------- */
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - 0px); }
.chat-head { padding: 16px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 14px; background: color-mix(in srgb, var(--bg) 60%, #fff); }
.chat-head .grow { flex: 1; }
.chat-scroll { flex: 1; overflow-y: auto; padding: 24px; }
.chat-inner { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 76%; padding: 10px 14px; border-radius: 16px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; }
.bubble.user { align-self: flex-end; background: var(--ink); color: #fff; border-bottom-right-radius: 5px; }
.bubble.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 5px; box-shadow: var(--shadow); }
.bubble.system { align-self: center; background: transparent; color: var(--muted); font-size: 12.5px; text-align: center; }
.typing { align-self: flex-start; color: var(--muted); font-size: 13px; padding: 4px 14px; }
.chat-foot { border-top: 1px solid var(--border); padding: 14px 24px; background: color-mix(in srgb, var(--bg) 60%, #fff); }
.chat-bar { max-width: 720px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; }
.chat-bar textarea { min-height: 0; height: 44px; max-height: 130px; }

/* Dropzone (base de conocimiento) */
.dropzone {
  border: 1.5px dashed var(--border-2); border-radius: var(--radius-sm);
  padding: 22px 16px; text-align: center; color: var(--ink-soft);
  cursor: pointer; transition: border-color .12s, background .12s; background: var(--surface-2);
}
.dropzone:hover { border-color: var(--accent); }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.loading { opacity: .7; cursor: default; }
.dropzone.disabled { cursor: default; color: var(--muted); background: var(--surface-2); border-style: solid; }
.dz-link { color: var(--accent); text-decoration: underline; }
.doclist { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.docitem { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--surface-2); border-radius: var(--radius-sm); border: 1px solid var(--border); }
.docitem .dn { font-weight: 500; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.docitem .dm { font-size: 12px; color: var(--muted); white-space: nowrap; }
.docitem .docdel { color: var(--muted); padding: 2px 8px; }
.docitem .docdel:hover { color: var(--bad); }

/* Tarjeta de integración API */
.apicard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin: 14px 0 4px; }
.apihead { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.apibody { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 12px; }
.apirow { display: flex; align-items: center; gap: 10px; padding: 6px 0; flex-wrap: wrap; }
.apirow .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; min-width: 130px; }
.apirow code { background: var(--surface-2); padding: 3px 8px; border-radius: 6px; font-size: 13px; border: 1px solid var(--border); }
.apipre { background: #1a1a19; color: #ede9e3; padding: 12px 14px; border-radius: var(--radius-sm); overflow-x: auto; font-size: 12.5px; line-height: 1.5; margin: 0; white-space: pre; }

/* Memoria / correcciones */
.addrow { display: flex; gap: 8px; }
.addrow input { flex: 1; }
.memlist { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.memitem { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--surface-2); border-radius: var(--radius-sm); border: 1px solid var(--border); }
.memitem .mn { flex: 1; line-height: 1.4; }
.memitem .memdel { color: var(--muted); padding: 2px 8px; }
.memitem .memdel:hover { color: var(--bad); }
a.btn { text-decoration: none; }

/* Toggle manual en la cabecera de conversación */
.toggle-manual { display: flex; align-items: center; gap: 8px; }

/* Tabla simple */
table.tbl { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); border: 1px solid var(--border); }
.tbl th, .tbl td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.tbl th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr { cursor: pointer; }
.tbl tbody tr:hover { background: var(--surface-2); }

/* stat cards */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 26px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat .v { font-family: var(--font-serif); font-size: 26px; font-weight: 600; margin-top: 4px; }

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { display: none; }
  .mobilebar {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg) 60%, #fff);
    position: sticky; top: 0; z-index: 5;
  }
  .view { padding: 22px 18px 60px; }
  .view-head h1 { font-size: 25px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .row2 { grid-template-columns: 1fr; }
  .chat-wrap { height: calc(100vh - 49px); }
}
