/* ==========================================================
   MICO — Custom Theme (AdminLTE 4 + Bootstrap 5)
   ========================================================== */

:root {
  --mico-brand:       #2563eb;
  --mico-brand-r:     37;
  --mico-brand-g:     99;
  --mico-brand-b:     235;
  --mico-green:       #10b981;
  --mico-amber:       #f59e0b;
  --mico-danger:      #ef4444;
  --mico-bg:          #f1f5f9;
  --mico-panel:       #ffffff;
  --mico-line:        #e2e8f0;
  --mico-muted:       #64748b;
  --mico-dark:        #0f172a;
  --mico-sidebar-bg:  #0f172a;
  --bubble-in:        #ffffff;
  --bubble-out:       #dcfce7;
  --radius-sm:        8px;
  --radius-md:        12px;
  --radius-lg:        16px;
  --shadow-card:      0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
}

/* ─── TIPOGRAFÍA ─────────────────────────────────────────── */
html,
body,
.app-wrapper {
  min-height: 100vh !important;
  height: 100%;
}

body,
.app-wrapper {
  font-family: 'Inter', system-ui, -apple-system, sans-serif !important;
  overflow-x: hidden;
}



a { text-decoration: none; }

/* ─── SIDEBAR ────────────────────────────────────────────── */
.mico-sidebar,
.mico-sidebar .sidebar-wrapper {
  background: var(--mico-sidebar-bg) !important;
}

.mico-sidebar {
  border-right: 1px solid rgba(255,255,255,.06);
  min-height: 100vh !important;
}

.mico-sidebar .sidebar-wrapper {
  height: calc(100vh - 60px) !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
}

/* Custom Scrollbar for Sidebar */
.mico-sidebar .sidebar-wrapper::-webkit-scrollbar {
  width: 5px;
}
.mico-sidebar .sidebar-wrapper::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.15);
  border-radius: 10px;
}
.mico-sidebar .sidebar-wrapper::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-brand .brand-link {
  padding: 1rem 1.15rem;
  border-bottom: 1px solid rgba(255,255,255,.07);
  text-decoration: none;
}

.brand-text {
  color: #f1f5f9 !important;
  font-size: 1.15rem;
  letter-spacing: .01em;
}

.mico-brand-mark {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  display: inline-grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: var(--mico-brand);
  color: #facc15;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* Panel de usuario en sidebar */
.user-panel {
  padding: .7rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.07);
  margin-bottom: 0 !important;
}

.user-avatar {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: var(--mico-brand);
  color: #fff;
  font-weight: 700;
  font-size: .825rem;
  flex-shrink: 0;
  letter-spacing: .02em;
}

.sidebar-avatar {
  background: #1d3461;
  color: #93c5fd;
}

.mico-role-badge {
  display: inline-block;
  padding: .2em .55em;
  border-radius: 5px;
  background: rgba(255,255,255,.09);
  color: #94a3b8;
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-top: 2px;
}

/* Separador de sección en sidebar */
.sidebar-nav-label {
  padding: .65rem 1rem .25rem;
  font-size: .66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: #475569;
}

/* Links del menú */
.sidebar-menu .nav-link {
  color: #94a3b8 !important;
  border-radius: var(--radius-sm);
  margin: 1px 10px;
  padding: .55rem .9rem;
  font-size: .875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: .5rem;
  transition: background .15s, color .15s;
}

.sidebar-menu .nav-link p {
  margin: 0;
  line-height: 1.4;
  white-space: normal;
}

.sidebar-menu .nav-link:hover {
  background: rgba(255,255,255,.07) !important;
  color: #e2e8f0 !important;
}

.sidebar-menu .nav-link.active {
  background: rgba(var(--mico-brand-r),var(--mico-brand-g),var(--mico-brand-b),.18) !important;
  color: #93c5fd !important;
  font-weight: 600;
}

.sidebar-menu .nav-link.active .nav-icon {
  color: #93c5fd;
}

.nav-icon {
  width: 1.1rem;
  text-align: center;
  flex-shrink: 0;
  opacity: .8;
  font-size: .9rem;
}

/* ─── NAVBAR ────────────────────────────────────────────── */
.app-header {
  border-bottom: 1px solid var(--mico-line) !important;
  box-shadow: 0 1px 4px rgba(0,0,0,.04) !important;
}

.mico-toggle-btn {
  font-size: 1.15rem;
  color: #64748b !important;
  padding: .5rem .75rem;
  border-radius: var(--radius-sm);
  transition: background .15s, color .15s;
}

.mico-toggle-btn:hover {
  background: #f1f5f9 !important;
  color: #1e293b !important;
}

.mico-status-dot {
  width: 8px;
  height: 8px;
  display: inline-block;
  border-radius: 50%;
  background: var(--mico-green);
  box-shadow: 0 0 0 2.5px rgba(16,185,129,.22);
  animation: pulse-dot 2.5s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 2.5px rgba(16,185,129,.22); }
  50%       { box-shadow: 0 0 0 5px rgba(16,185,129,.08); }
}

.mico-user-btn {
  padding: .4rem .65rem;
  border-radius: var(--radius-sm);
  color: #1e293b !important;
  transition: background .15s;
}

.mico-user-btn:hover {
  background: #f1f5f9;
}

.mico-chevron {
  font-size: .6rem;
  opacity: .5;
}

.mico-user-dropdown {
  border-radius: var(--radius-md);
  border: 1px solid var(--mico-line) !important;
  min-width: 210px;
  padding: .4rem;
  margin-top: .3rem !important;
}

.mico-user-dropdown .dropdown-item {
  border-radius: var(--radius-sm);
  padding: .5rem .85rem;
  font-size: .875rem;
  font-weight: 500;
  transition: background .12s;
}

/* ─── CONTENIDO ─────────────────────────────────────────── */
.app-main {
  min-height: calc(100vh - 60px) !important;
  background: var(--mico-bg) !important;
}

.app-content {
  background: var(--mico-bg) !important;
}

/* ─── PAGE HEADER ─────────────────────────────────────────  */
.mico-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1.5rem;
}

.mico-page-title {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--mico-dark);
  margin: 0 0 .2rem;
  line-height: 1.2;
}

.mico-page-subtitle {
  font-size: .85rem;
  color: var(--mico-muted);
  margin: 0;
}

.breadcrumb {
  background: transparent;
  padding: 0;
  margin: 0;
  font-size: .8rem;
}

.breadcrumb-item + .breadcrumb-item::before {
  color: #cbd5e1;
}

/* ─── CARDS ─────────────────────────────────────────────── */
.card {
  border: 1px solid var(--mico-line) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-card) !important;
}

.card-header {
  background: transparent !important;
  border-bottom: 1px solid var(--mico-line) !important;
  border-radius: var(--radius-md) var(--radius-md) 0 0 !important;
  padding: .9rem 1.25rem !important;
}

.card-title {
  font-size: .82rem !important;
  font-weight: 700 !important;
  color: #1e293b !important;
  text-transform: uppercase !important;
  letter-spacing: .05em !important;
  margin: 0 !important;
}

.card-body {
  padding: 1.25rem !important;
}

/* ─── INFO-BOX (Stats) ─────────────────────────────────── */
.info-box {
  border-radius: var(--radius-md) !important;
  border: 1px solid var(--mico-line) !important;
  box-shadow: var(--shadow-card) !important;
  min-height: 90px;
  overflow: hidden;
  margin-bottom: 1rem;
  transition: transform .2s, box-shadow .2s;
}

.info-box:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,.09) !important;
}

.info-box .info-box-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 70px;
  font-size: 1.6rem;
}

.info-box-number {
  font-size: 1.65rem !important;
  font-weight: 800 !important;
  color: #0f172a !important;
  line-height: 1.1;
}

.info-box-text {
  font-size: .75rem !important;
  font-weight: 600 !important;
  text-transform: uppercase !important;
  letter-spacing: .05em !important;
  color: var(--mico-muted) !important;
}

/* ─── MODULE LINKS (Dashboard) ─────────────────────────── */
.mico-module-link {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--mico-line);
  border-radius: var(--radius-md);
  background: #fff;
  color: var(--mico-dark);
  text-decoration: none;
  transition: all .2s ease;
  margin-bottom: 1rem;
}

.mico-module-link:hover {
  border-color: rgba(var(--mico-brand-r),var(--mico-brand-g),var(--mico-brand-b),.35);
  background: rgba(var(--mico-brand-r),var(--mico-brand-g),var(--mico-brand-b),.03);
  color: var(--mico-dark);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(var(--mico-brand-r),var(--mico-brand-g),var(--mico-brand-b),.1);
}

.mico-module-icon {
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  display: inline-grid;
  place-items: center;
  border-radius: 10px;
  background: rgba(var(--mico-brand-r),var(--mico-brand-g),var(--mico-brand-b),.1);
  color: var(--mico-brand);
  font-size: 1.1rem;
  transition: background .2s;
}

.mico-module-link:hover .mico-module-icon {
  background: rgba(var(--mico-brand-r),var(--mico-brand-g),var(--mico-brand-b),.15);
}

.mico-module-link strong {
  display: block;
  font-size: .875rem;
  font-weight: 700;
}

.mico-module-link small {
  display: block;
  color: var(--mico-muted);
  font-size: .775rem;
  margin-top: 2px;
}

/* ─── TABLAS ─────────────────────────────────────────────── */
.table {
  font-size: .875rem;
  margin-bottom: 0 !important;
}

.table thead th {
  background: #f8fafc !important;
  color: var(--mico-muted) !important;
  font-size: .72rem !important;
  font-weight: 700 !important;
  text-transform: uppercase !important;
  letter-spacing: .07em !important;
  padding: .7rem 1rem !important;
  border-bottom: 1px solid var(--mico-line) !important;
  white-space: nowrap;
}

.table td {
  padding: .75rem 1rem !important;
  color: #1e293b;
  vertical-align: middle;
  border-bottom: 1px solid #f1f5f9 !important;
}

.table tbody tr:last-child td {
  border-bottom: 0 !important;
}

.table-hover tbody tr:hover td {
  background: #f8fbff !important;
}

/* Badges de estado */
.badge-active {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: .28em .65em;
  border-radius: 20px;
  background: #dcfce7;
  color: #166534;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.badge-inactive {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: .28em .65em;
  border-radius: 20px;
  background: #fee2e2;
  color: #991b1b;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.badge-http-ok  { background:#dcfce7; color:#166534; }
.badge-http-err { background:#fee2e2; color:#991b1b; }
.badge-http-warn{ background:#fef9c3; color:#854d0e; }

.http-badge {
  display: inline-block;
  padding: .25em .6em;
  border-radius: 6px;
  font-size: .75rem;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace, 'Courier New';
}

/* ─── FORMULARIOS ─────────────────────────────────────────  */
.form-label {
  font-size: .77rem !important;
  font-weight: 700 !important;
  color: #475569 !important;
  text-transform: uppercase !important;
  letter-spacing: .05em !important;
  margin-bottom: .3rem !important;
}

.form-control,
.form-select {
  border-color: var(--mico-line) !important;
  border-radius: var(--radius-sm) !important;
  font-size: .875rem !important;
  padding: .5rem .75rem !important;
  color: #1e293b !important;
  background: #fff !important;
  transition: border-color .15s, box-shadow .15s !important;
  min-height: 40px;
}

.form-control:focus,
.form-select:focus {
  border-color: #93c5fd !important;
  box-shadow: 0 0 0 3px rgba(37,99,235,.1) !important;
  outline: 0 !important;
}

.form-control[multiple],
.form-select[multiple] {
  min-height: 130px;
  height: auto !important;
}

textarea.form-control {
  min-height: 90px;
  resize: vertical;
}

/* ─── BOTONES ─────────────────────────────────────────────  */
.btn {
  border-radius: var(--radius-sm) !important;
  font-weight: 600 !important;
  font-size: .875rem !important;
  transition: all .15s ease !important;
}

.btn-primary {
  background: var(--mico-brand) !important;
  border-color: var(--mico-brand) !important;
}

.btn-primary:hover,
.btn-primary:focus {
  background: #1d4ed8 !important;
  border-color: #1d4ed8 !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37,99,235,.3) !important;
}

.btn-warning {
  background: #f59e0b !important;
  border-color: #f59e0b !important;
  color: #fff !important;
}

.btn-warning:hover {
  background: #d97706 !important;
  border-color: #d97706 !important;
  transform: translateY(-1px);
}

.btn-danger {
  background: #dc2626 !important;
  border-color: #dc2626 !important;
}

.btn-danger:hover {
  background: #b91c1c !important;
  border-color: #b91c1c !important;
  transform: translateY(-1px);
}

.btn-success {
  background: #16a34a !important;
  border-color: #16a34a !important;
}

.btn-success:hover {
  background: #15803d !important;
  border-color: #15803d !important;
  transform: translateY(-1px);
}

.btn-outline-secondary {
  border-color: var(--mico-line) !important;
  color: var(--mico-muted) !important;
}

.btn-outline-secondary:hover {
  background: #f1f5f9 !important;
  color: #1e293b !important;
}

/* Accordion border fix */
.accordion-item {
  border: 1px solid var(--mico-line) !important;
}

.accordion-button:not(.collapsed) {
  box-shadow: none !important;
}

.accordion-button:focus {
  box-shadow: 0 0 0 3px rgba(37,99,235,.1) !important;
}

/* Alerts AdminLTE/Bootstrap override */
.alert {
  border-radius: var(--radius-sm) !important;
  font-size: .875rem;
}

.alert-success {
  background: #f0fdf4;
  border-color: #bbf7d0;
  color: #166534;
}

.alert-warning {
  background: #fffbeb;
  border-color: #fde68a;
  color: #92400e;
}

.alert-danger {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

.alert-info {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1e40af;
}

/* ─── AUTH / LOGIN ─────────────────────────────────────── */
.mico-auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(37,99,235,.18) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(16,185,129,.12) 0%, transparent 50%),
    #0c1424;
}

.mico-login-card {
  width: min(440px, 100%);
  background: #fff;
  border-radius: 20px;
  padding: 2.5rem;
  box-shadow: 0 30px 70px rgba(0,0,0,.4);
}

.mico-login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 1.75rem;
}

.mico-login-logo .mico-brand-mark {
  width: 42px;
  height: 42px;
  font-size: 13px;
  border-radius: 10px;
}

.mico-login-logo-text {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--mico-dark);
  letter-spacing: -.02em;
}

.mico-login-subtitle {
  font-size: .88rem;
  color: var(--mico-muted);
  margin-bottom: 1.75rem;
}

/* ─── ALERTAS ─────────────────────────────────────────────  */
.mico-alert {
  padding: .9rem 1.1rem;
  border-radius: var(--radius-sm);
  border-left: 4px solid;
  margin-bottom: 1.25rem;
  font-size: .875rem;
}

.mico-alert-success {
  background: #f0fdf4;
  border-color: var(--mico-green);
  color: #166534;
}

.mico-alert-danger {
  background: #fef2f2;
  border-color: var(--mico-danger);
  color: #991b1b;
}

.mico-alert-title {
  font-weight: 700;
  margin-bottom: .3rem;
}

/* ─── CHAT ────────────────────────────────────────────────  */
/* Asegurar que el chat cubra el 100% del área disponible sin márgenes ni scroll de página */
body:has(.chat-shell) {
  overflow: hidden !important;
}

body:has(.chat-shell) .app-main {
  height: calc(100vh - 56px) !important;
  overflow: hidden !important;
}

body:has(.chat-shell) .app-content {
  padding: 0 !important;
  height: 100% !important;
  min-height: 0 !important;
  overflow: hidden !important;
}

body:has(.chat-shell) .app-content .container-fluid {
  padding: 0 !important;
  margin: 0 !important;
  max-width: 100% !important;
  width: 100% !important;
  height: 100% !important;
}

.chat-shell {
  height: 100% !important;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr) 280px;
  overflow: hidden;
  border: none !important;
  border-radius: 0 !important;
  background: #fff;
  box-shadow: none !important;
  position: relative;
  transition: all 0.3s ease;
}

/* Ocultar barra lateral derecha de forma dinâmica si se desea */
.chat-shell.hide-side {
  grid-template-columns: 340px minmax(0, 1fr) 0px;
}

.chat-shell.hide-side .chat-side {
  display: none;
}

/* LISTA DE CONVERSACIONES */
.chat-list {
  border-right: 1px solid var(--mico-line);
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow: hidden;
}

.chat-list-search {
  padding: 10px 14px;
  background: #f6f6f6;
  border-bottom: 1px solid var(--mico-line);
}

.chat-list-search .search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.chat-list-search .search-wrapper input {
  width: 100%;
  background: #fff !important;
  border: 1px solid #e2e8f0 !important;
  border-radius: 8px;
  font-size: 0.825rem !important;
  padding: 6px 10px 6px 32px !important;
  min-height: 34px;
}

.chat-list-search .search-wrapper i {
  position: absolute;
  left: 10px;
  color: #a0aec0;
  font-size: 0.85rem;
}

.chat-list-container {
  overflow-y: auto;
  flex-grow: 1;
}

/* Estilo para barra de scroll WhatsApp */
.chat-list-container::-webkit-scrollbar,
.messages::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.chat-list-container::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb {
  background-color: rgba(0,0,0,0.15);
  border-radius: 4px;
}
.chat-list-container::-webkit-scrollbar-track,
.messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid #f2f4f7;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: background 0.15s ease;
  user-select: none;
}

.chat-item:hover {
  background: #f5f6f9;
}

.chat-item.active {
  background: #efeae2;
  background: #f0f2f5;
  box-shadow: inset 4px 0 0 #128c7e;
}

.chat-item-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex-grow: 1;
}

.chat-item-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: space-between;
  flex-shrink: 0;
  height: 38px;
  margin-left: 8px;
}

.chat-avatar-text {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
  flex-shrink: 0;
  text-shadow: 0 1px 1px rgba(0,0,0,0.1);
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.chat-item-details {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-item-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: #111b21;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.chat-item-body {
  font-size: 0.775rem;
  color: #667781;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 3px;
}

.chat-item-body i.status-icon {
  font-size: 0.8rem;
}
.chat-item-body i.status-icon.text-success {
  color: #25d366 !important;
}

.chat-item-time {
  font-size: 0.675rem;
  color: #667781;
}

.chat-item-badge {
  background: #25d366;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  padding: 0 4px;
}

/* ÁREA DE CHAT PRINCIPAL */
.chat-main {
  min-width: 0;
  display: grid;
  grid-template-rows: 60px minmax(0, 1fr) auto;
  background-color: #efeae2;
  background-image: radial-gradient(rgba(0, 0, 0, 0.04) 1px, transparent 0), radial-gradient(rgba(0, 0, 0, 0.04) 1px, transparent 0);
  background-size: 24px 24px;
  background-position: 0 0, 12px 12px;
  position: relative;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.chat-header {
  height: 60px;
  background: #f0f2f5;
  border-bottom: 1px solid var(--mico-line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  z-index: 10;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  cursor: pointer;
}

.chat-header-info:hover .chat-header-title {
  color: #128c7e;
}

.chat-header-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: #111b21;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  transition: color 0.15s;
}

.chat-header-status {
  font-size: 0.72rem;
  color: #667781;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.chat-header-btn {
  background: none;
  border: none;
  color: #54656f;
  font-size: 1.05rem;
  padding: 6px;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.chat-header-btn:hover {
  background: rgba(0,0,0,0.05);
  color: #111b21;
}

/* HISTORIAL DE MENSAJES */
.messages {
  padding: 20px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.bubble-container {
  display: flex;
  width: 100%;
  margin-bottom: 2px;
}

.bubble-container.in {
  justify-content: flex-start;
}

.bubble-container.out {
  justify-content: flex-end;
}

.bubble {
  max-width: 65%;
  min-width: 90px;
  padding: 6px 10px 8px;
  border-radius: 8px;
  box-shadow: 0 1px 1px rgba(0,0,0,0.12);
  font-size: 0.875rem;
  line-height: 1.45;
  color: #111b21;
  position: relative;
  word-wrap: break-word;
  display: flex;
  flex-direction: column;
}

.bubble.in {
  background: #ffffff;
  border-top-left-radius: 0px;
}

.bubble.out {
  background: #dcfce7;
  border-top-right-radius: 0px;
}

/* Burbujas multimedia especiales */
.bubble.media-bubble {
  padding: 4px;
}

.bubble-media-wrapper {
  border-radius: 6px;
  overflow: hidden;
  position: relative;
  background: rgba(0,0,0,0.02);
}

.bubble-image-container img {
  max-width: 100%;
  max-height: 280px;
  width: auto;
  height: auto;
  object-fit: cover;
  cursor: zoom-in;
  display: block;
  transition: filter 0.2s;
}
.bubble-image-container img:hover {
  filter: brightness(0.95);
}

.bubble-video-container video {
  max-width: 100%;
  max-height: 280px;
  background: #000;
  display: block;
  outline: none;
}

/* Audio Player Nota de Voz */
.bubble-audio-container {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  min-width: 240px;
}

.audio-vn-avatar {
  font-size: 1.4rem;
  color: #8696a0;
  position: relative;
  flex-shrink: 0;
}
.audio-vn-avatar .vn-mic-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  font-size: 0.65rem;
  background: #fff;
  border-radius: 50%;
  width: 14px;
  height: 14px;
  display: grid;
  place-items: center;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.bubble.out .audio-vn-avatar .vn-mic-badge {
  color: #00a884;
}

.audio-play-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: none;
  border: none;
  color: #54656f;
  font-size: 1.1rem;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.audio-play-btn:hover {
  background: rgba(0,0,0,0.05);
  color: #111b21;
}

.audio-timeline-wrapper {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.audio-timeline {
  width: 100%;
  height: 4px;
  background: rgba(0,0,0,0.1);
  border-radius: 2px;
  position: relative;
  cursor: pointer;
}

.audio-timeline-progress {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  background: #00a884;
  border-radius: 2px;
  width: 0%;
  pointer-events: none;
}

.audio-timeline-progress::after {
  content: '';
  position: absolute;
  right: -5px;
  top: -3px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #00a884;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.audio-duration {
  font-size: 0.68rem;
  color: #667781;
}

/* Documento */
.bubble-document-container {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  min-width: 250px;
  background: rgba(0,0,0,0.03);
  border-radius: 6px;
  border: 1px solid rgba(0,0,0,0.05);
}

.doc-icon {
  font-size: 2.2rem;
  flex-shrink: 0;
}
.doc-icon.pdf { color: #f40f02; }
.doc-icon.zip { color: #f1c40f; }
.doc-icon.word { color: #2b579a; }
.doc-icon.excel { color: #217346; }
.doc-icon.powerpoint { color: #d24726; }
.doc-icon.generic { color: #7f8c8d; }

.doc-info {
  flex-grow: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.doc-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: #111b21;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-meta {
  font-size: 0.68rem;
  color: #667781;
  display: flex;
  gap: 6px;
}

.doc-download-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,0.7);
  border: 1px solid rgba(0,0,0,0.08);
  color: #54656f;
  font-size: 0.9rem;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}
.doc-download-btn:hover {
  background: #fff;
  color: #00a884;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Sticker */
.bubble.sticker-bubble {
  background: none !important;
  box-shadow: none !important;
  padding: 0px !important;
  max-width: 130px;
}
.bubble.sticker-bubble img {
  width: 120px;
  height: 120px;
  object-fit: contain;
  display: block;
}

/* Texto de caption de multimedia */
.media-caption {
  font-size: 0.85rem;
  padding: 6px 8px 2px;
  color: #111b21;
}

/* Metadatos del mensaje (Hora y Checks) */
.bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 3px;
  align-self: flex-end;
  user-select: none;
  font-size: 0.65rem;
  color: #667781;
}

.bubble.media-bubble .bubble-meta {
  padding: 2px 6px 0px;
}

.bubble-meta .checks-icon {
  font-size: 0.75rem;
}
.bubble-meta .checks-icon.text-primary {
  color: #53bdeb !important;
}

/* Exclamación roja de fallo */
.failed-indicator {
  color: #ea0038;
  cursor: pointer;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
}

/* BANDA ADVERTENCIA 24H */
.warning-24h-banner {
  background-color: #ffeeb3;
  color: #856404;
  border-bottom: 1px solid #ffeeba;
  padding: 8px 16px;
  font-size: 0.775rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 5;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* COMPOSITOR DE MENSAJE */
.chat-compose {
  background: #f0f2f5;
  border-top: 1px solid var(--mico-line);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  z-index: 20;
}

.compose-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.compose-btn {
  background: none;
  border: none;
  color: #54656f;
  font-size: 1.35rem;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.compose-btn:hover,
.compose-btn.active {
  background: rgba(0,0,0,0.07);
  color: #111b21;
}

/* Caja de entrada con tamaño dinâmico */
.compose-input-wrapper {
  flex-grow: 1;
  min-width: 0;
  background: #fff;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  padding: 3px 6px;
}

.compose-textarea {
  width: 100%;
  border: none;
  background: none;
  font-size: 0.875rem;
  padding: 6px 8px;
  max-height: 100px;
  overflow-y: auto;
  resize: none;
  outline: none;
  color: #111b21;
  display: block;
}

/* EMOJI PICKER PERSONALIZADO */
.emoji-picker-drawer {
  position: absolute;
  bottom: 60px;
  left: 14px;
  width: 320px;
  height: 280px;
  background: #fff;
  border: 1px solid var(--mico-line);
  border-radius: 12px;
  box-shadow: 0 4px 18px rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 100;
  transform: scale(0.9);
  opacity: 0;
  pointer-events: none;
  transform-origin: bottom left;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.emoji-picker-drawer.active {
  transform: scale(1);
  opacity: 1;
  pointer-events: auto;
}

.emoji-picker-tabs {
  display: flex;
  background: #f0f2f5;
  border-bottom: 1px solid var(--mico-line);
  overflow-x: auto;
}
.emoji-picker-tab-btn {
  flex-grow: 1;
  border: none;
  background: none;
  font-size: 1.05rem;
  padding: 6px 2px;
  cursor: pointer;
  opacity: 0.65;
  transition: opacity 0.15s, border-color 0.15s;
}
.emoji-picker-tab-btn.active {
  opacity: 1;
  border-bottom: 2px solid #00a884;
}

.emoji-picker-grid {
  overflow-y: auto;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  flex-grow: 1;
}
.emoji-btn {
  font-size: 1.3rem;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 6px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  transition: background 0.15s, transform 0.1s;
}
.emoji-btn:hover {
  background: #f0f2f5;
  transform: scale(1.15);
}
.emoji-btn:active {
  transform: scale(0.9);
}

/* POPUP ARCHIVOS ADJUNTOS */
.attach-menu {
  position: absolute;
  bottom: 60px;
  left: 60px;
  background: #fff;
  border: 1px solid var(--mico-line);
  border-radius: 12px;
  box-shadow: 0 4px 18px rgba(0,0,0,0.15);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 100;
  min-width: 180px;
  transform: scale(0.9);
  opacity: 0;
  pointer-events: none;
  transform-origin: bottom left;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.attach-menu.active {
  transform: scale(1);
  opacity: 1;
  pointer-events: auto;
}

.attach-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  font-size: 0.825rem;
  font-weight: 600;
  color: #54656f;
  background: none;
  border: none;
  text-align: left;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  width: 100%;
}
.attach-menu-item:hover {
  background: #f0f2f5;
  color: #111b21;
}
.attach-menu-item i {
  font-size: 1rem;
  width: 22px;
  text-align: center;
}
.attach-menu-item i.img-vid { color: #007bec; }
.attach-menu-item i.doc-file { color: #9f66ff; }

/* PANEL DE PROGRESO DE SUBIDA */
.upload-progress-panel {
  background: #fff;
  border: 1px solid var(--mico-line);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: absolute;
  bottom: 58px;
  left: 14px;
  right: 14px;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
  z-index: 95;
  transform: translateY(10px);
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s;
}

.upload-progress-panel.active {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.upload-progress-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.upload-file-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: #111b21;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  max-width: 80%;
}

.upload-cancel-btn {
  background: none;
  border: none;
  color: #a0aec0;
  font-size: 0.95rem;
  cursor: pointer;
}
.upload-cancel-btn:hover {
  color: #e53e3e;
}

.upload-progress-bar-wrapper {
  width: 100%;
  height: 6px;
  background: #edf2f7;
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}

.upload-progress-bar-fill {
  height: 100%;
  background: #00a884;
  width: 0%;
  transition: width 0.1s ease;
}

.upload-progress-percent {
  font-size: 0.72rem;
  color: #718096;
  text-align: right;
}

/* GRABACIÓN DE AUDIO (NOTA DE VOZ) */
.recording-bar {
  display: none;
  align-items: center;
  gap: 14px;
  width: 100%;
  background: #f0f2f5;
  padding: 4px 6px;
  border-radius: 8px;
}

.recording-bar.active {
  display: flex;
}

.recording-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #ea0038;
}

.recording-dot {
  width: 8px;
  height: 8px;
  background: #ea0038;
  border-radius: 50%;
  animation: rec-pulse 1s infinite alternate;
}

@keyframes rec-pulse {
  from { opacity: 0.3; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1.15); }
}

.recording-timer {
  font-family: monospace;
  font-size: 0.9rem;
  color: #111b21;
  font-weight: bold;
}

/* Ondas animadas de audio */
.recording-waves {
  display: flex;
  align-items: center;
  gap: 2.5px;
  height: 20px;
  flex-grow: 1;
  padding-left: 10px;
}
.rec-wave-bar {
  width: 3px;
  height: 6px;
  background: #a0aec0;
  border-radius: 1px;
  transition: height 0.1s ease;
}
.recording-bar.active .rec-wave-bar {
  animation: wave-dance 1.2s infinite ease-in-out alternate;
}
.recording-bar.active .rec-wave-bar:nth-child(2n) { animation-delay: 0.2s; }
.recording-bar.active .rec-wave-bar:nth-child(3n) { animation-delay: 0.4s; }
.recording-bar.active .rec-wave-bar:nth-child(4n) { animation-delay: 0.1s; }
.recording-bar.active .rec-wave-bar:nth-child(5n) { animation-delay: 0.5s; }

@keyframes wave-dance {
  from { height: 4px; background: #a0aec0; }
  to { height: 18px; background: #00a884; }
}

.recording-btn-trash {
  color: #e53e3e !important;
}
.recording-btn-send {
  color: #00a884 !important;
}

/* PANEL LATERAL DE DETALLES DEL CONTACTO */
.chat-side {
  background: #fff;
  border-left: 1px solid var(--mico-line);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  animation: slide-in 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slide-in {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.chat-side-header {
  height: 60px;
  border-bottom: 1px solid var(--mico-line);
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: #f0f2f5;
  gap: 12px;
}

.chat-side-header h3 {
  margin: 0 !important;
  font-size: 0.9rem !important;
  font-weight: 700 !important;
  color: #111b21 !important;
  text-transform: none !important;
}

.chat-side-content {
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.chat-side-section {
  border-bottom: 1px solid #f2f4f7;
  padding-bottom: 16px;
}
.chat-side-section:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.chat-side-section-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #667781;
  margin-bottom: 10px;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* LIGHTBOX NATIVO */
.mico-lightbox {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(11, 20, 26, 0.95);
  display: none;
  place-items: center;
  z-index: 9999;
  cursor: zoom-out;
  animation: fade-in 0.2s;
}

.mico-lightbox.active {
  display: grid;
}

.mico-lightbox img {
  max-width: 90%;
  max-height: 85%;
  border-radius: 4px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  cursor: default;
}

.mico-lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: none;
  border: none;
  color: #fff;
  font-size: 1.8rem;
  cursor: pointer;
  transition: transform 0.2s;
}
.mico-lightbox-close:hover {
  transform: scale(1.1);
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.muted { color: var(--mico-muted); }

/* ─── CHATBOT BUILDER ─────────────────────────────────────  */

/* Full-height layout como el módulo de chats */
body:has(.cb-shell) .app-main {
  height: calc(100vh - 56px) !important;
  overflow: hidden !important;
}
body:has(.cb-shell) .app-content {
  padding: 0 !important;
  height: 100% !important;
  min-height: 0 !important;
  overflow: hidden !important;
}
body:has(.cb-shell) .app-content .container-fluid {
  padding: 0 !important;
  margin: 0 !important;
  max-width: 100% !important;
  width: 100% !important;
  height: 100% !important;
}

.cb-shell {
  height: 100% !important;
  display: grid;
  grid-template-columns: 280px 260px minmax(0, 1fr);
  overflow: hidden;
  background: #fff;
  position: relative;
}

/* ── Panel 1: Lista de Bots ── */
.cb-panel-bots {
  border-right: 1px solid var(--mico-line);
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow: hidden;
}

.cb-panel-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--mico-line);
  background: #f8fafc;
  flex-shrink: 0;
}

.cb-panel-header h2 {
  font-size: .95rem;
  font-weight: 800;
  color: var(--mico-dark);
  margin: 0 0 2px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.cb-panel-header p {
  font-size: .72rem;
  color: var(--mico-muted);
  margin: 0;
}

.cb-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

.cb-panel-body::-webkit-scrollbar {
  width: 5px;
}
.cb-panel-body::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,.12);
  border-radius: 4px;
}

.cb-panel-footer {
  border-top: 1px solid var(--mico-line);
  padding: 12px 16px;
  background: #f8fafc;
  flex-shrink: 0;
}

/* Bot items en la lista */
.cb-bot-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  transition: background .15s;
  text-decoration: none;
  color: inherit;
}
.cb-bot-item:hover {
  background: #f8fafc;
}
.cb-bot-item.active {
  background: rgba(var(--mico-brand-r),var(--mico-brand-g),var(--mico-brand-b),.06);
  box-shadow: inset 3px 0 0 var(--mico-brand);
}

.cb-bot-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 1rem;
  flex-shrink: 0;
  background: rgba(var(--mico-brand-r),var(--mico-brand-g),var(--mico-brand-b),.1);
  color: var(--mico-brand);
}

.cb-bot-info {
  min-width: 0;
  flex: 1;
}

.cb-bot-info h4 {
  font-size: .84rem;
  font-weight: 700;
  color: var(--mico-dark);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cb-bot-meta {
  font-size: .68rem;
  color: var(--mico-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.cb-bot-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.cb-bot-actions .btn {
  padding: 3px 6px !important;
  font-size: .72rem !important;
}

.cb-badge-active {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--mico-green);
  box-shadow: 0 0 0 2px rgba(16,185,129,.2);
}

.cb-badge-inactive {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
}

/* ── Panel 2: Árbol de Estructura ── */
.cb-panel-tree {
  border-right: 1px solid var(--mico-line);
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow: hidden;
}

.cb-tree-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--mico-muted);
  padding: 24px;
  text-align: center;
}

.cb-tree-empty i {
  font-size: 2.5rem;
  opacity: .15;
  margin-bottom: 12px;
}

.cb-category-group {
  border-bottom: 1px solid #f1f5f9;
}

.cb-category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  cursor: pointer;
  transition: background .12s;
  user-select: none;
}
.cb-category-header:hover {
  background: #f8fafc;
}

.cb-category-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .8rem;
  font-weight: 700;
  color: var(--mico-dark);
  min-width: 0;
}

.cb-category-label i {
  color: var(--mico-brand);
  font-size: .75rem;
}

.cb-category-badge {
  font-size: .6rem;
  font-weight: 600;
  color: var(--mico-muted);
  background: #f1f5f9;
  padding: 2px 7px;
  border-radius: 10px;
}

.cb-category-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity .15s;
}
.cb-category-header:hover .cb-category-actions {
  opacity: 1;
}

.cb-category-actions button {
  background: none;
  border: none;
  padding: 3px 5px;
  cursor: pointer;
  font-size: .75rem;
  border-radius: 4px;
  transition: background .1s;
  color: var(--mico-muted);
}
.cb-category-actions button:hover {
  background: #f1f5f9;
}
.cb-category-actions button.text-danger { color: var(--mico-danger); }
.cb-category-actions button.text-primary { color: var(--mico-brand); }

.cb-category-nodes {
  display: none;
}
.cb-category-group.open .cb-category-nodes {
  display: block;
}

.cb-category-group.open .cb-category-chevron {
  transform: rotate(90deg);
}

.cb-category-chevron {
  font-size: .6rem;
  color: #94a3b8;
  transition: transform .2s;
  flex-shrink: 0;
}

.cb-node-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px 8px 36px;
  cursor: pointer;
  transition: background .12s;
  font-size: .78rem;
  color: #475569;
  border-left: 2px solid transparent;
}
.cb-node-item:hover {
  background: #f8fafc;
}
.cb-node-item.active {
  background: rgba(var(--mico-brand-r),var(--mico-brand-g),var(--mico-brand-b),.08);
  border-left-color: var(--mico-brand);
  color: var(--mico-brand);
  font-weight: 600;
}

.cb-node-item-label {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.cb-node-item-label i {
  font-size: .7rem;
  opacity: .5;
}

.cb-node-type-badge {
  font-size: .55rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 1px 6px;
  border-radius: 4px;
  background: #f1f5f9;
  color: #64748b;
}

.cb-node-delete {
  background: none;
  border: none;
  color: #cbd5e1;
  font-size: .7rem;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity .15s, color .15s;
}
.cb-node-item:hover .cb-node-delete {
  opacity: 1;
}
.cb-node-delete:hover {
  color: var(--mico-danger);
}

/* ── Panel 3: Simulador de Chat + Editor ── */
.cb-panel-editor {
  display: flex;
  flex-direction: column;
  background: #f0f2f5;
  overflow: hidden;
  min-width: 0;
}

.cb-editor-header {
  height: 56px;
  background: #fff;
  border-bottom: 1px solid var(--mico-line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}

.cb-editor-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cb-editor-header-info h3 {
  font-size: .88rem;
  font-weight: 700;
  color: var(--mico-dark);
  margin: 0;
}

.cb-editor-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Editor layout: Simulador + Panel lateral */
.cb-editor-body {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  min-height: 0;
  overflow: hidden;
}

.cb-editor-body.no-edit-panel {
  grid-template-columns: 1fr;
}
.cb-editor-body.no-edit-panel .cb-edit-panel {
  display: none;
}

/* Simulador de Chat */
.cb-chat-simulator {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background-color: #efeae2;
  background-image: radial-gradient(rgba(0,0,0,.04) 1px, transparent 0),
                    radial-gradient(rgba(0,0,0,.04) 1px, transparent 0);
  background-size: 24px 24px;
  background-position: 0 0, 12px 12px;
}

.cb-chat-window {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cb-chat-window::-webkit-scrollbar {
  width: 5px;
}
.cb-chat-window::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,.12);
  border-radius: 4px;
}

/* Burbujas del bot en el simulador */
.cb-bubble {
  max-width: 75%;
  background: #fff;
  border-radius: 0 8px 8px 8px;
  padding: 8px 12px;
  font-size: .84rem;
  color: #111b21;
  position: relative;
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
  cursor: pointer;
  transition: box-shadow .15s, transform .1s;
  animation: cb-bubble-in .25s ease-out;
  word-wrap: break-word;
}
.cb-bubble:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
  transform: translateY(-1px);
}
.cb-bubble.active {
  box-shadow: 0 0 0 2px var(--mico-brand), 0 2px 8px rgba(37,99,235,.2);
}

.cb-bubble::before {
  content: '';
  position: absolute;
  left: -6px;
  top: 0;
  width: 0;
  height: 0;
  border-top: 6px solid #fff;
  border-left: 6px solid transparent;
}

.cb-bubble p {
  margin: 0;
  line-height: 1.45;
  white-space: pre-wrap;
}

.cb-bubble-time {
  display: block;
  text-align: right;
  font-size: .6rem;
  color: #667781;
  margin-top: 4px;
}

.cb-bubble-empty {
  color: #94a3b8;
  font-style: italic;
}

/* Burbujas multimedia */
.cb-bubble-media {
  padding: 4px;
  max-width: 280px;
}
.cb-bubble-media img,
.cb-bubble-media video {
  width: 100%;
  border-radius: 6px;
  display: block;
}

.cb-bubble-media .cb-media-placeholder {
  width: 100%;
  height: 140px;
  background: #f1f5f9;
  border: 2px dashed #cbd5e1;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-size: .75rem;
  gap: 6px;
  transition: border-color .2s, background .2s;
}
.cb-bubble-media .cb-media-placeholder i {
  font-size: 1.5rem;
  opacity: .4;
}
.cb-bubble-media .cb-media-placeholder:hover,
.cb-bubble-media .cb-media-placeholder.dragover {
  border-color: var(--mico-brand);
  background: rgba(var(--mico-brand-r),var(--mico-brand-g),var(--mico-brand-b),.05);
  color: var(--mico-brand);
}

.cb-bubble-caption {
  padding: 4px 8px 2px;
  font-size: .8rem;
  color: #111b21;
  margin: 0;
}

/* Botones interactivos estilo WhatsApp */
.cb-interactive-group {
  max-width: 75%;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: -2px;
  animation: cb-bubble-in .3s ease-out;
}

.cb-wa-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: .82rem;
  font-weight: 500;
  color: #0076d6;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
  transition: background .15s;
}
.cb-wa-button:hover {
  background: #f0f7ff;
}

.cb-wa-button i {
  font-size: .7rem;
}

/* Lista estilo WhatsApp */
.cb-wa-list-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: .82rem;
  font-weight: 500;
  color: #0076d6;
  cursor: default;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
  max-width: 75%;
}

/* Add bubble FAB */
.cb-add-bubble-row {
  padding: 12px 24px;
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  justify-content: center;
  background: linear-gradient(to top, rgba(239,234,226,.9), transparent);
}

.cb-add-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
  border: 1px solid var(--mico-line);
  background: #fff;
  color: var(--mico-dark);
  cursor: pointer;
  transition: all .15s;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.cb-add-btn:hover {
  border-color: var(--mico-brand);
  color: var(--mico-brand);
  box-shadow: 0 2px 8px rgba(37,99,235,.15);
  transform: translateY(-1px);
}
.cb-add-btn i {
  font-size: .7rem;
}

/* ── Panel de Edición Lateral ── */
.cb-edit-panel {
  background: #fff;
  border-left: 1px solid var(--mico-line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: cb-slide-in .2s ease-out;
}

.cb-edit-panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--mico-line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f8fafc;
  flex-shrink: 0;
}

.cb-edit-panel-header h4 {
  font-size: .82rem;
  font-weight: 700;
  color: var(--mico-dark);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 7px;
}

.cb-edit-panel-close {
  background: none;
  border: none;
  color: var(--mico-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 2px;
  border-radius: 4px;
  transition: background .12s;
}
.cb-edit-panel-close:hover {
  background: #f1f5f9;
  color: var(--mico-dark);
}

.cb-edit-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
.cb-edit-panel-body::-webkit-scrollbar {
  width: 5px;
}
.cb-edit-panel-body::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,.1);
  border-radius: 4px;
}

.cb-edit-panel-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--mico-line);
  background: #f8fafc;
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Formulario dentro del panel de edición */
.cb-field-group {
  margin-bottom: 14px;
}

.cb-field-label {
  display: block;
  font-size: .68rem;
  font-weight: 700;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 5px;
}

.cb-field-input {
  width: 100%;
  border: 1px solid var(--mico-line);
  border-radius: var(--radius-sm);
  font-size: .82rem;
  padding: 8px 10px;
  color: var(--mico-dark);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
.cb-field-input:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(37,99,235,.08);
  outline: none;
}
textarea.cb-field-input {
  resize: vertical;
  min-height: 80px;
}

.cb-field-hint {
  font-size: .63rem;
  color: var(--mico-muted);
  margin-top: 3px;
}

.cb-char-counter {
  font-size: .62rem;
  color: var(--mico-muted);
  text-align: right;
  margin-top: 2px;
}
.cb-char-counter.over {
  color: var(--mico-danger);
  font-weight: 700;
}

/* Upload zone en el panel de edición */
.cb-upload-zone {
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius-sm);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  margin-bottom: 10px;
}
.cb-upload-zone:hover,
.cb-upload-zone.dragover {
  border-color: var(--mico-brand);
  background: rgba(var(--mico-brand-r),var(--mico-brand-g),var(--mico-brand-b),.04);
}

.cb-upload-zone i {
  font-size: 1.6rem;
  color: #94a3b8;
  display: block;
  margin-bottom: 6px;
}

.cb-upload-zone span {
  font-size: .75rem;
  color: var(--mico-muted);
}

.cb-upload-preview {
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 10px;
  position: relative;
}
.cb-upload-preview img,
.cb-upload-preview video {
  width: 100%;
  display: block;
  border-radius: var(--radius-sm);
}
.cb-upload-preview .cb-upload-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0,0,0,.6);
  color: #fff;
  border: none;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: .65rem;
  transition: background .15s;
}
.cb-upload-preview .cb-upload-remove:hover {
  background: rgba(239,68,68,.9);
}

/* Opciones interactivas en el panel lateral */
.cb-option-card {
  background: #f8fafc;
  border: 1px solid var(--mico-line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 8px;
  transition: border-color .15s;
}
.cb-option-card:hover {
  border-color: #93c5fd;
}

.cb-option-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.cb-option-num {
  font-size: .7rem;
  font-weight: 700;
  color: var(--mico-brand);
}

.cb-option-actions {
  display: flex;
  gap: 3px;
}

.cb-option-actions button {
  background: none;
  border: none;
  padding: 2px 4px;
  cursor: pointer;
  font-size: .7rem;
  color: #94a3b8;
  border-radius: 3px;
  transition: color .1s, background .1s;
}
.cb-option-actions button:hover {
  background: #f1f5f9;
  color: var(--mico-dark);
}

.cb-option-dest {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: .65rem;
  color: var(--mico-muted);
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed #e2e8f0;
}
.cb-option-dest i {
  color: var(--mico-brand);
}

/* Empty states */
.cb-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--mico-muted);
  text-align: center;
  padding: 40px 24px;
}
.cb-empty-state i {
  font-size: 3rem;
  opacity: .12;
  margin-bottom: 14px;
}
.cb-empty-state h5 {
  font-size: .9rem;
  font-weight: 700;
  color: #475569;
  margin: 0 0 6px;
}
.cb-empty-state p {
  font-size: .78rem;
  margin: 0;
  max-width: 240px;
}

/* Section dividers in edit panel */
.cb-divider {
  height: 1px;
  background: var(--mico-line);
  margin: 16px 0;
}

.cb-section-title {
  font-size: .72rem;
  font-weight: 700;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.cb-section-title i {
  color: var(--mico-brand);
  font-size: .7rem;
}

/* Bot config form */
.cb-config-form {
  padding: 16px;
}

.cb-config-form .cb-field-group:last-child {
  margin-bottom: 0;
}

/* Sección de tabs en el panel lateral */
.cb-edit-tabs {
  display: flex;
  border-bottom: 1px solid var(--mico-line);
  background: #fff;
  flex-shrink: 0;
}

.cb-edit-tab {
  flex: 1;
  padding: 10px 8px;
  font-size: .72rem;
  font-weight: 600;
  color: var(--mico-muted);
  text-align: center;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}
.cb-edit-tab:hover {
  color: var(--mico-dark);
}
.cb-edit-tab.active {
  color: var(--mico-brand);
  border-bottom-color: var(--mico-brand);
}

/* Toast de estado guardado */
.cb-save-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: .82rem;
  font-weight: 600;
  color: #fff;
  z-index: 9000;
  animation: cb-toast-in .3s ease-out;
  box-shadow: 0 6px 20px rgba(0,0,0,.15);
}
.cb-save-toast.success {
  background: var(--mico-green);
}
.cb-save-toast.error {
  background: var(--mico-danger);
}

/* Animations */
@keyframes cb-bubble-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes cb-slide-in {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes cb-toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Chatbot Builder responsive */
@media (max-width: 1200px) {
  .cb-shell {
    grid-template-columns: 240px 220px minmax(0, 1fr);
  }
  .cb-editor-body {
    grid-template-columns: minmax(0, 1fr) 300px;
  }
}

@media (max-width: 992px) {
  .cb-shell {
    grid-template-columns: 220px minmax(0, 1fr);
  }
  .cb-panel-tree {
    display: none;
  }
  .cb-editor-body {
    grid-template-columns: 1fr;
  }
  .cb-edit-panel {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 340px;
    z-index: 50;
    box-shadow: -4px 0 20px rgba(0,0,0,.1);
  }
}

/* ─── RESPONSIVE ──────────────────────────────────────────  */
@media (max-width: 1180px) {
  .chat-shell {
    grid-template-columns: 300px minmax(0, 1fr);
  }
  .chat-side { display: none; }
}

@media (max-width: 860px) {
  .chat-shell {
    grid-template-columns: 1fr;
    height: auto;
  }
  .chat-list {
    max-height: 260px;
    border-right: 0;
    border-bottom: 1px solid var(--mico-line);
  }
  .compose-row,
  .media-row { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .container-fluid { padding-inline: 12px; }
}

@media (max-width: 992px) {
  .table { 
    display: block; 
    width: 100%;
    overflow-x: auto; 
    white-space: nowrap; 
    -webkit-overflow-scrolling: touch;
  }
}

.app-main {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}
