/* ============================================================
   FIXEL IA — Sistema de diseño (autocontenido, sin dependencias)
   Marca: violeta #8900ff sobre azul marino oscuro.
   ============================================================ */

:root {
  /* Tema CLARO (blanco y negro). Acento monocromo (casi negro). */
  --brand:        #111318;
  --brand-2:      #000000;
  --brand-glow:   #111318;
  --brand-soft:   rgba(17, 19, 24, 0.06);
  --brand-ring:   rgba(17, 19, 24, 0.28);
  --accent-cyan:  #0e7490;

  /* Superficies */
  --bg:        #ffffff;
  --bg-2:      #f6f7f9;
  --surface:   #ffffff;
  --surface-2: #fbfbfc;
  --surface-3: #f1f2f5;
  --border:    #e5e7eb;
  --border-2:  #d4d7dd;

  /* Texto */
  --text:      #14161c;
  --text-2:    #4b5160;
  --text-3:    #8b909c;

  /* Estados (se conservan para significado: alertas, badges) */
  --ok:      #15803d;
  --ok-bg:   rgba(21, 128, 61, 0.10);
  --warn:    #b45309;
  --warn-bg: rgba(180, 83, 9, 0.10);
  --danger:  #dc2626;
  --danger-bg: rgba(220, 38, 38, 0.09);
  --info:    #0369a1;
  --info-bg: rgba(3, 105, 161, 0.09);

  --radius:   16px;
  --radius-sm:10px;
  --shadow:   0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.10);
  --shadow-lg:0 12px 36px rgba(16, 24, 40, 0.16);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --sidebar-w: 250px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    radial-gradient(900px 500px at 15% -10%, rgba(17, 19, 24, 0.03), transparent 60%);
  background-attachment: fixed;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Layout con sidebar ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  border-right: 1px solid var(--border);
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 6px 8px 20px;
}
.brand-mark {
  width: 38px; height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--brand), var(--brand-glow));
  display: grid; place-items: center;
  font-weight: 800; color: #fff; font-size: 19px;
  box-shadow: 0 6px 18px var(--brand-ring);
}
.brand-name { font-size: 17px; font-weight: 800; }
.brand-name span { color: var(--brand-glow); }
.brand-sub { font-size: 11px; color: var(--text-3); letter-spacing: 0.04em; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 3px; margin-top: 4px; }
.nav-section { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); padding: 14px 10px 6px; }
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: 500; font-size: 14px;
  transition: background 0.15s, color 0.15s;
}
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.85; }
.nav-link:hover { background: var(--surface-3); color: var(--text); }
.nav-link.active {
  background: var(--brand);
  color: #fff;
  box-shadow: none;
}
.nav-link.active svg { opacity: 1; color: #fff; }

.sidebar-foot { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px 6px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--brand);
  display: grid; place-items: center; font-weight: 700; font-size: 14px; color: #fff;
}
.user-chip .meta { line-height: 1.2; min-width: 0; }
.user-chip .name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .role { font-size: 11px; color: var(--text-3); text-transform: capitalize; }
.logout { display: block; margin-top: 8px; text-align: center; font-size: 13px; color: var(--text-3); padding: 8px; border-radius: var(--radius-sm); }
.logout:hover { color: var(--danger); background: var(--danger-bg); }

/* ---------- Contenido ---------- */
.main { flex: 1; min-width: 0; }
.topbar {
  display: none;
  align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  position: sticky; top: 0; z-index: 30;
}
.content { max-width: 1180px; margin: 0 auto; padding: 34px 30px 60px; }

.page-head { margin-bottom: 26px; }
.page-head h1 { font-size: 26px; }
.page-head p { color: var(--text-2); margin-top: 6px; }
.page-head .row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

/* ---------- Tarjetas ---------- */
.card {
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card.hover { transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s; }
.card.hover:hover { transform: translateY(-3px); border-color: var(--brand-ring); box-shadow: var(--shadow-lg); }

.grid { display: grid; gap: 18px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

/* KPI */
.kpi .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); }
.kpi .value { font-size: 30px; font-weight: 800; margin-top: 6px; letter-spacing: -0.02em; }
.kpi .sub { font-size: 13px; color: var(--text-2); margin-top: 4px; }
.kpi .value.brand { color: var(--brand-glow); }
.kpi-ico {
  width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand-glow); font-size: 20px; float: right;
}

/* Delta badges */
.delta { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; font-size: 14px; padding: 3px 9px; border-radius: 999px; }
.delta.up { color: var(--ok); background: var(--ok-bg); }
.delta.down { color: var(--danger); background: var(--danger-bg); }
.delta.flat { color: var(--text-2); background: var(--surface-3); }

/* ---------- Tarjetas de herramienta ---------- */
.tool-card { display: block; position: relative; }
.tool-top { display: flex; align-items: flex-start; justify-content: space-between; }
.tool-ico { font-size: 26px; width: 48px; height: 48px; border-radius: 13px; background: var(--surface-3); display: grid; place-items: center; }
.tool-card h3 { margin-top: 14px; font-size: 16px; }
.tool-card p { color: var(--text-2); font-size: 13.5px; margin-top: 4px; }
.tool-open { color: var(--brand-glow); font-size: 13px; font-weight: 600; margin-top: 12px; display: inline-flex; gap: 5px; }

/* ---------- Badges / pills ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; padding: 4px 10px; border-radius: 999px; }
.badge.ok { color: var(--ok); background: var(--ok-bg); }
.badge.off { color: var(--danger); background: var(--danger-bg); }
.badge.warn { color: var(--warn); background: var(--warn-bg); }
.badge.info { color: var(--info); background: var(--info-bg); }
.badge.mute { color: var(--text-2); background: var(--surface-3); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.dot.off { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-bg); }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: var(--radius-sm);
  font-weight: 600; font-size: 14px; border: 1px solid transparent;
  transition: filter 0.15s, background 0.15s, border-color 0.15s;
}
.btn-primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; box-shadow: 0 6px 18px var(--brand-ring); }
.btn-primary:hover { filter: brightness(1.1); }
.btn-ghost { background: var(--surface-3); color: var(--text); border-color: var(--border-2); }
.btn-ghost:hover { border-color: var(--brand-ring); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: rgba(239,68,68,0.35); }
.btn-danger:hover { background: rgba(239,68,68,0.22); }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Formularios ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.field .hint { font-size: 12px; color: var(--text-3); margin-bottom: 8px; }
input, select, textarea {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%236f7b98' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 38px; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-3); padding: 13px 16px; background: var(--bg-2); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border); color: var(--text); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-2); }
td .mono, .mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; }

/* ---------- Flash ---------- */
.flash { margin-bottom: 18px; padding: 13px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border); font-size: 14px; display: flex; gap: 10px; align-items: center; }
.flash.success { background: var(--ok-bg); border-color: rgba(21,128,61,0.30); color: var(--ok); }
.flash.error { background: var(--danger-bg); border-color: rgba(220,38,38,0.30); color: var(--danger); }
.flash.info { background: var(--info-bg); border-color: rgba(3,105,161,0.30); color: var(--info); }

/* ---------- Secciones ---------- */
.section { margin-bottom: 34px; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.section-title h2 { font-size: 18px; }
.section-title .link { color: var(--brand-glow); font-size: 13.5px; font-weight: 600; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 400px; }
.login-card .brand { justify-content: center; padding-bottom: 8px; }
.login-card .card { padding: 28px; }
.login-tagline { text-align: center; color: var(--text-2); font-size: 13.5px; margin: 4px 0 24px; }

/* ---------- Chips de meta ---------- */
.meta-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip { font-size: 11.5px; color: var(--text-2); background: var(--surface-3); border: 1px solid var(--border); padding: 3px 9px; border-radius: 999px; }

/* ---------- Utilidades ---------- */
.muted { color: var(--text-3); }
.text-sm { font-size: 13px; }
.mb-0 { margin-bottom: 0; }
.flex { display: flex; }
.between { justify-content: space-between; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.wrap { flex-wrap: wrap; }
.right { text-align: right; }
.hidden { display: none !important; }
.chart-box { position: relative; height: 260px; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--border-2); border-top-color: var(--brand-glow); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-3 { grid-template-columns: 1fr; }
  .grid.cols-2 { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 50; transform: translateX(-100%); transition: transform 0.25s; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .topbar { display: flex; }
  .content { padding: 22px 16px 50px; }
  .backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 40; }
}
.menu-btn { background: var(--surface-3); border: 1px solid var(--border-2); border-radius: 10px; width: 40px; height: 40px; display: grid; place-items: center; color: var(--text); }
.version-chip { position: fixed; top: 14px; right: 20px; z-index: 45; font-size: 11px; color: var(--text-3); background: var(--surface); border: 1px solid var(--border); padding: 3px 10px; border-radius: 999px; }
@media (max-width: 900px) { .version-chip { display: none; } }

/* Backdrop del menú lateral en móvil */
.nav-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 45; }
@media (max-width: 900px) { .nav-backdrop.show { display: block; } }

/* ---------- Móvil pequeño ---------- */
@media (max-width: 560px) {
  html, body { font-size: 14.5px; }
  .content { padding: 18px 13px 46px; }
  .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 21px; }
  .kpi .value { font-size: 25px; }
  .kpi-ico { width: 34px; height: 34px; font-size: 17px; }
  .card { padding: 16px; }
  .section { margin-bottom: 24px; }
  .page-head .row { flex-direction: column; align-items: flex-start; }
  .chatw { right: 12px; left: 12px; width: auto; bottom: 84px; height: 68vh; }
  .fab { right: 16px; bottom: 16px; }
  .btn { padding: 9px 13px; }
  thead th, tbody td { padding: 10px 12px; }
  #presets { gap: 6px; }
  #presets input[type=date], #presets select { width: 100% !important; }
}
/* En móvil el chat a página completa y el detalle de agente se apilan */
@media (max-width: 900px) {
  .chat-full { height: auto; }
  .chat-full .chatw-body { height: 55vh; }
}

/* ---------- Chat flotante ---------- */
.fab {
  position: fixed; right: 22px; bottom: 22px; z-index: 60;
  width: 58px; height: 58px; border-radius: 50%; border: none;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff;
  display: grid; place-items: center; box-shadow: 0 10px 30px var(--brand-ring);
  transition: transform 0.15s;
}
.fab:hover { transform: scale(1.06); }
.chatw {
  position: fixed; right: 22px; bottom: 92px; z-index: 61;
  width: 380px; max-width: calc(100vw - 32px); height: 540px; max-height: calc(100vh - 130px);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border-2); border-radius: 18px;
  box-shadow: var(--shadow-lg); overflow: hidden;
}
.chatw-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--border); background: var(--bg-2); }
.chatw-x { background: none; border: none; color: var(--text-3); font-size: 15px; padding: 4px 6px; border-radius: 6px; }
.chatw-x:hover { color: var(--text); background: var(--surface-3); }
.chatw-body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.chatw-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); }
.chatw-form input { flex: 1; }
.msg { max-width: 85%; padding: 10px 13px; border-radius: 14px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word; }
.msg.me { align-self: flex-end; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--surface-3); color: var(--text); border-bottom-left-radius: 4px; }
.msg.pending { opacity: 0.75; font-style: italic; }
.mini-spin { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--border-2); border-top-color: var(--brand-glow); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -2px; margin-right: 6px; }
/* Markdown dentro de los mensajes del chat */
.msg strong { font-weight: 700; }
.msg em { font-style: italic; }
.msg code { background: rgba(0,0,0,0.07); padding: 1px 5px; border-radius: 5px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.9em; }
.msg .md-h { font-weight: 700; margin: 8px 0 4px; }
.msg ul { margin: 6px 0; padding-left: 20px; }
.msg li { margin: 3px 0; }
.msg a { color: var(--brand-glow); text-decoration: underline; }
.msg .md-t { border-collapse: collapse; margin: 8px 0; width: 100%; }
.msg .md-t td { border: 1px solid var(--border-2); padding: 5px 9px; font-size: 0.92em; }
.msg .md-t tr:first-child td { font-weight: 700; background: rgba(0,0,0,0.04); }

/* Chat página completa */
.chat-full { display: flex; flex-direction: column; height: calc(100vh - 160px); min-height: 420px; }
.chat-full .chatw-body { border: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; background: var(--surface); }
.chat-full .chatw-form { border: 1px solid var(--border); border-top: none; border-radius: 0 0 var(--radius) var(--radius); background: var(--surface); }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.suggestion { font-size: 13px; background: var(--surface-3); border: 1px solid var(--border-2); padding: 7px 12px; border-radius: 999px; cursor: pointer; color: var(--text-2); }
.suggestion:hover { border-color: var(--brand-ring); color: var(--text); }
