/* Paleta y tipografía importadas del prototipo editor-agente-n8n.html */
:root {
  --bg: #101418;
  --panel: #171d23;
  --panel2: #1d242c;
  --line: #2a333d;
  --text: #e8edf2;
  --muted: #8a98a6;
  --accent: #ffb45c;
  --accent-ink: #2a1c08;
  --ok: #5ad08a;
  --err: #ff7a7a;
  --warn: #ffd479;
  --info: #7ec8f3;
  --mono: 'SF Mono', ui-monospace, 'Cascadia Code', Consolas, monospace;
  --sans: 'Avenir Next', 'Segoe UI', system-ui, sans-serif;
  --radius: 10px;
  --radius-sm: 7px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 15px; line-height: 1.5; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { filter: brightness(1.15); }
code, pre, textarea, input, .mono { font-family: var(--mono); }

/* --- Topbar de navegación (siempre visible cuando hay sesión) --- */
.topbar { background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 60; }
.topbar-inner { max-width: 1080px; margin: 0 auto; padding: 0 20px; height: 52px; display: flex; align-items: center; gap: 18px; }
.brand { font-weight: 600; color: var(--text); letter-spacing: 0.2px; font-size: 14px; }
.brand:hover { color: var(--accent); }
.nav-links { display: flex; gap: 2px; flex: 1; }
.nav-link { padding: 6px 10px; border-radius: var(--radius-sm); color: var(--muted); font-size: 13px; }
.nav-link:hover { background: var(--panel2); color: var(--text); }
.nav-link.small { font-size: 12px; }
.user-box { display: flex; gap: 10px; align-items: center; color: var(--muted); font-size: 12px; }
.badge { background: rgba(255, 180, 92, 0.14); color: var(--accent); padding: 2px 8px; border-radius: 999px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }

/* --- Container general --- */
.wrap, .container { max-width: 1040px; margin: 0 auto; padding: 28px 20px 80px; }

header.top { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; border-bottom: 1px solid var(--line); padding-bottom: 18px; margin-bottom: 22px; }
header.top h1 { font-size: 21px; font-weight: 600; letter-spacing: 0.2px; }
header.top h1 span.dot { color: var(--accent); }
.status { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.status.ok { color: var(--ok); }
.status.err { color: var(--err); }

/* --- Card / form general --- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card.narrow { max-width: 520px; }
.card h1, .card h2 { font-size: 18px; font-weight: 600; margin-bottom: 12px; }

label.f, .field > span, .label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 0 0 14px; }
input[type=text], input[type=password], input[type=email], input[type=url], input[type=number], textarea, select {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm);
  color: var(--text); padding: 9px 11px; font-family: var(--mono); font-size: 13px;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; min-height: 60px; line-height: 1.55; }

/* --- Botones --- */
button, .btn {
  font-family: var(--sans); font-size: 13px; font-weight: 600; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text); border-radius: var(--radius-sm); padding: 9px 16px;
  cursor: pointer; text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { border-color: var(--accent); }
button.primary, .btn.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:hover, .btn.btn-primary:hover { filter: brightness(1.08); }
button.ghost, .btn.btn-ghost { background: transparent; color: var(--muted); padding: 6px 10px; font-weight: 500; }
button.ghost:hover { color: var(--text); border-color: var(--line); }
button.mode-on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button:disabled, .btn:disabled { opacity: 0.45; cursor: not-allowed; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-danger { background: transparent; color: var(--err); border-color: var(--err); }
.btn-danger:hover { background: rgba(255, 122, 122, 0.08); }
.btn-small { padding: 5px 10px; font-size: 12px; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* --- Login (mismo tema, centrado) --- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { margin: 0 0 4px; font-size: 18px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* --- Alerts inline --- */
.alert { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; border: 1px solid; }
.alert-error { background: rgba(255,122,122,0.08); border-color: var(--err); color: #ffd6d6; }
.alert-warn { background: rgba(255,212,121,0.08); border-color: var(--warn); color: #ffe2a8; }
.alert-success { background: rgba(90,208,138,0.08); border-color: var(--ok); color: #c0f1d0; }
.alert-info { background: rgba(126,200,243,0.08); border-color: var(--info); color: #c4e3f5; }

/* ============ EDITOR ============ */
.toolbar {
  position: sticky; top: 52px; z-index: 5; background: var(--bg); padding: 12px 0;
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--line); margin-bottom: 16px;
}
.tabs { display: flex; gap: 6px; }
.tabs button { padding: 7px 14px; }
.dirty-dot { display: none; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.dirty .dirty-dot { display: inline-block; }

details.sec {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  margin-bottom: 12px; overflow: hidden;
}
details.sec > summary {
  cursor: pointer; padding: 13px 16px; font-weight: 600; font-size: 14px; list-style: none;
  display: flex; align-items: center; gap: 10px; user-select: none;
}
details.sec > summary::before { content: '▸'; color: var(--accent); font-size: 12px; transition: transform .15s; }
details.sec[open] > summary::before { transform: rotate(90deg); }
details.sec > summary .count { font-family: var(--mono); font-size: 11px; color: var(--muted); font-weight: 400; }
details.sec > .body { padding: 4px 16px 16px; border-top: 1px solid var(--line); }
details.sub { border: 1px solid var(--line); border-radius: 8px; margin: 10px 0; background: var(--panel2); }
details.sub > summary { cursor: pointer; padding: 9px 12px; font-size: 13px; font-weight: 600; color: var(--text); list-style: none; }
details.sub > summary::before { content: '▸ '; color: var(--muted); font-size: 11px; }
details.sub[open] > summary::before { content: '▾ '; }
details.sub > .body { padding: 2px 12px 12px; }

.fld { margin: 12px 0; }
.fld > .k { font-family: var(--mono); font-size: 12px; color: var(--accent); margin-bottom: 5px; display: block; }
.arr-item { display: flex; gap: 8px; align-items: flex-start; margin: 7px 0; }
.arr-item textarea { flex: 1; }
.arr-item .ghost { flex: 0 0 auto; margin-top: 2px; }
.add-line { margin-top: 8px; }

/* JSON tab */
#rawTab { display: none; }
#rawJson { width: 100%; min-height: 480px; font-size: 12.5px; }
.raw-actions { display: flex; gap: 10px; margin-top: 10px; align-items: center; flex-wrap: wrap; }
.hint { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--panel2); border: 1px solid var(--line); border-left: 3px solid var(--ok);
  border-radius: 8px; padding: 12px 18px; font-size: 13px; display: none; max-width: 90vw; z-index: 100;
}
.toast.err { border-left-color: var(--err); }
.toast.warn { border-left-color: var(--warn); }
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toast-up .2s ease; }
  @keyframes toast-up { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
}

/* ============ Tablas (users / history / audit) ============ */
.data-table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.data-table th, .data-table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); }
.data-table th { background: var(--panel2); font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 500; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tr:hover td { background: rgba(255,255,255,0.02); }
.row-actions { display: flex; gap: 6px; }

/* Modal */
dialog.modal { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; min-width: 420px; max-width: 92vw; }
dialog.modal::backdrop { background: rgba(0,0,0,0.6); }
dialog.modal.large { width: 92vw; max-width: 900px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin: 14px 0 0; padding: 0; list-style: none; }
.preview { white-space: pre-wrap; word-break: break-word; max-height: 60vh; overflow: auto; background: var(--bg); padding: 12px; border-radius: var(--radius-sm); font-family: var(--mono); font-size: 12.5px; }

.page-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-header h1 { font-size: 21px; font-weight: 600; }
.page-actions { display: flex; gap: 8px; align-items: center; }
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0; color: var(--muted); }
.check input { width: auto; }
.row.actions { margin-top: 14px; }

/* code in inline */
kbd, .topbar code, p code { background: var(--panel2); padding: 1px 6px; border-radius: 4px; font-family: var(--mono); font-size: 12px; color: var(--accent); }
