/* ZIC Landing — Chat popup
 *
 * Strategy (parity with landing-multipost-admin.css):
 *   1. The inner `ac-*` panel is rendered VERBATIM from the admin chat panel
 *      (zic_admin/templates/dashboard/chat.html). To get the exact same look,
 *      we copy the whole `admin-chat.css` rules below — only the workspace
 *      shell selectors (`.aw-app:has(...)`) are skipped, replaced by the
 *      landing overlay shell at the end of this file.
 *   2. The bottom section defines the landing-only overlay shell:
 *      .zh-chat-overlay / .zh-chat-overlay-card / .zh-chat-overlay-close
 *      plus the `.ac-empty--guest` block and responsive breakpoints
 *      (master-detail tablet, full-screen mobile).
 *   3. NO restyling of `.ac-*` rules — keep admin look (white card,
 *      indigo accent #6366f1, soft greys). The landing layer only adds the
 *      popup chrome and the guest empty-state CTA.
 */

/* ============================================================================
 * Inner panel — copied verbatim from zic_admin_python/static/css/admin-chat.css
 * (workspace-shell `.aw-*:has(#ac-root)` rules omitted on purpose ; we size
 * the panel via the overlay shell below.)
 * ============================================================================ */

#ac-root.ac-root {
  --ac-primary: #6366f1;
  --ac-primary-dark: #4f46e5;
  --ac-slate50: #f8fafc;
  --ac-slate100: #f1f5f9;
  --ac-slate200: #e2e8f0;
  --ac-slate400: #94a3b8;
  --ac-slate500: #64748b;
  --ac-slate600: #475569;
  --ac-slate800: #1e293b;
  --ac-radius: 12px;
  --ac-msg-radius: 16px;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  color: var(--ac-slate800);
}

.ac-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  border: 1px solid var(--ac-slate200);
  border-radius: var(--ac-radius);
  overflow: hidden;
  background: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.ac-sidebar {
  width: 100%;
  max-width: 360px;
  flex-shrink: 0;
  min-height: 0;
  border-right: 1px solid var(--ac-slate200);
  display: flex;
  flex-direction: column;
  background: #fff;
}

.ac-sidebar-head {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--ac-slate200);
}

.ac-sidebar-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.ac-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ac-slate800);
}

.ac-filter {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--ac-slate600);
  cursor: pointer;
  user-select: none;
}

.ac-filter input {
  accent-color: var(--ac-primary);
}

.ac-iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #818cf8, var(--ac-primary-dark));
  color: #fff;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

.ac-iconbtn:hover {
  transform: translateY(-1px);
}

.ac-iconbtn svg {
  width: 18px;
  height: 18px;
}

.ac-new-btn {
  flex-shrink: 0;
}

.ac-list-wrap {
  flex: 1;
  overflow-y: auto;
  min-height: 200px;
}

.ac-conv-list {
  list-style: none;
  margin: 0;
  padding: 8px;
}

.ac-conv-item {
  margin: 0;
}

.ac-conv-item.is-pinned .ac-conv-btn {
  border-left: 3px solid var(--ac-primary);
  padding-left: 7px;
}

.ac-conv-item.is-pinned .ac-conv-name::before {
  content: "📌";
  margin-right: 6px;
  font-size: 11px;
  vertical-align: 1px;
}

.ac-textbtn.is-on {
  background: rgba(99, 102, 241, 0.14);
  color: var(--ac-primary-dark);
  border-radius: 8px;
}

.ac-conv-btn {
  width: 100%;
  text-align: left;
  padding: 10px 10px;
  border: none;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  transition: background 0.15s ease;
  color: inherit;
  font: inherit;
}

.ac-conv-btn:hover {
  background: var(--ac-slate50);
}

.ac-conv-item.is-active .ac-conv-btn {
  background: rgba(99, 102, 241, 0.1);
  outline: 1px solid rgba(99, 102, 241, 0.25);
}

.ac-conv-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--ac-slate200);
  flex-shrink: 0;
  object-fit: cover;
}

.ac-conv-avatar--fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--ac-slate600);
}

.ac-conv-body {
  flex: 1;
  min-width: 0;
}

.ac-conv-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.ac-conv-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ac-conv-time {
  font-size: 11px;
  color: var(--ac-slate400);
  flex-shrink: 0;
}

.ac-conv-preview {
  font-size: 12px;
  color: var(--ac-slate500);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ac-conv-unread {
  margin-top: 4px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--ac-primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ac-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--ac-slate500);
  font-size: 13px;
}

/* Main thread */
.ac-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--ac-slate50);
  position: relative;
}

.ac-main-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--ac-slate200);
  background: #fff;
  flex-shrink: 0;
}

.ac-back {
  display: none;
  transform: rotate(90deg);
  background: var(--ac-slate100);
  color: var(--ac-slate800);
  box-shadow: none;
}

.ac-main-peer {
  flex: 1;
  min-width: 0;
}

.ac-peer-name {
  font-weight: 600;
  font-size: 15px;
}

.ac-peer-status {
  font-size: 12px;
  color: var(--ac-slate500);
  line-height: 1.35;
}

.ac-peer-status.is-online {
  color: #16a34a;
}

.ac-peer-status.is-away {
  color: #ca8a04;
}

.ac-main-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.ac-textbtn {
  border: none;
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  color: var(--ac-primary);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
}

.ac-textbtn:hover {
  background: rgba(99, 102, 241, 0.08);
}

.ac-typing {
  font-size: 12px;
  color: var(--ac-slate500);
  font-style: italic;
  padding: 4px 16px 0;
  margin: 0;
  flex-shrink: 0;
}

.ac-thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  -webkit-overflow-scrolling: touch;
}

.ac-thread-inner {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 0 0 auto;
}

.ac-msg-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 85%;
  animation: acFadeUp 0.22s ease;
}

.ac-msg-row.is-mine {
  align-self: flex-end;
  align-items: flex-end;
}

@keyframes acFadeUp {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ac-msg-row {
    animation: none;
  }
}

.ac-bubble {
  padding: 10px 14px;
  border-radius: var(--ac-msg-radius);
  background: #fff;
  border: 1px solid var(--ac-slate200);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
}

.ac-msg-row.is-mine .ac-bubble {
  background: linear-gradient(135deg, #818cf8, var(--ac-primary-dark));
  color: #fff;
  border-color: transparent;
}

.ac-bubble.is-deleted {
  opacity: 0.55;
  font-style: italic;
}

.ac-msg-meta {
  font-size: 10px;
  color: var(--ac-slate400);
  margin-top: 4px;
  padding: 0 4px;
}

.ac-msg-row.is-mine .ac-msg-meta {
  color: var(--ac-slate400);
}

.ac-msg-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.ac-msg-row:hover .ac-msg-actions {
  opacity: 1;
}

.ac-msg-actions button {
  font-size: 11px;
  border: none;
  background: var(--ac-slate100);
  border-radius: 6px;
  padding: 2px 8px;
  cursor: pointer;
  color: var(--ac-slate600);
}

.ac-loadmore {
  align-self: center;
  margin-top: 8px;
  border: 1px solid var(--ac-slate200);
  background: #fff;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ac-primary);
  cursor: pointer;
}

.ac-loadmore:hover {
  background: var(--ac-slate50);
}

.ac-composer {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--ac-slate200);
  background: #fff;
  align-items: flex-end;
  flex-shrink: 0;
}

.ac-input {
  flex: 1;
  border: 1px solid var(--ac-slate200);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  resize: none;
  max-height: 140px;
  min-height: 44px;
}

.ac-input:focus {
  outline: none;
  border-color: var(--ac-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.ac-send {
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-weight: 600;
  font-size: 14px;
  color: #fff;
  background: linear-gradient(135deg, #818cf8, var(--ac-primary-dark));
  cursor: pointer;
  flex-shrink: 0;
}

.ac-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ac-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  color: var(--ac-slate500);
  font-size: 14px;
  text-align: center;
}

.ac-main.has-conv .ac-placeholder {
  display: none;
}

.ac-main-head.ac-is-hidden,
.ac-composer.ac-is-hidden {
  display: none !important;
}

.ac-main.has-conv .ac-main-head:not(.ac-is-hidden),
.ac-main.has-conv .ac-composer:not(.ac-is-hidden) {
  display: flex;
}

/* Modal interne (Nouvelle conversation) */
.ac-modal {
  position: absolute;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.ac-modal[hidden] {
  display: none !important;
}

.ac-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}

.ac-modal-panel {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: 85vh;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: acModalIn 0.2s ease;
}

@keyframes acModalIn {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ac-modal-panel {
    animation: none;
  }
}

.ac-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--ac-slate200);
}

.ac-modal-head h2 {
  margin: 0;
  font-size: 1rem;
}

.ac-modal-search {
  margin: 12px 16px 8px;
  padding: 10px 12px;
  border: 1px solid var(--ac-slate200);
  border-radius: 10px;
  font: inherit;
}

.ac-user-list {
  list-style: none;
  margin: 0;
  padding: 8px 12px 12px;
  overflow-y: auto;
  flex: 1;
  max-height: 48vh;
}

.ac-user-btn {
  width: 100%;
  text-align: left;
  padding: 10px 10px;
  border: none;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: center;
  font: inherit;
}

.ac-user-btn:hover {
  background: var(--ac-slate50);
}

.ac-modal-empty {
  padding: 16px;
  text-align: center;
  color: var(--ac-slate500);
  font-size: 13px;
}

.ac-modal-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--ac-slate200);
  display: flex;
  justify-content: flex-end;
}

.ac-btn {
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  border: none;
}

.ac-btn--ghost {
  background: var(--ac-slate100);
  color: var(--ac-slate800);
}

/* Variante primaire (landing-only — utilisée par le CTA guest). */
.ac-btn--primary {
  background: linear-gradient(135deg, #818cf8, #4f46e5);
  color: #fff;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

.ac-btn--primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
}

/* Mobile : liste pleine largeur, thread en overlay */
@media (max-width: 899px) {
  .ac-layout {
    flex-direction: column;
    position: relative;
    flex: 1;
    min-height: 0;
  }

  .ac-sidebar {
    max-width: none;
    border-right: none;
    flex: 1;
    min-height: 0;
  }

  .ac-main {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 5;
    background: var(--ac-slate50);
    min-height: 0;
  }

  .ac-layout.ac-show-thread .ac-sidebar {
    display: none;
  }

  .ac-layout.ac-show-thread .ac-main {
    display: flex;
    min-height: 0;
  }

  .ac-back {
    display: inline-flex;
  }
}

/* Desktop / large tablette */
@media (min-width: 900px) {
  .ac-layout {
    flex-direction: row;
  }

  .ac-sidebar {
    width: 320px;
  }
}


/* ============================================================================
 * Landing overlay shell — parité visuelle avec .zh-mp-overlay (multipost).
 * Cette partie est landing-only ; aucun rule `.ac-*` n'est redéfinie ici.
 * ============================================================================ */

.zh-chat-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(7, 9, 25, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 0.22s ease;
}

.zh-chat-overlay.is-open {
  opacity: 1;
}

.zh-chat-overlay[hidden] {
  display: none !important;
}

body.zh-chat-overlay-open {
  overflow: hidden;
}

.zh-chat-overlay-card {
  position: relative;
  width: min(960px, calc(100vw - 32px));
  height: min(620px, calc(100vh - 64px));
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 24px 64px -16px rgba(8, 12, 30, 0.45);
  overflow: hidden;
  transform: translateY(12px);
  transition: transform 0.22s ease;
  display: flex;
  flex-direction: column;
}

.zh-chat-overlay.is-open .zh-chat-overlay-card {
  transform: translateY(0);
}

.zh-chat-overlay-card:focus {
  outline: none;
}

.zh-chat-overlay-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  background: rgba(15, 18, 40, 0.08);
  color: #1e293b;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.zh-chat-overlay-close:hover {
  background: rgba(15, 18, 40, 0.14);
  transform: scale(1.06);
}

.zh-chat-overlay-close svg {
  width: 18px;
  height: 18px;
}

/* Le panneau ac-root remplit la carte overlay (la sidebar admin a une
   max-width:360px par défaut — on garde, et on ajuste juste l'enveloppe). */
.ac-root--landing {
  height: 100%;
  border: 0;
  flex: 1;
}

.ac-root--landing .ac-layout {
  height: 100%;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

/* Petit padding-top pour éviter que le titre touche le bouton de fermeture
   sur desktop ; sur mobile la close passe en haut-gauche-relative. */
.ac-root--landing .ac-sidebar-head {
  padding-right: 48px;
}

/* État vide invité — vit dans la sidebar du même ac-root. */
.ac-empty--guest {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 28px 20px;
  color: var(--ac-slate800, #1e293b);
}

.ac-empty--guest[hidden] {
  display: none !important;
}

.ac-empty--guest .ac-empty-illu {
  width: 64px;
  height: 64px;
  color: var(--ac-primary, #6366f1);
  opacity: 0.85;
  margin-bottom: 4px;
}

.ac-empty--guest .ac-empty-title {
  margin: 4px 0 0;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--ac-slate800, #1e293b);
}

.ac-empty--guest .ac-empty-desc {
  margin: 0 0 14px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ac-slate500, #64748b);
}

.ac-empty--guest .ac-btn {
  width: 100%;
  padding: 10px 16px;
  font-size: 14px;
}

.ac-empty--guest .ac-btn + .ac-btn {
  margin-top: 6px;
}

/* Mode invité — désactive visuellement les actions et le composer pour bien
   signaler que la saisie n'est pas dispo. Le JS intercepte aussi les clics. */
.ac-root--landing[data-zc-mode="guest"] .ac-new-btn,
.ac-root--landing[data-zc-mode="guest"] .ac-filter,
.ac-root--landing[data-zc-mode="guest"] .ac-composer {
  opacity: 0.55;
}

.ac-root--landing[data-zc-mode="guest"] .ac-input {
  background: var(--ac-slate50, #f8fafc);
  cursor: not-allowed;
}

/* ─── Responsive : tablette (≤ 899px) master-detail, mobile (<640px) full-screen ─── */
@media (max-width: 899px) {
  .zh-chat-overlay {
    padding: 8px;
  }
  .zh-chat-overlay-card {
    width: 100%;
    height: 100%;
    max-width: none;
  }
}

@media (max-width: 639px) {
  .zh-chat-overlay {
    padding: 0;
  }
  .zh-chat-overlay-card {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
  }
  .zh-chat-overlay-close {
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
  }
  .ac-root--landing .ac-sidebar-head {
    padding-right: 52px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .zh-chat-overlay,
  .zh-chat-overlay-card {
    transition: none;
    transform: none;
  }
}
