:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --text: #13201e;
  --muted: #5b6b68;
  --line: #d9e2e0;
  --brand: #0f766e;
  --brand-strong: #0b5e57;
  --brand-soft: #e3f3f1;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1615;
    --surface: #17211f;
    --text: #e6eeec;
    --muted: #9aaba7;
    --line: #2a3734;
    --brand: #2dd4bf;
    --brand-strong: #5eead4;
    --brand-soft: #123532;
    --danger: #f97066;
    --danger-soft: #3a1a17;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}

body > * { max-width: 720px; margin-inline: auto; }

[hidden] { display: none !important; }

/* ---------- Header ---------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 0 12px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand h1 { margin: 0; font-size: 1.5rem; line-height: 1.1; letter-spacing: -0.01em; }
.brand h1 span { color: var(--brand); }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 0.875rem; }

.lang { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; flex-shrink: 0; }
.lang button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 6px 12px;
  cursor: pointer;
}
.lang button[aria-pressed="true"] { background: var(--brand); color: var(--surface); }

/* ---------- Beranda: launcher Olah PDF ---------- */

.home-title {
  display: none;
}

.tool-grid {
  list-style: none;
  margin: 38px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
}

.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  min-height: 100px;
  padding: 0;
  text-align: center;
  text-decoration: none;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  transition: transform 0.12s ease;
}

.tool:hover,
.tool:focus-visible {
  border: 0;
  box-shadow: none;
  background: transparent;
}

.tool:active {
  transform: scale(0.96);
}

.tool-icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 16px;
  color: #fff;
  flex-shrink: 0;
}

.tool-icon svg {
  width: 32px;
  height: 32px;
}

.tool-icon.merge { background: #0f766e; }
.tool-icon.split { background: #c2410c; }
.tool-icon.organize { background: #1d4ed8; }
.tool-icon.compress { background: #6d28d9; }
.tool-icon.images { background: #be185d; }
.tool-icon.read { background: #0369a1; }

.tool-name {
  font-weight: 500;
  font-size: 0.9rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.tool-desc {
  display: none !important;
}

@media (min-width: 600px) {
  .tool-grid {
    gap: 18px;
  }

  .tool {
    min-height: 100px;
  }
}

@media (max-width: 599px) {
  .tool-grid {
    margin-top: 30px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 14px;
    row-gap: 28px;
  }

  .tool {
    min-height: 88px;
  }

  .tool-icon {
    width: 56px;
    height: 56px;
    border-radius: 15px;
  }

  .tool-icon svg {
    width: 28px;
    height: 28px;
  }

  .tool-name {
    font-size: 0.85rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tool {
    transition: none;
  }

  .tool:active {
    transform: none;
  }
}

/* ---------- Bar alat (di atas panel) ---------- */
.tool-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.back {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 0.875rem;
  text-decoration: none;
  white-space: nowrap;
}
.back:hover { border-color: var(--brand); }
.tool-title { margin: 0; font-size: 1.125rem; min-width: 0; }
.tool-title:focus { outline: none; }

/* ---------- Panel ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
  padding: 28px 16px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.drop:hover, .drop.over, .drop:focus-within { border-color: var(--brand); background: var(--brand-soft); }
.drop strong { color: var(--brand-strong); }
.drop small { color: var(--muted); }

/* ---------- Daftar file ---------- */
.list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.list:empty { display: none; }
.list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.list li.bad { border-color: var(--danger); background: var(--danger-soft); }
.list > li > img, .badge {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 6px;
  object-fit: cover;
  background: var(--bg);
}
.badge {
  display: grid;
  place-items: center;
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--danger);
  border: 1px solid var(--line);
}
.info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.meta { color: var(--muted); font-size: 0.8125rem; }
.bad .meta { color: var(--danger); }
.tools { display: flex; gap: 4px; flex-shrink: 0; }
.icon {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
}
.icon:disabled { opacity: 0.35; cursor: default; }

/* ---------- Opsi ---------- */
.options {
  margin: 16px 0 0;
  padding: 0;
  border: 0;
  display: grid;
  gap: 10px;
}
.options legend { font-weight: 600; margin-bottom: 6px; padding: 0; }
.options label { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.options label > span:first-child:not(:only-child) { min-width: 110px; }
.options select, .options input[type="text"] {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  flex: 1;
  min-width: 0;
}
.options input[type="radio"] { accent-color: var(--brand); width: 18px; height: 18px; margin: 0; }
.range-field { padding-left: 26px; }
.range-field small { width: 100%; color: var(--muted); }

/* ---------- Tombol ---------- */
.actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.primary, .ghost {
  font: inherit;
  font-weight: 600;
  padding: 12px 20px;
  border-radius: 10px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
}
.primary { background: var(--brand); color: var(--surface); border: 1px solid var(--brand); flex: 1; }
.primary:hover { background: var(--brand-strong); }
.primary:disabled { opacity: 0.45; cursor: default; background: var(--brand); }
.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }

/* ---------- Status & hasil ---------- */
.status {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--brand-soft);
  color: var(--brand-strong);
}
.status.error { background: var(--danger-soft); color: var(--danger); }

.result {
  margin-top: 12px;
  padding: 16px;
  border: 1px solid var(--brand);
  border-radius: var(--radius);
  background: var(--brand-soft);
  display: grid;
  gap: 10px;
}
.result-text { margin: 0; font-weight: 500; }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.result-actions > * { flex: 1 1 auto; }
.download { display: block; overflow-wrap: anywhere; flex-basis: 100%; }
.result-file { margin: 0; font-size: 0.875rem; color: var(--muted); overflow-wrap: anywhere; }

footer {
  margin-top: 54px;
  padding: 16px 0 24px;
  display: grid;
  gap: 5px;
}

.privacy {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.5;
}

.privacy-note {
  opacity: 0.9;
}

.privacy a {
  color: inherit;
}

:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

.options label.choice { flex-wrap: nowrap; align-items: flex-start; }
.options label.choice input { margin-top: 3px; flex-shrink: 0; }

/* ---------- Halaman dokumen (privasi) ---------- */
a { color: var(--brand-strong); }
a.brand { color: inherit; text-decoration: none; }
.brand-name { margin: 0; font-size: 1.5rem; font-weight: 700; line-height: 1.1; letter-spacing: -0.01em; }
.brand-name span { color: var(--brand); }
.privacy a { color: inherit; }

.doc {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 20px 20px;
}
.doc-lang { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 0 4px; }
.doc-lang a {
  font-size: 0.875rem;
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  text-decoration: none;
}
.doc article + article { border-top: 1px solid var(--line); margin-top: 28px; }
.doc h1 { font-size: 1.375rem; margin: 20px 0 4px; }
.doc h2 { font-size: 1.0625rem; margin: 22px 0 6px; }
.doc p, .doc li { overflow-wrap: anywhere; }
.doc ul { padding-left: 20px; }
.doc li + li { margin-top: 4px; }
.muted { color: var(--muted); margin-top: 0; font-size: 0.875rem; }
.summary { background: var(--brand-soft); border-radius: 10px; padding: 12px 14px; }

/* ---------- Thumbnail halaman ---------- */
.list li { flex-wrap: wrap; }
.pages { flex-basis: 100%; min-width: 0; }
.pages.strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 6px;
  scroll-snap-type: x proximity;
  overscroll-behavior-x: contain;
}
.pages.strip .thumb { flex: 0 0 72px; scroll-snap-align: start; }
.pages.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 10px;
  padding: 4px 0;
}
.pages.failed::after { content: "—"; color: var(--muted); }

.thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.75rem;
  cursor: zoom-in;
  min-width: 0;
}
.thumb-img {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1 / 1.414;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  overflow: hidden;
}
.thumb img { display: none; max-width: 100%; max-height: 100%; background: #fff; }
.thumb.ready img { display: block; }
.thumb.ready .thumb-img { background: var(--surface); }
.thumb:not(.ready):not(.failed) .thumb-img {
  background: linear-gradient(90deg, var(--bg), var(--line), var(--bg));
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}
.thumb.failed .thumb-img::after { content: "!"; color: var(--danger); font-weight: 700; }
.thumb:hover .thumb-img, .thumb:focus-visible .thumb-img { border-color: var(--brand); }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .thumb .thumb-img { animation: none !important; } }

.result-preview-title { margin: 4px 0 0; font-size: 0.875rem; color: var(--muted); }
.result-preview-title strong { color: var(--text); }
.result-preview { display: grid; gap: 10px; min-width: 0; }
.result-preview:empty { display: none; }
.part-name { margin: 0; font-size: 0.8125rem; font-weight: 600; overflow-wrap: anywhere; }

/* ---------- Penampil halaman ---------- */
.viewer {
  width: min(100vw - 16px, 900px);
  height: min(100dvh - 16px, 1100px);
  max-width: none;
  max-height: none;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
.viewer[open] { display: flex; flex-direction: column; }
.viewer::backdrop { background: rgb(0 0 0 / 0.6); }
.viewer-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 8px 14px;
  border-bottom: 1px solid var(--line);
}
.viewer-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.viewer-count { color: var(--muted); font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.viewer-stage {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 8px;
  background: var(--bg);
  overflow: auto;
  touch-action: pan-y pinch-zoom;
}
.viewer-stage canvas { background: #fff; box-shadow: 0 1px 6px rgb(0 0 0 / 0.18); }
.viewer-msg { color: var(--muted); }
.viewer-nav { display: flex; gap: 8px; padding: 8px; border-top: 1px solid var(--line); }
.viewer-nav button { flex: 1; }
.viewer-nav button:disabled { opacity: 0.4; cursor: default; }

/* ---------- Pratinjau langsung Gambar ke PDF ---------- */
.live-preview { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.live-status { margin: 0; color: var(--muted); font-size: 0.875rem; }
.live-status.error { color: var(--danger); }
.fit-note { color: var(--muted); }
.options select:disabled { opacity: 0.5; }

/* ---------- Atur halaman ---------- */
.organize-tools { margin-top: 12px; display: grid; gap: 10px; }
.organize-bulk { display: flex; flex-wrap: wrap; gap: 8px; }
.ghost.small { padding: 8px 12px; font-size: 0.875rem; }
.organize-summary { margin: 0; color: var(--muted); font-size: 0.875rem; }
.organizer {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 12px;
}
.org-card {
  display: grid;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  min-width: 0;
}
/* Kotak persegi supaya halaman yang diputar tetap muat. */
.org-card .thumb-img { aspect-ratio: 1; }
.org-card .thumb img { transition: transform 0.15s; }
.org-card.removed { background: var(--danger-soft); border-color: var(--danger); }
.org-card.removed .thumb-img { opacity: 0.35; }
.org-card.removed .thumb-n { text-decoration: line-through; color: var(--danger); }
.org-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.org-actions .icon { width: auto; height: 32px; font-size: 0.9375rem; padding: 0; }
@media (prefers-reduced-motion: reduce) { .org-card .thumb img { transition: none; } }

/* ---------- Kompres ---------- */
.note {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
  color: var(--muted);
  font-size: 0.875rem;
}

/* ---------- Seret & lepas ---------- */
.drag-handle { cursor: grab; touch-action: none; }
.org-actions .drag-handle { font-size: 1.1rem !important; }
.list .drag-handle {
  width: 28px;
  height: 44px;
  margin-right: -6px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1.2rem;
  flex-shrink: 0;
}
@media (pointer: fine) {
  .sortable > * { cursor: grab; }
  .sortable button:not(.drag-handle), .sortable .pages { cursor: pointer; }
}
.sortable > .dragging {
  position: relative;
  z-index: 20;
  pointer-events: none;
  box-shadow: 0 10px 28px rgb(0 0 0 / 0.25);
  border-color: var(--brand);
  background: var(--surface);
}
body.is-dragging { user-select: none; -webkit-user-select: none; cursor: grabbing; }
body.is-dragging .sortable > * { cursor: grabbing; }

/* ---------- Pemberitahuan singkat ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  width: max-content;
  max-width: calc(100vw - 32px);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px 10px 16px;
  border-radius: 12px;
  background: #13201e;
  color: #fff;
  border: 1px solid rgb(255 255 255 / 0.18);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.3);
  animation: toast-in 0.2s ease-out;
}
.toast-text { min-width: 0; }
.toast-open {
  font: inherit;
  font-weight: 700;
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: #2dd4bf;
  color: #062c28;
  cursor: pointer;
  flex-shrink: 0;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* ---------- Pembaca PDF (layar penuh) ---------- */
body.reading { overflow: hidden; }
body.reading > :not(.reader):not(.toast):not(dialog) { display: none !important; }
.reader {
  position: fixed;
  inset: 0;
  z-index: 50;
  max-width: none;
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.reader-bar, .reader-foot, .reader-find {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--surface);
  flex-shrink: 0;
}
.reader-bar { position: relative; border-bottom: 1px solid var(--line); }
.reader-foot { border-top: 1px solid var(--line); justify-content: space-between; }
.reader-find { border-bottom: 1px solid var(--line); }
.reader-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.reader .icon { display: inline-grid; place-items: center; flex-shrink: 0; padding: 0; }
.reader-find input {
  flex: 1;
  min-width: 0;
  font: inherit;
  padding: 6px 10px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}
.reader-find-count { color: var(--muted); font-size: 0.8125rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.reader-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 8px;
  z-index: 5;
  min-width: 200px;
  display: grid;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 10px 28px rgb(0 0 0 / 0.2);
}
.reader-menu button {
  font: inherit;
  text-align: left;
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text);
  cursor: pointer;
}
.reader-menu button:hover { background: var(--brand-soft); }
.reader-menu-title { margin: 6px 12px 2px; padding-top: 6px; border-top: 1px solid var(--line); font-size: 0.75rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.reader-pages {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  /* Cubit untuk zoom ditangani sendiri (reader.js), bukan zoom seluruh halaman. */
  touch-action: pan-x pan-y;
}
.reader-pages:focus { outline: none; }
.reader-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 10px;
  width: max-content;
  min-width: 100%;
}
.r-page {
  position: relative;
  flex-shrink: 0;
  background: #fff;
  box-shadow: 0 1px 6px rgb(0 0 0 / 0.18);
}
.r-page canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.r-page:not(.ready)::before {
  content: attr(data-page);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #9aaba7;
  font-size: 1.25rem;
}
.r-page.failed::before { content: "!"; color: #b42318; }
.r-hl { position: absolute; inset: 0; pointer-events: none; }
.r-hl span { position: absolute; background: rgb(250 204 21 / 0.4); border-radius: 2px; }
.r-hl span.current { background: rgb(249 115 22 / 0.55); outline: 2px solid #ea580c; }
/* Mode baca gelap: halaman dibalik warnanya (gambar ikut, tapi warna tetap mirip). */
.reader.dark .reader-pages { background: #000; }
.reader.dark .r-page { background: #111; }
.reader.dark .r-page canvas { filter: invert(0.92) hue-rotate(180deg); }
.reader-pos { display: flex; align-items: center; gap: 6px; color: var(--muted); font-variant-numeric: tabular-nums; }
.reader-page {
  width: 64px;
  height: 36px;
  font: inherit;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  -moz-appearance: textfield;
}
.reader-page::-webkit-inner-spin-button, .reader-page::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.reader-zooms { display: flex; align-items: center; gap: 4px; }
.reader-zoom {
  font: inherit;
  font-size: 0.875rem;
  min-width: 56px;
  height: 36px;
  border: 0;
  background: none;
  color: var(--text);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
[data-reader="dark"][aria-pressed="true"] { background: var(--brand); color: var(--surface); border-color: var(--brand); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
