/* Premium Crop PDF - styles */

:root {
  --accent-1: #0F766E;
  --accent-2: #2DD4BF;
  --ink: #1E1B2E;
  --ink-soft: #6B7280;
  --border: #E5E7EB;
  --bg-soft: #F0FDFA;
  --danger: #DC2626;
  --success: #059669;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: linear-gradient(160deg, #ECFEFF 0%, #F0FDFA 45%, #F8FAFC 100%);
  color: var(--ink);
  min-height: 100vh;
}

.app-wrapper {
  max-width: 1080px;
  margin: 0 auto;
  padding: 70px 20px 40px;
}

.glass-card {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 24px;
  box-shadow: 0 20px 60px rgba(15, 118, 110, 0.10), 0 2px 8px rgba(0,0,0,0.04);
  padding: 28px 24px;
}

.app-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 18px;
}
.app-icon svg { width: 28px; height: 28px; }

.app-title {
  text-align: center;
  font-size: 26px;
  font-weight: 800;
  margin: 0 0 6px;
  letter-spacing: -0.02em;
}
.app-subtitle {
  text-align: center;
  color: var(--ink-soft);
  font-size: 14.5px;
  margin: 0 0 28px;
}

.screen { display: none; }
.screen.active { display: block; }

/* ---------------- Upload ---------------- */
.upload-zone {
  border: 2px dashed #5EEAD4;
  border-radius: 18px;
  background: var(--bg-soft);
  padding: 56px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--accent-1);
  background: #CCFBF1;
}
.upload-icon { width: 46px; height: 46px; color: var(--accent-1); margin-bottom: 14px; }
.upload-text { font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.upload-subtext { color: var(--ink-soft); font-size: 13px; margin-bottom: 14px; }
.btn-choose {
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  color: #fff;
  border: none;
  padding: 11px 26px;
  border-radius: 30px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.upload-meta { margin-top: 16px; font-size: 12px; color: #9CA3AF; }

.upload-progress-card {
  margin-top: 16px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
}
.upload-progress-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.spinner {
  width: 22px; height: 22px; flex: none;
  animation: spin 0.9s linear infinite;
}
.spinner circle { stroke: var(--accent-1); stroke-dasharray: 46; stroke-dashoffset: 14; stroke-linecap: round; }
@keyframes spin { to { transform: rotate(360deg); } }
.upload-progress-text { flex: 1; min-width: 0; text-align: left; }
.upload-progress-name { font-size: 13.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.upload-progress-label { font-size: 12px; color: var(--ink-soft); }
.upload-progress-percent { font-size: 15px; font-weight: 800; color: var(--accent-1); flex: none; }
.upload-progress-track { height: 6px; background: var(--bg-soft); border-radius: 6px; overflow: hidden; }
.upload-progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent-1), var(--accent-2)); transition: width 0.2s ease; }

/* ---------------- Toolbar ---------------- */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.toolbar-file {
  font-size: 13.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}
.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}
.link-btn {
  background: none;
  border: none;
  color: var(--accent-1);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  padding: 0;
}

/* ---------------- Editor layout ---------------- */
.editor-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 22px;
  margin-bottom: 20px;
  align-items: start;
}
@media (max-width: 860px) {
  .editor-layout { grid-template-columns: 1fr; }
}

.editor-main { min-width: 0; }

.editor-stage-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
}

.page-nav-btn {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  transition: background-color .12s ease, color .12s ease;
}
.page-nav-btn svg { width: 18px; height: 18px; }
.page-nav-btn:hover:not(:disabled) { background: var(--accent-1); color: #fff; border-color: var(--accent-1); }
.page-nav-btn:disabled { opacity: 0.35; cursor: default; }

.editor-stage {
  position: relative;
  max-width: 100%;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(15,23,42,0.12);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  line-height: 0;
}
.page-image {
  display: block;
  max-width: min(78vw, 560px);
  max-height: 68vh;
  width: auto;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}

.stage-loading {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Dimmed mask outside the crop box -- four rectangles recomputed in JS
   whenever the box moves/resizes, rather than a single clip-path hole,
   so each edge's exact pixel bounds stay simple to reason about. */
.crop-mask {
  position: absolute;
  background: rgba(15, 23, 42, 0.55);
  pointer-events: none;
}

.crop-box {
  position: absolute;
  border: 2px solid #fff;
  outline: 1px solid rgba(15, 118, 110, 0.9);
  box-shadow: 0 0 0 9999px rgba(0,0,0,0); /* placeholder, masks do the dimming */
  cursor: move;
}
.crop-grid-line {
  position: absolute;
  background: rgba(255,255,255,0.55);
  pointer-events: none;
}
.crop-grid-line.v1 { left: 33.333%; top: 0; bottom: 0; width: 1px; }
.crop-grid-line.v2 { left: 66.666%; top: 0; bottom: 0; width: 1px; }
.crop-grid-line.h1 { top: 33.333%; left: 0; right: 0; height: 1px; }
.crop-grid-line.h2 { top: 66.666%; left: 0; right: 0; height: 1px; }

.crop-handle {
  position: absolute;
  background: #fff;
  border: 2px solid var(--accent-1);
  border-radius: 4px;
  width: 14px;
  height: 14px;
  z-index: 3;
}
.handle-n  { top: -8px; left: 50%; margin-left: -7px; cursor: ns-resize; }
.handle-s  { bottom: -8px; left: 50%; margin-left: -7px; cursor: ns-resize; }
.handle-e  { right: -8px; top: 50%; margin-top: -7px; cursor: ew-resize; }
.handle-w  { left: -8px; top: 50%; margin-top: -7px; cursor: ew-resize; }
.handle-ne { top: -8px; right: -8px; cursor: nesw-resize; border-radius: 50%; }
.handle-nw { top: -8px; left: -8px; cursor: nwse-resize; border-radius: 50%; }
.handle-se { bottom: -8px; right: -8px; cursor: nwse-resize; border-radius: 50%; }
.handle-sw { bottom: -8px; left: -8px; cursor: nesw-resize; border-radius: 50%; }

.page-counter {
  text-align: center;
  font-size: 12.5px;
  color: var(--ink-soft);
  font-weight: 700;
  margin-top: 10px;
}

/* ---------------- Page strip ---------------- */
.page-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 14px 2px 4px;
  margin-top: 4px;
}
.page-strip-item {
  flex: none;
  width: 56px;
  cursor: pointer;
  text-align: center;
}
.page-strip-thumb {
  position: relative;
  width: 56px;
  height: 72px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: #fff repeating-linear-gradient(45deg, #F1F5F9 0 8px, #F8FAFC 8px 16px);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.page-strip-thumb img { max-width: 100%; max-height: 100%; display: block; }
.page-strip-item.active .page-strip-thumb { border-color: var(--accent-1); box-shadow: 0 0 0 3px rgba(15,118,110,0.18); }
.page-strip-num { font-size: 10.5px; color: var(--ink-soft); margin-top: 4px; font-weight: 600; }
.page-strip-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent-1);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.page-strip-badge svg { width: 9px; height: 9px; }

/* ---------------- Editor panel ---------------- */
.editor-panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 2px 10px rgba(15,23,42,0.04);
}
.panel-section { margin-bottom: 18px; }
.panel-section:last-child { margin-bottom: 0; }
.panel-section-title {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  margin-bottom: 10px;
}

.unit-toggle {
  display: flex;
  background: var(--bg-soft);
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 12px;
}
.unit-toggle button {
  flex: 1;
  border: none;
  background: none;
  padding: 7px 0;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-soft);
  cursor: pointer;
}
.unit-toggle button.active {
  background: #fff;
  color: var(--accent-1);
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

.margin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.margin-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.margin-field span { font-size: 11.5px; font-weight: 700; color: var(--ink-soft); }
.margin-field input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
}
.margin-field input:focus { outline: none; border-color: var(--accent-1); }

.preset-row { display: flex; flex-wrap: wrap; gap: 8px; }
.preset-btn {
  border: 1px solid var(--border);
  background: #fff;
  padding: 7px 12px;
  border-radius: 20px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  transition: background-color .12s ease, border-color .12s ease, color .12s ease;
}
.preset-btn:hover { border-color: var(--accent-1); color: var(--accent-1); background: var(--bg-soft); }
.preset-btn.active { background: var(--accent-1); border-color: var(--accent-1); color: #fff; }

.crop-size-readout {
  background: var(--bg-soft);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--accent-1);
  text-align: center;
  margin-bottom: 12px;
}

.btn-apply-all {
  width: 100%;
  background: #fff;
  border: 1.5px solid var(--accent-1);
  color: var(--accent-1);
  padding: 11px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 13.5px;
  cursor: pointer;
  margin-bottom: 8px;
}
.btn-apply-all:hover { background: var(--bg-soft); }
.btn-apply-all:disabled { opacity: 0.45; cursor: default; background: #fff; }
.panel-hint { font-size: 11.5px; color: var(--ink-soft); line-height: 1.5; text-align: center; }

.btn-compress {
  margin-top: 4px;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  color: #fff;
  border: none;
  padding: 14px 20px;
  border-radius: 14px;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
}
.btn-compress svg { width: 20px; height: 20px; }
.btn-compress:hover { filter: brightness(1.05); }

/* ---------------- Processing ---------------- */
.processing-screen { text-align: center; padding: 30px 0; }
.progress-circle-wrap { position: relative; width: 170px; height: 170px; margin: 0 auto 20px; }
.progress-circle-wrap svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.progress-circle-bg { fill: none; stroke: #F0FDFA; stroke-width: 10; }
.progress-circle-fg {
  fill: none;
  stroke: var(--accent-1);
  stroke-width: 10;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.3s ease;
}
.progress-percent {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 800;
}
.progress-bar-track { height: 6px; background: #F0FDFA; border-radius: 6px; max-width: 340px; margin: 0 auto 16px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent-1), var(--accent-2)); width: 0%; transition: width 0.3s ease; }
.processing-message { font-weight: 700; margin-bottom: 4px; }
.processing-subtext { color: var(--ink-soft); font-size: 13px; }

/* ---------------- Result ---------------- */
.result-screen { text-align: center; padding: 10px 0 0; }
.result-badge {
  width: 64px; height: 64px; border-radius: 50%;
  background: #ECFDF5; color: var(--success);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 14px;
}
.result-badge svg { width: 30px; height: 30px; }
.result-title { font-size: 20px; font-weight: 800; margin-bottom: 10px; }

.quality-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: #ECFDF5; color: var(--success);
  padding: 6px 14px; border-radius: 30px; font-size: 12.5px; font-weight: 700;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 20px 0;
}
@media (max-width: 600px) { .result-stats { grid-template-columns: repeat(2, 1fr); } }
.result-stat { background: var(--bg-soft); border-radius: 12px; padding: 14px 8px; }
.result-stat-label { font-size: 11px; color: var(--ink-soft); margin-bottom: 4px; }
.result-stat-value { font-size: 18px; font-weight: 800; }
.result-stat-value.accent { color: var(--accent-1); }

.download-section { max-width: 380px; margin: 0 auto; }
.download-label { display: block; font-size: 12.5px; font-weight: 700; margin-bottom: 6px; text-align: left; }
.download-filename-input {
  width: 100%; padding: 11px 14px; border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 14px; font-size: 14px;
}
.btn-download {
  width: 100%;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  color: #fff; border: none; padding: 14px; border-radius: 14px;
  font-weight: 700; font-size: 15px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-bottom: 10px;
}
.btn-download svg { width: 20px; height: 20px; }
.btn-compress-another {
  width: 100%; background: none; border: none; color: var(--accent-1);
  font-weight: 700; font-size: 14px; cursor: pointer; padding: 8px;
}

.app-footer { text-align: center; color: var(--ink-soft); font-size: 12px; margin-top: 18px; }

/* ---------------- Toasts ---------------- */
.toast-container { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 100000; display: flex; flex-direction: column; gap: 10px; width: min(420px, 92vw); }
.toast-error {
  background: #fff; border-left: 4px solid var(--danger);
  border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.12);
  padding: 14px 16px; display: flex; gap: 12px; align-items: flex-start;
}
.toast-icon { width: 22px; height: 22px; color: var(--danger); flex: none; }
.toast-title { font-weight: 700; font-size: 13.5px; margin-bottom: 2px; }
.toast-message { font-size: 13px; color: var(--ink-soft); }
.toast-close { background: none; border: none; cursor: pointer; color: #9CA3AF; margin-left: auto; }

.d-none { display: none !important; }
