:root {
  --primary-green: #8bc34a;
  --dark-text: #2c3e50;
  --light-bg: #f9f9f9;
  --border-color: #e0e0e0;
  --c-1400: #4caf50;
  --c-1600: #2196f3;
  --c-1800: #ff9800;
  --c-2000: #ff5722;
  --c-2400: #e91e63;
}

* { box-sizing: border-box; }

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  color: var(--dark-text);
  background-color: #f0f2f5;
  margin: 0;
  padding: 0;
}

a { color: var(--primary-green); text-decoration: none; }
a:hover { text-decoration: underline; }

/* App layout */
.app-header {
  background: #1a252f;
  color: #fff;
  padding: 16px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-header h1 {
  margin: 0;
  font-size: 1.4rem;
}

.app-header nav a {
  color: #fff;
  margin-left: 24px;
  font-weight: 600;
}

.app-header nav a:hover { color: var(--primary-green); text-decoration: none; }

.app-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 20px;
}

.page-title {
  margin: 0;
  font-size: 1.8rem;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

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

.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.is-open {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 37, 47, 0.55);
}

.modal-dialog {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 12px;
  padding: 28px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.18);
}

.modal-title {
  margin: 0 0 8px;
  font-size: 1.35rem;
}

.modal-text {
  margin: 0 0 20px;
  color: #5f6c7b;
}

.modal-options {
  margin-bottom: 24px;
}

.modal-section .modal-options {
  margin-bottom: 0;
}

.modal-section {
  margin-bottom: 20px;
}

.modal-section-label {
  display: block;
  font-weight: 700;
  margin-bottom: 10px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

#export-render-container {
  position: fixed;
  left: -10000px;
  top: 0;
  width: 1200px;
  pointer-events: none;
}

#export-render-container .recipe-wrapper {
  margin-bottom: 20px;
}

/* Product grid */
.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
}

.product-card {
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 15px rgba(0,0,0,0.08);
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: block;
}

.product-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 25px rgba(0,0,0,0.12);
}

.product-card-wrap {
  position: relative;
}

.product-card-edit {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid #d5dbe3;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary-green);
  text-decoration: none;
}

.product-card-edit:hover {
  background: var(--primary-green);
  color: #fff;
  text-decoration: none;
}

.product-card-image {
  height: 180px;
  background-size: cover;
  background-position: center;
  background-color: #e9ecef;
}

.product-card-body { padding: 20px; }

.product-card-category {
  color: var(--primary-green);
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.product-card-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0 0 8px;
  text-transform: uppercase;
}

.product-card-desc {
  font-size: 0.9rem;
  color: #7f8c8d;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  background: #fff;
  border-radius: 12px;
}

.empty-state p { color: #7f8c8d; margin-bottom: 20px; }

.products-filter {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  padding: 16px 20px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}

.products-filter-label {
  font-weight: 700;
  color: var(--dark-text);
}

.filter-option,
.radio-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  cursor: pointer;
}

.field-label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
}

.radio-group {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.product-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.product-card-meta .product-card-category {
  margin-bottom: 0;
}

.product-card-group {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.product-card-group-essential {
  background: #e8f5e9;
  color: #2e7d32;
}

.product-card-group-premium {
  background: #fff3e0;
  color: #ef6c00;
}

/* Form */
.form-card {
  background: #fff;
  border-radius: 12px;
  padding: 32px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.08);
  max-width: 800px;
}

.form-wide {
  max-width: 960px;
}

.form-section {
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border-color);
}

.form-section:last-of-type {
  border-bottom: none;
  padding-bottom: 0;
}

.form-section-title {
  margin: 0 0 16px;
  font-size: 1.15rem;
  color: #1a252f;
}

.form-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.form-section-header .form-section-title {
  margin: 0;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-row-3 {
  grid-template-columns: 80px 1fr auto;
  align-items: center;
}

.form-row-4 {
  grid-template-columns: repeat(4, 1fr);
}

.form-group { margin-bottom: 20px; }

.form-group label,
.sub-label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
}

.sub-label {
  font-size: 0.85rem;
  color: #7f8c8d;
  margin-top: 12px;
}

.form-group input[type="text"],
.form-group textarea,
.form-group input[type="file"],
.list-item input[type="text"],
.list-item textarea,
.amount-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
}

.form-group textarea.json-input {
  min-height: 320px;
  resize: vertical;
  font-family: 'Courier New', monospace;
  font-size: 0.9rem;
}

.form-group textarea { min-height: 80px; resize: vertical; }

.form-group input[readonly] {
  background: #f5f5f5;
  color: #666;
}

.list-editor {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.list-editor-inline {
  flex-direction: row;
  flex-wrap: wrap;
}

.list-item {
  display: flex;
  gap: 10px;
  align-items: center;
}

.list-item-block {
  flex-direction: column;
  align-items: stretch;
  padding: 14px;
  background: #fafafa;
  border: 1px solid var(--border-color);
  border-radius: 8px;
}

.list-item-inline {
  flex: 0 0 auto;
}

.list-item-inline input {
  width: 140px;
}

.list-item-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  align-items: center;
}

.list-item-grid-3 {
  display: grid;
  grid-template-columns: 80px 1fr 1fr auto;
  align-items: center;
}

.amounts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
  white-space: nowrap;
}

.form-hint {
  margin: -4px 0 8px;
  font-size: 0.9rem;
  color: #7f8c8d;
}

.image-preview {
  margin-top: 12px;
  max-width: 200px;
  max-height: 200px;
  border-radius: 8px;
  display: none;
}

.btn {
  display: inline-block;
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

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

.btn-primary:hover { background: #7cb342; }

.btn-secondary {
  background: #1a252f;
  color: #fff;
}

.btn-secondary:hover { background: #2c3e50; }

.btn-outline {
  background: transparent;
  border: 2px solid var(--primary-green);
  color: var(--primary-green);
}

.btn-outline:hover {
  background: var(--primary-green);
  color: #fff;
}

.btn-danger {
  background: #e74c3c;
  color: #fff;
}

.btn-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 20px;
}

.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 20px;
}

.alert-error { background: #fdecea; color: #c0392b; }
.alert-success { background: #e8f5e9; color: #2e7d32; }

/* Product detail toolbar */
.detail-toolbar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 24px;
  align-items: center;
}

.detail-toolbar .back-link {
  margin-right: auto;
  font-weight: 600;
}

/* Recipe template */
.recipe-wrapper {
  background: #fff;
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.08);
}

.hero-green-bar {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  margin-top: auto;
  margin-bottom: auto;
  width: 50px;
  max-height: 480px;
  background-color: #4caf50;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.vertical-text {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  color: white;
  font-weight: 700;
  letter-spacing: 0.25em;
  font-size: 0.9rem;
  white-space: nowrap;
}

.recipe-card {
  max-width: 1200px;
  margin: 0 auto;
  overflow: hidden;
  box-shadow: 0 4px 15px rgba(0,0,0,0.05);
  background: var(--light-bg);
}

.hero-section {
  display: flex;
  align-items: center;
  position: relative;
  padding: 40px;
  background-color: #fdfdfd;
  min-height: 420px;
  overflow: visible;
}

.hero-content {
  flex: 0 0 37%;
  width: 37%;
  max-width: 37%;
  min-width: 37%;
  position: relative;
  z-index: 2;
  isolation: isolate;
}

.category-tag {
  color: var(--primary-green);
  font-weight: 800;
  letter-spacing: 1px;
  font-size: 1.2rem;
  margin-bottom: 10px;
}

.hero-content h1 {
  font-size: 1.5rem;
  line-height: 1.1;
  margin: 0 0 20px 0;
  text-transform: uppercase;
  color: #1a252f;
  text-align: left;
}

.hero-content h1::first-line {
  font-size: 2.5rem; /* Overrides the first line only */
}

.hero-content p {
  font-size: 1rem;
  line-height: 1.6;
  margin-bottom: 25px;
}

.bullet-list {
  list-style: none;
  padding: 0;
}

.bullet-list li {
  margin-bottom: 10px;
  font-weight: 600;
  display: flex;
  align-items: center;
}

.bullet-list li::before {
  content: '✔';
  color: var(--primary-green);
  margin-right: 10px;
  font-size: 1.2rem;
}

.hero-image-container {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  margin-top: auto;
  margin-bottom: auto;
  width: 100%;
  max-height: 480px;
  overflow: hidden;
  z-index: 1;
  pointer-events: none;
  /* DELETED: clip-path: polygon(50% 0%, 100% 0%, 100% 100%, 30% 100%); */
}

/* NEW: Styles the SVG mask to stretch exactly over the image */
.pdf-mask {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2; /* Forces the mask to sit directly on top of the image */
}

.hero-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.quick-stats-panel {
  flex: 0 0 210px;
  width: 210px;
  margin-left: auto;
  position: relative;
  z-index: 3;
  background: #e8ebef;
  border-radius: 14px;
  padding: 0 6px 6px 0;
}

.quick-stats {
  background: #fff;
  padding: 20px;
  border-radius: 12px;
  border: 1px solid #d5dbe3;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 15px;
}

.stat-icon { font-size: 2rem; }
.stat-info span { display: block; }
.stat-value { font-size: 1.4rem; font-weight: bold; }
.stat-label { font-size: 0.8rem; color: #7f8c8d; text-transform: uppercase; }

.tables-section { padding: 0 40px 40px 40px; }

.section-title {
  display: flex;
  align-items: center;
  font-size: 1.2rem;
  font-weight: bold;
  margin-bottom: 15px;
  gap: 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  margin-bottom: 30px;
  border-radius: 8px;
  overflow: hidden;
}

th, td {
  padding: 12px 15px;
  text-align: center;
  border: 1px solid var(--border-color);
}

th:first-child, td:first-child { text-align: left; font-weight: bold; }

thead th { color: #fff; }
thead th:first-child { background-color: #e9ecef; color: var(--dark-text); }

.c-1400 { background-color: var(--c-1400); }
.c-1600 { background-color: var(--c-1600); }
.c-1800 { background-color: var(--c-1800); }
.c-2000 { background-color: var(--c-2000); }
.c-2400 { background-color: var(--c-2400); }

.nutrition-table td { font-weight: 500; }
.highlight-col { color: var(--c-2000); font-weight: bold; }

.bottom-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 40px;
  padding: 0 40px 40px 40px;
}

.prep-steps ol {
  padding-left: 20px;
  margin: 0;
}

.prep-steps li {
  margin-bottom: 12px;
  line-height: 1.5;
}

.substitutions ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.substitutions li {
  margin-bottom: 12px;
  font-size: 0.95rem;
}

.sub-arrow { margin: 0 5px; color: #7f8c8d; }

.suitability { display: flex; gap: 20px; }

.suit-list {
  list-style: none;
  padding: 0;
  margin: 0;
  flex: 1;
}

.suit-list li {
  margin-bottom: 10px;
  font-size: 0.9rem;
  display: flex;
  align-items: flex-start;
}

.suit-list.positive li::before {
  content: '✔';
  color: var(--primary-green);
  margin-right: 8px;
  font-weight: bold;
}

.suit-list.negative li::before {
  content: '✖';
  color: red;
  margin-right: 8px;
  font-weight: bold;
}

.card-footer {
  background-color: #1a252f;
  color: #fff;
  display: flex;
  justify-content: space-around;
  padding: 20px;
}

.footer-item {
  display: flex;
  align-items: center;
  gap: 15px;
}

.footer-icon { font-size: 2rem; }
.footer-item span { display: block; }
.f-label { font-size: 0.8rem; color: #bdc3c7; text-transform: uppercase; }
.f-value { font-size: 1.2rem; font-weight: bold; }

.recipe-card.export-capture .hero-content {
  z-index: 10;
}

.recipe-card.export-capture .hero-content h1 {
  text-align: left;
}

.recipe-card.export-capture .hero-content h1 .title-line {
  display: block;
  text-align: left;
}

.recipe-card.export-capture .hero-image-container {
  z-index: 1;
  top: 0;
  bottom: 0;
  margin-top: auto;
  margin-bottom: auto;
  transform: none;
}

/* Ingredient prices editor */
.prices-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.prices-toolbar .page-title {
  margin: 0;
}

.prices-category {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.08);
}

.prices-category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.category-name-input {
  font-size: 1.2rem;
  font-weight: 700;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 4px 0;
  min-width: 200px;
  background: transparent;
  color: #1a252f;
}

.category-name-input:focus {
  outline: none;
  border-bottom-color: var(--primary-green);
}

.prices-table-wrap {
  overflow-x: auto;
}

.prices-table {
  width: 100%;
  border-collapse: collapse;
}

.prices-table th,
.prices-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.prices-table th {
  background: #f5f6f7;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #7f8c8d;
}

.prices-table input[type="text"],
.prices-table input[type="number"],
.prices-table select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 0.95rem;
}

.prices-table input[type="number"] {
  max-width: 120px;
}

.prices-table select {
  max-width: 120px;
}

.prices-actions {
  width: 100px;
  text-align: right;
}

@media (max-width: 900px) {
  .hero-section {
    flex-direction: column;
    align-items: stretch;
    min-height: auto;
    gap: 24px;
  }

  .hero-content {
    flex: none;
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .hero-image-container {
    position: relative;
    top: auto;
    right: auto;
    transform: none;
    width: 100%;
    max-width: 100%;
    aspect-ratio: 16 / 10;
    border-radius: 12px;
    pointer-events: auto;
  }

  .quick-stats-panel {
    flex: none;
    width: 100%;
    margin-left: 0;
  }

  .bottom-grid { grid-template-columns: 1fr; }
  .hero-content h1 { font-size: 2rem; }
}

@media (max-width: 768px) {
  .form-row,
  .form-row-4,
  .list-item-grid-2,
  .list-item-grid-3,
  .form-row-3 {
    grid-template-columns: 1fr;
  }

  .list-item {
    flex-direction: column;
    align-items: stretch;
  }
}
