/* Sign PDF - styles */

:root {
  --accent-1: #4338CA;
  --accent-2: #818CF8;
  --ink: #1E1B2E;
  --ink-soft: #6B7280;
  --border: #E5E7EB;
  --bg-soft: #EEF2FF;
  --danger: #DC2626;
  --success: #059669;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: linear-gradient(160deg, #EEF2FF 0%, #F5F3FF 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(67, 56, 202, 0.10), 0 2px 8px rgba(0,0,0,0.04);
  padding: 28px 24px;
}

.info-note {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--bg-soft);
  border: 1px solid #C7D2FE;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13px;
  color: #3730A3;
  margin-bottom: 22px;
}
.info-note svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }

.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 #C7D2FE;
  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: #E0E7FF;
}
.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; }

/* ---------------- Editor ---------------- */
.editor-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 22px;
  align-items: start;
}
@media (max-width: 780px) {
  .editor-layout { grid-template-columns: 1fr; }
}

.page-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 12px;
}
.page-nav-btn {
  width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--border); background: #fff; color: var(--accent-1);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.page-nav-btn svg { width: 16px; height: 16px; }
.page-nav-btn:disabled { opacity: 0.35; cursor: default; }
.page-nav-label { font-size: 13px; font-weight: 700; color: var(--ink-soft); min-width: 110px; text-align: center; }

.page-canvas-wrap {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  display: flex;
  justify-content: center;
}
.page-canvas {
  position: relative;
  max-width: 100%;
  background: #000;
  box-shadow: 0 4px 18px rgba(0,0,0,0.14);
}
.page-canvas img { display: block; width: 100%; height: auto; max-height: 70vh; -webkit-user-drag: none; user-drag: none; }
.canvas-hint { text-align: center; font-size: 11.5px; color: var(--ink-soft); margin-top: 10px; }

.field-layer { position: absolute; inset: 0; touch-action: none; }
.field-box {
  position: absolute;
  cursor: move;
  /* No overflow/border/background here -- those live on
     .field-box-content below instead, so the rotate/resize handles and
     the remove button (all positioned outside the box's own edges) turn
     with the box via its transform without ever being clipped by it. */
}
.field-box-content {
  position: absolute;
  inset: 0;
  border: 1.5px dashed rgba(67, 56, 202, 0.55);
  background: rgba(129, 140, 248, 0.08);
  display: flex;
  align-items: center;
  overflow: hidden;
}
.field-box.selected .field-box-content { border: 1.5px solid var(--accent-1); background: rgba(129, 140, 248, 0.14); box-shadow: 0 0 0 3px rgba(67,56,202,0.14); }
.field-box img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; -webkit-user-drag: none; }
.field-box .field-text { white-space: nowrap; pointer-events: none; line-height: 1; }
.field-box .resize-handle {
  position: absolute; right: -6px; bottom: -6px; width: 14px; height: 14px;
  background: var(--accent-1); border: 2px solid #fff; border-radius: 50%;
  cursor: nwse-resize; display: none;
}
.field-box.selected .resize-handle { display: block; }
.field-box .field-remove {
  position: absolute; top: -10px; right: -10px; width: 20px; height: 20px;
  background: #fff; border: 1px solid var(--border); border-radius: 50%;
  color: var(--danger); display: none; align-items: center; justify-content: center;
  cursor: pointer; font-size: 13px; line-height: 1; padding: 0;
}
.field-box.selected .field-remove { display: flex; }

.field-box .rotate-line {
  position: absolute; left: 50%; top: -22px; width: 1px; height: 22px;
  background: rgba(67, 56, 202, 0.4); display: none;
}
.field-box .rotate-handle {
  position: absolute; left: 50%; top: -30px; width: 16px; height: 16px;
  margin-left: -8px;
  background: #fff; border: 2px solid var(--accent-1); border-radius: 50%;
  cursor: grab; display: none; align-items: center; justify-content: center;
}
.field-box.selected .rotate-line, .field-box.selected .rotate-handle { display: flex; }
.field-box .rotate-handle svg { width: 9px; height: 9px; color: var(--accent-1); pointer-events: none; }

.editor-sidebar {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.sidebar-section { display: flex; flex-direction: column; gap: 10px; padding-bottom: 14px; border-bottom: 1px dashed var(--border); }
.sidebar-section:last-of-type { border-bottom: none; padding-bottom: 0; }
.section-label { font-size: 12.5px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); }

.add-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.btn-add {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: #fff; border: 1.5px solid var(--border); border-radius: 12px;
  padding: 12px 4px; cursor: pointer; font-size: 11.5px; font-weight: 700; color: var(--ink);
}
.btn-add:hover { border-color: var(--accent-2); }
.btn-add svg { width: 20px; height: 20px; color: var(--accent-1); }

.option-row-inline { display: flex; flex-direction: column; gap: 5px; }
.prop-label { font-size: 11.5px; font-weight: 700; color: var(--ink-soft); }
.prop-label-row { display: flex; align-items: center; justify-content: space-between; }
.link-btn-small { background: none; border: none; color: var(--accent-1); font-weight: 700; font-size: 11px; cursor: pointer; padding: 0; }
.prop-input {
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  font-size: 13px; background: #fff; width: 100%;
}
.prop-color { width: 100%; height: 34px; border: 1px solid var(--border); border-radius: 8px; padding: 2px; background: #fff; cursor: pointer; }
#propSize { width: 100%; accent-color: var(--accent-1); }
.prop-size-value { font-size: 12px; font-weight: 700; color: var(--accent-1); }
.prop-style-toggles { display: flex; gap: 6px; }
.style-toggle-btn {
  width: 34px; height: 30px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; cursor: pointer; font-size: 13px;
}
.style-toggle-btn.active { border-color: var(--accent-1); background: var(--bg-soft); color: var(--accent-1); }

.btn-remove-field {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  background: #FEF2F2; border: 1px solid #FCA5A5; color: var(--danger);
  border-radius: 10px; padding: 9px; font-size: 12.5px; font-weight: 700; cursor: pointer; margin-top: 4px;
}
.btn-remove-field svg { width: 14px; height: 14px; }

.option-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.option-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.option-label { font-size: 13px; font-weight: 700; color: var(--ink); }
.option-hint { font-size: 11px; color: var(--ink-soft); }

.switch { position: relative; display: inline-block; width: 44px; height: 26px; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-track { position: absolute; inset: 0; background: #D1D5DB; border-radius: 20px; transition: background-color 0.15s ease; }
.switch-thumb { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; background: #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,0.25); transition: transform 0.15s ease; }
.switch input:checked ~ .switch-track { background: var(--accent-1); }
.switch input:checked ~ .switch-track .switch-thumb { transform: translateX(18px); }

.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;
}
.btn-compress svg { width: 20px; height: 20px; }
.btn-compress:hover { filter: brightness(1.05); }

.link-btn { background: none; border: none; color: var(--accent-1); font-weight: 700; font-size: 13px; cursor: pointer; padding: 0; }

/* ---------------- Modal ---------------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5);
  display: flex; align-items: center; justify-content: center; z-index: 100000; padding: 20px;
}
.modal-box {
  background: #fff; border-radius: 18px; padding: 20px; width: min(600px, 100%);
  max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; font-weight: 800; font-size: 17px; margin-bottom: 14px; }
.modal-close { background: none; border: none; font-size: 22px; color: var(--ink-soft); cursor: pointer; line-height: 1; }
.modal-tabs { display: flex; gap: 4px; background: var(--bg-soft); border-radius: 10px; padding: 4px; margin-bottom: 16px; }
.modal-tab { flex: 1; background: none; border: none; padding: 9px; border-radius: 8px; font-weight: 700; font-size: 13px; color: var(--ink-soft); cursor: pointer; }
.modal-tab.active { background: #fff; color: var(--accent-1); box-shadow: 0 1px 4px rgba(0,0,0,0.08); }
.modal-tab-panel { display: none; }
.modal-tab-panel.active { display: block; }

.pen-color-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.pen-color-swatch {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent;
  cursor: pointer; padding: 0; box-shadow: 0 0 0 1px rgba(0,0,0,0.08);
}
.pen-color-swatch.active { border-color: var(--accent-1); box-shadow: 0 0 0 2px rgba(67,56,202,0.25); }
.pen-color-custom { width: 26px; height: 26px; border: none; border-radius: 50%; padding: 0; cursor: pointer; background: none; }
.pen-color-custom::-webkit-color-swatch-wrapper { padding: 0; border-radius: 50%; }
.pen-color-custom::-webkit-color-swatch { border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0,0,0,0.08); }

#signatureCanvas {
  width: 100%; height: 220px; border: 1.5px dashed var(--border); border-radius: 12px;
  background: #fff; touch-action: none; cursor: crosshair;
}
.modal-row-between { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.canvas-hint-small { font-size: 11.5px; color: var(--ink-soft); }

.type-font-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 12px 0; }
.type-font-option { display: none; }
.type-font-tile {
  border: 1.5px solid var(--border); border-radius: 10px; padding: 10px; cursor: pointer;
  font-size: 18px; text-align: center; color: var(--ink); background: #fff;
}
.type-font-option:checked + .type-font-tile { border-color: var(--accent-1); background: var(--bg-soft); box-shadow: 0 0 0 3px rgba(67,56,202,0.12); }
.type-preview-wrap { border: 1.5px dashed var(--border); border-radius: 12px; padding: 20px; text-align: center; background: #FAFAFF; min-height: 90px; display: flex; align-items: center; justify-content: center; }
.type-preview { font-size: 34px; color: #1a1a2e; word-break: break-word; }

.upload-sig-zone { border: 1.5px dashed var(--border); border-radius: 12px; padding: 24px; text-align: center; background: #FAFAFF; }
.upload-sig-preview { display: block; max-width: 100%; max-height: 160px; margin: 14px auto; background: repeating-conic-gradient(#F1F5F9 0% 25%, #fff 0% 50%) 50% / 16px 16px; border-radius: 8px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-soft); margin-top: 10px; cursor: pointer; }
.checkbox-row input { accent-color: var(--accent-1); width: 16px; height: 16px; }

/* ---------------- 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: #EEF2FF; 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: #EEF2FF; 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; margin: 0 4px 6px; }
.quality-pill.raster { background: #FEF3C7; color: #92400E; }
.tamper-pill { background: #EEF2FF; color: var(--accent-1); }

.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 20px 0; }
@media (max-width: 480px) { .result-stats { grid-template-columns: repeat(1, 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; }

.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: 100001; 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; }
