/* ------------------------------------------------------------
   Desserts – Admin (mobile-first)
   Die .a5-canvas ist eine 1:1-Vorschau der PDF-Seite.
   --s = Skalierungsfaktor: 1pt im PDF == calc(var(--s)) im Editor.
   ------------------------------------------------------------ */

:root {
  --accent: #b04a21;
  --accent-dark: #8f3a18;
  --bg: #f5efe7;
  --card: #ffffff;
  --ink: #342b26;
  --muted: #96887f;
  --line: #e6dbce;
  --danger: #c03434;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(60, 40, 20, .08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* ---------- Login ---------- */

.login-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 34px 28px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-logo { font-size: 44px; }
.login-card h1 { margin: 8px 0 4px; font-size: 26px; color: var(--accent); }
.login-hint { color: var(--muted); font-size: 14px; margin: 6px 0 20px; }

.login-card input {
  width: 100%;
  padding: 13px 14px;
  margin-bottom: 10px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  font-size: 16px;
  background: #fdfbf8;
}
.login-card input:focus { outline: none; border-color: var(--accent); }

.login-card button {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.login-card button:active { background: var(--accent-dark); }
.login-error { color: var(--danger); font-size: 14px; min-height: 18px; margin: 12px 0 0; }

/* ---------- Kopfleiste ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: env(safe-area-inset-top) 12px 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 240px;
  min-width: 0;
}

.logo { font-size: 22px; }

.book-title {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  padding: 10px 4px;
}
.book-title:focus { outline: none; border-bottom: 2px solid var(--accent); }

.save-state { font-size: 13px; color: var(--muted); white-space: nowrap; }
.save-state.saving { color: #b8860b; }
.save-state.saved { color: #2e7d32; }
.save-state.error { color: var(--danger); font-weight: 700; }

.topbar-actions { display: flex; gap: 8px; margin-top: 6px; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent-dark); }
.btn-ghost { background: transparent; color: var(--muted); font-size: 18px; }
.btn-border { border: 1px solid var(--line); border-radius: 10px; background: #fdfbf8; }

/* ---------- Modal (Mailversand) ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(40, 30, 22, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.modal[hidden] { display: none; }

.modal-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(40, 30, 20, .3);
  padding: 22px 20px;
  width: 100%;
  max-width: 420px;
}
.modal-card h2 { margin: 0 0 14px; font-size: 19px; color: var(--accent); }

.modal-label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin: 10px 0 4px;
}

.modal-card input,
.modal-card textarea {
  width: 100%;
  padding: 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  font-size: 16px;
  background: #fdfbf8;
  font-family: inherit;
  resize: vertical;
}
.modal-card input:focus,
.modal-card textarea:focus { outline: none; border-color: var(--accent); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.modal-status { min-height: 18px; font-size: 14px; margin: 12px 0 0; }
.modal-status.ok { color: #2e7d32; }
.modal-status.err { color: var(--danger); }

/* ---------- Seitenliste ---------- */

.page-list {
  max-width: 720px;
  margin: 0 auto;
  padding: 14px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.page-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 12px 14px;
  position: relative;
  transition: box-shadow .15s, opacity .15s;
}
.page-card.drag-over-files { outline: 3px dashed var(--accent); outline-offset: -6px; }
.page-card.dragging { opacity: .5; }
.page-card.drop-target { outline: 3px solid var(--accent); outline-offset: -3px; }

.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--muted);
}

.drag-handle { cursor: grab; font-size: 18px; padding: 2px 6px; user-select: none; }
.page-num { font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.head-spacer { flex: 1; }

.icon-btn {
  border: 1px solid var(--line);
  background: #fdfbf8;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  font-size: 15px;
  cursor: pointer;
  color: var(--ink);
}
.icon-btn:active { background: var(--line); }
.icon-btn.danger { color: var(--danger); }
.icon-btn:disabled { opacity: .3; cursor: default; }

/* ---------- A5-Canvas (1:1 PDF-Vorschau) ---------- */

.a5-canvas {
  position: relative;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  aspect-ratio: 419.53 / 595.28;
  background: #fbf6ef;
  overflow: hidden;
  border-radius: 3px;
  box-shadow: 0 3px 16px rgba(60, 40, 20, .22);
}
/* Zierrahmen wie im PDF, wenn keine Fotos */
.a5-canvas.no-images::before {
  content: "";
  position: absolute;
  inset: calc(var(--s) * 14);
  border: 1px solid var(--line);
  pointer-events: none;
}

.collage {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: calc(var(--s) * 3);
  background: #fff;
}
.a5-canvas.no-images .collage { display: none; }

.collage-row {
  display: flex;
  gap: calc(var(--s) * 3);
  flex: 1;
  min-height: 0;
}

.cell {
  flex: 1;
  position: relative;
  overflow: hidden;
  touch-action: none;      /* Foto-Ausschnitt per Finger verschieben */
  cursor: grab;
  background: #eee;
}
.cell:active { cursor: grabbing; }
.cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
}
.cell .zoom-ctl {
  position: absolute;
  right: 5px;
  bottom: 5px;
  display: flex;
  gap: 5px;
  z-index: 2;
}
.cell .order-ctl {
  position: absolute;
  left: 5px;
  top: 5px;
  display: flex;
  gap: 5px;
  z-index: 2;
}
.cell .order-ctl button {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, .45);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}
.cell .order-ctl button:disabled { opacity: .35; cursor: default; }
.cell .order-ctl button:active:not(:disabled) { background: rgba(0, 0, 0, .7); }
.cell .zoom-ctl button {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, .45);
  color: #fff;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}
.cell .zoom-ctl button:active { background: rgba(0, 0, 0, .7); }

.cell .pan-hint {
  position: absolute;
  left: 5px;
  bottom: 5px;
  background: rgba(0, 0, 0, .4);
  color: #fff;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 9px;
  pointer-events: none;
  opacity: .85;
}

/* Titelbalken – wie im PDF: 44pt hoch, halbtransparent dunkel */
.title-bar {
  position: absolute;
  left: 0;
  right: 0;
  height: calc(var(--s) * 44);
  transform: translateY(-50%);
  background: rgba(15, 12, 10, .45);
  display: flex;
  align-items: center;
  z-index: 3;
}
.a5-canvas.no-images .title-bar { background: transparent; }

.title-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: #fff;
  font-weight: 700;
  text-align: center;
  font-family: Helvetica, Arial, sans-serif;
  font-size: calc(var(--s) * 20);
  padding: 0 calc(var(--s) * 34);
}
.title-input:focus { outline: none; }
.title-input::placeholder { color: rgba(255, 255, 255, .6); font-weight: 400; }
.a5-canvas.no-images .title-input { color: var(--accent); }
.a5-canvas.no-images .title-input::placeholder { color: #c9bdb2; }

/* Textkarte – wie im PDF: Rand 28pt, Padding 12pt, weiß 88 % */
.text-card {
  position: absolute;
  left: calc(var(--s) * 28);
  right: calc(var(--s) * 28);
  background: rgba(255, 255, 255, .88);
  border-radius: calc(var(--s) * 8);
  padding: calc(var(--s) * 12);
  z-index: 2;
}

.text-input {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  resize: none;
  overflow: hidden;
  color: var(--ink);
  font-family: Helvetica, Arial, sans-serif;
  font-size: calc(var(--s) * 10);
  line-height: 1.5;
  padding: 0;
  min-height: calc(var(--s) * 15);
}
.text-input:focus { outline: none; }
.text-input::placeholder { color: #b3a698; }

/* Verschiebe-Griffe an Balken und Textkarte */
.ov-drag {
  position: absolute;
  right: calc(var(--s) * 4);
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .38);
  color: #fff;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  cursor: ns-resize;
  user-select: none;
  z-index: 4;
}
.text-card .ov-drag { top: 0; transform: translateY(-40%); right: calc(var(--s) * -2); }
.a5-canvas.no-images .ov-drag { background: rgba(176, 74, 33, .55); }

/* ---------- Foto-Leiste unter dem Canvas ---------- */

.photos {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 0 6px;
  -webkit-overflow-scrolling: touch;
}

.photo {
  position: relative;
  flex: 0 0 auto;
  width: 84px;
  height: 84px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--line);
}
.photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  -webkit-user-drag: none;
}
.photo.uploading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, .55);
}
.photo.uploading::before {
  content: "";
  position: absolute;
  z-index: 2;
  top: 50%; left: 50%;
  width: 22px; height: 22px;
  margin: -13px 0 0 -13px;
  border: 3px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.photo.drag-src { opacity: .4; }
.photo.drag-over { outline: 3px solid var(--accent); outline-offset: -3px; }

.photo-del {
  position: absolute;
  top: 3px; right: 3px;
  width: 22px; height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 11px;
  cursor: pointer;
  line-height: 1;
}

.photo-move {
  position: absolute;
  bottom: 3px; left: 3px; right: 3px;
  display: flex;
  justify-content: space-between;
}
.photo-move button {
  width: 24px; height: 24px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.photo-add {
  flex: 0 0 auto;
  width: 84px;
  height: 84px;
  border: 2px dashed var(--line);
  border-radius: 10px;
  background: #fdfbf8;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.photo-add span:first-child { font-size: 22px; color: var(--accent); }
.photo-add:active { border-color: var(--accent); }

.drop-hint {
  display: none;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin: 2px 0 0;
}

/* ---------- Sonstiges ---------- */

.add-page-btn {
  display: block;
  margin: 6px auto 8px;
  max-width: 720px;
  width: calc(100% - 24px);
  padding: 15px;
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  background: transparent;
  color: var(--accent);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.add-page-btn:active { background: rgba(176, 74, 33, .08); }

.footer-note {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 10px 16px calc(24px + env(safe-area-inset-bottom));
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 46px 20px;
  font-size: 15px;
}
.empty-state .big { font-size: 40px; margin-bottom: 8px; }

/* ---------- Desktop ---------- */

@media (min-width: 700px) {
  .topbar { padding: 10px 20px; flex-wrap: nowrap; }
  .topbar-actions { margin-top: 0; }
  .drop-hint { display: block; }
  .a5-canvas { max-width: 460px; }
  .photo-move, .photo-del { opacity: 0; transition: opacity .15s; }
  .photo:hover .photo-move, .photo:hover .photo-del { opacity: 1; }
}
