:root {
  --primary: #2c3ab2;
  --primary-dark: #202b8f;
  --accent: #37d4e2;
  --mint: #00edc9;
  --ink: #1e1e1e;
  --muted: #6d7280;
  --line: #e7e9f1;
  --surface: #ffffff;
  --background: #f6f7fb;
  --danger: #c53030;
  --shadow: 0 18px 50px rgba(33, 43, 103, 0.09);
}

* { box-sizing: border-box; }

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

body.no-scroll { overflow: hidden; }

button, input, select { font: inherit; }
button, label[for] { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(980px, calc(100% - 32px));
  margin: 0 auto;
  padding: 40px 0 70px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }

h1 {
  margin-bottom: 8px;
  font-size: clamp(2rem, 5vw, 3.3rem);
  line-height: 1.02;
  letter-spacing: -.045em;
}

h2 { margin-bottom: 6px; font-size: 1.35rem; }

.subtitle {
  max-width: 650px;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.6;
}

.status-pill {
  flex: 0 0 auto;
  padding: 9px 13px;
  border: 1px solid #dfe3ff;
  border-radius: 999px;
  background: #eef0ff;
  color: var(--primary);
  font-size: .85rem;
  font-weight: 700;
}

.scanner-card, .pages-section, .desktop-handoff {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.scanner-card { padding: 18px; }

.dropzone {
  min-height: 360px;
  display: grid;
  place-items: center;
  align-content: center;
  padding: 40px 24px;
  border: 2px dashed #cfd4ee;
  border-radius: 18px;
  text-align: center;
  background:
    radial-gradient(circle at top left, rgba(55, 212, 226, .13), transparent 35%),
    linear-gradient(180deg, #fcfdff, #f8f9ff);
}

.dropzone p {
  max-width: 480px;
  margin-bottom: 24px;
  color: var(--muted);
}

.camera-icon {
  display: grid;
  width: 72px;
  height: 72px;
  margin-bottom: 18px;
  place-items: center;
  border-radius: 22px;
  background: #eef0ff;
  font-size: 2rem;
}

.primary-button, .secondary-button, .small-button, .icon-button {
  display: inline-flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
}

.primary-button { padding: 0 20px; background: var(--primary); color: #fff; }
.primary-button:hover { background: var(--primary-dark); }

.secondary-button {
  margin-top: 10px;
  padding: 0 20px;
  border-color: #d9dcef;
  background: #fff;
  color: var(--primary);
}

.small-button {
  min-height: 40px;
  padding: 0 14px;
  background: #eef0ff;
  color: var(--primary);
}

.icon-button {
  width: 42px;
  min-height: 42px;
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.pages-section { margin-top: 24px; padding: 24px; }

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 18px;
}

.pages-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.page-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}

.page-preview-wrap {
  position: relative;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  background: #eef0f7;
}

.page-preview {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: transform .2s ease;
}

.page-number {
  position: absolute;
  top: 10px;
  left: 10px;
  display: grid;
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  place-items: center;
  border-radius: 999px;
  background: rgba(30, 30, 30, .82);
  color: #fff;
  font-size: .78rem;
  font-weight: 800;
}

.page-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 12px;
}

.page-actions button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: .82rem;
  font-weight: 700;
}

.page-actions .danger-link { color: var(--danger); }

.document-fields {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-top: 24px;
}

.document-fields label, .editor-controls label {
  display: grid;
  gap: 8px;
  color: #484c59;
  font-size: .87rem;
  font-weight: 700;
}

.document-fields input, .document-fields select, .editor-controls select {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid #dfe2ec;
  border-radius: 11px;
  background: #fff;
  color: var(--ink);
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 22px;
}

.actions .secondary-button { margin-top: 0; }
.danger { border-color: #f0c8c8; color: var(--danger); }

.tip-card {
  margin-top: 18px;
  padding: 16px 18px;
  border: 1px solid #dfe8de;
  border-radius: 14px;
  background: #f4fbf5;
  color: #445344;
  line-height: 1.55;
}

.desktop-handoff {
  display: grid;
  grid-template-columns: 1.4fr auto;
  gap: 32px;
  align-items: center;
  margin-bottom: 24px;
  padding: 28px;
  background:
    radial-gradient(circle at top left, rgba(55, 212, 226, .14), transparent 38%),
    #fff;
}

.handoff-copy p:not(.eyebrow):not(.copy-feedback) {
  max-width: 560px;
  color: var(--muted);
  line-height: 1.6;
}

.handoff-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.handoff-actions .secondary-button { margin-top: 0; }

.qr-panel {
  width: 230px;
  padding: 18px;
  border: 1px solid #e1e4f0;
  border-radius: 18px;
  background: #fff;
  text-align: center;
}

.qr-code {
  display: grid;
  min-height: 190px;
  place-items: center;
}

.qr-code img, .qr-code canvas { max-width: 100%; height: auto !important; }

.current-url {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: .76rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.copy-feedback {
  min-height: 22px;
  margin: 10px 0 0;
  color: var(--primary);
  font-size: .86rem;
  font-weight: 700;
}

.editor-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(12, 16, 34, .78);
  backdrop-filter: blur(8px);
}

.editor-modal {
  width: min(1100px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 22px;
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(0,0,0,.3);
}

.editor-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.editor-header p:last-child { margin-bottom: 0; color: var(--muted); }

.canvas-shell {
  display: grid;
  min-height: 420px;
  place-items: center;
  overflow: hidden;
  border-radius: 16px;
  background: #111827;
}

#editorCanvas {
  display: block;
  max-width: 100%;
  max-height: 68vh;
  touch-action: none;
}

.editor-controls {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: end;
  margin-top: 16px;
}

.editor-controls .secondary-button { margin-top: 0; }

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0,0,0,0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}


[hidden] {
  display: none !important;
}

@media (max-width: 760px) {
  .app-shell { width: min(100% - 20px, 980px); padding-top: 22px; }
  .topbar { display: block; }
  .status-pill { display: inline-flex; margin-top: 14px; }
  .desktop-handoff { display: none !important; }
  .dropzone { min-height: 320px; padding-inline: 16px; }
  .section-heading { align-items: flex-start; }
  .document-fields { grid-template-columns: 1fr; }
  .actions { display: grid; grid-template-columns: 1fr; }
  .actions .primary-button, .actions .secondary-button { width: 100%; }
  .editor-overlay { padding: 0; }
  .editor-modal { min-height: 100vh; max-height: 100vh; border-radius: 0; padding: 14px; }
  .canvas-shell { min-height: 55vh; }
  .editor-controls { grid-template-columns: 1fr; }
  .editor-controls .primary-button, .editor-controls .secondary-button { width: 100%; }
}


/* Device-specific views */
body.desktop-mode #mobileScannerApp {
  display: none !important;
}

body.mobile-mode #desktopHandoff {
  display: none !important;
}

body.desktop-mode .app-shell {
  min-height: 100vh;
  display: grid;
  align-content: center;
}

body.desktop-mode .topbar {
  margin-bottom: 20px;
}

body.desktop-mode .desktop-handoff {
  margin-bottom: 0;
}

@media (max-width: 760px) {
  body.mobile-mode .topbar {
    margin-bottom: 18px;
  }
}


/* Editor móvil v2: la página desplaza; solo los tiradores capturan el gesto */
.editor-overlay {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  align-items: start;
}

.editor-modal {
  margin: auto;
}

.document-stage-wrap {
  position: relative;
}

.document-stage {
  position: relative;
  width: min(100%, 920px);
  margin: 0 auto;
  line-height: 0;
  user-select: none;
  -webkit-user-select: none;
}

.editor-image {
  display: block;
  width: 100%;
  height: auto;
  max-height: none;
  border-radius: 14px;
  background: #111827;
  pointer-events: none;
}

.crop-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.outside-shade {
  fill: rgba(0, 0, 0, .48);
}

.crop-polygon {
  fill: rgba(0, 237, 201, .08);
  stroke: #00edc9;
  stroke-width: 4;
  vector-effect: non-scaling-stroke;
}

.corner-handle {
  position: absolute;
  z-index: 8;
  width: 48px;
  height: 48px;
  min-height: 48px;
  margin: 0;
  padding: 0;
  transform: translate(-50%, -50%);
  border: 4px solid #2c3ab2;
  border-radius: 50%;
  background: #ffffff;
  color: #2c3ab2;
  box-shadow: 0 5px 18px rgba(0,0,0,.26);
  font-size: .82rem;
  font-weight: 900;
  line-height: 1;
  touch-action: none;
  cursor: grab;
}

.corner-handle:active {
  cursor: grabbing;
  transform: translate(-50%, -50%) scale(1.08);
}

.corner-magnifier {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  z-index: 1100;
  width: 150px;
  overflow: hidden;
  border: 3px solid #ffffff;
  border-radius: 18px;
  background: #ffffff;
  box-shadow: 0 14px 36px rgba(0, 0, 0, .32);
  pointer-events: none;
}

#magnifierCanvas {
  display: block;
  width: 100%;
  height: auto;
  background: #111827;
}

.magnifier-label {
  display: block;
  padding: 7px 9px;
  color: var(--primary);
  font-size: .72rem;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
}

.editor-help {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.45;
}

.editor-controls {
  position: sticky;
  bottom: 0;
  z-index: 20;
  margin: 16px -22px -22px;
  padding: 14px 22px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,.97);
  backdrop-filter: blur(12px);
}

@media (max-width: 760px) {
  .editor-overlay {
    display: block;
    padding: 0;
  }

  .editor-modal {
    width: 100%;
    min-height: 100%;
    max-height: none;
    overflow: visible;
    padding: 14px;
    border-radius: 0;
  }

  .editor-header {
    position: sticky;
    top: 0;
    z-index: 25;
    margin: -14px -14px 14px;
    padding: calc(12px + env(safe-area-inset-top)) 14px 12px;
    border-bottom: 1px solid var(--line);
    background: rgba(255,255,255,.97);
    backdrop-filter: blur(12px);
  }

  .document-stage {
    width: 100%;
  }

  .corner-handle {
    width: 54px;
    height: 54px;
    min-height: 54px;
  }

  .corner-magnifier {
    top: calc(82px + env(safe-area-inset-top));
    right: 12px;
    width: 138px;
  }

  .editor-controls {
    grid-template-columns: 1fr;
    margin: 16px -14px -14px;
    padding-inline: 14px;
  }

  .editor-controls .primary-button,
  .editor-controls .secondary-button {
    width: 100%;
  }
}
