/* ============ Tokens (mismos colores que la app de chat) ============ */
:root {
  --bg: #ffffff;
  --bg-soft: #f9f9f9;
  --bg-hover: #ececec;
  --bg-active: #e8e8e8;
  --bg-input: #ffffff;
  --text: #0d0d0d;
  --text-2: #5d5d5d;
  --text-3: #8f8f8f;
  --border: #e5e5e5;
  --accent: #2f7cf6;
  --accent-bg: #e8f0fe;
  --accent-text: #1f6ae0;
  --ok-bg: #e6f4ea;
  --ok-text: #1e7e34;
  --warn-bg: #fef7e0;
  --warn-text: #8a5a00;
  --danger: #d93025;
  --danger-bg: #fdecea;
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #212121; --bg-soft: #181818; --bg-hover: #2a2a2a; --bg-active: #303030; --bg-input: #2a2a2a;
    --text: #ececec; --text-2: #b4b4b4; --text-3: #8a8a8a; --border: #3a3a3a;
    --accent-bg: #1c2b45; --accent-text: #8ab4f8; --ok-bg: #1d3524; --ok-text: #81c995;
    --warn-bg: #3a2f12; --warn-text: #fdd663; --danger-bg: #3b1f1d;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #212121; --bg-soft: #181818; --bg-hover: #2a2a2a; --bg-active: #303030; --bg-input: #2a2a2a;
  --text: #ececec; --text-2: #b4b4b4; --text-3: #8a8a8a; --border: #3a3a3a;
  --accent-bg: #1c2b45; --accent-text: #8ab4f8; --ok-bg: #1d3524; --ok-text: #81c995;
  --warn-bg: #3a2f12; --warn-text: #fdd663; --danger-bg: #3b1f1d;
  color-scheme: dark;
}

/* ============ Base ============ */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-text); }
h1 { margin: 0; font-size: 24px; font-weight: 600; letter-spacing: -.01em; }
code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.inline { display: inline; }

/* ============ Layout ============ */
.shell { display: flex; min-height: 100%; }
.nav {
  width: 232px; flex-shrink: 0; display: flex; flex-direction: column; gap: 8px;
  position: sticky; top: 0; height: 100vh;
  padding: 14px 8px 10px; background: var(--bg-soft); border-right: 1px solid var(--border);
}
.nav__brand { padding: 2px 10px 10px; font-size: 20px; font-weight: 700; color: var(--text); text-decoration: none; letter-spacing: -.01em; }
.nav__brand span { margin-left: 2px; font-size: 13px; font-weight: 600; color: var(--accent); vertical-align: middle; }
.nav__list { flex: 1; display: flex; flex-direction: column; gap: 1px; }
.nav__item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px;
  color: var(--text); text-decoration: none;
}
.nav__item:hover { background: var(--bg-hover); }
.nav__item.is-active { background: var(--bg-active); font-weight: 600; }
.nav svg { width: 20px; height: 20px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav__user { display: flex; align-items: center; gap: 6px; padding: 8px 4px 0 10px; border-top: 1px solid var(--border); }
.nav__user-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.nav__user-text strong { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav__user-text small { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { flex: 1; min-width: 0; }
.content { max-width: 1160px; margin: 0 auto; padding: 28px 28px 48px; }

.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-header p { margin: 4px 0 0; }
.back { display: inline-block; margin-bottom: 6px; font-size: 14px; color: var(--text-2); text-decoration: none; }
.back:hover { color: var(--text); }

/* ============ Botones ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font: inherit; font-size: 14px; font-weight: 500;
  white-space: nowrap; text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--bg-hover); }
.btn--primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn--primary:hover { background: var(--text); opacity: .85; }
.btn--danger { color: var(--danger); }
.btn--danger:hover { background: var(--danger-bg); border-color: var(--danger); }
.btn--sm { height: 30px; padding: 0 12px; font-size: 13px; }
.btn--block { width: 100%; height: 44px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px;
  border: 0; background: none; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

/* ============ Alertas e insignias ============ */
.alert { margin-bottom: 16px; padding: 10px 14px; border-radius: 10px; font-size: 14px; }
.alert--ok { background: var(--ok-bg); color: var(--ok-text); }
.alert--warn { background: var(--warn-bg); color: var(--warn-text); }
.alert--warn a { color: inherit; font-weight: 600; }
.alert--error { background: var(--danger-bg); color: var(--danger); }
.alert--error ul { margin: 0; padding-left: 18px; }
.validation-summary-valid { display: none; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 500; white-space: nowrap; }
.badge--ok { background: var(--ok-bg); color: var(--ok-text); }
.badge--off { background: var(--bg-hover); color: var(--text-2); }
.badge--accent { background: var(--accent-bg); color: var(--accent-text); }
.badge--error { background: var(--danger-bg); color: var(--danger); }
/* ============ Resumen ============ */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat {
  display: flex; flex-direction: column; gap: 2px; padding: 16px 18px;
  border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); text-decoration: none;
}
a.stat:hover { background: var(--bg-soft); }
.stat__value { font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat__label { font-size: 13px; color: var(--text-2); }
.stat--error .stat__value { color: var(--danger); }

/* ============ Filtros ============ */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
.filters select, .filters input, .field input, .field select {
  height: 38px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-input); color: var(--text); font: inherit; font-size: 14px; outline: none;
}
.field textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); resize: vertical;
  background: var(--bg-input); color: var(--text); font: inherit; font-size: 14px; font-weight: 400; line-height: 1.5; outline: none;
}
.filters select:focus, .filters input:focus, .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.filters__search { flex: 1; min-width: 220px; }
.filters__date { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text-2); }

/* ============ Tablas ============ */
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; font-weight: 500; font-size: 13px; color: var(--text-2); white-space: nowrap;
  padding: 10px 14px; background: var(--bg-soft); border-bottom: 1px solid var(--border);
}
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--bg-soft); }
.table__actions { width: 1%; white-space: nowrap; text-align: right; }
.table__actions > * + * { margin-left: 4px; }
.table__detail { max-width: 380px; overflow-wrap: anywhere; color: var(--text-2); }
.table__texto { max-width: 640px; white-space: pre-line; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.table__num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table__empty { padding: 28px 14px; text-align: center; color: var(--text-3); }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 12px; font-size: 14px; color: var(--text-2); }
.pager span { margin-right: auto; }

/* ============ Formularios ============ */
.card { border: 1px solid var(--border); border-radius: 16px; background: var(--bg); padding: 24px; }
.form { max-width: 720px; display: flex; flex-direction: column; gap: 16px; }
.section-title { margin: 28px 0 10px; font-size: 16px; font-weight: 600; }
.form__row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form__row--3 { grid-template-columns: repeat(3, 1fr); }
.form__actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 16px; border-top: 1px solid var(--border); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; font-size: 13px; font-weight: 500; color: var(--text-2); }
.field input, .field select { width: 100%; font-weight: 400; }
.field select:disabled { opacity: .6; }
.field small { font-weight: 400; color: var(--text-3); }
.field__error { font-weight: 400; color: var(--danger); }
.field__error:empty { display: none; }
.input-validation-error { border-color: var(--danger) !important; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ============ Gestores: agente ============ */
.agente { margin-top: 16px; }
.agente .section-title { margin: 0; }
.agente__estado { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; font-size: 14px; }
.agente__estado dt { color: var(--text-2); }
.agente__estado dd { margin: 0; }
.token pre { margin: 10px 0; padding: 12px; border-radius: 10px; background: var(--bg); color: var(--text); overflow-x: auto; font-size: 13px; }

/* ============ Login / error ============ */
body.simple { display: grid; place-items: center; min-height: 100%; padding: 24px 16px; background: var(--bg-soft); }
.card--login { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; padding: 32px 28px; border-radius: 20px; }
.card--login h1 { text-align: center; }
.card--login .muted { margin: -6px 0 6px; font-size: 14px; }
.card--login .field input { height: 44px; font-size: 15px; }
.card--center { max-width: 460px; display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
.login__logo {
  width: 44px; height: 44px; margin: 0 auto 4px; border-radius: 12px;
  display: grid; place-items: center; background: var(--text); color: var(--bg); font-weight: 700; font-size: 20px;
}

/* ============ Móvil ============ */
@media (max-width: 768px) {
  .shell { flex-direction: column; }
  .nav { width: auto; height: auto; position: static; flex-direction: row; align-items: center; gap: 4px; padding: 8px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .nav__brand, .nav__user-text { display: none; }
  .nav__list { flex-direction: row; gap: 2px; }
  .nav__item { white-space: nowrap; padding: 7px 10px; }
  .nav__user { border-top: 0; padding: 0; }
  .content { padding: 20px 16px 40px; }
  .page-header { flex-direction: column; align-items: stretch; }
  .form__row, .form__row--3 { grid-template-columns: 1fr; }
  .card { padding: 18px; }
}
