:root {
  --accent: #e11d48;
  --accent-dark: #be123c;
  --accent-soft: #ffe4e6;
  --bg: #f4f4f6;
  --surface: #ffffff;
  --text: #18181b;
  --muted: #6b7280;
  --border: #e4e4e7;
  --success: #16a34a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.06);
  --topbar: 64px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

h1, h2, h3 { line-height: 1.2; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Komponen dasar ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { border-color: #d4d4d8; background: #fafafa; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.block { display: flex; width: 100%; }
.btn.wa { background: #25d366; border-color: #25d366; color: #fff; margin-top: 10px; }
.btn.support { margin-left: auto; background: #fff7ed; border-color: #fed7aa; color: #9a3412; }
.btn.support:hover { background: #ffedd5; border-color: #fdba74; }
.doc-page .btn.support { margin-left: 0; }
.qris { display: block; width: 100%; max-width: 320px; height: auto; margin: 0 auto; border-radius: 12px; box-shadow: var(--shadow); }
.btn.danger { color: #b91c1c; border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; border-color: #fca5a5; }

.link {
  border: none;
  background: none;
  padding: 0;
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  background: var(--surface);
  color: var(--text);
}
.input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: var(--topbar);
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 20px;
  font-weight: 500;
}
.brand b { color: var(--accent); }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 100;
  max-width: min(380px, calc(100vw - 40px));
  padding: 12px 16px;
  border-radius: 10px;
  background: #18181b;
  color: #fff;
  font-size: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: none; }
.toast.success { background: #14532d; }
.toast.error { background: #991b1b; }

/* ---------- Beranda ---------- */

.home-main {
  max-width: 880px;
  margin: 0 auto;
  padding: 48px 16px 64px;
  display: grid;
  gap: 28px;
}

.hero { text-align: center; }
.hero h1 { font-size: clamp(28px, 5vw, 44px); letter-spacing: -0.02em; }
.hero h1 span { color: var(--accent); }
.hero p { max-width: 600px; margin: 14px auto 0; color: var(--muted); font-size: 17px; }

.upload-card { display: grid; gap: 18px; }
.field { display: grid; gap: 6px; font-weight: 600; font-size: 14px; }

.drop {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 44px 16px;
  border: 2px dashed #fda4af;
  border-radius: 14px;
  background: #fff7f8;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.drop:hover, .drop.over { background: var(--accent-soft); border-color: var(--accent); }
.drop.busy { pointer-events: none; opacity: 0.8; }
.drop strong { font-size: 18px; }
.drop.compact { padding: 24px 16px; }
.drop.compact strong { font-size: 15px; }

/* Latar kotak-kotak supaya bagian transparan terlihat. */
.upload-preview {
  display: grid;
  place-items: center;
  margin-top: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: repeating-conic-gradient(#f4f4f5 0% 25%, #fff 0% 50%) 0 0 / 16px 16px;
}
.upload-preview img { max-width: 100%; max-height: 160px; object-fit: contain; }
.drop-icon { font-size: 40px; }

.progress {
  width: min(320px, 80%);
  height: 6px;
  margin-top: 12px;
  border-radius: 99px;
  background: #fecdd3;
  overflow: hidden;
}
.progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.1s; }

.steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.step { background: var(--surface); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); }
.step b {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
}
.step h3 { margin: 10px 0 4px; font-size: 16px; }
.step p { margin: 0; color: var(--muted); font-size: 14px; }

.recent { list-style: none; margin: 12px 0 0; padding: 0; }
.recent a {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
}
.recent a:hover .recent-name { color: var(--accent); }
.recent-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Halaman dokumen ---------- */

.doc-meta { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.doc-meta h1 { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.live {
  flex-shrink: 0;
  padding: 2px 10px;
  border-radius: 99px;
  background: #f4f4f5;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.live.on { background: #dcfce7; color: var(--success); }
.live.on::before { content: "● "; }

.banner {
  padding: 10px 20px;
  background: #fef3c7;
  color: #92400e;
  font-size: 14px;
  text-align: center;
}

.doc-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }

.pages { padding: 28px 20px 80px; }
.loading, .fatal { text-align: center; color: var(--muted); padding: 60px 0; }
.fatal p { font-size: 16px; color: var(--text); }

.page {
  position: relative;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  background: #fff;
  box-shadow: var(--shadow);
}
.page canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.page:not(.ready) {
  background: linear-gradient(90deg, #fff 0%, #f6f6f7 50%, #fff 100%) 0 0 / 200% 100%;
  animation: shimmer 1.4s infinite linear;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.page-label { margin: 8px 0 28px; text-align: center; font-size: 12px; color: var(--muted); }

.sig-layer { position: absolute; inset: 0; }
.placing .sig-layer { cursor: crosshair; }
.placing .page { outline: 2px dashed #fda4af; outline-offset: 4px; }
.placing .sig:not(.ghost) { pointer-events: none; }

.sig { position: absolute; border-radius: 4px; }
.sig img { display: block; width: 100%; height: 100%; object-fit: contain; pointer-events: none; user-select: none; }
.sig-name {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 2px;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(24, 24, 27, 0.85);
  color: #fff;
  font-size: 11px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}
.sig:hover .sig-name, .sig.flash .sig-name { opacity: 1; }

.sig.mine { outline: 1.5px dashed var(--accent); cursor: move; touch-action: none; }
.sig.mine:hover, .sig.dragging { background: rgba(225, 29, 72, 0.06); }
.sig-del {
  position: absolute;
  top: -11px;
  right: -11px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.sig-resize {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 3px;
  background: var(--accent);
  cursor: nwse-resize;
}
.sig.ghost { opacity: 0.75; outline: 2px dashed var(--accent); pointer-events: none; }
.sig.flash { animation: flash 1.2s ease-out; }
@keyframes flash {
  0%, 40% { box-shadow: 0 0 0 6px rgba(225, 29, 72, 0.35); }
  100% { box-shadow: 0 0 0 0 rgba(225, 29, 72, 0); }
}

.place-hint {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 30;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px 10px 18px;
  border-radius: 99px;
  background: #18181b;
  color: #fff;
  font-size: 14px;
  box-shadow: var(--shadow);
  white-space: nowrap;
}

.sidebar {
  position: sticky;
  top: var(--topbar);
  max-height: calc(100vh - var(--topbar));
  overflow: auto;
  padding: 16px;
  border-left: 1px solid var(--border);
  background: var(--surface);
  min-height: calc(100vh - var(--topbar));
}
.panel { padding: 14px 4px 18px; border-bottom: 1px solid var(--border); display: grid; gap: 10px; justify-items: start; }
.panel:last-child { border-bottom: none; }
.panel h3 { font-size: 14px; display: flex; align-items: center; gap: 8px; }
.panel p { margin: 0; }
.panel .btn.block { justify-self: stretch; }
.count { padding: 0 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-size: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 3px 10px 3px 8px;
  border-radius: 99px;
  background: #f4f4f5;
  font-size: 13px;
}
.chip::before { content: "● "; color: var(--success); }
.chip.me { background: var(--accent-soft); }

/* ---------- Dialog ---------- */

.dialog {
  width: min(440px, calc(100vw - 32px));
  border: none;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  color: var(--text);
}
.dialog.wide { width: min(580px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(15, 15, 20, 0.5); }
.dialog form { display: grid; gap: 14px; }
.dialog p { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.tabs { display: flex; gap: 4px; padding: 4px; border-radius: 10px; background: #f4f4f5; }
.tab {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 8px;
  background: transparent;
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); }

.pad {
  display: block;
  width: 100%;
  height: 200px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  background:
    linear-gradient(transparent calc(75% - 1px), #e4e4e7 calc(75% - 1px), #e4e4e7 75%, transparent 75%),
    #fafafa;
  touch-action: none;
  cursor: crosshair;
}

.pad-tools { display: flex; align-items: center; gap: 10px; }
.pad-tools .link { margin-left: auto; }
.ink {
  width: 26px;
  height: 26px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 0 1px var(--border);
  cursor: pointer;
}
.ink.active { box-shadow: 0 0 0 2px var(--accent); }

.font-options { display: grid; gap: 8px; margin-top: 10px; }
.font-opt {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 34px;
  line-height: 1.3;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.font-opt.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

.saved-sig {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fafafa;
}
.saved-sig img { height: 48px; max-width: 60%; object-fit: contain; }
.saved-sig .btn { margin-left: auto; }

.check { display: flex; align-items: flex-start; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { margin-top: 3px; accent-color: var(--accent); }

.copy-row { display: flex; gap: 8px; }

/* ---------- Masuk dengan kode ---------- */

.logged-out .doc-layout,
.logged-out .actions,
.logged-out .live { display: none; }

.login-view { display: grid; place-items: center; padding: 60px 16px; }
.login-card { width: min(400px, 100%); display: grid; gap: 14px; text-align: center; }
.login-card p { margin: 0; }
.login-icon { font-size: 40px; }
.code-input { text-align: center; font-size: 22px; font-weight: 700; letter-spacing: 0.12em; }
.error-text { color: #b91c1c; font-size: 14px; }

.code-big {
  padding: 16px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font: 700 32px/1.2 ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: 0.12em;
  text-align: center;
  user-select: all;
}

/* ---------- Daftar penanda tangan ---------- */

.signer-list { list-style: none; margin: 0; padding: 0; width: 100%; display: grid; gap: 6px; }
.signer-list .empty { color: var(--muted); font-size: 13px; }
.signer { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.signer-main {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: var(--surface);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.signer-main:hover { background: #fafafa; }
.signer-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.signer-name.online::before { content: "● "; color: var(--success); }
.status { flex-shrink: 0; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.status.done { background: #dcfce7; color: var(--success); }
.status.wait { background: #fef3c7; color: #92400e; }
.signer-tools { display: flex; gap: 14px; padding: 6px 10px; border-top: 1px solid var(--border); background: #fafafa; }
.signer-tools { align-items: center; }
.signer-tools .link { font-size: 12px; }
.signer-code {
  margin-right: auto;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font: 700 13px/1.4 ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: 0.06em;
  user-select: all;
}
.link.danger { color: #b91c1c; }

.add-signer { display: flex; gap: 6px; width: 100%; }
.add-signer .input { padding: 8px 10px; font-size: 14px; }

/* ---------- Layar kecil (HP) ---------- */

@media (max-width: 900px) {
  .doc-layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: static;
    order: -1;
    min-height: 0;
    max-height: none;
    border-left: none;
    border-bottom: 1px solid var(--border);
    padding: 4px 16px;
  }
  .pages { padding: 20px 12px 90px; }
  .steps { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .brand-text { display: none; }
  .doc-page .support-text { display: none; }
  .actions { width: 100%; }
  .actions .btn { flex: 1; padding: 9px 8px; }
  .doc-page { --topbar: 112px; }
  .place-hint { white-space: normal; width: calc(100vw - 32px); font-size: 13px; }
}
