:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface-2: #1f1f1f;
  --border: #2a2a2a;
  --text: #e8e8e8;
  --text-dim: #888;
  --accent: #ff6b35;
  --accent-dim: #ff6b3520;
  --success: #4ade80;
  --danger: #ef4444;
  --radius: 10px;
  --font: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding: 20px;
  max-width: 720px;
  margin: 0 auto;
}

/* --- Header --- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

h1 {
  font-family: var(--font);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--accent);
}

.security-badge {
  display: inline-flex;
  align-items: center;
  font-family: var(--font);
  font-size: 10px;
  color: var(--success);
  padding: 3px 8px;
  background: #4ade8015;
  border: 1px solid #4ade8030;
  border-radius: 4px;
}

.usage-badge {
  font-family: var(--font);
  font-size: 11px;
  color: var(--text-dim);
  padding: 3px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.settings-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
}

.settings-btn:hover { color: var(--text); }

/* --- Tool Tabs (top-level) --- */
.tool-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  padding: 4px;
  border-radius: var(--radius);
  margin-bottom: 20px;
}

.tool-tab {
  flex: 1;
  padding: 10px 12px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.15s;
}

.tool-tab.active {
  background: var(--surface-2);
  color: var(--text);
}

.tool-tab:hover:not(.active) { color: var(--text); }

/* --- Tool Panels --- */
.tool-panel { display: none; }
.tool-panel.active { display: block; }

/* --- Drop Zone --- */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--surface);
  display: block;
}

.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.drop-zone-icon { font-size: 36px; margin-bottom: 8px; display: block; }
.drop-zone-text { font-size: 14px; color: var(--text-dim); }
.drop-zone-text strong { color: var(--text); font-weight: 500; }
.drop-zone-sub { font-size: 12px; color: var(--text-dim); margin-top: 4px; font-family: var(--font); }

#file-input,
#merge-file-input,
#image-file-input { display: none; }

/* --- File Info --- */
.file-info {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 16px;
  display: none;
}

.file-info.active { display: block; }
.file-info-name { font-weight: 500; word-break: break-all; margin-bottom: 8px; }

.file-info-meta {
  font-family: var(--font);
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.file-info-meta span::before { content: '·'; color: var(--accent); margin-right: 6px; }

/* --- Split Mode Tabs --- */
.tabs {
  display: flex;
  gap: 4px;
  margin-top: 24px;
  background: var(--surface);
  padding: 4px;
  border-radius: var(--radius);
}

.tab {
  flex: 1;
  padding: 10px 12px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.15s;
}

.tab.active { background: var(--surface-2); color: var(--text); }

/* --- Panels --- */
.panel {
  display: none;
  margin-top: 16px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.panel.active { display: block; }
.panel-desc { font-size: 13px; color: var(--text-dim); margin-bottom: 12px; }

/* --- AI Preset --- */
.preset-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.preset-label { font-size: 13px; color: var(--text-dim); white-space: nowrap; }
.preset-select { flex: 1; }

/* --- Inputs --- */
.input-row { display: flex; gap: 8px; align-items: stretch; }

.input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 6px;
  font-family: var(--font);
  font-size: 14px;
  width: 100%;
}

.input:focus { outline: none; border-color: var(--accent); }

select.input {
  cursor: pointer;
  appearance: auto;
}

.input-unit {
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
}

textarea.input { resize: vertical; min-height: 80px; line-height: 1.6; }
.hint { font-size: 11px; color: var(--text-dim); margin-top: 6px; font-family: var(--font); }

/* --- Buttons --- */
.btn {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 20px;
  transition: all 0.15s;
  letter-spacing: 0.02em;
}

.btn:hover:not(:disabled) { background: #ff7a47; transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { background: var(--surface-2); color: var(--text-dim); cursor: not-allowed; }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  margin-top: 8px;
  font-size: 13px;
  padding: 10px;
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface);
  border-color: var(--danger);
  color: var(--danger);
  transform: none;
}

/* --- Results --- */
.results { margin-top: 24px; }

.bulk-actions { display: flex; gap: 8px; margin-bottom: 12px; }

.bulk-actions .dl-btn {
  flex: 1;
  padding: 12px;
  font-size: 13px;
  text-align: center;
}

.dl-folder {
  background: var(--surface-2);
  border: 1px solid var(--success);
  color: var(--success);
}

.dl-folder:hover { background: var(--success); color: #000; }

.result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  gap: 12px;
}

.result-name {
  font-family: var(--font);
  font-size: 13px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-meta { font-family: var(--font); font-size: 11px; color: var(--text-dim); }

.dl-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 6px;
  font-family: var(--font);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.dl-btn:hover { border-color: var(--accent); color: var(--accent); }

.dl-all {
  background: var(--surface-2);
  border: 1px solid var(--accent);
  color: var(--accent);
}

.dl-all:hover { background: var(--accent); color: #000; }

/* --- Status --- */
.status {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-family: var(--font);
  display: none;
}

.status.active { display: block; }
.status.success { background: #4ade8015; color: var(--success); border: 1px solid #4ade8030; }
.status.error { background: #ef444415; color: var(--danger); border: 1px solid #ef444430; }
.status.info { background: var(--surface-2); color: var(--text-dim); border: 1px solid var(--border); }

/* --- Merge / Image file list --- */
.merge-file-list { margin-top: 12px; }

.merge-file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 4px;
  cursor: grab;
  transition: background 0.15s;
}

.merge-file-item.dragging { opacity: 0.4; }

.merge-file-item.drag-over {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.merge-grip {
  color: var(--text-dim);
  font-size: 16px;
  cursor: grab;
  user-select: none;
}

.merge-file-name {
  flex: 1;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.merge-file-size {
  font-family: var(--font);
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}

.merge-remove {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.merge-remove:hover { color: var(--danger); }

/* --- Image thumbnail --- */
.image-thumb {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}

/* --- Image options --- */
.image-options {
  margin-top: 16px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.option-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.option-row:last-child { margin-bottom: 0; }

.option-row label {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
}

.option-row .input {
  width: auto;
  flex: 0 1 auto;
  min-width: 140px;
}

/* --- Modal --- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 90%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { font-size: 16px; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.modal-close:hover { color: var(--text); }

.modal-body { padding: 20px; }

.settings-section { margin-bottom: 24px; }
.settings-section:last-child { margin-bottom: 0; }

.settings-section h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

.settings-row:last-child { border-bottom: none; }

/* --- Preview Grid --- */
.pdf-preview-container { margin: 16px 0; }

.preview-select-all {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}

.preview-card {
  position: relative;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.preview-card.selected { border-color: var(--accent); }

.preview-canvas {
  width: 100%;
  aspect-ratio: 210 / 297;
  object-fit: contain;
  display: block;
  border-radius: 4px;
  background: #fff;
}

.preview-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  gap: 4px;
}

.preview-label {
  font-size: 11px;
  color: var(--text-dim);
  flex: 1;
  text-align: center;
}

.preview-rot-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 14px;
  width: 26px;
  height: 26px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s, color 0.15s;
}

.preview-rot-btn:hover {
  background: var(--border);
  color: var(--text);
}

.preview-cb {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.btn-extract {
  margin-top: 12px;
  background: var(--border);
  color: var(--text);
  border: none;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 20px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
}

.btn-extract:hover { background: var(--accent); color: #fff; }
.btn-extract:disabled { opacity: 0.4; cursor: default; }

/* --- Progress Bar --- */
.progress-container { margin: 12px 0; }

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.2s ease;
}

.progress-text {
  font-family: var(--font);
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
  text-align: center;
}

/* --- Modal Small --- */
.modal-sm { max-width: 360px; }

/* --- Footer --- */
footer {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-family: var(--font);
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
}

.footer-sub { font-size: 10px; margin-top: 4px; display: inline-block; }

/* --- Responsive --- */
@media (max-width: 480px) {
  body { padding: 12px; }
  .drop-zone { padding: 28px 16px; }
  .tool-tab { font-size: 12px; padding: 9px 8px; }
  .tab { font-size: 12px; padding: 9px 8px; }
  .bulk-actions { flex-direction: column; }
  .option-row { flex-direction: column; align-items: stretch; gap: 4px; }
  .option-row .input { min-width: 0; }
}
