/* ================================================================
   Meal Planner — Dark Theme Stylesheet
   Colors: bg #1a1a2e, accent #e94560, text #eaeaea
   ================================================================ */

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

:root {
  --bg: #1a1a2e;
  --bg-card: #16213e;
  --bg-input: #0f3460;
  --accent: #e94560;
  --accent-hover: #d63851;
  --text: #eaeaea;
  --text-muted: #a0a0b8;
  --border: #2a2a4a;
  --success: #2ecc71;
  --warning: #f39c12;
  --danger: #e74c3c;
  --radius: 8px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  --transition: 0.2s ease;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { font-weight: 600; }

.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }

/* --- Utility --- */
.input-full { width: 100%; }
.input-small { width: 120px; }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  font-size: 0.95rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), opacity var(--transition);
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: #153a6e; }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: rgba(255, 255, 255, 0.05); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #c0392b; }

.btn-small { padding: 6px 12px; font-size: 0.8rem; }
.btn-block { width: 100%; }

/* --- Inputs --- */
input[type="text"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="password"],
select,
textarea {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.2);
}
textarea { resize: vertical; }

.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 0.85rem; color: var(--text-muted); font-weight: 500; }

.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 100px; }

.form-inline { display: flex; align-items: center; gap: 8px; }
.form-inline label { font-size: 0.85rem; color: var(--text-muted); white-space: nowrap; }
.form-inline input { width: 70px; }

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

.login-container {
  width: 100%;
  max-width: 420px;
}

.login-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 40px 32px;
  box-shadow: var(--shadow);
  text-align: center;
}

.login-title {
  font-size: 2rem;
  margin-bottom: 4px;
  color: var(--accent);
}

.login-subtitle {
  color: var(--text-muted);
  margin-bottom: 32px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: left;
}

.login-success {
  margin-top: 16px;
  padding: 20px;
  background: rgba(46, 204, 113, 0.1);
  border: 1px solid var(--success);
  border-radius: var(--radius);
  text-align: center;
}

.success-icon {
  font-size: 2.5rem;
  color: var(--success);
  margin-bottom: 8px;
}

.login-error {
  margin-top: 16px;
  padding: 14px;
  background: rgba(231, 76, 60, 0.1);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  color: var(--danger);
  text-align: center;
}

/* ================================================================
   NAVBAR
   ================================================================ */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  padding: 0 24px;
  height: 56px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-brand {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
}

.navbar-tabs {
  display: flex;
  gap: 2px;
  overflow-x: auto;
}

.tab-btn {
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: 16px 16px;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  transition: color var(--transition), border-color var(--transition);
  font-family: inherit;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ================================================================
   APP CONTENT
   ================================================================ */
.app-content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 80px;
}

.tab-section { display: none; }
.tab-section.active { display: block; }

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

.section-header h2 { font-size: 1.4rem; }

/* ================================================================
   TAB 1 — PLAN SEMAINE
   ================================================================ */
.plan-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Breakfast */
.plan-breakfast {
  margin-bottom: 28px;
}
.plan-breakfast h3 {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.breakfast-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.meal-text { flex: 1; }

/* Week grid */
.plan-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 10px;
}

.day-column {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.day-header {
  text-align: center;
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  color: var(--accent);
  padding: 6px 0;
  border-bottom: 2px solid var(--accent);
}

.meal-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 90px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: box-shadow var(--transition);
  position: relative;
}
.meal-card:hover { box-shadow: 0 0 0 1px var(--accent); }

.meal-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.meal-name {
  font-size: 0.9rem;
  flex: 1;
  cursor: pointer;
  word-break: break-word;
}
.meal-name:empty::before {
  content: "Cliquez pour ajouter";
  color: var(--text-muted);
  font-style: italic;
}

.meal-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}
.meal-actions .btn-small { padding: 4px 8px; font-size: 0.75rem; }

.meal-feedback {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}
.feedback-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background var(--transition), border-color var(--transition);
  color: var(--text);
  font-family: inherit;
}
.feedback-btn:hover { border-color: var(--accent); background: rgba(233, 69, 96, 0.1); }
.feedback-btn.selected { background: var(--accent); border-color: var(--accent); }

/* Shopping list */
.shopping-list {
  background: var(--bg);
  padding: 16px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  font-family: "Fira Code", "Cascadia Code", monospace;
  font-size: 0.9rem;
  max-height: 60vh;
  overflow-y: auto;
  line-height: 1.8;
}

/* ================================================================
   TAB 2 — RECETTES
   ================================================================ */
.recipe-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.search-bar {
  margin-bottom: 20px;
}

/* Suggest filters */
.suggest-filters {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.suggest-filters h3 { margin-bottom: 12px; font-size: 1rem; }
.filters-grid {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.filters-grid .form-group { flex: 1; min-width: 150px; }

/* Recipe list */
.recipe-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.recipe-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: box-shadow var(--transition), transform var(--transition);
}
.recipe-card:hover { box-shadow: 0 0 0 1px var(--accent); transform: translateY(-2px); }

.recipe-card-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.recipe-card-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--bg-input);
  color: var(--text-muted);
}
.badge-accent { background: rgba(233, 69, 96, 0.15); color: var(--accent); }

.recipe-card-rating {
  color: #f1c40f;
  font-size: 0.9rem;
}

/* Expanded recipe detail */
.recipe-detail {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.recipe-detail h4 {
  font-size: 0.9rem;
  margin: 12px 0 6px;
  color: var(--accent);
}

.recipe-detail ul,
.recipe-detail ol {
  padding-left: 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.recipe-detail li { margin-bottom: 4px; }

/* AI recipe preview */
.ai-recipe-preview {
  margin-bottom: 20px;
}

.recipe-detail-card {
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 24px;
}

.recipe-detail-header { margin-bottom: 16px; }
.recipe-detail-header h3 { margin-bottom: 8px; }
.recipe-meta { display: flex; gap: 8px; flex-wrap: wrap; }

.recipe-detail-body {
  margin-bottom: 16px;
  line-height: 1.8;
}
.recipe-detail-body h4 {
  font-size: 0.95rem;
  margin: 16px 0 6px;
  color: var(--accent);
}
.recipe-detail-body ul,
.recipe-detail-body ol {
  padding-left: 20px;
  color: var(--text-muted);
}
.recipe-detail-body li { margin-bottom: 4px; }

.recipe-detail-actions {
  display: flex;
  gap: 10px;
}

/* ================================================================
   TAB 3 — FRIGO / PLACARD
   ================================================================ */
.pantry-add-form {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
}
.pantry-add-form h3 { margin-bottom: 12px; font-size: 1rem; }
.pantry-add-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.pantry-add-header h3 { margin-bottom: 0; }

.pantry-form-grid {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.pantry-form-grid .form-group { flex: 1; min-width: 120px; }
.pantry-form-grid .form-group-btn { flex: none; }

.pantry-table-container { overflow-x: auto; }

.pantry-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
}
.pantry-table th {
  background: var(--bg-input);
  text-align: left;
  padding: 12px 16px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}
.pantry-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.pantry-table tr:last-child td { border-bottom: none; }

.expiry-danger { color: var(--danger); font-weight: 600; }
.expiry-warning { color: var(--warning); font-weight: 600; }
.expiry-ok { color: var(--success); }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 0;
  font-style: italic;
}

/* ================================================================
   TAB 4 — PARAMÈTRES
   ================================================================ */
.settings-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
}
.settings-card h3 { margin-bottom: 8px; }
.settings-card .text-muted { margin-bottom: 16px; }

.preferences-summary {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 16px;
  font-size: 0.9rem;
  line-height: 1.8;
  white-space: pre-wrap;
}

/* ================================================================
   MODAL
   ================================================================ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modal-content {
  position: relative;
  background: var(--bg-card);
  border-radius: 12px;
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}
.modal-large { max-width: 680px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.1rem; }

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  font-family: inherit;
}
.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 24px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

/* ================================================================
   LOADING & TOAST
   ================================================================ */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(26, 26, 46, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--bg-card);
  color: var(--text);
  padding: 14px 20px;
  border-radius: var(--radius);
  border-left: 4px solid var(--accent);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  pointer-events: auto;
  animation: slideIn 0.3s ease;
  max-width: 360px;
}
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 900px) {
  .plan-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 700px) {
  .navbar {
    flex-direction: column;
    height: auto;
    padding: 10px 16px;
    gap: 4px;
  }
  .navbar-tabs { width: 100%; justify-content: space-around; }
  .tab-btn { padding: 10px 8px; font-size: 0.8rem; }

  .section-header { flex-direction: column; align-items: flex-start; }

  .plan-grid {
    grid-template-columns: 1fr 1fr;
  }

  .recipe-list {
    grid-template-columns: 1fr;
  }

  .pantry-form-grid {
    flex-direction: column;
  }
  .pantry-form-grid .form-group { min-width: 100%; }

  .filters-grid { flex-direction: column; }

  .plan-actions { flex-direction: column; align-items: flex-start; width: 100%; }
  .plan-actions .btn { width: 100%; }

  .modal-content { max-width: 100%; }

  .toast-container { left: 16px; right: 16px; }
  .toast { max-width: 100%; }
}

@media (max-width: 480px) {
  .plan-grid {
    grid-template-columns: 1fr;
  }
  .app-content { padding: 16px 12px 80px; }
  .login-card { padding: 28px 20px; }
}

/* --- Calendar month view --- */
.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 16px 0 12px;
}
.calendar-nav h3 { margin: 0; text-transform: capitalize; }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  background: var(--border);
  padding: 4px;
  border-radius: var(--radius);
}
.calendar-weekday {
  background: var(--bg-card);
  padding: 8px 4px;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
}
.calendar-day {
  background: var(--bg-card);
  padding: 6px;
  min-height: 80px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: background var(--transition);
  border-radius: 4px;
}
.calendar-day:hover { background: var(--bg-input); }
.calendar-day.other-month { opacity: 0.35; }
.calendar-day.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.calendar-day.has-meal { border-left: 3px solid var(--accent); }
.calendar-day-num {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}
.calendar-meal {
  font-size: 0.72rem;
  line-height: 1.2;
  padding: 2px 4px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.calendar-meal.away {
  background: #3a1a1a;
  color: var(--warning);
  font-style: italic;
}
.calendar-meal-slot { font-weight: 600; color: var(--text-muted); margin-right: 3px; }

/* Day edit modal */
.day-slot { margin-bottom: 20px; }
.day-slot h4 { margin-bottom: 8px; color: var(--accent); }
.slot-row { display: flex; gap: 8px; margin-bottom: 10px; }
.slot-row .input-full { flex: 1; }
.slot-away {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px;
  background: var(--bg-input);
  border-radius: 4px;
  font-size: 0.88rem;
}
.slot-away label { display: flex; align-items: center; gap: 6px; cursor: pointer; }

/* Disliked ingredients list */
.disliked-add-row { display: flex; gap: 8px; margin: 12px 0; }
.disliked-add-row .input-full { flex: 1; }
.disliked-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.disliked-list li {
  background: var(--bg-input);
  padding: 6px 10px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.disliked-list button {
  background: transparent;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0;
}

/* Recipe card extra actions */
.recipe-detail-extra-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

@media (max-width: 768px) {
  .calendar-day { min-height: 60px; padding: 3px; }
  .calendar-meal { font-size: 0.65rem; }
  .calendar-day-num { font-size: 0.75rem; }
}
