/*
 * RecipeBox — Custom Theme
 * Warm food-inspired colour palette applied via oat-ui CSS variables.
 */

:root {
  --primary: #d97706;
  --primary-foreground: #fff;
  --secondary: #fef3c7;
  --secondary-foreground: #92400e;
  --accent: #f59e0b;
  --accent-foreground: #1c1917;
  --background: #fffbeb;
  --foreground: #1c1917;
  --card: #ffffff;
  --card-foreground: #1c1917;
  --border: #e5e7eb;
  --input: #d4d4d8;
  --ring: #d97706;
  --muted: #f5f5f4;
  --muted-foreground: #78716c;
  --faint: #fefce8;
  --faint-foreground: #a8a29e;
  --danger: #dc2626;
  --danger-foreground: #fff;
  --success: #16a34a;
  --success-foreground: #fff;
  --warning: #f59e0b;
  --warning-foreground: #1c1917;
}

[data-theme="dark"] {
  --primary: #f59e0b;
  --primary-foreground: #1c1917;
  --secondary: #44403c;
  --secondary-foreground: #fef3c7;
  --accent: #d97706;
  --accent-foreground: #fff;
  --background: #1c1917;
  --foreground: #fafaf9;
  --card: #292524;
  --card-foreground: #fafaf9;
  --border: #44403c;
  --input: #57534e;
  --ring: #f59e0b;
  --muted: #292524;
  --muted-foreground: #a8a29e;
  --faint: #1c1917;
  --faint-foreground: #78716c;
  --danger: #ef4444;
  --danger-foreground: #fff;
  --success: #22c55e;
  --success-foreground: #fff;
  --warning: #f59e0b;
  --warning-foreground: #1c1917;
}

/* ---- RecipeBox-specific styles ---- */

/* Recipe card image */
.recipe-card-img {
  width: 100%;
  height: 180px;
  object-fit: cover;
  border-radius: var(--radius, 0.375rem) var(--radius, 0.375rem) 0 0;
}

.recipe-card-placeholder {
  width: 100%;
  height: 180px;
  background: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted-foreground);
  font-size: 3rem;
  border-radius: var(--radius, 0.375rem) var(--radius, 0.375rem) 0 0;
}

/* Recipe detail hero */
.recipe-hero {
  display: block;
  margin-left: auto;
  margin-right: auto;
  width: auto;
  max-width: 100%;
  max-height: 250px;
  object-fit: contain;
  border-radius: var(--radius, 0.375rem);
  margin-bottom: var(--space-4, 1rem);
}

.recipe-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3, 0.75rem);
  align-items: center;
  margin-bottom: var(--space-4, 1rem);
  color: var(--muted-foreground);
}

.recipe-meta span {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

/* Calendar */
.calendar-table {
  table-layout: fixed;
  width: 100%;
}

.calendar-table th {
  text-align: center;
  font-size: 0.85rem;
  padding: var(--space-2, 0.5rem);
}

.calendar-table td {
  vertical-align: top;
  height: 100px;
  padding: var(--space-1, 0.25rem) var(--space-2, 0.5rem);
  border: 1px solid var(--border);
  position: relative;
}

.calendar-table td.today {
  background: var(--secondary);
}

.calendar-table td.other-month {
  opacity: 0.4;
}

.calendar-day-num {
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: var(--space-1, 0.25rem);
}

.calendar-day-name {
  display: none;
}

.calendar-day-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-1);
}

.calendar-entries {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

@media (max-width: 768px) {
  .calendar-table thead {
    display: none;
  }
  .calendar-table, 
  .calendar-table tbody, 
  .calendar-table tr, 
  .calendar-table td {
    display: block;
    width: 100%;
  }
  .calendar-table td {
    height: auto;
    min-height: 80px;
    padding: var(--space-4) !important;
    border-bottom: 1px solid var(--border);
  }
  .calendar-table td.other-month {
    display: none; /* Hide days from other months on mobile list view */
  }
  .calendar-day-name {
    display: inline;
    font-weight: 600;
  }
  .calendar-day-num {
    font-size: 1.2rem;
    font-weight: 700;
    margin: 0;
  }
  .calendar-entries {
    margin-bottom: var(--space-4);
    gap: 4px;
  }
  .calendar-add-btn {
    position: relative;
    bottom: 0;
    right: 0;
    display: block !important;
    width: 100%;
    margin-top: var(--space-2);
  }
}

.calendar-add-btn {
  position: absolute;
  bottom: 4px;
  right: 4px;
  font-size: 0.75rem;
  padding: 0 0.4rem;
  line-height: 1.5;
}

/* Ingredient row styling */
.ingredient-row {
  display: grid;
  gap: var(--space-3, 0.75rem);
  margin-bottom: var(--space-3, 0.75rem);
  padding: var(--space-3, 0.75rem);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-medium);
}

.ingredient-primary-fields,
.ingredient-secondary-fields {
  display: grid;
  gap: var(--space-2, 0.5rem);
  align-items: end;
}

.ingredient-primary-fields {
  grid-template-columns: minmax(180px, 0.9fr) minmax(0, 1.4fr);
}

.ingredient-secondary-fields {
  grid-template-columns: minmax(120px, 0.8fr) minmax(0, 1.4fr) auto;
}

.ing-field {
  min-width: 0;
}

.ing-field label {
  display: block;
  margin-bottom: var(--space-1, 0.25rem);
  font-size: 0.875rem;
  color: var(--muted-foreground);
}

.ing-qty-group {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: var(--space-2, 0.5rem);
}

.ing-qty,
.ing-unit,
.ing-name,
.ing-aisle,
.ing-notes {
  width: 100%;
  min-width: 0;
}

.ing-actions {
  display: flex;
  align-items: end;
}

.remove-ingredient {
  white-space: nowrap;
}

@media (max-width: 600px) {
  .ingredient-row {
    padding: var(--space-4);
    margin-bottom: var(--space-4);
    gap: var(--space-3);
  }

  .ingredient-primary-fields,
  .ingredient-secondary-fields,
  .ing-qty-group,
  .ing-actions {
    grid-template-columns: minmax(0, 1fr);
  }

  .ingredient-primary-fields,
  .ingredient-secondary-fields,
  .ing-field,
  .ing-qty-group,
  .ing-name,
  .ing-aisle,
  .ing-notes,
  .remove-ingredient {
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
  }

  .ing-qty-group input,
  .ing-qty-group select,
  .ing-name,
  .ing-aisle,
  .ing-notes,
  .remove-ingredient {
    width: 100% !important;
    min-width: 0 !important;
  }

  .ing-actions {
    display: block;
  }

  .ingredient-row > input[type="hidden"] {
    display: none;
  }

  [role="tablist"] {
    flex-wrap: wrap;
    width: 100%;
  }

  [role="tab"] {
    flex: 1 1 auto;
  }
}

/* Auth pages centered layout */
.auth-container {
  max-width: 420px;
  margin: 4rem auto;
  padding: 0 var(--space-4, 1rem);
}

.auth-container h1 {
  text-align: center;
  margin-bottom: var(--space-4, 1rem);
}

/* Meal type badge colors */
.badge.meal-breakfast {
  background: #fbbf24;
  color: #1c1917;
}

.badge.meal-lunch {
  background: #34d399;
  color: #1c1917;
}

.badge.meal-dinner {
  background: #60a5fa;
  color: #1c1917;
}

.badge.meal-snack {
  background: #c084fc;
  color: #1c1917;
}

/* ---- Mobile & Accessibility Overrides ---- */

:root {
  --touch-target-min: 44px;
}

@media (max-width: 768px) {
  html {
    font-size: 16px; /* Ensure base is 16px */
  }

  nav[data-topnav] button[popovertarget] {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
  }

  /* Increase touch targets for buttons and interactive elements */
  button, 
  .button, 
  input[type="submit"], 
  input[type="button"], 
  input[type="reset"],
  .recipe-rating,
  [role="menuitem"],
  [role="tab"],
  nav[data-sidebar] a {
    min-height: var(--touch-target-min);
    min-width: var(--touch-target-min);
  }

  /* Ensure form inputs are easy to tap */
  input:not([type="checkbox"]):not([type="radio"]), 
  select, 
  textarea {
    min-height: var(--touch-target-min);
    font-size: 1rem !important; /* Prevent iOS zoom on focus */
  }

  /* Checkboxes and radios need larger hit areas too */
  input[type="checkbox"], 
  input[type="radio"] {
    width: 1.5rem;
    height: 1.5rem;
  }

  label:has(input[type="checkbox"]), 
  label:has(input[type="radio"]) {
    padding: var(--space-2) 0;
    min-height: var(--touch-target-min);
  }

  .outline-mobile-only {
    display: inline-flex !important;
  }

  /* Search & Filter form stacking on mobile */
  fieldset.group {
    flex-direction: column;
    border: none;
    padding: 0;
  }

  fieldset.group > legend,
  fieldset.group > :is(input, select, button) {
    border-radius: var(--radius-medium) !important;
    border-inline-end: 1px solid var(--input) !important;
    margin-bottom: var(--space-2);
    width: 100% !important;
  }
}

.outline-mobile-only {
  display: none;
}

/* ---- Responsive grid breakpoints ---- */

/* 3-column → 2-column on tablets */
@media (max-width: 1024px) {
  .col-4 {
    flex: 0 0 50% !important;
    max-width: 50% !important;
    --span: 6 !important;
  }
}

/* 2-column → 1-column on mobile */
@media (max-width: 600px) {
  .col-4 {
    flex: 0 0 100%;
    max-width: 100%;
  }

  .recipe-hero {
    max-height: 240px;
  }

  .auth-container {
    margin: 2rem auto;
  }
}

/* Calendar empty state */
.calendar-empty-msg {
  text-align: center;
  padding: var(--space-6, 1.5rem) var(--space-4, 1rem);
  color: var(--muted-foreground);
  font-style: italic;
}
