/* Global reset + base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #f5f7fa;
  color: #1a1a2e;
  line-height: 1.5;
}

/* HEADER */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  background: #fff;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.06);
  position: sticky;
  top: 0;
  z-index: 10;
}

.logo-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.logo span {
  color: #e63946;
}
.logo-owner {
  margin-left: 32px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #999;
}

.nav a {
  margin-left: 22px;
  text-decoration: none;
  color: #444;
  font-weight: 500;
}
.nav a:hover {
  color: #e63946;
}

/* HERO */
.hero {
  text-align: center;
  padding: 64px 20px 40px;
}
.hero h1 {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: 14px;
}
.hero p {
  color: #555;
  max-width: 560px;
  margin: 0 auto;
}

/* TOOL MENU (categorized columns) */
.tools {
  max-width: 1300px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px 28px;
  align-items: start;
}

.cat {
  display: flex;
  flex-direction: column;
}

.cat-title {
  font-size: 1rem;
  color: #6b7280;
  font-weight: 600;
  margin: 18px 0 10px;
}
.cat-title:first-child {
  margin-top: 0;
}

.tool {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 8px;
  border-radius: 8px;
  text-decoration: none;
  color: #1a1a2e;
  font-weight: 500;
  font-size: 0.97rem;
  cursor: pointer;
  transition: background 0.12s ease;
}
.tool:hover {
  background: #eef1f6;
}

/* small colored icon tiles */
.ti {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  font-size: 1.05rem;
  flex-shrink: 0;
  background: #e5e7eb;
}
.ti.red    { background: #fde2e2; }
.ti.blue   { background: #dbe7ff; }
.ti.green  { background: #d8f3e3; }
.ti.purple { background: #e7ddff; }
.ti.teal   { background: #d4f1f4; }
.ti.orange { background: #ffe6cc; }
.ti.yellow { background: #fff3cc; }
.ti.pink   { background: #ffe0ef; }

/* PAGE LOADING (shown briefly on first load before auth.js decides what to show) */
.page-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 120px 20px;
  color: #777;
  font-size: 0.95rem;
}
.page-loading .spinner {
  width: 30px;
  height: 30px;
  border-width: 3px;
  margin-right: 0;
}
.page-loading.hidden {
  display: none;
}

/* FOOTER */
.footer {
  text-align: center;
  padding: 30px 20px;
  margin-top: 30px;
  color: #777;
  font-size: 0.9rem;
}
.footer-founder {
  margin-top: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #555;
}
.footer-dot {
  margin: 0 8px;
  opacity: 0.6;
}
.footer-founder a {
  color: #e63946;
  text-decoration: none;
  font-weight: 600;
}
.footer-founder a:hover {
  text-decoration: underline;
}

/* MODAL (tool popup) */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal.hidden {
  display: none;
}
.modal-box {
  background: #fff;
  border-radius: 14px;
  padding: 28px;
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.modal-box.wide {
  max-width: 760px;
}

/* always hide the hidden file picker (belt-and-suspenders) */
input[type="file"][hidden] {
  display: none !important;
}

/* file manager grid */
.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
  margin: 16px 0;
  max-height: 60vh;
  overflow-y: auto;
}
.file-card {
  position: relative;
  border: 1px solid #e3e6ec;
  border-radius: 10px;
  padding: 10px;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.card-remove {
  position: absolute;
  top: 4px;
  right: 6px;
  border: none;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  color: #888;
}
.card-remove:hover {
  color: #e63946;
}
.thumb {
  width: 100%;
  height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #f7f8fa;
  border-radius: 6px;
  margin-bottom: 8px;
}
.thumb canvas,
.thumb img {
  max-width: 100%;
  max-height: 100%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}
.thumb-fallback {
  font-size: 3rem;
}
.card-name {
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.card-meta {
  font-size: 0.74rem;
  color: #888;
}
/* dashed add tile */
.add-tile {
  border: 2px dashed #b8c2d6;
  justify-content: center;
  min-height: 200px;
  cursor: pointer;
  color: #4a72ff;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  gap: 8px;
}
.add-tile:hover {
  background: #f3f6ff;
  border-color: #4a72ff;
}
.add-plus {
  font-size: 2rem;
}

/* ===== unified editor (editor.js) ===== */
.ed2-scroll {
  max-height: 60vh;
  overflow: auto;
  background: #eef1f6;
  border-radius: 8px;
  padding: 16px;
  text-align: center;
}
.ed2-stage {
  position: relative;
  display: inline-block;
  line-height: 0;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}
.ed2-stage canvas { display: block; max-width: none; }
.ed2-anno { position: absolute; left: 0; top: 0; pointer-events: none; }
.ed2-stage.ed2-penmode .ed2-anno { pointer-events: auto; cursor: crosshair; }
.ed2-layer { position: absolute; left: 0; top: 0; }
.ed2-stage.ed2-markmode .ed2-layer { cursor: crosshair; }
/* optional grid */
.ed2-stage.ed2-showgrid::before {
  content: "";
  position: absolute; inset: 0; pointer-events: none; z-index: 1;
  background-image:
    linear-gradient(to right, rgba(74,114,255,0.12) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(74,114,255,0.12) 1px, transparent 1px);
  background-size: 20px 20px;
}
.ed2-obj {
  position: absolute;
  transform-origin: center center;
  line-height: 1.25;
}
.ed2-obj.sel { outline: 1px solid #4a72ff; }
.ed2-content {
  display: block;
  width: 100%;
  outline: none;
  white-space: pre-wrap;
  word-break: break-word;
  cursor: text;
}
.ed2-image img, .ed2-obj img { width: 100%; height: 100%; display: block; }
.ed2-rect { }
/* replace-mode hotspots */
.ed2-hot { position: absolute; left: 0; top: 0; width: 100%; height: 100%; z-index: 3; }
.ed2-stage.ed2-replacemode .ed2-hot span { position: absolute; cursor: text; border-radius: 2px; }
.ed2-stage.ed2-replacemode .ed2-hot span:hover { background: rgba(74,114,255,0.2); outline: 1px solid rgba(74,114,255,0.6); }
.ed2-hot span { position: absolute; pointer-events: auto; }
/* selection box + handles */
.ed2-selbox {
  position: absolute;
  border: 1px dashed #4a72ff;
  pointer-events: none;
  transform-origin: center center;
  z-index: 4;
}
.ed2-handle { position: absolute; pointer-events: auto; }
.ed2-resize {
  right: -7px; bottom: -7px; width: 14px; height: 14px;
  background: #fff; border: 2px solid #4a72ff; border-radius: 50%;
  cursor: nwse-resize;
}
.ed2-rotate {
  left: 50%; top: -26px; margin-left: -8px; width: 16px; height: 16px;
  background: #4a72ff; border-radius: 50%; cursor: grab;
}
.ed2-form {
  background: #f5f7fa; border-radius: 8px; padding: 12px;
  margin-bottom: 10px; max-height: 30vh; overflow-y: auto;
}

/* converter hub */
.conv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.conv-btn {
  padding: 14px 10px;
  font-weight: 600;
}

/* AI panels */
.ai-log {
  margin-top: 12px;
  max-height: 40vh;
  overflow-y: auto;
  background: #f5f7fa;
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ai-msg {
  padding: 8px 12px;
  border-radius: 10px;
  max-width: 85%;
  white-space: pre-wrap;
  font-size: 0.92rem;
}
.ai-msg.user {
  align-self: flex-end;
  background: #4a72ff;
  color: #fff;
}
.ai-msg.bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid #e3e6ec;
}
.ai-out {
  margin-top: 12px;
  background: #f5f7fa;
  border-radius: 8px;
  padding: 14px;
  white-space: pre-wrap;
  font-size: 0.92rem;
  max-height: 45vh;
  overflow-y: auto;
}

/* annotator: toolbar + drawing overlay */
.anno-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.anno-tool {
  border: 1px solid #d8dde6;
  background: #fff;
  border-radius: 8px;
  width: 38px;
  height: 34px;
  font-size: 1.05rem;
  cursor: pointer;
}
.anno-tool.active {
  border-color: #4a72ff;
  background: #eef3ff;
}
.anno-bar input[type="color"] {
  width: 38px;
  height: 34px;
  border: 1px solid #d8dde6;
  border-radius: 8px;
  padding: 2px;
  cursor: pointer;
  background: #fff;
}
.anno-overlay {
  position: absolute;
  left: 0;
  top: 0;
  cursor: crosshair;
  touch-action: none;
}
.anno-sel {
  height: 34px;
  border: 1px solid #d8dde6;
  border-radius: 8px;
  padding: 0 6px;
  background: #fff;
  font-size: 0.85rem;
  cursor: pointer;
}
.anno-hint {
  font-size: 0.78rem;
  color: #8a93a6;
  margin: 0 0 8px;
}
/* keep annotator page at true pixel size for accurate coords */
.anno-stage canvas {
  max-width: none;
}
.anno-textlayer {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.anno-textlayer.editing .anno-text {
  pointer-events: auto;
  cursor: move;
}
.anno-text {
  position: absolute;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
  font-weight: 600;
}
.anno-textlayer.editing .anno-text {
  outline: 1px dashed rgba(74, 114, 255, 0.7);
  padding: 1px 2px;
}
.anno-text-x {
  display: none;
  position: absolute;
  top: -10px;
  right: -10px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #e63946;
  color: #fff;
  font-size: 0.8rem;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
}
.anno-textlayer.editing .anno-text:hover .anno-text-x {
  display: block;
}

/* reader: toolbar + scrollable pages */
.reader-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  position: sticky;
  top: 0;
  background: #fff;
  border-bottom: 1px solid #eee;
  margin-bottom: 10px;
}
.reader-bar #rdZoom {
  min-width: 48px;
  text-align: center;
  font-size: 0.9rem;
}
.reader-pages {
  max-height: 62vh;
  overflow-y: auto;
  background: #eef1f6;
  padding: 14px;
  border-radius: 8px;
  text-align: center;
}
.reader-page {
  display: block;
  margin: 0 auto 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  max-width: 100%;
}

/* sign: page stage, pad, placed signature */
.sign-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 10px;
  font-size: 0.9rem;
  color: #555;
}
.sign-stage {
  position: relative;
  display: inline-block;
  line-height: 0;
  border: 1px solid #e3e6ec;
  border-radius: 6px;
  overflow: hidden;
  max-width: 100%;
}
.sign-stage canvas {
  display: block;
  max-width: 100%;
}
.sign-placed {
  position: absolute;
  cursor: move;
  border: 1px dashed #4a72ff;
  background: rgba(74, 114, 255, 0.05);
  touch-action: none;
}
.sign-pad {
  border: 1px dashed #b8c2d6;
  border-radius: 8px;
  background: #fcfcfe;
  width: 100%;
  max-width: 400px;
  touch-action: none;
  cursor: crosshair;
}

/* organize: page thumbnails grid */
.page-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 14px;
  margin: 16px 0;
  max-height: 55vh;
  overflow-y: auto;
}
.page-tile {
  position: relative;
  border: 1px solid #e3e6ec;
  border-radius: 8px;
  padding: 8px;
  background: #fff;
  cursor: grab;
  text-align: center;
}
.page-tile.dragging {
  opacity: 0.4;
}
.page-tile:active {
  cursor: grabbing;
}
.page-tools {
  position: absolute;
  top: 4px;
  right: 4px;
  display: flex;
  gap: 4px;
}
.page-btn {
  border: none;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  color: #555;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.page-btn:hover {
  color: #e63946;
}
.page-thumb {
  height: 130px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.page-thumb img {
  max-width: 100%;
  max-height: 100%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  transition: transform 0.15s ease;
}
.page-num {
  margin-top: 6px;
  font-size: 0.8rem;
  color: #666;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  border: none;
  background: none;
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  color: #888;
}
.modal-close:hover {
  color: #e63946;
}
.modal-box h2 {
  margin-bottom: 14px;
}
.modal-box p {
  color: #555;
  margin-bottom: 14px;
}
.modal-box input[type="file"] {
  display: block;
  width: 100%;
  margin-bottom: 16px;
}
.btn {
  background: #e63946;
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
.btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}
.status {
  margin-top: 12px;
  font-size: 0.92rem;
}
.lbl {
  display: block;
  font-size: 0.9rem;
  color: #444;
  margin-bottom: 6px;
}
.text-input {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
  margin-bottom: 14px;
  font-size: 0.95rem;
}
.auth-password-wrap {
  position: relative;
  margin-bottom: 14px;
}
.auth-password-wrap .text-input {
  margin-bottom: 0;
  padding-right: 56px;
}
.auth-password-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: #e63946;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  padding: 6px 8px;
}
.auth-password-toggle:hover {
  text-decoration: underline;
}
.btn-light {
  background: #f0f0f3;
  color: #1a1a2e;
  margin-left: 8px;
}
.btn-light:hover {
  background: #e4e4ea;
}
.soon {
  text-align: center;
  font-size: 1.05rem;
  padding: 16px 0;
}

/* Mobile tweaks consolidated into the single @media (max-width: 720px) block
   in theme.css — that breakpoint is wider and already covers .hero h1 and
   .header, so a separate 600px block here was redundant (and its .header
   rule was already dead: theme.css loads after this file, so its value won
   the cascade at every width below 600px anyway). */
