:root {
  --ink: #1f2937;
  --muted: #6b7280;
  --gold: #c79a46;
  --bg: #f7f7f5;
  --card: #ffffff;
  --border: #e5e7eb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.topbar {
  background: var(--ink);
  color: #fff;
  padding: 28px 32px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.topbar h1 { margin: 0 0 6px; font-size: 22px; }
.topbar p { margin: 0; color: #cbd5e1; font-size: 14px; }
.back-link {
  display: inline-block;
  font-size: 12.5px;
  font-weight: 600;
  color: #cbd5e1;
  text-decoration: none;
  margin-bottom: 12px;
}
.back-link:hover { color: #fff; }
.guide-btn {
  background: transparent;
  border: 1px solid #48545f;
  color: #e5e7eb;
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  margin-top: 2px;
}
.guide-btn:hover { background: #1f2a33; }

.layout {
  max-width: 920px;
  margin: 0 auto;
  padding: 24px 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 22px;
}
.panel h2 {
  font-size: 15px;
  margin: 0 0 14px;
  color: var(--ink);
  border-bottom: 2px solid var(--gold);
  display: inline-block;
  padding-bottom: 4px;
}
.panel-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}
.field input[type="text"],
.field input[type="date"] {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  color: var(--ink);
}
.field input[type="checkbox"] {
  width: 18px;
  height: 18px;
  align-self: flex-start;
}
.checkbox-field {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--ink);
}

.cover-fields { margin-top: 8px; }

.segmented {
  display: flex;
  gap: 16px;
  margin-bottom: 14px;
  font-size: 13.5px;
  color: var(--ink);
}
.segmented label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.segmented input[type="radio"] { width: 16px; height: 16px; }

.index-style-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 4px;
}
.field-inline { margin-bottom: 0; }
.field-inline input[type="color"] {
  width: 40px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}
.field-inline select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13.5px;
  color: var(--ink);
}

.hint { font-size: 12.5px; color: var(--muted); margin: 0 0 12px; }

input[type="file"] {
  font-size: 13px;
  margin-bottom: 12px;
}

.secondary-btn {
  background: #fff;
  border: 1px solid var(--gold);
  color: #8a6626;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.secondary-btn:hover { background: #fdf6e8; }
.secondary-btn.needs-attention {
  background: var(--gold);
  color: #201a0d;
  border-color: var(--gold);
}
.secondary-btn.needs-attention:hover { background: #b98835; }

.stale-banner {
  align-items: center;
  gap: 8px;
  background: #fdf1de;
  border: 1px solid #ecd9ab;
  color: #7a5a12;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12.5px;
  margin-bottom: 10px;
}
.stale-banner:not([hidden]) { display: flex; }
.stale-banner .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c08a2e;
  flex-shrink: 0;
}

.cover-tile {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
  font-size: 12px;
  color: var(--muted);
}
.cover-tile img {
  border: 2px solid var(--gold);
  border-radius: 6px;
  max-width: 140px;
  display: block;
}

.page-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}
.page-tile {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafafa;
  padding: 10px;
  cursor: grab;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.page-tile.index-tile { border-color: var(--gold); background: #fdf9ee; }
.thumb-wrap { position: relative; }
.thumb-wrap img {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 4px;
  display: block;
  background: #fff;
}
.page-badge {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: rgba(31, 41, 55, 0.85);
  color: #fff;
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 10px;
}
.tile-meta { display: flex; flex-direction: column; gap: 2px; }
.tile-label {
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile-sub { font-size: 11px; color: var(--muted); }
.tile-actions { display: flex; justify-content: flex-end; gap: 6px; }
.icon-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 5px;
  width: 26px;
  height: 26px;
  font-size: 13px;
  cursor: pointer;
  line-height: 1;
}
.icon-btn.delete-btn { color: #b91c1c; }
.icon-btn:hover { background: #f3f4f6; }

.build-btn {
  align-self: center;
  background: var(--gold);
  color: #201a0d;
  border: none;
  padding: 14px 32px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.build-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.action-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
}
.action-hint { text-align: center; margin-top: 6px; }
#closeBtn:disabled { opacity: 0.5; cursor: not-allowed; }

.subheading {
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 4px 0 10px;
}
.index-entries-list {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.index-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fafafa;
  font-size: 13px;
  cursor: grab;
}
.index-entry .entry-label { display: flex; align-items: center; gap: 8px; min-width: 0; }
.index-entry .entry-pages { color: var(--muted); font-size: 12px; }
.index-entries-empty { font-size: 12.5px; color: var(--muted); margin: 0 0 12px; }

.index-heading-entry {
  background: #fdf9ee;
  border-color: var(--gold);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.03em;
}

.editable { cursor: text; border-radius: 3px; padding: 1px 4px; margin: -1px -4px; }
.editable:hover { background: rgba(199, 154, 70, 0.12); }
.inline-edit-input {
  font: inherit;
  padding: 2px 6px;
  border: 1px solid var(--gold);
  border-radius: 4px;
  min-width: 160px;
}
.custom-label-badge {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: none;
  letter-spacing: normal;
  color: #8a6626;
  margin-left: 4px;
}
.index-entry .entry-actions { display: flex; gap: 6px; flex-shrink: 0; }
.index-entry .entry-actions .delete-file-btn { color: #b91c1c; border-color: #f3c5c5; }
.index-entry .entry-actions .secondary-btn.confirm-armed,
.icon-btn.confirm-armed {
  background: #b91c1c;
  color: #fff;
  border-color: #b91c1c;
}

@media (max-width: 480px) {
  .index-entry {
    flex-direction: column;
    align-items: stretch;
  }
  .index-entry .entry-actions {
    width: 100%;
  }
  .index-entry .entry-actions .secondary-btn {
    flex: 1;
    text-align: center;
  }
}

.page-tile.separator-tile { border-color: var(--gold); background: #fdf9ee; }
.page-tile.heading-divider-tile { border: 2px solid var(--gold); background: #fdf9ee; }

.stamp-row {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.stamp-row .field { margin-bottom: 0; text-align: center; }

.status {
  text-align: center;
  font-size: 13.5px;
  color: var(--muted);
  min-height: 18px;
}
.status.error { color: #b91c1c; }

.guide-panel {
  background: #fffdf6;
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  border-radius: 10px;
  padding: 20px 22px 18px;
}
.guide-panel .guide-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.guide-panel h2 { font-size: 15px; margin: 0; color: var(--ink); }
.guide-dismiss {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.guide-dismiss:hover { background: #f3f4f6; }
.guide-steps { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 12px; }
.guide-steps li { display: flex; gap: 12px; font-size: 13.5px; line-height: 1.5; }
.guide-steps li::before {
  content: attr(data-n);
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--gold);
  color: #201a0d;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}
.guide-steps b { font-weight: 600; }
.guide-steps .optional {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-left: 6px;
}

.site-footer { border-top: 1px solid var(--border); padding: 22px 0 32px; }
.site-footer-inner {
  max-width: 920px;
  margin: 0 auto;
  padding: 0 20px;
  font-size: 12.5px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.site-footer .footer-links { display: flex; gap: 16px; }
.site-footer .footer-links a { color: var(--muted); text-decoration: none; }
.site-footer .footer-links a:hover { color: var(--ink); }

.field-label { display: flex; align-items: center; gap: 5px; }
.section-help-label {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--muted);
}
.btn-with-help { position: relative; display: inline-flex; align-items: center; gap: 6px; }

.help-dot {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}
.help-dot:hover,
.help-dot.is-open { background: var(--gold); border-color: var(--gold); color: #201a0d; }
.help-pop {
  display: none;
  position: absolute;
  top: 22px;
  left: 0;
  z-index: 5;
  width: max-content;
  max-width: 260px;
  background: #fff;
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  border-radius: 6px;
  padding: 9px 11px;
  font-size: 12px;
  font-weight: 400;
  color: var(--ink);
  line-height: 1.4;
  text-transform: none;
  letter-spacing: normal;
  cursor: default;
}
.help-dot.is-open .help-pop { display: block; }
.help-pop.help-steps { max-width: 300px; }
.help-pop.help-steps ol { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.help-pop.help-steps li { display: flex; gap: 7px; }
.help-pop.help-steps li::before {
  content: attr(data-n);
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--gold);
  color: #201a0d;
  font-size: 9px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}
