/* Shared receipt and extension signature styles. */
.sig-x.sig-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(15, 23, 42, .55);
  backdrop-filter: blur(2px);
  overscroll-behavior: contain;
}
.sig-x .sig-dialog {
  width: min(680px, 100%);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: .8rem;
  border: 1px solid #e2e8f0;
  box-shadow: 0 24px 70px rgba(15, 23, 42, .28);
  overflow: hidden;
}
.sig-x.sig-backdrop--expanded { padding: .5rem; }
.sig-x.sig-backdrop--expanded .sig-dialog {
  width: min(1100px, 100%);
  max-height: calc(100vh - 1rem);
}
.sig-x .sig-dialog-header {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #f1f5f9;
  background: #f8fafc;
}
.sig-x .sig-dialog-header h4 { margin: 0 0 .15rem; font-size: 1rem; color: #1e293b; }
.sig-x .sig-dialog-header p { margin: 0; font-size: .82rem; color: #64748b; }
.sig-x .sig-close-btn {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  background: #fff;
  color: #475569;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.sig-x .sig-close-btn:hover { background: #f1f5f9; }
.sig-x .sig-dialog-body {
  padding: 1.25rem;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* ---- Pole podpisu (modal + sekcja edycji) ---- */
.sig-x .sig-mode-selector { display: flex; flex-wrap: wrap; gap: .4rem 1rem; margin-bottom: .85rem; }
.sig-x .sig-mode-opt {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .85rem; color: #334155; margin: 0; cursor: pointer;
}
.sig-x .sig-mode-group.is-disabled { opacity: .4; pointer-events: none; filter: grayscale(1); }
.sig-x .sig-field-group { margin-bottom: .75rem; }
.sig-x .sig-field-heading {
  display: flex; align-items: center; justify-content: space-between;
  gap: .75rem; margin-bottom: .35rem;
}
.sig-x .sig-field-heading .sig-field-label { margin-bottom: 0; }
.sig-x .sig-pad-wrapper {
  position: relative;
  padding: 8px;
  border: 2px dashed #cbd5e1;
  border-radius: .6rem;
  background: #f8fafc;
  overscroll-behavior: contain;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.sig-x .sig-pad-wrapper::after {
  content: "";
  position: absolute;
  inset: 16px;
  z-index: 0;
  border: 1px solid rgba(148, 163, 184, .22);
  border-radius: .25rem;
  pointer-events: none;
}
.sig-x .sig-pad-wrapper.is-pointer-over {
  border-color: var(--pico-primary, #2563eb);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.sig-x .sig-pad-wrapper.is-drawing {
  border-style: solid;
  border-color: var(--pico-primary, #2563eb);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, .14);
}
.sig-x .sig-pad {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  border-radius: .4rem;
  background: #fff;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: crosshair;
}
.sig-x .sig-pad-actions {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: .55rem .8rem; margin-top: .5rem;
}
.sig-x .sig-pad-buttons { display: flex; align-items: center; flex-wrap: wrap; gap: .45rem; }
.sig-x .sig-pad-tool { padding: .3rem .7rem; font-size: .78rem; }
.sig-x .sig-pad-hint { color: #64748b; font-size: .74rem; }
.sig-x .sig-field-label { display: block; font-size: .82rem; font-weight: 600; color: #475569; margin-bottom: .35rem; }
.sig-x .sig-hint { display: block; margin-top: .3rem; font-size: .72rem; color: #94a3b8; }
.sig-x .sig-errors { margin: .25rem 0 .65rem; font-size: .78rem; color: #dc2626; }

/* ---- Akcje modalu (przyciski) ---- */
.sig-x .sig-dialog-actions {
  display: flex; justify-content: flex-end; gap: .6rem;
  margin-top: 1rem; padding-top: .75rem; border-top: 1px solid #f1f5f9;
}
.sig-x .sig-btn-save {
  background: var(--pico-primary);
  color: white; border: none;
  padding: .45rem 1.5rem; border-radius: .4rem; font-weight: 600; cursor: pointer;
}
.sig-x .sig-btn-cancel {
  background: #fff; border: 1px solid #cbd5e1; color: #64748b;
  padding: .45rem 1.25rem; border-radius: .4rem; cursor: pointer;
}
.sig-x .sig-btn-cancel:disabled { opacity: .5; cursor: not-allowed; }

/* ---- Sekcja podpisu przedłużenia w formularzu edycji ---- */
.ext-sig-section { margin-top: .5rem; }
.ext-sig-section.is-locked { opacity: .5; pointer-events: none; filter: grayscale(1); }
.ext-sig-lock-note { font-size: .78rem; color: #64748b; margin: .25rem 0 .5rem; }

/* ---- Podgląd podpisu w historii (globalne, unikatowe nazwy) ---- */
.sig-view { display: inline-flex; flex-direction: column; gap: .3rem; }
.sig-view-img {
  max-width: 220px; max-height: 120px;
  border: 1px solid #e2e8f0; border-radius: .4rem; background: #f8fafc;
  padding: .3rem; object-fit: contain; cursor: zoom-in;
}
.sig-view-actions { display: flex; gap: .6rem; font-size: .76rem; }

.sig-lightbox-backdrop {
  position: fixed; inset: 0; z-index: 10000;
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem; background: rgba(15, 23, 42, .8); cursor: zoom-out;
}
.sig-lightbox-img {
  max-width: 100%; max-height: 100%;
  background: #fff; border-radius: .4rem; padding: .5rem;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .5);
}

@media (max-width: 640px) {
  .sig-x.sig-backdrop { padding: .5rem; }
  .sig-x .sig-dialog { max-height: calc(100vh - 1rem); }
  .sig-x .sig-dialog-body { padding: 1rem; }
  .sig-x .sig-field-heading { align-items: flex-start; }
  .sig-x .sig-pad-actions { align-items: flex-start; }
  .sig-x .sig-dialog-actions > button { flex: 1 1 0; }
}

.sig-preview { display: flex; flex-direction: column; align-items: center; gap: .4rem; padding: .75rem; border-radius: .6rem; background: #f8fafc; margin: .25rem 0 1rem; }
.sig-preview.has-signature { border: 2px solid #cbd5e1; }
.sig-preview.is-empty { border: 2px dashed #cbd5e1; }
.sig-preview-label { font-size: .82rem; font-weight: 600; color: #475569; }
.sig-preview-img { display: block; max-width: 100%; max-height: 140px; object-fit: contain; }
.sig-preview-empty { font-size: .85rem; color: #94a3b8; }
.signature-submit-errors { white-space: pre-line; color: #b91c1c; padding: .75rem; border: 1px solid #fecaca; border-radius: .4rem; margin-bottom: 1rem; }
.signature-submit-errors[hidden] { display: none; }
.sig-diagnostics { font-size: .8rem; margin: .75rem 0; }
.sig-diagnostics p { margin-bottom: .25rem; }

.sig-x .sig-pad-tool { min-height: 40px; }

/* Identical viewport layout for receipt, extension and edit forms. The driver
   mapping is configured separately; this mode does not move the OS cursor. */
.sig-x .sig-pad-wrapper { max-width: 640px; margin-inline: auto; }
.sig-x .sig-station-done { display: none; }
.sig-x .sig-station {
  position: fixed;
  inset: 0;
  z-index: 10002;
  margin: 0;
  padding: 16px;
  box-sizing: border-box;
  background: #f8fafc;
  display: grid;
  grid-template-rows: 48px minmax(0, 1fr) 80px 48px;
  justify-items: center;
  align-items: center;
  gap: 8px;
  overflow: auto;
}
.sig-x .sig-station .sig-pad-wrapper {
  flex: 0 0 auto;
  box-sizing: content-box;
  width: min(960px, calc(100vw - 56px), calc((100dvh - 252px) * 4 / 3));
  max-width: none;
  padding: 8px;
  margin: 0;
}
.sig-x .sig-station .sig-field-heading,
.sig-x .sig-station .sig-pad-actions {
  flex: 0 0 auto;
  width: min(980px, 100%);
  margin: 0;
}
.sig-x .sig-station .sig-station-done { display: block; flex: 0 0 auto; min-height: 44px; }
.sig-x .sig-station .sig-diagnostics { display: none; }
.sig-x .sig-station .sig-pad-hint { max-width: 34rem; }
.sig-x .sig-station button { margin: 0; width: auto; line-height: 1.2; }
.sig-x .sig-station .sig-pad { margin: 0; padding: 0; border: 0; }
.sig-x .sig-current-img { max-width: 100%; max-height: 140px; object-fit: contain; }
@media (max-height: 420px) {
  .sig-x .sig-station { grid-template-rows: 48px minmax(180px, 1fr) 80px 48px; }
  .sig-x .sig-station .sig-pad-wrapper { width: min(280px, calc(100vw - 56px)); }
}
