/* ==========================================================
   TTD.in — Editor dokumen
   ========================================================== */
[hidden] { display: none !important; }
body.editing { overflow: hidden; }
body.editing .site { display: none; }

.editor { display: none; position: fixed; inset: 0; z-index: 100; background: #e9edf3; flex-direction: column; }
body.editing .editor { display: flex; }

/* Topbar */
.ed-top {
  display: flex; align-items: center; gap: 12px; height: 64px; padding: 0 16px;
  background: #fff; border-bottom: 1px solid var(--ink-200); flex: none;
}
.ed-top .logo { font-size: 18px; }
.ed-top .logo img { width: 30px; height: 30px; }
.ed-file { display: flex; align-items: center; gap: 8px; min-width: 0; padding-left: 12px; margin-left: 4px; border-left: 1px solid var(--ink-200); }
.ed-file svg { width: 18px; height: 18px; color: var(--ink-400); flex: none; }
.ed-file span { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30vw; }
.ed-file small { font-size: 12px; color: var(--ink-500); white-space: nowrap; background: var(--ink-100); padding: 2px 8px; border-radius: 999px; }
.ed-spacer { flex: 1; }
.ed-secure { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ok); font-weight: 600; padding: 6px 10px; background: var(--ok-bg); border-radius: 999px; }
.ed-secure svg { width: 15px; height: 15px; }

/* Banner peringatan dokumen bertanda tangan digital / e-Meterai */
.ed-banner {
  display: flex; align-items: flex-start; gap: 12px; padding: 10px 16px; flex: none;
  background: #fffbeb; border-bottom: 1px solid #fde68a; color: #78350f; font-size: 13.5px;
}
.ed-banner > svg { width: 20px; height: 20px; flex: none; color: #d97706; margin-top: 1px; }
.ed-banner span { flex: 1; }
.ed-banner .icon-btn { width: 30px; height: 30px; color: #92400e; }

/* Download dropdown */
.dl { position: relative; }
.dl-menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 240px; padding: 6px;
  background: #fff; border-radius: 12px; border: 1px solid var(--ink-200); box-shadow: var(--shadow-lg);
  display: none; z-index: 20;
}
.dl.open .dl-menu { display: block; }
.dl-menu button {
  display: flex; gap: 12px; align-items: center; width: 100%; padding: 10px 12px; border: 0; background: none;
  border-radius: 8px; cursor: pointer; text-align: left;
}
.dl-menu button:hover { background: var(--ink-100); }
.dl-menu svg { width: 20px; height: 20px; color: var(--brand-600); flex: none; }
.dl-menu b { display: block; font-size: 14px; }
.dl-menu small { color: var(--ink-500); font-size: 12px; }

/* Body */
.ed-body { flex: 1; display: flex; min-height: 0; position: relative; }

/* Panel kiri */
.ed-tools {
  width: 264px; flex: none; background: #fff; border-right: 1px solid var(--ink-200);
  padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 22px;
}
.ed-tools h4 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-400); font-weight: 700; }

/* Pustaka tanda tangan */
.lib-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.lib-head h4 { margin: 0; color: var(--ink-700); }
.lib-add {
  display: inline-flex; align-items: center; gap: 4px; height: 30px; padding: 0 10px; border-radius: 8px;
  border: 0; background: var(--brand-600); color: #fff; font-size: 13px; font-weight: 600; cursor: pointer;
}
.lib-add:hover { background: var(--brand-700); }
.lib-add svg { width: 14px; height: 14px; }
.lib-list { display: grid; gap: 8px; }
.lib-item {
  position: relative; height: 76px; border: 1.5px solid var(--ink-200); border-radius: 12px; background: #fff;
  display: grid; place-items: center; padding: 8px 30px; cursor: grab; touch-action: none;
  transition: border-color .15s, box-shadow .15s, transform .1s; user-select: none; -webkit-user-select: none;
}
.lib-item:hover { border-color: var(--brand-500); box-shadow: 0 4px 14px -6px rgba(79, 70, 229, .35); }
.lib-item:active { cursor: grabbing; transform: scale(.98); }
.lib-item img { max-height: 58px; max-width: 100%; object-fit: contain; pointer-events: none; -webkit-user-drag: none; }
.lib-item .grip { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; color: var(--ink-400); }
.lib-badge { position: absolute; left: 6px; bottom: 5px; font-size: 10px; font-weight: 700; color: var(--brand-700); background: var(--brand-50); padding: 1px 6px; border-radius: 6px; letter-spacing: .03em; }
.lib-item .x, .saved-item .x {
  position: absolute; top: 5px; right: 5px; width: 24px; height: 24px; border-radius: 6px; border: 0;
  background: transparent; color: var(--ink-400); cursor: pointer; display: grid; place-items: center;
}
.lib-item .x:hover, .saved-item .x:hover { background: #fee2e2; color: var(--danger); }
.lib-item .x svg, .saved-item .x svg { width: 14px; height: 14px; }
.lib-empty { display: grid; gap: 8px; padding: 14px; border: 1.5px dashed var(--brand-200); border-radius: 12px; background: var(--brand-50); text-align: center; }
.lib-empty p { margin: 0 0 4px; font-size: 13px; color: var(--ink-700); }
.lib-empty .btn { height: 36px; font-size: 13px; }
.lib-hint { margin: 8px 0 0; font-size: 12px; color: var(--ink-400); }

.drag-ghost {
  position: fixed; left: 0; top: 0; z-index: 400; pointer-events: none; width: 170px; padding: 6px;
  background: rgba(255,255,255,.85); border: 1.5px solid var(--brand-500); border-radius: 10px;
  box-shadow: var(--shadow-lg); opacity: .95;
}
.drag-ghost img { width: 100%; height: auto; display: block; }
.page.drop-target { box-shadow: 0 0 0 3px var(--brand-500), 0 8px 30px rgba(79, 70, 229, .25); }

.tool-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px;
  border: 1px solid var(--ink-200); border-radius: 12px; background: #fff; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--ink-700); transition: border-color .15s, background .15s, color .15s;
}
.tool:hover { border-color: var(--brand-500); color: var(--brand-700); background: var(--brand-50); }
.tool svg { width: 22px; height: 22px; }
.tool-meterai { grid-column: span 2; flex-direction: row; justify-content: center; }

.tip { font-size: 12.5px; color: var(--ink-500); background: var(--ink-50); border: 1px solid var(--ink-200); border-radius: 12px; padding: 12px; }
.tip b { color: var(--ink-700); }

/* Area halaman */
.ed-stage { flex: 1; overflow: auto; position: relative; scrollbar-gutter: stable; }
.ed-pages { display: flex; flex-direction: column; align-items: center; gap: 28px; padding: 32px 24px 120px; min-width: min-content; }
.page {
  position: relative; background: #fff; box-shadow: 0 2px 10px rgba(15, 23, 42, .12), 0 0 0 1px rgba(15, 23, 42, .04);
  flex: none; user-select: none; -webkit-user-select: none; touch-action: pan-x pan-y; transition: box-shadow .15s;
}
.page canvas { display: block; width: 100%; height: 100%; }
.page-label { position: absolute; left: 0; top: -22px; font-size: 12px; color: var(--ink-500); font-weight: 600; }

/* Zoom */
.ed-zoom {
  position: absolute; right: 20px; bottom: 20px; display: flex; align-items: center; gap: 2px;
  background: #fff; padding: 4px; border-radius: 12px; box-shadow: var(--shadow); border: 1px solid var(--ink-200); z-index: 5;
}
.ed-zoom button { width: 36px; height: 36px; border: 0; background: none; border-radius: 8px; cursor: pointer; display: grid; place-items: center; }
.ed-zoom button:hover { background: var(--ink-100); }
.ed-zoom svg { width: 18px; height: 18px; }
.ed-zoom span { min-width: 48px; text-align: center; font-size: 13px; font-weight: 600; }

/* Elemen di atas halaman */
.el {
  position: absolute; cursor: move; touch-action: none;
  outline: 1.5px dashed transparent; outline-offset: 2px; border-radius: 2px;
}
.el:hover { outline-color: var(--brand-200); }
.el.selected { outline: 1.5px solid var(--brand-500); z-index: 2; }
.el img { width: 100%; height: 100%; display: block; pointer-events: none; -webkit-user-drag: none; }
.el .txt { white-space: pre; line-height: 1.15; outline: none; padding: 0 1px; cursor: move; }
.el .txt:empty::before { content: attr(data-ph); color: var(--ink-400); }
.el.editing .txt { cursor: text; user-select: text; -webkit-user-select: text; }
.el .handle {
  position: absolute; width: 16px; height: 16px; right: -10px; bottom: -10px; border-radius: 50%;
  background: #fff; border: 2px solid var(--brand-500); cursor: nwse-resize; display: none; touch-action: none;
}
.el .handle::after { content: ""; position: absolute; inset: -10px; }
.el.selected .handle { display: block; }
.el-bar {
  position: absolute; left: 50%; top: -48px; transform: translateX(-50%);
  display: none; gap: 2px; padding: 4px; background: var(--ink-900); border-radius: 10px; box-shadow: var(--shadow);
  white-space: nowrap; z-index: 3;
}
.el.selected .el-bar { display: flex; }
.el.near-top .el-bar { top: auto; bottom: -48px; }
.el-bar button {
  height: 32px; min-width: 32px; padding: 0 8px; border: 0; border-radius: 7px; background: none; color: #fff;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600;
}
.el-bar button:hover { background: rgba(255,255,255,.14); }
.el-bar button.danger:hover { background: var(--danger); }
.el-bar svg { width: 16px; height: 16px; }
.el-bar .sw { width: 18px; height: 18px; min-width: 18px; padding: 0; border-radius: 50%; border: 2px solid rgba(255,255,255,.7); margin: 0 3px; }

/* Loading */
.ed-loading { position: absolute; inset: 0; display: none; place-items: center; background: rgba(233, 237, 243, .88); z-index: 30; }
.ed-loading.show { display: grid; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid var(--brand-100); border-top-color: var(--brand-600); animation: spin .8s linear infinite; margin: 0 auto 14px; }
.ed-loading p { margin: 0; font-weight: 600; color: var(--ink-700); text-align: center; padding: 0 20px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Wadah render dokumen Word (di luar layar) */
.docx-host {
  position: absolute; left: -30000px; top: 0; background: #fff; width: max-content;
  font-family: Calibri, Carlito, "Segoe UI", Arial, sans-serif; font-size: 11pt; line-height: 1.15; color: #000;
}
.docx-host section.docx { margin: 0 0 20px; box-shadow: none; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 200; display: none; align-items: center; justify-content: center; padding: 16px; background: rgba(15, 23, 42, .55); backdrop-filter: blur(4px); }
.modal.open { display: flex; }
.modal-card { width: 100%; max-width: 680px; background: #fff; border-radius: 20px; box-shadow: var(--shadow-lg); overflow: hidden; display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.modal-sm { max-width: 540px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px 0; }
.modal-head h3 { margin: 0; font-size: 19px; letter-spacing: -.01em; }
.icon-btn { width: 38px; height: 38px; border: 0; border-radius: 10px; background: none; cursor: pointer; display: grid; place-items: center; color: var(--ink-500); flex: none; }
.icon-btn:hover { background: var(--ink-100); color: var(--ink-900); }
.icon-btn svg { width: 20px; height: 20px; }
.tabs { display: flex; gap: 2px; padding: 14px 22px 0; border-bottom: 1px solid var(--ink-200); overflow-x: auto; scrollbar-width: none; flex: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 10px 12px; border: 0; background: none; cursor: pointer; font-weight: 600; font-size: 14px; color: var(--ink-500);
  border-bottom: 2px solid transparent; margin-bottom: -1px; display: inline-flex; gap: 7px; align-items: center; white-space: nowrap; flex: none;
}
.tab svg { width: 17px; height: 17px; }
.tab:hover { color: var(--ink-900); }
.tab.active { color: var(--brand-600); border-color: var(--brand-600); }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.pane { display: none; }
.pane.active { display: block; }
.pane-intro { margin: 0 0 12px; font-size: 14px; color: var(--ink-700); }
.pane-alt { margin: 14px 0 0; font-size: 14px; color: var(--ink-500); }
.pane-note { margin: 14px 0 0; font-size: 13px; color: var(--ink-500); }
.link-btn { border: 0; background: none; padding: 0; color: var(--brand-600); font-weight: 600; cursor: pointer; font-size: inherit; }
.link-btn:hover { color: var(--brand-700); text-decoration: underline; }

.pad-wrap { position: relative; border: 1px solid var(--ink-200); border-radius: 14px; background: #fff; overflow: hidden; }
.pad-wrap canvas { display: block; width: 100%; height: 230px; touch-action: none; cursor: crosshair; }
.pad-line { position: absolute; left: 28px; right: 28px; bottom: 56px; border-top: 1.5px dashed var(--ink-200); pointer-events: none; }
.pad-hint { position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%); text-align: center; color: var(--ink-400); font-size: 15px; pointer-events: none; transition: opacity .2s; }
.pad-wrap.dirty .pad-hint { opacity: 0; }
.pad-actions { position: absolute; right: 8px; top: 8px; display: flex; gap: 4px; }
.pad-actions button { height: 32px; padding: 0 10px; border: 1px solid var(--ink-200); background: #fff; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; color: var(--ink-700); }
.pad-actions button:hover { border-color: var(--ink-400); }
.pad-actions svg { width: 15px; height: 15px; }

.field { display: block; width: 100%; height: 46px; padding: 0 14px; border: 1px solid var(--ink-200); border-radius: 12px; font-size: 16px; background: #fff; }
.field:focus { outline: none; border-color: var(--brand-500); box-shadow: 0 0 0 4px var(--brand-100); }
.font-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.font-opt {
  height: 76px; border: 1.5px solid var(--ink-200); border-radius: 12px; background: #fff; cursor: pointer;
  font-size: 30px; padding: 0 12px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; line-height: 76px; text-align: center;
}
.font-opt:hover { border-color: var(--ink-400); }
.font-opt.active { border-color: var(--brand-500); box-shadow: 0 0 0 3px var(--brand-100); }

.upload-box { border: 2px dashed var(--ink-200); border-radius: 14px; min-height: 210px; display: grid; place-items: center; text-align: center; padding: 20px; cursor: pointer; background: var(--ink-50); }
.upload-box:hover, .upload-box.drag { border-color: var(--brand-500); background: var(--brand-50); }
.upload-box svg { width: 36px; height: 36px; color: var(--brand-600); margin: 0 auto 10px; }
.upload-box p { margin: 0; color: var(--ink-500); font-size: 14px; }
.upload-box b { color: var(--ink-900); display: block; margin-bottom: 4px; font-size: 15px; }
.upload-box img { max-height: 170px; max-width: 100%; margin: 0 auto; }
.upload-opts { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 14px; color: var(--ink-700); }

/* QR */
.qr-grid { display: grid; grid-template-columns: 1fr 210px; gap: 20px; align-items: start; }
.qr-form { display: grid; gap: 12px; }
.fl { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink-700); }
.fl em { color: var(--danger); font-style: normal; }
.fl .opt { font-weight: 400; color: var(--ink-400); }
.qr-form .check { font-size: 13.5px; }
.qr-preview { position: sticky; top: 0; text-align: center; padding: 14px; border: 1px solid var(--ink-200); border-radius: 14px; background: var(--ink-50); }
.qr-preview img { width: 100%; height: auto; background: #fff; border-radius: 8px; min-height: 120px; }
.qr-preview small { display: block; margin-top: 10px; font-size: 12px; color: var(--ink-500); }

/* Tersimpan */
.saved-list { display: grid; gap: 8px; }
.saved-grid { grid-template-columns: repeat(2, 1fr); }
.saved-item {
  position: relative; height: 96px; border: 1px solid var(--ink-200); border-radius: 12px; background: #fff;
  display: grid; place-items: center; padding: 8px 28px; cursor: pointer; transition: border-color .15s, box-shadow .15s;
}
.saved-item:hover { border-color: var(--brand-500); box-shadow: var(--shadow-sm); }
.saved-item img { max-height: 76px; max-width: 100%; object-fit: contain; }
.saved-empty { font-size: 13px; color: var(--ink-400); padding: 12px; border: 1px dashed var(--ink-200); border-radius: 12px; text-align: center; }

.modal-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 16px 22px; border-top: 1px solid var(--ink-200); background: var(--ink-50); flex: none; }
.colors { display: flex; align-items: center; gap: 8px; }
.colors span { font-size: 13px; color: var(--ink-500); margin-right: 2px; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--ink-200); cursor: pointer; padding: 0; }
.swatch.active { box-shadow: 0 0 0 2px var(--brand-500); }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-700); cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brand-600); flex: none; }
.modal-foot .grow { flex: 1; }

/* e-Meterai */
.meterai-body p { margin: 0 0 14px; font-size: 14.5px; color: var(--ink-700); }
.meterai-steps { margin: 0 0 18px; padding-left: 20px; display: grid; gap: 10px; font-size: 14px; color: var(--ink-700); }
.meterai-links { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.lib-head h4 { white-space: nowrap; letter-spacing: .05em; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); z-index: 300;
  background: var(--ink-900); color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
  display: flex; gap: 10px; align-items: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }
.toast svg { width: 18px; height: 18px; flex: none; }

/* ---------- Responsif editor (HP & tablet kecil) ---------- */
@media (max-width: 860px) {
  .ed-secure, .ed-file small { display: none; }
  .ed-file span { max-width: 34vw; }
  .ed-top { padding: 0 10px; gap: 8px; }
  .ed-top .logo span { display: none; }
  .ed-top .btn-outline { display: none; }

  .ed-tools {
    position: fixed; left: 0; right: 0; bottom: 0; width: auto; z-index: 20; overflow: visible;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); gap: 10px;
    border-right: 0; border-top: 1px solid var(--ink-200); box-shadow: 0 -6px 20px rgba(15,23,42,.08);
  }
  .ed-tools .tip, .ed-tools h4, .lib-hint { display: none; }
  .lib { display: flex; align-items: center; gap: 8px; }
  .lib-head { margin: 0; flex: none; }
  .lib-add { height: 56px; width: 56px; padding: 0; flex-direction: column; justify-content: center; border-radius: 12px; font-size: 11px; gap: 2px; }
  .lib-add svg { width: 18px; height: 18px; }
  .lib-list { display: flex; gap: 8px; overflow-x: auto; flex: 1; scrollbar-width: none; padding: 2px; }
  .lib-list::-webkit-scrollbar { display: none; }
  .lib-item { flex: none; width: 108px; height: 56px; padding: 6px 22px 6px 8px; touch-action: pan-x; }
  .lib-item img { max-height: 42px; }
  .lib-item .grip { display: none; }
  .lib-item .x { top: 2px; right: 2px; width: 22px; height: 22px; }
  .lib-empty { flex: 1; padding: 8px 10px; display: flex; align-items: center; text-align: left; }
  .lib-empty p { margin: 0; font-size: 12px; flex: 1; }
  .lib-empty .btn { display: none; }

  .tool-grid { display: flex; gap: 6px; }
  .tool, .tool-meterai { flex: 1; min-width: 0; padding: 7px 2px; font-size: 11px; gap: 3px; flex-direction: column; grid-column: auto; }
  .tool svg { width: 19px; height: 19px; }

  .ed-pages { padding: 28px 12px 200px; }
  .ed-zoom { bottom: 172px; right: 12px; }
  body.editing .toast { bottom: auto; top: 76px; transform: translate(-50%, -12px); }
  body.editing .toast.show { transform: translate(-50%, 0); }
}
@media (max-width: 600px) {
  .qr-grid { grid-template-columns: 1fr; }
  .qr-preview { position: static; max-width: 190px; margin: 0 auto; order: -1; padding: 10px; }
}
@media (max-width: 520px) {
  .font-list, .saved-grid { grid-template-columns: 1fr; }
  .modal { padding: 0; align-items: flex-end; }
  .modal-card { border-radius: 20px 20px 0 0; max-height: 94vh; }
  .modal-foot .colors { width: 100%; }
  .modal-foot .grow, .modal-foot .btn-ghost { display: none; }
  .modal-foot .btn-primary { flex: 1; }
  .tabs { padding: 12px 12px 0; }
  .tab { padding: 10px 9px; }
}
