:root {
  color-scheme: light;
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-sunk: #fbfaf6;
  --ink: #211c15;
  --ink-soft: #4a4438;
  --text-muted: #6b6352;
  --muted: #948a76;
  --border: #e6e0d3;
  --border-soft: #efeae0;
  --border-strong: #d6ccb6;
  --grip: #c9bfa8;
  --skeleton: #efeae0;
  --skeleton-soft: #f3efe7;
  --accent: #96773b;
  --accent-ink: #6e5527;
  --accent-soft: rgba(150, 119, 59, 0.12);
  --accent-wash: rgba(150, 119, 59, 0.06);
  --danger: #a8453a;
  --danger-soft: rgba(168, 69, 58, 0.1);
  --knob: #ffffff;
  --knob-shadow: 0 1px 3px rgba(33, 28, 21, 0.18);
  --track: #efeae0;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #16130e;
    --surface: #201b14;
    --surface-sunk: #1c1812;
    --ink: #eee7d8;
    --ink-soft: #cabf9e;
    --text-muted: #a2957b;
    --muted: #8f836b;
    --border: #392f21;
    --border-soft: #2c251b;
    --border-strong: #4a3f2d;
    --grip: #5a4e3a;
    --skeleton: #2c251b;
    --skeleton-soft: #262017;
    --accent: #cc9f4f;
    --accent-ink: #f0cd8b;
    --accent-soft: rgba(204, 159, 79, 0.16);
    --accent-wash: rgba(204, 159, 79, 0.07);
    --danger: #dd8177;
    --danger-soft: rgba(221, 129, 119, 0.14);
    --knob: #3a3024;
    --knob-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    --track: #16130e;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #16130e;
  --surface: #201b14;
  --surface-sunk: #1c1812;
  --ink: #eee7d8;
  --ink-soft: #cabf9e;
  --text-muted: #a2957b;
  --muted: #8f836b;
  --border: #392f21;
  --border-soft: #2c251b;
  --border-strong: #4a3f2d;
  --grip: #5a4e3a;
  --skeleton: #2c251b;
  --skeleton-soft: #262017;
  --accent: #cc9f4f;
  --accent-ink: #f0cd8b;
  --accent-soft: rgba(204, 159, 79, 0.16);
  --accent-wash: rgba(204, 159, 79, 0.07);
  --danger: #dd8177;
  --danger-soft: rgba(221, 129, 119, 0.14);
  --knob: #3a3024;
  --knob-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --track: #16130e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
}

svg {
  flex-shrink: 0;
}

/* ---------- Barre du haut ---------- */

.topbar {
  height: 64px;
  padding: 0 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

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

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 7px;
  background: var(--ink);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 14px;
}

.brand-name {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.01em;
}

.brand-tag {
  margin-left: 8px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

/* ---------- Actions de la barre du haut ---------- */

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.icon-btn:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

.icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Interrupteur de thème ---------- */

.theme-toggle {
  height: 44px;
  padding: 0;
  border: none;
  background: none;
  display: flex;
  align-items: center;
  cursor: pointer;
  border-radius: 999px;
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.theme-track {
  position: relative;
  width: 68px;
  height: 34px;
  padding: 3px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 999px;
  background: var(--track);
  border: 1px solid var(--border);
}

.theme-track::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 28px;
  height: 26px;
  border-radius: 999px;
  background: var(--knob);
  box-shadow: var(--knob-shadow);
  transition: transform 0.22s ease, background-color 0.22s ease;
}

.theme-option {
  position: relative;
  z-index: 1;
  width: 28px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  transition: color 0.22s ease;
}

.theme-option svg {
  width: 15px;
  height: 15px;
}

.theme-light {
  color: var(--accent);
}

:root[data-theme="dark"] .theme-track::before {
  transform: translateX(32px);
}

:root[data-theme="dark"] .theme-light {
  color: var(--muted);
}

:root[data-theme="dark"] .theme-dark {
  color: var(--accent-ink);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-track::before {
    transform: translateX(32px);
  }

  :root:not([data-theme="light"]) .theme-light {
    color: var(--muted);
  }

  :root:not([data-theme="light"]) .theme-dark {
    color: var(--accent-ink);
  }
}

/* ---------- Page ---------- */

.page {
  max-width: 1360px;
  margin: 0 auto;
  padding: 32px 40px 48px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}

.page-head h1 {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 32px;
  letter-spacing: -0.015em;
  line-height: 1.1;
}

.summary {
  margin: 6px 0 0;
  font-size: 15px;
  color: var(--text-muted);
}

.page-actions {
  display: flex;
  gap: 12px;
}

.btn {
  height: 44px;
  padding: 0 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn svg {
  width: 18px;
  height: 18px;
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-secondary {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
}

.btn-secondary:hover {
  border-color: var(--border-strong);
}

.btn-primary {
  border: none;
  background: var(--ink);
  color: var(--bg);
}

.btn-primary:not(:disabled):hover {
  background: var(--accent-ink);
}

.btn-primary:disabled {
  background: var(--border);
  color: var(--muted);
  cursor: not-allowed;
}

.layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card[hidden] {
  display: none;
}

.card-quiet {
  background: transparent;
  padding: 16px 20px;
  gap: 8px;
}

.card-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.card-text {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink-soft);
}

/* ---------- Dépôt ---------- */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 28px 16px;
  border: 1.5px dashed var(--border-strong);
  border-radius: 10px;
  background: var(--surface-sunk);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-wash);
}

.dropzone:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.dropzone-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-ink);
  display: flex;
  align-items: center;
  justify-content: center;
}

.dropzone-icon svg {
  width: 22px;
  height: 22px;
}

.dropzone-title {
  font-size: 15px;
  font-weight: 600;
}

.dropzone-sub {
  font-size: 14px;
  color: var(--text-muted);
}

.dropzone-link {
  color: var(--accent-ink);
  font-weight: 600;
  text-decoration: underline;
}

.dropzone-hint {
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- Progression ---------- */

.progress-card {
  gap: 12px;
}

.progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.progress-count {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.progress-bar {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: var(--border-soft);
  background-image: repeating-linear-gradient(
    135deg,
    var(--accent-soft) 0 8px,
    transparent 8px 16px
  );
  background-size: 23px 23px;
  animation: progress-stripes 0.9s linear infinite;
  overflow: hidden;
}

@keyframes progress-stripes {
  from {
    background-position: 0 0;
  }
  to {
    background-position: 23px 0;
  }
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.25s ease;
}

.progress-label {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--ink-soft);
  min-width: 0;
}

.progress-label::before {
  content: "";
  width: 8px;
  height: 8px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}

.progress-label strong {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

.progress-note {
  margin: 0;
  padding-top: 12px;
  border-top: 1px solid var(--border-soft);
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-muted);
}

/* ---------- Tableau des lots ---------- */

.lots {
  padding: 0;
  gap: 0;
  overflow: hidden;
}

.lots-head {
  min-height: 56px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.lots-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.lots-title h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.count-badge {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--border-soft);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

.lots-hint {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.lots-hint svg {
  width: 14px;
  height: 14px;
}

.lots-columns,
.queue-item {
  display: grid;
  grid-template-columns: 20px 40px 40px minmax(0, 1fr) 220px 64px 40px;
  gap: 16px;
  align-items: center;
  padding: 0 20px;
}

.lots-columns {
  height: 40px;
  background: var(--surface-sunk);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.queue-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.queue-item {
  min-height: 68px;
  padding-top: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface);
  transition: background-color 0.15s ease;
}

.queue-item:hover {
  background: var(--accent-wash);
}

.lots .queue-list:last-of-type .queue-item:last-child {
  border-bottom: none;
}

.sortable-ghost {
  background: var(--accent-soft);
  opacity: 0.6;
}

.handle {
  display: flex;
  cursor: grab;
  color: var(--grip);
  touch-action: none;
}

.handle svg {
  width: 14px;
  height: 20px;
}

.queue-item:hover .handle {
  color: var(--accent);
}

.lot-num {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent-ink);
}

.thumb {
  width: 36px;
  height: 48px;
  object-fit: cover;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: var(--border-soft);
}

.info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.titre,
.auteur,
.meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.titre {
  font-size: 15px;
  font-weight: 600;
}

.auteur {
  font-size: 14px;
  color: var(--text-muted);
}

.meta {
  display: none;
  font-size: 13px;
  color: var(--text-muted);
}

.edition,
.annee {
  font-size: 14px;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.annee {
  font-variant-numeric: tabular-nums;
}

.delete-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  border-radius: 6px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.delete-btn svg {
  width: 17px;
  height: 17px;
}

.delete-btn:hover,
.delete-btn:focus-visible {
  color: var(--danger);
  background: var(--danger-soft);
  outline: none;
}

/* Ligne en cours d'analyse */

.queue-item.pending:hover {
  background: var(--surface);
}

.pending .lot-num {
  color: var(--muted);
}

.thumb-placeholder {
  width: 36px;
  height: 48px;
  border-radius: 3px;
  border: 1px dashed var(--border-strong);
  background: var(--skeleton);
}

.pending-info {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.skeleton-lines {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.skeleton {
  display: block;
  height: 10px;
  border-radius: 4px;
  background: var(--skeleton);
  animation: pulse 1.4s ease-in-out infinite;
}

.skeleton.soft {
  background: var(--skeleton-soft);
}

.status-badge {
  flex-shrink: 0;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 700;
}

.pending-name {
  min-width: 0;
  font-size: 13px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  margin: 0;
  padding: 48px 20px;
  text-align: center;
  font-size: 15px;
  color: var(--text-muted);
}

.empty-state[hidden] {
  display: none;
}

/* ---------- Mobile / tablette ---------- */

@media (max-width: 960px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .card-quiet {
    display: none;
  }
}

@media (max-width: 640px) {
  .topbar {
    height: 56px;
    padding: 0 16px;
  }

  .brand-mark {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }

  .brand-name {
    font-size: 17px;
  }

  .brand-tag {
    display: none;
  }

  .page {
    padding: 20px 16px 104px;
    gap: 16px;
  }

  .page-head h1 {
    font-size: 26px;
  }

  .summary {
    font-size: 14px;
  }

  .page-actions {
    width: 100%;
  }

  #add-btn {
    display: none;
  }

  .download-btn {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: 16px;
    z-index: 10;
    height: 50px;
    font-size: 16px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  }

  .dropzone {
    flex-direction: row;
    text-align: left;
    padding: 16px;
    gap: 14px;
  }

  .dropzone-hint,
  .dropzone-sub {
    display: none;
  }

  .lots-hint,
  .lots-columns {
    display: none;
  }

  .queue-item {
    grid-template-columns: 16px 22px 36px minmax(0, 1fr) 40px;
    gap: 12px;
    padding: 10px 8px 10px 12px;
  }

  .edition,
  .annee,
  .auteur,
  .pending .skeleton-cell {
    display: none;
  }

  .meta {
    display: block;
  }

  .lot-num {
    font-size: 13px;
  }
}
