:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --success: #059669;
  --success-hover: #047857;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
}

[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #283548;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-soft: rgba(59, 130, 246, 0.14);
  --success: #10b981;
  --success-hover: #059669;
  --success-soft: rgba(16, 185, 129, 0.14);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.14);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.14);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.app-shell {
  max-width: 1060px;
  margin: 0 auto;
  padding: 24px 18px 72px;
}

.hidden {
  display: none !important;
}

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

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

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.topbar-badges {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-icon-toggle {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all 0.15s ease;
}

.btn-icon-toggle:hover {
  background: var(--surface-2);
  border-color: var(--primary);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.badge-privacy {
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid #a7f3d0;
}

.badge-privacy .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

/* Folder Bar */
.folder-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}

.folder-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.folder-icon {
  font-size: 1.4rem;
}

.folder-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
}

.folder-path {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

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

/* Tabs */
.tabs {
  display: flex;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  flex: 1 0 auto;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.tab:hover {
  color: var(--text);
  background: var(--surface-2);
}

.tab.active {
  background: var(--primary);
  color: #fff;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.card-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.muted {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

/* Presets */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
}

.preset-card {
  text-align: left;
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 11px 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.preset-card:hover {
  border-color: #93c5fd;
  background: var(--primary-soft);
}

.preset-card.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.preset-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}

.preset-sub {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
}

/* Form controls */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}

.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s ease;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.input-group {
  display: flex;
  gap: 6px;
}

.input-group input {
  flex: 1;
}

.input-group select {
  width: 82px;
  flex-shrink: 0;
}

.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  font-size: 0.86rem;
  color: var(--text);
  cursor: pointer;
}

.checkbox-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 15px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.8rem;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: #bfdbfe;
}

.btn-secondary:hover:not(:disabled) {
  background: #dbeafe;
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-success:hover:not(:disabled) {
  background: var(--success-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
  border-color: #fecaca;
}

.btn-danger-ghost:hover:not(:disabled) {
  background: var(--danger-soft);
}

/* Dropzone */
.dropzone {
  border: 2px dashed #cbd5e1;
  border-radius: 12px;
  background: var(--surface-2);
  padding: 28px 18px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.dropzone-icon {
  font-size: 1.9rem;
  margin-bottom: 6px;
}

.dropzone-title {
  font-weight: 700;
  font-size: 0.96rem;
}

.dropzone-sub {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 3px;
}

/* Batch Toolbar & Queue */
.batch-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.batch-summary {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}

.batch-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.file-queue {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 14px;
}

.file-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  background: var(--surface-2);
}

.file-item.done {
  border-color: #a7f3d0;
  background: #f8fffc;
}

.file-item.error {
  border-color: #fecaca;
  background: var(--danger-soft);
}

.file-item-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.file-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.type-pill {
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  flex-shrink: 0;
}

.type-pill.img {
  background: #dbeafe;
  color: #1d4ed8;
}

.type-pill.pdf {
  background: #fee2e2;
  color: #b91c1c;
}

.file-orig-name {
  font-weight: 700;
  font-size: 0.92rem;
  word-break: break-all;
}

.file-orig-size {
  font-size: 0.8rem;
  color: var(--muted);
}

.file-controls {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

@media (max-width: 640px) {
  .file-controls {
    grid-template-columns: 1fr;
  }
}

.file-result {
  margin-top: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 0.83rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.file-result.ok {
  background: var(--success-soft);
  color: #065f46;
}

.file-result.warn {
  background: var(--warning-soft);
  color: #92400e;
}

.file-result.err {
  background: var(--danger-soft);
  color: #991b1b;
}

.file-item-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* Merge List */
.merge-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}

.merge-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.merge-item-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.merge-index {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.action-row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.split-info {
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: #1e40af;
  font-size: 0.88rem;
  font-weight: 600;
}

.result-banner {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 0.88rem;
  background: var(--success-soft);
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.result-banner.err {
  background: var(--danger-soft);
  color: #991b1b;
  border-color: #fecaca;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  background: #0f172a;
  color: #fff;
  padding: 11px 16px;
  border-radius: 10px;
  font-size: 0.86rem;
  font-weight: 500;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.25);
  z-index: 1000;
  max-width: 360px;
}

/* Signature Tab */
.subtabs {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  gap: 3px;
}

.subtab {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.subtab.active {
  background: var(--primary);
  color: #fff;
}

.sig-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.toolbar-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.sig-colors,
.sig-stroke,
.sig-pad-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s ease;
}

.color-dot.active {
  border-color: #93c5fd;
  box-shadow: 0 0 0 2px var(--primary);
  transform: scale(1.1);
}

.sig-canvas-wrap {
  position: relative;
  border: 1.5px dashed #cbd5e1;
  border-radius: 10px;
  background: #ffffff;
  overflow: hidden;
  touch-action: none;
}

#sigCanvas {
  display: block;
  width: 100%;
  height: 190px;
  cursor: crosshair;
  touch-action: none;
}

.sig-canvas-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  color: #94a3b8;
  font-size: 0.9rem;
}

.dropzone-compact {
  padding: 18px 14px;
}

.checker-bg {
  background-image:
    linear-gradient(45deg, #e2e8f0 25%, transparent 25%),
    linear-gradient(-45deg, #e2e8f0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e2e8f0 75%),
    linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
  background-size: 14px 14px;
  background-position: 0 0, 0 7px, 7px -7px, -7px 0;
  background-color: #ffffff;
}

.sig-upload-editor {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 14px;
  margin-top: 12px;
  align-items: center;
}

@media (max-width: 640px) {
  .sig-upload-editor {
    grid-template-columns: 1fr;
  }
}

.sig-upload-preview-wrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  min-height: 140px;
  display: grid;
  place-items: center;
}

.sig-upload-preview-wrap img {
  max-width: 100%;
  max-height: 150px;
  object-fit: contain;
}

.sig-upload-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sig-collection-wrap {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.sig-collection {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.sig-empty {
  font-size: 0.84rem;
  color: var(--muted);
  padding: 8px 0;
}

.sig-card {
  position: relative;
  width: 140px;
  height: 76px;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  padding: 6px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.sig-card:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.14);
}

.sig-card img {
  max-width: 100%;
  max-height: 58px;
  object-fit: contain;
  pointer-events: none;
}

.sig-card-del {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid #fecaca;
  background: #fff;
  color: var(--danger);
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.sig-card-del:hover {
  background: var(--danger);
  color: #fff;
}

.sign-doc-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 12px;
}

.sign-doc-meta {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.sign-page-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-label {
  font-size: 0.84rem;
  font-weight: 700;
  min-width: 105px;
  text-align: center;
}

.sign-stage-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.sign-stage-outer {
  background: #e2e8f0;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  justify-content: center;
  overflow: auto;
  max-height: 72vh;
}

.sign-stage {
  position: relative;
  display: inline-block;
  line-height: 0;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.16);
  background: #fff;
  user-select: none;
  touch-action: none;
}

#signDocImg {
  display: block;
  max-width: 100%;
  max-height: 66vh;
  width: auto;
  height: auto;
  pointer-events: none;
}

.sign-overlay-layer {
  position: absolute;
  inset: 0;
}

.sig-placement {
  position: absolute;
  border: 1.5px dashed var(--primary);
  background: rgba(37, 99, 235, 0.06);
  border-radius: 4px;
  cursor: move;
  touch-action: none;
}

.sig-placement:hover,
.sig-placement.active {
  border-style: solid;
  background: rgba(37, 99, 235, 0.1);
}

.sig-placement img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  display: block;
}

.sig-placement-del {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: var(--danger);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.sig-placement-resize {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: var(--primary);
  border: 2px solid #fff;
  cursor: nwse-resize;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.sign-placement-summary {
  margin-top: 10px;
  font-size: 0.84rem;
  color: var(--muted);
  text-align: center;
}

/* Remove BG Tab */
.rbg-preview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 12px;
}

@media (max-width: 640px) {
  .rbg-preview-grid {
    grid-template-columns: 1fr;
  }
}

.rbg-preview-box {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-2);
}

.rbg-preview-label {
  padding: 7px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.rbg-preview-frame {
  height: 300px;
  display: grid;
  place-items: center;
  padding: 10px;
  overflow: hidden;
}

.rbg-preview-frame img,
.rbg-preview-frame canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

.rbg-placeholder {
  font-size: 0.86rem;
  color: var(--muted);
  text-align: center;
  padding: 16px;
}

.rbg-controls {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.rbg-control-group {
  margin-bottom: 12px;
}

.rbg-swatches,
.rbg-ratios {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.rbg-swatch,
.rbg-ratio {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.rbg-swatch:hover,
.rbg-ratio:hover {
  border-color: #93c5fd;
  background: var(--primary-soft);
}

.rbg-swatch.active,
.rbg-ratio.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.swatch-chip {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid #cbd5e1;
  display: inline-block;
}

.rbg-swatch-custom input[type="color"] {
  width: 20px;
  height: 20px;
  border: none;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

/* Dark mode overrides for subtle cards */
[data-theme="dark"] .file-item.done {
  background: rgba(16, 185, 129, 0.08);
}

[data-theme="dark"] .file-result.ok {
  color: #6ee7b7;
}

[data-theme="dark"] .file-result.warn {
  color: #fcd34d;
}

[data-theme="dark"] .file-result.err {
  color: #fca5a5;
}

[data-theme="dark"] .sign-stage-outer {
  background: #0f172a;
}

[data-theme="dark"] .result-banner {
  color: #6ee7b7;
}

[data-theme="dark"] .result-banner.err {
  color: #fca5a5;
}

/* Mobile & Tablet Responsive Polish */
@media (max-width: 640px) {
  .app-shell {
    padding: 14px 12px 56px;
  }

  .brand h1 {
    font-size: 1.18rem;
  }

  .subtitle {
    font-size: 0.8rem;
  }

  .folder-bar {
    padding: 12px;
  }

  .folder-actions {
    width: 100%;
  }

  .folder-actions .btn {
    flex: 1;
    min-height: 42px;
  }

  .card {
    padding: 14px;
  }

  .preset-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .preset-card {
    padding: 9px 10px;
  }

  .preset-name {
    font-size: 0.82rem;
  }

  .preset-sub {
    font-size: 0.72rem;
  }

  .btn {
    min-height: 42px;
  }

  .btn-sm {
    min-height: 36px;
  }

  .batch-actions,
  .action-row {
    width: 100%;
  }

  .batch-actions .btn,
  .action-row .btn {
    flex: 1;
  }

  .color-dot {
    width: 28px;
    height: 28px;
  }

  .sig-placement-resize {
    width: 20px;
    height: 20px;
    right: -9px;
    bottom: -9px;
  }

  .sig-placement-del {
    width: 26px;
    height: 26px;
    top: -12px;
    right: -12px;
  }

  .rbg-preview-frame {
    height: 230px;
  }

  .toast {
    left: 12px;
    right: 12px;
    bottom: 14px;
    max-width: none;
    text-align: center;
  }
}

/* Subtab Bar & Panels (PDF Toolkit, Crop & Watermark) */
.subtab-bar {
  display: flex;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 5px;
  margin-bottom: 14px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.subtab-bar::-webkit-scrollbar {
  display: none;
}

.subtab-bar .subtab {
  white-space: nowrap;
  flex: 1 0 auto;
  padding: 8px 12px;
}

.pdf-subpanel,
.edit-subpanel {
  display: none;
}

.pdf-subpanel.active,
.edit-subpanel.active {
  display: block;
}

/* Crop & Watermark Canvases */
#cropPreviewCanvas,
#wmPreviewCanvas {
  display: block;
  max-width: 100%;
  max-height: 62vh;
  width: auto;
  height: auto;
}

.crop-box {
  position: absolute;
  border: 2px solid var(--primary);
  box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.45);
  cursor: move;
  touch-action: none;
}

.crop-handle {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  background: var(--primary);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.crop-handle[data-handle="nw"] { top: -8px; left: -8px; cursor: nwse-resize; }
.crop-handle[data-handle="ne"] { top: -8px; right: -8px; cursor: nesw-resize; }
.crop-handle[data-handle="sw"] { bottom: -8px; left: -8px; cursor: nesw-resize; }
.crop-handle[data-handle="se"] { bottom: -8px; right: -8px; cursor: nwse-resize; }

@media (max-width: 640px) {
  .crop-handle {
    width: 22px;
    height: 22px;
  }
  .crop-handle[data-handle="nw"] { top: -11px; left: -11px; }
  .crop-handle[data-handle="ne"] { top: -11px; right: -11px; }
  .crop-handle[data-handle="sw"] { bottom: -11px; left: -11px; }
  .crop-handle[data-handle="se"] { bottom: -11px; right: -11px; }
}
