/* signing.css - Styles for signing interface */

/* CSS Variables are defined in dark-theme.css */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--sd-display);
  font-size: 14px;
  color: var(--sd-fg);
  background-color: var(--sd-bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background: var(--sd-bg);
  border-bottom: 1px solid var(--sd-line);
  z-index: 10;
}

.toolbar > .btn {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: 0 16px;
}

.toolbar > .btn svg {
  display: block;
  vertical-align: baseline;
}

/* Takes the free space between Back and the toolbar actions. Without flex:1 it
   collapses to its min-width and truncates the filename. */
.document-name {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-width: 0;
  margin: 0 16px;
  padding: 0;
}

.document-name input,
#document-name-input {
  padding: 0 16px;
  border: 1px solid var(--sd-chip-line);
  border-radius: var(--sd-radius-pill);
  font-family: var(--sd-display);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-align: center;
  min-width: 0;
  max-width: 620px;
  width: 100%;
  background: var(--sd-bg);
  color: var(--sd-fg);
  height: 40px;
  line-height: normal;
  box-sizing: border-box;
  text-overflow: ellipsis;
  margin: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  vertical-align: middle;
  outline-offset: -1px;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-actions .btn {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

/* Zoom steppers sit in a 40px toolbar row, so they run a touch larger than the
   default small chip. navigation.js disables them at the ends of the range. */
.toolbar-actions .chip-btn-sm {
  width: 34px;
  height: 34px;
}

.toolbar-actions label {
  font-weight: 500;
  color: var(--text-primary);
}

.toolbar-actions select {
  padding: 0 32px 0 14px;
  border: 1px solid var(--sd-chip-line);
  border-radius: var(--sd-radius-pill);
  font-family: var(--sd-display);
  font-size: 13px;
  font-weight: 600;
  background: var(--sd-bg);
  color: var(--sd-fg);
  height: 40px;
  cursor: pointer;
  box-sizing: border-box;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L6 6L11 1' stroke='%235f6368' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

/* Zoom controls */
#zoom-out-btn,
#zoom-in-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

#zoom-out-btn:hover,
#zoom-in-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--primary-color);
}

#zoom-out-btn:disabled,
#zoom-in-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: var(--bg-secondary);
  border-color: var(--border-color);
}

#zoom-out-btn:disabled:hover,
#zoom-in-btn:disabled:hover {
  background: var(--bg-secondary);
  border-color: var(--border-color);
}

#zoom-select {
  min-width: 100px;
  height: 40px;
  padding: 0 16px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.2s ease;
  box-sizing: border-box;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  text-align: center;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L6 6L11 1' stroke='%235f6368' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  margin: 0;
  line-height: normal;
}

/* Main content */
.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: var(--sd-bg);
  border-right: 1px solid var(--sd-line);
  display: flex;
  flex-direction: column;
  padding: 20px;
  overflow-y: auto;
}

#drawing-sidebar {
  background: var(--sd-bg);
}

.sidebar-section {
  margin-bottom: 24px;
  position: relative;
}

.sidebar-section:last-child {
  margin-bottom: 0;
}

#drawing-sidebar .sidebar-section {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--sd-fg-soft);
}

/* Tools container */
.tools-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

/* Deliberately colourless. These sit beside the document, and the document is
   what should hold the eye; colour here is reserved for the selected state. */
.tool-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 10px;
  background: var(--sd-well);
  border: 1px solid transparent;
  border-radius: var(--sd-radius-card);
  cursor: grab;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
  user-select: none;
  position: relative;
}

.tool-card:hover {
  background: var(--sd-well-hover);
  transform: translateY(-2px);
}

.tool-card.active,
.tool-card[aria-pressed='true'] {
  border-color: var(--sd-fg);
  background: var(--sd-bg);
}

.tool-card:active,
.tool-card.dragging {
  cursor: grabbing;
  transform: scale(0.96);
  opacity: 0.85;
}

.tool-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--sd-radius-pill);
  background: var(--sd-chip);
  border: 1px solid var(--sd-chip-line);
  color: var(--sd-fg);
  line-height: 1;
}

.tool-icon svg {
  width: 20px;
  height: 20px;
  stroke-width: 1.75;
}

.tool-name {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--sd-fg);
  text-align: center;
}

.tool-edit-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease, background 0.2s ease;
  z-index: 10;
  pointer-events: auto;
}

.tool-card:hover .tool-edit-btn {
  opacity: 1;
  pointer-events: auto;
}

.tool-edit-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--primary-color);
}

.tool-edit-btn svg {
  display: block;
  color: var(--text-secondary);
}

.tool-edit-btn:hover svg {
  color: var(--primary-color);
}

.signatures-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
  overflow-y: auto;
}

.signature-card {
  border: 2px solid var(--border-color);
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
  transition: all 0.2s;
  /* Always white background for signature visibility in both themes */
  background: #ffffff !important;
}

.signature-card:hover {
  border-color: var(--primary-color);
  box-shadow: var(--shadow-md);
}

.signature-card.selected {
  border-color: var(--primary-color);
  background: #e8f0fe !important;
}

.signature-card.dragging {
  opacity: 0.5;
  cursor: move;
}

.signature-card[draggable="true"] {
  cursor: grab;
}

.signature-card[draggable="true"]:active {
  cursor: grabbing;
}

.signature-card img {
  max-width: 100%;
  height: auto;
  max-height: 60px;
  object-fit: contain;
  pointer-events: none; /* Let the card handle drag */
}

.signature-card-name {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
}

/* Drawing Sidebar */
.sidebar-header-actions {
  display: flex;
  gap: 8px;
}

.tool-btn-small {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all 0.2s ease;
}

.tool-btn-small:hover:not(:disabled) {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.tool-btn-small:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.drawing-modes {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border-color);
}

.drawing-mode-btn {
  width: 56px;
  height: 56px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.drawing-mode-btn:hover:not(.active) {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--primary-color);
}

.drawing-mode-btn.active {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.drawing-mode-btn svg {
  width: 22px;
  height: 22px;
}

.drawing-control-group {
  margin-bottom: 24px;
}

.control-label {
  display: block;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.size-selector {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.size-btn {
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  max-width: 48px;
  max-height: 48px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
}

.size-btn:hover:not(.active) {
  background: var(--bg-tertiary);
  border-color: var(--primary-color);
}

.size-btn.active {
  background: var(--primary-color);
  border-color: var(--primary-color);
}

.size-btn.active .size-preview {
  background: white !important;
}

.size-preview {
  background: var(--text-secondary);
  border-radius: 50%;
  transition: all 0.2s ease;
}

.size-preview-1 {
  width: 4px;
  height: 4px;
}

.size-preview-2 {
  width: 8px;
  height: 8px;
}

.size-preview-3 {
  width: 12px;
  height: 12px;
}

.size-preview-5 {
  width: 16px;
  height: 16px;
}

.size-preview-8 {
  width: 20px;
  height: 20px;
}

.color-selector {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.color-row {
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.color-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.color-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.color-btn.active {
  border-color: var(--primary-color);
  border-width: 3px;
  box-shadow: 0 0 0 2px var(--bg-secondary);
}

/* Tool Label */
.tool-label {
  position: absolute;
  bottom: 20px;
  right: 20px;
  padding: 8px 16px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  pointer-events: none;
}

/* Canvas area */
.canvas-area {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px;
  overflow: auto;
  position: relative;
  background: var(--sd-well);
  min-height: 500px;
}

.canvas-container {
  position: relative;
  max-width: 100%;
  display: block;
}

.pages-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: center;
  width: 100%;
}

.page-wrapper {
  position: relative; /* CRITICAL: needed for absolute positioning of canvases */
  box-shadow: var(--shadow-md);
  background: white; /* PDF pages should always be white */
  scroll-margin-top: 20px;
  transition: all 0.2s ease;
  display: block;
  width: fit-content;
}

.page-wrapper.drag-over {
  box-shadow: 0 0 0 3px var(--primary-color), var(--shadow-lg);
  background: white; /* Keep PDF background white even when dragging */
  outline: 3px solid var(--primary-color);
  outline-offset: -3px;
}

.page-wrapper.drag-over::before {
  content: "Drop signature here";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--primary-color);
  color: white;
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 16px;
  pointer-events: none;
  z-index: 100;
  box-shadow: var(--shadow-lg);
}

.page-wrapper canvas.pdf-canvas {
  display: block !important;
  width: 100% !important;
  height: auto !important;
  position: relative !important;
  z-index: 1 !important;
  background: white !important;
  opacity: 1 !important;
  visibility: visible !important;
}

.page-wrapper canvas.signature-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: default;
  pointer-events: auto;
  z-index: 10; /* Ensure it's above PDF canvas */
  background: transparent !important;
  opacity: 1 !important;
}

/* Fabric.js wrapper - must cover the entire page */
.page-wrapper .fabric-wrapper {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  z-index: 5 !important;
  pointer-events: none !important; /* Let clicks through to canvases inside */
}

/* Fabric.js lower canvas (where signatures are drawn) */
.page-wrapper .lower-canvas {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  z-index: 10 !important;
  pointer-events: auto !important;
}

/* Fabric.js upper canvas (for selection/controls) */
.page-wrapper .upper-canvas {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  z-index: 11 !important;
  pointer-events: auto !important;
  cursor: default !important;
  background: transparent !important; /* CRITICAL: must be transparent to see lower canvas */
}

/* ---------------------------------------------------------------------------
 * Text layer (T-0035) — selection + in-document search.
 * A copied, trimmed subset of node_modules/pdfjs-dist/web/pdf_viewer.css
 * (Apache-2.0, see NOTICE), plus our own z-index / pointer-events rules. The
 * spans are transparent text positioned over the rendered glyphs so the OS/
 * Chrome selection lands on the real characters. --scale-factor is set on the
 * .page-wrapper by pdf-renderer; the spans read it via calc().
 * ------------------------------------------------------------------------- */
.page-wrapper .textLayer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  line-height: 1;
  text-align: initial;
  text-size-adjust: none;
  forced-color-adjust: none;
  transform-origin: 0 0;
  opacity: 1;
  /* Above the PDF canvas (z1), below the Fabric overlays (z5/10/11) so signing
     tools stay clickable. Selection is off by default; the toggle raises it. */
  z-index: 4;
  pointer-events: none;
}

.page-wrapper .textLayer span,
.page-wrapper .textLayer br {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0 0;
}

/* Chrome-only fix (pdf.js issue 14205): zero-size marked-content spans. */
.page-wrapper .textLayer span.markedContent {
  top: 0;
  height: 0;
}

/* Selected text shows the system accent behind the transparent glyphs. */
.page-wrapper .textLayer ::selection {
  background: AccentColor;
}

/* pdf.js appends this helper to keep selection from running past the last line. */
.page-wrapper .textLayer .endOfContent {
  display: block;
  position: absolute;
  inset: 100% 0 0;
  z-index: -1;
  cursor: default;
  user-select: none;
}

/* "Select text" mode: let the text layer take clicks and lift it above the
 * Fabric upper-canvas (z11). The id selector out-specifies the !important
 * pointer-events on .upper-canvas / .lower-canvas so those go inert. */
#pages-container[data-text-select] .page-wrapper .textLayer {
  pointer-events: auto;
  z-index: 20;
}

#pages-container[data-text-select] .page-wrapper .fabric-wrapper,
#pages-container[data-text-select] .page-wrapper .upper-canvas,
#pages-container[data-text-select] .page-wrapper .lower-canvas {
  pointer-events: none !important;
}

/* Search-match highlight overlay: sibling of the text layer, painted by the
 * find bar from Range.getClientRects(). Sits above the Fabric overlays so
 * matches are visible even with signatures placed; never takes pointer events. */
.page-wrapper .textLayer-highlights {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 12;
}

.page-wrapper .textLayer-highlights .search-hl {
  position: absolute;
  background: var(--sd-accent);
  opacity: 0.32;
  border-radius: 2px;
}

.page-wrapper .textLayer-highlights .search-hl.current {
  opacity: 0.55;
  outline: 1.5px solid var(--sd-accent);
}

/* Find bar (T-0035) — floats top-right of the canvas area. */
.find-bar {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--sd-chip, #fff);
  border: 1px solid var(--sd-chip-line, #e7e7ea);
  border-radius: var(--sd-radius-pill, 999px);
  box-shadow: var(--shadow-md);
}

.find-bar.hidden {
  display: none;
}

/* createInput wraps the field in a .form-group; neutralize its block layout so
   the field sits inline in the bar. */
.find-bar .form-group {
  margin: 0;
  display: flex;
  align-items: center;
}

.find-bar input.find-input {
  width: 200px;
  padding: 4px 10px;
  border: 1px solid var(--sd-line, #ededef);
  border-radius: var(--sd-radius-pill, 999px);
  background: var(--sd-bg, #fff);
  color: var(--sd-fg, #0b0b0c);
  font-size: 13px;
}

.find-bar input.find-input:focus {
  outline: 2px solid var(--sd-accent);
  outline-offset: -1px;
}

.find-bar .find-count {
  min-width: 56px;
  text-align: center;
  font-size: 12px;
  color: var(--sd-fg-soft, #6b6b70);
  white-space: nowrap;
}

.find-bar .chip-btn[disabled] {
  opacity: 0.4;
  cursor: default;
}

/* "Select text" toggle uses the shared chip button; the pressed state marks it
   selected without becoming a second solid control. */
#text-select-toggle[aria-pressed="true"] {
  background: var(--sd-well-hover, #ebebee);
  color: var(--sd-accent);
}

/* Make sure signature canvas is interactive */
.page-wrapper {
  pointer-events: auto;
}

.page-number-label {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  z-index: 5;
}

/* Page navigation */
.page-navigation {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--bg-primary);
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  z-index: 1000;
}

.page-navigation #page-info {
  min-width: 80px;
  text-align: center;
  font-weight: 600;
  font-size: 16px;
  color: var(--text-primary) !important;
  background: var(--bg-secondary) !important;
  padding: 8px 16px;
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  visibility: visible !important;
  opacity: 1 !important;
}

.page-counter {
  font-weight: 600;
  font-size: 16px;
  color: var(--text-primary) !important;
  background: var(--bg-secondary) !important;
  padding: 8px 16px;
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  visibility: visible !important;
  opacity: 1 !important;
}

/* Fixed page navigation on the right */
.fixed-page-nav {
  position: fixed;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: rgba(23, 23, 23, 0.3); /* 70% transparent (30% opacity) */
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 8px 6px;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 100;
}

.page-nav-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-primary);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  font-size: 14px;
}

.page-nav-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.2);
  border-color: var(--primary-color);
}

.page-nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.page-nav-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 6px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 6px;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.page-nav-current {
  font-size: 18px;
  font-weight: 700;
  color: #ffffff;
  line-height: 1;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.page-nav-separator {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.7);
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.page-nav-total {
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.8);
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* Loading indicator */
.loading-indicator {
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100% !important;
  height: 100% !important;
  text-align: center;
  background: var(--sd-well);
  z-index: 100 !important;
  animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.spinner {
  width: 56px;
  height: 56px;
  border: 4px solid var(--border-color);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  box-shadow: 0 4px 12px rgba(66, 133, 244, 0.2);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#loading-text {
  font-size: 18px;
  color: var(--text-secondary);
  font-weight: 500;
  margin: 0;
  letter-spacing: 0.3px;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

/* Progress bar */
.progress-container {
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.4);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

.progress-fill {
  height: 100%;
  background: var(--sd-solid);
  border-radius: 10px;
  width: 0%;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: none;
}

.progress-text {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
  letter-spacing: 0.2px;
}

/* Error message */
.error-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 40px;
  background: var(--bg-primary);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.error-message p {
  color: var(--error-color);
  font-weight: 500;
}

/* Buttons */
/* Buttons come from styles/controls.css. */

.hidden {
  display: none !important;
}


/* Form elements */
label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--text-primary);
}

input[type="text"],
select {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 16px;
}

input[type="text"]:focus,
select:focus {
  outline: none;
  border-color: var(--primary-color);
}

/* Canvas */
.signature-preview,
.drawing-canvas-container {
  border: 2px dashed var(--border-color);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 16px;
  background: var(--bg-secondary);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 120px;
}

.drawing-canvas-container {
  background: var(--bg-primary);
  border: 2px solid var(--primary-color);
}

#drawing-canvas,
#typed-preview-canvas {
  background: white;
  border-radius: 4px;
  max-width: 400px;
  max-height: 150px;
  width: 400px;
  height: 150px;
}

#drawing-canvas,
#signature-canvas {
  cursor: crosshair;
}

#typed-preview-canvas {
  cursor: default;
}

/* Drawing mode selector */
.drawing-mode-selector {
  margin-bottom: 16px;
  display: flex;
  gap: 16px;
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: 6px;
}

.drawing-mode-selector label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  margin: 0;
  font-size: 13px;
}

.drawing-mode-selector input[type="radio"] {
  cursor: pointer;
}

/* Drawing controls */
.drawing-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.pen-width-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  margin-bottom: 0;
}

#pen-width {
  width: 100px;
}

/* Upload zone (for signing-upload.html) */
.upload-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 500px;
  padding: 40px;
  flex: 1;
  width: 100%;
}

.upload-instructions {
  max-width: 600px;
  text-align: center;
}

.upload-instructions h2 {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.upload-instructions > p {
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-size: 16px;
}

.upload-area {
  margin-bottom: 48px;
}

.hidden-input {
  display: none !important;
}

.instructions-list {
  text-align: left;
  background: var(--bg-primary);
  padding: 24px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.instructions-list h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-primary);
}

.instructions-list ol {
  padding-left: 20px;
}

.instructions-list li {
  margin-bottom: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Signing interface (for uploaded PDFs) */
.signing-interface {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.signing-interface .canvas-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow: auto;
  position: relative;
}

.signing-interface .controls {
  background: var(--bg-primary);
  border-top: 1px solid var(--border-color);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.page-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.signature-selector {
  display: flex;
  align-items: center;
  gap: 12px;
}

.signature-selector label {
  margin-bottom: 0;
  white-space: nowrap;
}

.signature-select {
  flex: 1;
}

.action-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* Signature method selection */
.signature-method-buttons {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.method-btn {
  position: relative;
  border: 2px solid var(--border-color);
  transition: all 0.2s;
}

.method-btn.active {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.method-btn:hover {
  border-color: var(--primary-color);
}

.method-description {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.phone-tip {
  background: var(--bg-secondary);
  border-left: 4px solid var(--success-color);
  padding: 12px;
  margin-bottom: 16px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--text-primary);
}

.phone-tip strong {
  color: var(--success-color);
}

/* Inline QR Code Display (in Draw tab) */
/* The code is the instruction; this is a caption under it. */
.draw-instruction {
  font-size: 13px;
  color: var(--sd-fg-soft);
  margin-bottom: 14px;
  text-align: center;
}

/* A white card behind the code, so the quiet zone is visible and not just encoded. */
.qr-code-display,
.qr-code-container {
  width: fit-content;
  padding: 10px;
  background: #ffffff;
  border-radius: 16px;
}

.qr-code-display canvas,
.qr-code-container canvas {
  display: block;
  border-radius: 6px;
}

.qr-code-display {
  margin: 0 auto 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  max-width: 100%;
}

.qr-code-display canvas {
  display: block;
  margin: 0 auto;
}

.qr-timer-inline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 10px;
  background: var(--bg-secondary);
  border-radius: 8px;
  border: 1px solid var(--warning-color);
}

.qr-timer-inline p {
  margin: 0;
  font-weight: 500;
  color: var(--text-primary);
  font-size: 13px;
}

.qr-status-inline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  margin-bottom: 12px;
}

.qr-status-inline p {
  margin: 0;
  color: var(--primary-color);
  font-weight: 500;
  font-size: 13px;
}

.qr-hint-inline {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-align: center;
}

.qr-url-container-inline {
  background: var(--bg-secondary);
  padding: 10px;
  border-radius: 6px;
  margin-bottom: 16px;
  text-align: center;
}

.draw-here-instead {
  margin-top: 16px;
}

.draw-here-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

/* QR Code Modal */
.qr-modal-content {
  max-width: 400px;
}

.qr-modal-body {
  text-align: center;
}

.qr-instructions {
  margin-bottom: 20px;
  font-size: 14px;
  color: var(--text-secondary);
}

.qr-code-container {
  margin: 0 auto 20px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.qr-code-container canvas {
  display: block;
  margin: 0 auto;
}

.qr-timer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: 8px;
  border: 1px solid var(--warning-color);
}

.timer-icon {
  font-size: 20px;
}

.qr-timer p {
  margin: 0;
  font-weight: 500;
  color: var(--text-primary);
}

#qr-timer {
  font-family: 'Courier New', monospace;
  font-weight: bold;
}

.qr-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  margin-bottom: 16px;
}

.qr-status p {
  margin: 0;
  color: var(--primary-color);
  font-weight: 500;
}

.spinner-small {
  width: 20px;
  height: 20px;
  border: 3px solid var(--border-color);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.qr-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.qr-url-container {
  background: var(--bg-secondary);
  padding: 12px;
  border-radius: 6px;
  margin-bottom: 0;
}

.qr-url {
  font-size: 11px;
  color: var(--primary-color);
  word-break: break-all;
  font-family: 'Courier New', monospace;
}

/* ==================== Phase 3: Enhanced Toolbar & Tools ==================== */

/* Toolbar tools section */
.toolbar-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-right: 1px solid var(--border-color);
  border-left: 1px solid var(--border-color);
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 18px;
  color: var(--text-primary);
}

.tool-btn:hover {
  background-color: var(--bg-tertiary);
  border-color: var(--primary-color);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.tool-btn:active {
  transform: translateY(0);
  box-shadow: none;
}

.tool-btn.active {
  background-color: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.tool-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.tool-btn:disabled:hover {
  background-color: var(--bg-secondary);
  border-color: var(--border-color);
  box-shadow: none;
}

.toolbar-separator {
  width: 1px;
  height: 24px;
  background-color: var(--border-color);
  margin: 0 4px;
}

/* Button sizes */

/* The finish button is the one solid control on this screen; it needs no
   gradient to be found. */
.btn-primary.btn-large {
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}

.btn-primary.btn-large:hover {
  transform: translateY(-1px);
}

/* Theme toggle */
.theme-toggle {
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: 8px;
}

.theme-toggle:hover {
  background-color: var(--bg-tertiary);
}

/* Auto-save status */
.autosave-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  padding: 8px 12px;
  border-radius: 6px;
  background-color: var(--bg-secondary);
  height: 40px;
  box-sizing: border-box;
}

.autosave-status[data-status="saving"] {
  color: var(--warning-color);
}

.autosave-status[data-status="saved"] {
  color: var(--success-color);
}

.autosave-status[data-status="error"] {
  color: var(--error-color);
}

/* Tool configuration panels */
.tool-config-panel {
  padding: 16px;
  background-color: var(--bg-secondary);
  border-radius: 8px;
  margin-top: 16px;
}

.tool-config-panel h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-primary);
}

.config-group {
  margin-bottom: 16px;
}

.config-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.config-group input[type="range"] {
  width: 100%;
  margin: 8px 0;
}

.config-group input[type="color"] {
  width: 100%;
  height: 40px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  cursor: pointer;
}

.config-group input[type="text"],
.config-group select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 14px;
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

.config-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.style-buttons,
.mode-buttons,
.color-buttons {
  display: flex;
  gap: 8px;
}

.style-btn,
.mode-btn,
.color-btn {
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 14px;
}

.style-btn:hover,
.mode-btn:hover,
.color-btn:hover {
  background-color: var(--bg-tertiary);
  border-color: var(--primary-color);
}

.style-btn.active,
.mode-btn.active,
.color-btn.active {
  background-color: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.color-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 2px solid var(--border-color);
  border-radius: 50%;
}

.color-btn.active {
  border-color: var(--primary-color);
  border-width: 3px;
}

/* Draft recovery toast - subtle bottom-right notification */
.draft-recovery-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-primary);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 12px 16px;
  max-width: 320px;
  z-index: 9999;
  animation: slideInRight 0.3s ease-out;
  border-left: 4px solid #667eea;
}

.toast-content {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}

.toast-content svg {
  color: var(--primary-color);
  margin-top: 2px;
}

.toast-text {
  flex: 1;
}

.toast-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.toast-time {
  font-size: 12px;
  color: var(--text-secondary);
}

.toast-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.toast-btn {
  padding: 6px 14px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
}

.toast-btn-primary {
  background: var(--primary-color);
  color: white;
}

.toast-btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.toast-btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  padding: 6px 10px;
  font-size: 16px;
  line-height: 1;
}

.toast-btn-secondary:hover {
  background: var(--bg-tertiary);
}

@keyframes slideInRight {
  from {
    transform: translateX(400px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOutRight {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(400px);
    opacity: 0;
  }
}

/* Tooltips */
.tooltip {
  position: absolute;
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 1000;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
}

.tooltip.visible {
  opacity: 1;
}

.tooltip kbd {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  padding: 2px 6px;
  margin-left: 8px;
  font-family: monospace;
  font-size: 11px;
}

/* Reduced motion overrides */
@media (prefers-reduced-motion: reduce) {
  .tool-btn,
  .btn,
  .style-btn,
  .mode-btn,
  .color-btn {
    transition: none !important;
  }

  .btn::after {
    display: none;
  }

  .tool-btn:hover {
    transform: none !important;
  }
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ARIA live regions for announcements */
[role="status"][aria-live] {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* Active tool cursor states */
body[data-active-tool="name"],
body[data-active-tool="date"],
body[data-active-tool="text"] {
  cursor: crosshair;
}

body[data-active-tool="draw"] {
  cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"><circle cx="12" cy="12" r="4" fill="black"/></svg>') 12 12, crosshair;
}

/* Responsive adjustments */
@media (max-width: 1024px) {
  .toolbar {
    flex-wrap: wrap;
    gap: 8px;
  }

  .toolbar-tools {
    border: none;
    padding: 0;
  }

  .tool-btn {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }
}

/* Medium screens */
@media (max-width: 1200px) {
  .document-name input,
  #document-name-input {
    max-width: 600px;
  }
}

@media (max-width: 992px) {
  .document-name input,
  #document-name-input {
    max-width: 450px;
  }
}

/* Small screens */
@media (max-width: 768px) {
  .sidebar {
    width: 240px;
  }

  .toolbar {
    padding: 8px 12px;
  }

  .document-name input,
  #document-name-input {
    min-width: 200px;
    max-width: 350px;
  }
}

/* Extra small screens */
@media (max-width: 480px) {
  .document-name input,
  #document-name-input {
    min-width: 150px;
    max-width: 250px;
  }
}

/* Upload Interface */
.upload-interface {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 40px;
}

.upload-interface.hidden {
  display: none;
}

.upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 40px;
  border: 2px dashed var(--border-color);
  border-radius: 12px;
  background: var(--bg-secondary);
  text-align: center;
  max-width: 500px;
  width: 100%;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.upload-zone.drag-over {
  border-color: var(--primary-color, #4285f4);
  background: var(--bg-hover, rgba(66, 133, 244, 0.08));
}

.upload-zone h2 {
  font-size: 24px;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.upload-zone p {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

/* Destructive, so it stays out of the way until you reach for the card. */
.signature-card {
  position: relative;
}

.signature-delete-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: var(--sd-radius-pill);
  background: rgba(255, 255, 255, 0.86);
  color: #6b6b70;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.signature-delete-btn svg {
  width: 15px;
  height: 15px;
}

.signature-card:hover .signature-delete-btn,
.signature-delete-btn:focus-visible {
  opacity: 1;
}

.signature-delete-btn:hover {
  background: var(--sd-danger);
  color: #ffffff;
}

/* Phone-only action bar (markup in signing.html). The extension runs in a
   desktop window, so this only ever appears on the web tool at signdrop.app —
   but it belongs with the markup rather than in the site's overrides. */
.mobile-sign-bar {
  display: none;
}

@media (max-width: 780px) {
  .mobile-sign-bar {
    display: flex;
    flex-shrink: 0;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
    background: var(--sd-bg);
    border-top: 1px solid var(--sd-line);
  }

  .mobile-sign-bar .btn {
    flex: 1;
    height: 48px;
    gap: 8px;
  }
}

/* Sign-above-the-line affordance + rotate nudge, phone only (markup in
   signing.html, styles mirrored from phone/sign.css). Desktop draws in a
   400×150 slot where neither helps. */
.drawing-canvas-container {
  position: relative;
}

.signature-line,
.rotate-hint {
  display: none;
}

/* Same condition as the sheet layout in the site's web-overrides.css: a phone
   sideways is 844×390, so width alone does not describe one. */
@media (max-width: 780px), (max-height: 520px) {
  .signature-line {
    position: absolute;
    left: 22px;
    right: 22px;
    bottom: 22%;
    display: flex;
    align-items: center;
    gap: 10px;
    pointer-events: none;
  }

  .signature-line-mark {
    font-size: 15px;
    line-height: 1;
    color: #c7c7cc;
  }

  .signature-line-rule {
    flex: 1;
    height: 1px;
    background: #dededf;
  }

  .rotate-hint {
    display: block;
    flex-shrink: 0;
    margin-bottom: 10px;
    text-align: center;
    font-size: 12px;
    color: var(--sd-fg-soft);
  }
}

/* Sideways there is already room, and vertical space is scarce. Flat rather
   than nested: nesting is younger than the phones this has to run on. */
@media (max-height: 520px) {
  .rotate-hint {
    display: none;
  }
}
