/* ===== CSS VARIABLES & THEME ===== */
:root {
  --bg: #f8f9fc;
  --bg-card: #ffffff;
  --bg-hover: #f1f3f9;
  --bg-drop: #f4f5fb;
  --text: #1a1a2e;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --border-hover: #d1d5db;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #eef2ff;
  --primary-glow: rgba(99, 102, 241, 0.15);
  --success: #10b981;
  --success-light: #ecfdf5;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.04), 0 2px 4px rgba(0,0,0,0.03);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.06), 0 4px 6px rgba(0,0,0,0.03);
  --shadow-xl: 0 20px 25px rgba(0,0,0,0.08), 0 10px 10px rgba(0,0,0,0.02);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --transition: 0.2s ease;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1117;
  --bg-card: #1a1c25;
  --bg-hover: #22252f;
  --bg-drop: #1e2028;
  --text: #f0f0f5;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --border: #2d303a;
  --border-hover: #3d404a;
  --primary: #818cf8;
  --primary-hover: #6366f1;
  --primary-light: rgba(99, 102, 241, 0.15);
  --primary-glow: rgba(129, 140, 248, 0.15);
  --success-light: rgba(16, 185, 129, 0.15);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.25);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.3);
  --shadow-xl: 0 20px 25px rgba(0,0,0,0.4);
}

/* ===== RESET & BASE ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

main {
  flex: 1;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
}

/* ===== CONTAINER ===== */
.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ===== HEADER ===== */
.header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  background: rgba(255,255,255,0.85);
}

[data-theme="dark"] .header {
  background: rgba(26, 28, 37, 0.85);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

.logo svg {
  flex-shrink: 0;
}

.nav {
  display: flex;
  gap: 8px;
}

.nav a {
  padding: 6px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.nav a:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.theme-toggle {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

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

.icon-sun { display: block; }
.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* ===== HERO ===== */
.hero {
  text-align: center;
  padding: 72px 0 48px;
  background: linear-gradient(180deg, var(--primary-light) 0%, transparent 100%);
}

.hero-badge {
  display: inline-block;
  padding: 6px 16px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 100px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-bottom: 20px;
  border: 1px solid var(--primary-glow);
}

.hero h1 {
  font-size: clamp(2rem, 5vw, 3.25rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
  margin-bottom: 16px;
  color: var(--text);
}

@supports (-webkit-background-clip: text) {
  .hero h1 {
    background: linear-gradient(135deg, var(--text) 0%, var(--primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
  }
}

.hero-sub {
  font-size: 1.1rem;
  color: var(--text-secondary);
  max-width: 520px;
  margin: 0 auto;
  line-height: 1.7;
}

/* ===== SEARCH BAR ===== */
.search-wrap {
  position: relative;
  max-width: 520px;
  margin: 28px auto 0;
}

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 14px 80px 14px 48px;
  border: 2px solid var(--border);
  border-radius: 100px;
  background: var(--bg-card);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  transition: all 0.25s ease;
  box-shadow: var(--shadow-md);
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-glow), var(--shadow-lg);
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-count {
  position: absolute;
  right: 18px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Section hiding when search is active */
.section-title.hidden-section,
.tools-grid.hidden-section {
  display: none !important;
}

.tool-card.hidden-card {
  display: none !important;
}

/* ===== SECTION TITLES ===== */
.section-title {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.35rem;
  font-weight: 700;
  margin: 48px 0 20px;
  letter-spacing: -0.02em;
}

.section-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: white;
}

.pdf-icon { background: linear-gradient(135deg, #6366f1, #8b5cf6); }
.image-icon { background: linear-gradient(135deg, #f59e0b, #ef4444); }

/* ===== TOOLS GRID ===== */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.tool-card {
  display: flex;
  flex-direction: column;
  padding: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all 0.25s ease;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.tool-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), #a855f7);
  opacity: 0;
  transition: opacity 0.25s ease;
}

.tool-card:hover {
  border-color: var(--primary-glow);
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--primary-glow);
  transform: translateY(-2px);
}

.tool-card:hover::before {
  opacity: 1;
}

.tool-card-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

.tool-card h3 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: -0.01em;
}

.tool-card p {
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Color variants for tool cards */
.tool-card[data-color="indigo"] .tool-card-icon { background: rgba(99,102,241,0.12); color: #6366f1; }
.tool-card[data-color="blue"] .tool-card-icon { background: rgba(59,130,246,0.12); color: #3b82f6; }
.tool-card[data-color="violet"] .tool-card-icon { background: rgba(139,92,246,0.12); color: #8b5cf6; }
.tool-card[data-color="cyan"] .tool-card-icon { background: rgba(6,182,212,0.12); color: #06b6d4; }
.tool-card[data-color="emerald"] .tool-card-icon { background: rgba(16,185,129,0.12); color: #10b981; }
.tool-card[data-color="rose"] .tool-card-icon { background: rgba(244,63,94,0.12); color: #f43f5e; }
.tool-card[data-color="amber"] .tool-card-icon { background: rgba(245,158,11,0.12); color: #f59e0b; }
.tool-card[data-color="teal"] .tool-card-icon { background: rgba(20,184,166,0.12); color: #14b8a6; }
.tool-card[data-color="orange"] .tool-card-icon { background: rgba(249,115,22,0.12); color: #f97316; }
.tool-card[data-color="pink"] .tool-card-icon { background: rgba(236,72,153,0.12); color: #ec4899; }

/* ===== VIEW SYSTEM ===== */
.view {
  display: none;
}

.view.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== TOOL VIEW COMMON ===== */
.tool-view .container {
  padding-top: 40px;
  padding-bottom: 80px;
}

.tool-header {
  margin-bottom: 32px;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 16px;
  transition: color var(--transition);
}

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

.tool-header h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
}

.tool-header p {
  color: var(--text-secondary);
  font-size: 1rem;
}

/* ===== DROP ZONE ===== */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-drop);
  padding: 48px 24px;
  text-align: center;
  transition: all 0.25s ease;
  cursor: pointer;
  position: relative;
}

.drop-zone:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.drop-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 4px var(--primary-glow);
  transform: scale(1.01);
}

.drop-zone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.drop-icon {
  color: var(--text-muted);
  margin-bottom: 8px;
}

.drop-zone:hover .drop-icon,
.drop-zone.drag-over .drop-icon {
  color: var(--primary);
}

.drop-zone-content p {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
}

.drop-zone-content span {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.drop-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.file-label {
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
}

.file-label:hover {
  text-decoration: underline;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  position: relative;
}

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

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 1px 2px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
  transform: translateY(-1px);
}

.btn-outline {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-style: solid;
}

.btn-outline:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

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

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

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

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

.btn-lg {
  padding: 14px 32px;
  font-size: 1rem;
}

.btn.loading .btn-text {
  visibility: hidden;
}

.btn.loading .btn-loader {
  display: block;
}

.btn-loader {
  display: none;
  position: absolute;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ===== INPUTS ===== */
.input, .select {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
  transition: all var(--transition);
  width: 100%;
}

.input:focus, .select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.select {
  cursor: pointer;
  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 1.5L6 6.5L11 1.5' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

[data-theme="dark"] .select {
  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 1.5L6 6.5L11 1.5' stroke='%239ca3af' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: none;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.9rem;
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  min-width: 18px;
  height: 18px;
  accent-color: var(--primary);
  margin-right: 4px;
}

/* ===== TOOL OPTIONS ===== */
.tool-options {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-top: 20px;
}

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

.option-group:last-child {
  margin-bottom: 0;
}

.option-group > label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.option-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.lock-permissions {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.lock-perm-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
}

.lock-perm-label input[type="checkbox"] {
  accent-color: var(--primary);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.range-group {
  display: flex;
  align-items: center;
  gap: 16px;
}

.range-group input[type="range"] {
  flex: 1;
}

.range-group span {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
  min-width: 60px;
}

/* ===== FILE LIST ===== */
.file-list {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.sortable .file-item {
  cursor: grab;
}

.sortable .file-item:active {
  cursor: grabbing;
}

.sortable .file-item.dragging {
  opacity: 0.5;
  box-shadow: var(--shadow-lg);
}

.file-item-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 800;
  flex-shrink: 0;
}

.file-item-thumb {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

.file-item-info {
  flex: 1;
  min-width: 0;
}

.file-item-name {
  font-size: 0.9rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-item-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.file-item-remove {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
  font-size: 1.2rem;
}

.file-item-remove:hover {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
}

.file-item-drag {
  color: var(--text-muted);
  cursor: grab;
  flex-shrink: 0;
  font-size: 1.1rem;
  user-select: none;
}

/* ===== TOOL ACTIONS ===== */
.tool-actions {
  margin-top: 24px;
  display: flex;
  justify-content: center;
}

/* ===== OUTPUT AREA ===== */
.output-area {
  margin-top: 32px;
}

.output-card {
  background: var(--success-light);
  border: 1px solid var(--success);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  color: var(--text);
}

.output-card h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--success);
  margin-bottom: 8px;
}

.output-card p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 16px;
}

.output-card .btn {
  margin: 4px;
}

/* ===== PREVIEW SECTIONS ===== */
.preview-section {
  margin-top: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.preview-section h4 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.preview-section img,
.preview-section canvas {
  max-width: 100%;
  max-height: 300px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  display: block;
}

.preview-compare {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 16px;
  align-items: start;
  margin: 16px 0;
}

.preview-panel {
  text-align: center;
}

.preview-panel h4 {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.preview-panel img {
  max-width: 100%;
  max-height: 280px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  display: inline-block;
}

.preview-panel .preview-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.preview-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: var(--primary);
  font-weight: 700;
  padding-top: 28px;
}

.output-preview {
  margin: 16px auto;
  text-align: center;
}

.output-preview img {
  max-width: 100%;
  max-height: 300px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  display: inline-block;
}

.output-preview .preview-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
}

@media (max-width: 600px) {
  .preview-compare {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .preview-arrow {
    padding-top: 0;
    transform: rotate(90deg);
  }
}

.output-filename {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 16px auto 8px;
  max-width: 400px;
}

.output-filename label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

.output-filename .input {
  text-align: center;
  font-weight: 500;
  padding: 8px 14px;
}

.output-images {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.output-image-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.output-image-card img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  display: block;
}

.output-image-card .output-image-info {
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.output-image-card .output-image-info span {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ===== PAGES GRID (Split PDF) ===== */
.pages-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 20px;
}

.page-thumb {
  position: relative;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s ease;
  aspect-ratio: 3/4;
  background: #fff;
}

[data-theme="dark"] .page-thumb {
  background: #2a2d38;
}

.page-thumb canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.page-thumb.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

.page-thumb .page-num {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: rgba(0,0,0,0.7);
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
}

.page-thumb .page-check {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 800;
}

.page-thumb.selected .page-check {
  display: flex;
}

/* ===== ROTATION BUTTONS ===== */
.rotation-btns {
  display: flex;
  gap: 8px;
}

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

/* ===== CROP WORKSPACE ===== */
.crop-workspace {
  margin-top: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.crop-canvas-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  cursor: crosshair;
  line-height: 0;
}

.crop-canvas-wrap canvas {
  max-width: 100%;
  border-radius: var(--radius-sm);
}

.crop-overlay {
  position: absolute;
  border: 2px solid var(--primary);
  background: rgba(99, 102, 241, 0.15);
  pointer-events: none;
  display: none;
}

.crop-info {
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* ===== IMAGE PREVIEW ===== */
.image-preview {
  margin-top: 16px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  max-width: 400px;
}

.image-preview img {
  width: 100%;
  border-radius: var(--radius-sm);
}

/* ===== TOAST ===== */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideIn 0.3s ease;
  max-width: 380px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--primary); }

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

/* ===== PROGRESS MODAL ===== */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 32px;
  min-width: 360px;
  box-shadow: var(--shadow-xl);
}

.progress-info {
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 0.9rem;
  font-weight: 600;
}

.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #a855f7);
  border-radius: 4px;
  transition: width 0.3s ease;
  width: 0%;
}

/* ===== FOOTER ===== */
.footer {
  text-align: center;
  padding: 40px 24px;
  margin-top: 60px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
}

.footer strong {
  color: var(--text-secondary);
}

/* ===== RESPONSIVE — SMALL SCREENS ===== */
@media (max-width: 768px) {
  .hero {
    padding: 48px 0 32px;
  }

  .hero h1 {
    font-size: 1.75rem;
  }

  .tools-grid {
    grid-template-columns: 1fr;
  }

  .nav {
    display: none;
  }

  .option-row {
    grid-template-columns: 1fr;
  }

  .tool-header h1 {
    font-size: 1.5rem;
  }

  .output-images {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }

  .pages-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }

  .modal-content {
    min-width: auto;
    margin: 0 20px;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 0 16px;
  }

  .drop-zone {
    padding: 32px 16px;
  }

  .tool-options {
    padding: 16px;
  }

  .rotation-btns {
    flex-wrap: wrap;
  }
}

/* ===== RESPONSIVE — LARGE DESKTOP (≥1200px) ===== */
@media (min-width: 1200px) {
  .container {
    max-width: 1200px;
  }

  .tools-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
  }

  .tool-card {
    padding: 28px;
  }

  .pages-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
  }

  .output-images {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 20px;
  }

  .stat-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
  }

  .tool-split {
    grid-template-columns: 1fr 380px;
    gap: 28px;
  }

  .latex-editor-wrap {
    min-height: 560px;
  }

  .kb-board {
    gap: 16px;
  }

  .sn-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  }
}

/* ===== RESPONSIVE — WIDE SCREEN (≥1440px) ===== */
@media (min-width: 1440px) {
  .container {
    max-width: 1400px;
    padding: 0 40px;
  }

  /* Home view tools container gets extra width */
  #home-view .container {
    max-width: 1400px;
  }

  .tools-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 22px;
  }

  .tool-card {
    padding: 30px;
  }

  .tool-card-icon {
    width: 52px;
    height: 52px;
    margin-bottom: 18px;
  }

  .section-title {
    font-size: 1.45rem;
    margin: 56px 0 24px;
  }

  .hero {
    padding: 80px 0 56px;
  }

  .tool-view .container {
    max-width: 1400px;
    padding-top: 48px;
  }

  .tool-split {
    grid-template-columns: 1fr 400px;
    gap: 32px;
  }

  .compare-panels {
    gap: 24px;
  }

  .pages-grid {
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  }

  .output-images {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  }

  .latex-editor-wrap {
    min-height: 600px;
    gap: 24px;
  }

  .drop-zone {
    padding: 56px 32px;
  }

  .tool-options {
    padding: 28px;
  }

  .option-row {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .stat-grid {
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  }

  .sn-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  }
}

/* ===== RESPONSIVE — ULTRA-WIDE (≥1920px) ===== */
@media (min-width: 1920px) {
  .container {
    max-width: 1720px;
    padding: 0 48px;
  }

  #home-view .container {
    max-width: 1720px;
  }

  .tools-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 24px;
  }

  .tool-card {
    padding: 32px;
  }

  .tool-card-icon {
    width: 56px;
    height: 56px;
  }

  .tool-card h3 {
    font-size: 1.1rem;
  }

  .section-title {
    font-size: 1.55rem;
    margin: 64px 0 28px;
  }

  .hero {
    padding: 96px 0 64px;
  }

  .hero h1 {
    font-size: 3.5rem;
  }

  .hero-sub {
    font-size: 1.2rem;
    max-width: 620px;
  }

  .search-wrap {
    max-width: 600px;
  }

  .tool-view .container {
    max-width: 1720px;
    padding-top: 56px;
  }

  .tool-header h1 {
    font-size: 2.25rem;
  }

  .tool-split {
    grid-template-columns: 1fr 440px;
    gap: 40px;
  }

  .pages-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
  }

  .output-images {
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 24px;
  }

  .compare-panels {
    gap: 28px;
  }

  .latex-editor-wrap {
    min-height: 650px;
    gap: 28px;
  }

  .latex-textarea {
    min-height: 500px;
  }

  .latex-preview {
    min-height: 500px;
  }

  .kb-board {
    gap: 20px;
  }

  .drop-zone {
    padding: 64px 40px;
  }

  .tool-options {
    padding: 32px;
  }

  .option-row {
    grid-template-columns: 1fr 1fr 1fr;
    gap: 24px;
  }

  .stat-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
  }

  .sn-grid {
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
  }

  .text-tool-wrap {
    padding: 32px;
  }

  .preview-compare {
    gap: 24px;
  }

  #preview-modal .preview-modal-inner {
    max-width: 1200px;
  }
}

/* ===== RESPONSIVE — SUPER ULTRA-WIDE (≥2560px) ===== */
@media (min-width: 2560px) {
  .container {
    max-width: 2200px;
    padding: 0 64px;
  }

  #home-view .container {
    max-width: 2200px;
  }

  .tools-grid {
    grid-template-columns: repeat(6, 1fr);
    gap: 28px;
  }

  .tool-view .container {
    max-width: 2200px;
  }

  .tool-split {
    grid-template-columns: 1fr 500px;
    gap: 48px;
  }

  .kb-board {
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
  }

  .latex-editor-wrap {
    min-height: 700px;
    gap: 32px;
  }

  .compare-panels {
    gap: 32px;
  }

  #preview-modal .preview-modal-inner {
    max-width: 1500px;
  }
}

/* ===== SIGN PAD & DRAW SECTION ===== */
.sign-draw-section {
  margin-bottom: 16px;
}

.sign-draw-label {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.sign-pad {
  width: 100%;
  max-width: 500px;
  height: 160px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: crosshair;
  touch-action: none;
  display: block;
}

[data-theme="dark"] .sign-pad {
  background: #2a2d38;
}

.sign-pad-controls {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  align-items: center;
}

.sign-draw-hint {
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* --- Signature placements on PDF overlay --- */
.sig-placement {
  position: absolute;
  border: 2px solid transparent;
  border-radius: 3px;
  cursor: move;
  user-select: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  z-index: 2;
}

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

.sig-placement:hover {
  border-color: var(--primary);
}

.sig-placement.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
  z-index: 3;
}

.sig-placement-del {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: var(--danger, #ef4444);
  color: #fff;
  font-size: 11px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.sig-placement.selected .sig-placement-del,
.sig-placement:hover .sig-placement-del {
  display: flex;
}

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

.sig-placement.selected .sig-resize-handle,
.sig-placement:hover .sig-resize-handle {
  display: block;
}

/* ===== PDF VISUAL EDITOR ===== */
.pdf-editor {
  margin-top: 20px;
}

.pdf-editor-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.pdf-editor-toolbar .toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pdf-editor-toolbar .toolbar-group label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

.pdf-editor-toolbar .toolbar-page-nav {
  margin-left: auto;
}

.pdf-editor-toolbar .toolbar-page-nav span {
  font-size: 0.82rem;
  font-weight: 600;
  min-width: 60px;
  text-align: center;
}

.toolbar-color-picker {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  padding: 2px;
  background: var(--bg-card);
}

.toolbar-opacity-group {
  gap: 6px;
}

.toolbar-opacity-slider {
  width: 80px;
  height: 6px;
  cursor: pointer;
  accent-color: var(--primary);
}

.toolbar-opacity-val {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 34px;
  text-align: center;
}

.input-sm {
  height: 34px;
  padding: 4px 8px;
  font-size: 0.85rem;
}

.btn-sm {
  height: 34px;
  padding: 0 10px;
  font-size: 0.85rem;
}

.pdf-editor-canvas-wrap {
  position: relative;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  overflow: hidden;
  background: #e5e5e5;
}

[data-theme="dark"] .pdf-editor-canvas-wrap {
  background: #1e1e24;
}

.pdf-editor-canvas-wrap canvas {
  display: block;
  width: 100%;
  height: auto;
}

.pdf-editor-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  cursor: crosshair;
}

/* --- Annotations --- */
.pdf-annotation {
  position: absolute;
  cursor: move;
  user-select: none;
  padding: 2px 4px;
  border-radius: 3px;
  border: 1.5px solid transparent;
  transition: border-color 0.15s, box-shadow 0.15s;
  white-space: pre-wrap;
  line-height: 1.3;
  z-index: 2;
}

.pdf-annotation:hover {
  border-color: var(--primary);
}

.pdf-annotation.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
  z-index: 3;
}

.pdf-annotation .annotation-text {
  pointer-events: none;
}

.pdf-annotation .annotation-del {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: var(--danger, #ef4444);
  color: #fff;
  font-size: 11px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.pdf-annotation.selected .annotation-del,
.pdf-annotation:hover .annotation-del {
  display: flex;
}

.annotation-input {
  border: none;
  outline: none;
  background: rgba(255,255,255,0.85);
  font-family: inherit;
  resize: none;
  min-width: 60px;
  min-height: 1.3em;
  padding: 0;
  margin: 0;
  line-height: 1.3;
  overflow: hidden;
}

[data-theme="dark"] .annotation-input {
  background: rgba(42,45,56,0.9);
}

/* ===== ORGANIZE GRID ===== */
.organize-grid .page-thumb {
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.organize-grid .page-thumb:active:not(.drag-placeholder) {
  cursor: grabbing;
}

.organize-grid .page-thumb.drag-placeholder {
  opacity: 0.25;
  border-style: dashed;
  border-color: var(--primary);
  background: var(--primary-light, rgba(99, 102, 241, 0.06));
}

/* Floating drag clone */
.drag-clone {
  position: fixed;
  z-index: 10000;
  pointer-events: none;
  opacity: 0.92;
  transform: rotate(1.5deg) scale(1.05);
  box-shadow: 0 20px 48px rgba(0,0,0,0.28), 0 0 0 2px var(--primary);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #fff;
  transition: transform 0.12s ease;
}

[data-theme="dark"] .drag-clone {
  background: #2a2d38;
}

/* Move bar at bottom of each organize thumbnail */
.page-move-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 3px 4px;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.page-move-bar .page-pos-label {
  color: #fff;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.page-move-bar button {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: #fff;
  cursor: pointer;
  font-size: 16px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  padding: 0;
  line-height: 1;
}

.page-move-bar button:hover:not(:disabled) {
  background: var(--primary);
}

.page-move-bar button:disabled {
  opacity: 0.3;
  cursor: default;
}

/* Hide old page-num in organize grid (replaced by move bar) */
.organize-grid .page-thumb .page-num {
  display: none;
}

.page-controls {
  position: absolute;
  top: 4px;
  right: 4px;
  display: flex;
  gap: 3px;
}

.page-controls button {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 4px;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 0.7rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.page-controls button:hover {
  background: var(--primary);
}

/* ===== FILE PREVIEW MODAL ===== */
#preview-modal .preview-modal-inner {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  width: 90vw;
  max-width: 900px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  animation: fadeIn 0.25s ease;
}

.preview-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
}

.preview-modal-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.preview-modal-title span:first-child {
  font-weight: 700;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-modal-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.preview-modal-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.preview-modal-body {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  min-height: 200px;
  background: var(--bg-drop);
}

.preview-modal-body img,
.preview-modal-body canvas {
  max-width: 100%;
  max-height: calc(90vh - 120px);
  border-radius: var(--radius-sm);
  object-fit: contain;
}

.preview-modal-loader {
  color: var(--text-muted);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.preview-modal-loader::before {
  content: '';
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* Make file items clickable for preview */
.file-item-thumb,
.file-item-icon {
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.file-item-thumb:hover,
.file-item-icon:hover {
  transform: scale(1.1);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.file-item-name {
  cursor: pointer;
}

.file-item-name:hover {
  color: var(--primary);
}

@media (max-width: 600px) {
  #preview-modal .preview-modal-inner {
    width: 96vw;
    max-height: 95vh;
  }
  .preview-modal-body {
    padding: 12px;
  }
}

/* ===== COMPARE PDF ===== */
.compare-toolbar,
.redact-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.compare-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.compare-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.compare-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.compare-panel h4 {
  padding: 10px 14px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  background: var(--bg-hover);
}

.compare-panel canvas {
  width: 100%;
  display: block;
}

.compare-diff-panel {
  margin-top: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  text-align: center;
}

.compare-diff-panel h4 {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.compare-diff-panel canvas {
  max-width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

@media (max-width: 700px) {
  .compare-panels {
    grid-template-columns: 1fr;
  }
}

/* ===== REDACT PDF ===== */
.redact-canvas-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  line-height: 0;
  cursor: crosshair;
}

.redact-canvas-wrap canvas:first-child {
  max-width: 100%;
  border-radius: var(--radius-sm);
  display: block;
}

.redact-overlay-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  border-radius: var(--radius-sm);
}

/* ===== LIVE PREVIEW & SPLIT LAYOUT ===== */
.tool-split {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  margin-top: 20px;
  align-items: start;
}

.tool-split-preview {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  position: sticky;
  top: 80px;
}

.tool-split-preview h4 {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}

.tool-split-preview canvas,
.tool-split-preview img {
  max-width: 100%;
  max-height: 50vh;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  display: inline-block;
}

.tool-split-preview .split-preview-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  text-align: center;
}

.tool-split-preview .split-preview-pair canvas {
  width: 100%;
  height: auto;
}

.tool-split-preview .split-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.tool-split-controls {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.tool-split-controls .option-group {
  margin-bottom: 16px;
}

.tool-split-controls .option-group:last-child {
  margin-bottom: 0;
}

.tool-split-controls .option-group > label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

@media (max-width: 800px) {
  .tool-split {
    grid-template-columns: 1fr;
  }
  .tool-split-preview {
    position: static;
  }
}

/* Legacy single-area previews */
.live-preview-area {
  margin: 16px 0;
}

.live-preview-area canvas {
  max-width: 100%;
  max-height: 350px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  display: block;
}

.live-preview-area .preview-compare {
  margin: 0;
}

.live-preview-area .preview-panel canvas {
  max-width: 100%;
  max-height: 300px;
}

/* ===== TEXT TOOL LAYOUTS ===== */
.text-tool-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-top: 20px;
}

.text-tool-wrap .option-group {
  margin-bottom: 16px;
}

.text-tool-wrap .option-group:last-child {
  margin-bottom: 0;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.stat-card {
  background: var(--bg-drop);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  text-align: center;
}

.stat-num {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.02em;
}

.stat-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Markdown Preview */
.md-preview {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  min-height: 200px;
  max-height: 500px;
  overflow-y: auto;
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--text);
}

.md-preview h1, .md-preview h2, .md-preview h3 { margin: 16px 0 8px; font-weight: 700; }
.md-preview h1 { font-size: 1.5rem; }
.md-preview h2 { font-size: 1.25rem; }
.md-preview h3 { font-size: 1.1rem; }
.md-preview p { margin: 8px 0; }
.md-preview code { background: var(--bg-hover); padding: 2px 6px; border-radius: 4px; font-size: 0.85em; }
.md-preview pre { background: var(--bg-hover); padding: 12px; border-radius: var(--radius-sm); overflow-x: auto; }
.md-preview blockquote { border-left: 3px solid var(--primary); padding-left: 12px; color: var(--text-secondary); margin: 8px 0; }
.md-preview ul, .md-preview ol { padding-left: 24px; }
.md-preview table { border-collapse: collapse; width: 100%; margin: 8px 0; }
.md-preview th, .md-preview td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.md-preview th { background: var(--bg-hover); font-weight: 600; }

/* Color palette swatches */
.palette-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
}

.palette-swatch {
  width: 80px;
  text-align: center;
}

.palette-swatch .swatch-color {
  width: 80px;
  height: 60px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
}

.palette-swatch .swatch-label {
  font-size: 0.72rem;
  color: var(--text-secondary);
  margin-top: 4px;
  font-family: monospace;
  word-break: break-all;
}

/* Diff output */
.diff-line { padding: 2px 8px; font-family: monospace; font-size: 0.82rem; white-space: pre-wrap; }
.diff-add { background: rgba(16, 185, 129, 0.15); color: var(--success); }
.diff-remove { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.diff-same { color: var(--text-muted); }

/* ===== OCR TEXT OUTPUT ===== */
.ocr-text-output {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  max-height: 400px;
  overflow-y: auto;
  font-family: monospace;
  font-size: 0.85rem;
  white-space: pre-wrap;
  line-height: 1.6;
  margin-top: 16px;
  color: var(--text);
}

/* ===== JSON CODE EDITOR (syntax-highlighted textarea) ===== */
.json-editor {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #fafbfc;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.json-editor:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

[data-theme="dark"] .json-editor {
  background: #0f111a;
  border-color: rgba(255,255,255,0.06);
}

[data-theme="dark"] .json-editor:focus-within {
  border-color: rgba(130,170,255,0.35);
  box-shadow: 0 0 0 3px rgba(130,170,255,0.08);
}

/* Shared properties — MUST be identical for perfect overlay alignment */
.json-editor-textarea,
.json-editor-highlight {
  font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', 'JetBrains Mono', Menlo, Consolas, 'Liberation Mono', monospace;
  font-size: 13px;
  line-height: 22px;
  padding: 16px 16px 16px 54px;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
  tab-size: 2;
  margin: 0;
  border: none;
  width: 100%;
  min-height: 640px;
  letter-spacing: 0.3px;
  box-sizing: border-box;
}

/* The highlighted <pre> sits behind */
.json-editor-highlight {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  overflow: hidden;
  color: #8b949e;
  z-index: 0;
}

[data-theme="dark"] .json-editor-highlight {
  color: #636d83;
}

.json-editor-highlight code {
  display: block;
  font: inherit;
  letter-spacing: inherit;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* The textarea on top — transparent text, visible caret */
.json-editor-textarea {
  position: relative;
  z-index: 1;
  color: transparent;
  caret-color: #24292f;
  background: transparent;
  outline: none;
  resize: vertical;
  -webkit-text-fill-color: transparent;
}

[data-theme="dark"] .json-editor-textarea {
  caret-color: #ffffffcc;
}

.json-editor-textarea::placeholder {
  -webkit-text-fill-color: #a0a8b7;
  color: #a0a8b7;
}

[data-theme="dark"] .json-editor-textarea::placeholder {
  -webkit-text-fill-color: #454d61;
  color: #454d61;
}

/* Line numbers gutter — MUST match code font metrics exactly */
.json-editor-gutter {
  position: absolute;
  top: 0;
  left: 0;
  width: 42px;
  padding: 16px 10px 16px 0;
  text-align: right;
  font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', 'JetBrains Mono', Menlo, Consolas, 'Liberation Mono', monospace;
  font-size: 13px;
  line-height: 22px;
  letter-spacing: 0.3px;
  white-space: pre;
  color: #bcc3ce;
  user-select: none;
  pointer-events: none;
  z-index: 2;
  border-right: 1px solid #e8ebef;
  background: #f3f5f7;
  overflow: hidden;
  box-sizing: border-box;
}

[data-theme="dark"] .json-editor-gutter {
  color: #2a3040;
  background: rgba(0,0,0,0.2);
  border-right-color: rgba(255,255,255,0.04);
}

/* Toolbar bar above editor */
.json-editor-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.json-editor-bar-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 7px;
}

.json-editor-bar-label .jf-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.2s ease;
}

.json-editor-bar-label .jf-status-dot.valid {
  background: var(--success);
  box-shadow: 0 0 6px rgba(16,185,129,0.35);
}

.json-editor-bar-label .jf-status-dot.invalid {
  background: var(--danger);
  box-shadow: 0 0 6px rgba(239,68,68,0.35);
}

.json-editor-bar-actions {
  display: flex;
  gap: 6px;
}

.json-editor-bar .json-bar-btn {
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: var(--font);
}

.json-editor-bar .json-bar-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

/* Error line highlight bar */
.json-editor-error-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 22px;
  background: rgba(239,68,68,0.12);
  border-left: 3px solid var(--danger);
  pointer-events: none;
  z-index: 0;
  display: none;
  transition: top 0.1s ease;
}

[data-theme="dark"] .json-editor-error-line {
  background: rgba(255,83,112,0.1);
  border-left-color: #ff5370;
}

/* Error state gutter number */
.json-editor-gutter .gutter-error {
  color: var(--danger);
  font-weight: 700;
}

[data-theme="dark"] .json-editor-gutter .gutter-error {
  color: #ff5370;
}

/* Syntax tokens — Light mode (GitHub-inspired) */
.json-key { color: #0550ae; }
.json-string { color: #0a3069; }
.json-number { color: #0550ae; }
.json-boolean { color: #cf222e; }
.json-null { color: #cf222e; }
.json-bracket { color: #24292f; font-weight: 600; }
.json-punctuation { color: #6e7781; }

/* Syntax tokens — Dark mode (Material Palenight) */
[data-theme="dark"] .json-key { color: #82aaff; }
[data-theme="dark"] .json-string { color: #c3e88d; }
[data-theme="dark"] .json-number { color: #f78c6c; }
[data-theme="dark"] .json-boolean { color: #c792ea; }
[data-theme="dark"] .json-null { color: #ff5370; }
[data-theme="dark"] .json-bracket { color: #89ddff; font-weight: 600; }
[data-theme="dark"] .json-punctuation { color: #89ddff; }

/* Custom scrollbar */
.json-editor-textarea::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.json-editor-textarea::-webkit-scrollbar-track {
  background: transparent;
}

.json-editor-textarea::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.1);
  border-radius: 4px;
}

.json-editor-textarea::-webkit-scrollbar-thumb:hover {
  background: rgba(0,0,0,0.18);
}

[data-theme="dark"] .json-editor-textarea::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.08);
}

[data-theme="dark"] .json-editor-textarea::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.15);
}

/* Compact variant for smaller JSON editors (used in tools like CSV↔JSON, String↔JSON, JSON→TS) */
.json-editor-compact .json-editor-textarea,
.json-editor-compact .json-editor-highlight {
  min-height: 260px;
}

/* Read-only overlay styling — dimmer caret since it's not editable */
.json-editor-readonly .json-editor-textarea {
  cursor: default;
}
.json-editor-readonly .json-editor-textarea:focus {
  caret-color: transparent;
}

/* ===== NEW TOOLS STYLES ===== */

/* EXIF Table */
.exif-table { width: 100%; border-collapse: collapse; text-align: left; margin: 12px 0; }
.exif-table td { padding: 6px 12px; border-bottom: 1px solid var(--border); font-size: 0.85rem; }
.exif-table td:first-child { width: 40%; color: var(--text-muted); }

/* Password / UUID list */
.pw-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.pw-item { display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; }
.pw-code { flex: 1; font-family: 'Courier New', monospace; font-size: 0.85rem; word-break: break-all; color: var(--text); }

/* JWT */
.jwt-exp { padding: 8px 12px; border-radius: var(--radius-sm); font-weight: 600; margin: 8px 0; }
.jwt-exp.expired { background: rgba(239, 68, 68, 0.1); color: #ef4444; }
.jwt-exp.valid { background: rgba(16, 185, 129, 0.1); color: #10b981; }

/* Image Compare Slider */
.compare-slider-wrap { max-width: 800px; margin: 0 auto; }
.compare-slider-container { position: relative; width: 100%; overflow: hidden; border-radius: var(--radius); border: 1px solid var(--border); cursor: ew-resize; user-select: none; }
.cs-img { display: block; width: 100%; height: auto; }
.cs-img-left { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; clip-path: inset(0 50% 0 0); z-index: 2; }
.cs-img-right { display: block; width: 100%; height: auto; }
.cs-handle { position: absolute; top: 0; bottom: 0; left: 50%; width: 4px; background: #fff; z-index: 3; transform: translateX(-50%); cursor: ew-resize; }
.cs-handle-line { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 32px; height: 32px; background: #fff; border-radius: 50%; border: 2px solid var(--primary); display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 8px rgba(0,0,0,0.2); }
.cs-handle-line::before { content: '◄ ►'; font-size: 10px; color: var(--primary); }

/* Gradient Preview */
.gradient-preview { width: 100%; height: 200px; border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 16px; }

/* Box Shadow Preview */
.shadow-preview-wrap { display: flex; justify-content: center; padding: 40px; background: var(--bg); border-radius: var(--radius); margin-bottom: 16px; }
.shadow-preview-box { width: 200px; height: 200px; background: var(--bg-card); border-radius: var(--radius); border: 1px solid var(--border); }

/* ASCII Art Output */
.ascii-output { font-family: 'Courier New', monospace; font-size: 5px; line-height: 6px; letter-spacing: 1px; overflow-x: auto; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; max-height: 500px; overflow-y: auto; white-space: pre; }

/* ===== BATCH 3 STYLES ===== */

/* Color Contrast Preview */
.contrast-preview { padding: 24px; border-radius: var(--radius); margin: 16px 0; text-align: center; border: 1px solid var(--border); }

/* Pattern Preview */
.pattern-preview { width: 100%; height: 200px; border-radius: var(--radius); border: 1px solid var(--border); margin: 16px 0; }

/* Emoji Grid */
.emoji-grid { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 12px; max-height: 400px; overflow-y: auto; }
.emoji-item { font-size: 28px; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; cursor: pointer; border-radius: var(--radius-sm); transition: background 0.15s; }
.emoji-item:hover { background: var(--primary-glow); }

/* Typing Test */
.tt-passage { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 16px; margin-bottom: 12px; font-size: 1.1rem; line-height: 1.7; min-height: 80px; color: var(--text); }

/* Email Signature Preview */
.sig-preview-box { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 20px; margin: 16px 0; color: #333; }

/* Pomodoro */
.pom-display { font-size: 5rem; font-weight: 800; letter-spacing: 4px; color: var(--primary); font-family: 'Courier New', monospace; }
.pom-label { font-size: 1.1rem; color: var(--text-muted); margin-bottom: 8px; }

/* Sticky Notes */
.sn-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.sn-note { border-radius: var(--radius-sm); padding: 4px; position: relative; box-shadow: 2px 2px 8px rgba(0,0,0,0.1); }
.sn-text { width: 100%; min-height: 120px; border: none; background: transparent; resize: vertical; font-family: inherit; font-size: 0.85rem; padding: 8px; }
.sn-del { position: absolute; top: 4px; right: 4px; background: none; border: none; cursor: pointer; font-size: 16px; color: #999; }
.sn-del:hover { color: #e00; }

/* Font Preview */
.fp-grid { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.fp-item { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 16px; }
.fp-font-name { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.fp-sample { line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }

/* Habit Tracker */
.ht-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.ht-table th, .ht-table td { padding: 8px; text-align: center; border-bottom: 1px solid var(--border); }
.ht-table th { font-size: 0.75rem; color: var(--text-muted); font-weight: 600; }
.ht-habit-name { text-align: left !important; font-weight: 600; }
.ht-cell { cursor: pointer; }
.ht-check { width: 20px; height: 20px; accent-color: var(--primary); cursor: pointer; }

/* Kanban Board */
.kb-board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; min-height: 300px; }
.kb-col { background: var(--bg); border-radius: var(--radius-sm); padding: 12px; border: 1px solid var(--border); }
.kb-col-title { font-size: 0.85rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin: 0 0 12px; padding-bottom: 8px; border-bottom: 2px solid var(--primary); }
.kb-cards { min-height: 60px; display: flex; flex-direction: column; gap: 8px; }
.kb-cards.kb-drop-hover { background: var(--primary-glow); border-radius: var(--radius-sm); }
.kb-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; cursor: grab; display: flex; align-items: center; justify-content: space-between; transition: box-shadow 0.15s, transform 0.15s; }
.kb-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.kb-card.dragging { opacity: 0.5; transform: rotate(2deg); }
.kb-card-text { font-size: 0.85rem; flex: 1; }
.kb-card-del { background: none; border: none; cursor: pointer; font-size: 16px; color: #999; padding: 0 0 0 8px; }
.kb-card-del:hover { color: #e00; }
@media (max-width: 640px) { .kb-board { grid-template-columns: 1fr; } }

/* LaTeX Editor */
.latex-editor-wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; min-height: 500px; }
@media (max-width: 768px) { .latex-editor-wrap { grid-template-columns: 1fr; } }
.latex-pane { display: flex; flex-direction: column; }
.latex-textarea { font-family: 'Courier New', Consolas, monospace; font-size: 0.85rem; line-height: 1.6; resize: vertical; flex: 1; min-height: 400px; tab-size: 2; }
.latex-preview { background: #fff; color: #1a1a2e; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 32px 40px; flex: 1; overflow-y: auto; font-family: Georgia, 'Times New Roman', serif; font-size: 12pt; line-height: 1.7; min-height: 400px; max-height: 600px; }
.latex-preview h1.latex-title { font-size: 1.8rem; text-align: center; margin: 0 0 4px; }
.latex-preview .latex-author { text-align: center; font-size: 1rem; color: #555; margin-bottom: 4px; }
.latex-preview .latex-date { text-align: center; font-size: 0.9rem; color: #777; margin-bottom: 24px; }
.latex-preview h2.latex-section { font-size: 1.3rem; margin: 24px 0 8px; border-bottom: 1px solid #ddd; padding-bottom: 4px; }
.latex-preview h3.latex-subsection { font-size: 1.1rem; margin: 16px 0 6px; }
.latex-preview h4.latex-subsubsection { font-size: 1rem; margin: 12px 0 4px; font-style: italic; }
.latex-preview ul, .latex-preview ol { margin: 8px 0 8px 24px; }
.latex-preview li { margin-bottom: 4px; }
.latex-preview blockquote { border-left: 3px solid #6366f1; padding-left: 16px; margin: 12px 0; color: #555; font-style: italic; }
.latex-preview pre.latex-verbatim { background: #f5f5f5; padding: 12px; border-radius: 4px; font-family: 'Courier New', monospace; font-size: 0.85rem; overflow-x: auto; }
.latex-preview code { background: #f0f0f0; padding: 1px 4px; border-radius: 3px; font-family: 'Courier New', monospace; font-size: 0.9em; }
.latex-preview hr.latex-pagebreak { border: none; border-top: 2px dashed #ccc; margin: 24px 0; }
.latex-preview mjx-container { margin: 12px 0 !important; }
.latex-preview p { margin: 0 0 10px; }
.latex-preview .latex-figure { margin: 16px 0; text-align: center; }
.latex-preview .latex-figure img { max-width: 100%; height: auto; border-radius: 4px; }
.latex-preview .latex-figure .latex-caption { font-size: 0.9em; color: #555; margin-top: 6px; font-style: italic; }
.latex-preview img.latex-img { max-width: 100%; height: auto; display: block; margin: 12px auto; border-radius: 4px; }