/* =========================================================
   CIEM AI Factory · Demo MVP
   Paleta corporativa – Plataforma web CIEM Badajoz
   ========================================================= */

:root {
  /* 1. Corporativos y de interfaz */
  --azul-principal: #2D6599;   /* menú lateral, botones principales, encabezados */
  --azul-secundario: #348BC0;  /* enlaces, iconos, elementos interactivos */
  --azul-tecnologico: #50A9D7; /* gráficos, indicadores, IA */
  --azul-suave: #EAF5FB;       /* fondos de tarjetas, seleccionados */
  --negro: #171C24;            /* títulos y textos importantes */
  --gris-texto: #64748B;       /* descripciones, etiquetas */
  --gris-fondo: #F5F7FA;       /* fondo general */
  --blanco: #FFFFFF;           /* tarjetas, formularios */

  /* 2. Estados */
  --exito: #16A34A;
  --advertencia: #F59E0B;
  --error: #DC2626;
  --info: #348BC0;

  /* Derivados */
  --azul-principal-hover: #24547F;
  --borde: #E2E8F0;
  --borde-suave: #EEF2F6;
  --exito-suave: #E8F6EE;
  --advertencia-suave: #FEF5E2;
  --error-suave: #FDECEC;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(23, 28, 36, .06);
  --shadow: 0 4px 16px rgba(23, 28, 36, .07);
  --shadow-lg: 0 20px 50px rgba(23, 28, 36, .18);

  --sidebar-w: 260px;
  --topbar-h: 64px;

  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--negro);
  background: var(--gris-fondo);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; color: var(--negro); line-height: 1.25; }
p { margin: 0; }
a { color: var(--azul-secundario); }
button { font-family: inherit; font-size: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

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

.sidebar {
  width: var(--sidebar-w);
  background: var(--azul-principal);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  transition: transform .25s ease;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 20px 20px 18px; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand { flex-direction: column; align-items: stretch; gap: 10px; }
.brand-logo { background: #fff; border-radius: 10px; padding: 10px 14px; display: flex; align-items: center; justify-content: center; }
.brand-logo img { display: block; max-width: 100%; max-height: 52px; object-fit: contain; }
.brand .brand-text { padding: 0 2px; }
.brand-mark svg { width: 38px; height: 38px; stroke: none; }
.brand-text { display: flex; flex-direction: column; }
.brand-text strong { font-size: 15px; letter-spacing: .2px; }
.brand-text span { font-size: 12px; color: rgba(255,255,255,.7); }

.nav { flex: 1; padding: 16px 12px; overflow-y: auto; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: rgba(255,255,255,.55); padding: 14px 12px 6px; font-weight: 600; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 10px 12px; margin-bottom: 2px;
  border: 0; border-radius: var(--radius-sm);
  background: transparent; color: rgba(255,255,255,.85);
  text-align: left; font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.09); color: #fff; }
.nav-item.active { background: #fff; color: var(--azul-principal); box-shadow: var(--shadow-sm); }
.nav-item.active svg { color: var(--azul-secundario); }
.nav-item .count { margin-left: auto; font-size: 11px; font-weight: 600; background: rgba(255,255,255,.16); padding: 1px 8px; border-radius: 99px; }
.nav-item.active .count { background: var(--azul-suave); color: var(--azul-principal); }
.nav-item.sub { padding-left: 20px; font-size: 13px; }
.nav-item.sub .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--azul-tecnologico); flex-shrink: 0; }
.nav-item .label-ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-footer { padding: 16px; border-top: 1px solid rgba(255,255,255,.12); }
.switch-label { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: rgba(255,255,255,.6); font-weight: 600; margin-bottom: 8px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: rgba(0,0,0,.18); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: transparent; color: rgba(255,255,255,.8); padding: 7px 6px; border-radius: 8px; font-weight: 600; font-size: 12.5px; }
.seg button.active { background: #fff; color: var(--azul-principal); }
.sidebar-footer select {
  margin-top: 10px; width: 100%; padding: 8px 10px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.1); color: #fff;
}
.sidebar-footer select option { color: var(--negro); }
.link-btn { background: none; border: 0; padding: 0; margin-top: 12px; color: rgba(255,255,255,.65); font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }
.link-btn:hover { color: #fff; }
.link-btn svg { width: 14px; height: 14px; }

.sidebar-overlay { display: none; }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h);
  background: var(--blanco);
  border-bottom: 1px solid var(--borde);
  display: flex; align-items: center; gap: 16px;
  padding: 0 28px;
  position: sticky; top: 0; z-index: 30;
}
.topbar-title { min-width: 0; }
.crumbs { font-size: 12px; color: var(--gris-texto); display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; }
.crumbs button { background: none; border: 0; padding: 0; color: var(--azul-secundario); font-size: 12px; }
.crumbs svg { width: 12px; height: 12px; }
.topbar-title h2 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.demo-pill { font-size: 12px; font-weight: 600; color: #92400E; background: var(--advertencia-suave); border: 1px solid #FCD9A0; padding: 4px 10px; border-radius: 99px; white-space: nowrap; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--azul-suave); color: var(--azul-principal); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.avatar.alt { background: var(--azul-tecnologico); color: #fff; }
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-meta strong { font-size: 13px; }
.user-meta span { font-size: 12px; color: var(--gris-texto); }
.topbar .menu-btn { display: none; }

.view { padding: 28px; flex: 1; }
.view.view-chat { padding: 0; }

/* ---------------- Generic components ---------------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; font-weight: 700; color: var(--azul-principal); }
.page-head p { color: var(--gris-texto); margin-top: 4px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.card { background: var(--blanco); border: 1px solid var(--borde); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--borde-suave); }
.card-head h3 { font-size: 15px; display: flex; align-items: center; gap: 8px; }
.card-head h3 svg { color: var(--azul-secundario); }
.card-head p { font-size: 12.5px; color: var(--gris-texto); margin-top: 2px; }
.card-body { padding: 20px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid transparent; font-weight: 600; font-size: 13.5px;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--azul-principal); color: #fff; }
.btn-primary:hover { background: var(--azul-principal-hover); }
.btn-secondary { background: var(--blanco); color: var(--azul-secundario); border-color: var(--borde); }
.btn-secondary:hover { border-color: var(--azul-secundario); background: var(--azul-suave); }
.btn-ghost { background: transparent; color: var(--azul-secundario); }
.btn-ghost:hover { background: var(--azul-suave); }
.btn-danger-ghost { background: transparent; color: var(--error); }
.btn-danger-ghost:hover { background: var(--error-suave); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.icon-btn { width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: var(--radius-sm); border: 1px solid transparent; background: transparent; color: var(--gris-texto); }
.icon-btn:hover { background: var(--azul-suave); color: var(--azul-secundario); }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.success { color: var(--exito); background: var(--exito-suave); }
.badge.warning { color: #B45309; background: var(--advertencia-suave); }
.badge.error { color: var(--error); background: var(--error-suave); }
.badge.info { color: var(--info); background: var(--azul-suave); }
.badge.neutral { color: var(--gris-texto); background: var(--gris-fondo); }
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 6px; font-size: 12px; font-weight: 500; background: var(--azul-suave); color: var(--azul-principal); }
.mono { font-family: var(--mono); font-size: 12px; color: var(--gris-texto); }
.muted { color: var(--gris-texto); }
.small { font-size: 12.5px; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 20px; }
.grid-2.even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 20px; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi { padding: 18px 20px; display: flex; gap: 14px; align-items: center; }
.kpi-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--azul-suave); color: var(--azul-secundario); }
.kpi-icon.tech { background: #E3F2FA; color: var(--azul-tecnologico); }
.kpi-icon svg { width: 22px; height: 22px; }
.kpi strong { font-size: 24px; display: block; line-height: 1.1; }
.kpi span { font-size: 12.5px; color: var(--gris-texto); }

/* Demo flow steps */
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.step { display: flex; align-items: center; gap: 14px; padding: 12px; border-radius: 10px; }
.step:hover { background: var(--gris-fondo); }
.step-num { width: 30px; height: 30px; border-radius: 50%; background: var(--azul-suave); color: var(--azul-principal); font-weight: 700; display: grid; place-items: center; flex-shrink: 0; font-size: 13px; }
.step.done .step-num { background: var(--exito); color: #fff; }
.step-text { flex: 1; min-width: 0; }
.step-text strong { display: block; font-size: 13.5px; }
.step-text span { font-size: 12.5px; color: var(--gris-texto); }

/* Pipeline */
.pipeline { display: flex; align-items: stretch; gap: 8px; flex-wrap: wrap; }
.pipe-node { flex: 1; min-width: 120px; background: var(--azul-suave); border-radius: 10px; padding: 12px; text-align: center; }
.pipe-node svg { color: var(--azul-secundario); margin-bottom: 4px; width: 22px; height: 22px; }
.pipe-node strong { display: block; font-size: 13px; }
.pipe-node span { font-size: 11.5px; color: var(--gris-texto); }
.pipe-arrow { display: grid; place-items: center; color: var(--azul-tecnologico); }
.pipe-companies { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 140px; }
.pipe-companies .tag { justify-content: center; padding: 7px; }

/* Activity */
.activity { list-style: none; margin: 0; padding: 0; }
.activity li { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--borde-suave); }
.activity li:last-child { border-bottom: 0; }
.activity .a-icon { width: 30px; height: 30px; border-radius: 8px; background: var(--azul-suave); color: var(--azul-secundario); display: grid; place-items: center; flex-shrink: 0; }
.activity .a-icon svg { width: 15px; height: 15px; }
.activity .a-text { font-size: 13px; }
.activity .a-time { font-size: 11.5px; color: var(--gris-texto); }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--gris-texto); font-weight: 600; padding: 12px 20px; background: #FAFBFD; border-bottom: 1px solid var(--borde); white-space: nowrap; }
td { padding: 14px 20px; border-bottom: 1px solid var(--borde-suave); vertical-align: middle; }
tbody tr { cursor: pointer; transition: background .12s; }
tbody tr:hover { background: var(--azul-suave); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: center; }
.company-cell { display: flex; align-items: center; gap: 12px; }
.company-logo { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff; background: var(--azul-secundario); flex-shrink: 0; }
.company-cell strong { display: block; }
.chev { color: var(--gris-texto); }

.search { position: relative; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--gris-texto); width: 16px; height: 16px; }
.search input { padding: 9px 12px 9px 34px; border: 1px solid var(--borde); border-radius: var(--radius-sm); width: 240px; background: #fff; }
.search input:focus { outline: none; border-color: var(--azul-secundario); box-shadow: 0 0 0 3px var(--azul-suave); }

/* Company detail */
.detail-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.detail-head .company-logo { width: 56px; height: 56px; font-size: 20px; border-radius: 14px; }
.detail-head h1 { font-size: 22px; color: var(--azul-principal); }
.detail-head .meta { display: flex; gap: 8px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.detail-head .actions { margin-left: auto; }

dl.data { display: grid; grid-template-columns: 160px 1fr; gap: 10px 16px; margin: 0; }
dl.data dt { color: var(--gris-texto); font-size: 13px; }
dl.data dd { margin: 0; font-weight: 500; word-break: break-word; }

.context-box { background: var(--azul-suave); border-left: 3px solid var(--azul-tecnologico); padding: 14px 16px; border-radius: 0 10px 10px 0; color: var(--negro); white-space: pre-wrap; }

.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--borde-suave); }
.list-item:last-child { border-bottom: 0; }
.list-item .li-icon { width: 38px; height: 38px; border-radius: 10px; background: var(--azul-suave); color: var(--azul-secundario); display: grid; place-items: center; flex-shrink: 0; }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-main strong { display: block; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .li-main span { font-size: 12px; color: var(--gris-texto); }
.list-item .li-actions { display: flex; gap: 4px; align-items: center; }

.empty { text-align: center; padding: 28px 16px; color: var(--gris-texto); }
.empty svg { width: 32px; height: 32px; color: var(--azul-tecnologico); margin-bottom: 8px; }
.empty strong { display: block; color: var(--negro); margin-bottom: 4px; }

/* Dropzone */
.dropzone {
  display: flex; align-items: center; justify-content: center; gap: 10px; flex-direction: column;
  border: 1.5px dashed #B9D7EA; background: #FAFDFF; border-radius: 10px; padding: 18px; text-align: center;
  color: var(--gris-texto); cursor: pointer; transition: background .15s, border-color .15s; margin-top: 12px;
}
.dropzone:hover, .dropzone.drag { background: var(--azul-suave); border-color: var(--azul-secundario); }
.dropzone svg { color: var(--azul-secundario); width: 24px; height: 24px; }
.dropzone strong { color: var(--azul-secundario); }
.dropzone input { display: none; }

.doc-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; }
.doc-status.completed { color: var(--exito); }
.doc-status.processing { color: #B45309; }
.spinner { width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Toggle */
.toggle { position: relative; width: 38px; height: 22px; border-radius: 99px; background: #CBD5E1; border: 0; padding: 0; transition: background .15s; flex-shrink: 0; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: var(--shadow-sm); }
.toggle.on { background: var(--exito); }
.toggle.on::after { transform: translateX(16px); }

/* Factory */
.factory-banner { background: linear-gradient(120deg, var(--azul-principal), var(--azul-secundario) 60%, var(--azul-tecnologico)); color: #fff; border-radius: var(--radius); padding: 22px 24px; display: flex; gap: 20px; align-items: center; margin-bottom: 24px; flex-wrap: wrap; }
.factory-banner h3 { color: #fff; font-size: 16px; margin-bottom: 4px; }
.factory-banner p { color: rgba(255,255,255,.85); font-size: 13px; max-width: 620px; }
.flow-chips { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.flow-chips span { background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.25); padding: 6px 12px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.flow-chips svg { width: 14px; height: 14px; opacity: .8; }

.solutions-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 20px; }
.sol-card { display: flex; flex-direction: column; padding: 22px; transition: box-shadow .15s, transform .15s, border-color .15s; }
.sol-card:hover { box-shadow: var(--shadow); border-color: #CFE3F0; transform: translateY(-2px); }
.sol-icon { width: 50px; height: 50px; border-radius: 14px; background: var(--azul-suave); color: var(--azul-secundario); display: grid; place-items: center; margin-bottom: 16px; position: relative; }
.sol-icon svg { width: 26px; height: 26px; }
.sol-icon .ai-dot { position: absolute; right: -3px; top: -3px; width: 14px; height: 14px; border-radius: 50%; background: var(--azul-tecnologico); border: 2px solid #fff; }
.sol-card h3 { font-size: 16px; margin-bottom: 6px; }
.sol-card > p { color: var(--gris-texto); font-size: 13.5px; flex: 1; }
.sol-meta { display: flex; gap: 14px; flex-wrap: wrap; margin: 16px 0; padding-top: 14px; border-top: 1px solid var(--borde-suave); font-size: 12px; color: var(--gris-texto); }
.sol-meta span { display: inline-flex; align-items: center; gap: 5px; }
.sol-meta svg { width: 14px; height: 14px; color: var(--azul-tecnologico); }
.sol-actions { display: flex; gap: 8px; }
.sol-actions .btn { flex: 1; }
.sol-card.placeholder { border-style: dashed; background: transparent; box-shadow: none; align-items: center; justify-content: center; text-align: center; color: var(--gris-texto); min-height: 280px; }
.sol-card.placeholder:hover { transform: none; box-shadow: none; }
.sol-card.placeholder .sol-icon { background: var(--blanco); border: 1px dashed #B9D7EA; }
.progress { width: 100%; max-width: 220px; height: 6px; background: var(--borde); border-radius: 99px; overflow: hidden; margin: 12px auto 6px; }
.progress span { display: block; height: 100%; background: var(--azul-tecnologico); border-radius: 99px; }

/* Portal hero */
.portal-hero { background: var(--blanco); border: 1px solid var(--borde); border-radius: var(--radius); padding: 24px; display: flex; gap: 18px; align-items: center; margin-bottom: 24px; flex-wrap: wrap; }
.portal-hero .company-logo { width: 54px; height: 54px; font-size: 19px; border-radius: 14px; }
.portal-hero h1 { font-size: 22px; color: var(--azul-principal); }
.portal-hero p { color: var(--gris-texto); }
.secure-note { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--gris-texto); background: var(--gris-fondo); padding: 8px 12px; border-radius: 8px; }
.secure-note svg { color: var(--exito); width: 16px; height: 16px; }

/* ---------------- Chat ---------------- */
.chat-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr) 300px; height: calc(100vh - var(--topbar-h)); height: calc(100dvh - var(--topbar-h)); }
.conv-panel { background: var(--blanco); border-right: 1px solid var(--borde); display: flex; flex-direction: column; min-height: 0; }
.conv-panel .panel-top { padding: 16px; border-bottom: 1px solid var(--borde-suave); }
.conv-panel .panel-top .btn { width: 100%; }
.conv-list { flex: 1; overflow-y: auto; padding: 8px; }
.conv-item { width: 100%; text-align: left; border: 0; background: transparent; padding: 10px 12px; border-radius: 8px; display: flex; flex-direction: column; gap: 2px; margin-bottom: 2px; }
.conv-item:hover { background: var(--gris-fondo); }
.conv-item.active { background: var(--azul-suave); }
.conv-item strong { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--negro); }
.conv-item.active strong { color: var(--azul-principal); font-weight: 600; }
.conv-item span { font-size: 11.5px; color: var(--gris-texto); }
.panel-label { font-size: 11px; text-transform: uppercase; letter-spacing: .7px; color: var(--gris-texto); font-weight: 600; padding: 10px 12px 6px; }

.chat-main { display: flex; flex-direction: column; min-height: 0; background: var(--gris-fondo); }
.chat-head { background: var(--blanco); border-bottom: 1px solid var(--borde); padding: 14px 24px; display: flex; align-items: center; gap: 14px; }
.chat-head .sol-icon { width: 42px; height: 42px; margin: 0; border-radius: 12px; }
.chat-head .sol-icon svg { width: 22px; height: 22px; }
.chat-head h3 { font-size: 15px; }
.chat-head p { font-size: 12.5px; color: var(--gris-texto); }
.chat-head .online { margin-left: auto; }

.messages { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.msg { display: flex; gap: 10px; max-width: 760px; width: 100%; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg .m-avatar { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; background: var(--azul-tecnologico); color: #fff; }
.msg .m-avatar svg { width: 17px; height: 17px; }
.msg.user .m-avatar { background: var(--azul-suave); color: var(--azul-principal); font-weight: 700; font-size: 12px; border-radius: 50%; }
.bubble { padding: 12px 16px; border-radius: 14px; background: var(--blanco); border: 1px solid var(--borde); box-shadow: var(--shadow-sm); font-size: 14px; min-width: 0; }
.msg.user .bubble { background: var(--azul-principal); color: #fff; border-color: var(--azul-principal); border-top-right-radius: 4px; max-width: 80%; white-space: pre-wrap; word-break: break-word; }
.msg.assistant .bubble { border-top-left-radius: 4px; }
.bubble p + p, .bubble p + ol, .bubble ol + p, .bubble ol + div { margin-top: 10px; }
.bubble ol { margin: 0; padding-left: 20px; }
.bubble ol li { margin: 4px 0; }
.bubble ol li b { color: var(--azul-principal); }
.m-time { font-size: 11px; color: var(--gris-texto); margin-top: 4px; }
.msg.user .m-time { text-align: right; }
.demo-flag { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; color: #92400E; background: var(--advertencia-suave); padding: 2px 8px; border-radius: 6px; margin-bottom: 8px; }
.demo-flag svg { width: 13px; height: 13px; }
.sources { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--borde-suave); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.sources > span { font-size: 11.5px; color: var(--gris-texto); margin-right: 2px; }
.source-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; padding: 3px 8px; border-radius: 6px; background: var(--azul-suave); color: var(--azul-principal); }
.source-chip svg { width: 12px; height: 12px; color: var(--azul-tecnologico); }

.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--azul-tecnologico); animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.chat-welcome { margin: auto; text-align: center; max-width: 560px; padding: 20px 0; }
.chat-welcome .sol-icon { margin: 0 auto 14px; width: 60px; height: 60px; border-radius: 18px; }
.chat-welcome .sol-icon svg { width: 30px; height: 30px; }
.chat-welcome h2 { font-size: 20px; margin-bottom: 6px; }
.chat-welcome p { color: var(--gris-texto); }
.suggestions { display: grid; gap: 10px; margin-top: 22px; }
.suggestion { text-align: left; border: 1px solid var(--borde); background: var(--blanco); border-radius: 10px; padding: 12px 16px; display: flex; align-items: center; gap: 12px; color: var(--negro); font-weight: 500; transition: border-color .15s, background .15s; }
.suggestion:hover { border-color: var(--azul-secundario); background: var(--azul-suave); }
.suggestion svg { color: var(--azul-tecnologico); }

.composer { padding: 16px 24px 20px; background: var(--gris-fondo); }
.composer form { max-width: 800px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; background: var(--blanco); border: 1px solid var(--borde); border-radius: 14px; padding: 8px 8px 8px 16px; box-shadow: var(--shadow-sm); }
.composer form:focus-within { border-color: var(--azul-secundario); box-shadow: 0 0 0 3px var(--azul-suave); }
.composer textarea { flex: 1; border: 0; resize: none; outline: none; padding: 8px 0; max-height: 140px; line-height: 1.45; background: transparent; color: var(--negro); }
.composer .btn { padding: 9px 14px; }
.composer-note { text-align: center; font-size: 11.5px; color: var(--gris-texto); margin-top: 8px; }

.ctx-panel { background: var(--blanco); border-left: 1px solid var(--borde); overflow-y: auto; padding: 20px; }
.ctx-panel h4 { font-size: 13px; margin-bottom: 4px; }
.ctx-panel > p { font-size: 12.5px; color: var(--gris-texto); margin-bottom: 16px; }
.layer { display: flex; gap: 12px; padding: 12px; border-radius: 10px; background: var(--gris-fondo); margin-bottom: 8px; }
.layer-n { width: 24px; height: 24px; border-radius: 7px; background: var(--azul-tecnologico); color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; flex-shrink: 0; }
.layer strong { font-size: 12.5px; display: block; }
.layer span { font-size: 12px; color: var(--gris-texto); }
.layer.locked { opacity: .75; }
.ctx-docs { list-style: none; padding: 0; margin: 8px 0 0; }
.ctx-docs li { display: flex; align-items: center; gap: 8px; font-size: 12.5px; padding: 6px 0; color: var(--negro); }
.ctx-docs li svg { width: 14px; height: 14px; color: var(--azul-secundario); }

/* ---------------- Modal ---------------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(23, 28, 36, .45); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; animation: fade .15s ease; }
.modal { background: var(--blanco); border-radius: 16px; width: 100%; max-width: 640px; box-shadow: var(--shadow-lg); }
.modal-backdrop.no-anim { animation: none; }
.modal-backdrop:not(.no-anim) .modal { animation: pop .18s ease; }
.modal.lg { max-width: 820px; }
.modal-head { display: flex; align-items: flex-start; gap: 14px; padding: 22px 24px 16px; border-bottom: 1px solid var(--borde-suave); }
.modal-head h3 { font-size: 18px; color: var(--azul-principal); }
.modal-head p { color: var(--gris-texto); font-size: 13px; margin-top: 3px; }
.modal-head .icon-btn { margin-left: auto; }
.modal-body { padding: 22px 24px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--borde-suave); background: #FAFBFD; border-radius: 0 0 16px 16px; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

.form-section { font-size: 12px; text-transform: uppercase; letter-spacing: .7px; font-weight: 700; color: var(--azul-principal); margin: 22px 0 12px; display: flex; align-items: center; gap: 8px; }
.form-section:first-child { margin-top: 0; }
.form-section::after { content: ""; flex: 1; height: 1px; background: var(--borde-suave); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--negro); }
.field label .req { color: var(--error); }
.field .hint { font-size: 12px; color: var(--gris-texto); }
.field input, .field select, .field textarea { padding: 9px 12px; border: 1px solid var(--borde); border-radius: var(--radius-sm); background: var(--blanco); color: var(--negro); width: 100%; }
.field textarea { resize: vertical; min-height: 80px; line-height: 1.45; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--azul-secundario); box-shadow: 0 0 0 3px var(--azul-suave); }
.field.invalid input { border-color: var(--error); }
.field-key { font-family: var(--mono); font-size: 10.5px; color: var(--azul-tecnologico); font-weight: 500; margin-left: 6px; }

.alert { display: flex; gap: 10px; padding: 12px 14px; border-radius: 10px; font-size: 13px; align-items: flex-start; }
.alert svg { margin-top: 1px; }
.alert.info { background: var(--azul-suave); color: var(--azul-principal); }
.alert.warning { background: var(--advertencia-suave); color: #92400E; }
.alert.success { background: var(--exito-suave); color: #166534; }

.prompt-box { background: #0F1A2A; color: #D6E6F5; font-family: var(--mono); font-size: 12px; line-height: 1.6; padding: 16px; border-radius: 10px; white-space: pre-wrap; max-height: 260px; overflow-y: auto; }
.prompt-box b { color: #7CC4EA; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.layers-diagram { display: grid; gap: 8px; }
.layers-diagram .layer { margin: 0; background: var(--azul-suave); }

/* ---------------- Toasts ---------------- */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast { display: flex; align-items: center; gap: 10px; background: var(--negro); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 13.5px; max-width: 360px; animation: slidein .2s ease; }
.toast svg { width: 18px; height: 18px; }
.toast.success svg { color: #4ADE80; }
.toast.info svg { color: var(--azul-tecnologico); }
.toast.warning svg { color: var(--advertencia); }
.toast.out { opacity: 0; transform: translateY(6px); transition: all .25s; }
@keyframes slidein { from { opacity: 0; transform: translateY(10px); } }

/* ---------------- Responsive ---------------- */
@media (max-width: 1280px) {
  .chat-layout { grid-template-columns: 240px minmax(0, 1fr); }
  .ctx-panel { display: none; }
}
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .grid-2.even { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-overlay { display: block; position: fixed; inset: 0; background: rgba(23,28,36,.4); z-index: 35; }
  .main { margin-left: 0; }
  .topbar .menu-btn { display: inline-grid; }
  .topbar { padding: 0 16px; gap: 10px; }
  .view { padding: 20px 16px; }
  .chat-layout { grid-template-columns: minmax(0, 1fr); }
  .conv-panel { display: none; }
  .user-meta { display: none; }
}
@media (max-width: 640px) {
  .demo-pill { display: none; }
  .kpis { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  dl.data { grid-template-columns: 1fr; gap: 2px; }
  dl.data dd { margin-bottom: 10px; }
  .search input { width: 100%; }
  .page-head .actions, .search { width: 100%; }
  .detail-head .actions { margin-left: 0; width: 100%; }
  .messages { padding: 16px; }
  .composer { padding: 12px 16px 16px; }
  .chat-head { padding: 12px 16px; }
  .chat-head .online { display: none; }
  .modal-backdrop { padding: 16px 12px; }
  .secure-note { margin-left: 0; }
  .flow-chips { margin-left: 0; }
  .solutions-grid { grid-template-columns: minmax(0, 1fr); }
}
