/* ====== CUSTOM PROPERTIES / THEME ====== */
:root {
  --bg-primary: #f5efe6;
  --bg-secondary: #ebe5dc;
  --bg-card: rgba(255, 255, 255, 0.96);
  --bg-card-hover: rgba(255, 255, 255, 1);
  --accent: #c75632;
  --accent-light: #d96846;
  --accent-glow: rgba(199, 86, 50, 0.25);
  --text-dark: #3d3530;
  --text-muted: #6b5f56;
  --text-light: #ffffff;
  --border-subtle: rgba(61, 53, 48, 0.08);
  --shadow-sm: 0 2px 8px rgba(61, 53, 48, 0.08);
  --shadow-md: 0 8px 30px rgba(61, 53, 48, 0.12);
  --shadow-lg: 0 20px 60px rgba(61, 53, 48, 0.16);
  --shadow-glow: 0 8px 30px rgba(199, 86, 50, 0.15);
  --radius-sm: 12px;
  --radius-md: 20px;
  --radius-lg: 28px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "DM Sans", system-ui, sans-serif;
  --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ====== RESET & BASE ====== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  background: var(--bg-primary);
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--text-dark);
  line-height: 1.6;
  overflow-x: hidden;
}

/* Ambient background */
body::before {
  content: "";
  position: fixed;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background:
    radial-gradient(
      ellipse at 20% 20%,
      rgba(255, 255, 255, 0.5) 0%,
      transparent 50%
    ),
    radial-gradient(
      ellipse at 80% 80%,
      rgba(199, 86, 50, 0.08) 0%,
      transparent 50%
    );
  z-index: -1;
  animation: ambientShift 20s ease-in-out infinite alternate;
}

@keyframes ambientShift {
  0% {
    transform: translate(0, 0) rotate(0deg);
  }
  100% {
    transform: translate(-5%, -5%) rotate(3deg);
  }
}

/* Grain texture overlay */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  opacity: 0.02;
  pointer-events: none;
  z-index: -1;
}

/* ====== TYPOGRAPHY ====== */
h1,
h2,
h3,
h4,
h5 {
  font-family: var(--font-display);
  font-weight: 500;
  line-height: 1.2;
}

h1 {
  font-size: clamp(2rem, 5vw, 3.5rem);
  font-weight: 400;
  color: var(--text-dark);
  letter-spacing: -0.02em;
}

/* Decorative underline for main title */
h1::after {
  content: "";
  display: block;
  width: 60px;
  height: 3px;
  background: var(--accent);
  margin: 0.75rem auto 0;
  border-radius: 2px;
}

/* ====== HEADER ====== */
.header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3rem;
  padding: 1rem 0;
}

.header-title {
  flex: 1;
  text-align: center;
}

.logout-btn {
  background: var(--accent);
  border: none;
  color: white;
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: 0 2px 8px var(--accent-glow);
}

.logout-btn:hover {
  background: var(--accent-light);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--accent-glow);
}

.search-panel {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.ingredient-row {
  cursor: grab;
}

.ingredient-row.dragging {
  cursor: grabbing;
  opacity: 0;
}

.search-input-group {
  display: flex;
  gap: 0.75rem;
  align-items: stretch;
}

.search-input-group .form-control {
  flex: 1;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  padding: 0.75rem 1rem;
  font-size: 1rem;
}

.search-input-group .btn {
  border-radius: var(--radius-sm);
  font-weight: 600;
}

#search-status {
  display: block;
  margin-top: 0.75rem;
}

/* ====== LOADING STATE ====== */
#loading {
  padding: 4rem 0;
}

.spinner-border {
  width: 3rem;
  height: 3rem;
  border-width: 3px;
  color: var(--accent) !important;
}

#loading p {
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--text-dark);
  opacity: 0.7;
  margin-top: 1.5rem;
}

/* ====== RECIPE CARDS GRID ====== */
#recipes-container.row {
  --bs-gutter-x: 2rem;
  --bs-gutter-y: 2rem;
}

/* ====== RECIPE CARD ====== */
.recipe-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  transition: all var(--transition-smooth);
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

.recipe-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--radius-lg);
  padding: 1px;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.4),
    rgba(255, 255, 255, 0.1)
  );
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.recipe-overview {
  cursor: pointer;
}

.recipe-overview:hover {
  transform: translateY(-8px) scale(1.01);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
}

.recipe-overview:hover .recipe-image {
  transform: scale(1.05);
}

.recipe-overview:active {
  transform: translateY(-4px) scale(1);
}

/* ====== RECIPE IMAGE ====== */
.recipe-image-wrapper {
  position: relative;
  overflow: hidden;
}

.recipe-image {
  width: 100%;
  height: 220px;
  object-fit: cover;
  transition: transform var(--transition-smooth);
}

.recipe-placeholder {
  width: 100%;
  height: 220px;
  background: linear-gradient(135deg, #f0e9de 0%, #e5ddd0 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-style: italic;
  position: relative;
}

.recipe-placeholder::before {
  content: "🍽️";
  font-size: 3rem;
  opacity: 0.3;
}

/* ====== RECIPE CONTENT ====== */
.recipe-content {
  padding: 1.5rem 1.75rem 1.75rem;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: var(--bg-card);
}

.recipe-title {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 500;
  color: var(--text-dark);
  margin: 0;
  text-align: center;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

/* ====== RECIPE DETAIL PAGE ====== */
.recipe-detail-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  max-width: 1100px;
  margin: 0 auto;
  animation: fadeInUp 0.6s ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.recipe-detail-image-wrapper {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #f0e9de 0%, #e5ddd0 100%);
}

.recipe-detail-image {
  width: 100%;
  height: auto;
  max-height: 450px;
  object-fit: cover;
  object-position: center;
}

.recipe-placeholder-large {
  width: 100%;
  height: 300px;
  background: linear-gradient(135deg, #f0e9de 0%, #e5ddd0 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 1.1rem;
  font-style: italic;
}

.recipe-detail-content {
  padding: 2rem;
  flex-grow: 1;
  color: var(--text-dark);
}

@media (min-width: 768px) {
  .recipe-detail-content {
    padding: 2.5rem;
  }
}

/* Two-column layout for description + ingredients on desktop */
.recipe-detail-body {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Auf schmalen Bildschirmen: Zutaten vor Beschreibung anzeigen */
.recipe-ingredients-col {
  order: -1;
}

@media (min-width: 1100px) {
  .recipe-detail-body {
    flex-direction: row;
    gap: 3rem;
    align-items: flex-start;
  }

  .recipe-description-col {
    flex: 1;
    min-width: 0;
  }

  .recipe-ingredients-col {
    flex: 0 0 420px;
    order: initial;
  }

  .recipe-ingredients-col .ingredients-section {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
  }
}

.recipe-detail-title {
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 500;
  color: var(--text-dark);
  margin-bottom: 1.5rem;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.recipe-detail-title::after {
  content: "";
  display: block;
  width: 50px;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  margin-top: 0.75rem;
  border-radius: 2px;
}

.recipe-description {
  color: var(--text-muted);
  margin-bottom: 1rem;
  font-size: 1rem;
}

.recipe-description p {
  margin: 0 0 0.6rem 0;
  line-height: 1.28;
}

/* ====== INGREDIENTS SECTION ====== */
.ingredients-section {
  text-align: left;
}

.ingredients-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--text-dark);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ingredients-title::before {
  content: "🥗";
  font-size: 1.1rem;
}

/* Servings controls */
.servings-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.servings-controls .form-label {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-dark);
  margin: 0;
}

.servings-controls input[type="number"] {
  width: 70px;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.95rem;
  text-align: center;
  background: rgba(255, 255, 255, 0.8);
  transition: all var(--transition-fast);
}

.servings-controls input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.servings-controls .btn {
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  transition: all var(--transition-fast);
}

/* Ingredients table */
.ingredients-wrap {
  overflow-x: auto;
}

#ingredientsTable {
  width: auto !important;
  border-collapse: separate;
  border-spacing: 0;
}

#ingredientsTable th,
#ingredientsTable td {
  padding: 0.35rem 0.5rem;
  vertical-align: middle;
  white-space: nowrap;
  color: var(--text-dark);
  background: rgba(199, 86, 50, 0.07);
  border-bottom: 1px solid rgba(61, 53, 48, 0.04);
  line-height: 1.15;
}

#ingredientsTable tr:first-child th,
#ingredientsTable tr:first-child td {
  border-top-left-radius: var(--radius-sm);
  border-top-right-radius: var(--radius-sm);
}

#ingredientsTable tr:last-child td {
  border-bottom-left-radius: var(--radius-sm);
  border-bottom-right-radius: var(--radius-sm);
  border-bottom: none;
}

#ingredientsTable th:first-child,
#ingredientsTable td:first-child {
  text-align: right;
  font-weight: 600;
  color: var(--accent);
  /* Make first column only as wide as its content (e.g. the word 'Menge') */
  width: 1%;
  white-space: nowrap;
}

#ingredientsTable th:nth-child(2),
#ingredientsTable td:nth-child(2) {
  text-align: left;
}

#ingredientsTable th:nth-child(3),
#ingredientsTable td:nth-child(3) {
  white-space: normal;
}

/* ====== BUTTONS ====== */
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--accent);
  border: none;
  color: white;
  padding: 0.85rem 1.5rem;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px var(--accent-glow);
  transition: all var(--transition-fast);
  text-decoration: none;
}

.btn-back:hover {
  background: var(--accent-light);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--accent-glow);
  color: white;
}

.btn-back:active {
  transform: translateY(0);
}

.btn-light {
  background: var(--bg-card);
  border: none;
  box-shadow: var(--shadow-sm);
  font-weight: 500;
  padding: 0.85rem 1.5rem;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  color: var(--text-dark);
}

.btn-light:hover {
  background: var(--bg-card-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  color: var(--text-dark);
}

.btn-accent {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--accent);
  border: none;
  color: var(--text-light);
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 12px var(--accent-glow);
  transition: all var(--transition-fast);
  text-decoration: none;
}

.btn-accent:hover {
  background: var(--accent-light);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px var(--accent-glow);
  color: var(--text-light);
}

.btn-accent:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ====== COOKED RECIPES SECTION ====== */
.recipe-cooked-section {
  margin-top: 2.5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.cooked-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
}

@media (min-width: 576px) {
  .cooked-actions {
    flex-direction: row;
    align-items: center;
  }
}

.cooked-feedback,
.cooked-error,
.cooked-stats-empty {
  margin: 0;
  font-size: 0.95rem;
}

.cooked-feedback {
  color: var(--accent);
}

.cooked-error {
  color: #b02a37;
}

.cooked-heading {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 500;
  margin: 0;
}

.cooked-stats-content {
  min-height: 1.75rem;
}

.cooked-stats-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.cooked-stats-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.75);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow-sm);
}

.cooked-name {
  font-weight: 600;
  color: var(--text-dark);
}

.cooked-count {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--accent);
}

/* ====== LOGIN PAGE ====== */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.login-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 3rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  animation: fadeInUp 0.5s ease-out;
}

.login-card h2 {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 500;
  color: var(--text-dark);
  text-align: center;
  margin-bottom: 0.5rem;
}

.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 2rem;
  font-size: 0.95rem;
}

.login-card .form-label {
  font-weight: 500;
  color: var(--text-dark);
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.login-card .form-control {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  font-family: var(--font-body);
  font-size: 1rem;
  transition: all var(--transition-fast);
  background: rgba(255, 255, 255, 0.8);
}

.login-card .form-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: white;
}

.btn-login {
  background: var(--accent);
  border: none;
  color: white;
  padding: 1rem;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  width: 100%;
  margin-top: 0.5rem;
}

.btn-login:hover {
  background: var(--accent-light);
  transform: translateY(-2px);
  box-shadow: 0 8px 25px var(--accent-glow);
}

.btn-login:active {
  transform: translateY(0);
}

.btn-login:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

/* ====== ERROR STATES ====== */
.error {
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  color: white;
  padding: 2.5rem;
  border-radius: var(--radius-lg);
  text-align: center;
  box-shadow: var(--shadow-md);
}

.error h2 {
  color: white;
  margin-bottom: 1rem;
}

#error-msg {
  color: var(--accent);
  font-size: 0.9rem;
  margin-top: 1rem;
  padding: 0.75rem;
  background: var(--accent-glow);
  border-radius: var(--radius-sm);
}

/* ====== UTILITIES ====== */
.text-white {
  color: var(--text-light) !important;
}

/* Staggered animation for recipe cards */
.recipe-card {
  animation: fadeInUp 0.5s ease-out backwards;
}

#recipes-container > div:nth-child(1) .recipe-card {
  animation-delay: 0.1s;
}
#recipes-container > div:nth-child(2) .recipe-card {
  animation-delay: 0.15s;
}
#recipes-container > div:nth-child(3) .recipe-card {
  animation-delay: 0.2s;
}
#recipes-container > div:nth-child(4) .recipe-card {
  animation-delay: 0.25s;
}
#recipes-container > div:nth-child(5) .recipe-card {
  animation-delay: 0.3s;
}
#recipes-container > div:nth-child(6) .recipe-card {
  animation-delay: 0.35s;
}

/* Responsive adjustments */
@media (max-width: 1100px) {
  .container {
    padding-left: 1.25rem;
    padding-right: 1.25rem;
  }

  h1::after {
    margin: 0.5rem auto 0;
  }

  .recipe-card {
    border-radius: var(--radius-md);
  }

  .recipe-content {
    padding: 1.25rem;
  }

  .recipe-title {
    font-size: 1.2rem;
  }

  .recipe-detail-content {
    padding: 1.75rem;
  }

  .login-card {
    padding: 2rem;
  }
}

/* Focus visible for accessibility */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Selection color */
::selection {
  background: var(--accent);
  color: white;
}
