:root {
  color-scheme: light;
  --ink: #1d2433;
  --muted: #687386;
  --line: #d8dee8;
  --panel: #ffffff;
  --soft: #f3f6fa;
  --accent: #1f7a8c;
  --accent-strong: #176273;
  --shadow: 0 18px 45px rgba(31, 45, 61, 0.16);
  --body-bg: #eef2f7;
}

[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e2e8f0;
  --muted: #94a3b8;
  --line: #2d3748;
  --panel: #1e2535;
  --soft: #252f42;
  --accent: #38b2c8;
  --accent-strong: #63c8dc;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.45);
  --body-bg: #141b2d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: var(--body-bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.toolbar-button {
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  min-height: 28px;
  border-radius: 6px;
  padding: 0 8px;
  cursor: pointer;
  white-space: nowrap;
}

.icon-button {
  width: 34px;
  min-width: 34px;
  padding: 0;
  font-weight: 700;
}

.tb-icon {
  width: 16px;
  height: 16px;
  display: block;
  flex-shrink: 0;
  pointer-events: none;
}

.icon-button[data-emoji]::before,
.toolbar-button[data-emoji]::before {
  content: attr(data-emoji);
  display: block;
  font-size: 17px;
  line-height: 1;
  pointer-events: none;
}

.icon-button[data-emoji] .tb-icon,
.toolbar-button[data-emoji] .tb-icon {
  display: none;
}

/* Formes : grille plus aérée avec SVG */
.form-item .tb-icon {
  width: 18px;
  height: 18px;
}

/* Bouton formes remplace form-menu-button */
#formMenuBtn {
  width: 34px;
  min-width: 34px;
  padding: 0;
}

.text-tool-button {
  min-width: 64px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 800;
}

button:hover,
.toolbar-button:hover {
  border-color: var(--accent);
}

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

.app {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr) 184px;
  grid-template-rows: 56px 32px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

.topbar {
  position: relative;
  z-index: 40;
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 6px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.document-tabs {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  overflow-x: auto;
  padding: 4px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--soft);
}

.document-tabs-empty {
  color: var(--muted);
  font-size: 11px;
  padding: 0 4px;
}

.document-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 220px;
  min-height: 24px;
  padding: 0 4px 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.document-tab.active {
  border-color: var(--accent);
  color: var(--accent-strong);
  box-shadow: 0 0 0 2px rgba(31, 122, 140, 0.12);
}

.document-tab-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.document-tab-close {
  width: 20px;
  min-width: 20px;
  min-height: 20px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font-size: 14px;
  line-height: 1;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 170px;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 7px;
  object-fit: cover;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.18);
}

.brand h1 {
  margin: 0;
  font-size: 14px;
}

.panel-head span,
.empty-state p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.brand p {
  display: none;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  overflow-x: auto;
  padding-bottom: 2px;
}

.file-menu-wrap {
  position: relative;
  display: inline-grid;
  flex: 0 0 auto;
}

.file-menu-button {
  min-height: 30px;
  padding: 0 10px;
  border-color: var(--accent);
  color: var(--accent-strong);
  font-size: 10px;
  font-weight: 800;
}

.file-menu {
  position: fixed;
  z-index: 1001;
  min-width: 170px;
  display: grid;
  gap: 3px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.file-menu button {
  justify-content: start;
  min-height: 30px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 11px;
  text-align: left;
}

.file-menu button:hover:not(:disabled) {
  background: var(--soft);
  border: 0;
}

.language-switch {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 30px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  background: var(--panel);
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
}

.language-switch select {
  width: 92px;
  min-height: 22px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 11px;
  font-weight: 800;
  outline: none;
}

.edit-menu {
  min-width: 210px;
}

.view-menu {
  min-width: 190px;
}

.zoom-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 2px 0;
}

.zoom-grid button {
  justify-content: center;
  min-height: 28px;
  padding: 0 4px;
  font-size: 11px;
}

.menu-separator {
  height: 1px;
  margin: 3px 4px;
  background: var(--line);
}

.toolbar-button input {
  display: none;
}

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
  font-weight: 700;
}

.page-meter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 58px;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
  font-size: 13px;
  white-space: nowrap;
}

.divider {
  width: 1px;
  align-self: stretch;
  min-height: 24px;
  background: var(--line);
  margin: 0 3px;
}

.tool.active {
  background: #dff3f5;
  border-color: var(--accent);
  color: var(--accent-strong);
  font-weight: 700;
}

#cursorMode.active {
  background: #1f7a8c;
  color: white;
}

.form-menu-wrap {
  position: relative;
  display: inline-grid;
}

.form-menu-button {
  min-width: 54px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 800;
}

.form-menu {
  position: fixed;
  z-index: 1000;
  display: grid;
  grid-template-columns: repeat(4, 34px);
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.form-item {
  width: 34px;
  min-width: 34px;
  height: 32px;
  padding: 0;
  font-size: 18px;
  font-weight: 800;
}

.pages-panel,
.inspector {
  min-height: 0;
  background: var(--panel);
  overflow: hidden;
}

.pages-panel {
  border-right: 1px solid var(--line);
}

.inspector {
  border-left: 1px solid var(--line);
  overflow-y: auto;
}

.panel-head {
  padding: 7px 8px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  margin: 0;
  font-size: 13px;
}

.section h3 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.thumbnail-list {
  height: calc(100vh - 136px);
  overflow-y: auto;
  padding: 12px;
}

.panel-empty {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  padding: 8px;
}

.thumbnail {
  width: 100%;
  display: grid;
  gap: 5px;
  margin-bottom: 9px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  text-align: left;
}

.thumbnail.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(31, 122, 140, 0.16);
}

.thumbnail canvas {
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  background: var(--panel);
}

.thumbnail span {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.workspace {
  min-width: 0;
  min-height: 0;
}

.viewer {
  position: relative;
  height: calc(100vh - 88px);
  overflow: auto;
  padding: 18px;
}

.empty-state {
  width: min(520px, calc(100% - 24px));
  margin: 12vh auto;
  padding: 28px;
  border: 1px dashed #b8c2d2;
  background: var(--panel);
  border-radius: 8px;
  text-align: center;
}

.empty-state h2 {
  margin: 0;
  font-size: 22px;
}

.page-host {
  position: relative;
  margin: 0 auto;
  background: var(--panel);
}

#pdfCanvas,
#annotationCanvas {
  display: block;
  position: absolute;
  inset: 0;
}

#annotationCanvas {
  z-index: 3;
  cursor: crosshair;
}

body.cursor-mode #annotationCanvas {
  cursor: grab;
  z-index: 6;
}

body.edit-mode #annotationCanvas {
  z-index: 6;
}

body.text-insert-mode #annotationCanvas {
  cursor: text;
}

body.peel-mode #annotationCanvas {
  cursor: copy;
}

body.text-select-mode #annotationCanvas {
  z-index: 1;
  pointer-events: none;
}

body.cursor-mode #annotationCanvas:active {
  cursor: grabbing;
}

body.precision-mode #annotationCanvas {
  cursor: crosshair;
}

body.cursor-mode .text-layer {
  pointer-events: none;
}

body.edit-mode .text-layer {
  pointer-events: none;
}

body.text-select-mode .text-layer {
  z-index: 6;
  pointer-events: auto;
  cursor: text;
}

body.text-select-mode .text-layer span {
  pointer-events: auto;
}

.text-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
  overflow: hidden;
  line-height: 1;
  user-select: text;
  -webkit-user-select: text;
  pointer-events: none;
}

.text-layer span {
  position: absolute;
  display: inline-block;
  color: transparent;
  cursor: text;
  transform-origin: 0 0;
  white-space: pre;
  line-height: 1;
  user-select: text;
  -webkit-user-select: text;
  pointer-events: auto;
}

.text-layer ::selection {
  background: rgba(37, 99, 235, 0.35);
}

.text-layer span.pdf-text-selected {
  background: rgba(37, 99, 235, 0.35);
}

.text-layer .pdf-char-selected {
  position: absolute;
  z-index: 1;
  background: rgba(37, 99, 235, 0.35);
  pointer-events: none;
}

#textEditor {
  position: absolute;
  z-index: 80;
  min-width: 180px;
  min-height: 42px;
  resize: both;
  border: 2px solid #111827;
  border-radius: 6px;
  padding: 8px;
  background: #fffef4;
  color: var(--ink);
  outline: none;
  box-shadow: 0 10px 24px rgba(31, 45, 61, 0.22);
}

.section {
  padding: 7px 8px;
  border-bottom: 1px solid var(--line);
}

.field {
  display: grid;
  grid-template-columns: minmax(50px, 1fr) minmax(70px, 76px);
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.15;
  margin-bottom: 6px;
}

.field input,
.field select,
.file-field {
  width: 100%;
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 6px;
  background: var(--panel);
  color: var(--ink);
  font-size: 11px;
}

body.rtl {
  direction: rtl;
}

body.rtl .app {
  grid-template-columns: 184px minmax(0, 1fr) 160px;
}

body.rtl .pages-panel {
  grid-column: 3;
  border-right: 1px solid var(--line);
  border-left: 0;
}

body.rtl .workspace {
  grid-column: 2;
  direction: ltr;
}

body.rtl .inspector {
  grid-column: 1;
  border-left: 1px solid var(--line);
  border-right: 0;
  direction: rtl;
}

body.rtl .toolbar,
body.rtl .document-tabs,
body.rtl .viewer,
body.rtl .page-host,
body.rtl .text-layer {
  direction: ltr;
}

body.rtl .file-menu button,
body.rtl .thumbnail {
  text-align: right;
}

body.rtl .field {
  grid-template-columns: minmax(70px, 76px) minmax(50px, 1fr);
}

.file-field {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 6px;
  cursor: pointer;
}

.file-field input {
  display: none;
}

.field input[type="color"] {
  height: 24px;
  padding: 2px;
}

.field input[type="range"] {
  padding: 0;
}

.range-with-value {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  gap: 6px;
  align-items: center;
}

.field .value-input {
  width: 48px;
  min-width: 0;
  min-height: 26px;
  padding: 0 4px;
  font-size: 11px;
  text-align: center;
}

.align-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin: -2px 0 6px;
}

.align-button {
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.align-button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.table-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin: 4px 0 6px;
}

.table-actions button,
.wide-button {
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.table-actions button:hover,
.wide-button:hover {
  border-color: var(--accent);
}

.table-axis-controls {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

.table-axis-controls label {
  min-height: 26px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
}

.table-axis-controls input {
  margin: 0;
}

.table-actions .danger-action {
  grid-column: 1 / -1;
  border-color: #f3b4b4;
  color: #b42318;
}

.table-actions .danger-action:hover {
  border-color: #dc2626;
  background: #fff1f1;
}

.table-cell-value {
  grid-template-columns: 1fr;
}

.table-cell-value textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 6px;
  background: var(--panel);
  color: var(--ink);
  font-size: 11px;
  resize: vertical;
}

.legal-note {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.25;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
}

.shape-palette {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.shape-button {
  height: 42px;
  padding: 0;
}

.shape-icon,
.shape-text {
  position: relative;
  display: block;
  width: 26px;
  height: 22px;
}

.shape-text {
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 18px;
}

.rect-icon {
  border: 2px solid currentColor;
}

.ellipse-icon {
  border: 2px solid currentColor;
  border-radius: 50%;
}

.line-icon::before,
.arrow-icon::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 11px;
  width: 22px;
  border-top: 2px solid currentColor;
  transform: rotate(-28deg);
  transform-origin: left center;
}

.arrow-icon::after {
  content: "";
  position: absolute;
  right: 0;
  top: 3px;
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-top: 2px solid currentColor;
  transform: rotate(18deg);
}

.highlight-icon {
  height: 12px;
  margin-top: 5px;
  background: #f4c430;
  border: 1px solid rgba(29, 36, 51, 0.35);
}

.mask-icon {
  border: 2px solid currentColor;
  background:
    linear-gradient(135deg, transparent 0 42%, currentColor 42% 50%, transparent 50%),
    #f8fafc;
}

.camera-panel {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(29, 36, 51, 0.42);
}

.stamp-modal {
  position: fixed;
  inset: 0;
  z-index: 35;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(29, 36, 51, 0.42);
}

.stamp-dialog {
  width: min(780px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.stamp-dialog-head,
.stamp-dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.stamp-dialog-actions {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.stamp-dialog-head h2 {
  margin: 0;
  font-size: 15px;
}

.stamp-dialog-head span {
  color: var(--muted);
  font-size: 11px;
}

.stamp-dialog-body {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(240px, 320px) minmax(240px, 1fr);
  gap: 12px;
  padding: 12px;
  overflow: auto;
  align-items: start;
}

.stamp-form {
  display: grid;
  align-content: start;
}

.stamp-preview-panel {
  position: sticky;
  top: 0;
  min-height: 320px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.stamp-preview {
  width: min(320px, 100%);
  aspect-ratio: 1.35;
  display: grid;
  place-items: center;
}

.stamp-preview svg {
  width: 100%;
  height: 100%;
  display: block;
}

.stamp-preview-rotator {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  transform-origin: center;
}

.stamp-template-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}

.stamp-template-actions button,
.stamp-dialog-actions button {
  min-height: 30px;
}

.choice-panel {
  position: fixed;
  inset: 0;
  z-index: 19;
  display: grid;
  place-items: center;
  background: rgba(29, 36, 51, 0.28);
}

.choice-box {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  width: min(360px, calc(100vw - 32px));
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.choice-box button {
  min-height: 38px;
}

.save-choice-box {
  display: grid;
  gap: 9px;
  width: min(420px, calc(100vw - 32px));
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.save-choice-box h2 {
  margin: 0;
  font-size: 16px;
}

.save-choice-box p {
  margin: 0;
  font-weight: 800;
}

.save-choice-box span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.save-choice-actions {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  margin-top: 4px;
}

.save-choice-actions button {
  min-height: 34px;
}

.camera-box {
  width: min(620px, calc(100vw - 32px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  box-shadow: var(--shadow);
}

.camera-box video {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #111827;
  display: block;
}

.camera-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding-top: 10px;
}

.camera-actions button {
  width: 42px;
  min-width: 42px;
  padding: 0;
  font-size: 20px;
}

.context-menu {
  position: fixed;
  z-index: 30;
  min-width: 160px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.context-menu button {
  width: 100%;
  justify-content: start;
  min-height: 28px !important;
  height: 28px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 12px;
  line-height: 1;
}

.context-menu button:hover {
  background: var(--soft);
  border: 0;
}

.context-menu button:disabled {
  color: var(--muted);
  cursor: default;
}

.context-menu button.hidden,
.context-separator.hidden {
  display: none;
}

.context-separator {
  height: 1px;
  margin: 3px 2px;
  background: var(--line);
}

.history-panel {
  display: block;
}

.history-panel summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 28px;
  cursor: pointer;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
  list-style: none;
}

.history-panel summary::-webkit-details-marker {
  display: none;
}

.history-panel summary::before {
  content: "+";
  width: 16px;
  color: var(--accent-strong);
  font-size: 14px;
  line-height: 1;
}

.history-panel[open] summary::before {
  content: "-";
}

#historyCount {
  min-width: 22px;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--accent-strong);
  font-size: 10px;
  text-align: center;
}

.toggle-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
}

.text-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.text-actions button {
  min-height: 28px;
  padding: 0;
  font-weight: 800;
}

.history-list {
  display: grid;
  gap: 4px;
  max-height: 178px;
  overflow-y: auto;
}

.history-list button {
  width: 100%;
  min-height: 26px;
  justify-content: start;
  padding: 3px 6px;
  border-color: var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 11px;
  text-align: left;
}

.history-list button.active {
  border-color: var(--accent);
  background: rgba(31, 122, 140, 0.1);
  color: var(--accent-strong);
  font-weight: 800;
}

.history-list button:disabled {
  color: var(--muted);
  background: var(--soft);
}

.stroke-presets {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  margin: -1px 0 6px;
}

.stroke-preset {
  min-height: 24px;
  padding: 0 4px;
}

.stroke-preset span {
  display: block;
  width: 100%;
  border-radius: 999px;
  background: currentColor;
}

.swatch {
  min-height: 24px;
  padding: 0;
  background: var(--swatch);
}

.info-box {
  display: grid;
  gap: 3px;
}

.info-box span {
  color: var(--accent-strong);
  font-weight: 700;
}

.info-box small {
  color: var(--muted);
  font-size: 11px;
}

.hidden {
  display: none !important;
}

/* ── Tampon : sections repliables ───────────────────────────────────────── */
.stamp-section {
  border-bottom: 1px solid var(--line);
}

.stamp-section-title {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 4px;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.stamp-section-title::-webkit-details-marker { display: none; }

.stamp-section-title::before {
  content: "▶";
  font-size: 8px;
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

details.stamp-section[open] > .stamp-section-title::before {
  transform: rotate(90deg);
}

.stamp-section-body {
  padding: 0 0 4px 2px;
}

.stamp-section-body .field {
  margin-bottom: 3px;
}

.stamp-section-body .toggle-row {
  margin-bottom: 3px;
}

.stamp-section-body .stamp-slider-row {
  margin-bottom: 3px;
}

/* ── Tampon : slider avec valeur affichée ───────────────────────────────── */
.stamp-slider-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 4px;
  margin-bottom: 6px;
}

.stamp-slider-row .field {
  margin-bottom: 0;
}

.slider-val {
  min-width: 32px;
  text-align: right;
  font-size: 10px;
  font-weight: 700;
  color: var(--accent-strong);
  white-space: nowrap;
}

/* ── Tampon : préréglages rapides ───────────────────────────────────────── */
.stamp-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 8px 2px 10px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
}

.stamp-preset-btn {
  flex: 1 1 auto;
  min-height: 28px;
  padding: 0 7px;
  font-size: 10px;
  font-weight: 700;
  border-radius: 6px;
  white-space: nowrap;
}

.stamp-preset-btn:hover {
  border-color: var(--accent);
  background: var(--soft);
}

/* ── Tampon : input inline pour nommer un modèle ────────────────────────── */
.stamp-save-name-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 4px;
  margin-top: 6px;
}

.stamp-save-name-row input {
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 6px;
  font-size: 11px;
  background: var(--panel);
  color: var(--ink);
}

.stamp-save-name-row button {
  min-height: 28px;
  min-width: 32px;
  padding: 0 6px;
  font-size: 11px;
}

/* ── Tampon scanné ──────────────────────────────────────────────────────── */
.stamp-scan-hint {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.4;
}

.stamp-scan-upload {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 0 8px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  margin-bottom: 6px;
  transition: border-color 0.15s, color 0.15s;
}

.stamp-scan-upload:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.stamp-scan-preview-wrap {
  position: relative;
  display: inline-flex;
  margin-bottom: 6px;
}

.stamp-scan-thumb {
  max-width: 100%;
  max-height: 90px;
  border: 1px solid var(--line);
  border-radius: 6px;
  object-fit: contain;
  background: white;
}

.stamp-scan-clear {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  min-width: 18px;
  height: 18px;
  min-height: 18px;
  padding: 0;
  font-size: 9px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--panel);
  border: none;
  cursor: pointer;
  line-height: 1;
}

/* ── Tampon scanné : vectorisation ──────────────────────────────────────── */
.stamp-vec-run-btn {
  width: 100%;
  min-height: 28px;
  margin: 4px 0 2px;
  font-weight: 700;
  font-size: 11px;
}

.stamp-vec-status {
  padding: 4px 6px;
  font-size: 10px;
  color: var(--accent-strong);
  font-weight: 700;
}

.stamp-vec-preview-wrap {
  margin-top: 6px;
}

.stamp-vec-svg-preview {
  width: 100%;
  min-height: 80px;
  max-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  margin-bottom: 6px;
  overflow: hidden;
}

.stamp-vec-svg-preview svg {
  max-width: 100%;
  max-height: 120px;
  display: block;
}

#stampScanApplyBtn {
  width: 100%;
  min-height: 30px;
  margin-top: 4px;
}

/* ── Générateur QR / Barcode ─────────────────────────────────────────────── */
.qrgen-dialog {
  width: min(980px, calc(100vw - 24px));
  max-height: calc(100vh - 40px);
  display: grid;
  grid-template-rows: auto 1fr;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.qrgen-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.qrgen-head h2 { margin: 0; font-size: 14px; }

.qrgen-body {
  display: grid;
  grid-template-columns: minmax(520px, 2.3fr) minmax(240px, 1fr);
  gap: 0;
  overflow-y: auto;
}

.qrgen-form {
  padding: 10px 12px;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.qrgen-content-field {
  display: block;
}

.qrgen-content-field input {
  display: block;
  width: 100%;
  min-height: 30px;
  margin-top: 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 12px;
  box-sizing: border-box;
}

.qrgen-colors {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.qrgen-hint {
  font-size: 10px;
  color: var(--accent-strong);
  padding: 2px 0 4px;
}

#qrgenGenerateBtn {
  margin-top: 6px;
  min-height: 30px;
}

.qrgen-preview-col {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.qrgen-preview {
  width: 100%;
  flex: 1;
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  overflow: hidden;
}

.qrgen-preview canvas,
.qrgen-preview svg {
  max-width: 100%;
  max-height: 200px;
  display: block;
}

.qrgen-preview-hint {
  font-size: 11px;
  color: var(--muted);
}

#qrgenInsertBtn {
  width: 100%;
  min-height: 32px;
  font-size: 12px;
}

@media (max-width: 820px) {
  .qrgen-body { grid-template-columns: 1fr; }
  .qrgen-form { border-right: none; border-bottom: 1px solid var(--line); }
}

/* ── Scanner QR / Barcode ───────────────────────────────────────────────── */
.qr-selection-overlay {
  position: absolute;
  border: 2px dashed var(--accent);
  background: rgba(31, 122, 140, 0.08);
  pointer-events: none;
  box-sizing: border-box;
}

.qr-result-panel {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  width: min(420px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.qr-result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px 6px;
  border-bottom: 1px solid var(--line);
}

.qr-result-type {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.qr-result-content {
  padding: 10px 12px;
  font-size: 13px;
  word-break: break-all;
  color: var(--ink);
  max-height: 120px;
  overflow-y: auto;
  font-family: monospace;
}

.qr-result-actions {
  display: flex;
  gap: 6px;
  padding: 6px 10px 10px;
}

.qr-result-actions button {
  flex: 1;
  min-height: 28px;
  font-size: 12px;
}

@media (max-width: 980px) {
  .app {
    grid-template-columns: 118px minmax(220px, 1fr) 150px;
    grid-template-rows: 56px 32px minmax(0, 1fr);
  }

  .topbar {
    align-items: center;
    flex-direction: row;
  }

  .brand {
    min-width: 140px;
  }

  .brand h1 {
    font-size: 13px;
  }

  .viewer {
    height: calc(100vh - 88px);
  }

  .thumbnail-list {
    height: calc(100vh - 136px);
  }

  .shape-palette,
  .toggle-row {
    grid-template-columns: 1fr;
  }

  .stamp-dialog-body {
    grid-template-columns: 1fr;
  }
}

/* ── Panneau raccourcis clavier ─────────────────────────────────────────── */
.shortcuts-dialog {
  width: min(680px, calc(100vw - 28px));
  max-height: calc(100vh - 40px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.shortcuts-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.shortcuts-head h2 {
  margin: 0;
  font-size: 15px;
}

.shortcuts-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  overflow-y: auto;
  padding: 8px 6px 14px;
}

.shortcuts-group {
  padding: 10px 10px 4px;
}

.shortcuts-group h3 {
  margin: 0 0 8px;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.shortcuts-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 28px;
  padding: 3px 6px;
  border-radius: 6px;
  font-size: 12px;
}

.shortcuts-row:hover {
  background: var(--soft);
}

.shortcut-desc {
  color: var(--ink);
  flex: 1;
}

.shortcut-keys {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
  color: var(--muted);
  font-size: 11px;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--soft);
  color: var(--ink);
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

@media (max-width: 600px) {
  .shortcuts-body {
    grid-template-columns: 1fr;
  }

}

/* Module tableau moderne */
.table-edit-panel {
  position: fixed;
  z-index: 45;
  top: 88px;
  left: 160px;
  right: 184px;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 8px 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  font-size: 11px;
  overflow-x: auto;
}

.tep-head {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  flex: 0 0 auto;
  white-space: nowrap;
}

.tep-ref {
  font-size: 11px;
  font-weight: 800;
  color: var(--accent);
  min-width: 28px;
}

.tep-tools {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
}

.tep-row-col-actions {
  display: flex;
  gap: 2px;
  flex: 0 0 auto;
}

.tep-btn {
  min-width: 24px;
  width: 24px;
  height: 24px;
  min-height: 24px;
  padding: 0;
  font-size: 10px;
}

.tep-btn.active {
  background: var(--soft);
  border-color: var(--accent);
  color: var(--accent);
}

.tep-color-wrap {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
  color: var(--ink);
}

.tep-color-wrap input[type="color"] {
  width: 20px;
  height: 18px;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0;
  cursor: pointer;
}

.tep-formula {
  flex: 1 1 220px;
  width: auto;
  min-width: 180px;
  box-sizing: border-box;
  min-height: 26px;
  padding: 3px 8px;
  border: none;
  border-bottom: 1px solid var(--line);
  background: var(--soft);
  color: var(--ink);
  font-size: 12px;
  font-family: monospace;
}

.tep-formula:focus {
  outline: none;
  background: var(--panel);
  border-bottom-color: var(--accent);
}

.tep-table-props {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0;
  flex: 0 0 auto;
  white-space: nowrap;
}

.tep-field {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  color: var(--ink);
  font-size: 10px;
  font-weight: 700;
}

.tep-field select,
.tep-field input {
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  color: var(--ink);
  font-size: 10px;
}

.tep-field select {
  width: 122px;
}

.tep-size-field input {
  width: 44px;
}

.tbl-create-dialog {
  width: min(500px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.tbl-create-body {
  padding: 12px;
}

.tbl-grid-picker {
  display: grid;
  grid-template-columns: repeat(10, 22px);
  gap: 2px;
  margin-bottom: 4px;
}

.tbl-cell-pick {
  width: 22px;
  height: 18px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--soft);
  cursor: pointer;
  transition: background 0.1s;
}

.tbl-cell-pick.active {
  background: var(--accent);
  border-color: var(--accent-strong);
}

.tbl-create-opts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
  font-size: 11px;
}

.tbl-create-opts .field {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  font-size: 11px;
}

.tbl-create-opts input[type="number"] {
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 4px;
  background: var(--panel);
  color: var(--ink);
  font-size: 11px;
}

@media (max-width: 980px) {
  .table-edit-panel {
    left: 118px;
    right: 150px;
  }
}

@media (max-width: 600px) {
  .table-edit-panel {
    left: 8px;
    right: 8px;
    flex-wrap: wrap;
    max-height: 128px;
  }
}
