/* ============================================================================
   PMBOT — Design tokens (derivados de IA SOLUTIONS)
   ============================================================================
   Paleta tomada del logo corporativo:
     · Cian eléctrico   #00d0f8  (acentos, foco)
     · Azul marino      #182878  (tipografía / fondos serios)
     · Azul noche       #081848  (sombra)
     · Azul intermedio  #1860a8  (brillos)
   Fuente: Inter.
   ========================================================================== */

:root {
  /* Marca: azul marino */
  --navy-50: #eef1fc;
  --navy-100: #d6ddf7;
  --navy-200: #adb9ee;
  --navy-300: #8291e0;
  --navy-400: #5566cc;
  --navy-500: #3a49b0;
  --navy-600: #2a3694;
  --navy-700: #212b82;
  --navy-800: #182878;
  --navy-900: #101c56;
  --navy-950: #081848;

  /* Marca: cian eléctrico */
  --brand-50: #e8fdff;
  --brand-100: #c4f7fe;
  --brand-200: #8feefd;
  --brand-300: #52e3fb;
  --brand-400: #1dd8fa;
  --brand-500: #00d0f8;
  --brand-600: #00a7cd;
  --brand-700: #0083a3;

  /* Marca: azul acción */
  --action-300: #6fa8f8;
  --action-400: #3d84ee;
  --action-500: #1860a8;
  --action-600: #14507f;

  --slate-line: #dbe1f0;
  --slate-50: #f8fafc;

  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;

  --gradient-brand: linear-gradient(135deg, #00d0f8 0%, #1860a8 60%, #182878 100%);
  --gradient-brand-soft: linear-gradient(135deg, #e8fdff 0%, #eef1fc 100%);
  --gradient-navy: linear-gradient(155deg, #081848 0%, #182878 55%, #1860a8 100%);
  --gradient-accent-bar: linear-gradient(90deg, #00d0f8 0%, #1860a8 55%, #182878 100%);
  --gradient-text: linear-gradient(135deg, #00a7cd 0%, #182878 100%);

  --shadow-panel: 0 24px 60px -24px rgba(8, 24, 72, 0.38);
  --radius-card: 1rem;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  font-family: var(--font-sans);
  color: var(--navy-900);
  background: var(--slate-50);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, textarea { font-family: inherit; }

.gradient-text {
  background-image: var(--gradient-text);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.accent-bar { background-image: var(--gradient-accent-bar); }

:where(a, button, input, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 2px;
}

/* Marca */
.brand-logo { object-fit: contain; }
.wordmark { font-weight: 800; letter-spacing: -0.02em; }
.wordmark--dark { color: var(--navy-800); }
.wordmark--light { color: #fff; }

@keyframes pm-fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.animate-fade-up { animation: pm-fade-up 420ms cubic-bezier(0.22, 1, 0.36, 1) both; }

@keyframes pm-spin { to { transform: rotate(360deg); } }
.animate-spin { animation: pm-spin 700ms linear infinite; }

.spinner {
  display: inline-block; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff;
  animation: pm-spin 0.7s linear infinite;
}
.spinner--dark { border-color: rgba(24,40,120,0.25); border-top-color: var(--navy-800); }

/* ============================================================================
   LOGIN
   ========================================================================== */
.login { display: flex; min-height: 100dvh; }

.login__brand {
  position: relative; display: none; overflow: hidden;
  width: 46%; flex-shrink: 0;
}
@media (min-width: 1024px) { .login__brand { display: flex; } }

.login__brand-bg { position: absolute; inset: 0; background-image: var(--gradient-navy); }

.login__brand .orb {
  position: absolute; border-radius: 50%; filter: blur(64px);
  background: rgba(0, 208, 248, 0.20);
}
.login__brand .orb--1 { left: -6rem; top: -6rem; width: 24rem; height: 24rem; }
.login__brand .orb--2 {
  right: -4rem; bottom: -8rem; width: 28rem; height: 28rem;
  background: rgba(61, 132, 238, 0.20);
}
.login__brand .bar {
  position: absolute; right: 4rem; border-radius: 999px; transform: rotate(35deg);
  background: rgba(0, 208, 248, 0.30);
}
.login__brand .bar--1 { top: 33%; height: 10rem; width: 2.5rem; }
.login__brand .bar--2 { top: 50%; right: 9rem; height: 6rem; width: 2.5rem; background: rgba(29, 216, 250, 0.20); }

.login__brand-inner {
  position: relative; z-index: 1; display: flex; flex-direction: column;
  justify-content: space-between; width: 100%; padding: 3rem 4rem;
}

.login__brand-top { display: flex; align-items: center; gap: 0.75rem; }
.login__brand-top .brand-logo { width: 44px; height: 44px; }
.login__brand-top .wordmark { font-size: 1.125rem; }

.login__brand-mid { max-width: 28rem; }
.login__brand-mid h1 {
  margin: 0; font-size: 2.5rem; font-weight: 800; line-height: 1.1; color: #fff;
}
.login__brand-mid h1 span { display: block; color: var(--brand-400); }
.login__brand-mid p {
  margin-top: 1.5rem; font-size: 1rem; line-height: 1.6; color: var(--navy-100);
}
.login__brand-mid ul { list-style: none; margin: 2.5rem 0 0; padding: 0; }
.login__brand-mid li {
  display: flex; align-items: center; gap: 0.75rem;
  margin-top: 0.75rem; font-size: 0.875rem; color: var(--navy-100);
}
.login__brand-mid li::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--brand-400);
  flex-shrink: 0;
}

.login__brand-foot { display: flex; align-items: center; gap: 0.5rem; font-size: 0.75rem; color: var(--navy-200); }
.login__brand-foot svg { width: 16px; height: 16px; }

.login__form-side {
  flex: 1; display: flex; align-items: center; justify-content: center;
  background: var(--slate-50); padding: 2.5rem 1.25rem;
}
.login__form-wrap { width: 100%; max-width: 26rem; }

.login__mobile-brand { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 2rem; }
.login__mobile-brand .brand-logo { width: 40px; height: 40px; }
@media (min-width: 1024px) { .login__mobile-brand { display: none; } }

.login__form-wrap > .accent-bar {
  display: block; height: 4px; width: 3.5rem; border-radius: 999px; margin-bottom: 1.25rem;
}
.login__form-wrap h2 {
  margin: 0; font-size: 1.875rem; font-weight: 700; letter-spacing: -0.02em; color: var(--navy-900);
}
.login__form-wrap .subtitle { margin-top: 0.5rem; font-size: 0.875rem; color: var(--navy-400); }

.login-error {
  display: flex; align-items: flex-start; gap: 0.75rem;
  border: 1px solid #fecaca; background: #fef2f2; color: #b91c1c;
  border-radius: 0.75rem; padding: 0.75rem 1rem; font-size: 0.875rem;
  margin-bottom: 1.25rem;
}
.login-error[hidden] { display: none; }

.field { margin-bottom: 1.25rem; }
.field label {
  display: block; font-size: 0.875rem; font-weight: 600; color: var(--navy-800); margin-bottom: 0.375rem;
}
.field .control { position: relative; }
.field .control > svg {
  position: absolute; left: 0.875rem; top: 50%; transform: translateY(-50%);
  width: 20px; height: 20px; color: var(--navy-300); pointer-events: none;
}
.field input {
  width: 100%; border: 1px solid var(--slate-line); background: #fff; color: var(--navy-900);
  border-radius: 0.75rem; padding: 0.75rem 2.75rem 0.75rem 2.75rem; font-size: 15px;
  box-shadow: 0 1px 2px rgba(8,24,72,0.04); outline: none;
}
.field input::placeholder { color: var(--navy-200); }
.field input:focus { border-color: var(--brand-500); box-shadow: 0 0 0 4px rgba(0,208,248,0.2); }
.field .toggle-eye {
  position: absolute; right: 0.5rem; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; padding: 0.5rem; color: var(--navy-300);
  border-radius: 0.5rem;
}
.field .toggle-eye:hover { color: var(--navy-700); background: var(--slate-50); }
.field .toggle-eye svg { width: 20px; height: 20px; }

.btn-login {
  position: relative; display: flex; width: 100%; align-items: center; justify-content: center;
  gap: 0.5rem; border: none; border-radius: 0.75rem; cursor: pointer;
  background-image: var(--gradient-brand); color: #fff;
  padding: 0.875rem 1.25rem; font-size: 15px; font-weight: 600;
  box-shadow: 0 10px 20px -8px rgba(16, 28, 86, 0.35);
  transition: filter 0.15s;
}
.btn-login:hover { filter: brightness(1.1); }
.btn-login:disabled { opacity: 0.6; cursor: default; filter: none; }

.login__form-wrap .footnote {
  margin-top: 1rem; text-align: center; font-size: 0.75rem; line-height: 1.5; color: var(--navy-300);
}
.login__form-wrap .login-footer {
  margin-top: 2.5rem; border-top: 1px solid var(--slate-line); padding-top: 1.25rem;
  text-align: center; font-size: 0.75rem; color: var(--navy-300);
}

/* ============================================================================
   CHAT (panel)
   ========================================================================== */
.app { display: grid; grid-template-columns: 256px 1fr; height: 100dvh; }

/* --- Sidebar --- */
.sidebar {
  display: flex; flex-direction: column; overflow: hidden;
  background-image: var(--gradient-navy); color: #fff;
}
.sidebar__brand { display: flex; align-items: center; gap: 0.75rem; padding: 1.5rem 1.25rem 0.5rem; }
.sidebar__brand .brand-logo { width: 40px; height: 40px; flex-shrink: 0; }
.sidebar__brand .wordmark { font-size: 0.9rem; line-height: 1.1; }
.sidebar__brand .wordmark small {
  display: block; font-weight: 600; font-size: 0.72rem; color: var(--brand-200); letter-spacing: 0.02em;
}

.sidebar__nav { flex: 1; overflow-y: auto; padding: 1rem 0.75rem; }
.sidebar__nav a, .sidebar__nav button {
  position: relative; display: flex; align-items: center; gap: 0.75rem; width: 100%;
  border: none; background: none; cursor: pointer; color: var(--navy-200);
  border-radius: 0.75rem; padding: 0.65rem 0.75rem; font-size: 0.875rem; font-weight: 600;
  text-align: left; text-decoration: none; transition: 0.15s;
}
.sidebar__nav a:hover, .sidebar__nav button:hover { background: rgba(255,255,255,0.05); color: #fff; }
.sidebar__nav a.active { background: rgba(255,255,255,0.10); color: #fff; }
.sidebar__nav a.active::before {
  content: ""; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  height: 1.5rem; width: 4px; border-radius: 999px; background: var(--brand-400);
}
.sidebar__nav svg { width: 20px; height: 20px; flex-shrink: 0; }

.sidebar__footer {
  border-top: 1px solid rgba(255,255,255,0.10); padding: 1rem 1.25rem;
}
.sidebar__footer .user { display: flex; align-items: center; gap: 0.75rem; }
.sidebar__footer .avatar {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  background-image: var(--gradient-brand); font-size: 0.75rem; font-weight: 700; color: #fff;
}
.sidebar__footer .user-name { display: block; font-size: 0.875rem; font-weight: 600; color: #fff; }
.sidebar__footer .user-role { display: block; font-size: 0.72rem; color: var(--brand-200); }
.sidebar__footer .note { margin-top: 0.75rem; font-size: 0.7rem; color: var(--navy-200); line-height: 1.5; }

/* --- Main --- */
.main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; background: var(--slate-50); }

/* Cabecera con efecto glass */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.9rem 1.5rem; gap: 1rem;
  background: rgba(255, 255, 255, 0.85);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--slate-line);
}
.topbar h2 { margin: 0; font-size: 1.05rem; font-weight: 700; color: var(--navy-900); }
.topbar p { margin: 2px 0 0; font-size: 0.78rem; color: var(--navy-400); }
.topbar .accent-line { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background-image: var(--gradient-accent-bar); }

.btn { border: none; border-radius: 0.75rem; padding: 0.65rem 1rem; font-size: 0.875rem; font-weight: 600; cursor: pointer; transition: 0.15s; }
.btn--ghost { background: transparent; color: var(--navy-700); border: 1px solid var(--slate-line); }
.btn--ghost:hover { background: var(--navy-50); }
.btn--primary { background-image: var(--gradient-brand); color: #fff; box-shadow: 0 8px 18px -8px rgba(16,28,86,0.4); }
.btn--primary:hover { filter: brightness(1.08); }
.btn--primary:disabled { opacity: 0.6; cursor: default; }

.chat { flex: 1; overflow-y: auto; padding: 1.5rem; }

.welcome { max-width: 640px; margin: 60px auto 0; text-align: center; }
.welcome__icon { font-size: 40px; }
.welcome h3 { font-size: 22px; margin: 10px 0 4px; color: var(--navy-900); }
.welcome p { color: var(--navy-400); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.chip {
  border: 1px solid var(--slate-line); background: #fff; color: var(--navy-800);
  border-radius: 20px; padding: 8px 14px; cursor: pointer; font-size: 13px; transition: 0.15s;
}
.chip:hover { border-color: var(--brand-500); color: var(--brand-600); }

/* Mensajes */
.msg { display: flex; gap: 10px; margin-bottom: 18px; max-width: 900px; }
.msg--user { flex-direction: row-reverse; margin-left: auto; }
.msg__avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  font-size: 15px; flex-shrink: 0;
}
.msg--user .msg__avatar { background-image: var(--gradient-brand); color: #fff; }
.msg--bot .msg__avatar { background-image: var(--gradient-navy); color: #fff; }
.msg__bubble {
  background: #fff; border: 1px solid var(--slate-line); border-radius: var(--radius-card);
  padding: 12px 16px; box-shadow: 0 1px 3px rgba(8,24,72,0.06); min-width: 0; max-width: 100%;
}
.msg--user .msg__bubble { background-image: var(--gradient-navy); color: #fff; border-color: transparent; }
.msg__bubble .answer { font-size: 14.5px; line-height: 1.55; }
.msg__bubble .answer.status { color: var(--navy-400); display: flex; align-items: center; gap: 8px; }
.msg__bubble .answer p { margin: 0 0 8px; }
.msg__bubble .answer p:last-child { margin-bottom: 0; }
.msg__bubble .answer ul, .msg__bubble .answer ol { margin: 6px 0; padding-left: 20px; }
.msg__bubble .answer code { background: rgba(24,40,120,0.06); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.msg--user .answer code { background: rgba(255,255,255,0.2); }
.msg__bubble .answer strong { font-weight: 700; }

/* Bloques */
.block { margin-top: 12px; }
.block__title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--navy-400); margin: 0 0 6px; font-weight: 700; }
.block--text { font-size: 14.5px; line-height: 1.55; }

.table-wrap { overflow-x: auto; border: 1px solid var(--slate-line); border-radius: 8px; }
table.data { border-collapse: collapse; width: 100%; font-size: 13.5px; background: #fff; }
table.data th, table.data td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--slate-line); white-space: nowrap; }
table.data th { background: var(--navy-800); color: #fff; font-weight: 600; }
table.data tbody tr:nth-child(even) { background: var(--navy-50); }
table.data tr:last-child td { border-bottom: none; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.kpi-card { background: #fff; border: 1px solid var(--slate-line); border-radius: 10px; padding: 14px 12px; text-align: center; box-shadow: 0 1px 3px rgba(8,24,72,0.05); }
.kpi-card__value { font-size: 24px; font-weight: 800; color: var(--navy-800); }
.kpi-card__label { font-size: 12px; color: var(--navy-400); margin-top: 4px; }

.chart-wrap {
  background: #fff; border: 1px solid var(--slate-line); border-radius: 10px;
  padding: 14px; box-shadow: 0 1px 3px rgba(8,24,72,0.05); position: relative; height: 320px;
}

.report-btn {
  display: inline-flex; align-items: center; gap: 8px; text-decoration: none;
  background-image: var(--gradient-brand); color: #fff; border-radius: 8px;
  padding: 10px 16px; font-size: 14px; font-weight: 600;
}
.report-btn:hover { filter: brightness(1.05); }

/* Composer */
.composer { padding: 0.75rem 1.5rem 0.5rem; background: var(--slate-50); }
.composer form {
  display: flex; gap: 10px; align-items: flex-end;
  background: rgba(255,255,255,0.9); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border: 1px solid var(--slate-line); border-radius: 14px; padding: 8px;
  box-shadow: 0 4px 16px -8px rgba(8,24,72,0.12);
}
.composer textarea {
  flex: 1; resize: none; border: none; background: transparent; padding: 8px 6px;
  font-size: 14.5px; line-height: 1.4; max-height: 160px; outline: none; color: var(--navy-900);
}
.composer .btn--primary { border-radius: 10px; padding: 0.7rem 1.1rem; }
.muted { color: var(--navy-400); }
.small { font-size: 11.5px; }
.composer .hint { margin: 6px 4px 0; font-size: 11px; color: var(--navy-300); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ============================================================================
   CONFIG / PROGRAMACIÓN
   ========================================================================== */
.settings { flex: 1; overflow-y: auto; padding: 1.5rem; }
.settings h2.page-title { margin: 0 0 1rem; font-size: 1.25rem; font-weight: 800; color: var(--navy-900); }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 1rem; }
.card {
  background: #fff; border: 1px solid var(--slate-line); border-radius: 1rem;
  padding: 1.25rem; box-shadow: 0 1px 3px rgba(8,24,72,0.05);
  display: flex; flex-direction: column; align-self: start;
}
.card h3 { margin: 0 0 0.75rem; font-size: 1rem; font-weight: 700; color: var(--navy-900); }
.card .sub { font-size: 0.78rem; color: var(--navy-400); margin: -0.5rem 0 0.75rem; }

.form-row { display: flex; gap: 0.5rem; margin-bottom: 0.6rem; }
.form-row input, .form-row select, .form-row textarea {
  flex: 1; min-width: 0; border: 1px solid var(--slate-line); border-radius: 0.6rem;
  padding: 0.55rem 0.7rem; font-size: 0.875rem; color: var(--navy-900); outline: none;
  background: #fff;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
  border-color: var(--brand-500); box-shadow: 0 0 0 3px rgba(0,208,248,0.15);
}
.form-row label { align-self: center; font-size: 0.8rem; font-weight: 600; color: var(--navy-700); white-space: nowrap; }

.chk-list { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.6rem; }
.chk-list label {
  display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.8rem;
  background: var(--navy-50); border: 1px solid var(--slate-line); border-radius: 999px;
  padding: 0.3rem 0.6rem; cursor: pointer;
}

.item-list { list-style: none; margin: 0.5rem 0 0; padding: 0; }
.item-list li {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0;
  border-top: 1px solid var(--slate-line); font-size: 0.84rem;
}
.item-list li:first-child { border-top: none; }
.item-list .item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.1rem; }
.item-list .item-title { display: block; font-weight: 600; color: var(--navy-900); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-list .item-sub { display: block; font-size: 0.72rem; color: var(--navy-400); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-list .item-title-row { display: flex; align-items: center; gap: 0.4rem; min-width: 0; }
.item-list .item-title-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; color: var(--navy-900); }
.item-list .item-title-row .pill { flex-shrink: 0; }
.item-list button {
  flex-shrink: 0; white-space: nowrap;
  border: none; background: none; cursor: pointer; color: var(--navy-400);
  border-radius: 0.5rem; padding: 0.3rem 0.5rem; font-size: 0.8rem; font-weight: 600;
}
.item-list button:hover { background: var(--navy-50); color: var(--navy-800); }
.item-list button.danger:hover { background: #fef2f2; color: #b91c1c; }

.pill { display: inline-block; font-size: 0.68rem; font-weight: 600; border-radius: 999px; padding: 0.15rem 0.55rem; }
.pill--pendiente { background: #fef3c7; color: #92400e; }
.pill--en_progreso { background: #dbeafe; color: #1d4ed8; }
.pill--completada { background: #dcfce7; color: #15803d; }
.pill--ok { background: #dcfce7; color: #15803d; }
.pill--error, .pill--sin_smtp { background: #fef2f2; color: #b91c1c; }

.section-full { grid-column: 1 / -1; }

.toast {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 50;
  background: var(--navy-900); color: #fff; border-radius: 0.75rem;
  padding: 0.7rem 1rem; font-size: 0.85rem; box-shadow: var(--shadow-panel);
  opacity: 0; transform: translateY(8px); transition: 0.25s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #b91c1c; }
