/* B-Tec · Plataforma de agentes — estilos. Tokens heredados del deck B-Tec. Sin frameworks. */
:root {
  --bg: #0e1116;
  --bg-2: #131821;
  --bg-3: #1a212c;
  --line: #273041;
  --text: #eaf0f6;
  --muted: #a3b2c4;
  --faint: #6f7f93;
  --accent: #3BA9FF;
  --accent-2: #22d3ee;
  --accent-soft: rgba(59, 169, 255, .12);
  --warn: #f5c451;
  --danger: #ff6b6b;
  --ok: #4ade80;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--text);
  font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; letter-spacing: -.01em; line-height: 1.2; }
h1 { font-size: 1.7rem; font-weight: 750; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 650; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.faint { color: var(--faint); font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* Wordmark B-Tec (como en el deck) */
.wordmark {
  font-weight: 800; font-size: 1.35rem; letter-spacing: -.02em; color: var(--text);
  display: inline-flex; align-items: baseline; text-decoration: none;
}
.wordmark:hover { text-decoration: none; }
.wordmark i { font-style: normal; color: var(--accent); margin: 0 .04em; }
.wordmark::after {
  content: ""; display: inline-block; width: .38em; height: .38em; border-radius: 50%;
  background: var(--accent); margin-left: .18em; box-shadow: 0 0 12px rgba(59, 169, 255, .8);
}

/* Estructura */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 18px;
  padding: 12px clamp(16px, 3vw, 36px); background: rgba(14, 17, 22, .92);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.topbar .product { color: var(--faint); font-size: .85rem; letter-spacing: .04em; text-transform: uppercase; }
.topbar .spacer { flex: 1; }
main { max-width: 1180px; margin: 0 auto; padding: 28px clamp(16px, 3vw, 36px) 64px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head .grow { flex: 1; min-width: 240px; }
.page-head p { color: var(--muted); margin-top: 6px; }
.crumbs { font-size: .85rem; color: var(--faint); margin-bottom: 10px; }
.crumbs a { color: var(--muted); }
.section-title { display: flex; align-items: center; gap: 12px; margin: 34px 0 14px; }
.section-title .grow { flex: 1; }

/* Tarjetas */
.card {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px;
}
.card h2 { margin-bottom: 4px; }
.grid { display: grid; gap: 16px; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid.agents { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.kpi .label { color: var(--muted); font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; }
.kpi .value { font-size: 1.9rem; font-weight: 760; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--faint); font-size: .82rem; margin-top: 2px; }

/* Botones y formularios */
button { font: inherit; cursor: pointer; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 16px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--bg-3); color: var(--text);
  font-weight: 600; font-size: .92rem; transition: border-color .15s, background .15s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #07121c; }
.btn.primary:hover:not(:disabled) { background: #5db6ff; border-color: #5db6ff; }
.btn.danger { color: var(--danger); }
.btn.danger:hover:not(:disabled) { border-color: var(--danger); }
.btn.small { padding: 6px 11px; font-size: .84rem; border-radius: 8px; }
.btn.ghost { background: transparent; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.card > p + .row { margin-top: 14px; }
.card > p.muted + form { margin-top: 14px; }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
input[type=text], input[type=password], input[type=number], input[type=url], select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 110px; line-height: 1.45; }
.hint { font-size: .8rem; color: var(--faint); margin-top: 6px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; border: 1px solid var(--line);
  border-radius: 999px; background: var(--bg); cursor: pointer; font-size: .88rem; user-select: none;
}
.check:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.check input { accent-color: var(--accent); margin: 0; }

/* Chips y estados */
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: .78rem; font-weight: 600; border: 1px solid var(--line); color: var(--muted); background: var(--bg);
  white-space: nowrap;
}
.chip.accent { color: var(--accent); border-color: rgba(59, 169, 255, .4); background: var(--accent-soft); }
.chip.ok { color: var(--ok); border-color: rgba(74, 222, 128, .35); background: rgba(74, 222, 128, .08); }
.chip.warn { color: var(--warn); border-color: rgba(245, 196, 81, .4); background: rgba(245, 196, 81, .08); }
.chip.danger { color: var(--danger); border-color: rgba(255, 107, 107, .4); background: rgba(255, 107, 107, .08); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.mono { font-family: var(--mono); }

/* Barra de consumo */
.meter { height: 8px; border-radius: 999px; background: var(--bg-3); overflow: hidden; border: 1px solid var(--line); }
.meter > span { display: block; height: 100%; border-radius: 999px; background: var(--accent); }
.meter.warn > span { background: var(--warn); }
.meter.danger > span { background: var(--danger); }
.meter-label { display: flex; justify-content: space-between; gap: 10px; font-size: .82rem; color: var(--muted); margin-top: 6px; }

/* Tabla */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-2); }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { text-align: left; padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .74rem; color: var(--faint); letter-spacing: .08em; text-transform: uppercase; font-weight: 700; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255, 255, 255, .02); }
td.right, th.right { text-align: right; }
.cell-meter { min-width: 220px; }
.name-link { font-weight: 650; color: var(--text); }

/* Tarjeta de agente */
.agent-card { display: flex; flex-direction: column; gap: 12px; }
.agent-card p.desc { color: var(--muted); font-size: .9rem; flex: 1; }
.agent-card .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Estado vacío */
.empty { text-align: center; padding: 38px 20px; color: var(--muted); }
.empty h3 { color: var(--text); margin-bottom: 6px; }
.empty .row { justify-content: center; margin-top: 14px; }
.row.stats { gap: 28px; margin-top: 14px; }

/* Acceso */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login { width: min(440px, 100%); }
.login .wordmark { font-size: 2rem; }
.login h1 { font-size: 1.25rem; margin: 18px 0 6px; }
.login .card { margin-top: 22px; }
.banner {
  margin-top: 16px; padding: 10px 14px; border-radius: 10px; font-size: .86rem;
  border: 1px solid rgba(59, 169, 255, .35); background: var(--accent-soft); color: var(--text);
}
.error-text { color: var(--danger); font-size: .86rem; margin-top: 10px; min-height: 1.2em; }

/* Chat */
.chat-shell { display: flex; flex-direction: column; height: min(640px, calc(100vh - 410px)); min-height: 380px; padding: 0; overflow: hidden; }
.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 78%; padding: 11px 15px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; }
.msg.user { align-self: flex-end; background: var(--accent); color: #07121c; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--bg-3); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.blocked { align-self: stretch; max-width: none; background: rgba(245, 196, 81, .08); border: 1px solid rgba(245, 196, 81, .45); color: var(--warn); }
.msg.error { align-self: stretch; max-width: none; background: rgba(255, 107, 107, .08); border: 1px solid rgba(255, 107, 107, .45); color: var(--danger); }
.msg .meta { display: block; margin-top: 8px; font-size: .74rem; opacity: .7; }
.msg.pending { color: var(--muted); font-style: italic; }
.composer { display: flex; gap: 10px; padding: 14px; border-top: 1px solid var(--line); background: var(--bg-2); align-items: flex-end; }
.composer textarea { min-height: 46px; max-height: 160px; height: 46px; }
.chat-empty { margin: auto; text-align: center; color: var(--muted); max-width: 420px; }

/* Pestañas del agente */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 0 0 20px; }
.tab { padding: 10px 16px; color: var(--muted); font-weight: 650; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Motor agéntico: ejecutar tarea */
.run-layout { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(300px, 1fr); gap: 16px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.grow-text { flex: 1; }
.run-actions { margin-top: 12px; justify-content: space-between; }
.steps-field { display: inline-flex; align-items: center; gap: 8px; }
.steps-field input { width: 84px; padding: 7px 10px; }
.chip.example { cursor: pointer; font-weight: 500; white-space: normal; text-align: left; line-height: 1.35; padding: 5px 11px; }
button.chip.example:hover { border-color: var(--accent); color: var(--text); }
.warn-banner { border-color: rgba(245, 196, 81, .5); background: rgba(245, 196, 81, .08); margin: 0 0 14px; }
.working { margin-top: 12px; }
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.step { display: grid; grid-template-columns: 124px minmax(0, 1fr); gap: 12px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); border-left: 3px solid var(--line); }
.step .kind { font-size: .72rem; letter-spacing: .07em; text-transform: uppercase; font-weight: 750; color: var(--faint); display: flex; flex-direction: column; gap: 2px; }
.step .kind .when { font-size: .72rem; letter-spacing: 0; text-transform: none; font-weight: 400; }
.step .body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; min-width: 0; }
.step .params { font-family: var(--mono); font-size: .8rem; color: var(--muted); margin-top: 3px; }
.step .result { margin-top: 6px; font-family: var(--mono); font-size: .82rem; color: var(--muted); max-height: 220px; overflow: auto; }
.step.k-tarea { border-left-color: var(--faint); }
.step.k-pensamiento { border-left-color: var(--accent-2); }
.step.k-pensamiento .kind { color: var(--accent-2); }
.step.k-herramienta { border-left-color: var(--accent); }
.step.k-herramienta .kind { color: var(--accent); }
.step.k-resultado { border-left-color: var(--ok); }
.step.k-aprobacion { border-left-color: var(--warn); }
.step.k-aprobacion .kind { color: var(--warn); }
.step.k-respuesta { border-left-color: var(--ok); background: rgba(74, 222, 128, .05); }
.step.k-respuesta .kind { color: var(--ok); }
.step.k-sistema, .step.k-error { border-left-color: var(--danger); }
.step.k-error .kind { color: var(--danger); }
.codeblock { font-family: var(--mono); font-size: .82rem; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 240px; overflow: auto; margin: 4px 0 8px; color: var(--text); }
.approval { border: 1px solid rgba(245, 196, 81, .45); background: rgba(245, 196, 81, .06); border-radius: 12px; padding: 14px; margin-top: 12px; }
.approval .arg .faint { font-family: var(--mono); }
.tool-row { padding: 12px 0; border-top: 1px solid var(--line); }
.tool-row:first-of-type { border-top: none; }
.tool-row select { margin-top: 8px; }
select.inline-select { width: auto; min-width: 190px; }
.tool-desc { margin: 4px 0 0; }
.run-item { display: block; width: 100%; text-align: left; padding: 10px 12px; margin-top: 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.run-item:hover, .run-item.active { border-color: var(--accent); }
.run-task-line { margin-top: 6px; color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }
.audit-table { min-width: 880px; }
.audit-table td { padding: 10px 14px; font-size: .88rem; }
.params-cell, .detail-cell { max-width: 300px; overflow-wrap: anywhere; font-size: .8rem; }
.nowrap { white-space: nowrap; }
.chip .dot.pulse { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .chip .dot.pulse { animation: none; } }
@media (max-width: 980px) { .run-layout { grid-template-columns: 1fr; } }
@media (max-width: 640px) { .step { grid-template-columns: 1fr; gap: 6px; } .step .kind { flex-direction: row; gap: 10px; align-items: baseline; } }

/* Modal y avisos */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(5, 8, 12, .72); display: grid;
  place-items: center; padding: 20px; overflow-y: auto;
}
.modal { width: min(560px, 100%); background: var(--bg-2); border: 1px solid var(--line); border-radius: 18px; padding: 24px; margin: auto; }
.modal h2 { margin-bottom: 16px; }
#toasts { position: fixed; top: 72px; right: 20px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 11px 16px; border-radius: 10px; background: var(--bg-3); border: 1px solid var(--line); box-shadow: 0 8px 28px rgba(0, 0, 0, .45); max-width: 360px; font-size: .9rem; }
.toast.error { border-color: rgba(255, 107, 107, .55); color: var(--danger); }
.toast.ok { border-color: rgba(74, 222, 128, .5); }

@media (max-width: 640px) {
  h1 { font-size: 1.4rem; }
  .msg { max-width: 92%; }
  .topbar .product { display: none; }
}
