/* ========================================
   TinyPlates App - Design System
   Matches landing page tokens
   ======================================== */

:root {
  --warm: #FFF8F0;
  --cream: #FEF3E2;
  --peach: #FFDAB3;
  --coral: #FF8B5E;
  --deep: #D94F1E;
  --bark: #3D2112;
  --sage: #7CB58A;
  --sage-light: #E8F5EB;
  --text: #2B1810;
  --text-light: #6B5347;
  --white: #FFFFFF;
  --border: rgba(255, 218, 179, 0.4);
  --shadow: rgba(61, 33, 18, 0.06);
  --shadow-md: rgba(61, 33, 18, 0.1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text);
  background: var(--warm);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ========== HEADER ========== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-logo {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 1.3rem;
  color: var(--bark);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-logo span { font-size: 1.4rem; }

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

/* ========== BUTTONS ========== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: var(--deep);
  color: white;
}
.btn-primary:hover { background: #c14518; }

.btn-secondary {
  background: var(--cream);
  color: var(--bark);
  border: 1px solid var(--peach);
}
.btn-secondary:hover { background: var(--peach); }

.btn-sage {
  background: var(--sage);
  color: white;
}
.btn-sage:hover { background: #6aa577; }

.btn-ghost {
  background: transparent;
  color: var(--text-light);
  padding: 8px 12px;
}
.btn-ghost:hover { background: var(--cream); color: var(--bark); }

.btn-sm { padding: 6px 12px; font-size: 0.8rem; border-radius: 8px; }
.btn-lg { padding: 14px 28px; font-size: 1rem; border-radius: 14px; }
.btn-icon { padding: 8px; border-radius: 10px; }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* ========== LAYOUT ========== */
.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px;
}

/* ========== WELCOME STATE ========== */
.welcome-section {
  text-align: center;
  padding: 60px 24px;
}

.welcome-section h2 {
  font-family: 'Syne', sans-serif;
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  font-weight: 800;
  color: var(--bark);
  margin-bottom: 12px;
}

.welcome-section p {
  color: var(--text-light);
  font-size: 1.05rem;
  max-width: 480px;
  margin: 0 auto 40px;
  line-height: 1.6;
}

/* ========== CHILDREN PANEL ========== */
.children-panel {
  background: var(--white);
  border-radius: 20px;
  padding: 28px;
  border: 1px solid var(--border);
  box-shadow: 0 2px 20px var(--shadow);
  margin-bottom: 28px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.panel-title {
  font-family: 'Syne', sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--bark);
}

/* Add child form */
.add-child-form {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  padding: 20px;
  background: var(--cream);
  border-radius: 14px;
  margin-bottom: 20px;
}

.form-group {
  flex: 1;
  min-width: 160px;
}

.form-group label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-group input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--peach);
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.9rem;
  background: var(--white);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: var(--coral);
  box-shadow: 0 0 0 3px rgba(255, 139, 94, 0.15);
}

.add-child-form .btn {
  align-self: flex-end;
  white-space: nowrap;
}

/* Children list */
.children-list {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.child-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: var(--warm);
  border-radius: 14px;
  border: 1px solid var(--border);
  transition: all 0.2s;
}

.child-avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.child-avatar.stage-0 { background: #FFE0CC; }
.child-avatar.stage-1 { background: #FFD4B8; }
.child-avatar.stage-2 { background: var(--sage-light); }
.child-avatar.stage-3 { background: #FFF0E0; }

.child-info h4 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--bark);
}

.child-info span {
  font-size: 0.78rem;
  color: var(--text-light);
}

.child-remove {
  background: none;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  padding: 4px;
  font-size: 1.1rem;
  opacity: 0.5;
  transition: opacity 0.2s;
}
.child-remove:hover { opacity: 1; color: var(--deep); }

/* ========== GENERATE BUTTON ========== */
.generate-section {
  text-align: center;
  padding: 20px 0 40px;
}

.generate-section .btn {
  font-size: 1.05rem;
  padding: 16px 36px;
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(217, 79, 30, 0.25);
}

.generate-section .btn:hover {
  box-shadow: 0 6px 28px rgba(217, 79, 30, 0.35);
}

/* ========== WEEKLY CALENDAR ========== */
.meal-plan-section {
  margin-bottom: 28px;
}

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

.plan-header h2 {
  font-family: 'Syne', sans-serif;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--bark);
  margin-bottom: 0;
}

.plan-header .plan-actions {
  display: flex;
  gap: 10px;
}

.week-label {
  font-size: 0.85rem;
  color: var(--text-light);
  font-weight: 500;
}

/* Calendar grid */
.calendar-grid {
  display: grid;
  grid-template-columns: 90px repeat(7, 1fr);
  gap: 2px;
  background: var(--border);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 2px 20px var(--shadow);
}

.calendar-header {
  background: var(--bark);
  color: white;
  padding: 14px 8px;
  font-size: 0.78rem;
  font-weight: 700;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.calendar-header.corner {
  background: var(--bark);
}

.calendar-row-label {
  background: var(--white);
  padding: 16px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--coral);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  justify-content: center;
  writing-mode: horizontal-tb;
}

.calendar-cell {
  background: var(--white);
  padding: 10px;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}

.calendar-cell:hover {
  background: var(--cream);
}

.meal-card-mini {
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--warm);
  border: 1px solid var(--border);
  transition: all 0.2s;
}

.meal-card-mini:hover {
  border-color: var(--coral);
  box-shadow: 0 2px 8px var(--shadow);
}

.meal-card-mini .meal-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--bark);
  line-height: 1.3;
  margin-bottom: 4px;
}

.meal-card-mini .meal-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  color: var(--text-light);
}

.age-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 600;
}

.age-badge.stage-6-12mo { background: #FFE0CC; color: #B85A00; }
.age-badge.stage-1-2yr { background: #FFD4B8; color: #A04500; }
.age-badge.stage-3-5yr { background: var(--sage-light); color: #2D7A3E; }
.age-badge.stage-6-10yr { background: #FFF0E0; color: #8B5E00; }

/* ========== MEAL DETAIL MODAL ========== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(43, 24, 16, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--white);
  border-radius: 24px;
  padding: 32px;
  max-width: 520px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(43, 24, 16, 0.2);
  transform: translateY(20px);
  transition: transform 0.2s;
}

.modal-overlay.active .modal {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h3 {
  font-family: 'Syne', sans-serif;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--bark);
}

.modal-close {
  background: var(--cream);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--text-light);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.modal-close:hover { background: var(--peach); }

.modal-description {
  color: var(--text-light);
  font-size: 0.95rem;
  line-height: 1.5;
  margin-bottom: 20px;
}

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

.modal-section h4 {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--coral);
  margin-bottom: 10px;
}

.ingredient-list {
  list-style: none;
}

.ingredient-list li {
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 218, 179, 0.2);
  font-size: 0.9rem;
  color: var(--text);
  display: flex;
  gap: 8px;
}

.ingredient-list li:last-child { border-bottom: none; }

.ingredient-qty {
  color: var(--coral);
  font-weight: 600;
  min-width: 70px;
}

.modal-instructions {
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.7;
  background: var(--cream);
  padding: 16px;
  border-radius: 12px;
}

/* Swap section in modal */
.swap-section {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.swap-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
}

.swap-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--warm);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
}

.swap-option:hover {
  border-color: var(--coral);
  background: var(--cream);
}

.swap-option .swap-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--bark);
}

.swap-option .swap-meta {
  font-size: 0.75rem;
  color: var(--text-light);
}

/* ========== GROCERY LIST ========== */
.grocery-panel {
  background: var(--white);
  border-radius: 20px;
  padding: 28px;
  border: 1px solid var(--border);
  box-shadow: 0 2px 20px var(--shadow);
}

.grocery-category {
  margin-bottom: 24px;
}

.grocery-category h3 {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--coral);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--cream);
}

.grocery-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 218, 179, 0.15);
}

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

.grocery-checkbox {
  width: 22px;
  height: 22px;
  border: 2px solid var(--peach);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
  background: var(--white);
}

.grocery-checkbox.checked {
  background: var(--sage);
  border-color: var(--sage);
}

.grocery-checkbox.checked::after {
  content: '\2713';
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
}

.grocery-item.checked .grocery-name {
  text-decoration: line-through;
  opacity: 0.5;
}

.grocery-name {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  flex: 1;
}

.grocery-amount {
  font-size: 0.78rem;
  color: var(--text-light);
  text-align: right;
}

/* ========== TAB NAVIGATION ========== */
.tab-bar {
  display: flex;
  gap: 4px;
  background: var(--cream);
  padding: 4px;
  border-radius: 14px;
  margin-bottom: 28px;
  max-width: 400px;
}

.tab {
  flex: 1;
  padding: 10px 16px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-light);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.tab.active {
  background: var(--white);
  color: var(--bark);
  box-shadow: 0 2px 8px var(--shadow);
}

.tab:hover:not(.active) {
  color: var(--bark);
}

/* ========== EMPTY STATE ========== */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-light);
}

.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.empty-state h3 {
  font-family: 'Syne', sans-serif;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--bark);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 0.95rem;
  max-width: 360px;
  margin: 0 auto;
  line-height: 1.5;
}

/* ========== LOADING ========== */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px;
  gap: 16px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--cream);
  border-top-color: var(--coral);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-size: 0.9rem;
  color: var(--text-light);
  font-weight: 500;
}

/* ========== TOAST ========== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 14px 24px;
  background: var(--bark);
  color: white;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 8px 30px rgba(43, 24, 16, 0.3);
  z-index: 2000;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.success { background: var(--sage); }
.toast.error { background: var(--deep); }

/* ========== RESPONSIVE ========== */
@media (max-width: 900px) {
  .calendar-grid {
    display: block;
    background: transparent;
    box-shadow: none;
  }

  .calendar-header, .calendar-header.corner {
    display: none;
  }

  .calendar-row-label {
    writing-mode: horizontal-tb;
    padding: 12px 16px;
    justify-content: flex-start;
    background: var(--cream);
    border-radius: 12px 12px 0 0;
    margin-top: 16px;
  }

  .calendar-cell {
    border-radius: 0;
    border-bottom: 1px solid var(--border);
    min-height: auto;
    padding: 12px 16px;
  }

  .calendar-cell::before {
    content: attr(data-day);
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--coral);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 6px;
  }

  .calendar-cell:last-child {
    border-radius: 0 0 12px 12px;
    margin-bottom: 8px;
  }
}

@media (max-width: 600px) {
  .app-container { padding: 20px 16px; }
  .children-panel { padding: 20px; }
  .add-child-form { padding: 16px; flex-direction: column; }
  .form-group { min-width: 100%; }
  .modal { padding: 24px; margin: 16px; }
  .plan-header { flex-direction: column; align-items: flex-start; }
  .grocery-panel { padding: 20px; }
}
