:root {
  --bg: #fafaf7;
  --fg: #222;
  --muted: #666;
  --accent: #8a3b1e;
  --border: #e2e0d8;
  --max: 56rem;
}

* { box-sizing: border-box; }

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

.container {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1rem 1.25rem 3rem;
}

/* Header */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.75rem 1.25rem;
  background: #fff;
  border-bottom: 1px solid var(--border);
}
.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--accent);
  font-weight: 700;
  font-size: 1.15rem;
}
.logo-mark { display: block; width: 40px; height: 40px; flex: none; }
.header-actions { display: flex; align-items: center; gap: 0.75rem; }
.inline { display: inline; margin: 0; }

/* Account dropdown menu */
.menu { position: relative; }
.menu-toggle { display: inline-flex; align-items: center; gap: 0.3rem; }
.menu-panel {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  min-width: 13rem;
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
  padding: 0.3rem;
  z-index: 50;
}
.menu-panel[hidden] { display: none; }
.menu-item-form { display: block; }
.menu-item {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 0.5rem 0.7rem;
  text-align: left;
  text-decoration: none;
  color: var(--text, #222);
  border-radius: 5px;
  font-size: 0.95rem;
  background: none;
  cursor: pointer;
}
button.menu-item { border: none; color: var(--muted); }
.menu-item:hover, .menu-item:focus { background: #f0eee7; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.45rem 0.8rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  text-decoration: none;
  font-size: 0.95rem;
  cursor: pointer;
}
.btn-link {
  background: none;
  color: var(--muted);
  padding: 0.45rem 0.3rem;
}

/* Forms */
.form { display: flex; flex-direction: column; gap: 0.85rem; max-width: 22rem; }
.form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; color: var(--muted); }
.form input {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
}
.error { color: #b00020; }
.auth { max-width: 22rem; }

.site-footer { text-align: center; color: var(--muted); padding: 2rem 1rem; }

/* Catalog */
.search { display: flex; gap: 0.5rem; margin: 0.5rem 0 1rem; }
.search input[type="search"] {
  flex: 1; padding: 0.55rem 0.7rem;
  border: 1px solid var(--border); border-radius: 6px; font-size: 1rem;
}
/* Compact category filter: a dropdown of the (CSS-indented) tree + breadcrumbs. */
.catalog-filter { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem 0.75rem; margin: 0.5rem 0 1.25rem; }
.cat-dropdown { position: relative; }
.cat-summary {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.4rem 0.8rem; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: var(--accent); font-size: 0.9rem; cursor: pointer;
  list-style: none; user-select: none;
}
.cat-summary::-webkit-details-marker { display: none; }
.cat-summary::after { content: "▾"; font-size: 0.75em; }
.cat-dropdown[open] .cat-summary::after { content: "▴"; }
.cat-panel {
  position: absolute; z-index: 50; margin-top: 0.3rem; min-width: 14rem;
  max-height: 60vh; overflow-y: auto;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12); padding: 0.3rem;
}
.cat-item {
  display: block; border-radius: 5px; text-decoration: none; color: var(--text, #222);
  font-size: 0.92rem; padding: 0.4rem 0.6rem;
  padding-left: calc(0.6rem + var(--d, 0) * 1rem); /* real indentation by depth */
}
.cat-item:hover, .cat-item:focus { background: #f0eee7; }
.cat-item.active { background: var(--accent); color: #fff; }
.breadcrumbs { font-size: 0.9rem; color: var(--muted); }
.breadcrumbs .crumb { color: var(--accent); text-decoration: none; }
.breadcrumbs .crumb.current { color: var(--muted); font-weight: 600; }
.breadcrumbs .crumb-sep { color: var(--border); margin: 0 0.15rem; }

/* Admin category tree with drag-and-drop reparenting. */
.cat-tree { display: flex; flex-direction: column; gap: 0.3rem; margin-top: 1rem; }
.cat-node {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.35rem 0.5rem; border: 1px solid var(--border); border-radius: 6px; background: #fff;
  margin-left: calc(var(--d, 0) * 1.4rem); /* nesting depth */
}
.cat-handle { cursor: grab; color: var(--muted); user-select: none; }
.cat-node.dragging { opacity: 0.5; }
.cat-node.drag-over { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.cat-node .rename-form { flex: 1; display: flex; gap: 0.4rem; align-items: center; }
.cat-node .rename-form input { flex: 1; min-width: 6rem; }
.cat-count { color: var(--muted); font-size: 0.85rem; min-width: 1.5rem; text-align: right; }
.cat-droproot {
  padding: 0.4rem 0.6rem; border: 1px dashed var(--border); border-radius: 6px;
  color: var(--muted); font-size: 0.9rem; text-align: center;
}
.cat-droproot.drag-over { border-color: var(--accent); color: var(--accent); background: #f0eee7; }

.recipe-grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); }
.recipe-card a {
  display: flex; flex-direction: column; gap: 0.25rem;
  padding: 0.9rem 1rem;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  text-decoration: none; color: var(--fg); height: 100%;
}
.recipe-card a:hover { border-color: var(--accent); }
.recipe-card-title { font-weight: 600; font-size: 1.05rem; }
.recipe-card-cat { color: var(--muted); font-size: 0.85rem; }
.empty { color: var(--muted); }

/* Recipe view */
.recipe-view { max-width: 42rem; }
.breadcrumbs { color: var(--muted); font-size: 0.9rem; margin-bottom: 0.5rem; }
.breadcrumbs a { color: var(--muted); }
.recipe-view h1 { margin: 0.2rem 0 1rem; }
.ingredients ul { margin: 0.3rem 0 1rem; padding-left: 1.3rem; }
.ingredients h3 { margin: 0.8rem 0 0.2rem; font-size: 1rem; }
.steps-body { white-space: pre-wrap; }
.steps-body img {
  display: block; max-width: 100%; height: auto;
  margin: 0.6rem 0; border-radius: 6px; cursor: zoom-in;
}
.recipe-footer { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 2rem; flex-wrap: wrap; }

/* Lightbox */
.lightbox {
  position: fixed; inset: 0; display: none;
  align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.9); z-index: 1000; padding: 1rem;
}
.lightbox.open { display: flex; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; cursor: zoom-in; transition: transform 0.15s ease; }
.lightbox img.zoomed { transform: scale(2); cursor: zoom-out; }

/* Admin: recipe management table */
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.head-actions { display: flex; align-items: center; gap: 1rem; }
.notice { color: #1b6e2e; }
.muted-note { color: var(--muted); font-size: 0.9rem; }
.rename-form { display: flex; gap: 0.4rem; align-items: center; }
.rename-form input { padding: 0.35rem 0.5rem; border: 1px solid var(--border); border-radius: 6px; }

/* iCloud sync */
.sync .form { margin: 1rem 0; }
.sync-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; margin: 1.5rem 0; }
.conflicts { list-style: none; padding: 0; }
.conflicts li {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  flex-wrap: wrap; padding: 0.6rem 0; border-bottom: 1px solid var(--border);
}
.admin-table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
.admin-table th, .admin-table td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); }
.row-actions { display: flex; gap: 0.75rem; align-items: center; white-space: nowrap; }
.btn-danger-link { color: #b00020; }

/* Recipe form */
.form-wide { max-width: 42rem; }
.recipe-form fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 0.9rem 1rem; margin: 0; }
.recipe-form legend { font-weight: 600; padding: 0 0.4rem; }
.ing-block { display: flex; flex-direction: column; gap: 0.4rem; padding: 0.6rem 0; border-bottom: 1px dashed var(--border); }
.ing-block textarea, .recipe-form input[type="text"], .recipe-form select, .recipe-form textarea {
  padding: 0.5rem 0.6rem; border: 1px solid var(--border); border-radius: 6px; font: inherit; width: 100%;
}
.hint { color: var(--muted); font-size: 0.85rem; margin: 0 0 0.4rem; }
.steps-editor {
  min-height: 10rem; padding: 0.7rem 0.8rem; border: 1px solid var(--border);
  border-radius: 6px; background: #fff;
}
.steps-editor img { max-width: 100%; height: auto; border-radius: 6px; margin: 0.4rem 0; }
.form-actions { display: flex; gap: 0.75rem; }
.btn-secondary { background: #fff; color: var(--accent); border: 1px solid var(--accent); }
.btn-danger { background: #b00020; }
.delete-form { margin-top: 1.5rem; }
.preview { margin-top: 1.5rem; padding: 1rem; border: 1px dashed var(--border); border-radius: 8px; }

/* Mobile: keep the header compact and never let it break the layout. */
@media (max-width: 30rem) {
  .site-header { padding: 0.6rem 0.9rem; gap: 0.5rem; }
  .logo { font-size: 1rem; gap: 0.4rem; }
  .logo-mark { width: 32px; height: 32px; }
  .site-name {
    max-width: 9.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .header-actions { gap: 0.4rem; }
  .btn { padding: 0.4rem 0.6rem; font-size: 0.85rem; }
  .menu-panel { right: 0; min-width: 11rem; max-width: calc(100vw - 1.8rem); }
  .container { padding: 0.75rem 1rem 2.5rem; }
  .recipe-grid { grid-template-columns: 1fr; }
}
