:root {
  --serif: Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --ink: #1a1a1a;
  --muted: #666;
  --line: #ddd;
  --accent: #8a5a2b;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: var(--sans); color: var(--ink); background: #faf7f2; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 24px; background: #2b2b2b; color: #fff; position: sticky; top: 0; z-index: 10;
}
.topbar .brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 18px; }
.topnav a { color: #ddd; text-decoration: none; margin-left: 16px; font-size: 14px; }
.topnav a:hover { color: #fff; }

main#app { max-width: 960px; margin: 0 auto; padding: 28px 20px 60px; }
.footer { text-align: center; color: var(--muted); padding: 24px; }

h1, h2, h3 { font-family: var(--serif); }
a { color: var(--accent); }

.btn {
  display: inline-block; padding: 8px 14px; border: 0; border-radius: 6px; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 14px; text-decoration: none;
}
.btn.secondary { background: #eee; color: #333; }
.btn.danger { background: #b33; }
.btn.small { padding: 4px 8px; font-size: 12px; }

/* TOC */
.toc-hero { text-align: center; margin-bottom: 24px; }
.toc-hero img { width: 100%; max-height: 240px; object-fit: cover; border-radius: 8px; }
.toc-section { margin: 18px 0; }
.toc-section h2 { font-size: 20px; margin: 0 0 6px; }
.toc-section a.section-link { text-decoration: none; color: var(--ink); }
.toc-recipe { padding: 3px 0 3px 12px; font-size: 15px; }
.toc-recipe a { text-decoration: none; color: var(--ink); }
.toc-recipe a:hover { color: var(--accent); }

/* Section page */
.section-divider { text-align: center; margin-bottom: 20px; }
.section-divider img { width: 100%; max-height: 220px; object-fit: cover; border-radius: 8px; }
.section-divider h1 { text-transform: uppercase; letter-spacing: 2px; font-size: 30px; margin: 10px 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; text-decoration: none; color: var(--ink); }
.card img { width: 100%; height: 140px; object-fit: cover; display: block; }
.card .body { padding: 10px 12px; }
.card .body h3 { margin: 0 0 4px; font-size: 16px; }
.card .body .meta { font-size: 12px; color: var(--muted); }

/* Recipe page */
.recipe h1 { font-size: 30px; margin: 0 0 4px; }
.recipe .byline { color: var(--muted); font-style: italic; margin-bottom: 8px; }
.recipe .times { color: #333; margin-bottom: 12px; font-size: 14px; }
.recipe .hero { width: 100%; max-height: 320px; object-fit: cover; border-radius: 8px; margin-bottom: 16px; }
.recipe h2 { font-size: 22px; text-transform: uppercase; letter-spacing: 1px; border-bottom: 2px solid var(--ink); padding-bottom: 3px; margin: 22px 0 8px; }
.recipe h3 { font-size: 14px; text-transform: uppercase; color: var(--muted); margin: 12px 0 2px; }
.ingredients { list-style: none; padding: 0; columns: 2; column-gap: 28px; font-size: 15px; }
.ingredients li { padding: 2px 0; break-inside: avoid; }
.ingredients li.group { font-weight: 700; margin-top: 6px; }
.steps { padding-left: 22px; font-size: 15px; line-height: 1.5; margin: 0 0 4px; }
.steps li { padding: 3px 0; }
.step-group { font-size: 14px; text-transform: uppercase; letter-spacing: 1px; color: var(--accent); margin: 14px 0 4px; }
.step-group:first-child { margin-top: 0; }
.notes, .nutrition { font-size: 14px; margin-top: 14px; color: #333; }

/* extra recipe images (below notes) */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-top: 14px; }
.gallery-item { margin: 0; }
.gallery-item img { width: 100%; height: 160px; object-fit: cover; border-radius: 6px; display: block; }
.gallery-item figcaption { font-size: 12px; color: var(--muted); margin-top: 4px; }
.xref { color: var(--accent); text-decoration: underline; }
.back-link { display: inline-block; margin-bottom: 14px; font-size: 14px; }

/* tags */
.tag-list { display: flex; flex-wrap: wrap; gap: 10px; }
.tag-list a { background: #fff; border: 1px solid var(--line); border-radius: 20px; padding: 6px 14px; text-decoration: none; color: var(--ink); }

/* Cookbook preview */
.preview-toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; }
.book { background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.1); border-radius: 4px; }
.book .page { padding: 22mm 18mm; min-height: 200mm; page-break-after: always; border-bottom: 1px solid #eee; font-family: var(--serif); position: relative; }
.book .page:last-child { border-bottom: 0; }
.book .pagenum { position: absolute; bottom: 6mm; left: 0; right: 0; text-align: center; font-size: 10pt; color: #555; }

/* Admin */
.admin-layout { display: grid; grid-template-columns: 260px 1fr; gap: 20px; }
.admin-sidebar { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 12px; height: fit-content; }
.admin-sidebar a { display: block; padding: 6px 8px; text-decoration: none; color: var(--ink); border-radius: 4px; }
.admin-sidebar a:hover, .admin-sidebar a.active { background: #f0e9e0; }
.admin-sidebar .recipe-item { font-size: 13px; }
.panel { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 18px; }
form.stacked { display: flex; flex-direction: column; gap: 12px; }
form.stacked label { font-size: 13px; font-weight: 600; }
form.stacked input, form.stacked select, form.stacked textarea {
  width: 100%; padding: 7px 9px; border: 1px solid #ccc; border-radius: 5px; font-size: 14px; font-family: inherit;
}
form.stacked textarea { min-height: 60px; }
input[readonly], input.readonly-input {
  background: #eef0f2 !important;
  color: #8a8f95 !important;
  border-color: #d4d8dc !important;
  cursor: not-allowed;
  pointer-events: none;
}
input.slug-input {
  background: #f4f5f7;
  color: #4a4f55;
  border-color: #d4d8dc;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  cursor: pointer;
  transition: background 0.15s;
}
input.slug-input:hover { background: #e6e8ec; }
input.slug-input:focus { outline: 2px solid #b9d4ec; }
.row-grid { display: grid; grid-template-columns: auto 140px 1fr auto; gap: 8px; align-items: center; }
.row-grid input, .row-grid textarea { width: 100%; }
.repeat-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.thumbs img { width: 200px; height: 135px; object-fit: cover; border-radius: 6px; margin-right: 6px; }
.muted { color: var(--muted); font-size: 13px; }
.flash { padding: 8px 12px; border-radius: 6px; margin-bottom: 12px; }
.flash.ok { background: #e3f6e3; color: #1a6b1a; }
.flash.err { background: #fbe3e3; color: #8a1a1a; }

@media (max-width: 720px) {
  .ingredients { columns: 1; }
  .admin-layout { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
}

/* Print: when printing the preview page, show only the book */
@media print {
  .topbar, .footer, .preview-toolbar, .back-link { display: none !important; }
  main#app { max-width: none; padding: 0; }
  body { background: #fff; }
  .book { box-shadow: none; }
  .book .page { min-height: auto; border: 0; padding: 0; }
}

/* drag handle + sortable */
.grip {
  cursor: grab; user-select: none; color: #aaa; padding: 0 4px;
  font-size: 16px; line-height: 1; touch-action: none;
}
.grip:active { cursor: grabbing; }
.grip:hover { color: #555; }
[data-id].dragging { opacity: .4; }
.recipe-row { display: flex; align-items: center; gap: 2px; }
.recipe-row > a { flex: 1; }
.recipe-row.drag-ghost { outline: 2px dashed var(--accent); }

/* tag editor rows */
.tag-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: #fff; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 6px; }
.tag-row .name { flex: 1; font-weight: 600; }
.tag-row input.name-input { flex: 1; padding: 4px 6px; border: 1px solid #bbb; border-radius: 4px; }

/* image field (single) */
.imagefield { display: flex; align-items: center; gap: 10px; }
.imagefield .preview { width: 162px; height: 122px; object-fit: cover; border-radius: 6px; background: #eee; border: 1px solid var(--line); }
.imagefield .placeholder { width: 162px; height: 122px; display: flex; align-items: center; justify-content: center; background: #f2f2f2; border: 1px dashed #bbb; border-radius: 6px; color: #aaa; font-size: 12px; }

/* image picker modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: #fff; border-radius: 8px; max-width: 720px; width: 92vw; max-height: 80vh; display: flex; flex-direction: column; }
.modal header { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal .picker-search { padding: 10px 16px; border-bottom: 1px solid var(--line); }
.modal .picker-search input { width: 100%; padding: 7px 9px; border: 1px solid #ccc; border-radius: 5px; }
.modal .picker-grid { overflow: auto; padding: 12px; display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.picker-thumb { cursor: pointer; border: 2px solid transparent; border-radius: 6px; overflow: hidden; position: relative; }
.picker-thumb img { width: 100%; height: 150px; object-fit: cover; display: block; }
.picker-thumb .cap { font-size: 10px; color: #555; padding: 3px 5px; word-break: break-all; background: #fafafa; }
.picker-thumb.selected { border-color: var(--accent); }
.picker-thumb:hover { border-color: #bbb; }
.picker-edit { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.6); color: #fff; border: 0; border-radius: 4px; padding: 2px 6px; font-size: 12px; cursor: pointer; opacity: 0; transition: opacity .15s; }
.picker-thumb:hover .picker-edit { opacity: 1; }
.picker-edit:hover { background: rgba(0,0,0,.85); }

/* image editor modal */
.editor-modal { max-width: 840px; }
.editor-modal header { gap: 8px; }
.editor-modal .hdr-actions { display: flex; gap: 6px; }
.editor-body { display: flex; gap: 16px; padding: 16px; overflow: auto; }
.editor-stage-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; background: #1a1a1a; border-radius: 8px; padding: 16px; min-height: 460px; }
.editor-stage { position: relative; cursor: grab; touch-action: none; background: #000; box-shadow: 0 0 0 1px rgba(255,255,255,.15); }
.editor-stage canvas { display: block; }
.editor-stage .crop-frame { position: absolute; inset: 0; pointer-events: none; border: 1px solid rgba(255,255,255,.55); }
.editor-hint { color: #bbb; font-size: 12px; margin-top: 8px; }
.editor-controls { width: 260px; display: flex; flex-direction: column; gap: 14px; }
.ctl-group { display: flex; flex-direction: column; gap: 4px; }
.ctl-label { font-size: 12px; font-weight: 600; color: #444; display: flex; justify-content: space-between; }
.ctl-label span { font-weight: 400; color: #888; }
.ctl-group input[type=range] { width: 100%; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.seg-btn { padding: 5px 8px; border: 1px solid #ccc; background: #fff; border-radius: 5px; font-size: 12px; cursor: pointer; }
.seg-btn:hover { background: #f4eee6; }
.seg-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.editor-modal footer { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.editor-modal footer .muted { font-size: 12px; }

@media (max-width: 720px) {
  .editor-body { flex-direction: column; }
  .editor-controls { width: 100%; }
}

