/* =========================================================================
   Nuevocentro · Backoffice — estilos a mano (plain CSS, sin CDN)
   Lenguaje visual tomado de aesthetic.png: violeta primario, menta, amarillo,
   tarjetas redondeadas con sombras suaves sobre fondo lavanda.
   ========================================================================= */

:root {
  /* Paleta */
  --violet:        #7B61FF;
  --violet-dark:   #6147d6;
  --violet-soft:   #ece8ff;
  --mint:          #34c9a3;
  --mint-soft:     #d8f5ec;
  --yellow:        #ffd23f;
  --pink-soft:     #ffe3ef;
  --blue-soft:     #e2efff;

  --bg:            #f5f3fb;
  --surface:       #ffffff;
  --ink:           #2e2a3f;
  --muted:         #8a8699;
  --line:          #ece9f3;

  --danger:        #e5484d;
  --danger-soft:   #fde8e8;
  --success:       #2b9d6e;
  --success-soft:  #ddf3e7;

  --radius:        18px;
  --radius-sm:     12px;
  --radius-lg:     26px;
  --shadow:        0 8px 28px rgba(91, 71, 188, 0.10);
  --shadow-sm:     0 2px 10px rgba(91, 71, 188, 0.08);

  --sidebar-w:     250px;
  --font:          system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
}

.hidden { display: none !important; }

/* ---------- App shell ---------- */
.app { min-height: 100vh; }

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 18px;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.3px;
}
.sidebar__logo {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--violet), var(--mint));
  display: grid; place-items: center;
  color: #fff; font-size: 18px;
}

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav__item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 14.5px;
  cursor: pointer;
  border: none; background: none; width: 100%; text-align: left;
  transition: background .15s ease, color .15s ease;
}
.nav__item:hover { background: var(--violet-soft); }
.nav__item.is-active { background: var(--violet); color: #fff; }
.nav__item.is-disabled {
  opacity: .45; cursor: not-allowed; pointer-events: none;
}
.nav__icon { width: 20px; text-align: center; }

.sidebar__user {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  display: flex; align-items: center; gap: 10px;
}
.sidebar__avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--mint-soft); color: var(--mint);
  display: grid; place-items: center; font-weight: 700;
}
.sidebar__user-meta { flex: 1; min-width: 0; }
.sidebar__user-name { font-weight: 700; font-size: 13.5px; }
.sidebar__user-role { color: var(--muted); font-size: 12px; }
.sidebar__logout {
  border: none; background: none; cursor: pointer;
  color: var(--muted); font-size: 18px; padding: 4px;
}
.sidebar__logout:hover { color: var(--danger); }

/* ---------- Main ---------- */
.main { padding: 30px 36px; overflow-x: hidden; }
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px;
}
.page-head h1 { margin: 0; font-size: 24px; letter-spacing: -0.5px; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 22px;
}
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
}
.kpi { display: flex; flex-direction: column; gap: 6px; }
.kpi__label { color: var(--muted); font-size: 13px; font-weight: 600; }
.kpi__value { font-size: 30px; font-weight: 800; letter-spacing: -1px; }
.kpi--violet { background: var(--violet-soft); }
.kpi--mint   { background: var(--mint-soft); }
.kpi--yellow { background: #fff6d6; }
.kpi--blue   { background: var(--blue-soft); }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: none; cursor: pointer;
  font-weight: 700; font-size: 14px; font-family: inherit;
  transition: transform .08s ease, filter .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn--primary   { background: var(--violet); color: #fff; }
.btn--primary:hover { filter: brightness(1.05); }
.btn--ghost     { background: var(--violet-soft); color: var(--violet-dark); }
.btn--danger    { background: var(--danger-soft); color: var(--danger); }
.btn--sm        { padding: 6px 12px; font-size: 13px; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
.data th, .data td {
  text-align: left; padding: 13px 14px; font-size: 14px;
  border-bottom: 1px solid var(--line);
}
.data th { color: var(--muted); font-weight: 700; font-size: 12.5px;
  text-transform: uppercase; letter-spacing: .4px; }
.data tr:last-child td { border-bottom: none; }
.data tbody tr:hover { background: var(--bg); }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700;
}
.badge--on  { background: var(--success-soft); color: var(--success); }
.badge--off { background: var(--danger-soft); color: var(--danger); }

.toolbar {
  display: flex; gap: 10px; align-items: center;
  margin-bottom: 16px; flex-wrap: wrap;
}
.toolbar input[type="text"], .toolbar select { max-width: 260px; }
.toolbar__spacer { flex: 1; }

.pager { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

/* ---------- Formularios ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; font-size: 13.5px; margin-bottom: 6px; }
input, select, textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-family: inherit; font-size: 14px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--violet);
  box-shadow: 0 0 0 3px var(--violet-soft);
}
textarea { resize: vertical; min-height: 120px; font-family: ui-monospace, monospace; }
.field__error { color: var(--danger); font-size: 12.5px; margin-top: 4px; }

/* Selector de imagen (formModal type:"image"): preview + input file + acciones. */
.imgpick { display: flex; gap: 14px; align-items: flex-start; }
.imgpick__preview {
  flex: 0 0 96px; width: 96px; height: 96px;
  border: 1px dashed var(--line); border-radius: var(--radius-sm);
  background: var(--bg); overflow: hidden;
  display: grid; place-items: center;
}
.imgpick__preview img { width: 100%; height: 100%; object-fit: contain; }
.imgpick__empty { color: var(--muted); font-size: 12px; text-align: center; padding: 0 8px; }
.imgpick__ctl { flex: 1; min-width: 0; }
.imgpick__ctl input[type="file"] { padding: 8px 10px; font-size: 13px; }
.imgpick__row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.imgpick__row .field__help { margin-top: 0; word-break: break-all; }
/* .btn fija display:inline-flex, que gana sobre el [hidden] del user-agent. */
.btn[hidden] { display: none; }

/* ---------- Estado vacío ---------- */
.empty {
  text-align: center; padding: 50px 20px; color: var(--muted);
}
.empty__icon { font-size: 40px; margin-bottom: 8px; }

/* ---------- Loader ---------- */
.loader {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(245, 243, 251, 0.6);
  display: grid; place-items: center;
}
.loader__spinner {
  width: 42px; height: 42px; border-radius: 50%;
  border: 4px solid var(--violet-soft); border-top-color: var(--violet);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed; bottom: 24px; right: 24px; z-index: 1100;
  display: flex; flex-direction: column; gap: 10px;
}
.toast {
  background: var(--surface); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); padding: 13px 18px;
  font-weight: 600; font-size: 14px; min-width: 240px;
  border-left: 4px solid var(--violet);
  animation: slidein .2s ease;
}
.toast--error   { border-left-color: var(--danger); }
.toast--success { border-left-color: var(--success); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 1050;
  background: rgba(46, 42, 63, 0.4);
  display: grid; place-items: center; padding: 20px;
}
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 26px;
  width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto;
}
.modal h2 { margin: 0 0 16px; font-size: 20px; }
.modal__actions {
  display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px;
}

/* ---------- QR descargable ---------- */
.qr-gen { text-align: center; }
.qr-gen__code { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.qr-gen__code strong { color: var(--text, inherit); }
.qr-gen__img {
  display: grid; place-items: center; padding: 12px;
  background: #fff; border-radius: var(--radius-lg); margin-bottom: 12px;
}
.qr-preview { width: 240px; height: 240px; image-rendering: pixelated; }

/* ---------- Login ---------- */
.login {
  min-height: 100vh; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--violet-soft), var(--mint-soft));
  padding: 20px;
}
.login__card {
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 38px 34px; width: 100%; max-width: 380px;
}
.login__brand {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  margin-bottom: 26px; text-align: center;
}
.login__logo {
  width: 56px; height: 56px; border-radius: 16px;
  background: linear-gradient(135deg, var(--violet), var(--mint));
  display: grid; place-items: center; color: #fff; font-size: 28px;
}
.login__brand h1 { margin: 0; font-size: 21px; }
.login__brand p { margin: 0; color: var(--muted); font-size: 13.5px; }
.login .btn { width: 100%; justify-content: center; margin-top: 8px; }

/* ---------- Placeholder de páginas (skeleton) ---------- */
.placeholder {
  border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 48px; text-align: center; color: var(--muted);
}
.placeholder__icon { font-size: 38px; margin-bottom: 10px; }
.placeholder code {
  background: var(--violet-soft); color: var(--violet-dark);
  padding: 2px 8px; border-radius: 6px; font-size: 13px;
}

/* ---------- Acciones en fila ---------- */
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Form helpers ---------- */
.field--check label {
  display: flex; align-items: center; gap: 8px;
  font-weight: 600; font-size: 14px; cursor: pointer;
}
.field--check input { width: auto; }
.field__help { color: var(--muted); font-size: 12.5px; margin-top: 5px; }

/* ---------- Detalle / JSON (auditoría, config) ---------- */
.json-view {
  background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 14px;
  font-family: ui-monospace, monospace; font-size: 12.5px;
  white-space: pre-wrap; word-break: break-word;
  max-height: 320px; overflow: auto; margin: 0;
}
.diff-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.diff-grid h3 { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
@media (max-width: 620px) { .diff-grid { grid-template-columns: 1fr; } }

.chip {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700;
  background: var(--violet-soft); color: var(--violet-dark);
}

.chips { display: flex; gap: 6px; flex-wrap: wrap; }

.muted { color: var(--muted); font-size: 13px; }

/* Herramientas a la derecha del título (buscador, selector de misión). */
.page-head__tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.page-head__tools .input,
.page-head__tools select { width: auto; min-width: 220px; max-width: 340px; }

/* Columnas de tabla con varias líneas (título + subtítulo + zona). */
.stack-xs { display: flex; flex-direction: column; gap: 3px; align-items: flex-start; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* Aviso contextual (misión inactiva / fuera de ventana). */
.notice {
  background: #fff6d6; border-left: 4px solid var(--yellow);
  border-radius: var(--radius-sm); padding: 12px 16px;
  font-size: 13.5px; font-weight: 600; margin-bottom: 16px;
}

/* Filas simples dentro de un modal (acciones de un objetivo). */
.list-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); margin-bottom: 8px;
}
.list-row__spacer { flex: 1; }

/* Lista de checkboxes (dependencias de desbloqueo). */
.checklist {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 8px 12px; max-height: 240px; overflow: auto;
}
.checklist__item {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 0; font-size: 14px; font-weight: 600; cursor: pointer;
}
.checklist__item input { width: auto; }

.badge--warn { background: #fff6d6; color: #8a6d00; }

/* ---------- Sección dashboard ---------- */
.section-title { margin: 28px 0 14px; font-size: 16px; font-weight: 800; }

/* Miniatura de asset en tabla + claves S3 largas sin romper el layout. */
.asset-thumb {
  display: grid; place-items: center;
  width: 44px; height: 44px; overflow: hidden;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg);
}
.asset-thumb img { width: 100%; height: 100%; object-fit: contain; }
.asset-thumb--none { color: var(--muted); font-size: 12px; font-family: ui-monospace, monospace; }
.mono-break { font-family: ui-monospace, monospace; font-size: 12.5px; word-break: break-all; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row;
    flex-wrap: wrap; align-items: center; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .main { padding: 20px; }
}

/* ---------- Analytics ---------- */
.section-help { margin: -8px 0 12px; }
.page-head--wrap { flex-wrap: wrap; gap: 12px 24px; }
.range-picker { display: flex; gap: 8px; align-items: center; flex-wrap: nowrap; }
.data .badge { white-space: nowrap; }
.input--date { width: auto; min-width: 0; max-width: 160px; }

/* Pestañas de reportes. */
.tabs {
  display: flex; gap: 6px; flex-wrap: wrap;
  background: var(--surface); padding: 6px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm); margin-bottom: 20px; width: fit-content; max-width: 100%;
}
.tabs__item {
  border: none; background: transparent; cursor: pointer; font: inherit;
  font-weight: 700; font-size: 14px; color: var(--muted);
  padding: 8px 14px; border-radius: 9px;
}
.tabs__item:hover { color: var(--ink); background: var(--bg); }
.tabs__item.is-active { background: var(--violet); color: #fff; }

/* Selector de dos opciones (progresión / misiones). */
.segmented {
  display: inline-flex; background: var(--violet-soft); border-radius: 10px; padding: 4px; gap: 4px;
  width: fit-content;
}
.segmented button {
  border: none; background: transparent; cursor: pointer; font: inherit;
  font-weight: 700; font-size: 13px; color: var(--violet-dark);
  padding: 6px 12px; border-radius: 7px;
}
.segmented button.is-active { background: var(--surface); box-shadow: var(--shadow-sm); }

/* Gráficos SVG (js/charts.js). */
.chart { display: flex; flex-direction: column; gap: 10px; }
.chart__svg { width: 100%; height: auto; display: block; }
.chart__grid { stroke: var(--line); stroke-width: 1; }
.chart__axis { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; font-weight: 600; color: var(--muted); }
.legend__item { display: inline-flex; align-items: center; gap: 6px; }
.legend__item i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.bars { display: flex; flex-direction: column; gap: 10px; }
.bars__row { display: grid; grid-template-columns: minmax(120px, 220px) 1fr auto; gap: 12px; align-items: center; }
.bars__label { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars__track { background: var(--bg); border-radius: 999px; height: 12px; overflow: hidden; }
.bars__fill { height: 100%; border-radius: 999px; min-width: 2px; }
.bars__value { font-size: 13.5px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Celda de retención: el fondo menta se intensifica con la tasa (--heat 0..1). */
.heat {
  display: inline-block; min-width: 64px; text-align: center;
  padding: 4px 10px; border-radius: 8px; font-weight: 700; font-variant-numeric: tabular-nums;
  background: color-mix(in srgb, var(--mint) calc(var(--heat) * 85% + 8%), var(--surface));
}

/* Dos columnas que colapsan a una en pantallas angostas (fricción: resultado / errores). */
.split { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 24px; }
.subhead { margin: 0 0 12px; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
