/**
 * pdf-tools.css
 * The PDF tools workspace (Phase 7): full-window layout, file list, tool list,
 * page grid, page preview stage (signing and redaction) and results.
 * Dark by default like the other studio dialogs; light-mode rules at the end.
 *
 * Dependencies: css/study.css (.ts-study-dialog, progress bar, buttons).
 */

@font-face {
  font-family: 'TS Signature Caveat';
  src: url('../assets/fonts/Caveat-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: block;
}

/* ============================================
   LAYOUT
   ============================================ */

.ts-study-dialog.ts-pdf-dialog .ts-study-dialog-box {
  width: min(1240px, 100%);
  height: calc(100vh - 2rem);
}

.ts-study-dialog.ts-pdf-dialog .ts-study-dialog-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  padding: 0;
}

.ts-pdf-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.ts-pdf-layout.is-dropping {
  outline: 3px dashed #22c55e;
  outline-offset: -6px;
}

.ts-pdf-side {
  overflow: auto;
  padding: 0.9rem;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.ts-pdf-side-title {
  margin: 0.4rem 0 0;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.7;
}

.ts-pdf-main {
  overflow: auto;
  padding: 1rem 1.2rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  min-width: 0;
}

/* ============================================
   FILES AND TOOLS
   ============================================ */

.ts-pdf-files {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.ts-pdf-file {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 0.35rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
}

.ts-pdf-file.is-current {
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.1);
}

.ts-pdf-file-pick {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: none;
  border: 0;
  color: inherit;
  padding: 0.25rem;
  display: flex;
  flex-direction: column;
  cursor: pointer;
}

.ts-pdf-file-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ts-pdf-file-meta {
  font-size: 0.8rem;
  opacity: 0.75;
}

.ts-pdf-file-tools {
  display: flex;
  gap: 0.15rem;
}

.ts-pdf-file-error {
  flex-basis: 100%;
  margin: 0 0.25rem 0.2rem;
  font-size: 0.8rem;
  color: #fca5a5;
}

.ts-pdf-password {
  flex-basis: 100%;
  display: flex;
  gap: 0.35rem;
  padding: 0 0.25rem 0.25rem;
}

.ts-pdf-password input {
  flex: 1;
  min-width: 0;
}

.ts-pdf-icon {
  min-width: 2rem;
  min-height: 2rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.05);
  color: inherit;
  cursor: pointer;
}

.ts-pdf-icon:hover,
.ts-pdf-icon:focus-visible {
  background: rgba(34, 197, 94, 0.2);
}

.ts-pdf-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.ts-pdf-nav-item {
  text-align: left;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid transparent;
  background: none;
  color: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}

.ts-pdf-nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.ts-pdf-nav-item[aria-pressed="true"] {
  border-color: rgba(34, 197, 94, 0.6);
  background: rgba(34, 197, 94, 0.15);
  font-weight: 600;
}

.ts-pdf-drop {
  border: 2px dashed rgba(255, 255, 255, 0.25);
  border-radius: 14px;
  padding: 2.5rem 1rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  cursor: pointer;
}

.ts-pdf-drop:hover,
.ts-pdf-drop:focus-visible {
  border-color: #22c55e;
}

/* ============================================
   STATUS, TOOL AREA, RESULTS
   ============================================ */

.ts-pdf-statusbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.ts-pdf-status {
  margin: 0;
  flex: 1;
  min-width: 12rem;
}

.ts-pdf-status[data-type="error"] {
  color: #fca5a5;
}

.ts-pdf-progress {
  flex: 1;
  min-width: 10rem;
}

.ts-pdf-progress.is-indeterminate .ts-study-progress-bar {
  animation: ts-pdf-pulse 1.2s ease-in-out infinite;
}

@keyframes ts-pdf-pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .ts-pdf-progress.is-indeterminate .ts-study-progress-bar { animation: none; }
}

.ts-pdf-tool-title {
  margin: 0;
  font-size: 1.2rem;
}

.ts-pdf-tool-area {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.ts-pdf-blocked {
  padding: 1rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
}

.ts-pdf-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}

.ts-pdf-toolbar-label {
  font-size: 0.9rem;
  opacity: 0.85;
}

.ts-pdf-range {
  width: 11rem;
}

.ts-pdf-number {
  width: 4.5rem;
}

.ts-pdf-actions {
  padding-top: 0.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.ts-pdf-result {
  border: 1px solid rgba(34, 197, 94, 0.5);
  border-radius: 12px;
  padding: 0.8rem 1rem;
  background: rgba(34, 197, 94, 0.08);
}

.ts-pdf-result-title {
  margin: 0 0 0.4rem;
  font-weight: 600;
}

.ts-pdf-result-list {
  margin: 0.6rem 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  max-height: 14rem;
  overflow: auto;
}

.ts-pdf-result-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.ts-pdf-honest {
  margin: 0;
  padding: 0.6rem 0.8rem;
  border-left: 4px solid #eab308;
  background: rgba(234, 179, 8, 0.1);
  border-radius: 6px;
}

/* ============================================
   PAGE GRID
   ============================================ */

.ts-pdf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.7rem;
}

.ts-pdf-tile {
  position: relative;
  border: 2px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 0.45rem;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}

.ts-pdf-tile:focus-visible {
  outline: 3px solid #60a5fa;
  outline-offset: 2px;
}

.ts-pdf-tile[aria-selected="true"] {
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.14);
}

.ts-pdf-tile.is-dragging {
  opacity: 0.45;
}

.ts-pdf-tile.drop-before {
  box-shadow: inset 5px 0 0 #22c55e;
}

.ts-pdf-tile.drop-after {
  box-shadow: inset -5px 0 0 #22c55e;
}

.ts-pdf-thumb {
  width: 130px;
  height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ts-pdf-thumb img {
  max-width: 120px;
  max-height: 140px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
  transition: transform 0.15s ease;
}

.ts-pdf-thumb img:not([src]) {
  width: 90px;
  height: 120px;
}

.ts-pdf-thumb-missing {
  font-size: 0.8rem;
  opacity: 0.7;
}

.ts-pdf-tile-caption {
  font-size: 0.85rem;
  font-weight: 600;
}

.ts-pdf-tile-was {
  font-weight: 400;
  opacity: 0.7;
}

.ts-pdf-tile-actions {
  display: flex;
  gap: 0.2rem;
}

/* ============================================
   PAGE PREVIEW STAGE (sign, redact)
   ============================================ */

.ts-pdf-stage-wrap {
  overflow: auto;
  max-width: 100%;
}

.ts-pdf-stage {
  position: relative;
  display: inline-block;
  line-height: 0;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  touch-action: none;
  user-select: none;
}

.ts-pdf-stage canvas {
  display: block;
  max-width: none;
}

.ts-pdf-stage-layer {
  position: absolute;
  inset: 0;
}

.ts-pdf-sign-mode {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0.5rem 0;
}

.ts-pdf-sig-current {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 2.5rem;
}

.ts-pdf-sig-image {
  max-height: 70px;
  max-width: 260px;
  background: #fff;
  border-radius: 8px;
  padding: 0.25rem 0.5rem;
}

.ts-pdf-merge-list {
  margin: 0;
  padding-left: 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.ts-pdf-merge-list .is-skipped {
  opacity: 0.6;
  font-style: italic;
}

.ts-pdf-stage.is-drawing {
  cursor: crosshair;
}

.ts-pdf-box {
  position: absolute;
  box-sizing: border-box;
}

.ts-pdf-box.is-redaction {
  background: rgba(0, 0, 0, 0.85);
  outline: 2px solid #ef4444;
}

.ts-pdf-box.is-signature {
  outline: 2px dashed #22c55e;
  cursor: move;
}

.ts-pdf-box.is-signature img {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

.ts-pdf-box-handle {
  position: absolute;
  right: -8px;
  bottom: -8px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid #fff;
  cursor: nwse-resize;
}

.ts-pdf-box-remove {
  position: absolute;
  top: -12px;
  right: -12px;
  width: 24px;
  height: 24px;
  line-height: 20px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: #ef4444;
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  padding: 0;
}

.ts-pdf-pad {
  display: block;
  width: 100%;
  max-width: 520px;
  height: 180px;
  background: #fff;
  border-radius: 10px;
  touch-action: none;
  cursor: crosshair;
}

.ts-pdf-typed-preview {
  font-family: 'TS Signature Caveat', cursive;
  font-size: 2.6rem;
  color: #1e3a8a;
  background: #fff;
  border-radius: 10px;
  padding: 0.3rem 1rem;
  min-height: 3.5rem;
  line-height: 1.3;
}

.ts-pdf-fields {
  display: grid;
  grid-template-columns: minmax(10rem, 16rem) minmax(0, 1fr);
  gap: 0.5rem 1rem;
  align-items: center;
}

.ts-pdf-fields input[type="text"],
.ts-pdf-fields textarea,
.ts-pdf-fields select {
  width: 100%;
  box-sizing: border-box;
}

/* ============================================
   LIGHT MODE
   ============================================ */

body.light-mode .ts-pdf-side {
  border-right-color: rgba(0, 0, 0, 0.1);
}

body.light-mode .ts-pdf-file,
body.light-mode .ts-pdf-tile {
  border-color: rgba(0, 0, 0, 0.12);
}

body.light-mode .ts-pdf-file.is-current,
body.light-mode .ts-pdf-tile[aria-selected="true"] {
  border-color: #16a34a;
  background: rgba(22, 163, 74, 0.1);
}

body.light-mode .ts-pdf-icon {
  border-color: rgba(0, 0, 0, 0.18);
  background: rgba(0, 0, 0, 0.03);
}

body.light-mode .ts-pdf-drop {
  border-color: rgba(0, 0, 0, 0.25);
}

body.light-mode .ts-pdf-status[data-type="error"],
body.light-mode .ts-pdf-file-error {
  color: #b91c1c;
}

body.light-mode .ts-pdf-blocked {
  background: rgba(0, 0, 0, 0.04);
}

body.light-mode .ts-pdf-actions {
  border-top-color: rgba(0, 0, 0, 0.1);
}
