:root {
  /* Neurotry — sistema de diseño actual (iva-flow / advanzer V2): Inter + navy + azul, slate claro */
  --bg: #f7fafc;
  --bg-soft: #edf2f7;
  --panel: #ffffff;
  --panel-2: #f7fafc;
  --border: #e2e8f0;
  --text: #2d3748;
  --text-dim: #718096;
  --text-faint: #a0aec0;
  --text-on-dark: #f7fafc;
  --accent: #3182ce;
  --accent-2: #2b6cb0;
  --navy: #1a365d;
  --accent-soft: rgba(49, 130, 206, 0.10);
  --green: #38a169;
  --green-soft: rgba(56, 161, 105, 0.12);
  --amber: #d69e2e;
  --amber-soft: rgba(214, 158, 46, 0.14);
  --red: #e53e3e;
  --red-soft: rgba(229, 62, 62, 0.10);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px 0 rgba(0,0,0,0.05);
  --shadow-lg: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
  --steel: #ffffff;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

/* El atributo [hidden] debe ganar contra reglas de clase con display:flex
   (sino el spinner-overlay queda siempre visible). */
[hidden] { display: none !important; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 .5rem; font-weight: 700; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }

.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); font-size: .85rem; }
.mono { font-family: var(--mono); }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

/* ── Layout ── */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}
.brand {
  display: flex;
  align-items: center;
  gap: .55rem;
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -.01em;
  color: var(--navy);
}
.brand .dot {
  width: 12px; height: 12px; border-radius: 3px;
  background: linear-gradient(135deg, var(--navy), var(--accent));
}
.brand-sub { color: var(--text-dim); font-size: .72rem; font-weight: 600; letter-spacing: .02em; }
.brand-tag { color: var(--text-dim); font-size: .85rem; font-weight: 400; margin-top: .25rem; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: .85rem 1.4rem;
  background: var(--steel);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar .user-box { display: flex; align-items: center; gap: 1rem; }
.topbar .user-email { color: var(--text-dim); font-size: .9rem; }
.content { flex: 1; max-width: 1080px; width: 100%; margin: 0 auto; padding: 1.6rem 1.4rem 3rem; }

/* ── Footer ── */
.site-footer {
  text-align: center;
  padding: 1.1rem 1rem;
  font-size: .82rem;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
}
.site-footer a { color: var(--accent); font-weight: 600; }
.auth-footer { margin-top: 1.6rem; }
.auth-footer .site-footer { border: none; background: transparent; padding: .4rem; }

.crumbs { font-size: .9rem; color: var(--text-dim); margin-bottom: 1rem; }
.crumbs a { color: var(--text-dim); }

/* ── Forms ── */
.field { margin-bottom: 1rem; }
label { display: block; font-size: .85rem; color: var(--text-dim); margin-bottom: .35rem; }
input, textarea, select {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: .6rem .7rem;
  font-size: .95rem;
  font-family: inherit;
}
textarea { resize: vertical; min-height: 90px; }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.row { display: flex; gap: .8rem; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }
.checks { display: flex; flex-direction: column; gap: .5rem; }
.check { display: flex; align-items: center; gap: .5rem; }
.check input { width: auto; }
.check label { margin: 0; color: var(--text); font-size: .95rem; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  background: var(--navy); color: var(--text-on-dark); border: 1px solid transparent;
  border-radius: var(--radius-sm); padding: .55rem 1rem; font-size: .92rem;
  font-weight: 600; cursor: pointer; font-family: inherit; transition: background .15s;
}
.btn:hover { background: var(--accent-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--navy); }
.btn.ghost:hover { background: var(--panel-2); }
.btn.danger { background: var(--red); }
.btn.danger:hover { background: #9c2922; }
.btn.sm { padding: .35rem .65rem; font-size: .82rem; }
.btn-row { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
.link-btn:hover { text-decoration: underline; }

/* ── Cards / panels ── */
.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.3rem;
}
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.1rem; flex-wrap: wrap; gap: .6rem; }

.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.agent-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem; cursor: pointer; transition: border-color .15s, transform .1s, box-shadow .15s;
}
.agent-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow); }
.agent-card h3 { margin-bottom: .35rem; }
.agent-card .meta { font-size: .82rem; color: var(--text-faint); margin-top: .6rem; }

.empty {
  text-align: center; padding: 3rem 1rem; color: var(--text-dim);
  border: 1px dashed var(--border); border-radius: var(--radius); background: var(--bg-soft);
}

/* ── Badges ── */
.badge {
  display: inline-block; font-size: .72rem; font-weight: 700; padding: .15rem .5rem;
  border-radius: 99px; text-transform: uppercase; letter-spacing: .03em;
}
.badge.active { background: var(--green-soft); color: var(--green); }
.badge.paused { background: var(--amber-soft); color: var(--amber); }
.badge.block { background: var(--red-soft); color: var(--red); }
.badge.warn { background: var(--amber-soft); color: var(--amber); }
.badge.info { background: var(--accent-soft); color: var(--accent); }

/* ── Tables ── */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .6rem .7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-dim); font-weight: 700; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--panel-2); }
.table-wrap { overflow-x: auto; }

/* ── Tabs ── */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.4rem; overflow-x: auto; }
.tab {
  background: none; border: none; color: var(--text-dim); padding: .65rem .9rem;
  cursor: pointer; font: inherit; font-size: .92rem; border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--navy); border-bottom-color: var(--accent); font-weight: 600; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(18,24,32,.55); display: flex;
  align-items: flex-start; justify-content: center; padding: 4vh 1rem; z-index: 50; overflow-y: auto;
}
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  width: 100%; max-width: 560px; padding: 1.6rem; box-shadow: var(--shadow);
}
.modal.modal-sm { max-width: 440px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.modal-close { background: none; border: none; color: var(--text-dim); font-size: 1.4rem; cursor: pointer; line-height: 1; }

/* ── Misc ── */
.alert { padding: .7rem .85rem; border-radius: var(--radius-sm); font-size: .9rem; margin-bottom: 1rem; }
.alert.error { background: var(--red-soft); color: #8c241e; border: 1px solid rgba(184,50,42,.3); }
.alert.ok { background: var(--green-soft); color: #1f6342; border: 1px solid rgba(45,134,89,.3); }
.alert.info { background: var(--accent-soft); color: var(--accent-2); border: 1px solid rgba(74,109,130,.3); }

.keybox {
  font-family: var(--mono); font-size: .85rem; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .7rem; word-break: break-all; margin: .5rem 0;
}
.copy-row { display: flex; gap: .5rem; align-items: stretch; }
.copy-row .keybox { flex: 1; margin: 0; }

.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .7rem; margin-top: .4rem; }
.tpl-opt {
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .8rem; cursor: pointer;
  background: var(--panel); transition: border-color .15s;
}
.tpl-opt:hover { border-color: var(--accent); }
.tpl-opt.sel { border-color: var(--accent); background: var(--accent-soft); }
.tpl-opt .tpl-name { font-weight: 600; font-size: .92rem; }
.tpl-opt .tpl-meta { font-size: .78rem; color: var(--text-faint); margin-top: .3rem; }

.answer-box {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 1rem; white-space: pre-wrap; word-break: break-word; margin-top: .8rem;
}
.meta-pills { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .8rem; }
.pill {
  font-size: .78rem; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 99px; padding: .2rem .6rem; color: var(--text-dim);
}
.source-item {
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .6rem .75rem; margin-top: .5rem;
  background: var(--panel-2);
}
.source-item .q { font-weight: 600; }
.source-item .sim { font-size: .78rem; color: var(--green); }

.kv { display: grid; grid-template-columns: 160px 1fr; gap: .4rem .8rem; font-size: .9rem; }
.kv dt { color: var(--text-dim); }
.kv dd { margin: 0; word-break: break-word; }

.cell-trunc { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Chat (tab Probar) ── */
.chat-thread {
  display: flex; flex-direction: column; gap: .8rem;
  max-height: 460px; overflow-y: auto; padding: .2rem .2rem 1rem;
  margin-bottom: 1rem; border-bottom: 1px solid var(--border);
}
.chat-thread .empty { width: 100%; }
.chat-bubble { max-width: 85%; }
.chat-bubble.user { align-self: flex-end; }
.chat-bubble.assistant { align-self: flex-start; }
.chat-bubble.user .answer-box {
  margin-top: 0; background: var(--navy); color: var(--text-on-dark); border-color: var(--navy);
}
.chat-bubble.assistant .answer-box { margin-top: 0; }

/* ── Spinner ── */
.spinner-overlay { position: fixed; inset: 0; background: rgba(18,24,32,.30); display: flex; align-items: center; justify-content: center; z-index: 100; }
.spinner {
  width: 38px; height: 38px; border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toasts ── */
.toasts { position: fixed; top: 1rem; right: 1rem; z-index: 200; display: flex; flex-direction: column; gap: .5rem; max-width: 340px; }
.toast {
  background: var(--panel); border: 1px solid var(--border); border-left-width: 3px;
  border-radius: var(--radius-sm); padding: .7rem .9rem; font-size: .88rem; box-shadow: var(--shadow);
  animation: slidein .2s ease;
}
.toast.ok { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
.toast.info { border-left-color: var(--accent); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } }

@media (max-width: 640px) {
  .kv { grid-template-columns: 1fr; }
  .content { padding: 1.2rem 1rem 3rem; }
  .topbar { padding: .75rem 1rem; }
  .chat-bubble { max-width: 95%; }
}
