/* ============================================================
   niqPDF — style.css
   Layout: toolrail sidebar (kiri, ber-icon) + viewer (tengah)
   + sidepanel tab Halaman/Properti (kanan). Dark/Light via
   [data-theme]. Modern, clean, profesional.
   ============================================================ */

:root {
  --bg: #eef1f5;
  --bg-panel: #ffffff;
  --bg-soft: #f6f8fa;
  --bg-hover: #e8ecf1;
  --text: #14171a;
  --text-dim: #616c78;
  --border: #dde2e8;
  --accent: #2563eb;
  --accent-2: #4c8dff;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --shadow: 0 10px 34px rgba(20, 30, 50, .12);
  --shadow-soft: 0 2px 10px rgba(20, 30, 50, .08);
  --radius: 12px;
  --glow: 0 4px 14px rgba(37, 99, 235, .35);
}

[data-theme="dark"] {
  --bg: #0c1016;
  --bg-panel: #141a22;
  --bg-soft: #1a222c;
  --bg-hover: #232d39;
  --text: #e8eef4;
  --text-dim: #8b97a5;
  --border: #2a3441;
  --accent: #4c8dff;
  --accent-2: #6ea3ff;
  --accent-text: #0c1016;
  --danger: #f85149;
  --ok: #3fb950;
  --shadow: 0 10px 34px rgba(0, 0, 0, .5);
  --shadow-soft: 0 2px 10px rgba(0, 0, 0, .35);
  --glow: 0 4px 18px rgba(76, 141, 255, .4);
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; color: inherit; }
a { color: var(--accent); }
code { background: var(--bg-hover); padding: 1px 5px; border-radius: 4px; font-size: .85em; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ================= HEADER ================= */
.topbar {
  display: flex; align-items: center; gap: 16px;
  height: 60px; padding: 0 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 11px; }
.logo-ring {
  width: 42px; height: 42px; padding: 2px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: var(--glow);
}
.logo {
  width: 100%; height: 100%;
  object-fit: contain;
  border-radius: 10px;
  background: var(--bg-panel);
}
.brand-text strong { display: block; font-size: 17px; letter-spacing: .2px; line-height: 1.15; }
.brand-text small {
  color: var(--text-dim); font-size: 10.5px;
  text-transform: uppercase; letter-spacing: 1.2px;
}

.file-chip {
  flex: 0 1 auto; max-width: 320px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 6px 14px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px; color: var(--text-dim);
}

.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.hbtn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-panel);
  color: var(--text);
  font-size: 13px; font-weight: 500;
  transition: background .15s, transform .08s, box-shadow .15s;
}
.hbtn svg { width: 17px; height: 17px; }
.hbtn:hover { background: var(--bg-hover); }
.hbtn:active { transform: scale(.96); }
.hbtn.icon { padding: 8px; }
.hbtn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-text);
  border-color: transparent;
  box-shadow: var(--glow);
}
.hbtn.primary:hover { filter: brightness(1.08); background: linear-gradient(135deg, var(--accent), var(--accent-2)); }

/* ================= LAYOUT ================= */
.layout {
  display: flex;
  height: calc(100vh - 60px - 48px);
}

/* ================= TOOLRAIL (sidebar kiri) ================= */
.toolrail {
  width: 68px;
  padding: 10px 0 14px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  scrollbar-width: thin;
}
.rail-group {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 8px 0 16px;
  position: relative;
  width: 100%;
}
.rail-group + .rail-group { border-top: 1px solid var(--border); }
.rail-group::after {
  content: attr(data-label);
  position: absolute; bottom: 2px; left: 0; right: 0;
  text-align: center;
  font-size: 8.5px; font-weight: 600;
  letter-spacing: 1px; text-transform: uppercase;
  color: var(--text-dim);
  opacity: .55;
  pointer-events: none;
}

.tool {
  width: 44px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text-dim);
  transition: background .13s, color .13s, transform .08s;
}
.tool svg { width: 19px; height: 19px; }
.tool:hover {
  background: var(--bg-hover);
  color: var(--text);
  transform: translateY(-1px);
}
.tool.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-text);
  box-shadow: var(--glow);
}

/* tooltip mengambang (JS) — lolos dari overflow-x:hidden toolrail.
   Dibuat/dihancurkan oleh JS di app.js, bukan via :hover::before
   (yang lama ke-clip dan sudah dihapus). */
.tip-float {
  position: fixed; z-index: 500; pointer-events: none;
  background: var(--text); color: var(--bg);
  padding: 6px 11px; border-radius: 8px;
  font-size: 11.5px; font-weight: 500; white-space: nowrap;
  box-shadow: var(--shadow-soft);
  animation: tipIn .12s ease;
}
@keyframes tipIn { from { opacity: 0; transform: translateX(-4px); } }

/* ================= VIEWER ================= */
.viewer-pane {
  flex: 1; overflow: auto;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(76, 141, 255, .07), transparent 60%),
    var(--bg);
  position: relative;
}
.viewer-pane.dragging::after {
  content: "📂 Letakkan PDF di sini";
  position: absolute; inset: 14px;
  display: flex; align-items: center; justify-content: center;
  border: 3px dashed var(--accent); border-radius: var(--radius);
  background: rgba(76, 141, 255, .10);
  font-size: 22px; font-weight: 600;
  pointer-events: none; z-index: 50;
}
.viewer {
  padding: 22px;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
}

.page-wrap { position: relative; }
.page-stack {
  position: relative;
  background: #fff;
  box-shadow: var(--shadow);
  border-radius: 4px;
  overflow: hidden;
}
.page-canvas { display: block; }
.page-label {
  position: absolute; top: -13px; right: 10px;
  background: var(--bg-panel); border: 1px solid var(--border);
  color: var(--text-dim); font-size: 10px; font-weight: 600;
  padding: 2px 10px; border-radius: 999px;
  box-shadow: var(--shadow-soft);
}

/* text layer */
.text-layer { position: absolute; inset: 0; overflow: hidden; line-height: 1; }
.text-layer span {
  position: absolute; white-space: pre;
  transform-origin: 0 0;
  color: transparent; cursor: text; user-select: text;
}
.text-layer span::selection { background: rgba(76, 141, 255, .35); }

/* ================= ANOTASI ================= */
.annot-layer { position: absolute; inset: 0; touch-action: none; }
.annot { position: absolute; cursor: move; min-width: 2px; min-height: 2px; }
.annot.selected { outline: 1.5px dashed var(--accent); outline-offset: 2px; }

.note-pin {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(145deg, #fde047, #facc15);
  border: 1px solid #ca8a04; border-radius: 8px;
  font-size: 14px; box-shadow: var(--shadow-soft);
}
.note-body {
  display: none;
  position: absolute; left: 112%; top: 0;
  width: 180px; padding: 9px 11px;
  background: #fffbe6; color: #422006;
  border: 1px solid #eab308; border-radius: 9px;
  font-size: 11px; z-index: 20;
  box-shadow: var(--shadow-soft);
}
.annot-note:hover .note-body { display: block; }

.annot-text {
  display: flex; align-items: center;
  padding: 1px 3px; cursor: text; white-space: pre-wrap;
}
.annot-image img, .annot-signature img { pointer-events: none; }
.stamp-inner {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%;
  border: 3px solid currentColor; border-radius: 7px;
  font-weight: 800; letter-spacing: 1.5px; opacity: .85;
}
.annot-form input { pointer-events: auto; }

.resize-handle {
  position: absolute; width: 10px; height: 10px;
  background: var(--accent);
  border: 2px solid #fff; border-radius: 50%;
  box-shadow: var(--shadow-soft);
  z-index: 30;
}
.rh-nw { left: -6px; top: -6px; cursor: nwse-resize; }
.rh-ne { right: -6px; top: -6px; cursor: nesw-resize; }
.rh-sw { left: -6px; bottom: -6px; cursor: nesw-resize; }
.rh-se { right: -6px; bottom: -6px; cursor: nwse-resize; }

/* ================= SIDEPANEL (kanan) ================= */
.sidepanel {
  width: 258px; min-width: 258px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.panel-tabs {
  display: flex; gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.panel-tab {
  flex: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 6px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px; font-weight: 600;
  transition: background .13s, color .13s;
}
.panel-tab svg { width: 15px; height: 15px; }
.panel-tab:hover { background: var(--bg-hover); color: var(--text); }
.panel-tab.active {
  background: var(--bg-soft);
  border-color: var(--border);
  color: var(--accent);
}

.panel-view { display: none; flex: 1; overflow-y: auto; padding: 12px; }
.panel-view.active { display: block; }

/* thumbnails */
.thumb {
  position: relative;
  margin-bottom: 12px; padding: 7px;
  border: 2px solid transparent;
  border-radius: 10px;
  background: var(--bg-soft);
  cursor: pointer;
  transition: border-color .13s, transform .1s;
}
.thumb:hover { border-color: var(--accent-2); transform: translateY(-1px); }
.thumb.drag-over { border-color: var(--accent); background: rgba(76, 141, 255, .1); }
.thumb canvas {
  width: 100%; display: block; border-radius: 5px;
  background: #fff;
  box-shadow: var(--shadow-soft);
}
.thumb-num {
  position: absolute; left: 11px; bottom: 11px;
  background: rgba(10, 14, 20, .7); color: #fff;
  font-size: 10px; font-weight: 600;
  padding: 1px 8px; border-radius: 999px;
}
.thumb-rot {
  position: absolute; right: 11px; top: 11px;
  background: var(--accent); color: var(--accent-text);
  font-size: 9px; font-weight: 700;
  padding: 1px 6px; border-radius: 999px;
}

.page-actions {
  display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 6px;
  margin-top: 12px;
}
.pbtn {
  display: flex; align-items: center; justify-content: center;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg-soft);
  color: var(--text-dim);
  transition: background .13s, color .13s;
}
.pbtn svg { width: 16px; height: 16px; }
.pbtn:hover { background: var(--bg-hover); color: var(--text); }
.pbtn.danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

/* property panel */
#props h3 { font-size: 11px; margin: 4px 0 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .8px; }
#props label {
  display: block; font-size: 12px; margin-bottom: 12px; color: var(--text-dim);
}
#props input:not([type="checkbox"]):not([type="range"]):not([type="color"]),
#props select {
  display: block; width: 100%; margin-top: 5px;
  padding: 7px 9px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg-soft); color: var(--text);
  font-size: 12.5px;
}
#props input[type="color"] { display: block; width: 100%; height: 34px; margin-top: 5px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-soft); }
#props input[type="range"] { display: block; width: 100%; margin-top: 8px; accent-color: var(--accent); }
#props .btn { width: 100%; margin-bottom: 8px; }
.props-empty { color: var(--text-dim); font-size: 12px; line-height: 1.6; padding: 10px 2px; }

/* ================= STATUS BAR ================= */
.statusbar {
  display: flex; align-items: center; gap: 8px;
  height: 48px; padding: 0 14px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  font-size: 12px;
}
.sb-group { display: flex; align-items: center; gap: 6px; }
.sbtn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 32px; height: 30px; padding: 0 7px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  transition: background .13s, color .13s;
}
.sbtn svg { width: 15px; height: 15px; }
.sbtn:hover { background: var(--bg-hover); color: var(--text); }
.sbtn.wide span { font-size: 11.5px; font-weight: 600; }
.page-input {
  width: 52px; padding: 5px 6px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg-soft); color: var(--text);
  font-size: 12px; text-align: center;
}
#pageIndicator, #zoomIndicator {
  min-width: 52px; text-align: center;
  color: var(--text-dim); font-weight: 600; font-size: 11.5px;
}
.sep { flex: 0 0 1px; height: 20px; background: var(--border); margin: 0 4px; }

.status-msg {
  margin-left: auto;
  display: flex; align-items: center; gap: 7px;
  color: var(--text-dim); font-size: 11px;
}
.status-msg .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 6px var(--ok);
}
.status-msg em { font-style: normal; opacity: .7; }

.muted { color: var(--text-dim); }
.small { font-size: 11px; }

/* ================= TOAST ================= */
#toast {
  position: fixed; bottom: 64px; left: 50%;
  transform: translate(-50%, 16px);
  background: var(--text); color: var(--bg);
  padding: 11px 20px; border-radius: 12px;
  font-size: 13px; font-weight: 500;
  opacity: 0;
  transition: opacity .22s, transform .22s;
  pointer-events: none; z-index: 400;
  max-width: 82vw;
  box-shadow: var(--shadow);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ================= MODALS ================= */
.modal {
  position: fixed; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  background: rgba(6, 10, 16, .6);
  backdrop-filter: blur(4px);
  z-index: 200;
}
.modal.open { display: flex; animation: fadeIn .15s ease; }
@keyframes fadeIn { from { opacity: 0; } }
.modal-box {
  position: relative;
  width: min(450px, 92vw);
  max-height: 86vh; overflow-y: auto;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  animation: popIn .18s ease;
}
@keyframes popIn { from { transform: scale(.96); opacity: 0; } }
.modal-wide { width: min(640px, 94vw); }
.modal-box h2 { font-size: 18px; margin-bottom: 16px; }
.modal-box h3 { font-size: 12px; margin: 16px 0 8px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .8px; }
.modal-box p { font-size: 13px; margin-bottom: 12px; line-height: 1.55; }
.modal-box label { display: block; font-size: 12px; margin-bottom: 13px; color: var(--text-dim); }
.modal-box input[type="text"],
.modal-box input[type="password"],
.modal-box input[type="number"],
.modal-box input[type="file"],
.modal-box select {
  display: block; width: 100%; margin-top: 5px;
  padding: 9px 11px;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--bg-soft); color: var(--text);
  font-size: 13px;
}
.modal-box .btn-primary { width: 100%; padding: 11px; margin-top: 8px; }
.modal-close {
  position: absolute; top: 14px; right: 14px;
  width: 30px; height: 30px;
  border: none; border-radius: 50%;
  background: var(--bg-hover); color: var(--text-dim);
  font-size: 14px;
}
.modal-close:hover { background: var(--danger); color: #fff; }
.row2 { display: flex; gap: 10px; align-items: end; }
.row2 label { flex: 1; }

/* buttons umum (modal) */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg-panel);
  color: var(--text);
  font-size: 13px;
  transition: background .15s, transform .07s;
}
.btn:hover { background: var(--bg-hover); }
.btn:active { transform: scale(.97); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-text); border-color: transparent;
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.08); background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 4px 9px; font-size: 12px; }

/* keys table */
.keys { width: 100%; border-collapse: collapse; font-size: 13px; }
.keys td { padding: 7px 8px; border-bottom: 1px solid var(--border); }
.keys td:first-child { width: 155px; }

/* about */
.about-head { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.about-logo { width: 64px; height: 64px; border-radius: 14px; box-shadow: var(--shadow-soft); }
.ver {
  font-size: 11px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-text);
  padding: 2px 10px; border-radius: 999px;
  vertical-align: middle; font-weight: 700;
}
.feat { list-style: none; font-size: 13px; line-height: 1.65; }
.feat li { margin-bottom: 4px; }

/* signature */
.sig-pad {
  width: 100%; height: 180px;
  border: 2px dashed var(--border); border-radius: 11px;
  background: var(--bg-soft);
  touch-action: none; cursor: crosshair;
}
details { margin-bottom: 13px; }
details summary {
  cursor: pointer; font-size: 13px; font-weight: 600;
  margin-bottom: 9px; color: var(--text);
}
.sig-gallery {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}
.sig-item {
  border: 1px solid var(--border); border-radius: 10px;
  padding: 9px; background: var(--bg-soft);
}
.sig-item img {
  width: 100%; height: 54px; object-fit: contain;
  background: #fff; border-radius: 6px;
}
.sig-meta { display: flex; gap: 5px; margin-top: 7px; }
.form-row label { font-size: 12px; margin-bottom: 9px; display: block; }

/* ================= RESPONSIVE ================= */
@media (max-width: 1100px) {
  .sidepanel { width: 220px; min-width: 220px; }
}
@media (max-width: 920px) {
  .sidepanel { display: none; }
  .file-chip { display: none; }
}
@media (max-width: 640px) {
  .toolrail { width: 56px; }
  .tool { width: 38px; height: 36px; }
  .rail-group::after { display: none; }
  .brand-text small { display: none; }
  .hbtn span { display: none; }
  .hbtn { padding: 8px; }
}

/* ================= BERANDA GALERI FITUR (v1.3) =================
   Gaya Stirling-PDF: kartu ikon + nama + fungsi di tengah layar.
   Overlay di dalam .viewer-pane; tampil sebelum dokumen dibuka
   atau lewat tombol Beranda. */
.home-gallery {
  position: absolute; inset: 0;
  overflow-y: auto;
  padding: 34px 26px 44px;
  z-index: 4;
}
.home-gallery[hidden] { display: none; }
.gallery-inner { max-width: 1020px; margin: 0 auto; }

.gallery-hero {
  border: 2px dashed var(--border);
  border-radius: 18px;
  background: var(--bg-panel);
  padding: 34px 24px 30px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .1s;
}
.gallery-hero:hover, .gallery-hero:focus-visible {
  border-color: var(--accent);
  box-shadow: var(--shadow-soft);
  outline: none;
}
.gallery-hero:active { transform: scale(.995); }
.gallery-hero svg { width: 42px; height: 42px; color: var(--accent); }
.gallery-hero h1 { font-size: 25px; margin: 12px 0 7px; letter-spacing: .2px; }
.gallery-hero p {
  color: var(--text-dim); font-size: 13.5px; line-height: 1.6;
  max-width: 560px; margin: 0 auto;
}

.gallery-group-title {
  margin: 30px 2px 13px;
  font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1.4px;
  color: var(--text-dim);
  display: flex; align-items: center; gap: 10px;
}
.gallery-group-title::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(228px, 1fr));
  gap: 12px;
}
.tool-card {
  display: flex; gap: 13px; align-items: flex-start;
  width: 100%; text-align: left;
  padding: 15px 16px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text);
  transition: transform .12s, border-color .12s, box-shadow .12s;
}
.tool-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow-soft);
}
.tool-card:active { transform: scale(.98); }
.tc-icon {
  flex: 0 0 44px; width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(76, 141, 255, .16), rgba(76, 141, 255, .05));
  color: var(--accent);
}
.tc-icon svg { width: 22px; height: 22px; }
.tc-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.tc-text strong { font-size: 14px; font-weight: 600; }
.tc-text span { font-size: 12px; line-height: 1.5; color: var(--text-dim); }

/* tool Edit Teks aktif: baris teks di halaman bisa diklik */
body[data-tool="edittext"] .text-layer span:hover {
  background: rgba(76, 141, 255, .30);
  outline: 1px dashed var(--accent);
  cursor: pointer;
}

@media (max-width: 640px) {
  .home-gallery { padding: 22px 14px 34px; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .gallery-hero h1 { font-size: 21px; }
}
