:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #17202e;
  --muted: #5b6575;
  --border: #d9dee6;
  --primary: #1b2a5c;
  --primary-hover: #26397a;
  --primary-text: #ffffff;
  --accent: #2f6fdb;
  --success: #17803d;
  --danger: #b42318;
  --warning-bg: #fff6e0;
  --warning-border: #f0c56a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141c;
    --surface: #171e29;
    --surface-2: #1f2835;
    --text: #e8ecf2;
    --muted: #9aa5b5;
    --border: #2c3747;
    --primary: #8fb0ff;
    --primary-hover: #a9c2ff;
    --primary-text: #0c1322;
    --accent: #8fb0ff;
    --success: #4cc27a;
    --danger: #ff7b6e;
    --warning-bg: #2c2414;
    --warning-border: #7a5d22;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
[hidden] { display: none !important; }
h1 { font-size: 1.6rem; margin: 0 0 .5rem; }
h2 { font-size: 1.2rem; margin: 0 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.error { color: var(--danger); margin: 0; min-height: 0; }
.error:empty { display: none; }
.feedback { margin: 0; }
.feedback.ok { color: var(--success); }
.feedback.ko { color: var(--danger); }
.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: .5rem 1rem; z-index: 10; }
.skip:focus { left: 1rem; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.row { display: flex; gap: .75rem; align-items: center; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }

input[type="email"], input[type="password"], input[type="text"], input:not([type]), textarea {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .6rem .75rem;
}
textarea { resize: vertical; }
label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; }
label .muted, label .small { font-weight: 400; }
label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 500; }
label.check input { width: 1.1rem; height: 1.1rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; font-size: .95rem;
  padding: .55rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.small { padding: .35rem .75rem; font-size: .85rem; }
.btn.big { padding: .75rem 2rem; font-size: 1.05rem; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn.copied { background: var(--success); border-color: var(--success); color: #fff; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

/* Connexion */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 1rem; }

/* Barre du haut */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: .75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.05rem; }
.topbar nav { display: flex; gap: .25rem; }
.topbar nav a { padding: .4rem .8rem; border-radius: 999px; color: var(--text); text-decoration: none; font-weight: 500; }
.topbar nav a:hover { background: var(--surface-2); }
.topbar nav a[aria-current="page"] { background: var(--primary); color: var(--primary-text); }
.user { display: flex; align-items: center; gap: .5rem; font-size: .9rem; }

main { max-width: 1200px; margin: 0 auto; padding: 1.5rem; outline: none; }

.notice {
  background: var(--warning-bg); border: 1px solid var(--warning-border);
  border-radius: var(--radius); padding: .75rem 1rem; margin-bottom: 1rem;
}

/* Dépôt */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .4rem;
  text-align: center;
  min-height: 220px;
  padding: 2rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  font-weight: 400;
  transition: border-color .15s, background .15s;
}
.dropzone strong { font-size: 1.15rem; }
.dropzone svg { color: var(--accent); }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--surface-2); }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
body.dragging .dropzone { border-color: var(--accent); }

#staged-wrap { margin-top: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.staged {
  list-style: none; padding: 0; margin: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .75rem;
}
.staged li {
  position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
}
.staged .pic { aspect-ratio: 1; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); font-weight: 700; text-transform: uppercase; }
.staged img { width: 100%; height: 100%; object-fit: cover; display: block; }
.staged .cap { padding: .35rem .5rem; font-size: .75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.staged .x {
  position: absolute; top: .3rem; right: .3rem; width: 1.8rem; height: 1.8rem; border-radius: 50%;
  border: none; background: rgba(0, 0, 0, .65); color: #fff; cursor: pointer; font-size: 1rem; line-height: 1;
}
.context { margin: 0; }

/* Résultats */
.results-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-bottom: 1rem; }
.progress .bar { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.results { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 1rem; }
.result {
  display: grid; grid-template-columns: minmax(220px, 360px) 1fr; gap: 1.25rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow);
}
.thumb {
  position: relative; display: grid; place-items: center;
  min-height: 200px; max-height: 300px; border-radius: 8px; overflow: hidden;
  background-color: #e9ecf1;
  background-image: linear-gradient(45deg, #d6dbe3 25%, transparent 25%), linear-gradient(-45deg, #d6dbe3 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d6dbe3 75%), linear-gradient(-45deg, transparent 75%, #d6dbe3 75%);
  background-size: 16px 16px; background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}
.thumb img { max-width: 100%; max-height: 300px; object-fit: contain; display: block; }
.thumb img:not([src]) { display: none; }
.spinner { position: absolute; width: 36px; height: 36px; border: 4px solid rgba(47, 111, 219, .25); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: none; }
.result.busy .spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.info { display: flex; flex-direction: column; gap: .6rem; min-width: 0; }
.name-row { display: flex; align-items: center; gap: .25rem; }
.name-row .filename { font-weight: 600; }
.name-row .ext { color: var(--muted); }
.meta { margin: 0; }
.meta .gain { color: var(--success); font-weight: 700; }
.meta .loss { color: var(--danger); font-weight: 700; }
.alt-wrap { display: flex; flex-direction: column; gap: .3rem; }
.alt-label { flex-direction: row; align-items: center; gap: .5rem; }
.alt-count { margin: 0; }
.alt-count.long { color: var(--danger); }
.badge { font-size: .75rem; font-weight: 600; padding: .1rem .5rem; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.result.busy .alt { opacity: .6; }

/* Lots */
.batches, .users { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .5rem; }
.batches li, .users li {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .75rem 1rem;
}
.users li { background: var(--surface-2); }
.form-grid { display: flex; flex-direction: column; gap: .9rem; max-width: 520px; }

.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%) translateY(150%);
  background: var(--text); color: var(--bg); padding: .7rem 1.2rem; border-radius: 999px;
  font-weight: 600; transition: transform .25s; z-index: 20; max-width: calc(100% - 2rem);
}
.toast.show { transform: translateX(-50%) translateY(0); }

@media (max-width: 720px) {
  main { padding: 1rem; }
  .topbar { padding: .75rem 1rem; }
  .user #user-email { display: none; }
  .result { grid-template-columns: 1fr; }
}
