/* EstoyAki · Atención Inteligente — Fase 4.1
   Paleta: azul noche, azul acero, cian, plata y blanco. Sin dependencias externas. */

:root {
  --night: #0b1a33;
  --night-2: #102449;
  --steel: #3d5a80;
  --steel-2: #5b7aa6;
  --cyan: #06b6d4;
  --cyan-2: #22d3ee;
  --silver: #c9d3e0;
  --white: #ffffff;

  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-alt: #eef3f9;
  --surface-sunk: #e6edf6;
  --text: #0b1a33;
  --muted: #5a6b84;
  --border: #d7e0ec;
  --primary: #12305f;
  --primary-hover: #0b1a33;
  --accent: #0891b2;
  --accent-soft: rgba(6, 182, 212, 0.12);
  --steel-soft: rgba(61, 90, 128, 0.1);
  --success: #0f9d74;
  --success-soft: rgba(15, 157, 116, 0.12);
  --warn: #b7791f;
  --warn-soft: rgba(183, 121, 31, 0.14);
  --danger: #c0352b;
  --danger-soft: rgba(192, 53, 43, 0.1);
  --focus: 0 0 0 3px rgba(6, 182, 212, 0.35);
  --shadow-sm: 0 1px 2px rgba(11, 26, 51, 0.06);
  --shadow: 0 1px 2px rgba(11, 26, 51, 0.05), 0 8px 24px rgba(11, 26, 51, 0.06);
  --shadow-lg: 0 24px 60px rgba(11, 26, 51, 0.18);
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #070f1f;
  --surface: #0d1a31;
  --surface-alt: #12233f;
  --surface-sunk: #0a1528;
  --text: #e8eef7;
  --muted: #93a4bd;
  --border: #1d3152;
  --primary: #22d3ee;
  --primary-hover: #67e8f9;
  --accent: #22d3ee;
  --accent-soft: rgba(34, 211, 238, 0.14);
  --steel-soft: rgba(91, 122, 166, 0.18);
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.14);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4 {
  margin: 0;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

h3 { font-size: 1.02rem; font-weight: 650; }
h4 { font-size: 0.95rem; font-weight: 650; margin-bottom: 8px; }

p { margin: 0; }

code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--surface-alt);
  padding: 1px 6px;
  border-radius: 6px;
}

.hidden { display: none !important; }

.muted-text { color: var(--muted); font-size: 0.9rem; }

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

/* ---------- Marca ---------- */
.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  display: block;
  height: 40px;
  width: auto;
  max-width: 200px;
}

.brand-lockup.compact .brand-logo { height: 34px; max-width: 170px; }

.brand-text { display: flex; flex-direction: column; }

.brand-title {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.brand-sub {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

/* ---------- Pantalla de acceso ---------- */
.auth-wrapper {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
}

.auth-hero {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 32px;
  padding: 48px clamp(28px, 5vw, 72px);
  color: #e8eef7;
  background:
    radial-gradient(900px 500px at 85% 15%, rgba(34, 211, 238, 0.18), transparent 60%),
    radial-gradient(700px 500px at 10% 90%, rgba(91, 122, 166, 0.35), transparent 60%),
    linear-gradient(160deg, #0b1a33 0%, #102449 55%, #0b1a33 100%);
}

.auth-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(201, 211, 224, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(201, 211, 224, 0.06) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(180deg, transparent, #000 30%, #000 70%, transparent);
  pointer-events: none;
}

.auth-hero > * { position: relative; z-index: 1; }

.auth-hero .brand-sub { color: #a9b8cf; }

.hero-copy h1 {
  font-size: clamp(1.8rem, 3vw, 2.5rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  max-width: 16ch;
}

.hero-copy h1 span { color: var(--cyan-2); }

.hero-copy p {
  margin-top: 14px;
  color: #b8c6da;
  max-width: 46ch;
  font-size: 1rem;
}

.hero-points {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 14px;
}

.hero-points li {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #d5deeb;
  font-size: 0.94rem;
}

.hero-points .icon-chip {
  background: rgba(34, 211, 238, 0.12);
  color: var(--cyan-2);
  border: 1px solid rgba(34, 211, 238, 0.25);
}

.auth-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  display: grid;
  gap: 18px;
}

.auth-card-head h2 { font-size: 1.5rem; font-weight: 700; }
.auth-card-head p { margin-top: 6px; color: var(--muted); }

.auth-mobile-brand { display: none; }

.info-banner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--steel-soft);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
}

.info-banner .icon { color: var(--accent); margin-top: 2px; }

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--surface-alt);
  border-radius: 12px;
}

.tab-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 9px 10px;
  border-radius: 9px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.auth-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.alert-error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
}

/* ---------- Formularios ---------- */
.stack-form {
  display: grid;
  gap: 14px;
}

.stack-form label,
.inline-field {
  display: grid;
  gap: 6px;
}

.stack-form label > span,
.inline-field > span {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  font: inherit;
  font-size: 0.93rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 42px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea { resize: vertical; min-height: 80px; }

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus);
}

input::placeholder,
textarea::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }

.checkbox-row {
  display: flex !important;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
}

.checkbox-row input {
  width: 18px;
  height: 18px;
  min-height: 0;
  margin: 2px 0 0;
  accent-color: var(--accent);
  flex: none;
}

.checkbox-row span {
  font-weight: 500 !important;
  color: var(--text) !important;
  font-size: 0.88rem !important;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.inline-form > select,
.inline-form > input { flex: 1 1 180px; width: auto; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
  user-select: none;
}

.btn:active { transform: scale(0.98); }
.btn .icon { width: 16px; height: 16px; }

.btn-primary {
  background: var(--primary);
  color: var(--white);
}

[data-theme="dark"] .btn-primary { color: #04121f; }

.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover { border-color: var(--steel-2); }

.btn-outline {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.btn-outline:hover { background: var(--surface-alt); }

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
}

.btn-danger:hover { background: var(--danger); color: var(--white); }

.btn-full { width: 100%; min-height: 46px; font-size: 0.95rem; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.icon-btn:hover { background: var(--surface-alt); }

/* ---------- Estructura de la aplicación ---------- */
.app-shell {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #0b1a33 0%, #0d1f3d 100%);
  color: #d5deeb;
  border-right: 1px solid rgba(201, 211, 224, 0.08);
}

.sidebar .brand-sub { color: #8fa1bc; }
.sidebar .brand-title { color: var(--white); }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 18px 16px;
}

.sidebar .icon-btn {
  background: transparent;
  color: #d5deeb;
  border-color: rgba(201, 211, 224, 0.16);
}

.nav-list {
  flex: 1;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 2px;
  padding: 6px 12px 12px;
}

.nav-section {
  margin: 14px 10px 6px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6f84a3;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #b8c6da;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  position: relative;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.nav-item .icon { color: #7f93b0; transition: color 0.15s ease; }

.nav-item:hover {
  background: rgba(201, 211, 224, 0.07);
  color: var(--white);
}

.nav-item.active {
  background: rgba(34, 211, 238, 0.12);
  color: var(--white);
}

.nav-item.active .icon { color: var(--cyan-2); }

.nav-item.active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--cyan-2);
}

.sidebar-footer {
  padding: 14px;
  border-top: 1px solid rgba(201, 211, 224, 0.08);
}

.session-badge {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex: none;
  font-weight: 700;
  font-size: 0.82rem;
  background: linear-gradient(135deg, var(--steel), var(--steel-2));
  color: var(--white);
}

.session-info { display: grid; min-width: 0; }

.session-name {
  color: var(--white);
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-role { color: #8fa1bc; font-size: 0.76rem; }

.main-area {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 28px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.topbar-left h2 {
  font-size: 1.2rem;
  font-weight: 700;
}

.topbar-left .muted-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-soft);
}

.status-pill.degraded .status-dot {
  background: var(--warn);
  box-shadow: 0 0 0 3px var(--warn-soft);
}

.content-area {
  padding: 24px 28px 40px;
  display: grid;
  gap: 20px;
  align-content: start;
}

.view-panel {
  display: grid;
  gap: 20px;
  animation: view-in 0.2s ease-out;
}

@keyframes view-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(7, 15, 31, 0.55);
  z-index: 40;
}

.mobile-only { display: none; }

/* ---------- Tarjetas ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  align-content: start;
  min-width: 0;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.card-sub { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }

.narrow-card { max-width: 520px; }

.section-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.split-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.stack-col { display: grid; gap: 20px; }

.divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 4px 0;
  width: 100%;
}

.list-stack {
  display: grid;
  gap: 10px;
}

.item-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.9rem;
  display: grid;
  gap: 4px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.item-box.clickable { cursor: pointer; transition: border-color 0.15s ease, background-color 0.15s ease; }
.item-box.clickable:hover { border-color: var(--accent); }
.item-box.selected { border-color: var(--accent); background: var(--accent-soft); }

.item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-self: start;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 650;
  background: var(--steel-soft);
  color: var(--steel);
  white-space: nowrap;
}

[data-theme="dark"] .badge { color: #b9cbe5; }

.badge.ok { background: var(--success-soft); color: var(--success); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.off { background: var(--danger-soft); color: var(--danger); }

.item-box.badge.warn {
  display: grid;
  border-radius: 12px;
  white-space: normal;
  font-weight: 500;
  font-size: 0.86rem;
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.empty-state .icon-chip { width: 44px; height: 44px; }

.icon-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  flex: none;
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------- KPI ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.kpi-card {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 4px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  min-width: 0;
}

.kpi-card .icon-chip { grid-row: span 2; }
.kpi-card .icon-chip .icon { width: 20px; height: 20px; }

.kpi-label {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.3;
}

.kpi-value {
  font-size: 1.65rem;
  font-weight: 750;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.kpi-hint {
  grid-column: 1 / -1;
  margin-top: 8px;
  font-size: 0.76rem;
  color: var(--muted);
}

.kpi-card.featured {
  grid-column: span 2;
  background:
    radial-gradient(400px 200px at 100% 0%, rgba(34, 211, 238, 0.22), transparent 60%),
    linear-gradient(135deg, #0b1a33, #183463);
  border-color: transparent;
  color: var(--white);
}

.kpi-card.featured .kpi-label,
.kpi-card.featured .kpi-hint { color: #a9b8cf; }

.kpi-card.featured .icon-chip {
  background: rgba(34, 211, 238, 0.16);
  color: var(--cyan-2);
}

.kpi-card.featured .kpi-value { font-size: 2.1rem; }

.kpi-card.tone-warn .icon-chip { background: var(--warn-soft); color: var(--warn); }
.kpi-card.tone-ok .icon-chip { background: var(--success-soft); color: var(--success); }
.kpi-card.tone-steel .icon-chip { background: var(--steel-soft); color: var(--steel-2); }

.progress {
  grid-column: 1 / -1;
  height: 6px;
  border-radius: 999px;
  background: rgba(201, 211, 224, 0.18);
  overflow: hidden;
  margin-top: 10px;
}

.progress > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--cyan-2));
}

/* ---------- Gráficas ---------- */
.charts-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 20px;
}

.chart-box { min-height: 160px; }

.chart-box svg { width: 100%; height: auto; display: block; overflow: visible; }

.chart-total {
  font-size: 0.82rem;
  color: var(--muted);
}

.donut-wrap {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 20px;
  align-items: center;
}

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  font-size: 0.86rem;
}

.legend li {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  align-items: center;
  gap: 10px;
}

.legend .swatch { width: 10px; height: 10px; border-radius: 3px; }
.legend strong { font-variant-numeric: tabular-nums; }

.mini-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.mini-stat {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-alt);
}

.mini-stat span { font-size: 0.76rem; color: var(--muted); font-weight: 600; }
.mini-stat strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }

/* ---------- Chat ---------- */
.chat-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  align-items: start;
}

.chat-layout.no-diagnostics { grid-template-columns: minmax(0, 1fr); }

.chat-card {
  padding: 0;
  gap: 0;
  overflow: hidden;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.chat-identity {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bot-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  flex: none;
  background: linear-gradient(135deg, #0b1a33, #1e4077);
  color: var(--cyan-2);
  box-shadow: inset 0 0 0 1px rgba(34, 211, 238, 0.3);
}

.bot-avatar.small { width: 30px; height: 30px; border-radius: 9px; }
.bot-avatar.small .icon { width: 16px; height: 16px; }

.chat-identity strong { display: block; font-size: 0.95rem; }

.chat-identity small {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
}

.chat-toolbar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.chat-toolbar .inline-field { min-width: 170px; }
.chat-toolbar .inline-field input { min-height: 38px; padding: 7px 10px; font-size: 0.85rem; }

.chat-messages {
  height: min(56vh, 520px);
  overflow-y: auto;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background:
    radial-gradient(600px 300px at 100% 0%, var(--accent-soft), transparent 70%),
    var(--surface-sunk);
  overscroll-behavior: contain;
}

.chat-messages.compact {
  height: min(60vh, 560px);
  border-radius: 12px;
  border: 1px solid var(--border);
  color: var(--muted);
}

.chat-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 82%;
}

.chat-row.from-user { align-self: flex-end; flex-direction: row-reverse; }
.chat-row.from-system { align-self: center; max-width: 92%; }

.chat-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.92rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text);
}

.chat-row.from-bot .chat-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-sm);
}

.chat-row.from-user .chat-bubble {
  background: linear-gradient(135deg, #12305f, #1d4a85);
  color: var(--white);
  border-bottom-right-radius: 6px;
}

.chat-row.from-operator .chat-bubble {
  background: var(--success-soft);
  border: 1px solid color-mix(in srgb, var(--success) 30%, transparent);
  border-bottom-left-radius: 6px;
}

.chat-row.from-system .chat-bubble {
  background: var(--warn-soft);
  color: var(--text);
  border-radius: 10px;
  font-size: 0.84rem;
  text-align: center;
}

.chat-bubble-role {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-bottom: 2px;
  opacity: 0.75;
}

.user-avatar {
  width: 30px;
  height: 30px;
  font-size: 0.72rem;
}

.chat-empty {
  margin: auto;
  display: grid;
  justify-items: center;
  gap: 12px;
  text-align: center;
  color: var(--muted);
  max-width: 360px;
}

.chat-empty strong { color: var(--text); font-size: 1rem; }

.suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
}

.chip:hover { border-color: var(--accent); color: var(--accent); }

.typing {
  display: inline-flex;
  gap: 4px;
  padding: 14px 16px;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing 1.1s infinite ease-in-out;
}

.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

.chat-input-row {
  display: flex;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.chat-input-row input { flex: 1; min-height: 46px; border-radius: 12px; }
.chat-input-row .btn { min-height: 46px; padding: 0 18px; }

.meta-stack { display: grid; gap: 8px; }

.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 0.86rem;
}

.meta-row:last-child { border-bottom: 0; }
.meta-row span { color: var(--muted); }
.meta-row strong { text-align: right; overflow-wrap: anywhere; }

/* ---------- Tablas ---------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.data-table th {
  text-align: left;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface-alt);
  padding: 10px 12px;
  white-space: nowrap;
}

.data-table td {
  padding: 12px;
  border-top: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tbody tr:hover { background: var(--surface-alt); }
.data-table td select { min-width: 160px; min-height: 36px; padding: 6px 10px; }

.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.row-actions .btn { min-height: 34px; padding: 6px 12px; font-size: 0.82rem; }

/* ---------- Kanban ---------- */
.kanban-board {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(240px, 1fr);
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 8px;
  scroll-snap-type: x proximity;
}

.kanban-col {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  gap: 10px;
  align-content: start;
  min-height: 160px;
  scroll-snap-align: start;
}

.kanban-col-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 650;
  font-size: 0.86rem;
  padding: 2px 4px 6px;
}

.kanban-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 8px;
  box-shadow: var(--shadow-sm);
  font-size: 0.88rem;
}

.kanban-card select { min-height: 36px; padding: 6px 10px; font-size: 0.84rem; }
.kanban-card .btn { min-height: 34px; font-size: 0.82rem; }

/* ---------- Usuarios / auditoría / otros ---------- */
.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.user-info { display: grid; gap: 2px; min-width: 0; }

.user-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.user-actions select { width: auto; min-height: 36px; padding: 6px 10px; }
.user-actions .btn { min-height: 36px; padding: 6px 12px; font-size: 0.82rem; }

.audit-list { max-height: 420px; overflow-y: auto; }
.audit-list .item-box { font-size: 0.82rem; }

.code-preview {
  background: var(--night);
  color: #cfe8f5;
  font-family: var(--mono);
  font-size: 0.8rem;
  padding: 16px;
  border-radius: 12px;
  overflow: auto;
  max-height: 420px;
}

#webchat-snippet { white-space: pre-wrap; word-break: break-all; }

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 60;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--night);
  color: var(--white);
  box-shadow: var(--shadow-lg);
  font-size: 0.88rem;
  border-left: 4px solid var(--cyan-2);
  animation: toast-in 0.2s ease-out;
}

.toast.error { border-left-color: #f87171; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1280px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi-card.featured { grid-column: span 3; }
}

@media (max-width: 1100px) {
  .charts-grid,
  .split-grid,
  .chat-layout { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 960px) {
  .auth-wrapper { grid-template-columns: 1fr; }
  .auth-hero { display: none; }
  .auth-mobile-brand { display: flex; }
  .auth-panel {
    min-height: 100vh;
    min-height: 100dvh;
    align-items: flex-start;
    padding-top: 48px;
  }

  .app-shell { grid-template-columns: minmax(0, 1fr); }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 50;
    width: 284px;
    max-width: 86vw;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open { transform: none; }
  .mobile-only { display: inline-flex; }

  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-card.featured { grid-column: span 2; }
}

@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .topbar { padding: 12px 14px; }
  .topbar-left h2 { font-size: 1.05rem; }
  .content-area { padding: 16px 14px 32px; gap: 16px; }
  .view-panel { gap: 16px; }
  .card { padding: 16px; }
  .topbar-actions .btn-label,
  .status-pill .status-text { display: none; }
  .topbar-actions .btn { padding: 8px 10px; }
  .status-pill { padding: 8px; }
  .kpi-grid { gap: 10px; }
  .kpi-card { padding: 14px; gap: 2px 10px; grid-template-columns: 1fr; }
  .kpi-card .icon-chip { grid-row: auto; width: 32px; height: 32px; margin-bottom: 6px; }
  .kpi-value { font-size: 1.35rem; }
  .kpi-card.featured .kpi-value { font-size: 1.7rem; }
  .donut-wrap { grid-template-columns: 1fr; justify-items: center; }
  .legend { width: 100%; }
  .chat-row { max-width: 92%; }
  .chat-messages { height: 58vh; padding: 14px 12px; }
  .chat-input-row { padding: 10px 12px; }
  .chat-toolbar { width: 100%; }
  .chat-toolbar .inline-field { flex: 1; min-width: 0; }
  .toast { right: 12px; left: 12px; bottom: 12px; }
  input, select, textarea { font-size: 16px; }
}

@media (hover: none) {
  .nav-item:hover { background: transparent; color: #b8c6da; }
  .nav-item.active:hover { background: rgba(34, 211, 238, 0.12); color: var(--white); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Sprite de iconos y elementos SVG de gráficas ---------- */
.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.bar-label { fill: var(--text); font-size: 12.5px; font-weight: 500; }
.bar-value { fill: var(--text); font-size: 12.5px; font-weight: 700; }
.bar-track { fill: var(--surface-alt); }
.bar-fill { fill: url(#bar-gradient); }
.bar-fill.is-won { fill: var(--success); }
.bar-fill.is-lost { fill: var(--danger); opacity: 0.75; }
.donut-track { fill: none; stroke: var(--surface-alt); }
.donut-center { fill: var(--text); font-size: 22px; font-weight: 750; }
.donut-caption { fill: var(--muted); font-size: 10px; font-weight: 600; letter-spacing: 0.04em; }

@media (max-width: 640px) {
  .chat-input-row .btn-label { display: none; }
  .chat-input-row .btn { width: 46px; padding: 0; }
}

/* ---------- Logotipo oficial EstoyAki ---------- */
.hero-logo {
  align-self: flex-start;
  width: clamp(170px, 16vw, 230px);
  padding: 10px;
  border-radius: 24px;
  background: #ffffff;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(201, 211, 224, 0.4);
}

.hero-logo img { display: block; width: 100%; height: auto; border-radius: 16px; }

/* Recorte del isotipo (mascota + escudo) desde la imagen original 1024×1024.
   --cx/--cy/--cw: caja de recorte en píxeles de la imagen original. */
.logo-crop {
  --size: 40px;
  --cx: 170;
  --cy: 50;
  --cw: 700;
  position: relative;
  display: inline-block;
  flex: none;
  width: var(--size);
  height: var(--size);
  overflow: hidden;
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 0 0 1px rgba(201, 211, 224, 0.5);
}

.logo-crop img {
  position: absolute;
  max-width: none;
  width: calc(var(--size) * 1024 / var(--cw));
  left: calc(var(--size) * var(--cx) / var(--cw) * -1);
  top: calc(var(--size) * var(--cy) / var(--cw) * -1);
}

.brand-lockup.compact .logo-crop { --size: 38px; }
.auth-mobile-brand .logo-crop { --size: 46px; }

/* Avatar del asistente: cara del robot */
.logo-crop.bot-face { --cx: 285; --cy: 95; --cw: 470; --size: 40px; border-radius: 12px; }
.logo-crop.bot-face.small { --size: 30px; border-radius: 9px; }
.chat-empty .logo-crop.bot-face { --size: 64px; border-radius: 18px; }

/* Fase 5.1a: sección de inteligencia artificial */
.ai-pills { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.ai-pills .badge { display: inline-flex; align-items: center; gap: 6px; }
.ai-pills .badge .icon { width: 14px; height: 14px; }
.ai-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.ai-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 16px; }
#ai-providers-body .badge { margin-left: 6px; }
#ai-providers-body td:last-child .badge { margin-left: 0; }
@media (max-width: 720px) {
  .ai-form-grid, .ai-kpis { grid-template-columns: 1fr; }
}

/* Fase 5.1a.1: sinonimos, laboratorio y parada de emergencia */
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.synonym-editor { display: grid; gap: 6px; }
.field-label { font-size: 0.85rem; font-weight: 600; }
.synonym-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.synonym-chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 10px; border-radius: 999px;
  background: var(--info-soft, rgba(37, 99, 235, 0.1)); font-size: 0.85rem; max-width: 100%; overflow-wrap: anywhere; }
.synonym-remove { border: 0; background: transparent; cursor: pointer; font-size: 1rem; line-height: 1; padding: 2px 6px;
  color: inherit; border-radius: 999px; }
.synonym-remove:hover, .synonym-remove:focus-visible { background: rgba(0, 0, 0, 0.08); }
.synonym-add { display: flex; gap: 6px; }
.synonym-add input { flex: 1; min-width: 0; }
.synonym-preview-list { margin: 6px 0 10px; padding-left: 18px; font-size: 0.9rem; }
.lab-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.lab-form label { flex: 1; min-width: 220px; display: grid; gap: 4px; }
.lab-form label.lab-provider { flex: 0 1 220px; min-width: 160px; }
.lab-form select { width: 100%; }
.lab-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 14px; }
.lab-col { border: 1px solid var(--border, #d9e0ea); border-radius: 10px; padding: 12px; min-width: 0; }
.lab-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.lab-metrics { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 0.85rem; margin: 8px 0 0; }
.lab-metrics dt { font-weight: 600; }
.lab-metrics dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 720px) { .lab-grid { grid-template-columns: 1fr; } }
/* Fase 5.1c: conversación de prueba e indicadores de calidad */
.lab-conversation { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 10px; font-size: 0.88rem; }
.lab-check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.lab-check input[type="checkbox"] { width: 16px; height: 16px; min-height: 0; margin: 0; padding: 0; flex: none; }
.lab-score { font-weight: 700; }
.lab-score.good { color: #157347; }
.lab-score.fair { color: #b26a00; }
.lab-score.poor { color: #b42318; }
/* Fase 5.1d: informe de consumo. Colores validados (dataviz): claro sobre #ffffff, oscuro sobre #0d1a31 */
:root { --series-1: #257de0; --series-2: #f47230; }
[data-theme="dark"] { --series-1: #338ced; --series-2: #e76624; }
.ai-alerts { display: grid; gap: 8px; margin-bottom: 12px; }
.ai-alerts:empty { display: none; }
.ai-alert { display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; font-size: 0.88rem; border: 1px solid transparent; }
.ai-alert .icon { flex: none; width: 18px; height: 18px; margin-top: 1px; }
.ai-alert strong { flex: none; }
.ai-alert.warning { background: var(--warn-soft); color: var(--text); border-color: var(--warn); }
.ai-alert.warning .icon, .ai-alert.warning strong { color: var(--warn); }
.ai-alert.critical { background: var(--danger-soft); color: var(--text); border-color: var(--danger); }
.ai-alert.critical .icon, .ai-alert.critical strong { color: var(--danger); }
.usage-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.usage-head h4 { margin: 0; }
.usage-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.seg-group { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg-btn { background: transparent; border: 0; padding: 7px 12px; font: inherit; font-size: 0.85rem; color: var(--muted); cursor: pointer; min-height: 36px; }
.seg-btn + .seg-btn { border-left: 1px solid var(--border); }
.seg-btn[aria-pressed="true"] { background: var(--surface-alt); color: var(--text); font-weight: 600; }
.usage-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.82rem; color: var(--text); margin: 6px 0; }
.legend-item { display: inline-flex; gap: 6px; align-items: center; }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; display: inline-block; }
.legend-swatch.s1 { background: var(--series-1); }
.legend-swatch.s2 { background: var(--series-2); }
.usage-chart { position: relative; min-height: 60px; }
.usage-svg { width: 100%; height: 200px; display: block; overflow: visible; }
.usage-svg .grid { stroke: var(--border); stroke-width: 1; opacity: 0.6; }
.usage-svg .axis { stroke: var(--border); stroke-width: 1; }
.usage-svg .tick { fill: var(--muted); font-size: 11px; }
.usage-svg .bar.s1 { fill: var(--series-1); }
.usage-svg .bar.s2 { fill: var(--series-2); }
.usage-svg .hit { fill: transparent; cursor: default; outline: none; }
.usage-svg .hit.active, .usage-svg .hit:focus-visible { fill: var(--text); fill-opacity: 0.06; }
.usage-tip { position: absolute; top: 0; z-index: 3; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font-size: 0.8rem; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.14); min-width: 170px; display: grid; gap: 3px; }
.usage-tip.hidden { display: none; }
.tip-row { display: flex; gap: 6px; align-items: center; }
.usage-empty { padding: 18px 0; }
.usage-details { margin: 8px 0 4px; font-size: 0.88rem; }
.usage-details summary { cursor: pointer; color: var(--muted); }
