/* ===== PDF-Formulare Styles ===== */

/* Button "PDF-Formular ausfüllen" im Upload-Sheet — analog .up-file-picker */
.up-pdf-form-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 14px 16px;
  margin-top: 8px;
  background: var(--surface-2, rgba(128,128,128,0.08));
  border: 1.5px dashed var(--border, rgba(128,128,128,0.3));
  border-radius: 12px;
  color: var(--text-primary, inherit);
  font-size: 1rem;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}
.up-pdf-form-btn:hover,
.up-pdf-form-btn:focus-visible {
  background: var(--surface-3, rgba(128,128,128,0.14));
  outline: none;
}

/* ===== Sheet-Kopfzeile (Zurück-Pfeil + Titel + Schrittanzeige) ===== */
.pdf-sheet-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.pdf-sheet-back {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid var(--border, rgba(128,128,128,0.3));
  border-radius: 10px;
  background: transparent;
  color: var(--text-primary, inherit);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.12s;
}

.pdf-sheet-back:hover {
  background: var(--surface-3, rgba(128,128,128,0.12));
}

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

.pdf-sheet-title {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pdf-sheet-step {
  font-size: 0.75rem;
  color: var(--text-secondary, rgba(128,128,128,0.8));
}

/* Import-Label (styled wie btn-secondary) — als <label> greift
   ".modal-actions button" nicht, daher Höhe/Layout hier setzen */
.pdf-import-label {
  cursor: pointer;
  flex: 1;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 1rem;
  font-weight: 600;
  border-radius: var(--radius-btn, 14px);
}

/* ===== Template-Liste ===== */
.pdf-template-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 40vh;
  overflow-y: auto;
  margin-bottom: 4px;
}

.pdf-template-list-empty {
  color: var(--text-secondary, rgba(128,128,128,0.8));
  font-size: 0.9rem;
  text-align: center;
  padding: 24px 0;
}

.pdf-template-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface-2, rgba(128,128,128,0.06));
  border-radius: 10px;
  border: 1px solid var(--border, rgba(128,128,128,0.15));
}

.pdf-template-item__name {
  flex: 1;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pdf-template-item__actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.pdf-template-item__actions button {
  min-height: 44px;
  padding: 6px 14px;
  font-size: 0.82rem;
  border-radius: 8px;
  border: 1px solid var(--border, rgba(128,128,128,0.3));
  background: transparent;
  color: var(--text-primary, inherit);
  cursor: pointer;
  transition: background 0.12s;
}
.pdf-template-item__actions button:hover {
  background: var(--surface-3, rgba(128,128,128,0.12));
}
.pdf-template-item__actions .btn-select {
  border-color: var(--accent, #007aff);
  color: var(--accent, #007aff);
}
.pdf-template-item__actions .btn-delete-tpl {
  border-color: var(--danger, #ff3b30);
  color: var(--danger, #ff3b30);
}

/* ===== Formular-Editor ===== */
.pdf-form-pages {
  max-height: 35vh;
  overflow-y: auto;
  border: 1px solid var(--border, rgba(128,128,128,0.2));
  border-radius: 10px;
  background: var(--surface-2, rgba(128,128,128,0.04));
  margin-bottom: 16px;
}

.pdf-form-page-canvas {
  width: 100%;
  display: block;
}

.pdf-form-pages .pdf-form-page-canvas + .pdf-form-page-canvas {
  border-top: 1px solid var(--border, rgba(128,128,128,0.15));
}

.pdf-form-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 35vh;
  overflow-y: auto;
  padding-right: 2px;
}

.pdf-field-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.pdf-field-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary, rgba(128,128,128,0.9));
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.pdf-field-label.is-required::after {
  content: ' *';
  color: var(--danger, #ff3b30);
}

.pdf-field-input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--border, rgba(128,128,128,0.3));
  background: var(--surface-1, transparent);
  color: var(--text-primary, inherit);
  font-size: 1rem;
  width: 100%;
  box-sizing: border-box;
  transition: border-color 0.15s;
}
.pdf-field-input:focus {
  outline: none;
  border-color: var(--accent, #007aff);
}
.pdf-field-input.is-error {
  border-color: var(--danger, #ff3b30);
}

textarea.pdf-field-input {
  min-height: 80px;
  resize: vertical;
}

.pdf-field-checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}

.pdf-field-checkbox-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: var(--accent, #007aff);
}

.pdf-field-radio-group {
  border: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pdf-field-radio-option {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  cursor: pointer;
}

.pdf-field-radio-option input[type="radio"] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: var(--accent, #007aff);
}

/* ===== Signatur-Button & Vorschau ===== */
.pdf-sig-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1.5px dashed var(--border, rgba(128,128,128,0.4));
  background: transparent;
  color: var(--text-primary, inherit);
  font-size: 0.95rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  width: 100%;
  justify-content: center;
}
.pdf-sig-btn:hover {
  background: var(--surface-2, rgba(128,128,128,0.08));
}
.pdf-sig-btn.is-signed {
  border-color: #34c759;
  color: #34c759;
  border-style: solid;
}

.pdf-sig-preview {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 1;
  margin-top: 6px;
  border-radius: 6px;
  border: 1px solid var(--border, rgba(128,128,128,0.2));
  background: white;
}

/* ===== Signaturdialog Canvas ===== */
.pdf-sig-canvas-wrap {
  width: 100%;
  aspect-ratio: 3 / 1;
  border-radius: 10px;
  border: 1.5px solid var(--border, rgba(128,128,128,0.35));
  background: white;
  overflow: hidden;
  margin-bottom: 4px;
  touch-action: none;
}

.pdf-sig-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

.pdf-sig-rotate-hint {
  display: none;
  font-size: 0.82rem;
  color: var(--text-secondary, rgba(128,128,128,0.8));
  text-align: center;
  margin-top: 4px;
}

/* Auf Smartphones im Hochformat: Hinweis einblenden */
@media (pointer: coarse) and (orientation: portrait) {
  .pdf-sig-rotate-hint {
    display: block;
  }
}

/* Im Querformat auf Touch-Geräten (Smartphones/Tablets):
   Dialog füllt den Bildschirm aus, Canvas wächst flexibel */
@media (pointer: coarse) and (orientation: landscape) {
  #dialog-pdf-signature {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    margin: 0;
    top: 0;
    left: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
  }

  #dialog-pdf-signature .sheet-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    box-sizing: border-box;
    overflow: hidden;
  }

  #dialog-pdf-signature .modal-title {
    flex-shrink: 0;
    margin: 0 0 8px 0;
    font-size: 1rem;
  }

  .pdf-sig-canvas-wrap {
    flex: 1;
    aspect-ratio: unset;
    margin-bottom: 0;
    min-height: 0;
  }

  #dialog-pdf-signature .modal-actions {
    flex-shrink: 0;
    margin-top: 8px;
    padding-bottom: 0;
  }

  .pdf-sig-rotate-hint {
    display: none;
  }
}

/* ===== PDF-Vorschau nach Flatten ===== */
.pdf-preview-pages {
  max-height: 65vh;
  overflow-y: auto;
  border: 1px solid var(--border, rgba(128,128,128,0.2));
  border-radius: 10px;
  background: var(--surface-2, rgba(128,128,128,0.04));
  margin-bottom: 16px;
}

.pdf-preview-page-canvas {
  width: 100%;
  display: block;
}

.pdf-preview-pages .pdf-preview-page-canvas + .pdf-preview-page-canvas {
  border-top: 1px solid var(--border, rgba(128,128,128,0.15));
}

/* ===== Fehlermeldung ===== */
.pdf-error-msg {
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(255, 59, 48, 0.1);
  border: 1px solid rgba(255, 59, 48, 0.3);
  color: var(--danger, #ff3b30);
  font-size: 0.9rem;
  margin-bottom: 10px;
}

/* ===== Ladeanzeige ===== */
.pdf-loading {
  text-align: center;
  padding: 24px;
  color: var(--text-secondary, rgba(128,128,128,0.7));
  font-size: 0.9rem;
  animation: pdf-pulse 1.2s ease-in-out infinite;
}

@keyframes pdf-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ===== Gerät-Suchblock im PDF-Formular ===== */
.pdf-device-search-block {
  margin: 20px 0 8px;
  padding: 14px;
  border: 1.5px dashed var(--border, rgba(128,128,128,0.3));
  border-radius: 12px;
  background: var(--surface-2, rgba(128,128,128,0.05));
}

.pdf-device-search-block--confirmed {
  border-style: solid;
  border-color: #34c759;
  background: rgba(52, 199, 89, 0.06);
}

.pdf-device-search-heading {
  margin: 0 0 10px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary, rgba(128,128,128,0.7));
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.pdf-device-search-input-wrap {
  margin-bottom: 10px;
}

.pdf-device-search-results {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}

.pdf-device-search-status {
  font-size: 0.88rem;
  color: var(--text-secondary, rgba(128,128,128,0.6));
  padding: 6px 0;
  margin: 0;
}


.pdf-device-search-confirmed {
  margin: 0 0 8px;
  font-size: 0.9rem;
  color: #34c759;
  font-weight: 500;
}
