/* Scope pour éviter de flinguer Elementor */
#gpro-chatpdf.gcp {
  /* Dark par défaut */
  --bg: #0f172a;
  --panel: #111827;
  --panel2: #0b1220;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --border: rgba(255,255,255,.08);
  --accent: #22c55e;

  display: flex;
  gap: 12px;
  height: 640px;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  position: relative;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

/* Theme */
#gpro-chatpdf.gcp.theme-light{
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel2: #f1f5f9;
  --text: #0f172a;
  --muted: #475569;
  --border: rgba(15,23,42,.12);
  --accent: #16a34a;
}
#gpro-chatpdf.gcp.theme-light .gcp-source{ color: #3730a3; }
#gpro-chatpdf.gcp.theme-light .gcp-msg.ai{ background: rgba(15,23,42,.04); }
#gpro-chatpdf.gcp.theme-light .gcp-drawer{ background: #ffffff; }
#gpro-chatpdf.gcp.theme-light .gcp-pdfloader{ background: rgba(255,255,255,0.75); }
#gpro-chatpdf.gcp.theme-light .gcp-spinner{
  border-color: rgba(15,23,42,0.18);
  border-top-color: rgba(15,23,42,0.8);
}

.gcp-chat {
  flex: 0 0 var(--chatW, 52%);
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--panel), var(--panel2));
  /* iOS/Safari: autorise les enfants flex (messages) à scroller */
  min-height: 0;
}

.gcp-header-right{ display:flex; align-items:center; gap:10px; }

.gcp-about{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:38px;
  height:38px;
  border-radius:12px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.04);
  color: var(--text);
  cursor:pointer;
  font-weight:800;
}
.gcp-about:hover{ background: rgba(255,255,255,.06); }
#gpro-chatpdf.gcp.theme-light .gcp-about:hover{ background: rgba(15,23,42,.04); }

.gcp-header {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
}

.gcp-header-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
}
.gcp-header-left{ min-width:0; }

.gcp-theme{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:38px;
  height:38px;
  border-radius:12px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.04);
  color: var(--text);
  cursor:pointer;
  flex:0 0 auto;
}
.gcp-theme:hover{ background: rgba(255,255,255,.06); }
#gpro-chatpdf.gcp.theme-light .gcp-theme:hover{ background: rgba(15,23,42,.04); }
.gcp-theme-ic{ font-size:16px; line-height:1; }

.gcp-title {
  font-weight: 700;
  letter-spacing: .2px;
}

.gcp-subtitle {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.gcp-messages {
  flex: 1;
  padding: 14px;
  overflow: auto;
  /* iOS: inertie + scroll fiable dans un flex column */
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.gcp-msg {
  max-width: 85%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  line-height: 1.35;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.gcp-msg.me {
  margin-left: auto;
  background: rgba(34,197,94,.12);
  border-color: rgba(34,197,94,.25);
}

.gcp-msg.ai {
  background: rgba(255,255,255,.05);
}

.gcp-msg.err {
  background: rgba(239,68,68,.10);
  border-color: rgba(239,68,68,.25);
}

.gcp-sources {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
}

.gcp-source {
  color: #c7d2fe;
  text-decoration: none;
  opacity: .9;
}
.gcp-source:hover { opacity: 1; text-decoration: underline; }

.gcp-inputbar {
  display: flex;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: rgba(0,0,0,.15);
}

.gcp-input {
  flex: 1;
  resize: none;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.04);
  color: var(--text);
  padding: 10px 12px;
  outline: none;
  min-height: 44px;
}

.gcp-input:focus {
  border-color: rgba(34,197,94,.35);
  box-shadow: 0 0 0 3px rgba(34,197,94,.12);
}

.gcp-send {
  border-radius: 12px;
  border: 1px solid rgba(34,197,94,.35);
  background: rgba(34,197,94,.18);
  color: var(--text);
  padding: 0 16px;
  min-width: 110px;
  cursor: pointer;
  font-weight: 700;
}

.gcp-send:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.gcp-hint {
  padding: 8px 12px 12px;
  font-size: 12px;
  color: var(--muted);
}

.gcp-hint code {
  color: #c7d2fe;
}

/* Drawer PDF */
.gcp-drawer {
  flex: 1 1 auto;
  background: #0b1220;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  /* iOS/Safari: autorise les zones internes (pdf) à scroller */
  min-height: 0;
}

.gcp-resizer{
  width: 10px;
  cursor: col-resize;
  background: rgba(255,255,255,.03);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}
#gpro-chatpdf.gcp.theme-light .gcp-resizer{ background: rgba(15,23,42,.03); }

/* Modal À propos */
.gcp-modal.hidden{ display:none; }
.gcp-modal{ position:absolute; inset:0; z-index:50; }
.gcp-modal-backdrop{ position:absolute; inset:0; background: rgba(0,0,0,.55); }
.gcp-modal-card{
  position:absolute;
  left:50%;
  top:50%;
  transform: translate(-50%,-50%);
  width:min(520px, calc(100% - 40px));
  border-radius:16px;
  border:1px solid var(--border);
  background: linear-gradient(180deg, var(--panel), var(--panel2));
  box-shadow: 0 18px 60px rgba(0,0,0,.35);
}
.gcp-modal-head{ display:flex; align-items:center; justify-content:space-between; padding:12px 14px; border-bottom:1px solid var(--border); }
.gcp-modal-title{ font-weight:800; letter-spacing:.2px; }
.gcp-modal-close{
  width:34px; height:34px; border-radius:12px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.04);
  color: var(--text);
  cursor:pointer;
  font-size:18px;
  line-height:1;
}
.gcp-modal-close:hover{ background: rgba(255,255,255,.06); }
.gcp-modal-body{ padding:14px; color: var(--text); }
.gcp-modal-body p{ margin: 0 0 10px; }

.gcp-drawer.hidden { display: none; }

.gcp-drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,.03);
}

.gcp-drawer-title {
  font-weight: 700;
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gcp-drawer-close {
  border: 1px solid var(--border);
  background: rgba(255,255,255,.04);
  color: var(--text);
  border-radius: 10px;
  padding: 6px 10px;
  cursor: pointer;
}

.gcp-pdf {
  flex: 1;
  overflow: auto;
  padding: 12px;
  height: 100%;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

/* PDF.js viewer iframe */
.gcp-pdf iframe{
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 10px;
  background: #0b1220;
}

/* Loader PDF */
.gcp-pdfwrap {
  position: relative;
  width: 100%;
  height: 100%;
}
.gcp-pdfwrap iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}
.gcp-pdfloader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(5, 10, 20, 0.65);
  backdrop-filter: blur(2px);
  z-index: 10;
}
.gcp-spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.25);
  border-top-color: rgba(255,255,255,0.9);
  animation: gcp-spin 0.9s linear infinite;
}
.gcp-pdfloader span {
  font-size: 13px;
  opacity: 0.9;
}
@keyframes gcp-spin {
  to { transform: rotate(360deg); }
}

/* Responsive (chat front only) */
@media (max-width: 1024px){
  #gpro-chatpdf.gcp{
    height: 75vh;
    min-height: 520px;
    max-height: 820px;
  }
  #gpro-chatpdf.gcp .gcp-msg{ max-width: 92%; }
}

@media (max-width: 768px){
  #gpro-chatpdf.gcp{
    height: 85vh;
    height: 85dvh;
    flex-direction: column;
    gap: 0;
  }

  #gpro-chatpdf.gcp .gcp-chat{
    flex: 1 1 auto;
    width: 100%;
  }

  /* Le séparateur n'a aucun sens en mode colonne */
  #gpro-chatpdf.gcp .gcp-resizer{ display:none; }

  /* Le PDF devient un "overlay" quand une source est ouverte */
  #gpro-chatpdf.gcp .gcp-drawer{
    position: absolute;
    inset: 0;
    z-index: 40;
    border-left: 0;
  }
  #gpro-chatpdf.gcp .gcp-drawer.hidden{ display:none; }

  /* Input toujours accessible */
  #gpro-chatpdf.gcp .gcp-inputbar{
    position: sticky;
    bottom: 0;
    z-index: 5;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  #gpro-chatpdf.gcp .gcp-msg{ max-width: 96%; }
}

@media (max-width: 480px){
  #gpro-chatpdf.gcp .gcp-header{ padding: 12px; }
  #gpro-chatpdf.gcp .gcp-inputbar{
    gap: 8px;
    padding: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
  #gpro-chatpdf.gcp .gcp-send{ min-width: 64px; padding: 0 12px; }
}
