/* ══ ATTACH APP — Specific styles ══ */
/* Shared styles loaded from /shared/ */

/* Offset toolbar and tracker to center relative to document, not sidebar */
.toolbar-controls {
  margin-right: 320px;
}

.wf-steps {
  margin-right: 320px;
}

/* Contenitore interno: impila le pagine PDF verticalmente con spazio tra di loro */
.canvas-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin: 0 auto;
}

/* ══ PDF PAGE ══ */
.pdf-page-wrapper {
  position: relative;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  border-radius: 2px;
}

.pdf-page-wrapper canvas {
  display: block;
}

/* Text layer for selection (pdf.js TextLayer) */
.textLayer {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  line-height: 1;
  -webkit-text-size-adjust: none;
  -moz-text-size-adjust: none;
  text-size-adjust: none;
  z-index: 2;
}

.textLayer :is(span, br) {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
}

.textLayer span::selection {
  background: rgba(234, 67, 53, 0.3);
}

/* ══ SORT TOGGLE ══ */
.sort-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  margin: 8px 0 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--grey-500);
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.15s;
  user-select: none;
}

.sort-toggle:hover {
  background: var(--grey-100);
  color: var(--grey-700);
}

.sort-toggle.active {
  background: var(--accent-light);
  color: var(--accent);
}

/* ══ ATTACHMENT CARDS ══ */
.attachment-card {
  background: var(--grey-50);
  border: 1px solid var(--grey-200);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 8px;
  transition: all 0.15s;
}

.attachment-card:hover {
  border-color: var(--grey-300);
  box-shadow: var(--shadow-1);
}

.attachment-card.linked {
  border-color: var(--blue);
  background: var(--blue-light);
}

.attachment-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.att-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--accent);
}

.att-info {
  flex: 1;
  min-width: 0;
}

.att-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--grey-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: default;
}

.att-meta {
  font-size: 11px;
  color: var(--grey-500);
  margin-top: 1px;
}

.att-remove {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--grey-500);
  flex-shrink: 0;
}

.att-remove:hover {
  background: var(--grey-200);
  color: var(--grey-700);
}

.att-remove .ti {
  font-size: 16px;
}

.att-link-status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--grey-200);
  font-size: 11px;
}

.att-link-status .ti {
  font-size: 14px;
}

.att-link-status.linked {
  color: var(--blue);
}

.att-link-status.unlinked {
  color: var(--grey-500);
}

.att-link-tag {
  background: white;
  border: 1px solid var(--grey-200);
  border-radius: 6px;
  padding: 2px 10px;
  font-size: 11px;
  color: var(--grey-700);
  font-weight: 500;
}

/* ══ LINK DETAIL PANEL ══ */
/* Pannello inline che si espande nella sidebar per mostrare i link di un allegato */
.att-link-status.linked {
  cursor: pointer;
}

.att-link-status.linked:hover {
  opacity: 0.8;
}

.att-link-detail {
  margin-top: 6px;
  border-top: 1px solid var(--grey-200);
  padding-top: 6px;
}

.att-link-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 11px;
  color: var(--grey-700);
  cursor: pointer;
  transition: background 0.1s;
}

.att-link-row:hover {
  background: var(--blue-hover);
}

.att-link-page {
  font-weight: 600;
  color: var(--grey-900);
  white-space: nowrap;
}

/* Bottone "mostra link nel documento" — icona occhio discreta */
.att-link-eye {
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--grey-400);
  flex-shrink: 0;
  padding: 0;
}

.att-link-eye:hover {
  background: var(--grey-200);
  color: var(--grey-700);
}

.att-link-remove {
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--grey-400);
  flex-shrink: 0;
  padding: 0;
  margin-left: auto;
}

.att-link-remove:hover {
  background: var(--grey-200);
  color: var(--grey-700);
}

/* ══ SELECTION POPUP ══ */
.selection-popup {
  position: fixed;
  background: white;
  border-radius: 12px;
  box-shadow: var(--shadow-2);
  display: flex;
  align-items: center;
  padding: 4px;
  gap: 2px;
  z-index: 200;
  animation: popIn 0.15s ease-out;
}

.selection-popup.hidden {
  display: none;
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(4px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.popup-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  font-family: "Inter", sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.popup-btn:hover {
  background: var(--accent-hover);
}

.popup-btn .ti {
  font-size: 18px;
}

.popup-btn-secondary {
  display: flex;
  align-items: center;
  padding: 8px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--grey-700);
  cursor: pointer;
}

.popup-btn-secondary:hover {
  background: var(--grey-100);
}

.popup-btn-secondary .ti {
  font-size: 18px;
}

/* ══ ATTACHMENT PICKER ══ */
.attachment-picker {
  position: fixed;
  background: white;
  border-radius: 12px;
  box-shadow: var(--shadow-2);
  padding: 8px 0;
  z-index: 201;
  min-width: 260px;
  max-height: 50vh;
  overflow-y: auto;
  animation: popIn 0.15s ease-out;
}

.picker-title {
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 500;
  color: var(--grey-500);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.picker-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  font-size: 13px;
  color: var(--grey-900);
  cursor: pointer;
  transition: background 0.1s;
}

.picker-item svg {
  color: var(--accent);
  flex-shrink: 0;
}

.picker-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.picker-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 500;
  color: var(--blue);
  min-width: 32px;
  justify-content: flex-end;
}

.picker-badge.hidden {
  visibility: hidden;
}

.picker-badge svg {
  color: var(--blue);
}

.picker-item:hover {
  background: var(--accent-light);
}

/* ══ LINK OVERLAY ══ */
/* Sottolineature blu posizionate sopra il text layer — WYSIWYG: identiche
   a come appariranno nel PDF esportato (sottolineatura blu 0.8pt).
   pointer-events: none di default — il testo sotto resta selezionabile.
   Al hover appare un leggero highlight per riconoscere l'area cliccabile. */
.link-overlay {
  position: absolute;
  background: transparent;
  border: none;
  border-bottom: 2px solid rgba(26, 115, 232, 0.85);
  pointer-events: none;
  z-index: 3;
  cursor: pointer;
  transition: background 0.15s;
}

.link-overlay.flash {
  animation: overlay-flash 2.5s ease-out;
}

@keyframes overlay-flash {
  0%,
  10%,
  20%,
  30%,
  40% {
    background: var(--blue-flash);
  }
  5%,
  15%,
  25%,
  35%,
  45% {
    background: transparent;
  }
  50%,
  100% {
    background: transparent;
  }
}

.link-overlay:hover {
  background: rgba(26, 115, 232, 0.08);
}

/* Tooltip che appare al passaggio del mouse su un link overlay */
.link-tooltip {
  position: fixed;
  background: var(--grey-900);
  color: white;
  font-family: "Inter", sans-serif;
  font-size: 12px;
  font-weight: 400;
  padding: 6px 10px;
  border-radius: 8px;
  z-index: 250;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: var(--shadow-2);
  opacity: 0;
  transition: opacity 0.15s;
}

.link-tooltip.visible {
  opacity: 1;
}

/* Quando l'utente sta selezionando testo, gli overlay non intercettano il mouse */
.link-overlays-interactive .link-overlay {
  pointer-events: auto;
}

/* ══ LINK MENU ══ */
.link-menu {
  position: fixed;
  background: white;
  border-radius: 12px;
  box-shadow: var(--shadow-2);
  padding: 8px;
  z-index: 201;
  min-width: 240px;
  transform: translateX(-50%);
  animation: popIn 0.15s ease-out;
}

.link-menu-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--grey-700);
  border-bottom: 1px solid var(--grey-200);
  margin-bottom: 4px;
}

.link-menu-remove {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  font-family: "Inter", sans-serif;
  font-size: 13px;
  color: var(--red);
  cursor: pointer;
  transition: background 0.1s;
}

.link-menu-remove:hover {
  background: var(--red-light);
}

/* ══ SIDEBAR RESIZE HANDLE ══ */
.sidebar-resize-handle {
  width: 5px;
  cursor: col-resize;
  background: transparent;
  flex-shrink: 0;
  position: relative;
  z-index: 91;
  transition: background 0.15s;
}

.sidebar-resize-handle:hover,
.sidebar-resize-handle.dragging {
  background: var(--accent);
}

/* ══ RESPONSIVE ══ */
@media (max-width: 900px) {
  .toolbar-filename {
    max-width: 140px;
  }
}
