/* Couleurs et typographie */
:root {
  font-family: Arial, Helvetica, sans-serif;
  color-scheme: light;
  --bg: #f6f6f6;
  --surface: #fff;
  --text: #24282d;
  --muted: #606770;
  --line: #d5d8dc;
  --accent: #2457a7;
  --on-accent: #fff;
  --soft: #f0f2f5;
  --error: #b12525;
  background: var(--bg);
  color: var(--text);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #181c21;
  --surface: #222830;
  --text: #f2f3f5;
  --muted: #b7bfc9;
  --line: #4a535f;
  --accent: #a9caff;
  --on-accent: #14243e;
  --soft: #2c3440;
  --error: #ffb4ab;
}

/* Base et mise en page */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

button {
  font: inherit;
  cursor: pointer;
}

input {
  font: inherit;
  width: 100%;
  min-height: 50px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text);
  padding: 11px 12px;
  font-size: 20px;
}

summary {
  cursor: pointer;
  padding: 20px 26px;
  font-size: 14px;
  color: var(--muted);
}

.shell {
  max-width: 900px;
  margin: 0 auto;
  padding: 30px 24px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

h1 {
  font-size: 25px;
  line-height: 1.3;
  letter-spacing: -.4px;
  margin: 0;
}

h2 {
  font-size: 18px;
  line-height: 1.4;
  margin: 0;
  font-weight: 600;
}

.theme-toggle {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 10px 14px;
  font-size: 13px;
  white-space: nowrap;
}

.intro {
  font-size: 15px;
  line-height: 1.7;
  color: var(--muted);
  margin: 16px 0 26px;
}

.workspace {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

/* Saisie des emplacements */
.formpanel {
  padding: 26px;
  border-bottom: 1px solid var(--line);
}

.fields {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin: 22px 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-width: 0;
}

label {
  font-size: 14px;
  color: var(--text);
}

#allee {
  text-transform: uppercase;
}

input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Boutons */
.btn {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 18px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.btn:hover:not(:disabled) {
  background: var(--soft);
}

.theme-toggle:hover {
  background: var(--soft);
}

.btn.primary {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}

.btn.primary:hover:not(:disabled) {
  filter: brightness(.94);
}

.btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.batch-add {
  width: 100%;
}

.error {
  font-size: 14px;
  line-height: 1.6;
  color: var(--error);
}

.error:not(:empty) {
  margin-bottom: 16px;
}

/* Légendes des étiquettes ajoutées */
.queue-position {
  font-size: 12px;
  color: var(--muted);
}

.remove-label {
  min-height: 38px;
  padding: 6px;
  font-size: 11px;
  font-weight: 400;
  border: 0;
  color: var(--muted);
}

.batch-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 22px;
}

#print-batch {
  flex: 1;
}

.session-note {
  font-size: 12px;
  line-height: 1.7;
  color: var(--muted);
  margin: 16px 0 0;
}

.status {
  font-size: 12px;
  color: var(--muted);
}

.paper {
  padding: 10px;
  background: white;
}

.paper canvas {
  width: 100%;
  height: auto;
  display: block;
}

.decoded {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 12px;
  padding: 18px 0;
  max-width: 450px;
}

.decoded span {
  color: var(--muted);
}

.decoded code {
  overflow-wrap: anywhere;
}

/* Export et impression */
.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.actions .btn {
  font-size: 12px;
  font-weight: 400;
}

/* Informations et notifications */
footer {
  text-align: center;
  font-size: 11px;
  line-height: 1.8;
  color: var(--muted);
  padding-top: 18px;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 28px);
  width: max-content;
  background: var(--text);
  color: var(--bg);
  padding: 12px 18px;
  border-radius: 6px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
}

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

#batch-print {
  display: none;
}

/* Aperçus en temps réel */
.queued-preview {
  width: 100%;
  height: auto;
  aspect-ratio: 2 / 1;
  display: block;
  background: white;
}

.label-caption {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: var(--soft);
}

.label-caption>span:nth-child(2) {
  font-size: 11px;
  line-height: 1.6;
}

.label-caption .queue-position {
  font-size: 10px;
}

/* Galerie commune */
.label-area {
  padding: 26px;
}

.gallery-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.gallery-heading>span {
  font-size: 12px;
  color: var(--muted);
}

.label-gallery {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.label-gallery>li {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  align-self: start;
}

.draft-card {
  border-color: var(--line) !important;
}

.draft-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  padding: 10px 12px;
  background: transparent;
  min-height: 36px;
}

.draft-heading>span:first-child {
  font-weight: 400;
  font-size: 11px;
  color: var(--muted);
}

.draft-card .decoded {
  padding: 12px;
  margin: 0;
  font-size: 10px;
  min-height: 60px;
  align-items: center;
  background: var(--soft);
  border-top: 1px solid var(--line);
}

.draft-card .paper {
  padding: 0 4px 8px;
}

.saved-card .queued-preview {
  padding: 0;
}

.saved-card .label-caption {
  min-height: 48px;
  background: var(--surface);
  padding: 8px 10px;
}

.gallery-tools {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 16px;
  justify-content: space-between;
}

.gallery-tools .btn {
  font-size: 12px;
  font-weight: 400;
  border: 0;
  padding: 8px 0;
  min-height: 40px;
  color: var(--muted);
}

.gallery-tools .session-note {
  margin: 0;
  font-size: 10px;
}

.output-options {
  margin-top: 18px;
  border-top: 1px solid var(--line);
}

.output-options summary {
  padding: 16px 0 0;
  font-size: 13px;
}

.output-options .batch-controls {
  margin-top: 18px;
  align-items: center;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.output-options .session-note {
  margin-top: 14px;
  font-size: 11px;
}

.draft-card .decoded code {
  font-size: 11px;
}

/* Visibilité et accessibilité */
[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.gallery-heading h2 {
  font-size: 16px;
}

.saved-card .label-caption>span:nth-child(2) {
  font-size: 10px;
}

.output-options .actions {
  gap: 8px;
  margin-top: 10px;
}

.output-options .btn {
  min-height: 40px;
  padding: 10px 14px;
}

/* Installation et disponibilité hors ligne */
.offline-panel {
  margin-top: 18px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.7;
}

.offline-panel>p {
  margin: 0;
}

.offline-panel summary {
  padding: 10px 0;
  font-size: 12px;
}

.offline-panel details p {
  margin: 8px 0;
}

.offline-panel .btn {
  font-size: 12px;
  margin-top: 8px;
}

/* Adaptation aux petits écrans */
@media (max-width: 600px) {
  .shell {
    padding: 22px 14px;
  }

  header {
    gap: 10px;
  }

  h1 {
    font-size: 21px;
  }

  .theme-toggle {
    font-size: 12px;
    padding: 9px 10px;
  }

  .intro {
    font-size: 14px;
  }

  .formpanel {
    padding: 20px;
  }

  .fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px 14px;
  }

  .field.full {
    grid-column: 1/-1;
  }

  h2 {
    font-size: 17px;
  }

  .batch-controls .btn {
    width: 100%;
  }

  summary {
    padding: 20px;
  }

  .actions .btn {
    flex: 1;
  }

  .session-note {
    font-size: 11px;
  }

  .label-caption>span:nth-child(2) {
    font-size: 12px;
  }

  .label-area {
    padding: 20px;
  }

  .label-gallery {
    grid-template-columns: 1fr;
  }

  .gallery-tools {
    gap: 4px;
    align-items: flex-start;
  }

  .output-options .actions {
    display: flex;
    grid-template-columns: 1fr;
  }

  .output-options .batch-controls .btn {
    width: 100%;
  }

  .gallery-tools .session-note {
    width: 100%;
  }

  .output-options .actions .btn {
    flex: 1;
  }

  .output-options .batch-controls {
    gap: 6px;
  }

  .output-options .batch-controls .session-note {
    margin: 0;
  }

}

/* Impression */
@media print {
  :root {
    background: #fff;
    color-scheme: light;
  }

  body {
    background: #fff;
  }

  .shell {
    padding: 0;
    max-width: none;
  }

  header {
    display: none !important;
  }

  .intro {
    display: none !important;
  }

  .formpanel {
    display: none !important;
  }

  .decoded {
    display: none !important;
  }

  .actions {
    display: none !important;
  }

  footer {
    display: none !important;
  }

  .toast {
    display: none !important;
  }

  .workspace {
    border: 0;
    padding: 0;
    border-radius: 0;
    background: white;
    max-width: none;
  }

  .paper {
    border: 0;
    padding: 0;
    border-radius: 0;
    background: white;
    max-width: none;
  }

  #label {
    width: 100%;
    max-width: 170mm;
    break-inside: avoid;
  }

  body.printing-batch .shell {
    display: none !important;
  }

  body.printing-batch #batch-print {
    display: block;
  }

  .print-sheet {
    display: grid;
    grid-template-columns: 130mm 130mm;
    grid-auto-rows: 65mm;
    gap: 8mm;
    break-after: page;
  }

  .print-sheet:last-child {
    break-after: auto;
  }

  .print-sheet canvas {
    width: 130mm;
    height: 65mm;
    display: block;
    break-inside: avoid;
  }

  .label-area {
    display: block;
    padding: 0;
  }

  .label-gallery {
    display: block;
    padding: 0;
  }

  .gallery-heading {
    display: none !important;
  }

  .gallery-tools {
    display: none !important;
  }

  .output-options {
    display: none !important;
  }

  .draft-heading {
    display: none !important;
  }

  .saved-card {
    display: none !important;
  }

  .label-gallery>li {
    border: 0;
    border-radius: 0;
  }

  .draft-card .paper {
    padding: 0;
  }

  .offline-panel {
    display: none !important;
  }

}

@page {
  size: landscape;
  margin: 10mm;
}
