/* --- RESET & ROOT VARIABLES --- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --color-primary: #d97757;
  --color-primary-dark: #c25d3d;
  --color-background: #faf8f6;
  --color-surface: #ffffff;
  --color-text: #2d2d2d;
  --color-text-secondary: #6b6b6b;
  --color-border: #e8e4df;
  --color-success: #4a9d5f;
  --color-danger: #d94a4a;

  --spacing-xs: 0.5rem;
  --spacing-sm: 1rem;
  --spacing-md: 1.5rem;
  --spacing-lg: 2rem;
  --spacing-xl: 3rem;

  --radius: 0.75rem;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
}

/* --- BASIS LAYOUT --- */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  background-color: var(--color-background);
  color: var(--color-text);
  line-height: 1.6;
  transition:
    background-color 0.3s ease,
    color 0.3s ease;
}

.header {
  background-color: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--spacing-md) var(--spacing-lg);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--color-primary);
  letter-spacing: -0.02em;
}

.nav {
  display: flex;
  gap: var(--spacing-xs);
}

.nav-btn {
  padding: var(--spacing-xs) var(--spacing-md);
  background: transparent;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.nav-btn:hover {
  background-color: var(--color-background);
  color: var(--color-text);
}

.nav-btn.active {
  background-color: var(--color-primary);
  color: white;
}

.main-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--spacing-xl) var(--spacing-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* --- VIEWS --- */
.view {
  display: none;
  width: 100%;
  max-width: 1200px;
}
.view.active {
  display: block;
}

.view-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--spacing-lg);
  width: 100%;
}

.view-header h2 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-text);
}

/* --- BUTTONS --- */
.btn-primary,
.btn-secondary,
.btn-danger {
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 600;
  border: none;
}

.btn-primary {
  padding: var(--spacing-sm) var(--spacing-md);
  background-color: var(--color-primary);
  color: white;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
  background-color: var(--color-primary-dark);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-secondary {
  padding: var(--spacing-xs) var(--spacing-md);
  background-color: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn-secondary:hover {
  background-color: var(--color-background);
  border-color: var(--color-primary);
}

.btn-danger {
  padding: var(--spacing-xs) var(--spacing-md);
  background-color: var(--color-danger);
  color: white;
}
.btn-danger:hover {
  background-color: #c23838;
}

.btn-small {
  padding: var(--spacing-xs);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

/* --- FILTRE & INPUTS --- */
.view-filters {
  background-color: var(--color-surface);
  padding: var(--spacing-md);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  width: 100%;
  margin-bottom: var(--spacing-lg);
}

.filter-select,
.filter-input {
  width: 100%;
  padding: 0.6rem var(--spacing-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background-color: var(--color-background);
  color: var(--color-text);
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.2s;
}

.filter-select {
  appearance: none;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="%236b6b6b" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>');
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

.filter-select:focus,
.filter-input:focus,
.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(217, 119, 87, 0.1);
}

/* --- MADPLAN GRID --- */
.week-navigation {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--spacing-lg);
  padding: var(--spacing-sm);
  background-color: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
}

.week-navigation h3 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--color-text);
  margin: 0 var(--spacing-md);
  text-align: center;
}

.week-navigation button {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.week-navigation button#prev-week-btn::after {
  content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-chevron-left"><path d="m15 18-6-6 6-6"/></svg>');
  display: block;
  width: 16px;
  height: 16px;
}
.week-navigation button#next-week-btn::after {
  content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-chevron-right"><path d="m9 18 6-6-6-6"/></svg>');
  display: block;
  width: 16px;
  height: 16px;
}

.meal-grid-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--spacing-md);
  width: 100%;
}

.day-column {
  display: flex;
  flex-direction: column;
  background-color: var(--color-surface);
  border-radius: var(--radius);
  padding: var(--spacing-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
  min-height: 200px;
}

.day-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: var(--spacing-sm);
  padding-bottom: var(--spacing-xs);
  border-bottom: 1px solid var(--color-border);
}
.day-header span:first-child {
  font-weight: 600;
  color: var(--color-text);
}
.date-label {
  font-size: 0.9rem;
  color: var(--color-text-secondary);
}

.meal-type-section {
  border-top: 1px dashed var(--color-border);
  padding-top: var(--spacing-sm);
  margin-top: var(--spacing-sm);
}
.meal-type-section:first-of-type {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

.meal-type-section h5 {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--color-text-secondary);
  margin-bottom: var(--spacing-xs);
  display: flex;
  align-items: center;
}

.add-meal-type-btn {
  background: none;
  border: none;
  color: var(--color-text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  margin-left: var(--spacing-xs);
}
.add-meal-type-btn::before {
  content: "+";
}

/* --- MEAL CARD --- */
.meal-card {
  background-color: var(--color-background);
  border-radius: calc(var(--radius) * 0.75);
  padding: var(--spacing-sm);
  margin-bottom: var(--spacing-xs);
  border: 1px solid var(--color-border);
  cursor: pointer;
  position: relative;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.meal-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.meal-card h4 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
  display: block;
}
.meal-card p {
  display: none;
}

.meal-card-actions .btn-danger {
  padding: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s;
}
.meal-card-actions .btn-danger::before {
  content: "✕";
  font-size: 12px;
}
.meal-card:hover .meal-card-actions .btn-danger {
  opacity: 1;
  visibility: visible;
}

/* --- OPSKRIFT / INGREDIENS CARDS --- */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--spacing-md);
  width: 100%;
}

.card {
  background-color: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
}

.recipe-card-image {
  width: 100%;
  height: 180px;
  object-fit: cover;
  border-top-left-radius: var(--radius);
  border-top-right-radius: var(--radius);
}

.card-header {
  padding: var(--spacing-md);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.card-content {
  padding: 0 var(--spacing-md) var(--spacing-md);
  color: var(--color-text-secondary);
  font-size: 0.9rem;
}

.card-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
  display: block;
}

/* --- INDKØBSLISTE --- */
.shopping-item {
  display: flex;
  align-items: center;
  padding: var(--spacing-sm);
  border-bottom: 1px solid var(--color-border);
  gap: var(--spacing-xs);
}
.shopping-item-text-name {
  flex-grow: 1;
  color: var(--color-text);
}
.shopping-item-text-name.checked {
  text-decoration: line-through;
  color: var(--color-text-secondary);
}
.shopping-item-quantity {
  width: 60px;
  text-align: right;
  padding: 4px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
}
.shopping-item-unit {
  width: 40px;
  color: var(--color-text-secondary);
  font-size: 0.9rem;
}

/* --- MODAL --- */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.active {
  display: flex;
}

.modal {
  background-color: var(--color-surface);
  border-radius: var(--radius);
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  padding: var(--spacing-md);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-body {
  padding: var(--spacing-lg);
}
.modal-close {
  font-size: 1.5rem;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text);
}

/* Form Elements */
.form-group {
  margin-bottom: var(--spacing-md);
}
.form-group label {
  display: block;
  margin-bottom: 5px;
  color: var(--color-text);
  font-weight: 500;
}
.form-group input,
.form-group select {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background-color: var(--color-background);
  color: var(--color-text);
}
.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* Autocomplete i Modal */
.ingredient-entry {
  margin-bottom: 10px;
}
.autocomplete-item {
  padding: 8px;
  cursor: pointer;
}
.autocomplete-item:hover {
  background-color: var(--color-background);
  color: var(--color-primary);
}

.autocomplete-container {
  position: relative;
}

.autocomplete-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 10001 !important;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  max-height: 200px;
  overflow-y: auto;
}

/* Opskrift Selection i Modal */
.recipe-modal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  max-height: 300px;
  overflow-y: auto;
}
.recipe-selection-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 5px;
  text-align: center;
  cursor: pointer;
}
.recipe-selection-card.selected {
  border-color: var(--color-primary);
  background-color: rgba(217, 119, 87, 0.1);
}
.recipe-selection-image {
  width: 100%;
  height: 80px;
  object-fit: cover;
  border-radius: 5px;
}

/* --- AUTH STYLES --- */
.auth-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--color-background);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-card {
  background-color: var(--color-surface);
  padding: var(--spacing-xl);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
  text-align: center;
  border: 1px solid var(--color-border);
}

.auth-card h2 {
  margin-bottom: var(--spacing-md);
  font-size: 1.5rem;
}

.auth-links {
  margin-top: var(--spacing-md);
  font-size: 0.9rem;
}
.auth-links a {
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 500;
}
.auth-links a:hover {
  text-decoration: underline;
}

body.not-logged-in #app {
  display: none;
}

/* =========================================
   MOBIL OPTIMERING
   ========================================= */
@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    padding: var(--spacing-sm);
  }

  .nav {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 5px;
    justify-content: flex-start;
  }

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

  .main-content {
    padding: var(--spacing-sm);
  }
  .view-filters {
    flex-direction: column;
    gap: var(--spacing-sm);
  }

  .meal-grid-columns {
    grid-template-columns: 1fr;
  }
  .day-header span:first-child {
    font-size: 1rem;
  }
  .meal-card h4 {
    max-width: 200px;
  }

  .shopping-item {
    flex-wrap: wrap;
  }
  .shopping-item-text-name {
    width: 100%;
    margin-bottom: 5px;
  }

  .modal {
    width: 95%;
    max-height: 95vh;
  }
}

/* =========================================
   DARK MODE - VARIABLER & OVERRIDES
   ========================================= */

/* Variabler */
body.dark-mode {
  --color-background: #121212;
  --color-surface: #1e1e1e;
  --color-text: #e4e4e4;
  --color-text-secondary: #b0b0b0;
  --color-border: #333333;
  --color-primary: #724434;
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.6);
}

/* Styling Overrides */
body.dark-mode .nav-btn:not(.active) {
  color: var(--color-text-secondary);
}

body.dark-mode .nav-btn:hover {
  background-color: #333;
  color: var(--color-text);
}

body.dark-mode .btn-secondary {
  background-color: #2a2a2a;
  color: var(--color-text);
  border-color: var(--color-border);
}

body.dark-mode .btn-secondary:hover {
  background-color: #333;
  border-color: var(--color-primary);
}

body.dark-mode h2,
body.dark-mode h3,
body.dark-mode h4,
body.dark-mode h5 {
  color: var(--color-text);
}

body.dark-mode .week-navigation,
body.dark-mode .day-column,
body.dark-mode .card,
body.dark-mode .view-filters {
  background-color: var(--color-surface);
  border-color: var(--color-border);
}

/* Vender pilene i ugenavigationen (gør dem hvide) */
body.dark-mode .week-navigation button#prev-week-btn::after,
body.dark-mode .week-navigation button#next-week-btn::after {
  filter: invert(1);
}

/* Gør dato-vælgerens kalender-ikon hvidt (Dette er fixet du bad om) */
body.dark-mode .filter-input::-webkit-calendar-picker-indicator {
  filter: invert(1);
  cursor: pointer;
}

/* Sikrer mørk kalender-popup i Chrome/Edge */
body.dark-mode input[type="date"] {
  color-scheme: dark;
}