/* ==========================================================================
   qimg — interface minimaliste de test d'un endpoint Runpod Serverless
   ========================================================================== */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* L'attribut `hidden` doit primer sur les `display: flex` des composants :
   les styles d'auteur écrasent sans cela la règle `[hidden] { display: none }`
   du navigateur, et les modales / boutons conditionnels restent visibles. */
[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: #fafafa;
  color: #333;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
}

code {
  background: #f0f0f3;
  border-radius: 3px;
  padding: 0.05rem 0.3rem;
  font-size: 0.85em;
}

/* --- Barre de navigation ------------------------------------------------ */

.navbar {
  background: white;
  border-bottom: 1px solid #e0e0e0;
  padding: 0.6rem 1rem;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  flex-shrink: 0;
}

.navbar-left {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  min-width: 0;
}

.navbar-title {
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}

.logo-icon {
  font-size: 1.1rem;
}

.navbar-right {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.navbar-btn {
  background: #333;
  color: white;
  border: none;
  padding: 0.4rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.navbar-btn:hover {
  background: #111;
}

.badge {
  font-size: 0.72rem;
  color: #666;
  background: #f2f2f5;
  border: 1px solid #e4e4e8;
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 32ch;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.badge.ok {
  color: #146c43;
  background: #e8f6ee;
  border-color: #b7e2c8;
}

.badge.warn {
  color: #8a5300;
  background: #fdf3e3;
  border-color: #f2d9ac;
}

/* --- Conteneur principal ------------------------------------------------ */

.container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 53px);
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  padding: 1rem;
  gap: 1rem;
}

.response-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: white;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  overflow: hidden;
  min-height: 0;
}

.response-header {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid #e0e0e0;
  background: #fafafa;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.response-info {
  font-size: 0.78rem;
  color: #666;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.response-controls {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.response-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- État vide ---------------------------------------------------------- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  color: #9a9aa2;
  text-align: center;
  max-width: 46ch;
}

.empty-state p {
  font-size: 0.9rem;
  color: #6a6a72;
}

.empty-state .empty-hint {
  font-size: 0.78rem;
  color: #9a9aa2;
  line-height: 1.5;
}

.empty-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 0.4rem;
}

/* --- Résultats ---------------------------------------------------------- */

.result-stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  align-self: flex-start;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.image-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: #fff;
  border: 1px solid #e6e6ea;
  border-radius: 8px;
  padding: 0.6rem;
}

.image-card img {
  width: 100%;
  border-radius: 6px;
  cursor: zoom-in;
  background:
    linear-gradient(45deg, #f3f3f5 25%, transparent 25%, transparent 75%, #f3f3f5 75%),
    linear-gradient(45deg, #f3f3f5 25%, transparent 25%, transparent 75%, #f3f3f5 75%);
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px;
  display: block;
}

.image-meta {
  font-size: 0.72rem;
  color: #77777f;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.image-actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

/* --- Notices / erreurs de job ------------------------------------------ */

.notice {
  border: 1px solid #e0e0e0;
  background: #fafafa;
  border-radius: 8px;
  padding: 0.9rem 1rem;
  font-size: 0.82rem;
  line-height: 1.5;
  color: #444;
  width: 100%;
  align-self: flex-start;
}

.notice.error {
  background: #fdf1f1;
  border-color: #f0c4c4;
  color: #8b1f1f;
}

.notice.warning {
  background: #fdf8ec;
  border-color: #eed9a8;
  color: #7a5405;
}

.notice h4 {
  font-size: 0.82rem;
  margin-bottom: 0.25rem;
}

.notice ul {
  margin: 0.35rem 0 0 1.1rem;
}

.notice code {
  background: rgba(0, 0, 0, 0.06);
}

/* --- Zone de saisie ----------------------------------------------------- */

.input-container {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: white;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 0.75rem;
}

.image-preview-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.image-preview-wrapper {
  position: relative;
  width: 68px;
  height: 68px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #e0e0e0;
}

.image-preview-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.remove-image-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  border: none;
  border-radius: 3px;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.input-wrapper {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.input-textarea {
  flex: 1;
  resize: vertical;
  min-height: 68px;
  max-height: 220px;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 0.6rem 0.7rem;
  font-family: inherit;
  font-size: 0.88rem;
  line-height: 1.45;
  color: #333;
  outline: none;
}

.input-textarea:focus {
  border-color: #1a56db;
  box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.12);
}

.input-buttons {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}

.send-btn,
.cancel-btn,
.restore-btn {
  border: none;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  min-width: 44px;
  transition: background 0.2s ease, opacity 0.2s ease;
}

.send-btn {
  background: #1a56db;
  color: #fff;
}

.send-btn:hover:not(:disabled) {
  background: #1546b4;
}

.cancel-btn {
  background: #fdf1f1;
  color: #8b1f1f;
  border: 1px solid #f0c4c4;
}

.cancel-btn:hover {
  background: #f8e2e2;
}

.restore-btn {
  background: #f2f2f5;
  color: #555;
  border: 1px solid #e0e0e0;
}

.restore-btn:hover {
  background: #e8e8ec;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.spinner {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.input-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.input-footer-left {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  min-width: 0;
}

.attach-image-btn,
.ghost-btn,
.control-btn,
.recap-btn {
  background: white;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
  color: #333;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: background 0.2s ease, border-color 0.2s ease;
  font-family: inherit;
}

.attach-image-btn:hover:not(:disabled),
.ghost-btn:hover,
.control-btn:hover:not(:disabled),
.recap-btn:hover {
  background: #f5f5f5;
  border-color: #ccc;
}

.recap-btn {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #555;
}

.char-count {
  font-size: 0.72rem;
  color: #9a9aa2;
}

/* --- Barre de statut ---------------------------------------------------- */

.status-bar {
  font-size: 0.78rem;
  padding: 0.45rem 0.7rem;
  border-radius: 6px;
  background: #f2f5fd;
  border: 1px solid #d3e0fb;
  color: #1a3e8f;
}

.status-bar.error {
  background: #fdf1f1;
  border-color: #f0c4c4;
  color: #8b1f1f;
}

.status-bar.success {
  background: #eef8f2;
  border-color: #bfe3cd;
  color: #146c43;
}

.status-bar .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  margin-right: 0.4rem;
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

/* --- Modales ------------------------------------------------------------ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1.5rem;
}

.modal-content {
  background: white;
  border-radius: 8px;
  width: 100%;
  max-width: 620px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
}

.modal-wide {
  max-width: 980px;
}

.modal-narrow {
  max-width: 380px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #e0e0e0;
  background: #fafafa;
}

.modal-header h2 {
  font-size: 0.92rem;
  font-weight: 600;
}

.close-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  color: #77777f;
  cursor: pointer;
  padding: 0 0.25rem;
}

.close-btn:hover {
  color: #222;
}

.modal-body {
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.params-section {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.params-section h3 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #88888f;
}

.param-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.param-group label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: #444;
}

.param-group label > span {
  font-weight: 500;
}

.param-group input[type="text"],
.param-group input[type="password"],
.param-group input[type="number"],
.param-group select,
.param-group textarea {
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 0.4rem 0.5rem;
  font-size: 0.82rem;
  font-family: inherit;
  color: #333;
  background: #fff;
  outline: none;
  width: 100%;
}

.param-group textarea {
  resize: vertical;
}

.param-group input:focus,
.param-group select:focus,
.param-group textarea:focus {
  border-color: #1a56db;
  box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.1);
}

.param-group input[type="range"] {
  width: 100%;
  accent-color: #1a56db;
}

.param-inline {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

.param-inline > label {
  flex: 1 1 140px;
  min-width: 0;
}

.param-description {
  font-size: 0.72rem;
  color: #8c8c94;
  line-height: 1.4;
}

.param-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.param-presets {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.seed-row {
  display: flex;
  gap: 0.35rem;
}

.seed-row input {
  flex: 1;
}

.advanced summary {
  font-size: 0.78rem;
  color: #666;
  cursor: pointer;
  padding: 0.2rem 0;
}

.advanced > * {
  margin-top: 0.6rem;
}

/* --- Vue JSON ----------------------------------------------------------- */

.json-view {
  background: #1f2126;
  color: #d8dbdf;
  border-radius: 6px;
  padding: 0.8rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.74rem;
  line-height: 1.5;
  overflow: auto;
  max-height: 46vh;
  white-space: pre-wrap;
  word-break: break-word;
}

/* --- Galerie ------------------------------------------------------------ */

.gallery-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}

.gallery-item {
  border: 1px solid #e6e6ea;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  display: flex;
  flex-direction: column;
}

.gallery-thumb {
  aspect-ratio: 1 / 1;
  background: #f6f6f8;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
}

.gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-thumb span {
  font-size: 0.75rem;
  color: #9a9aa2;
  padding: 0.5rem;
  text-align: center;
}

.gallery-item-body {
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.gallery-prompt {
  font-size: 0.74rem;
  color: #555;
  line-height: 1.35;
  max-height: 2.7em;
  overflow: hidden;
}

.gallery-meta {
  font-size: 0.68rem;
  color: #9a9aa2;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.gallery-item-actions {
  display: flex;
  gap: 0.3rem;
  padding: 0 0.5rem 0.5rem;
  flex-wrap: wrap;
}

.pill {
  display: inline-block;
  font-size: 0.66rem;
  border-radius: 999px;
  padding: 0.05rem 0.4rem;
  border: 1px solid transparent;
}

.pill.completed { background: #eef8f2; color: #146c43; border-color: #bfe3cd; }
.pill.failed { background: #fdf1f1; color: #8b1f1f; border-color: #f0c4c4; }
.pill.running { background: #f2f5fd; color: #1a3e8f; border-color: #d3e0fb; }
.pill.cancelled { background: #f5f5f7; color: #6a6a72; border-color: #e2e2e6; }

/* --- Visionneuse d'image (lightbox) ------------------------------------- */

/* Plein écran sombre : la barre d'outils et le bandeau de détails sont dans le
   flux, le stage prend toute la place restante (l'image n'est jamais
   recouverte). */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #101014;
  display: flex;
  flex-direction: column;
}

.lightbox-toolbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  padding: 0.45rem 0.6rem;
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.lb-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #e8e8ee;
  border-radius: 6px;
  padding: 0.32rem 0.6rem;
  font-size: 0.76rem;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  transition: background 0.15s ease;
}

.lb-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.22);
}

.lb-btn[aria-pressed="true"] {
  background: #1a56db;
  border-color: #1a56db;
  color: #fff;
}

.lb-zoom {
  min-width: 3.6rem;
  text-align: center;
  font-size: 0.74rem;
  color: #b9b9c4;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.lb-counter {
  font-size: 0.74rem;
  color: #b9b9c4;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.lb-spacer {
  flex: 1;
}

.lightbox-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  /* `touch-action: none` est indispensable : sans lui le navigateur interprète
     le pincement comme un zoom de page et ne laisse pas passer nos évènements. */
  touch-action: none;
}

.lightbox-stage.can-pan {
  cursor: grab;
}

.lightbox-stage.can-pan.grabbing {
  cursor: grabbing;
}

/* L'image garde sa taille naturelle : tout le zoom passe par `transform`,
   avec une origine en haut à gauche pour calculer le cadrage simplement. */
.lightbox-stage img {
  position: absolute;
  top: 0;
  left: 0;
  max-width: none;
  max-height: none;
  transform-origin: 0 0;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
  border-radius: 2px;
  /* damier : rend visible la transparence des PNG/WebP */
  background:
    linear-gradient(45deg, #2a2a32 25%, transparent 25%, transparent 75%, #2a2a32 75%),
    linear-gradient(45deg, #2a2a32 25%, transparent 25%, transparent 75%, #2a2a32 75%),
    #232329;
  background-size: 18px 18px;
  background-position: 0 0, 9px 9px;
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(20, 20, 26, 0.66);
  color: #f0f0f4;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.lightbox-nav:hover {
  background: rgba(44, 44, 56, 0.9);
}

.lightbox-nav.prev { left: 0.75rem; }
.lightbox-nav.next { right: 0.75rem; }

.lightbox-info {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.5rem 0.75rem;
  background: rgba(255, 255, 255, 0.05);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  max-height: 26vh;
  overflow-y: auto;
}

.lightbox-prompt {
  font-size: 0.82rem;
  color: #e6e6ec;
  line-height: 1.4;
}

.lightbox-meta {
  font-size: 0.72rem;
  color: #9a9aa8;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.lightbox-hint {
  font-size: 0.68rem;
  color: #7c7c8a;
  margin-top: 0.1rem;
}

/* --- Glisser-déposer des références ------------------------------------- */

/* `pointer-events: none` est indispensable : l'overlay couvre la page, sans
   quoi il capterait lui-même les évènements de glisser et ferait clignoter
   l'affichage (dragenter/dragleave en boucle). */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(22, 26, 40, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.drop-overlay-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 1.5rem 2.25rem;
  border: 2px dashed #8fb0ff;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.97);
  color: #1a3e8f;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}

.drop-overlay-title {
  font-size: 1rem;
  font-weight: 600;
}

.drop-overlay-hint {
  font-size: 0.78rem;
  color: #5a6b8c;
}

/* Mise en évidence de la zone d'accueil pendant un glisser de fichiers */
body.dragging-files .input-container {
  border-color: #7d9ff5;
  box-shadow: 0 0 0 3px rgba(125, 159, 245, 0.18);
}

body.dragging-files .image-preview-container:not([hidden]) {
  outline: 2px dashed #9db8f7;
  outline-offset: 4px;
  border-radius: 6px;
}

/* --- Toast -------------------------------------------------------------- */

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: #26262b;
  color: #fff;
  font-size: 0.8rem;
  padding: 0.55rem 0.9rem;
  border-radius: 6px;
  z-index: 80;
  max-width: 80vw;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

.toast.error {
  background: #8b1f1f;
}

@media (max-width: 720px) {
  .navbar {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }
  .navbar-title { justify-content: center; }
  .navbar-left, .navbar-right { justify-content: center; }
  .badge { max-width: 100%; }
  .container { height: auto; }
  body { overflow: auto; }
}
