:root {
  --color-bg: #fdfcfb;
  --color-text: #2b2622;
  --color-muted: #7a7166;
  --color-accent: #b5561f;
  --color-accent-dark: #8a4116;
  --color-border: #e8e1d8;
  --color-card-bg: #ffffff;
  --max-width: 760px;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

/* [hidden] must always win, even against elements whose class sets `display`
   (e.g. .btn { display: inline-block }) — same specificity, so without this
   the later rule in the cascade would otherwise show a "hidden" element. */
[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  overflow-x: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.6;
}

a {
  color: var(--color-accent-dark);
}

a:hover {
  color: var(--color-accent);
}

img {
  max-width: 100%;
  display: block;
}

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

/* Header */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  padding: 1.25rem 0;
}

.site-header .wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-title {
  font-size: 1.3rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--color-text);
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.site-nav a {
  text-decoration: none;
  color: var(--color-muted);
  font-size: 0.95rem;
}

.site-nav a:hover {
  color: var(--color-accent);
}

/* Main content */

main {
  padding: 2.5rem 0 4rem;
}

.page-heading {
  font-size: 1.8rem;
  margin-bottom: 0.5rem;
}

.page-intro {
  color: var(--color-muted);
  margin-top: 0;
  margin-bottom: 2.5rem;
}

/* Recipe list (view pathway) */

.recipe-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1.5rem;
}

.recipe-card {
  display: flex;
  gap: 1.25rem;
  background: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.recipe-card:hover {
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.06);
  transform: translateY(-1px);
}

.recipe-card-thumb {
  flex: 0 0 140px;
  height: 140px;
  object-fit: cover;
  background: var(--color-border);
}

.recipe-card-body {
  padding: 1rem 1.25rem 1rem 0;
  min-width: 0;
}

.recipe-card-date {
  display: block;
  font-size: 0.85rem;
  color: var(--color-muted);
}

.recipe-card-title {
  margin: 0.2rem 0 0;
  font-size: 1.1rem;
  line-height: 1.35;
}

/* Recipe detail (view pathway) */

.post-header {
  margin-bottom: 1.25rem;
}

.post-title {
  font-size: 1.7rem;
  margin-bottom: 0.25rem;
}

.post-meta {
  color: var(--color-muted);
  font-size: 0.9rem;
  margin: 0;
}

.recipe-hero img {
  width: 100%;
  border-radius: var(--radius);
  margin: 1.25rem 0;
}

.recipe-instagram-link {
  margin: 0 0 1.5rem;
}

.recipe-instagram-link a {
  font-weight: 600;
  text-decoration: none;
}

.post-content ul, .post-content ol {
  padding-left: 1.4rem;
}

.post-content li {
  margin-bottom: 0.35rem;
}

.back-link {
  display: inline-block;
  margin-top: 2rem;
  font-size: 0.95rem;
  text-decoration: none;
  color: var(--color-muted);
}

.state-message {
  color: var(--color-muted);
  padding: 2rem 0;
}

.state-message.is-error {
  color: #a1341e;
}

/* Footer */

.site-footer {
  border-top: 1px solid var(--color-border);
  padding: 1.5rem 0;
  color: var(--color-muted);
  font-size: 0.9rem;
}

/* ---- QR code modal ---- */

.site-title {
  cursor: pointer;
}

.qr-modal {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  margin: 0;
  width: 100vw;
  height: 100vh;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}

.qr-modal-backdrop {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(43, 38, 34, 0.55);
}

.qr-modal-panel {
  position: relative;
  background: var(--color-card-bg);
  border-radius: var(--radius);
  padding: 1.75rem;
  max-width: 320px;
  width: 100%;
  max-height: calc(100vh - 2.5rem);
  overflow: auto;
  margin: auto;
  text-align: center;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
}

.qr-modal-panel h2 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
}

.qr-modal-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 2rem;
  height: 2rem;
  border: none;
  background: transparent;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--color-muted);
}

.qr-modal-close:hover {
  color: var(--color-text);
}

.qr-code-container {
  max-width: 220px;
  margin: 0 auto;
}

.qr-code-container svg {
  width: 100%;
  height: auto;
  display: block;
}

.qr-url-text {
  margin: 1rem 0 0;
  font-size: 0.8rem;
  color: var(--color-muted);
  word-break: break-all;
}

/* ---- Admin pathway ---- */

.admin-body {
  background: #f4f1ec;
}

.admin-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--color-text);
  color: #fff;
  padding: 1rem 0;
}

.admin-header .wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.admin-header a {
  color: #fff;
  text-decoration: none;
}

.admin-header-left,
.admin-header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.admin-badge {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--color-accent);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
}

.update-banner {
  background: var(--color-accent);
  color: #fff;
}

.update-banner .wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 1.25rem;
  font-size: 0.9rem;
}

.update-banner .btn-secondary {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.5);
}

.update-banner .btn-secondary:hover {
  border-color: #fff;
  background: rgba(255, 255, 255, 0.15);
}

.admin-header .btn-secondary {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.35);
}

.admin-header .btn-secondary:hover {
  border-color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.08);
}

.admin-panel {
  background: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.admin-panel h2 {
  margin-top: 0;
  font-size: 1.1rem;
}

.field {
  margin-bottom: 1.1rem;
}

.field label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
}

.field .hint {
  display: block;
  font-weight: 400;
  color: var(--color-muted);
  font-size: 0.8rem;
  margin-top: 0.25rem;
}

.field input[type="text"],
.field input[type="password"],
.field input[type="date"],
.field input[type="url"],
.field textarea,
.field select {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font: inherit;
  background: #fff;
  color: var(--color-text);
}

.field textarea {
  min-height: 220px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  resize: vertical;
}

/* Rich text editor (recipe body) */

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem;
  border: 1px solid var(--color-border);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: #f4f1ec;
}

.toolbar-btn {
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.5rem;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--color-text);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.toolbar-btn:hover {
  border-color: var(--color-border);
  background: #fff;
}

.toolbar-btn.is-active {
  border-color: var(--color-accent);
  background: #fdf1ea;
  color: var(--color-accent-dark);
}

.toolbar-sep {
  width: 1px;
  height: 1.4rem;
  background: var(--color-border);
  margin: 0 0.2rem;
}

.editor-toolbar .toolbar-select {
  /* Overrides ".field select { width: 100% }" - needs the extra class in
     the selector to win on specificity, not just source order. */
  width: auto;
  height: 2rem;
  padding: 0 0.4rem;
  border: 1px solid var(--color-border);
  border-radius: 5px;
  background: #fff;
  font: inherit;
  font-size: 0.85rem;
  color: var(--color-text);
}

.rich-editor {
  min-height: 260px;
  padding: 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 0 0 6px 6px;
  background: #fff;
  color: var(--color-text);
  overflow-y: auto;
}

.rich-editor:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: -1px;
}

.rich-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--color-muted);
}

.rich-editor p {
  margin: 0 0 1em;
}

.rich-editor ul,
.rich-editor ol {
  margin: 0 0 1em;
  padding-left: 1.4rem;
}

.rich-editor blockquote {
  margin: 0 0 1em;
  padding-left: 1rem;
  border-left: 3px solid var(--color-border);
  color: var(--color-muted);
}

.rich-editor pre {
  margin: 0 0 1em;
  padding: 0.6rem 0.8rem;
  background: #f4f1ec;
  border-radius: 6px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
}

.field-row {
  display: flex;
  gap: 1rem;
}

.field-row .field {
  flex: 1;
  min-width: 0; /* flex items default to min-width:auto, which can force the row wider than its container */
}

.btn {
  display: inline-block;
  border: none;
  border-radius: 6px;
  padding: 0.6rem 1.1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  background: var(--color-accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--color-accent-dark);
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-text);
}

.btn-danger {
  background: transparent;
  border: 1px solid #a1341e;
  color: #a1341e;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-sm {
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
}

.image-btn-row {
  margin-top: 0.6rem;
}

.btn-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.btn-row input[type="file"] {
  flex: 1;
  min-width: 0;
  max-width: 100%;
}

.status-line {
  margin-top: 1rem;
  font-size: 0.9rem;
}

.status-line.is-error {
  color: #a1341e;
}

.status-line.is-success {
  color: #2c7a3f;
}

.recipe-picker {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.recipe-picker select {
  flex: 1;
  min-width: 200px;
}

.thumb-preview {
  margin-top: 0.75rem;
  max-width: 220px;
  border-radius: 6px;
  border: 1px solid var(--color-border);
}

/* ---- Phone mode ---- */

@media (max-width: 640px) {
  .wrapper {
    padding: 0 1rem;
  }

  .admin-header .wrapper {
    justify-content: flex-start;
  }

  .admin-header-right {
    margin-left: auto;
  }

  .admin-panel {
    padding: 1.1rem;
    border-radius: 0;
    border-left: none;
    border-right: none;
    margin: 0 -1rem 1rem;
  }

  .field-row {
    flex-direction: column;
    gap: 0;
  }

  .recipe-picker {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .recipe-picker select {
    width: 100%;
    min-width: 0;
  }

  .image-btn-row {
    flex-direction: column;
    align-items: stretch;
  }

  .image-btn-row input[type="file"] {
    width: 100%;
    max-width: 100%;
  }

  .recipe-card {
    flex-direction: column;
  }

  .recipe-card-thumb {
    width: 100%;
    height: 180px;
    flex: none;
  }

  .recipe-card-body {
    padding: 0.85rem 1rem 1rem;
  }

  .thumb-preview {
    max-width: 100%;
  }
}
