@import url("https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;700&family=IBM+Plex+Mono:wght@400;500&display=swap");

:root {
  --bg0: #f4f7f3;
  --bg1: #e8f0ea;
  --panel: #ffffff;
  --ink: #172220;
  --soft-ink: #48615a;
  --line: #c7d8d0;
  --accent: #0a7f63;
  --accent-2: #de7024;
  --danger: #9f2d2d;
  --selected: #d7f6ec;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 14%, #d7efe6 0%, rgba(215, 239, 230, 0) 38%),
    radial-gradient(circle at 86% 12%, #ffe2c9 0%, rgba(255, 226, 201, 0) 36%),
    linear-gradient(160deg, var(--bg0), var(--bg1));
}

.topbar {
  padding: 1.1rem 1.4rem;
  background: #0f1b1c;
  color: #eefaf6;
  border-bottom: 4px solid #21564b;
}

.topbar h1 {
  margin: 0;
  font-size: 1.52rem;
}

.topbar p {
  margin: 0.3rem 0 0;
  color: #b9ddd4;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 8px 22px rgba(19, 38, 33, 0.08);
  margin: 0.8rem 1rem;
}

.thumbs-card,
.progress-card,
.status-card {
  margin-left: 1rem;
  margin-right: 1rem;
}

.thumb-empty-state {
  position: absolute;
  inset: 6px;
  padding: 0.95rem 1rem;
  border: 2px dashed #8dbcae;
  border-radius: 12px;
  text-align: center;
  color: #2f4d46;
  display: grid;
  align-content: center;
  gap: 0.35rem;
  cursor: pointer;
  background: #f9fcfb;
}

.thumbnail-strip.file-drag-over .thumb-empty-state {
  border-color: var(--accent);
  background: #ecfbf4;
}

.thumb-empty-state strong {
  font-size: 1rem;
}

.thumb-empty-state span {
  color: var(--soft-ink);
  font-size: 0.9rem;
}

#browseBtn {
  justify-self: center;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 9px;
  padding: 0.55rem 0.85rem;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: transform 110ms ease, background 110ms ease;
}

button:hover:enabled {
  transform: translateY(-1px);
  background: #086850;
}

button:disabled {
  cursor: not-allowed;
  background: #9ab5ad;
}

.download-btn {
  background: var(--accent-2);
  margin-top: 1rem;
}

.download-btn:hover:enabled {
  background: #c85f18;
}

.thumbs-card {
  padding: 0.45rem 0.45rem 0.4rem;
}

.thumbnail-strip {
  position: relative;
  display: flex;
  gap: 0.55rem;
  overflow-x: auto;
  overflow-y: hidden;
  align-items: flex-start;
  padding: 0.25rem;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #f7fbf9;
  min-height: 168px;
}

.thumbnail-strip.empty {
  overflow-x: hidden;
}

.thumbnail-strip:not(.empty) .thumb-empty-state {
  display: none;
}

.thumbnail-strip.file-drag-over::after {
  content: "";
  position: absolute;
  inset: 5px;
  border: 2px dashed var(--accent);
  border-radius: 10px;
  background: rgba(9, 126, 98, 0.08);
  pointer-events: none;
}

.thumb-item {
  position: relative;
  min-width: 132px;
  width: 132px;
  border: 2px solid #d5e2dc;
  border-radius: 9px;
  background: #fff;
  padding: 0.25rem;
  cursor: pointer;
  user-select: none;
}

.thumb-item canvas {
  width: 100%;
  display: block;
  border-radius: 6px;
  background: #eef3f0;
}

.thumb-label {
  text-align: center;
  font-size: 0.78rem;
  color: #38514a;
  margin-top: 0.22rem;
}

.thumb-item.selected {
  border-color: #70c4a8;
  background: var(--selected);
}

.thumb-item.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.thumb-item.drag-source {
  opacity: 0.62;
}

.thumb-item.drop-before::before {
  content: "";
  position: absolute;
  left: -4px;
  top: 1px;
  bottom: 1px;
  width: 4px;
  border-radius: 999px;
  background: var(--accent-2);
}

.thumbnail-strip.drop-at-end {
  box-shadow: inset -4px 0 0 var(--accent-2);
}

.thumb-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  padding: 0;
  background: var(--danger);
}

.thumb-delete:hover:enabled {
  background: #7f1f1f;
}

.progress-card {
  padding: 0.42rem 0.6rem;
}

.progress-track {
  position: relative;
  height: 28px;
  border-radius: 999px;
  overflow: hidden;
  background: #dbe8e2;
  border: 1px solid #bfd2c9;
}

.progress-fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #0a7f63, #1bb38e);
  transition: width 180ms ease;
}

.progress-track.indeterminate .progress-fill {
  width: 36%;
  background: linear-gradient(90deg, #de7024, #f3b388);
  animation: indeterminate-slide 1100ms linear infinite;
}

.progress-text {
  position: relative;
  z-index: 2;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.86rem;
  color: #17312b;
}

@keyframes indeterminate-slide {
  0% {
    transform: translateX(-110%);
  }
  100% {
    transform: translateX(320%);
  }
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 0;
  align-items: stretch;
  margin-top: 0;
}

.viewer-card {
  margin: 0 0.5rem 0.8rem 1rem;
  padding: 0.72rem;
}

.viewer-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.58rem;
}

.viewer-zoom-tools {
  display: flex;
  align-items: center;
  gap: 0.34rem;
  justify-self: start;
}

.zoom-btn {
  width: 34px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid #b7cdc4;
  background: #e6f2ee;
  color: #1a4338;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-weight: 700;
}

.zoom-btn:hover:enabled {
  background: #d5ebe4;
  transform: none;
}

.viewer-title-wrap {
  justify-self: center;
  text-align: center;
}

.viewer-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

#viewerInfo,
#selectionInfo {
  color: var(--soft-ink);
  font-size: 0.88rem;
}

#viewerInfo {
  justify-self: end;
  white-space: nowrap;
}

.viewer-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f3f8f4;
  min-height: 620px;
  max-height: 72vh;
  overflow-x: auto;
  overflow-y: auto;
  scrollbar-gutter: stable both-edges;
  padding: 0.7rem;
}

.viewer-wrap.has-document {
  cursor: grab;
}

.viewer-wrap.panning {
  cursor: grabbing;
}

.canvas-host {
  position: relative;
  width: fit-content;
  margin: 0 auto;
}

#pageCanvas {
  display: block;
  border-radius: 8px;
  box-shadow: 0 7px 20px rgba(22, 41, 37, 0.12);
  background: #fff;
}

.overlay-layer {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: auto;
}

.overlay-item {
  position: absolute;
  border: 2px solid rgba(211, 105, 39, 0.9);
  border-radius: 6px;
  background: rgba(230, 173, 136, 0.16);
  cursor: move;
  overflow: hidden;
}

.overlay-item.active {
  border-color: #0f7f63;
  box-shadow: 0 0 0 1px #0f7f63;
}

.overlay-item.signature img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
}

.overlay-item.signature.certificate-backed::after {
  content: "CERT";
  position: absolute;
  left: 0;
  bottom: 0;
  padding: 0.12rem 0.35rem;
  border-radius: 0 6px 0 0;
  background: rgba(10, 127, 99, 0.92);
  color: #f7fff9;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  pointer-events: none;
}

.overlay-item.redaction {
  border-style: dashed;
  border-color: #1a1a1a;
  background:
    repeating-linear-gradient(
      -45deg,
      rgba(10, 10, 10, 0.92),
      rgba(10, 10, 10, 0.92) 7px,
      rgba(40, 40, 40, 0.9) 7px,
      rgba(40, 40, 40, 0.9) 14px
    );
}

.overlay-item.text .text-chip {
  width: 100%;
  height: 100%;
  padding: 0;
  display: flex;
  align-items: center;
  line-height: 1.2;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  pointer-events: none;
}

.overlay-remove {
  position: absolute;
  top: 0;
  right: 0;
  width: 20px;
  height: 20px;
  border-radius: 0 0 0 6px;
  background: #8d1f1f;
  padding: 0;
  font-size: 0.76rem;
  line-height: 1;
}

.overlay-remove:hover:enabled {
  background: #711616;
}

.overlay-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  border-left: 2px solid rgba(16, 70, 60, 0.8);
  border-top: 2px solid rgba(16, 70, 60, 0.8);
  background: rgba(204, 240, 228, 0.75);
  cursor: nwse-resize;
}

.viewer-foot {
  margin-top: 0.55rem;
}

.tools-card {
  margin: 0 1rem 0.8rem 0.5rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: calc(620px + 84px);
  max-height: calc(72vh + 84px);
  overflow: hidden;
}

.tools-head {
  padding: 0.75rem 0.8rem 0.45rem;
  border-bottom: 1px solid #d3e3dc;
  background: var(--panel);
}

.tools-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.tools-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.25rem 0.8rem 0.8rem;
}

.tools-scroll h3 {
  font-size: 0.95rem;
  margin-top: 0.9rem;
  margin-bottom: 0.5rem;
  color: #244039;
}

.tools-scroll label {
  display: block;
  font-size: 0.88rem;
  color: #314b44;
  margin: 0.3rem 0;
}

.tools-scroll input:not([type="checkbox"]),
.tools-scroll select {
  width: 100%;
  margin-top: 0.18rem;
  border: 1px solid #b7c8c0;
  border-radius: 8px;
  padding: 0.42rem 0.48rem;
}

.tool-note {
  margin: 0.2rem 0 0.4rem;
  font-size: 0.8rem;
  color: #4e6861;
}

.check-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.5rem;
  margin: 0.3rem 0 0.15rem;
}

.check-inline {
  display: flex !important;
  align-items: center;
  gap: 0.42rem;
  font-size: 0.8rem !important;
  margin: 0 !important;
  color: #35514a !important;
}

.check-inline input[type="checkbox"] {
  margin: 0;
  width: auto;
  accent-color: #0a7f63;
}

.tools-scroll input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  --range-progress: 0%;
  width: 100%;
  margin-top: 0.26rem;
  border: 0;
  padding: 0;
  background: transparent;
  height: 18px;
}

.tools-scroll input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    #0a7f63 0 var(--range-progress),
    #ffffff var(--range-progress) 100%
  );
  border: 1px solid #b8cfc6;
}

.tools-scroll input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -4.5px;
  border-radius: 999px;
  border: 1px solid #0f5f4b;
  background: #f6fffc;
}

.tools-scroll input[type="range"]::-moz-range-track {
  height: 5px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid #b8cfc6;
}

.tools-scroll input[type="range"]::-moz-range-progress {
  height: 5px;
  border-radius: 999px;
  background: #0a7f63;
}

.tools-scroll input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 1px solid #0f5f4b;
  background: #f6fffc;
}

.tools-scroll button {
  width: 100%;
  margin-top: 0.42rem;
}

.tools-foot {
  border-top: 1px solid #d3e3dc;
  background: var(--panel);
  padding: 0.6rem 0.8rem 0.8rem;
}

.tools-foot .download-btn {
  margin-top: 0;
}

.row.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

.compact-actions {
  margin-top: 0.42rem;
}

.compact-actions button {
  margin-top: 0;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(8, 21, 19, 0.68);
}

.modal-card {
  width: min(680px, 100%);
  max-height: min(88vh, 820px);
  overflow-y: auto;
  border-radius: 18px;
  border: 1px solid rgba(183, 200, 192, 0.9);
  background: #f8fbfa;
  box-shadow: 0 22px 60px rgba(11, 27, 23, 0.35);
  padding: 1.2rem 1.2rem 1rem;
}

.modal-card h3 {
  margin: 0;
  color: #244039;
}

.modal-note {
  margin-top: 0.45rem;
}

.signature-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  margin: 1rem 0 0.8rem;
}

.signature-tab {
  margin-top: 0;
  background: #edf5f2;
  color: #2f4d45;
  border: 1px solid #bfd1c9;
}

.signature-tab:hover:enabled {
  background: #e2efe9;
}

.signature-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.signature-panel + .signature-panel {
  margin-top: 0.5rem;
}

.signature-pad {
  width: 100%;
  margin-top: 0.3rem;
  border: 1px solid #b7c8c0;
  border-radius: 10px;
  background: #fff;
  cursor: crosshair;
  touch-action: none;
}

.secondary-btn {
  background: #e9f1ee;
  color: #27443d;
  border: 1px solid #b9cbc4;
}

.secondary-btn:hover:enabled {
  background: #dae9e3;
}

.modal-check {
  margin-top: 0.9rem !important;
}

.signature-cert-fields {
  margin-top: 0.8rem;
  padding-top: 0.8rem;
  border-top: 1px solid #d7e5df;
}

.signature-cert-status {
  margin-top: 0.55rem;
  border-radius: 10px;
  background: #e7f7ef;
  border: 1px solid #b9dfc9;
  color: #1f5f43;
  padding: 0.55rem 0.7rem;
  font-size: 0.82rem;
}

.modal-actions {
  display: flex;
  gap: 0.7rem;
  margin-top: 1rem;
}

.modal-actions button {
  margin-top: 0;
}

.modal-actions button:first-child {
  width: auto;
  min-width: 120px;
}

.status-card {
  padding: 0.55rem;
}

#output {
  margin: 0;
  min-height: 72px;
  max-height: 180px;
  overflow: auto;
  background: #0f1918;
  color: #d5e8e1;
  border-radius: 8px;
  padding: 0.6rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.82rem;
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .viewer-card,
  .tools-card {
    margin: 0 1rem 0.8rem;
  }

  .viewer-wrap {
    min-height: 420px;
  }

  .tools-card {
    min-height: 0;
    max-height: none;
  }

  .tools-scroll {
    max-height: 64vh;
  }

  .modal-card {
    padding: 1rem 0.9rem 0.9rem;
  }

  .modal-actions {
    flex-direction: column;
  }

  .modal-actions button:first-child {
    width: 100%;
  }

  .viewer-head {
    grid-template-columns: auto 1fr auto;
    gap: 0.45rem;
  }

  .viewer-zoom-tools {
    gap: 0.25rem;
  }

  .viewer-head h2 {
    font-size: 1rem;
  }

  #viewerInfo {
    width: auto;
    font-size: 0.82rem;
  }
}
