:root {
  color-scheme: light;
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --line: #d9dee8;
  --line-strong: #b9c4d6;
  --text: #1e2633;
  --muted: #6d7685;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --green: #1f9d55;
  --green-soft: #dcfce7;
  --red: #d92d20;
  --red-soft: #fee4e2;
  --shadow: 0 18px 54px rgba(30, 38, 51, .14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  overscroll-behavior: none;
}

body.touch-gesture-lock {
  touch-action: none;
  overscroll-behavior: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
label.primary-file {
  user-select: none;
}

[hidden] {
  display: none !important;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(420px, 1fr) 360px;
  grid-template-rows: 64px minmax(0, 1fr);
  height: 100vh;
}

.topbar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 250px minmax(320px, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(14px);
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 850;
  font-size: 21px;
  color: #182235;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #174ea6;
  color: #fff;
  font-size: 10px;
  letter-spacing: .04em;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.center-tools {
  justify-content: center;
}

.right-tools {
  justify-content: flex-end;
}

.tool-button,
.save-button,
.icon-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 13px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  font-size: 14px;
  font-weight: 760;
  white-space: nowrap;
}

.tool-button:hover,
.icon-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
}

.tool-button.active,
.segment.active {
  color: var(--blue);
  border-color: var(--blue);
  background: var(--blue-soft);
}

.tool-button:disabled,
.save-button:disabled,
.icon-button:disabled,
.danger-button:disabled {
  cursor: not-allowed;
  opacity: .48;
}

a.tool-button {
  text-decoration: none;
}

.save-button {
  border-color: transparent;
  color: #fff;
  background: var(--green);
}

.save-button:hover {
  background: #168348;
}

.danger-button {
  color: var(--red);
  border-color: #f6b9b4;
  background: #fff;
}

.danger-button:hover {
  background: var(--red-soft);
}

.primary-file {
  position: relative;
}

.primary-file input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.icon {
  display: grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  border-radius: 5px;
  color: var(--blue);
  background: var(--blue-soft);
  font-size: 10px;
  font-weight: 900;
}

.save-button .icon {
  color: #14713e;
  background: #e6f8ee;
}

.icon-button {
  width: 38px;
  padding: 0;
  font-size: 18px;
}

output {
  min-width: 68px;
  text-align: center;
  color: var(--text);
  font-weight: 780;
  font-size: 14px;
}

.divider {
  width: 1px;
  height: 28px;
  background: var(--line);
}

.sidebar {
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow: auto;
}

.inspector {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.doc-panel,
.pages-panel,
.selected-panel {
  padding: 20px;
}

.doc-panel {
  border-bottom: 1px solid var(--line);
}

h1,
h2,
p {
  margin: 0;
}

h2 {
  margin-bottom: 12px;
  color: #2a3342;
  font-size: 12px;
  font-weight: 850;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.doc-panel strong {
  display: block;
  margin-bottom: 6px;
  overflow-wrap: anywhere;
  font-size: 16px;
}

.doc-panel p,
.empty-state p,
.no-selection {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.status-list {
  display: grid;
  gap: 9px;
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.status-item {
  position: relative;
  padding-left: 26px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 680;
}

.status-item:before {
  content: "";
  position: absolute;
  left: 0;
  top: 2px;
  width: 15px;
  height: 15px;
  border-radius: 999px;
  border: 2px solid currentColor;
}

.status-item.done {
  color: var(--green);
}

.status-item.busy {
  color: var(--blue);
}

.status-item.error {
  color: var(--red);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-heading h2 {
  margin-bottom: 0;
}

#page-count {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.thumbs {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.thumb {
  display: grid;
  grid-template-columns: 26px 1fr;
  gap: 10px;
  align-items: center;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.thumb:hover {
  background: var(--surface-soft);
}

.thumb.active {
  border-color: var(--blue);
  background: var(--blue-soft);
}

.thumb span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.thumb canvas {
  width: 84px;
  max-height: 118px;
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: 0 3px 12px rgba(30, 38, 51, .12);
}

.workspace {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 36px;
  background: linear-gradient(180deg, #f4f6fa 0%, #e8edf5 100%);
}

.drop-zone {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  display: grid;
  place-items: start center;
  padding: 28px 34px;
}

.drop-zone.dragover:after {
  content: "Suelta el PDF";
  position: absolute;
  inset: 18px;
  display: grid;
  place-items: center;
  border: 2px dashed var(--blue);
  border-radius: 8px;
  color: var(--blue);
  background: rgba(219, 234, 254, .72);
  font-weight: 900;
  font-size: 24px;
  z-index: 10;
}

.empty-state {
  width: min(420px, calc(100vw - 48px));
  margin-top: 14vh;
  text-align: center;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 82px;
  height: 82px;
  margin: 0 auto 18px;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--blue);
  font-weight: 950;
}

.empty-state h1 {
  margin-bottom: 10px;
  font-size: 34px;
  letter-spacing: 0;
}

.page-stage {
  display: grid;
  justify-items: center;
  width: 100%;
}

.page-wrap {
  position: relative;
  background: #fff;
  box-shadow: var(--shadow);
  transform-origin: top center;
}

#pdf-canvas {
  display: block;
}

.text-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.text-layer.eraser-active {
  cursor: crosshair;
  touch-action: none;
  overscroll-behavior: contain;
  user-select: none;
  -webkit-user-select: none;
}

.page-stage.eraser-gesture-lock,
.page-wrap.eraser-gesture-lock {
  touch-action: none;
  overscroll-behavior: contain;
}

.text-layer.eraser-active.eraser-brush-active {
  cursor: none;
}

.text-layer.eraser-active .text-block,
.text-layer.eraser-active .stamp-block {
  pointer-events: none;
}

.erase-zone,
.erase-preview {
  position: absolute;
  z-index: 2;
  min-width: 4px;
  min-height: 4px;
  border: 1px solid rgba(37, 99, 235, .78);
  background: rgba(37, 99, 235, .10);
  pointer-events: none;
}

.erase-zone.brush {
  border-radius: 999px;
}

.erase-preview {
  border-style: dashed;
  background: rgba(31, 157, 85, .12);
}

.brush-cursor {
  position: absolute;
  z-index: 14;
  border: 2px solid rgba(37, 99, 235, .98);
  border-radius: 999px;
  background: rgba(37, 99, 235, .08);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, .95),
    0 0 0 1px rgba(9, 22, 48, .28),
    0 8px 20px rgba(30, 38, 51, .16);
  pointer-events: none;
}

.brush-cursor::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: rgba(37, 99, 235, .95);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .95);
  transform: translate(-50%, -50%);
}

.brush-cursor.active {
  border-color: rgba(31, 157, 85, .98);
  background: rgba(31, 157, 85, .14);
}

.brush-cursor.active::after {
  background: rgba(31, 157, 85, .98);
}

.text-block {
  position: absolute;
  min-width: 10px;
  min-height: 10px;
  border: 1px solid transparent;
  outline: 0;
  color: #111;
  background: rgba(255, 255, 255, .02);
  line-height: 1.08;
  white-space: pre-wrap;
  overflow: hidden;
  resize: none;
  cursor: move;
  user-select: none;
}

.text-block:hover {
  border-color: rgba(37, 99, 235, .72);
  background: rgba(219, 234, 254, .16);
}

.text-block.selected {
  border-style: solid;
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, .18);
  z-index: 3;
}

.text-block.editing {
  cursor: text;
  user-select: text;
  background: rgba(255, 255, 255, .22);
}

.text-block.dirty {
  background: rgba(220, 252, 231, .24);
}

.text-block.ocr {
  border-color: transparent;
}

.text-block.ocr:hover,
.text-block.ocr.selected {
  border-color: rgba(31, 157, 85, .7);
}

.stamp-block {
  position: absolute;
  z-index: 4;
  min-width: 24px;
  min-height: 16px;
  border: 1px solid transparent;
  object-fit: contain;
  transform-origin: left top;
  cursor: move;
  user-select: none;
}

.stamp-block:hover,
.stamp-block.selected {
  border-color: rgba(37, 99, 235, .78);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, .14);
}

.block-controls {
  position: absolute;
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px;
  border: 1px solid rgba(37, 99, 235, .34);
  border-radius: 8px;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 10px 26px rgba(30, 38, 51, .20);
  user-select: none;
  pointer-events: auto;
}

.block-control-button {
  min-width: 52px;
  height: 28px;
  padding: 0 9px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: #fff;
  background: var(--blue);
  font-size: 12px;
  font-weight: 850;
  line-height: 1;
  letter-spacing: 0;
  box-shadow: none;
}

.block-control-button.edit {
  color: var(--text);
  background: #fff;
  border-color: rgba(37, 99, 235, .32);
}

.block-control-button.move {
  cursor: move;
}

.block-control-button.rotate {
  cursor: grab;
  color: var(--text);
  background: #eef4ff;
  border-color: rgba(37, 99, 235, .36);
}

.block-control-button.rotate:active {
  cursor: grabbing;
}

.block-control-button:focus-visible {
  outline: 2px solid rgba(37, 99, 235, .55);
  outline-offset: 2px;
}

.block-angle-readout {
  min-width: 44px;
  color: #536071;
  font-size: 11px;
  font-weight: 750;
  text-align: center;
}

.progress-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 7px 14px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, .84);
}

progress {
  width: 100%;
  height: 8px;
  accent-color: var(--blue);
}

#progress-label {
  min-width: 180px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  text-align: right;
}

.inspector-form {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

label {
  display: block;
  margin-bottom: 6px;
  color: #485366;
  font-size: 12px;
  font-weight: 800;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  color: var(--text);
  background: #fff;
  outline: 0;
  font-size: 14px;
}

textarea {
  min-height: 90px;
  resize: vertical;
  line-height: 1.35;
}

input[type="color"] {
  min-height: 40px;
  padding: 4px;
}

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

.style-toggle,
.fit-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  min-height: 36px;
  padding: 0 10px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.style-toggle {
  width: 38px;
  padding: 0;
  font-size: 15px;
  font-weight: 800;
}

.style-toggle.italic span {
  font-style: italic;
}

.fit-toggle {
  font-size: 12px;
  font-weight: 800;
  color: #485366;
}

.style-toggle input,
.fit-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.style-toggle:has(input:checked),
.fit-toggle:has(input:checked) {
  border-color: var(--blue);
  background: var(--blue-soft);
  color: var(--blue);
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .14);
}

.field-grid {
  display: grid;
  gap: 10px;
}

.field-grid.two {
  grid-template-columns: 1fr 110px;
}

.field-grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.ocr-readout {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
}

.ocr-readout strong {
  color: var(--text);
}

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.no-selection {
  margin-top: 18px;
  padding: 18px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--surface-soft);
}

.eraser-panel {
  display: grid;
  gap: 14px;
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.segment {
  height: 34px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 850;
}

.sample-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.sample-status {
  min-height: 20px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.sample-status.ready {
  color: var(--green);
}

.sample-status.armed {
  color: var(--blue);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(24, 34, 53, .48);
  z-index: 20;
}

.pro-dialog {
  width: min(1120px, calc(100vw - 44px));
  max-height: calc(100vh - 44px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.pro-header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .96);
  z-index: 2;
}

.pro-header h2 {
  margin-bottom: 4px;
}

.pro-header strong {
  font-size: 18px;
}

.pro-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
}

.pro-section {
  display: grid;
  gap: 12px;
  align-content: start;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.pro-section.wide {
  grid-column: 1 / -1;
}

.pro-section h3 {
  margin: 0;
  color: #2a3342;
  font-size: 13px;
  font-weight: 850;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.pro-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.pro-actions.single {
  grid-template-columns: 1fr;
}

.signature-pad {
  width: 100%;
  height: 150px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  cursor: crosshair;
  touch-action: none;
  overscroll-behavior: contain;
  user-select: none;
  -webkit-user-select: none;
}

.company-logo-preview {
  max-width: 148px;
  max-height: 72px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px;
  background: #fff;
  object-fit: contain;
}

.history-list {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
}

.account-panel {
  display: grid;
  gap: 5px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.account-panel strong,
.account-panel span {
  display: block;
}

.account-panel strong {
  color: var(--text);
  font-size: 15px;
}

.account-panel span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.server-documents {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
}

.server-document {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

.server-document strong,
.server-document span {
  display: block;
}

.server-document strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.server-document span {
  color: var(--muted);
  font-size: 12px;
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

.history-item strong {
  overflow-wrap: anywhere;
  font-size: 13px;
}

.history-item span {
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 1180px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 220px minmax(360px, 1fr);
    grid-template-rows: auto minmax(620px, 1fr) auto;
    min-height: 100vh;
    height: auto;
  }

  .topbar {
    grid-template-columns: 1fr;
  }

  .center-tools,
  .right-tools {
    justify-content: flex-start;
  }

  .inspector {
    grid-column: 1 / -1;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .pro-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .left-panel {
    max-height: 300px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .toolbar {
    flex-wrap: wrap;
  }

  .field-grid.two,
  .field-grid.four {
    grid-template-columns: 1fr 1fr;
  }

  .drop-zone {
    padding: 16px;
  }
}
