/* ═══════════════════════════════════════════
   CSS VARIABLES & RESET
═══════════════════════════════════════════ */

:root {
  /* Colors */
  --bg-base:        #ebebeb;
  --bg-surface:     #f5f5f5;
  --bg-raised:      #ffffff;
  --bg-hover:       #e2e2e2;
  --bg-active:      #d4d4d4;

  --border:         #d0d0d0;
  --border-subtle:  #e0e0e0;

  --text-primary:   #1c1c1c;
  --text-secondary: #585858;
  --text-muted:     #9a9a9a;

  --accent:         #1a6ed4;        /* blue */
  --accent-dim:     #1558b0;
  --accent-glow:    rgba(26, 110, 212, 0.10);

  --danger:         #d4373e;
  --danger-dim:     rgba(212, 55, 62, 0.10);

  --selected-ring:  #1a6ed4;
  --grouped-ring:   #2a9d5c;        /* green for grouped state */

  /* Typography */
  --font-display:   -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono:      'Consolas', 'Menlo', 'Monaco', monospace;

  /* Spacing */
  --header-h:       52px;
  --toolbar-h:      48px;
  --strip-w:        220px;
  --strip-min-w:    140px;
  --strip-max-w:    360px;

  /* Thumbnail sizes */
  --thumb-w-s:      80px;
  --thumb-w-m:      120px;
  --thumb-w-l:      160px;
  --thumb-w:        var(--thumb-w-m);

  /* Radii */
  --radius-sm:      4px;
  --radius-md:      8px;
  --radius-lg:      12px;

  /* Transitions */
  --ease:           cubic-bezier(0.16, 1, 0.3, 1);
  --t-fast:         120ms;
  --t-mid:          220ms;
  --t-slow:         380ms;

  /* Shadows */
  --shadow-sm:      0 1px 3px rgba(0,0,0,0.12);
  --shadow-md:      0 4px 16px rgba(0,0,0,0.15);
  --shadow-lg:      0 12px 40px rgba(0,0,0,0.20);
}

/* Thumbnail size variants */
body[data-thumb-size="s"] { --thumb-w: var(--thumb-w-s); }
body[data-thumb-size="m"] { --thumb-w: var(--thumb-w-m); }
body[data-thumb-size="l"] { --thumb-w: var(--thumb-w-l); }

/* ═══════════════════════════════════════════
   RESET
═══════════════════════════════════════════ */

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

/* Ensure HTML hidden attribute always wins over CSS display rules */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  data-thumb-size: m;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input {
  font-family: var(--font-mono);
  color: inherit;
}

/* ═══════════════════════════════════════════
   APP SHELL
═══════════════════════════════════════════ */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ═══════════════════════════════════════════
   HEADER
═══════════════════════════════════════════ */

.app-header {
  height: var(--header-h);
  background: var(--bg-surface);
  position: relative;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  z-index: 10;
}

.app-header__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  margin: -4px -8px;
  transition: background var(--t-fast);
}

.app-header__brand:hover {
  background: var(--bg-hover);
}

.brand-mark {
  width: 38px;
  height: 38px;
  object-fit: cover;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.30);
  transition: box-shadow var(--t-fast);
}

.app-header__brand:hover .brand-mark {
  box-shadow: 0 2px 8px rgba(140,100,0,0.45);
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.app-header__notice {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  letter-spacing: 0.02em;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.app-header__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-copyright {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  margin-right: 4px;
}

/* ═══════════════════════════════════════════
   BUTTONS
═══════════════════════════════════════════ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  transition: background var(--t-fast) var(--ease),
              color var(--t-fast) var(--ease),
              opacity var(--t-fast);
}

.btn--primary {
  background: linear-gradient(135deg, #1a6ed4 0%, #2a9fd8 60%, #38c6e8 100%);
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.20);
}

.btn--primary:hover {
  background: linear-gradient(135deg, #1558b0 0%, #1a80bc 60%, #22a8cc 100%);
}

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

.btn--ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--bg-active);
}

.btn--danger {
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid transparent;
}

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

.btn--teal {
  background: linear-gradient(135deg, #b84a08 0%, #e08010 60%, #f0a820 100%);
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.25);
}

.btn--teal:hover {
  background: linear-gradient(135deg, #9a3e06 0%, #c87010 60%, #d99018 100%);
}

.btn:disabled {
  opacity: 0.35;
  pointer-events: none;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: background var(--t-fast), color var(--t-fast);
}

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

.icon-btn:disabled {
  opacity: 0.3;
  pointer-events: none;
}

/* ═══════════════════════════════════════════
   EMPTY STATE
═══════════════════════════════════════════ */

.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-state__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  animation: fadeUp 0.5s var(--ease) both;
}

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

.empty-state__title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.empty-state__sub {
  color: var(--text-secondary);
  font-size: 17px;
  width: 420px;
  line-height: 1.6;
}

/* ═══════════════════════════════════════════
   WORKSPACE
═══════════════════════════════════════════ */

.workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: fadeIn 0.3s var(--ease) both;
}

.workspace__content {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* ═══════════════════════════════════════════
   RESIZE HANDLE
═══════════════════════════════════════════ */

.resize-handle {
  width: 4px;
  background: var(--border-subtle);
  cursor: col-resize;
  flex-shrink: 0;
  transition: background var(--t-fast);
  position: relative;
  z-index: 5;
}

.resize-handle:hover,
.resize-handle.dragging {
  background: var(--accent);
}

/* ═══════════════════════════════════════════
   DROP OVERLAY
═══════════════════════════════════════════ */

.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 15, 0.88);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-mid) var(--ease);
  backdrop-filter: blur(4px);
}

.drop-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.drop-overlay__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--accent);
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.05em;
  border: 2px dashed var(--accent);
  border-radius: var(--radius-lg);
  padding: 60px 80px;
  animation: pulse 1.6s ease-in-out infinite;
}

/* ═══════════════════════════════════════════
   DIALOG
═══════════════════════════════════════════ */

.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(3px);
  animation: fadeIn var(--t-mid) var(--ease) both;
}

.dialog {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 320px;
  box-shadow: var(--shadow-lg);
  animation: scaleIn var(--t-mid) var(--ease) both;
}

.dialog__title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.dialog__sub {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 20px;
  line-height: 1.5;
}

.dialog__sub strong {
  color: var(--accent);
}

.dialog__options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.dialog-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  transition: background var(--t-fast), border-color var(--t-fast);
}

.dialog-option:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  color: var(--accent);
}

.dialog-option__icon {
  font-size: 16px;
  width: 24px;
  text-align: center;
  color: var(--accent);
}

.dialog__cancel {
  width: 100%;
  padding: 9px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
  transition: color var(--t-fast);
}

.dialog__cancel:hover {
  color: var(--text-secondary);
}

/* ═══════════════════════════════════════════
   EMPTY STATE — ACTIONS ROW
═══════════════════════════════════════════ */

.empty-state__actions {
  display: flex;
  gap: 16px;
  width: 420px;
}

.empty-state__actions .btn {
  flex: 1;
  justify-content: center;
  padding: 16px 28px;
  font-size: 17px;
  border-radius: 50px;
}

/* ═══════════════════════════════════════════
   DIALOG — WIDE VARIANT
═══════════════════════════════════════════ */

.dialog--wide {
  width: 92vw;
}

/* ═══════════════════════════════════════════
   BATCH MERGE DIALOG
═══════════════════════════════════════════ */

.batch-file-list {
  max-height: min(55vh, 560px);
  overflow-y: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  background: var(--bg-surface);
}

.batch-empty-hint {
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.batch-file-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-raised);
  transition: background var(--t-fast);
  outline: none;
  cursor: grab;
  user-select: none;
}

.batch-file-row:active {
  cursor: grabbing;
}

.batch-file-row:last-child {
  border-bottom: none;
}

.batch-file-row:hover,
.batch-file-row:focus {
  background: var(--bg-hover);
}

.batch-file-row:focus {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.batch-row--ghost {
  opacity: 0.4;
}

/* Filename — takes all remaining space */
.batch-row__name {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 14px;
  color: var(--text-primary);
}

/* Page count — fixed column */
.batch-row__pages {
  flex-shrink: 0;
  width: 72px;
  text-align: right;
  font-size: 13px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

/* Arrow buttons — salient, bordered, horizontal */
.batch-row__arrows {
  display: flex;
  flex-direction: row;
  gap: 4px;
  flex-shrink: 0;
}

.batch-row__arrow {
  width: 36px;
  height: 36px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}

.batch-row__arrow:hover:not(:disabled) {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.batch-row__arrow:disabled {
  opacity: 0.22;
  pointer-events: none;
}

/* Trash button */
.batch-row__remove {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast), color var(--t-fast);
}

.batch-row__remove:hover {
  background: var(--danger-dim);
  color: var(--danger);
}

/* ═══════════════════════════════════════════
   BATCH PREVIEW POPUP
═══════════════════════════════════════════ */

.batch-preview-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  z-index: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  animation: fadeIn var(--t-mid) var(--ease) both;
}

.batch-preview-box {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 20px;
  width: min(480px, 88vw);
  animation: scaleIn var(--t-mid) var(--ease) both;
}

.batch-preview-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.batch-preview-name {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--text-primary);
}

.batch-preview-pages {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.batch-preview-close {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast), color var(--t-fast);
}

.batch-preview-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.batch-preview-image {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: center;
}

.batch-preview-image img {
  max-width: 100%;
  max-height: 60vh;
  object-fit: contain;
  box-shadow: var(--shadow-md);
  display: block;
  margin: 0 auto;
}

.batch-preview-label {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 10px;
}

.batch-actions {
  margin-bottom: 20px;
}

.dialog__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.dialog__footer .dialog__cancel {
  width: auto;
  padding: 7px 14px;
}

/* ═══════════════════════════════════════════
   KEYFRAMES
═══════════════════════════════════════════ */

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

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

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

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

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

/* ═══════════════════════════════════════════
   EXPORT DIALOG
═══════════════════════════════════════════ */

.dialog--export {
  width: min(560px, 92vw);
}

.export-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  margin: 14px 0 0;
  color: var(--text-primary);
}

.export-toggle input[type="checkbox"] {
  width: 15px;
  height: 15px;
  cursor: pointer;
  accent-color: var(--accent);
}

#export-number-opts {
  margin-top: 12px;
  padding: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.export-opt-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.export-opt-row select {
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-raised);
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
}

.export-opt-row--mode {
  width: 100%;
  flex-wrap: nowrap;
}

.export-mode-options {
  display: flex;
  gap: 14px;
}

.export-mode-options label {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
}

.export-mode-options input[type="radio"] {
  cursor: pointer;
  accent-color: var(--accent);
}

.export-mode-help-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin-left: 5px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--accent-glow);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: bold;
  cursor: pointer;
  vertical-align: middle;
  line-height: 1;
  padding: 0;
  transition: background 0.15s, color 0.15s;
}
.export-mode-help-btn:hover,
.export-mode-help-btn[aria-expanded="true"] {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.export-mode-help-panel {
  margin-top: 6px;
  padding: 8px 10px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
}
.export-mode-help-panel p {
  margin: 0;
}
.export-mode-help-panel p + p {
  margin-top: 3px;
}

#export-preview-area {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 12px;
}

#export-preview-area canvas {
  max-width: 47%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

/* ═══════════════════════════════════════════
   PAGE NUMBER BADGE (header)
═══════════════════════════════════════════ */

.pagenumber-badge {
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--accent);
  color: #ffffff;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
