/* Reset & Base */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Header gradient */
  --header-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);

  /* Day card gradients */
  --card-pink: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  --card-blue: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  --card-green: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);

  /* Content area */
  --content-bg: #ffffff;
  --content-radius: 24px;

  /* Text */
  --text-primary: #1a1a2e;
  --text-secondary: #666;
  --text-light: rgba(255, 255, 255, 0.9);
  --text-muted: rgba(255, 255, 255, 0.7);

  /* UI */
  --border-color: #e5e5e5;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
}

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

body {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
    sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  color: var(--text-primary);
  line-height: 1.5;
}

/* App Container */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  background: var(--header-bg);
  color: white;
  padding: 2rem 1.5rem;
  padding-top: calc(2rem + env(safe-area-inset-top, 0px));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.header-compact {
  padding: 1.5rem;
  padding-top: calc(1.5rem + env(safe-area-inset-top, 0px));
  align-items: center;
}

.header h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.header-compact h1 {
  font-size: 1.5rem;
  margin-bottom: 0;
}

.subtitle {
  font-size: 1rem;
  color: var(--text-muted);
}

.header-nav {
  display: flex;
  gap: 1rem;
}

.nav-link {
  color: var(--text-light);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.15);
  transition: background 0.2s;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.25);
}

.back-link {
  color: var(--text-light);
  text-decoration: none;
  font-size: 0.9rem;
}

/* Content Area */
.content {
  flex: 1;
  background: var(--content-bg);
  border-radius: var(--content-radius) var(--content-radius) 0 0;
  padding: 1.5rem;
  margin-top: -1rem;
}

/* Week View */
.week-view {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Day Cards */
.day-card {
  border-radius: 16px;
  padding: 1.25rem;
  color: white;
  box-shadow: var(--shadow);
  transition:
    transform 0.2s,
    box-shadow 0.2s;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.day-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15);
}

.day-card.consumed {
  opacity: 0.6;
}

.gradient-pink {
  background: var(--card-pink);
}
.gradient-blue {
  background: var(--card-blue);
}
.gradient-green {
  background: var(--card-green);
}

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

.day-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  opacity: 0.8;
}

.ingredient-count {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.875rem;
}

.ingredient-icon {
  font-size: 1rem;
}

.day-card .meal-name {
  font-size: 1.25rem;
  font-weight: 600;
  color: white;
  text-decoration: none;
}

.day-card-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.btn-icon {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Unassigned Section */
.unassigned-section {
  margin-top: 2rem;
}

.section-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 1rem;
}

.unassigned-card {
  background: #f5f5f5;
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.unassigned-card .meal-name {
  color: var(--text-primary);
  text-decoration: none;
  font-weight: 500;
}

.unassigned-card .ingredient-count {
  color: var(--text-secondary);
}

/* Sections */
.section {
  margin-top: 2rem;
}

/* Backlog Section */
.backlog-section {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
}

.backlog-card {
  background: #f0f0f0;
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.backlog-card .meal-name {
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
}

.backlog-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.backlog-card .ingredient-count {
  color: var(--text-secondary);
}

.btn-add-week {
  background: var(--header-bg);
  color: white;
  font-size: 1.25rem;
  font-weight: bold;
}

.btn-add-week:hover {
  opacity: 0.9;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-secondary);
}

.empty-state p {
  margin-bottom: 0.5rem;
}

.hint {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.hint a {
  color: #667eea;
}

/* FAB */
.fab {
  position: fixed;
  bottom: 2rem;
  right: 1.5rem;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--header-bg);
  color: white;
  font-size: 2rem;
  border: none;
  box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
  cursor: pointer;
  transition:
    transform 0.2s,
    box-shadow 0.2s;
}

.fab:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

/* Modal */
.modal {
  border: none;
  border-radius: 16px;
  padding: 0;
  max-width: 400px;
  width: calc(100% - 2rem);
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  padding: 1.5rem;
}

/* Forms */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

input[type="text"],
input[type="password"],
select {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: white;
  transition: border-color 0.2s;
}

input:focus,
select:focus {
  outline: none;
  border-color: #667eea;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

/* Buttons */
.btn {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 500;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition:
    opacity 0.2s,
    transform 0.2s;
}

.btn:hover {
  opacity: 0.9;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--header-bg);
  color: white;
}

.btn-secondary {
  background: #f5f5f5;
  color: var(--text-primary);
}

.btn-danger {
  background: #f5576c;
  color: white;
}

.btn-block {
  width: 100%;
}

/* Meal Detail */
.meal-detail-form {
  margin-bottom: 2rem;
}

.ingredients-section {
  margin-bottom: 2rem;
}

.ingredients-section h2 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

.ingredient-form {
  margin-bottom: 1rem;
}

.ingredient-inputs {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 0.5rem;
  align-items: center;
}

.input-name {
  min-width: 0;
}

.input-qty {
  width: 70px !important;
}

.input-category {
  width: 100px !important;
}

.btn-add {
  padding: 0.75rem 1rem;
  min-width: 44px;
}

.ingredients {
  list-style: none;
}

.ingredient-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.ingredient-name {
  flex: 1;
  font-weight: 500;
}

.ingredient-qty {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.ingredient-category {
  background: #f0f0f0;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.btn-delete {
  background: none;
  border: none;
  color: #f5576c;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
}

.no-ingredients {
  color: var(--text-secondary);
  font-style: italic;
  padding: 1rem 0;
}

.danger-zone {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-color);
}

/* Login */
.login-form {
  max-width: 300px;
  margin: 2rem auto;
}

.pin-input {
  font-size: 1.5rem !important;
  text-align: center;
  letter-spacing: 0.5em;
}

.error-message {
  background: #fee2e2;
  color: #dc2626;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  margin-bottom: 1rem;
  text-align: center;
}

/* Shopping List */
.shopping-actions {
  margin-bottom: 1.5rem;
}

.shopping-list {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.category-group {
  background: #f9f9f9;
  border-radius: 12px;
  padding: 1rem;
}

.category-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}

.category-items {
  list-style: none;
}

.shopping-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-color);
}

.shopping-item:last-child {
  border-bottom: none;
}

.item-name {
  font-weight: 500;
}

.item-qty {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* Responsive */
@media (min-width: 640px) {
  .ingredient-inputs {
    grid-template-columns: 1fr 80px 120px auto;
  }
}

@media (min-width: 768px) {
  .app {
    max-width: 800px;
    margin: 0 auto;
  }

  .header {
    border-radius: 0 0 24px 24px;
    margin-top: 1rem;
  }

  .content {
    border-radius: 24px 24px 0 0;
  }

  body {
    padding: 0 1rem;
  }
}

@media (min-width: 1024px) {
  .app {
    max-width: 900px;
  }
}

/* Dark Mode */
@media (prefers-color-scheme: dark) {
  :root {
    --content-bg: #1a1a2e;
    --text-primary: #f0f0f0;
    --text-secondary: #a0a0a0;
    --border-color: #3a3a4e;
  }

  body {
    background: linear-gradient(135deg, #4a5568 0%, #2d3748 100%);
  }

  .content {
    background: var(--content-bg);
  }

  .unassigned-card,
  .backlog-card {
    background: #2a2a3e;
  }

  .backlog-card .meal-name {
    color: var(--text-secondary);
  }

  .category-group {
    background: #2a2a3e;
  }

  input[type="text"],
  input[type="password"],
  select {
    background: #2a2a3e;
    border-color: var(--border-color);
    color: var(--text-primary);
  }

  .btn-secondary {
    background: #3a3a4e;
    color: var(--text-primary);
  }

  .modal {
    background: var(--content-bg);
  }

  .ingredient-category {
    background: #3a3a4e;
  }

  .error-message {
    background: #4a2020;
    color: #ff8080;
  }
}
