:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --border: #e6e8f0;
  --border-strong: #d5d9e6;
  --text: #1c2033;
  --text-2: #5a6076;
  --text-3: #8b91a6;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --accent-hover: #4338ca;
  --success: #12a150;
  --danger: #e5484d;
  --warning: #b7791f;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(24, 28, 49, .04), 0 8px 24px rgba(24, 28, 49, .06);
  --shadow-sm: 0 1px 2px rgba(24, 28, 49, .06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 20px 40px;
}

/* ---------- Header ---------- */
.app-header { margin-bottom: 20px; }

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

.brand-icon {
  width: 44px; height: 44px;
  flex: 0 0 44px;
  border-radius: 12px;
  background: linear-gradient(140deg, #6366f1, #4f46e5);
  color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 6px 16px rgba(79, 70, 229, .28);
}
.brand-icon svg { width: 24px; height: 24px; }

.brand-text h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: .2px;
}
.brand-text p {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-2);
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}

.tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 550;
  font-family: inherit;
  cursor: pointer;
  transition: background .18s, color .18s;
}
.tab svg { width: 17px; height: 17px; }
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(79, 70, 229, .14);
}

/* ---------- Panels ---------- */
.panel { display: none; animation: fade .22s ease; }
.panel.is-active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

/* ---------- Dropzone ---------- */
.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 30px 18px;
  text-align: center;
  cursor: pointer;
  transition: border-color .18s, background .18s, transform .18s;
  outline: none;
}
.dropzone:hover { border-color: var(--accent); background: #fafaff; }
.dropzone:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 70, 229, .14); }
.dropzone.is-dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: scale(1.005);
}
.dz-icon {
  width: 46px; height: 46px;
  margin: 0 auto 10px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--accent);
  display: grid; place-items: center;
}
.dz-icon svg { width: 22px; height: 22px; }
.dz-title { margin: 0; font-size: 15px; font-weight: 550; }
.dz-sub { margin: 4px 0 0; font-size: 12.5px; color: var(--text-3); }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.field { display: flex; flex-direction: column; gap: 5px; min-width: 130px; }
.field > span { font-size: 12px; color: var(--text-2); font-weight: 550; }
.field > span b { color: var(--accent); font-weight: 650; }
.field-narrow { min-width: 150px; max-width: 200px; }
.field-range { min-width: 160px; }

select, input[type="text"] {
  appearance: none;
  height: 36px;
  padding: 0 30px 0 11px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: #fff url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%235a6076' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>") no-repeat right 9px center;
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
input[type="text"] { background: #fff; padding-right: 11px; cursor: text; }
select:focus, input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .13);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 36px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 5px; border-radius: 999px; background: var(--border-strong);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px; margin-top: -5.5px;
  border-radius: 50%; background: var(--accent);
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(24, 28, 49, .25);
}
input[type="range"]::-moz-range-track { height: 5px; border-radius: 999px; background: var(--border-strong); }
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border: 2px solid #fff; border-radius: 50%;
  background: var(--accent); box-shadow: 0 1px 4px rgba(24, 28, 49, .25);
}

.toolbar-actions { display: flex; gap: 8px; margin-left: auto; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 15px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 550;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, opacity .15s;
}
.btn:hover:not(:disabled) { background: var(--surface-2); border-color: #c3c8da; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 2px 8px rgba(79, 70, 229, .22);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-sm { height: 30px; padding: 0 11px; font-size: 12.5px; border-radius: 8px; }
.btn.is-loading { pointer-events: none; opacity: .7; }
.btn svg { width: 15px; height: 15px; }

/* ---------- Progress ---------- */
.progress { margin-top: 14px; display: flex; align-items: center; gap: 12px; }
.progress-bar {
  flex: 1;
  height: 7px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}
.progress-bar > i {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #6366f1, #4f46e5);
  transition: width .25s ease;
}
.progress-text { font-size: 12.5px; color: var(--text-2); min-width: 108px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Result head ---------- */
.result-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 24px 2px 12px;
}
.result-head h2 { margin: 0; font-size: 15px; font-weight: 650; }
.muted { font-size: 12.5px; color: var(--text-3); }

.empty {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 34px 18px;
  text-align: center;
  color: var(--text-3);
  background: rgba(255, 255, 255, .6);
}
.empty p { margin: 0; font-size: 13px; }
.empty[hidden] { display: none; }

/* ---------- Grid / cards ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}
.grid-pages { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }

.item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.item-head { display: flex; align-items: center; gap: 8px; }
.item-name {
  font-size: 13.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.item-tag {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.item-tag.ok { background: #e8f7ee; color: var(--success); border-color: #c9ecd7; }
.item-tag.err { background: #fdecec; color: var(--danger); border-color: #f7cfd0; }
.icon-btn {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border: 0; border-radius: 7px;
  background: transparent; color: var(--text-3);
  cursor: pointer; flex: 0 0 26px;
}
.icon-btn:hover { background: #fdecec; color: var(--danger); }
.icon-btn svg { width: 15px; height: 15px; }

.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.compare figure {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
}
.compare .ph {
  aspect-ratio: 4 / 3;
  display: grid; place-items: center;
  background:
    linear-gradient(45deg, #f1f2f7 25%, transparent 25%, transparent 75%, #f1f2f7 75%),
    linear-gradient(45deg, #f1f2f7 25%, transparent 25%, transparent 75%, #f1f2f7 75%) 8px 8px,
    #fafbfd;
  background-size: 16px 16px;
  color: var(--text-3);
  font-size: 12px;
}
.compare .ph img { width: 100%; height: 100%; object-fit: contain; display: block; }
.compare img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background: #fafbfd;
  cursor: zoom-in;
}
.compare figcaption {
  padding: 5px 8px;
  font-size: 11.5px;
  color: var(--text-2);
  border-top: 1px solid var(--border);
  background: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.compare figcaption b { color: var(--text); font-weight: 600; }

.item-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.item-actions select { height: 30px; font-size: 12.5px; flex: 1; min-width: 96px; }

/* PDF page card */
.page-card { padding: 10px; gap: 8px; }
.page-num {
  font-size: 12px;
  font-weight: 650;
  color: var(--text-2);
}
.thumb {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #fafbfd;
  aspect-ratio: 3 / 4;
  display: grid;
  place-items: center;
}
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; cursor: zoom-in; }
.thumb .spinner {
  width: 22px; height: 22px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.page-meta { font-size: 11.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(16, 18, 32, .82);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 60;
  animation: fade .18s ease;
}
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
}
.lightbox-close {
  position: absolute;
  top: 18px; right: 20px;
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, .16);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.lightbox-close:hover { background: rgba(255, 255, 255, .28); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 16px);
  max-width: min(92vw, 460px);
  padding: 11px 16px;
  border-radius: 10px;
  background: #1c2033;
  color: #fff;
  font-size: 13.5px;
  box-shadow: 0 10px 30px rgba(16, 18, 32, .28);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 80;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { background: #10733c; }
.toast.err { background: #b3261e; }
.toast.warn { background: #8a5a00; }

/* ---------- Footer ---------- */
.app-footer {
  margin-top: 34px;
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
}

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .app { padding: 18px 14px 32px; }
  .brand-text h1 { font-size: 18px; }
  .brand-text p { font-size: 11.5px; }
  .tab { font-size: 13.5px; padding: 10px 8px; gap: 6px; }
  .toolbar { align-items: stretch; }
  .field { flex: 1 1 140px; min-width: 0; }
  .field-narrow { max-width: none; }
  .toolbar-actions { margin-left: 0; width: 100%; }
  .toolbar-actions .btn { flex: 1; }
  .grid { grid-template-columns: 1fr; }
  .grid-pages { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .progress { flex-wrap: wrap; }
  .progress-text { min-width: 0; text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
