/* mejoras.css - Sobrescritura visual operativa y responsive para Alma */
:root {
  --nav-btn-min: 44px;
  --header-chat-h: 74px;
  --header-chat-compact-h: 48px;
}

/* 1. LAYOUT Y NAVEGACIÓN (5 ÍTEMS CON CONTADORES) */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar-nav .nav-item,
.mobile-bottom-nav .bottom-item {
  min-height: var(--nav-btn-min);
  min-width: var(--nav-btn-min);
}
.sidebar-nav .nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
}
.mobile-bottom-nav {
  display: none;
  grid-template-columns: repeat(5, 1fr) !important;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  padding-bottom: max(6px, env(safe-area-inset-bottom, 0px));
  z-index: 60;
}
.bottom-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 2px;
}
.bottom-item.active {
  color: var(--color-primary);
  font-weight: 600;
}

/* Contadores / Badges sin polling de fondo */
.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  color: #fff;
  background: var(--color-primary, #b45309);
  border-radius: 9px;
  margin-left: auto;
}
.bottom-item .nav-badge {
  position: absolute;
  top: 3px;
  right: 22%;
  min-width: 16px;
  height: 16px;
  font-size: 10px;
  margin-left: 0;
}

/* 2. VISTAS Y SCROLLER ÚNICO */
.content-area {
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  position: relative;
  max-width: 860px;
}
.view-panel {
  display: none;
  flex-direction: column;
  gap: 18px;
}
.view-panel.active {
  display: flex;
}

/* 3. INICIO ESTABLE: IMAGEN GRANDE SIN RECORTE */
#view-home .editorial-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}
#view-home .alma-presence {
  display: inline-flex;
  align-items: flex-end;
  gap: 12px;
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
}
#view-home .alma-portrait-wrap,
#view-home .alma-portrait {
  width: 180px;
  height: 208px;
  overflow: visible;
  border-radius: 0;
  background: transparent;
}
#view-home .alma-img {
  width: 180px;
  height: auto;
  max-width: 100%;
  object-fit: contain;
  display: block;
  mix-blend-mode: normal;
}
[data-theme="dark"] #view-home .alma-img {
  opacity: 0.96;
}

/* 4. CABECERA PROPIA DE CHAT (COMPACTABLE Y DESPLEGABLE) */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  transition: padding 0.15s ease, height 0.15s ease;
  position: sticky;
  top: 0;
  z-index: 25;
}
.chat-header-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.chat-portrait-wrap {
  width: 72px;
  height: 80px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
  transition: width 0.15s ease, height 0.15s ease;
}
.chat-alma-img {
  width: 72px;
  height: auto;
  max-width: none;
  object-fit: contain;
  border: none;
  border-radius: 0;
  background: transparent;
}
.chat-header-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.chat-name {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
}
.chat-status {
  font-size: 13px;
  color: var(--text-muted);
}
.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.btn-history-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  cursor: pointer;
  min-height: 44px;
}
.btn-toggle-compact {
  font-size: 16px;
  line-height: 1;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
}

/* Modo compacto al scrollear o escribir */
.chat-header.compact {
  padding: 4px 10px;
}
.chat-header.compact .chat-portrait-wrap {
  width: 32px;
  height: 32px;
  overflow: hidden;
}
.chat-header.compact .chat-alma-img {
  width: 32px;
}
.chat-header.compact .chat-name {
  font-size: 15px;
}
.chat-header.compact .chat-status {
  display: none;
}

/* 5. TRES PUNTOS ANIMADOS Y LOADER CSS */
.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 4px;
}
.typing-dots .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: currentColor;
  opacity: 0.35;
  animation: dotBlink 1.2s infinite ease-in-out;
}
.typing-dots .dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dots .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotBlink {
  0%, 100% { opacity: 0.25; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1.15); }
}
@media (prefers-reduced-motion: reduce) {
  .typing-dots .dot {
    animation: none;
    opacity: 0.7;
    transform: none;
  }
}

.loader-status {
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 500;
}

/* 6. BANNER DE MENSAJE PENDIENTE Y RETOMA SEGURA */
.pending-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #fef3c7;
  color: #92400e;
  padding: 10px 14px;
  border: 1px solid #f59e0b;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
[data-theme="dark"] .pending-banner {
  background: #3b280c;
  color: #fde68a;
  border-color: #92400e;
}
.pending-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.btn-sm {
  min-height: 44px !important;
  padding: 0 14px !important;
  font-size: 13px !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* 7. BOTÓN FLOTANTE "IR AL ÚLTIMO" */
.btn-scroll-bottom {
  position: sticky;
  bottom: 76px;
  align-self: center;
  margin: 0 auto;
  background: var(--bg-surface);
  color: var(--color-primary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  cursor: pointer;
  z-index: 30;
  min-height: 44px;
  min-width: 44px;
}

/* 8. COMPOSER AUTOCRECIMIENTO Y RESPONSIVE IPHONE */
.composer-form {
  position: sticky;
  bottom: 0;
  z-index: 20;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-top: 8px;
  padding-bottom: max(4px, env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: flex-end;
}
.composer-textarea {
  flex: 1;
  min-height: 44px;
  max-height: 140px;
  box-sizing: border-box;
  padding: 11px 14px;
  font-size: 15px;
  line-height: 1.45;
  resize: none;
  overflow-y: auto;
  border: none;
  background: transparent;
  color: var(--text-main);
  font-family: inherit;
}
.composer-textarea:focus {
  outline: none;
}
.composer-submit {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--color-primary);
  cursor: pointer;
  padding: 10px;
}
.chat-thread {
  flex: 1;
  min-height: 120px;
}

/* Aviso de error único y discreto */
.chat-error-notice {
  background: #fef2f2 !important;
  color: #991b1b !important;
  border: 1px solid #fca5a5 !important;
  border-radius: var(--radius-md, 8px);
  padding: 12px 14px;
  margin: 8px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
[data-theme="dark"] .chat-error-notice {
  background: #2d1515 !important;
  color: #fca5a5 !important;
  border-color: #7f1d1d !important;
}
.error-notice-text {
  margin: 0;
  font-size: 14px;
  line-height: 1.4;
}
.error-notice-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.error-notice-actions button {
  min-height: 44px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
}
.error-bubble {
  background: #fef2f2 !important;
  color: #991b1b !important;
  border: 1px solid #f87171 !important;
}
[data-theme="dark"] .error-bubble {
  background: #381616 !important;
  color: #fca5a5 !important;
  border-color: #991b1b !important;
}

/* Tarjetas de revisión, miniaturas e imágenes */
.thumb-wrapper {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.art-preview-image {
  max-width: 140px;
  max-height: 140px;
  object-fit: cover;
  border-radius: var(--radius-sm, 6px);
  border: 1px solid var(--border-color);
  cursor: zoom-in;
  transition: transform 0.15s ease;
}
.art-preview-image:hover {
  transform: scale(1.03);
}
.thumb-caption {
  font-size: 12px;
  color: var(--text-muted);
  max-width: 140px;
  margin: 0;
}
.live-images {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin: 10px 0;
}
.review-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md, 8px);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}
.review-card-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}
.review-card-status {
  font-size: 12px;
}
.copy-box {
  white-space: pre-wrap;
  background: var(--bg-subtle, rgba(0,0,0,0.03));
  padding: 8px 10px;
  border-radius: var(--radius-sm, 4px);
  font-size: 14px;
  line-height: 1.45;
  margin: 0;
}

/* Agenda / Tareas: Distinción explícita de estado sin sobreafirmar */
.task-it {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md, 8px);
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.task-title {
  font-weight: 600;
  font-size: 15px;
  flex: 1;
  min-width: 160px;
}
.task-status-badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 12px;
  font-weight: 500;
}
.status-publicado {
  background: #dcfce7;
  color: #166534;
}
[data-theme="dark"] .status-publicado {
  background: #14381e;
  color: #86efac;
}
.status-programado {
  background: #dbeafe;
  color: #1e40af;
}
[data-theme="dark"] .status-programado {
  background: #172554;
  color: #93c5fd;
}
.status-pendiente {
  background: #f3f4f6;
  color: #4b5563;
}
[data-theme="dark"] .status-pendiente {
  background: #262626;
  color: #d1d5db;
}

/* Barra de offline y reconexión */
.offline-bar {
  background: #dc2626;
  color: #ffffff;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

/* Botones con accesibilidad táctil */
button, .btn-primary, .btn-secondary, .btn-chip, .history-choice {
  min-height: 44px;
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .mobile-bottom-nav { display: grid; }
  .content-area {
    padding: 12px 14px calc(76px + env(safe-area-inset-bottom, 0px)) 14px;
  }
  .chat-header {
    border-radius: 0;
    margin-left: -14px;
    margin-right: -14px;
    border-left: none;
    border-right: none;
  }
}

html, body { height: 100%; overflow: hidden; }
.app-layout { height: var(--alma-vh, 100dvh); min-height: 0; overflow: hidden; }
.main-wrapper { min-width: 0; min-height: 0; height: 100%; }
.mobile-topbar, .topbar-status { flex-shrink: 0; }
.content-area { min-height: 0; box-sizing: border-box; scroll-behavior: auto; }
#view-chat { min-height: 100%; gap: 14px; }
#view-chat .chat-thread { overflow: visible; max-height: none; min-height: 110px; flex: 1; }
.messages-list { display: grid; gap: 10px; margin: 4px 0; }
.messages-list h2 { font-size: 22px; margin: 0 0 6px; }
.history-choice { width: 100%; text-align: left; min-height: 48px; font-size: 16px; }
.chat-header-actions button, .btn-scroll-bottom { min-width: 44px; min-height: 44px; }
.keyboard-open .mobile-bottom-nav { display: none !important; }
@media (max-width: 768px) {
  .chat-header { gap: 6px; padding: 8px; }
  .chat-header-info { max-width: 128px; }
  .chat-status { font-size: 12px; }
  .chat-header-actions { gap: 4px; }
  .btn-history-toggle { padding: 6px; }
  .content-area { padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }
  .keyboard-open .content-area { padding-bottom: 8px; }
}

.mobile-topbar .sidebar-brand { margin-right: auto; }
.mobile-topbar { gap: 8px; }
.account-dialog .session-row { padding: 14px 0; border-bottom: 1px solid var(--border-color); }
.bottom-item { font-size: 12px; }
.chat-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.chat-tools button { min-height: 44px; }
.chat-tools .helper-text { font-size: 13px; margin: 0; }
