:root {
  color-scheme: light;
  --bg: #f5f5f5;
  --surface: #ffffff;
  --panel: #fbfbfb;
  --border: #d8d8d8;
  --text: #161616;
  --muted: #767676;
  --accent: #e6322c;
  --accent-soft: #fdebea;
  --blue: #2368d8;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input {
  font: inherit;
}

button,
.file-button {
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: stretch;
  gap: 6px;
  min-height: 74px;
  padding: 4px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.toolbar-cluster {
  display: flex;
  align-items: stretch;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.toolbar-cluster.history {
  border-color: transparent;
}

.toolbar-spacer {
  flex: 1;
}

.icon-tool {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  min-width: 64px;
  min-height: 58px;
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.1;
  white-space: nowrap;
}

.icon-tool:hover {
  background: #f3f4f6;
}

.icon-tool.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.icon-tool.primary {
  background: #202124;
  color: #ffffff;
}

.icon-tool.primary:hover {
  background: #000000;
}

.icon-tool.word-export {
  border: 1px solid #1f5fbf;
  background: #ffffff;
  color: #1f5fbf;
}

.icon-tool.word-export:hover {
  background: #edf4ff;
}

.icon-tool.muted {
  color: #5f6368;
}

.tool-icon {
  display: block;
  min-height: 22px;
  color: inherit;
  font-size: 22px;
  font-weight: 500;
  line-height: 1;
}

.file-button input {
  display: none;
}

.status-strip {
  position: sticky;
  top: 140px;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  min-height: 38px;
  border-bottom: 1px solid #eeeeee;
  background: #fafafa;
  color: var(--muted);
  font-size: 13px;
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.search-bar input {
  width: 220px;
  min-height: 30px;
  border: 0;
  outline: 0;
  padding: 4px 6px;
}

.search-bar button {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  color: var(--text);
  font-size: 20px;
  line-height: 1;
}

.search-bar button:hover {
  background: #f0f2f5;
}

#searchCount {
  min-width: 46px;
  color: var(--muted);
  text-align: center;
}

.app-shell {
  display: block;
  min-height: calc(100vh - 112px);
}

.workspace {
  position: relative;
  min-width: 0;
  padding: 34px 24px 80px;
  overflow: auto;
}

.inspector {
  position: sticky;
  top: 74px;
  z-index: 45;
  display: flex;
  align-items: stretch;
  gap: 8px;
  width: 100%;
  min-height: 66px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior: contain;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: #fafafa;
  pointer-events: auto;
}

.settings-card {
  display: flex;
  align-items: end;
  gap: 10px;
  width: auto;
  min-width: max-content;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: none;
  pointer-events: auto;
}

.settings-card[data-panel="text"] {
  transform: scale(0.88);
  transform-origin: left center;
  margin-right: -96px;
}

.settings-card[data-panel="watermark"] {
  transform: scale(0.88);
  transform-origin: left center;
  margin-right: -36px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
}

h2 {
  font-size: 14px;
  line-height: 1.35;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.settings-card > label {
  min-width: 130px;
}

.settings-card > h2 {
  align-self: center;
  min-width: max-content;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #ffffff;
  color: var(--text);
  padding: 7px 9px;
}

.settings-card input[type="number"] {
  width: 86px;
}

.settings-card input[type="color"] {
  width: 92px;
}

.format-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  min-width: 150px;
}

.format-row button {
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #ffffff;
  font-weight: 700;
}

.format-row button:nth-child(2) {
  font-style: italic;
}

.format-row button:nth-child(3) {
  text-decoration: underline;
}

.format-row button.active,
.format-row button[aria-pressed="true"] {
  border-color: var(--blue);
  background: rgba(35, 104, 216, 0.1);
  color: var(--blue);
}

input[type="color"] {
  width: 100%;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #ffffff;
  padding: 4px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.redact-options {
  display: none;
  align-items: end;
  gap: 10px;
  padding-left: 10px;
  border-left: 1px solid var(--border);
}

.highlight-options {
  display: none;
  align-items: end;
  gap: 10px;
  padding-left: 10px;
  border-left: 1px solid var(--border);
}

body.tool-highlight .highlight-options {
  display: flex;
}

.inline-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.inline-actions button,
#applyWatermark {
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #ffffff;
}

.signature-popup {
  position: fixed;
  top: 148px;
  left: 32px;
  z-index: 80;
  display: grid;
  gap: 12px;
  width: 292px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.signature-popup[hidden] {
  display: none;
}

.popup-handle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: move;
  user-select: none;
}

.popup-handle button {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

.popup-handle button:hover {
  background: #f1f3f5;
  color: var(--text);
}

#signaturePad {
  width: 100%;
  height: 120px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background:
    linear-gradient(45deg, #edf1f5 25%, transparent 25%),
    linear-gradient(-45deg, #edf1f5 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #edf1f5 75%),
    linear-gradient(-45deg, transparent 75%, #edf1f5 75%);
  background-color: #ffffff;
  background-position:
    0 0,
    0 8px,
    8px -8px,
    -8px 0;
  background-size: 16px 16px;
  touch-action: none;
}

.upload-signature {
  display: grid;
  place-items: center;
  min-height: 36px;
  border: 1px dashed var(--border);
  border-radius: 5px;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
}

.upload-signature:hover {
  background: #f7f8fa;
}

.upload-signature input {
  display: none;
}

.signature-preview {
  display: block;
  max-width: 100%;
  max-height: 120px;
  border: 1px solid var(--border);
  border-radius: 5px;
  object-fit: contain;
  background:
    linear-gradient(45deg, #edf1f5 25%, transparent 25%),
    linear-gradient(-45deg, #edf1f5 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #edf1f5 75%),
    linear-gradient(-45deg, transparent 75%, #edf1f5 75%);
  background-color: #ffffff;
  background-position:
    0 0,
    0 8px,
    8px -8px,
    -8px 0;
  background-size: 16px 16px;
}

.signature-preview[hidden] {
  display: none;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 220px);
  color: var(--muted);
  text-align: center;
}

.empty-state h1 {
  color: var(--text);
  margin-bottom: 8px;
}

.pages {
  display: grid;
  gap: 36px;
  justify-content: center;
}

.page-wrap {
  display: grid;
  gap: 38px;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  color: #8a8a8a;
  font-size: 17px;
  font-weight: 700;
}

.page-menu {
  letter-spacing: 3px;
}

.page-stage {
  position: relative;
  overflow: hidden;
  background: #ffffff;
  box-shadow: none;
}

.pdf-canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

.text-layer,
.annotation-layer {
  position: absolute;
  inset: 0;
}

.text-layer {
  z-index: 1;
  overflow: hidden;
  opacity: 1;
  line-height: 1;
  pointer-events: none;
}

body.tool-edit .text-layer {
  z-index: 4;
  pointer-events: auto;
}

.text-layer span {
  position: absolute;
  color: transparent;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
}

body.tool-edit .text-layer span:hover {
  background: rgba(86, 93, 255, 0.2);
  outline: 1px solid rgba(35, 104, 216, 0.45);
}

.text-layer span.replaced {
  pointer-events: none;
}

.text-layer span.search-match {
  background: rgba(255, 214, 10, 0.55);
  outline: 1px solid rgba(180, 135, 0, 0.65);
}

.text-layer span.search-current {
  background: rgba(35, 104, 216, 0.32);
  outline: 2px solid rgba(35, 104, 216, 0.8);
}

.annotation-layer {
  z-index: 2;
  cursor: default;
}

body.tool-text .annotation-layer,
body.tool-signature .annotation-layer,
body.tool-erase .annotation-layer,
body.tool-highlight .annotation-layer,
body.tool-redact .annotation-layer {
  cursor: crosshair;
}

.annotation {
  position: absolute;
  min-width: 24px;
  min-height: 20px;
  border: 1px solid transparent;
  user-select: none;
}

.annotation.selected {
  border-color: var(--blue);
  outline: 2px solid rgba(35, 104, 216, 0.18);
}

.annotation.text {
  padding: 0 2px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.15;
}

.annotation.text.cover,
.annotation.erase {
  background: #ffffff;
}

.annotation.erase {
  border-color: rgba(35, 104, 216, 0.2);
}

.annotation.highlight {
  mix-blend-mode: multiply;
}

.annotation.redact {
  background: #000000;
}

.resize-handle {
  position: absolute;
  display: none;
  width: 10px;
  height: 10px;
  border: 1px solid var(--blue);
  background: #ffffff;
  z-index: 3;
  user-select: none;
}

.annotation.selected .resize-handle {
  display: block;
}

.resize-handle.nw {
  top: -6px;
  left: -6px;
  cursor: nwse-resize;
}

.resize-handle.n {
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  cursor: ns-resize;
}

.resize-handle.ne {
  top: -6px;
  right: -6px;
  cursor: nesw-resize;
}

.resize-handle.e {
  top: 50%;
  right: -6px;
  transform: translateY(-50%);
  cursor: ew-resize;
}

.resize-handle.se {
  right: -6px;
  bottom: -6px;
  cursor: nwse-resize;
}

.resize-handle.s {
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  cursor: ns-resize;
}

.resize-handle.sw {
  bottom: -6px;
  left: -6px;
  cursor: nesw-resize;
}

.resize-handle.w {
  top: 50%;
  left: -6px;
  transform: translateY(-50%);
  cursor: ew-resize;
}

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

.annotation.signature {
  background: transparent;
}

.annotation.watermark {
  display: grid;
  place-items: center;
  color: #344054;
  font-weight: 800;
  text-align: center;
  transform-origin: center;
  pointer-events: auto;
}

.editing {
  border-color: var(--blue);
  cursor: text;
  user-select: text;
}

@media (max-width: 1050px) {
  .topbar {
    overflow-x: auto;
  }

  .right-tools {
    display: none;
  }

  .app-shell {
    display: block;
  }

  .inspector {
    position: sticky;
    top: 74px;
    max-height: none;
    min-height: 66px;
    padding: 8px 12px;
  }
}

@media (max-width: 720px) {
  .history,
  .status-strip {
    top: 140px;
    justify-content: flex-start;
    padding: 0 12px;
    overflow: hidden;
  }

  .app-shell {
    display: block;
  }

  .workspace {
    padding: 24px 12px 120px;
  }

  .icon-tool {
    min-width: 56px;
  }
}
