/* ============================================================
   PDF Merger – Main Stylesheet
   Design tokens → base styles → layout → components → dark mode
   ============================================================ */

/* ── Design tokens (CSS custom properties) ─────────────────── */
:root {
  /* Brand colours */
  --primary:        #4f46e5;
  --primary-hover:  #4338ca;
  --primary-light:  #ede9fe;
  --danger:         #ef4444;
  --danger-hover:   #dc2626;
  --success:        #22c55e;
  --warning:        #f59e0b;

  /* Neutral palette */
  --bg:             #f8fafc;
  --surface:        #ffffff;
  --surface-raised: #f1f5f9;
  --border:         #e2e8f0;
  --border-focus:   #a5b4fc;
  --text-primary:   #0f172a;
  --text-secondary: #64748b;
  --text-muted:     #94a3b8;

  /* Typography */
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;

  /* Sizing */
  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow:    0 4px 6px -1px rgb(0 0 0 / 0.08), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 10px 24px -4px rgb(0 0 0 / 0.12), 0 4px 8px -4px rgb(0 0 0 / 0.06);

  /* Transitions */
  --transition: 180ms ease;
}

/* Dark mode tokens */
.dark-mode {
  --bg:             #0f172a;
  --surface:        #1e293b;
  --surface-raised: #293548;
  --border:         #334155;
  --border-focus:   #818cf8;
  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:     #64748b;
  --primary-light:  #1e1b4b;
  --shadow-sm:      0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow:         0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.3);
  --shadow-lg:      0 10px 24px -4px rgb(0 0 0 / 0.5), 0 4px 8px -4px rgb(0 0 0 / 0.4);
}

/* ── Reset / Base ───────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

h1, h2, h3 {
  line-height: 1.25;
  font-weight: 700;
}

button { cursor: pointer; }
input, button { font-family: inherit; }
a { color: var(--primary); }

/* ── Layout ─────────────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(8px);
  transition: background var(--transition), border-color var(--transition);
}

.header-content {
  max-width: 900px;
  margin: 0 auto;
  padding: 0.875rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--primary);
}

.logo-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.app-main {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.app-footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.8125rem;
  border-top: 1px solid var(--border);
}

/* ── Hero ────────────────────────────────────────────────────── */
.hero {
  text-align: center;
  padding: 1rem 0 0.5rem;
}

.hero h1 {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  color: var(--text-primary);
  margin-bottom: 0.75rem;
}

.hero-subtitle {
  font-size: 1rem;
  color: var(--text-secondary);
  max-width: 560px;
  margin: 0 auto;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition),
              box-shadow var(--transition), opacity var(--transition),
              transform 80ms ease;
  user-select: none;
}

.btn:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.btn:active:not(:disabled) { transform: scale(0.97); }

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

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

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

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

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: none;
  padding: 0.375rem;
  border-radius: var(--radius-sm);
}

.btn-danger:hover {
  background: #fef2f2;
  color: var(--danger-hover);
}

.dark-mode .btn-danger:hover {
  background: #450a0a;
}

.btn-icon {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 0.5rem;
  border-radius: var(--radius);
}

.btn-icon:hover {
  background: var(--surface-raised);
  color: var(--text-primary);
}

.btn-sm {
  font-size: 0.8125rem;
  padding: 0.375rem 0.75rem;
}

.btn-lg {
  padding: 0.75rem 2rem;
  font-size: 1rem;
  border-radius: var(--radius-lg);
}

/* ── Drop Zone ───────────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  padding: 3rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition),
              box-shadow var(--transition);
  outline: none;
}

.drop-zone:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: var(--shadow);
}

.drop-zone-icon {
  width: 72px;
  height: 72px;
  color: var(--primary);
  opacity: 0.85;
  transition: transform var(--transition);
}

.drop-zone:hover .drop-zone-icon,
.drop-zone.drag-over .drop-zone-icon {
  transform: translateY(-4px);
}

.drop-zone-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
}

.drop-zone-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: -0.25rem;
}

.drop-zone-hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Hidden file input */
#fileInput {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* ── Message Banner ─────────────────────────────────────────── */
.message-banner {
  border-radius: var(--radius);
  padding: 0.875rem 1.25rem;
  font-size: 0.9375rem;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  animation: slideIn 200ms ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message-banner.error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
}

.dark-mode .message-banner.error {
  background: #450a0a;
  border-color: #7f1d1d;
  color: #fca5a5;
}

.message-banner.success {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}

.dark-mode .message-banner.success {
  background: #052e16;
  border-color: #166534;
  color: #86efac;
}

.message-banner.info {
  background: var(--primary-light);
  border: 1px solid #c7d2fe;
  color: #3730a3;
}

.dark-mode .message-banner.info {
  border-color: #3730a3;
  color: #a5b4fc;
}

/* ── File List Section ───────────────────────────────────────── */
.file-list-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  transition: background var(--transition), border-color var(--transition);
}

.file-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.file-list-header h2 {
  font-size: 1.125rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 0.375rem;
  background: var(--primary);
  color: #fff;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.drag-hint {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* ── File List Items ─────────────────────────────────────────── */
.file-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: box-shadow var(--transition), background var(--transition),
              transform 120ms ease;
  user-select: none;
}

.file-item:hover {
  box-shadow: var(--shadow-sm);
}

/* SortableJS drag state */
.file-item.sortable-chosen {
  box-shadow: var(--shadow-lg);
  opacity: 0.9;
}

.file-item.sortable-ghost {
  opacity: 0.4;
  background: var(--primary-light);
  border-color: var(--primary);
}

.file-item.sortable-drag {
  box-shadow: var(--shadow-lg);
}

.drag-handle {
  color: var(--text-muted);
  cursor: grab;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 0 2px;
  touch-action: none;
}

.drag-handle:active { cursor: grabbing; }

.drag-handle svg { pointer-events: none; }

.file-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  background: var(--primary-light);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
}

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

.file-name {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-meta {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.file-item-actions {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-shrink: 0;
}

.btn-preview {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 0.375rem 0.625rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}

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

/* ── Progress Bar ────────────────────────────────────────────── */
.progress-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem;
  background: var(--surface-raised);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.progress-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
}

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

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), #818cf8);
  border-radius: 999px;
  transition: width 150ms ease;
}

/* ── Merge Actions ───────────────────────────────────────────── */
.merge-actions {
  display: flex;
  justify-content: center;
  padding-top: 0.5rem;
}

/* ── Modal / Preview ─────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgb(0 0 0 / 0.6);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 840px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: scaleIn 200ms ease;
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 1rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: calc(100% - 48px);
}

.modal-body {
  flex: 1;
  overflow: hidden;
  min-height: 400px;
}

#previewFrame {
  width: 100%;
  height: 100%;
  min-height: 400px;
  border: none;
  display: block;
}

/* ── Theme Toggle Icons ─────────────────────────────────────── */
.icon-moon { display: none; }

.dark-mode .icon-sun  { display: none; }
.dark-mode .icon-moon { display: block; }

.btn-icon svg {
  width: 18px;
  height: 18px;
}

/* ── Utility ─────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 600px) {
  .app-main    { padding: 1.25rem 1rem 3rem; }
  .drop-zone   { padding: 2rem 1.25rem; }
  .file-item   { flex-wrap: wrap; }
  .btn-preview { display: none; } /* hide preview on small screens */
  .btn-lg      { width: 100%; }
}
