:root { --app-font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial; }
html, body { height: 100%; margin: 0; font-family: var(--app-font-family); color: #111; }
body, button, input, select, textarea, label, code, .leaflet-container, .leaflet-control, .leaflet-tooltip { font-family: var(--app-font-family); }
.muted { color: #666; }
.small { font-size: 12px; line-height: 1.35; }

.layout { display:grid; grid-template-columns: 1fr 340px; height: 100%; }
.map { height: 100%; }
.side { border-left: 1px solid #eee; background: #fafafa; padding: 12px; overflow:auto; }

.card { background:#fff; border:1px solid #eee; border-radius: 16px; padding: 12px; box-shadow: 0 1px 8px rgba(0,0,0,0.04); margin-bottom: 12px; }
.card__title { font-weight: 700; margin-bottom: 8px; }

.kv { display:grid; grid-template-columns: 140px 1fr; gap: 6px 10px; font-size: 13px; }
.progress { height: 8px; background:#f0f0f0; border-radius: 999px; overflow:hidden; margin-top: 10px; }
.progress__bar { height: 100%; background:#2b6dff; }
.topProgress {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 1500;
  width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  background: rgba(250,250,250,0.98);
  border: 1px solid #ececec;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.18);
  backdrop-filter: saturate(140%) blur(3px);
  display: none;
  pointer-events: none;
}
.topProgress.hidden { display: none !important; }
.topProgress .progress { margin-top: 0; height: 8px; }
.topProgress .small {
  display: block;
  margin-top: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

.btn { border: 1px solid #e6e6e6; background:#fff; padding: 8px 10px; border-radius: 10px; cursor:pointer; font-weight: 600; }
.btn--ghost { background:#fff; }
.btn--primary { background:#2b6dff; color:#fff; border-color:#2b6dff; }
.btn:hover { filter: brightness(0.98); }
.fileBtn { display:inline-flex; align-items:center; gap: 8px; }
.fileBtn input { display:none; }
.sideActions { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.sideActions .btn { width: 100%; min-width: 0; max-width: none; justify-content: center; box-sizing: border-box; font-size: 16px; }
.sideActions__status { display: block; text-align: center; width: 100%; }

.modal.hidden { display:none; }
.modal { position: fixed; inset: 0; z-index: 2000; display:flex; align-items: center; justify-content: center; }
.modal__backdrop { position:absolute; inset:0; background: rgba(0,0,0,0.35); }
.modal__panel {
  position: relative;
  margin: 24px;
  width: min(600px, calc(100vw - 48px));
  height: auto;
  max-height: min(860px, calc(100vh - 48px));
  max-height: min(860px, calc(100dvh - 48px));
  background:#fff; border-radius: 18px; overflow:hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  display:flex; flex-direction: column;
}
.modal__header { padding: 12px 14px; border-bottom: 1px solid #eee; display:flex; align-items:center; justify-content: space-between; gap: 12px; }
.modal__title { font-weight: 900; font-size: 18px; }
.modal__controls {
  padding: 12px 14px; border-bottom: 1px solid #eee;
  display:flex; align-items:flex-end; gap: 12px; flex-wrap: wrap;
}
.modal__controls .toggleCheck {
  flex: 1 1 auto;
  min-width: 0;
}
.modal__controls .toggleCheck .btn {
  display: block;
  width: 100%;
  text-align: center;
}
.modal__controls .btn {
  font-size: 13px;
  line-height: 1.2;
}
.toggleCheck {
  display: inline-flex;
  align-items: center;
  position: relative;
}
.toggleCheck input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.toggleCheck .btn {
  display: inline-block;
  user-select: none;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease, box-shadow 120ms ease, filter 120ms ease;
}
.toggleCheck input:focus-visible + span {
  box-shadow: 0 0 0 3px rgba(43, 109, 255, 0.2);
}
.toggleCheck input:checked + span {
  background: #2b6dff;
  border-color: #2b6dff;
  color: #fff;
}
.field { display:flex; flex-direction: column; gap: 6px; }
.field__label { font-size: 12px; color:#666; font-weight: 700; }
.input { border:1px solid #ddd; border-radius: 10px; padding: 8px 10px; font-weight: 600; }
.massDownload__controls { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.massDownload__format .input { width: 100%; box-sizing: border-box; }
.massDownload__controls .btn { width: fit-content; }
#massDownloadBtn:disabled {
  background: #e5e7eb;
  border-color: #d1d5db;
  color: #6b7280;
  cursor: not-allowed;
  opacity: 1;
  filter: none;
}
.massDownload--needsSelection #massSelectionCount {
  color: #374151;
  font-weight: 600;
}
.sideLinks__list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }
.sideLinks__list a { color: #2b6dff; text-decoration: none; font-weight: 600; }
.sideLinks__list a:hover { text-decoration: underline; }
#massSelectionOverlay {
  position: absolute;
  inset: 0;
  display: none;
  z-index: 1200;
  cursor: crosshair;
  touch-action: none;
}
#massSelectionOverlay.active { display: block; }
.massSelectionOverlay__hint {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(17, 17, 17, 0.86);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 999px;
  pointer-events: none;
}
.massSelectionOverlay__rect {
  position: absolute;
  display: none;
  border: 2px solid #2b6dff;
  background: rgba(43, 109, 255, 0.14);
  box-sizing: border-box;
  pointer-events: none;
}
.modal__body { padding: 12px 14px; overflow: auto; display:block; flex: 1; min-height: 0; }
.signWrap { display:block; width: fit-content; max-width: 100%; margin: 0 auto; flex: 0 0 auto; min-height: 0; overflow: visible; padding: 0; }
#signCanvas { display:block; max-width: 100%; width: auto; height: auto; border: 1px solid #eee; border-radius: 12px; background:#fff; transform-origin: center center; will-change: transform; }

@media (max-width: 1250px) {
  .topProgress { display: block; }
  .topProgress.hidden { display: none !important; }
  .layout { grid-template-columns: 1fr; }
  .side { display: none; }
}

.modal__panel {
  margin: 12px;
  width: min(480px, calc(100vw - 24px));
  height: auto;
  max-height: min(860px, calc(100vh - 24px));
  max-height: min(860px, calc(100dvh - 24px));
}

@media (max-width: 500px) {
  .topProgress {
    left: 16px;
    right: 16px;
    width: auto;
    max-width: none;
    transform: translateY(-50%);
    padding: 10px 12px;
  }
  #copyBtn { display: none; }
}

@media (max-width: 400px) {
  .modal__controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: stretch;
    gap: 8px;
  }

  .modal__controls .toggleCheck {
    grid-column: 1 / -1;
    width: 100%;
  }

  .modal__controls .toggleCheck .btn {
    display: block;
    width: 100%;
    text-align: center;
  }

  #downloadSvgBtn,
  #downloadBtn {
    width: 100%;
  }
}

@media (min-width: 401px) {
  .modal__controls {
    flex-wrap: nowrap;
    align-items: stretch;
  }
}
