/* ==========================================================================
   GestIA · Componentes base: botones, tarjetas, chips, avatares, formularios y barras de herramientas
   ========================================================================== */

/* Botones */
.btn {
  --h: 40px;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: var(--h);
  padding: 0 16px;
  border-radius: 12px;
  font-size: 13.5px;
  font-weight: 700;
  white-space: nowrap;
  user-select: none;
  transition: transform .18s var(--ease), box-shadow .2s var(--ease), background-color .2s, color .2s, border-color .2s, filter .2s;
}
.btn .i { width: 17px; height: 17px; }
.btn:active:not(:disabled) { transform: translateY(1px) scale(.98); }
.btn:disabled { opacity: .55; }
.btn-primary {
  color: #fff;
  background: var(--grad-brand);
  background-size: 170% 170%;
  background-position: 0% 50%;
  box-shadow: var(--shadow-blue), inset 0 1px 0 rgba(255, 255, 255, .22);
  transition: transform .18s var(--ease), box-shadow .2s var(--ease), background-position .5s var(--ease);
}
.btn-primary::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(110deg, transparent 25%, rgba(255, 255, 255, .38) 50%, transparent 75%);
  transform: translateX(-120%);
}
.btn-primary:hover:not(:disabled) { background-position: 100% 50%; transform: translateY(-1px); box-shadow: 0 16px 30px -12px rgba(47, 91, 234, .75); }
.btn-primary:hover:not(:disabled)::after { animation: sweep .9s var(--ease); }
.btn-secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); box-shadow: var(--shadow-xs); }
.btn-secondary:hover:not(:disabled) { border-color: var(--blue-200); color: var(--blue-700); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn-soft { background: var(--tone-soft, var(--blue-100)); color: var(--tone-ink, var(--blue-700)); }
.btn-soft:hover:not(:disabled) { filter: brightness(.96); transform: translateY(-1px); }
.btn-ghost { color: var(--ink-2); }
.btn-ghost:hover:not(:disabled) { background: var(--canvas); color: var(--ink); }
.btn-success { background: var(--green-500); color: #fff; box-shadow: 0 8px 18px -10px rgba(22, 168, 113, .85); }
.btn-success:hover:not(:disabled) { filter: brightness(1.06); transform: translateY(-1px); }
.btn-danger { background: #fde4e5; color: #b42330; }
.btn-danger:hover:not(:disabled) { background: #fbd0d2; transform: translateY(-1px); }
.btn-sm { --h: 32px; padding: 0 12px; border-radius: 10px; font-size: 12.5px; gap: 6px; }
.btn-sm .i { width: 15px; height: 15px; }
.btn-lg { --h: 48px; padding: 0 22px; border-radius: 14px; font-size: 14.5px; }
.btn-block { width: 100%; }
.btn-icon {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 11px;
  color: var(--ink-2);
  transition: background .2s, color .2s, transform .2s var(--ease);
}
.btn-icon:hover:not(:disabled) { background: var(--canvas); color: var(--ink); }
.btn-icon:disabled { opacity: .4; }
.spinner {
  width: 16px;
  height: 16px;
  flex: none;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: spin .7s linear infinite;
}

/* Tarjetas */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.card-pad { padding: 20px 22px 22px; }
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 22px 0;
}
.card-head h3 { font-size: 16px; font-weight: 750; }
.card-head p { color: var(--ink-3); font-size: 13px; margin-top: 2px; }
.card-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.card-foot { padding: 12px 22px 16px; border-top: 1px solid var(--line-soft); }
.icon-tile {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 12px;
  background: var(--tone-soft, var(--blue-100));
  color: var(--tone-ink, var(--blue-700));
}
.icon-tile .i { width: 20px; height: 20px; }
.link-btn { display: inline-flex; align-items: center; gap: 6px; color: var(--blue-600); font-weight: 700; font-size: 13px; }
.link-btn .i { width: 15px; height: 15px; transition: transform .2s var(--ease); }
.link-btn:hover { color: var(--blue-700); }
.link-btn:hover .i { transform: translateX(3px); }

/* Encabezado de página */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head h2 { font-size: clamp(22px, 2.2vw, 28px); font-weight: 800; letter-spacing: -.03em; }
.page-head p { margin-top: 4px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.stack { display: grid; gap: 22px; }

/* Chips y estados */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
  background: var(--tone-soft, var(--canvas));
  color: var(--tone-ink, var(--ink-2));
}
.chip .i { width: 14px; height: 14px; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 10px 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  background: var(--tone-soft);
  color: var(--tone-ink);
}
.badge .i { width: 13px; height: 13px; stroke-width: 2.6; }
.badge.tone-amber .i { animation: flip 3s ease-in-out infinite; }
.demo-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 12px;
  border-radius: 99px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 650;
  color: var(--ink-2);
  white-space: nowrap;
}
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green-500); flex: none; }

/* Avatares y banderas */
.avatar {
  --s: 38px;
  width: var(--s);
  height: var(--s);
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  font-size: calc(var(--s) * .36);
  font-weight: 750;
  letter-spacing: .02em;
  background: linear-gradient(135deg, var(--a1, #4f77f6), var(--a2, #7c5cfa));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .2);
}
.avatar-sm { --s: 30px; }
.avatar-lg { --s: 48px; }
.avatar-xl { --s: 68px; }
.flag {
  display: inline-block;
  flex: none;
  width: 18px;
  height: 12px;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(14, 22, 51, .12);
  vertical-align: -1px;
}
.flag-pe { background: linear-gradient(90deg, #d91023 0 33.33%, #fff 33.33% 66.66%, #d91023 66.66%); }
.flag-ec { background: linear-gradient(180deg, #ffd100 0 50%, #034ea2 50% 75%, #ef3340 75%); }
.flag-lg { width: 26px; height: 18px; border-radius: 4px; }

/* Formularios */
.field { display: grid; gap: 7px; font-size: 12.5px; font-weight: 650; color: var(--ink-2); min-width: 0; }
.field em { font-style: normal; font-weight: 500; color: var(--ink-4); }
.field small { font-weight: 500; font-size: 11.5px; line-height: 1.4; color: var(--ink-3); }
.field > span small { color: var(--ink-4); }
.input {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  outline: none;
  transition: border-color .2s, box-shadow .2s, background-color .2s;
}
.input::placeholder { color: var(--ink-4); }
.input:hover:not(:disabled) { border-color: #cdd4e4; }
.input:focus { border-color: var(--blue-500); box-shadow: 0 0 0 4px rgba(47, 91, 234, .14); }
.input:disabled { background: var(--surface-2); color: var(--ink-3); }
select.input {
  appearance: none;
  padding-right: 38px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236f7894' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
textarea.input { height: auto; min-height: 92px; padding: 11px 14px; resize: vertical; line-height: 1.5; }
input[type="date"].input { padding-right: 10px; }
.control { position: relative; display: flex; align-items: center; min-width: 0; }
.control > .i { position: absolute; left: 13px; color: var(--ink-4); pointer-events: none; transition: color .2s; }
.control.has-icon > .input { padding-left: 40px; }
.control:focus-within > .i { color: var(--blue-600); }
.control-btn {
  position: absolute;
  right: 5px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  color: var(--ink-3);
}
.control-btn:hover { background: var(--canvas); color: var(--ink); }
.form-error { min-height: 0; font-size: 13px; font-weight: 600; color: #b42330; }
.form-error:not(:empty) { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-radius: 12px; background: #fde4e5; animation: pop .3s var(--spring); }

/* Control segmentado */
.seg {
  display: inline-flex;
  gap: 2px;
  padding: 4px;
  max-width: 100%;
  overflow-x: auto;
  border-radius: 13px;
  background: var(--canvas);
  border: 1px solid var(--line-soft);
  scrollbar-width: none;
}
.seg button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 12px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 650;
  color: var(--ink-3);
  white-space: nowrap;
  transition: background .2s, color .2s, box-shadow .2s;
}
.seg button:hover { color: var(--ink); }
.seg button.active { background: #fff; color: var(--ink); box-shadow: var(--shadow-sm); }
.seg .count {
  display: grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 99px;
  background: var(--line-soft);
  font-size: 11px;
  font-weight: 750;
}
.seg button.active .count { background: var(--tone-soft, var(--blue-100)); color: var(--tone-ink, var(--blue-700)); }

/* Barra de herramientas */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line-soft); }
.toolbar .control { flex: 1 1 240px; }
.toolbar select.input { width: auto; flex: 0 1 200px; }
