:root {
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f8fafc;
  --card: #ffffff;
  --danger: #dc2626;
  --ok: #059669;
  --radius: 12px;
  --pad: 16px;
}

* { box-sizing: border-box; }

/* The [hidden] attribute must always win.
   An author rule that sets display on the same element (for example .overlay { display:flex }
   or .edit-fields { display:grid }) overrides the browser default of [hidden]{display:none}, so
   the element stays on screen even though JS set hidden = true. That is what left the library
   modal stuck open on load and made its Close button appear to do nothing. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
  /* page is a column: header, main, footer. main grows (below) so the footer
     rests at the bottom of the viewport on short pages. */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* safe-area aware container: iPhone notch / home indicator */
.wrap {
  width: 100%;
  max-width: 940px;
  margin: 0 auto;
  padding-left: max(var(--pad), env(safe-area-inset-left));
  padding-right: max(var(--pad), env(safe-area-inset-right));
}

/* ------------------------------------------------------------------ topbar */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px 14px; min-height: 60px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; flex: none;
  background: var(--blue); color: #fff; border-radius: 10px; font-size: 15px;
}
.brand-text { min-width: 0; }
.brand-text strong { display: block; font-size: 16px;  font-weight: 600; letter-spacing: -.01em; }
.brand-text .brand-short { display: none; }
.topbar-right { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.trust {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--ok); font-weight: 500; padding: 0 6px;
}
.badge {
  background: var(--blue); color: #fff; font-size: 11px; font-weight: 700;
  border-radius: 999px; padding: 1px 7px; margin-left: 2px;
}
.chip {
  background: #eef2ff; color: var(--blue-dark); font-size: 12px; font-weight: 500;
  border-radius: 999px; padding: 5px 11px; max-width: 200px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

main { flex: 1 0 auto; padding-top: 24px; padding-bottom: 8px; }

/* ------------------------------------------------------------------- cards */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}
.card h2 { font-size: 15px; margin: 0 0 4px;  font-weight: 600; letter-spacing: -.01em; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ----------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 10px; padding: 10px 14px; min-height: 42px;
  transition: background .15s, border-color .15s, color .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn i { font-size: 13px; line-height: 1; }
.btn:hover { background: #f3f4f6; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: #f3f4f6; }
.btn-link { border-color: transparent; background: transparent; color: var(--blue); padding-left: 0; min-height: auto; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: #fef2f2; border-color: #fecaca; }
.btn-sm { padding: 8px 11px; font-size: 13px; min-height: 38px; border-radius: 9px; }

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.row.space-between { justify-content: space-between; margin-top: 0; }

/* ------------------------------------------------------------------ inputs */
label { display: block; font-size: 13px; font-weight: 500; margin: 14px 0 6px; }
input[type="text"], input[type="email"], input[type="password"], input[type="tel"], select {
  font: inherit; font-size: 16px; width: 100%; padding: 11px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
input:focus, select:focus { outline: 3px solid #dbeafe; outline-offset: 0; border-color: var(--blue); }
textarea {
  font: inherit; font-size: 16px; width: 100%; padding: 11px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
  min-height: 88px; resize: vertical; line-height: 1.45;
}
textarea:focus { outline: 3px solid #dbeafe; outline-offset: 0; border-color: var(--blue); }
.settings { display: grid; gap: 0 14px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

/* --------------------------------------------------------------- dropzone */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  border: 2px dashed #cbd5e1; border-radius: var(--radius);
  background: var(--card); padding: 34px 20px; text-align: center;
  margin-top: 12px; margin-bottom: 16px;
  transition: border-color .15s, background .15s;
}
.dropzone.dragover { border-color: var(--blue); background: #eff6ff; }
.dropzone-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 52px; height: 52px; border-radius: 14px; margin-bottom: 4px;
  background: #eff6ff; color: var(--blue); font-size: 22px;
}
.dropzone-title { font-size: 17px;  font-weight: 600; letter-spacing: -.01em; }
.dropzone .btn { margin-top: 8px; }

/* ------------------------------------------------------------------- grid */
.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); margin-top: 14px; }
.thumb { position: relative; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.thumb img { display: block; width: 100%; height: 104px; object-fit: cover; }
.thumb-bar { display: flex; align-items: center; justify-content: space-between; padding: 3px 4px 3px 7px; gap: 4px; }
.thumb-bar .fname { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb-actions { display: flex; gap: 1px; flex: none; }
.icon-btn {
  border: none; background: transparent; cursor: pointer; font-size: 12px;
  min-width: 26px; min-height: 26px; border-radius: 7px; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { background: #f3f4f6; color: var(--ink); }
.icon-btn.rm:hover { color: var(--danger); background: #fef2f2; }

/* --------------------------------------------------------------- progress */
.bar { height: 8px; background: #e5e7eb; border-radius: 999px; overflow: hidden; margin-top: 16px; }
.bar-fill { height: 100%; width: 0; background: var(--blue); transition: width .2s; }

/* --------------------------------------------------------------- features */
.features { display: grid; gap: 14px; margin: 26px 0 8px; }
.feature {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px 20px; text-align: center;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}
.feature-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 48px; height: 48px; border-radius: 14px; font-size: 19px; margin-bottom: 12px;
}
.tone-emerald { background: #ecfdf5; color: #059669; }
.tone-amber   { background: #fffbeb; color: #d97706; }
.tone-blue    { background: #eff6ff; color: var(--blue); }
.tone-ok      { color: var(--ok); }
.tone-danger  { color: var(--danger); }
.feature h3 { margin: 0 0 6px; font-size: 15px;  font-weight: 600; letter-spacing: -.01em; }
.feature p { margin: 0; font-size: 14px; color: var(--muted); }

/* ----------------------------------------------------------------- footer */
.site-footer {
  flex: none;
  border-top: 1px solid var(--line); background: var(--card);
  padding: 22px 0 calc(22px + env(safe-area-inset-bottom));
  margin-top: 28px;
}
.site-footer p { margin: 0; font-size: 12.5px; color: var(--muted); text-align: center; line-height: 1.6; }

/* ------------------------------------------------------------------ modal */
.overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 16px; z-index: 50;
  padding-top: calc(16px + env(safe-area-inset-top));
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  overflow-y: auto;
}
.modal {
  background: var(--card); border-radius: 14px; width: 100%; max-width: 720px;
  max-height: calc(100vh - 32px); display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 20px 40px rgba(16, 24, 40, .18);
}
.modal-sm { max-width: 420px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--line); flex: none;
}
.modal-title { margin: 0; font-size: 16px;  font-weight: 600; display: flex; align-items: center; gap: 8px; }
.modal-title i { color: var(--blue); font-size: 15px; }
.modal-body { padding: 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* ------------------------------------------------------------ pdf records */
.pdf-item {
  display: grid; grid-template-columns: auto 1fr; gap: 12px;
  border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 10px;
  background: #fff;
}
.pdf-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; height: 42px; border-radius: 11px; flex: none;
  background: #fef2f2; color: #dc2626; font-size: 19px;
}
.pdf-main { min-width: 0; }
.pdf-main h3 { margin: 0 0 3px; font-size: 14.5px;  font-weight: 600; letter-spacing: -.01em; overflow-wrap: anywhere; }
.pdf-meta { font-size: 12.5px; color: var(--muted); margin: 0 0 10px; overflow-wrap: anywhere; }
.pdf-notes {
  font-size: 13px; margin: 0 0 10px; white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--bg); border-radius: 8px; padding: 8px 10px; color: #374151;
}
.pdf-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* mini image strip on each saved PDF; clicking it opens the gallery on this page */
.pdf-minis {
  display: flex; align-items: center; gap: 6px;
  margin: 0 0 10px; width: fit-content; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.pdf-mini {
  display: block; width: 54px; height: 54px; object-fit: cover;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .06);
  transition: border-color .15s, transform .15s;
}
.pdf-minis:hover .pdf-mini { border-color: var(--blue); transform: translateY(-1px); }
.pdf-more {
  flex: none; font-size: 11px; font-weight: 600; color: var(--muted);
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px 8px; white-space: nowrap;
}

/* ------------------------------------------------------------- image gallery */
.modal-wide { max-width: 900px; }
.gallery-head-right { display: flex; align-items: center; gap: 10px; }
.gallery-grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.gallery-grid img {
  display: block; width: 100%; height: 150px; object-fit: cover;
  border-radius: 10px; border: 1px solid var(--line); background: #fff;
}

.edit-fields { display: grid; gap: 8px; margin: 10px 0 0; }
.edit-fields input, .edit-fields textarea {
  font: inherit; font-size: 15px; width: 100%; padding: 9px 10px;
  border: 1px solid var(--line); border-radius: 9px;
}
.edit-fields textarea { min-height: 70px; resize: vertical; }

/* --------------------------------------------------------- qr / share modal */
.qr-frame {
  display: flex; align-items: center; justify-content: center;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; margin: 0 auto;
}
.qr-frame img { display: block; width: 200px; height: 200px; max-width: 100%; }
.center { text-align: center; margin: 10px 0 0; }
.install-card { background: #eff6ff; border: 1px solid #dbeafe; border-radius: 12px; padding: 14px; margin-top: 16px; }
.install-card h4 { margin: 0 0 8px; font-size: 13.5px;  font-weight: 600; color: #1e3a8a; display: flex; align-items: center; gap: 7px; }
.install-card ol { margin: 0; padding-left: 20px; font-size: 13px; color: #1e40af; line-height: 1.7; }
.app-url {
  margin: 14px 0 0; font-size: 12px; color: var(--muted); text-align: center;
  overflow-wrap: anywhere; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ------------------------------------------------------------------ toast */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #111827; color: #fff; padding: 12px 18px; border-radius: 11px;
  font-size: 14px; font-weight: 500; z-index: 60; max-width: calc(100vw - 32px); text-align: center;
  box-shadow: 0 10px 24px rgba(16, 24, 40, .25);
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

.msg { font-size: 13px; margin: 14px 0 0; }
.msg.err { color: var(--danger); }
.msg.ok { color: var(--ok); }

/* ------------------------------------------------------- responsive steps */

/* 3 feature cards side by side once there is room */
@media (min-width: 760px) {
  .features { grid-template-columns: repeat(3, 1fr); }
}

/* phones: shorten the header, full-width primary actions */
@media (max-width: 700px) {
  /* .brand-text strong sets display:block and would otherwise beat .brand-long,
     so both titles showed at once. Two classes outrank class+element. */
  .brand-text .brand-long { display: none; }
  .brand-text .brand-short { display: block; }
  .hide-sm { display: none; }
}

@media (max-width: 640px) {
  :root { --pad: 14px; }
  .btn-block-xs { width: 100%; }
  /* topbar labels collapse too, so the header stays one row */
  .hide-xs { display: none; }
  .chip { max-width: 118px; font-size: 11.5px; padding: 4px 9px; }
  /* action buttons drop their labels and become square icon buttons */
  .pdf-actions .lbl { display: none; }
  .pdf-actions { gap: 6px; }
  .pdf-actions .btn { padding: 0; width: 40px; height: 40px; min-height: 40px; }
  .pdf-actions .btn i { font-size: 15px; }
  .pdf-mini { width: 46px; height: 46px; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 8px; }
  .gallery-grid img { height: 108px; }
  .gallery-head-right .muted { display: none; }
  .card { padding: 16px; }
  .modal-head { padding: 12px 14px; }
  .modal-body { padding: 14px; }
  .overlay { padding: 10px; }
}

@media (max-width: 400px) {
  .brand-text strong { font-size: 15px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
  .thumb img { height: 92px; }
  .pdf-item { padding: 12px; gap: 10px; }
  .pdf-icon { width: 38px; height: 38px; font-size: 17px; }
  .settings { grid-template-columns: 1fr; }
}
