@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── Design Tokens ─────────────────────────────────────────────────────── */
:root {
  --bg-0:        #080c18;
  --bg-1:        #0e1420;
  --bg-2:        #141c2e;
  --bg-card:     rgba(20, 28, 46, 0.85);
  --border:      rgba(99, 102, 241, 0.15);
  --border-soft: rgba(255, 255, 255, 0.06);

  --accent:      #6366f1;
  --accent-2:    #8b5cf6;
  --accent-glow: rgba(99, 102, 241, 0.25);

  --text-1:   #f1f5f9;
  --text-2:   #94a3b8;
  --text-3:   #475569;

  --success:  #10b981;
  --warning:  #f59e0b;
  --danger:   #ef4444;
  --info:     #3b82f6;

  --meal-froid:  #3b82f6;
  --meal-chaud1: #ef4444;
  --meal-chaud2: #f97316;
  --meal-vege:   #10b981;
  --meal-other:  #8b5cf6;

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 16px;
  --radius-xl: 22px;

  --shadow:    0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.6);

  --transition: 0.18s ease;
}

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

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

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-0);
  color: var(--text-1);
  min-height: 100vh;
  line-height: 1.6;
}

/* ── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-1); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ── Typography ─────────────────────────────────────────────────────────── */
h1 { font-size: 1.75rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 600; }
h3 { font-size: 1rem;    font-weight: 600; }
p  { color: var(--text-2); font-size: 0.9rem; }
a  { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ─────────────────────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: 60px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ── Top bar ─────────────────────────────────────────────────────────────── */
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.5rem;
  height: 60px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.02em;
}

.topbar-logo .logo-icon {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.topbar-spacer { flex: 1; }

.topbar-btn {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.4rem 1rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity var(--transition), transform var(--transition);
  text-decoration: none;
}
.topbar-btn:hover { opacity: 0.88; transform: translateY(-1px); text-decoration: none; }

/* ── Sidebar nav ─────────────────────────────────────────────────────────── */
.sidebar-nav {
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  padding: 1.2rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  overflow-y: auto;
}

.nav-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  padding: 0.6rem 0.75rem 0.3rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 0.88rem;
  cursor: pointer;
  transition: all var(--transition);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover { background: var(--bg-2); color: var(--text-1); }
.nav-item.active { background: var(--accent-glow); color: var(--accent); font-weight: 500; }

/* ── Main content ────────────────────────────────────────────────────────── */
.main-content {
  padding: 1.75rem 2rem;
  overflow-y: auto;
  background: var(--bg-0);
}

/* ── Card ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-soft);
}

.card-body { padding: 1.25rem; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
}
.btn-primary:hover { opacity: 0.9; }

.btn-secondary {
  background: var(--bg-2);
  color: var(--text-1);
  border: 1px solid var(--border-soft);
}
.btn-secondary:hover { border-color: var(--accent); }

.btn-success {
  background: var(--success);
  color: #fff;
}
.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.78rem; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  padding: 0.7rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}

thead th.sortable {
  cursor: pointer;
  user-select: none;
  transition: color var(--transition);
}

thead th.sortable:hover {
  color: var(--text-1);
}

thead th.sortable::after {
  content: ' ↕';
  opacity: 0.2;
  font-size: 0.8em;
  margin-left: 0.4rem;
  display: inline-block;
  transition: opacity var(--transition), transform var(--transition);
}

thead th.sortable.asc::after {
  content: ' ↑';
  opacity: 1;
  color: var(--accent);
}

thead th.sortable.desc::after {
  content: ' ↓';
  opacity: 1;
  color: var(--accent);
}

tbody tr {
  border-bottom: 1px solid var(--border-soft);
  transition: background var(--transition);
}
tbody tr:hover { background: rgba(99, 102, 241, 0.04); }
tbody tr:last-child { border-bottom: none; }

tbody td {
  padding: 0.65rem 1rem;
  color: var(--text-1);
  vertical-align: middle;
}

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.55rem;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-froid  { background: rgba(59, 130, 246, 0.15); color: var(--meal-froid); }
.badge-chaud1 { background: rgba(239, 68, 68, 0.15);  color: var(--meal-chaud1); }
.badge-chaud2 { background: rgba(249, 115, 22, 0.15); color: var(--meal-chaud2); }
.badge-vege   { background: rgba(16, 185, 129, 0.15); color: var(--meal-vege); }
.badge-other  { background: rgba(139, 92, 246, 0.15); color: var(--meal-other); }
.badge-success { background: rgba(16, 185, 129, 0.15); color: var(--success); }
.badge-warning { background: rgba(245, 158, 11, 0.15); color: var(--warning); }

/* ── Form elements ───────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 1rem; }
.form-label { font-size: 0.8rem; font-weight: 500; color: var(--text-2); }

input, select, textarea {
  background: var(--bg-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  padding: 0.55rem 0.8rem;
  font-size: 0.88rem;
  font-family: inherit;
  width: 100%;
  transition: border-color var(--transition);
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
select option { background: var(--bg-2); }

/* ── Tabs ────────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border-soft); margin-bottom: 1.5rem; }
.tab {
  padding: 0.6rem 1.1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
}
.tab:hover { color: var(--text-1); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Section header ──────────────────────────────────────────────────────── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.25rem;
}

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  gap: 0.75rem; padding: 3rem 1rem; color: var(--text-3); text-align: center;
}
.empty-state .empty-icon { font-size: 2.5rem; }

/* ── Stat cards ──────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 1.1rem 1.25rem;
  backdrop-filter: blur(12px);
}

.stat-label { font-size: 0.75rem; color: var(--text-3); font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 1.7rem; font-weight: 700; color: var(--text-1); margin-top: 0.2rem; }
.stat-sub   { font-size: 0.78rem; color: var(--text-2); margin-top: 0.15rem; }

/* ── Accordion ───────────────────────────────────────────────────────────── */
.accordion-item {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  overflow: hidden;
}

.accordion-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.85rem 1.1rem;
  cursor: pointer;
  background: var(--bg-2);
  transition: background var(--transition);
}
.accordion-header:hover { background: var(--bg-card); }
.accordion-header .chevron { transition: transform var(--transition); }
.accordion-item.open .chevron { transform: rotate(180deg); }

.accordion-body {
  display: none;
  padding: 1rem 1.1rem;
  background: var(--bg-1);
  border-top: 1px solid var(--border-soft);
}
.accordion-item.open .accordion-body { display: block; }

/* ── Toast ───────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  display: flex; flex-direction: column; gap: 0.5rem;
  z-index: 9999;
}
.toast {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.7rem 1.1rem;
  border-radius: var(--radius);
  background: var(--bg-2);
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  animation: slideIn 0.2s ease;
  max-width: 320px;
}
.toast.success { border-color: var(--success); }
.toast.error   { border-color: var(--danger); }
.toast.warning { border-color: var(--warning); }

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

/* ── Loading spinner ─────────────────────────────────────────────────────── */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Meal colors ───────────────────────────────────────────────────────── */
.color-froid  { color: var(--meal-froid); }
.color-chaud1 { color: var(--meal-chaud1); }
.color-chaud2 { color: var(--meal-chaud2); }
.color-vege   { color: var(--meal-vege); }
.color-other  { color: var(--meal-other); }

.badge-froid  { background: rgba(59, 130, 246, 0.15); color: #60a5fa; border: 1px solid rgba(59, 130, 246, 0.2); }
.badge-chaud1 { background: rgba(239, 68, 68, 0.15); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.2); }
.badge-chaud2 { background: rgba(249, 115, 22, 0.15); color: #fb923c; border: 1px solid rgba(249, 115, 22, 0.2); }
.badge-vege   { background: rgba(16, 185, 129, 0.15); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.2); }
.badge-other  { background: rgba(139, 92, 246, 0.15); color: #a78bfa; border: 1px solid rgba(139, 92, 246, 0.2); }

/* ── Utility ─────────────────────────────────────────────────────────────── */
.flex       { display: flex; }
.items-center { align-items: center; }
.gap-2      { gap: 0.5rem; }
.gap-3      { gap: 0.75rem; }
.gap-4      { gap: 1rem; }
.mt-1       { margin-top: 0.25rem; }
.mt-2       { margin-top: 0.5rem; }
.mt-3       { margin-top: 0.75rem; }
.mt-4       { margin-top: 1rem; }
.mb-4       { margin-bottom: 1rem; }
.text-muted { color: var(--text-2); }
.text-small { font-size: 0.8rem; }
.text-right { text-align: right; }
.w-full     { width: 100%; }
.hidden     { display: none !important; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar-nav { display: none; }
  .main-content { padding: 1rem; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* ── Suggestion Items (Merge Modal) ────────────────────────────────────── */
.suggestion-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.8rem;
  background: var(--bg-1);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}
.suggestion-item:hover {
  background: var(--bg-2);
  border-color: var(--accent);
}
.suggestion-item.selected {
  background: var(--accent-glow);
  border-color: var(--accent);
}
.suggestion-item .sugg-name {
  font-weight: 500;
  color: var(--text-1);
}
.suggestion-item .sugg-meta {
  font-size: 0.75rem;
  color: var(--text-3);
}

/* ── Calendar ───────────────────────────────────────────────────────────── */
.calendar-container {
  background: var(--bg-1);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 1rem;
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  height: 32px; /* Fixed height to prevent vertical shifting */
}

.calendar-header h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-1);
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  background: var(--border-soft);
  border: 1px solid var(--border-soft);
}

.calendar-day-label {
  padding: 0.5rem 0;
  text-align: center;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-3);
  background: var(--bg-1);
}

.calendar-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  background: var(--bg-2);
  color: var(--text-2);
  cursor: default;
  transition: all var(--transition);
}

.calendar-day.monday {
  cursor: pointer;
  color: var(--text-1);
  font-weight: 600;
}

.calendar-day.monday:hover {
  background: var(--accent-glow);
  color: var(--accent);
}

.calendar-day.selected {
  background: var(--accent) !important;
  color: #fff !important;
  font-weight: 700;
}

.calendar-day.other-month {
  opacity: 0.2;
}

.calendar-day.today {
  box-shadow: inset 0 0 0 2px var(--accent-glow);
}

.calendar-day.conflict {
  background: var(--bg-1);
  color: var(--text-muted);
  opacity: 0.4;
  cursor: not-allowed;
  text-decoration: line-through;
}

/* ── Usage Popover ─────────────────────────────────────────────── */
.usage-popover {
  position: fixed;
  z-index: 1000;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 1rem;
  min-width: 300px;
  max-width: 450px;
  pointer-events: none;
  animation: popoverFadeIn 0.15s ease-out;
  display: none;
}

@keyframes popoverFadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.usage-popover h4 {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.75rem;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: 0.4rem;
  font-weight: 700;
}

.usage-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.usage-table th {
  text-align: left;
  color: var(--text-3);
  font-weight: 600;
  padding-bottom: 0.4rem;
  font-size: 0.65rem;
  text-transform: uppercase;
}

.usage-table td {
  padding: 0.4rem 0;
  color: var(--text-2);
  border-bottom: 1px solid var(--border-soft);
}

.usage-table tr:last-child td {
  border-bottom: none;
}

.usage-table .usage-meal {
  color: var(--text-1);
  font-weight: 500;
}

.ing-name-cell {
  cursor: help;
  transition: color var(--transition);
}

.ing-name-cell:hover .ing-name {
  color: var(--accent);
}

