:root {
  --color-bg: #f5f6f8;
  --color-surface: #ffffff;
  --color-text: #1f2933;
  --color-muted: #6b7280;
  --color-accent: #2563eb;
  --color-border: #e5e7eb;
  /* Croix noire personnalisée (liseré blanc pour rester visible partout) */
  --cursor-cross: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Cg stroke-linecap='round'%3E%3Cline x1='12' y1='2' x2='12' y2='22' stroke='white' stroke-width='3'/%3E%3Cline x1='2' y1='12' x2='22' y2='12' stroke='white' stroke-width='3'/%3E%3Cline x1='12' y1='2' x2='12' y2='22' stroke='black' stroke-width='1.5'/%3E%3Cline x1='2' y1='12' x2='22' y2='12' stroke='black' stroke-width='1.5'/%3E%3C/g%3E%3C/svg%3E") 12 12, crosshair;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  background: var(--color-surface);
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--color-border);
}

.app-header h1 {
  margin: 0;
  font-size: 1.5rem;
}

.subtitle {
  margin: 0.25rem 0 0;
  color: var(--color-muted);
}

/* Espace entre le titre d'une carte et un bouton "Choisir un PDF" placé juste après */
.signature-panel .file-button {
  display: inline-block;
  margin-top: 0.85rem;
}

.header-cta {
  display: inline-block;
  margin-top: 0.75rem;
  color: var(--color-accent);
  font-weight: 600;
  text-decoration: none;
}

.header-cta:hover {
  text-decoration: underline;
}

.create-layout {
  max-width: 700px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.signer-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.signer-field input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 1rem;
}

.link-item {
  display: block;
  padding: 0.75rem 0.85rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.link-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.4rem;
}

.link-row input {
  flex: 1;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 0.85rem;
  font-family: monospace;
}

.back-link {
  max-width: 700px;
  margin: 1.5rem auto 0;
}

.back-link a {
  color: var(--color-accent);
}

.badge {
  font-size: 0.8rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-done {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.badge-pending {
  background: #fef9c3;
  color: #854d0e;
  border: 1px solid #fde68a;
}

/* Lien stylé en bouton, état désactivé */
a.file-button {
  display: inline-block;
  text-decoration: none;
  text-align: center;
}

.is-disabled {
  background: var(--color-border);
  color: var(--color-muted);
  cursor: not-allowed;
  pointer-events: none;
}

.message {
  max-width: 600px;
  margin: 2rem auto;
  padding: 1rem 1.25rem;
  border-radius: 10px;
  font-size: 1rem;
  text-align: center;
}

.message-success {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
}

.message-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
}

.app-main {
  flex: 1;
  padding: 2rem;
}

.app-layout {
  display: flex;
  align-items: flex-start;
  gap: 2rem;
  max-width: 1250px;
  margin: 0 auto;
}

.document-column {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.sidebar {
  width: 360px;
  flex-shrink: 0;
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

@media (max-width: 900px) {
  .app-layout {
    flex-direction: column-reverse;
  }

  .sidebar {
    width: 100%;
    position: static;
    max-height: none;
  }
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.file-button {
  background: var(--color-accent);
  color: #fff;
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.file-button:hover {
  filter: brightness(0.95);
}

.file-button:disabled {
  background: var(--color-border);
  color: var(--color-muted);
  cursor: not-allowed;
  filter: none;
}

.file-name {
  color: var(--color-muted);
  font-size: 0.9rem;
}

.signature-panel {
  width: 100%;
  max-width: 800px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
}

.panel-title {
  margin: 0;
  font-size: 1.1rem;
}

.panel-hint {
  margin: 0.25rem 0 1rem;
  color: var(--color-muted);
  font-size: 0.9rem;
}

.field {
  display: block;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  color: var(--color-text);
}

.field input {
  display: block;
  width: 100%;
  max-width: 400px;
  margin-top: 0.35rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 1rem;
}

.signers-section {
  width: 100%;
  max-width: 800px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
}

.option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--color-text);
  cursor: pointer;
}

.option input {
  width: 1rem;
  height: 1rem;
  cursor: pointer;
}

.signers-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.signer-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 0.85rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.remove-button {
  background: transparent;
  border: none;
  color: var(--color-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
}

.remove-button:hover {
  background: #fee2e2;
  color: #b91c1c;
}

.signature-pad {
  width: 100%;
  max-width: 400px;
  height: 150px;
  background: #fff;
  border: 2px dashed var(--color-border);
  border-radius: 8px;
  touch-action: none;
  cursor: var(--cursor-cross);
  display: block;
}

.signature-actions {
  margin-top: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.link-button {
  background: none;
  border: none;
  color: var(--color-muted);
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.5rem 0.25rem;
}

.link-button:hover {
  color: #b91c1c;
}

.saved-note {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--color-accent);
}

.secondary-button {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.secondary-button:hover {
  background: var(--color-bg);
}

.viewer {
  width: 100%;
  max-width: 800px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.page-wrapper {
  position: relative;
  width: 100%;
  line-height: 0;
}

.page-canvas {
  width: 100%;
  height: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  cursor: var(--cursor-cross);
}

.sig-overlay {
  position: absolute;
  transform: translate(-50%, -50%);
  cursor: move;
  touch-action: none;
  border: 1px dashed transparent;
  border-radius: 2px;
}

.sig-overlay:hover,
.sig-overlay.active {
  border-color: var(--color-accent);
}

.sig-overlay-img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
  user-select: none;
}

/* Texte posé sur le document : la boîte épouse la taille du texte */
.text-overlay {
  white-space: nowrap;
  line-height: 1;
}

.text-overlay-content {
  display: block;
  color: #000;
  font-family: Helvetica, Arial, sans-serif;
  pointer-events: none;
  user-select: none;
}

/* Bouton "Placer ce texte" en surbrillance quand le mode texte est actif */
.secondary-button.active {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}

/* Poignée de redimensionnement (coin bas-droite) : visible au survol de la signature */
.sig-handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  background: var(--color-accent);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  cursor: nwse-resize;
  touch-action: none;
  opacity: 0;
  transition: opacity 0.15s;
}

.sig-overlay:hover .sig-handle,
.sig-overlay.active .sig-handle {
  opacity: 1;
}

.place-hint {
  margin: 0;
  padding: 0.6rem 1rem;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  color: #1e40af;
  font-size: 0.9rem;
}

.placeholder {
  width: 100%;
  min-height: 400px;
  background: var(--color-surface);
  border: 2px dashed var(--color-border);
  border-radius: 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--color-muted);
}

.loading,
.error {
  color: var(--color-muted);
}

.error {
  color: #b91c1c;
}

.app-footer {
  padding: 1rem 2rem;
  text-align: center;
  color: var(--color-muted);
  font-size: 0.85rem;
}
