/* PDF Editor — dark neutral theme.
   @font-face registrations make the bundled TTFs available for on-screen
   editing; the same files are embedded by pdf-lib at export time. */

@font-face { font-family: 'Noto Nastaliq Urdu'; src: url('fonts/NotoNastaliqUrdu-Regular.ttf') format('truetype'); font-weight: 400; }
@font-face { font-family: 'Noto Nastaliq Urdu'; src: url('fonts/NotoNastaliqUrdu-Bold.ttf') format('truetype'); font-weight: 700; }
@font-face { font-family: 'Noto Naskh Arabic'; src: url('fonts/NotoNaskhArabic-Regular.ttf') format('truetype'); font-weight: 400; }
@font-face { font-family: 'Noto Naskh Arabic'; src: url('fonts/NotoNaskhArabic-Bold.ttf') format('truetype'); font-weight: 700; }
@font-face { font-family: 'Gulzar'; src: url('fonts/Gulzar-Regular.ttf') format('truetype'); font-weight: 400; }
@font-face { font-family: 'Scheherazade New'; src: url('fonts/ScheherazadeNew-Regular.ttf') format('truetype'); font-weight: 400; }
@font-face { font-family: 'Scheherazade New'; src: url('fonts/ScheherazadeNew-Bold.ttf') format('truetype'); font-weight: 700; }
@font-face { font-family: 'Lateef'; src: url('fonts/Lateef-Regular.ttf') format('truetype'); font-weight: 400; }
@font-face { font-family: 'Lateef'; src: url('fonts/Lateef-Bold.ttf') format('truetype'); font-weight: 700; }
@font-face { font-family: 'Roboto'; src: url('fonts/Roboto-Regular.ttf') format('truetype'); font-weight: 400; }
@font-face { font-family: 'Roboto'; src: url('fonts/Roboto-Bold.ttf') format('truetype'); font-weight: 700; }
@font-face { font-family: 'Poppins'; src: url('fonts/Poppins-Regular.ttf') format('truetype'); font-weight: 400; }
@font-face { font-family: 'Poppins'; src: url('fonts/Poppins-SemiBold.ttf') format('truetype'); font-weight: 600; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; display: flex; flex-direction: column;
  font-family: 'Segoe UI', Roboto, Arial, sans-serif;
  background: #1e1f24; color: #e8e9eb; overflow: hidden;
}
.hidden { display: none !important; }

/* ---------- toolbar ---------- */
#toolbar {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 6px 8px; background: #26282e; border-bottom: 1px solid #3a3d44;
  z-index: 30;
}
.tb-group { display: flex; align-items: center; gap: 4px; }
.tb-sep { width: 1px; height: 26px; background: #3f4249; margin: 0 3px; }
.tb-spacer { flex: 1; }
.tb-btn {
  background: #33363d; color: #e8e9eb; border: 1px solid #45484f;
  border-radius: 6px; padding: 6px 10px; font-size: 13px; cursor: pointer;
  white-space: nowrap; line-height: 1.2;
}
.tb-btn:hover:not(:disabled) { background: #3f4249; }
.tb-btn:disabled { opacity: .38; cursor: default; }
.tb-btn.primary { background: #1f6feb; border-color: #1f6feb; color: #fff; }
.tb-btn.primary:hover:not(:disabled) { background: #3580f5; }
.tb-btn.danger:hover:not(:disabled) { background: #6e2a2a; }
.tb-btn.big { font-size: 15px; padding: 10px 22px; }
.tool-btn.active { background: #1f6feb; border-color: #79b4ff; color: #fff; }
.tool-btn.inspect.active { background: #7a4fd0; border-color: #b79aff; }
.page-ind { font-size: 13px; color: #c9ccd1; min-width: 74px; text-align: center; }
#zoomLabel { min-width: 44px; }

/* ---------- layout ---------- */
#main { flex: 1; display: flex; min-height: 0; }

#leftPanel {
  width: 172px; background: #232529; border-right: 1px solid #3a3d44;
  overflow-y: auto; flex-shrink: 0; display: flex; flex-direction: column;
}
.lp-tabs { display: flex; border-bottom: 1px solid #33363d; }
.lp-tab {
  flex: 1; background: none; border: none; color: #9aa0a8; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; padding: 10px 4px; cursor: pointer;
}
.lp-tab.active { color: #fff; border-bottom: 2px solid #1f6feb; }
#ltab-pages { padding: 8px 6px; }
#ltab-elements { padding: 10px 10px 16px; }
.el-sec { margin-bottom: 16px; }
.el-sec h4 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: #9aa0a8; margin: 0 0 8px;
}
.el-add {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: #2b2e35; border: 1px solid #3a3d44; color: #eef0f2;
  border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; cursor: pointer; font-size: 13px;
}
.el-add:hover { background: #343842; border-color: #1f6feb; }
.el-prev {
  width: 34px; height: 30px; display: flex; align-items: center; justify-content: center;
  background: #17181c; border-radius: 6px; flex-shrink: 0;
}
.urdu-prev { font-family: 'Noto Nastaliq Urdu', serif; font-size: 15px; }
.shape-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.el-shape {
  background: #2b2e35; border: 1px solid #3a3d44; color: #eef0f2;
  border-radius: 8px; font-size: 22px; padding: 8px 4px; cursor: pointer;
}
.el-shape:hover { background: #343842; border-color: #1f6feb; }
.el-note { font-size: 11.5px; color: #9aa0a8; line-height: 1.5; margin-top: 8px; }
.drag-ghost {
  position: fixed; z-index: 9999; pointer-events: none;
  background: #1f6feb; color: #fff; font-size: 12px; font-weight: 600;
  padding: 6px 12px; border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.5);
  opacity: .92;
}
/* smart guides (Canva-style pink snap lines) */
.guide-line { position: absolute; background: #ff2d78; z-index: 60; pointer-events: none; }
.guide-v { width: 1px; top: 0; bottom: 0; }
.guide-h { height: 1px; left: 0; right: 0; }
.thumbs-hint { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #9aa0a8; text-align: center; margin-bottom: 6px; }
.thumb {
  margin: 0 auto 10px; cursor: pointer; text-align: center; padding: 5px 3px 3px;
  border: 2px solid transparent; border-radius: 6px; width: 128px;
}
.thumb canvas { background: #fff; box-shadow: 0 1px 5px rgba(0,0,0,.55); max-width: 118px; height: auto; }
.thumb .tno { font-size: 11px; color: #9aa0a8; margin-top: 3px; }
.thumb.active { border-color: #1f6feb; background: #2b2e35; }
.thumb.active .tno { color: #fff; }

#stageWrap { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#stageScroll {
  flex: 1; overflow: auto; padding: 26px; position: relative;
  display: flex; align-items: flex-start; justify-content: center;
  background: #17181c;
}
#pageStage { position: relative; box-shadow: 0 4px 28px rgba(0,0,0,.6); background: #fff; flex-shrink: 0; }
#pageCanvas { display: block; }
#overlay { position: absolute; inset: 0; overflow: visible; }
#drawSvg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
#drawSvg .pel-path { pointer-events: stroke; cursor: move; }
#drawSvg g.pel { pointer-events: all; cursor: move; }
#drawSvg g.pel.locked, .pel.locked { cursor: not-allowed; }
.pel.locked { outline: 1.5px dotted #f0a020 !important; }

/* ---------- layers panel ---------- */
.layer-row {
  display: flex; align-items: center; gap: 6px;
  background: #2b2e35; border: 1px solid #3a3d44; border-radius: 8px;
  padding: 6px 8px; margin-bottom: 6px; font-size: 13px; color: #eef0f2;
}
.layer-row.selected { border-color: #1f6feb; background: #31353e; }
.layer-row.hidden-el { opacity: .5; }
.layer-icon { font-size: 16px; width: 22px; text-align: center; flex-shrink: 0; }
.layer-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.layer-btn {
  background: none; border: none; color: #9aa0a8; font-size: 14px;
  cursor: pointer; padding: 2px 4px; border-radius: 4px;
}
.layer-btn:hover { color: #fff; background: #3a3d44; }
.layer-btn.on { color: #f0a020; }
.layers-actions { display: flex; gap: 6px; margin-bottom: 10px; }
#inspectLayer { position: absolute; inset: 0; pointer-events: none; }
.inspect-box {
  position: absolute; border: 1.5px solid rgba(31,111,235,.85); background: rgba(31,111,235,.10);
  cursor: pointer; pointer-events: auto; border-radius: 2px;
}
.inspect-box:hover { background: rgba(31,111,235,.28); border-color: #79b4ff; }
.inspect-box.img { border-color: rgba(212,140,32,.9); background: rgba(212,140,32,.10); }
.inspect-box.img:hover { background: rgba(212,140,32,.28); border-color: #ffb340; }
.inspect-box.picked { border-color: #2ea043; background: rgba(46,160,67,.22); }

#emptyState { margin: auto; text-align: center; }
.empty-card {
  background: #232529; border: 1.5px dashed #4a4d54; border-radius: 14px;
  padding: 44px 52px; max-width: 560px;
}
.empty-icon { font-size: 52px; }
.empty-card h2 { margin: 8px 0 6px; font-weight: 600; }
.empty-card p { color: #b9bdc4; font-size: 14px; line-height: 1.55; }
.empty-sub { font-size: 12.5px !important; color: #84898f !important; }

#statusBar {
  padding: 4px 12px; background: #26282e; border-top: 1px solid #3a3d44;
  font-size: 12.5px; color: #aeb2b9; min-height: 24px;
}

/* ---------- overlay elements ---------- */
.pel { position: absolute; box-sizing: border-box; }
.pel.image, .pel.shape { user-select: none; -webkit-user-select: none; }
.pel .textcontent[contenteditable="false"] { user-select: none; -webkit-user-select: none; }
.pel.text { cursor: move; }
.pel.text .textcontent {
  width: 100%; height: 100%; outline: none; white-space: pre-wrap; word-break: break-word;
  overflow: hidden; padding: 1px 2px; min-height: 1em;
}
.pel.text .textcontent[contenteditable="true"] { cursor: text; overflow: visible; background: rgba(31,111,235,.06); }
.pel.image img { width: 100%; height: 100%; display: block; pointer-events: none; }
.pel.shape { border-style: solid; }
.pel.selected-outline { outline: 1.5px dashed #1f6feb; outline-offset: 1px; }

#selBox {
  position: absolute; border: 1.5px solid #1f6feb; pointer-events: none; z-index: 60;
  box-shadow: 0 0 0 1px rgba(255,255,255,.35);
}
#selHandle {
  position: absolute; right: -8px; bottom: -8px; width: 14px; height: 14px;
  background: #1f6feb; border: 2px solid #fff; border-radius: 3px;
  cursor: nwse-resize; pointer-events: auto;
}
.rubber { position: absolute; border: 1.5px dashed #1f6feb; background: rgba(31,111,235,.12); z-index: 55; pointer-events: none; }

/* ---------- properties panel ---------- */
#props {
  width: 264px; background: #232529; border-left: 1px solid #3a3d44;
  overflow-y: auto; flex-shrink: 0; padding: 0 0 18px;
}
.props-tabs { display: flex; border-bottom: 1px solid #33363d; margin-bottom: 10px; }
.props-tab {
  flex: 1; background: none; border: none; color: #9aa0a8; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em; padding: 10px 4px; cursor: pointer;
}
.props-tab.active { color: #fff; border-bottom: 2px solid #1f6feb; }
#propsBody, #layersBody { padding: 0 14px; }
.props-hint { color: #9aa0a8; font-size: 13px; line-height: 1.55; }
.prop-row { margin-bottom: 11px; }
.prop-row label { display: block; font-size: 12px; color: #aeb2b9; margin-bottom: 4px; }
.prop-row input[type="text"], .prop-row input[type="number"], .prop-row select, .prop-row textarea {
  width: 100%; background: #17181c; color: #eef0f2; border: 1px solid #45484f;
  border-radius: 6px; padding: 6px 8px; font-size: 13.5px;
}
.prop-row textarea { min-height: 74px; resize: vertical; }
.prop-row textarea.urdu { font-family: 'Noto Nastaliq Urdu', serif; font-size: 16px; line-height: 2; }
.prop-inline { display: flex; gap: 8px; }
.prop-inline > div { flex: 1; }
.prop-row input[type="color"] { width: 100%; height: 32px; padding: 2px; background: #17181c; border: 1px solid #45484f; border-radius: 6px; }
.prop-row input[type="range"] { width: 100%; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 13.5px; margin: 7px 0; cursor: pointer; }
.check-row input { width: 16px; height: 16px; accent-color: #1f6feb; }
.props-btn {
  width: 100%; margin-top: 6px; background: #33363d; color: #eef0f2; border: 1px solid #45484f;
  border-radius: 6px; padding: 8px 10px; font-size: 13.5px; cursor: pointer;
}
.props-btn:hover { background: #3f4249; }
.props-btn.primary { background: #1f6feb; border-color: #1f6feb; color: #fff; }
.props-btn.danger { border-color: #7a3737; color: #ff9d94; }
.props-btn.danger:hover { background: #552626; }
.btn-row { display: flex; gap: 6px; }
.btn-row .props-btn { flex: 1; }
.props-btn.sm { padding: 6px 4px; font-size: 15px; margin-top: 0; }
.align-row .props-btn { flex: 1; }
.props-note { font-size: 12px; color: #84898f; line-height: 1.5; margin-top: 8px; }
.badge {
  display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 10px;
  background: #33363d; color: #c9ccd1; margin-bottom: 8px;
}

/* ---------- veils ---------- */
#dropVeil {
  position: fixed; inset: 0; background: rgba(20,40,80,.55); z-index: 100;
  display: flex; align-items: center; justify-content: center; pointer-events: none;
}
#dropVeil div {
  font-size: 26px; padding: 38px 58px; border: 3px dashed #79b4ff; border-radius: 16px;
  background: rgba(20,22,28,.85); color: #fff;
}
#busyVeil {
  position: fixed; inset: 0; background: rgba(12,13,15,.55); z-index: 110;
  display: flex; flex-direction: column; gap: 14px; align-items: center; justify-content: center;
  color: #fff; font-size: 15px;
}
.spinner {
  width: 42px; height: 42px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,.25); border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  #leftPanel { width: 128px; }
  .thumb { width: 92px; } .thumb canvas { max-width: 84px; }
  #props { width: 216px; }
}

/* ============ Templates, Auth & Cloud ============ */
.modal-veil { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-veil.hidden { display: none; }
.modal { background: #fff; border-radius: 14px; max-width: 860px; width: 100%;
  max-height: 88vh; overflow-y: auto; padding: 22px 24px; color: #1e293b;
  box-shadow: 0 24px 64px rgba(0,0,0,.3); }
.modal.small { max-width: 420px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.modal-head h3 { margin: 0; font-size: 19px; }
.modal-x { border: 0; background: #f1f5f9; border-radius: 8px; width: 32px; height: 32px;
  cursor: pointer; font-size: 14px; }
.modal-x:hover { background: #e2e8f0; }
.muted { color: #64748b; font-size: 13px; }
.muted.small { font-size: 12px; }
.tpl-cat { margin: 18px 0 8px; font-size: 14px; color: #0f766e; text-transform: uppercase; letter-spacing: .5px; }
.tpl-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.tpl-card { border: 1px solid #e2e8f0; border-radius: 10px; padding: 10px; cursor: pointer;
  background: #fff; transition: transform .12s, box-shadow .12s; text-align: left; }
.tpl-card:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(15,118,110,.15); border-color: #0f766e; }
.tpl-thumb { background: #f8fafc; border-radius: 6px; overflow: hidden; display: flex; justify-content: center; }
.tpl-thumb svg { max-width: 100%; height: auto; border: 1px solid #eef2f7; }
.tpl-name { font-weight: 700; margin-top: 8px; font-size: 14px; color: #1e293b; }
.tpl-desc { font-size: 12px; color: #64748b; }
.auth-tabs { display: flex; gap: 8px; margin: 10px 0 16px; }
.auth-tab { flex: 1; padding: 10px; border: 1px solid #e2e8f0; background: #f8fafc;
  border-radius: 8px; cursor: pointer; font-weight: 600; }
.auth-tab.active { background: #0f766e; color: #fff; border-color: #0f766e; }
.modal label { display: block; margin: 10px 0; font-size: 13px; font-weight: 600; }
.modal input { width: 100%; margin-top: 5px; padding: 10px 12px; border: 1px solid #cbd5e1;
  border-radius: 8px; font-size: 14px; box-sizing: border-box; }
.modal input:focus { outline: 2px solid #0f766e; border-color: #0f766e; }
.auth-err { color: #dc2626; font-size: 13px; min-height: 18px; margin: 6px 0; }
.tb-btn.full { width: 100%; margin-top: 8px; }
.tb-btn.big { padding: 12px 22px; font-size: 15px; }
.design-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-top: 12px; }
.design-card { border: 1px solid #e2e8f0; border-radius: 10px; overflow: hidden; background: #fff; }
.design-card img { width: 100%; height: 130px; object-fit: cover; background: #f8fafc; display: block; }
.design-ph { height: 130px; display: flex; align-items: center; justify-content: center;
  font-size: 40px; background: #f8fafc; }
.design-name { font-weight: 700; padding: 8px 10px 0; font-size: 14px; }
.design-date { font-size: 11px; color: #94a3b8; padding: 0 10px; }
.design-actions { display: flex; gap: 8px; padding: 8px 10px 10px; }
.mini-btn { flex: 1; padding: 7px; border-radius: 7px; border: 1px solid #cbd5e1;
  background: #f8fafc; cursor: pointer; font-size: 13px; font-weight: 600; }
.mini-btn.open { background: #0f766e; color: #fff; border-color: #0f766e; }
.mini-btn.danger { color: #dc2626; }
.mini-btn:hover { filter: brightness(.95); }
.tb-btn.logged-in { background: #e6f7f4; border-color: #0f766e; color: #0f766e; font-weight: 700; }
#btnOpen2tpl { margin-left: 8px; }
@media (max-width: 640px) {
  .modal { padding: 16px; }
  .tpl-row { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}
