/* ---------- Design tokens ---------- */
:root {
  --bg: #f4f4fb;
  --surface: #ffffff;
  --surface-2: #f7f7fc;
  --border: #e6e6f0;
  --text: #17172b;
  --text-muted: #6b6b85;
  --accent-1: #7c5cff;
  --accent-2: #ff6bcb;
  --accent-contrast: #ffffff;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --shadow: 0 20px 50px -20px rgba(30, 20, 80, 0.25);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e17;
    --surface: #17172a;
    --surface-2: #1e1e34;
    --border: #2b2b44;
    --text: #f2f2fb;
    --text-muted: #9797b3;
    --shadow: 0 20px 60px -20px rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 16px 48px;
  position: relative;
  overflow-x: hidden;
}

.bg-glow {
  position: fixed;
  inset: -20% -20% auto -20%;
  height: 60vh;
  background: radial-gradient(60% 60% at 30% 20%, rgba(124, 92, 255, 0.25), transparent 70%),
    radial-gradient(50% 50% at 80% 10%, rgba(255, 107, 203, 0.2), transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* ---------- Header ---------- */
.site-header {
  position: relative;
  z-index: 1;
  text-align: center;
  margin-bottom: 28px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: block;
  box-shadow: 0 6px 16px -4px rgba(124, 92, 255, 0.5);
}

.brand-name {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* ---------- Card ---------- */
.app-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 22px;
}

/* ---------- Tabs ---------- */
.tabs {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 22px;
}

.tab {
  position: relative;
  z-index: 1;
  border: none;
  background: transparent;
  padding: 10px 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 999px;
  transition: color 0.2s ease;
}

.tab.active { color: var(--accent-contrast); }

.tab-indicator {
  position: absolute;
  top: 4px;
  left: 4px;
  width: calc(50% - 4px);
  height: calc(100% - 8px);
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  border-radius: 999px;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.tabs.is-retrieve .tab-indicator {
  transform: translateX(100%);
}

/* [hidden] doit toujours l'emporter, meme sur un element dont la classe
   fixe elle-meme un display (ex: .upload-progress, .empty-state) : sans le
   !important, la specificite est identique et l'ordre du cascade donne la
   victoire a la classe, ce qui affichait les etapes "en chargement" au
   premier rendu de la page. */
[hidden] { display: none !important; }

/* ---------- Dropzone ---------- */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 36px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.15s ease;
  color: var(--text-muted);
}

.dropzone:hover,
.dropzone:focus-visible {
  border-color: var(--accent-1);
  background: var(--surface-2);
  outline: none;
}

.dropzone.dragover {
  border-color: var(--accent-1);
  background: var(--surface-2);
  transform: scale(1.01);
}

.dropzone-icon {
  width: 34px;
  height: 34px;
  color: var(--accent-1);
  margin-bottom: 10px;
}

.dropzone-title {
  margin: 0;
  font-weight: 700;
  color: var(--text);
  font-size: 1.02rem;
}

.dropzone-sub {
  margin: 6px 0 0;
  font-size: 0.82rem;
  line-height: 1.4;
}

/* ---------- File preview ---------- */
.file-preview-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
  margin-top: 16px;
}

.file-preview-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

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

.file-preview-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  border: none;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  border: none;
  padding: 13px 20px;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.2s ease, background 0.2s ease;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-block { width: 100%; }

.btn-primary {
  color: var(--accent-contrast);
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  box-shadow: 0 10px 24px -10px rgba(124, 92, 255, 0.6);
}

.btn-secondary {
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-ghost {
  color: var(--text-muted);
  background: transparent;
}

.btn-sm { padding: 9px 14px; font-size: 0.85rem; }

.icon-btn {
  border: none;
  background: var(--surface-2);
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.copied { color: var(--success); }

.icon-btn-sm {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}
.icon-btn-sm svg { width: 14px; height: 14px; }

#upload-btn { margin-top: 16px; }

/* ---------- Errors / states ---------- */
.error-text {
  color: var(--danger);
  font-size: 0.88rem;
  margin: 12px 2px 0;
}

.upload-progress {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 40px 0;
  color: var(--text-muted);
}

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent-1);
  animation: spin 0.8s linear infinite;
}

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

.empty-state {
  text-align: center;
  padding: 30px 0;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

/* ---------- Result (code + QR) ---------- */
.result-block { text-align: center; }

.result-label {
  margin: 0 0 14px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.code-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.code-text {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  /* Couleur pleine et non un degrade en background-clip:text : cette
     technique peut echouer selon le navigateur et rendre le code
     invisible (texte transparent sans decoupe visible), ce qui est
     arrive en pratique. Une couleur simple garantit qu'il reste lisible
     partout. */
  color: var(--accent-1);
  user-select: all;
}

.code-text-sm {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--accent-1);
  user-select: all;
}

.countdown {
  margin: 10px 0 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.countdown.warning { color: var(--warning); }
.countdown.danger { color: var(--danger); }

.qr-block {
  margin: 22px 0 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.qr-canvas-wrap {
  display: inline-flex;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
  padding: 8px;
  min-width: 180px;
  min-height: 180px;
  align-items: center;
  justify-content: center;
}

.qr-canvas-wrap img,
.qr-canvas-wrap canvas {
  display: block;
  border-radius: 4px;
}

.qr-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  max-width: 280px;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

/* ---------- Retrieve form ---------- */
.field-label {
  margin: 0 0 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

#retrieve-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.code-input {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-align: center;
  text-transform: uppercase;
  padding: 14px 10px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  width: 100%;
}

.code-input:focus {
  outline: none;
  border-color: var(--accent-1);
}

/* ---------- Gallery ---------- */
.gallery-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.gallery-code-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.gallery-code-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.gallery-header-actions {
  display: flex;
  gap: 8px;
}

.gallery-header-actions .btn { flex: 1; text-align: center; }

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

.gallery-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
}

.gallery-thumb {
  aspect-ratio: 1;
  width: 100%;
  object-fit: cover;
  display: block;
  background: var(--border);
}

.gallery-item-footer {
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.gallery-item-name {
  font-size: 0.72rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gallery-download {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: none;
  background: var(--surface);
  color: var(--accent-1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
}

.gallery-download svg { width: 15px; height: 15px; }

/* ---------- Footer ---------- */
.site-footer {
  position: relative;
  z-index: 1;
  max-width: 460px;
  text-align: center;
  margin-top: 26px;
  color: var(--text-muted);
  font-size: 0.78rem;
  line-height: 1.5;
}

/* ---------- Responsive ---------- */
@media (max-width: 420px) {
  .app-card { padding: 18px; border-radius: 20px; }
  .code-text { font-size: 1.6rem; }
}
