:root {
  --bg: #ffb71b;
  --panel: rgba(255, 255, 255, 0.38);
  --panel2: rgba(255, 255, 255, 0.26);
  --border: rgba(0, 0, 0, 0.1);
  --text: rgba(25, 18, 5, 0.92);
  --muted: rgba(25, 18, 5, 0.68);
  --muted2: rgba(25, 18, 5, 0.52);
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.22);
  --accent: #111111;
  --accent2: #2b2b2b;
  --danger: #b00020;
  --ok: #0e7a43;
  --radius: 14px;
  --radius2: 18px;
  --mono:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  --sans:
    ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial,
    "Apple Color Emoji", "Segoe UI Emoji";

  /* Link type colors */
  --col-url: #185fa5;
  --col-url-bg: rgba(24, 95, 165, 0.13);
  --col-url-border: rgba(24, 95, 165, 0.6);
  --col-email: #0e7a43;
  --col-email-bg: rgba(14, 122, 67, 0.13);
  --col-email-border: rgba(14, 122, 67, 0.6);
  --col-phone: #7c3aed;
  --col-phone-bg: rgba(124, 58, 237, 0.13);
  --col-phone-border: rgba(124, 58, 237, 0.6);
}

* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background: var(--bg);
}

.protocol-warn {
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.78);
  color: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  font-size: 13px;
}
.mono {
  font-family: var(--mono);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  backdrop-filter: blur(8px);
  background: rgba(255, 255, 255, 0.28);
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.brand-mark img {
  width: 70%;
  height: 70%;
  object-fit: contain;
}
.brand-title {
  font-weight: 760;
  letter-spacing: -0.02em;
  font-size: 16px;
}
.brand-subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.file-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.14);
  background: rgba(255, 255, 255, 0.35);
  cursor: pointer;
  user-select: none;
}
.file-pill input {
  display: none;
}
.file-pill span {
  font-size: 13px;
  color: var(--text);
}

.btn {
  border: 1px solid #000;
  background: #000;
  color: #fff;
  padding: 9px 12px;
  border-radius: 12px;
  font-weight: 650;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 9px 12px;
  border-radius: 12px;
  font-weight: 650;
  font-size: 13px;
  cursor: pointer;
  transition:
    transform 90ms ease,
    background 140ms ease,
    border-color 140ms ease;
}
.btn:hover {
  transform: translateY(-1px);
  background: #000;
  color: #ffb71b;
}
.btn:active {
  transform: translateY(0px);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}
.btn-primary {
  border-color: #000;
  background: #000;
  color: #fff;
}
.btn-ghost {
  background: #000;
  color: #fff;
}
.btn-danger {
  border-color: rgba(176, 0, 32, 0.4);
  background: rgba(176, 0, 32, 0.1);
  color: var(--danger);
}
.btn-danger:hover {
  background: rgba(176, 0, 32, 0.18);
}

/* Draw mode button active state */
.draw-btn.active {
  background: rgba(0, 0, 0, 0.82) !important;
  color: rgba(255, 255, 255, 0.94) !important;
  border-color: rgba(0, 0, 0, 0.6) !important;
  transform: none !important;
}

.app {
  max-width: 1250px;
  margin: 0 auto;
  padding: 18px 22px 26px;
  display: grid;
  grid-template-columns: 1.25fr 0.75fr;
  gap: 18px;
}
@media (max-width: 980px) {
  .app {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: rgba(255, 255, 255, 0.3);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: var(--radius2);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-header {
  padding: 14px 14px 10px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}
.panel-title {
  font-weight: 750;
  font-size: 14px;
  letter-spacing: -0.01em;
}
.panel-hint {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.viewer-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.22);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  flex-wrap: wrap;
}
.page-indicator {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  padding: 0 4px;
}
.spacer {
  flex: 1;
}
.zoom {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}
.zoom input {
  width: 100px;
}

.viewer-wrap {
  position: relative;
  min-height: 560px;
  padding: 14px;
}
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  height: 100%;
  min-height: 520px;
  border-radius: var(--radius);
  border: 1px dashed rgba(0, 0, 0, 0.18);
  background: rgba(255, 255, 255, 0.22);

  text-align: center;
}
.empty-title {
  font-weight: 750;
}
.empty-subtitle {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  max-width: 420px;
}

.page-host {
  position: relative;
  border-radius: var(--radius);
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: white;
  overflow: hidden;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.22);
  user-select: text;
}
#pdfCanvas {
  display: block;
  width: 100%;
  height: auto;
}

.textLayer {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
  z-index: 5;
  opacity: 1;
  line-height: 1;
}
.textLayer span {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
}
.textLayer ::selection {
  background: rgba(0, 0, 0, 0.18);
}

.linkLayer {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
}

/* Base overlay */
.linkOverlay {
  position: absolute;
  border-radius: 5px;
  pointer-events: auto;
  cursor: pointer;
  transition: background 120ms ease;
}
/* URL overlay */
.linkOverlay--url {
  border: 2px solid var(--col-url-border);
  background: var(--col-url-bg);
}
.linkOverlay--url:hover {
  background: rgba(24, 95, 165, 0.22);
}
/* Email overlay */
.linkOverlay--email {
  border: 2px solid var(--col-email-border);
  background: var(--col-email-bg);
}
.linkOverlay--email:hover {
  background: rgba(14, 122, 67, 0.22);
}
/* Phone overlay */
.linkOverlay--phone {
  border: 2px solid var(--col-phone-border);
  background: var(--col-phone-bg);
}
.linkOverlay--phone:hover {
  background: rgba(124, 58, 237, 0.22);
}

/* Edit hint tooltip on hover */
.linkOverlay::after {
  content: attr(title);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  font-size: 11px;
  font-family: var(--mono);
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  opacity: 0;
  transition: opacity 160ms ease;
  z-index: 100;
}
.linkOverlay:hover::after {
  opacity: 1;
}

/* Rubber-band draw rect */
.rubber-band {
  position: absolute;
  z-index: 20;
  border: 2px dashed rgba(17, 17, 17, 0.75);
  background: rgba(17, 17, 17, 0.06);
  border-radius: 4px;
  pointer-events: none;
}

.selection-toolbar {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: min(420px, calc(100% - 32px));
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 16px;
  padding: 12px 12px 10px;
  box-shadow: 0 22px 55px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(10px);
  z-index: 10;
}
.selection-title {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
.selection-text {
  font-family: var(--mono);
  font-size: 12px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 12px;
  padding: 8px 10px;
  max-height: 72px;
  overflow: auto;
}
.selection-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.selection-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

/* ── Link Properties Popup ───────────────────────────────────────────────── */
.popup-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(3px);
}
.link-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.97);
  z-index: 110;
  width: min(400px, calc(100vw - 32px));
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid rgba(0, 0, 0, 0.14);
  border-radius: 20px;
  box-shadow:
    0 32px 72px rgba(0, 0, 0, 0.28),
    0 4px 12px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  transition:
    transform 180ms cubic-bezier(0.34, 1.56, 0.64, 1),
    opacity 160ms ease;
}
.link-popup.popup-in {
  transform: translate(-50%, -50%) scale(1);
}

.link-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}
.link-popup-title {
  font-size: 15px;
  font-weight: 750;
  letter-spacing: -0.01em;
}
.popup-close-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  border-radius: 999px;
}

.link-popup-body {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.popup-radio-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  user-select: none;
  transition: background 120ms ease;
}
.popup-radio-row:hover {
  background: rgba(0, 0, 0, 0.04);
}
.popup-radio-row input[type="radio"] {
  width: 16px;
  height: 16px;
  accent-color: #111;
  cursor: pointer;
  flex-shrink: 0;
}
.popup-radio-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
}

.popup-radio-icon {
  font-size: 16px;
  line-height: 1;
}
.popup-radio-icon--url {
  filter: none;
}
.popup-radio-icon--email {
}
.popup-radio-icon--phone {
}

.popup-field {
  padding: 2px 12px 10px 38px;
}
.popup-input {
  width: 100%;
  padding: 9px 12px;
  font-size: 13px;
  font-family: var(--mono);
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.14);
  border-radius: 10px;
  outline: none;
  color: var(--text);
  transition:
    border-color 140ms ease,
    background 140ms ease;
}
.popup-input:focus {
  border-color: rgba(0, 0, 0, 0.35);
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.07);
}
.popup-input::placeholder {
  color: var(--muted);
}

.link-popup-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 16px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  gap: 10px;
}
.popup-footer-right {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

/* ── Right panel ─────────────────────────────────────────────────────────── */
.right-actions {
  display: flex;
  gap: 10px;
  padding: 12px 12px 0;
}

.items {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.item {
  border-radius: var(--radius);
  border: 1px solid rgba(0, 0, 0, 0.1);
  background: rgba(255, 255, 255, 0.26);
  padding: 12px;
}
.item-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.chip {
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid;
  display: inline-block;
  margin-bottom: 5px;
}
.chip--url {
  color: var(--col-url);
  background: var(--col-url-bg);
  border-color: var(--col-url-border);
}
.chip--email {
  color: var(--col-email);
  background: var(--col-email-bg);
  border-color: var(--col-email-border);
}
.chip--phone {
  color: var(--col-phone);
  background: var(--col-phone-bg);
  border-color: var(--col-phone-border);
}

.item-title {
  font-weight: 750;
  font-size: 13px;
}
.item-sub {
  margin-top: 4px;
  font-family: var(--mono);
  font-size: 12px;
  color: rgba(25, 18, 5, 0.78);
  overflow-wrap: anywhere;
}
.item-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.muted {
  color: var(--muted);
}

.app-footer {
  max-width: 1250px;
  margin: 0 auto;
  padding: 0 22px 24px;
  color: var(--muted2);
  font-size: 12px;
}

#downloadPdfBtn {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px;
  font-weight: 600;
  border-radius: 12px;
}

.right-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

@media (max-width: 768px) {
  body {
    overflow-x: hidden;
  }

  .app-header {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    padding: 16px;
  }

  .brand {
    width: 100%;
  }

  .header-actions {
    width: 100%;
    display: flex;
    gap: 10px;
  }

  .file-pill,
  .header-actions .btn {
    flex: 1;
    justify-content: center;
  }

  .app {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 12px;
  }

  .left,
  .right {
    width: 100%;
    max-width: 100%;
  }

  .viewer-toolbar {
    flex-wrap: wrap;
    gap: 10px;
  }

  .viewer-toolbar .spacer {
    display: none;
  }

  .zoom {
    width: 100%;
    display: flex;
    justify-content: space-between;
  }

  .zoom input {
    flex: 1;
    min-width: 120px;
  }

  .viewer-wrap {
    overflow-x: auto;
  }

  .page-host {
    max-width: 100%;
    overflow: hidden;
  }

  #pdfCanvas {
    max-width: 100%;
    height: auto !important;
  }

  .right-actions {
    width: 100%;
  }

  #downloadPdfBtn {
    width: 100%;
  }
  .empty .center-upload {
    width: auto !important;
    min-width: 150px;
    max-width: 220px;
    height: auto !important;
    padding: 12px 22px;
    border-radius: 999px;
    flex: 0 0 auto !important;
  }
}
.center-upload {
  margin-top: 18px;
  justify-content: center;
  flex: 0 0 auto;
}

.powered-footer {
  display: flex;
  align-items: right;
  justify-content: right;
  gap: 10px;
  margin-top: 20px;
}

.powered-footer span {
  font-size: 14px;
  color: rgba(0,0,0,0.7);
  font-weight: 500;
}

.powered-footer img {
  height: 36px;
  object-fit: contain;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-box {
  background: #ffcf71;
  border-radius: 18px;
  padding: 28px 34px;
  text-align: center;
  box-shadow: 0 18px 40px rgba(0,0,0,0.25);
}

.loader {
  width: 42px;
  height: 42px;
  margin: 0 auto 14px;
  border: 4px solid rgba(0,0,0,0.15);
  border-top-color: #000;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-title {
  font-weight: 700;
  font-size: 16px;
}

.loading-text {
  margin-top: 4px;
  font-size: 13px;
  opacity: 0.7;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.loading-overlay[hidden] {
  display: none !important;
}

.viewer-wrap {
  overflow-x: hidden;
}

.page-host {
  max-width: 100%;
  margin: 0 auto;
}

#pdfCanvas {
  max-width: 100%;
}