:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #fbf9f5;
  --border: #e7e2d8;
  --text: #2b2723;
  --text-muted: #8a8378;
  --primary: #e0673a;
  --primary-dark: #c8512a;
  --primary-soft: #fbe7dd;
  --accent: #3f7d5a;
  --accent-soft: #e2efe7;
  --warning: #d9a441;
  --danger: #c8453b;
  --danger-soft: #f7dedb;
  --info: #4a73a8;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 3px rgba(43, 39, 35, 0.06), 0 8px 24px rgba(43, 39, 35, 0.05);
  --shadow-sm: 0 1px 2px rgba(43, 39, 35, 0.08);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3, h4 { font-weight: 650; line-height: 1.25; margin: 0 0 .5rem; letter-spacing: -0.01em; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1rem; }

/* ---------- Layout ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.4rem 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: .35rem;
}
.sidebar .brand {
  display: flex; align-items: center; gap: .6rem;
  font-size: 1.2rem; font-weight: 750; color: var(--text);
  padding: .3rem .6rem 1.1rem;
  letter-spacing: -0.02em;
}
.sidebar .brand .logo {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  display: grid; place-items: center; font-size: 1.1rem;
}
.nav-link {
  display: flex; align-items: center; gap: .7rem;
  padding: .6rem .8rem; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 550; font-size: .94rem;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--primary-soft); color: var(--primary-dark); }
.nav-link .ic { width: 20px; text-align: center; font-size: 1.05rem; }
.nav-sep { height: 1px; background: var(--border); margin: .6rem .4rem; }
.sidebar-foot { margin-top: auto; font-size: .82rem; color: var(--text-muted); padding: .6rem; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 2rem; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.topbar .user-chip { display: flex; align-items: center; gap: .6rem; font-size: .9rem; color: var(--text-muted); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 650; font-size: .85rem;
}
.content { padding: 1.8rem 2rem; max-width: 1180px; width: 100%; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: 1.3rem;
}
.card + .card { margin-top: 1.2rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; gap: 1rem; }
.card-head h2, .card-head h3 { margin: 0; }
.muted { color: var(--text-muted); }
.small { font-size: .85rem; }

.grid { display: grid; gap: 1.2rem; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

/* ---------- Stat cards ---------- */
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.2rem; box-shadow: var(--shadow-sm);
}
.stat .label { color: var(--text-muted); font-size: .85rem; font-weight: 550; }
.stat .value { font-size: 2rem; font-weight: 720; letter-spacing: -0.02em; margin-top: .25rem; }
.stat .ic { font-size: 1.3rem; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .45rem; justify-content: center;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: .55rem 1rem; font-size: .92rem; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: background .15s, border-color .15s, transform .05s;
  background: var(--primary); color: #fff; text-decoration: none;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; color: var(--text-muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #a8362d; }
.btn.accent { background: var(--accent); }
.btn.accent:hover { background: #336249; }
.btn.sm { padding: .35rem .7rem; font-size: .82rem; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: .6rem; flex-wrap: wrap; }

/* ---------- Forms ---------- */
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: .88rem; font-weight: 600; margin-bottom: .35rem; }
.field input, .field select, .field textarea {
  width: 100%; padding: .6rem .75rem; font-size: .94rem; font-family: inherit;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.field textarea { min-height: 90px; resize: vertical; }
.field .hint { font-size: .8rem; color: var(--text-muted); margin-top: .3rem; }
.field .error { color: var(--danger); font-size: .82rem; margin-top: .3rem; }
.check { display: flex; align-items: center; gap: .5rem; }
.check input { width: auto; }
.form-inline { display: flex; gap: .8rem; align-items: flex-end; flex-wrap: wrap; }
.form-inline .field { margin-bottom: 0; flex: 1; min-width: 140px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .7rem .8rem; border-bottom: 1px solid var(--border); }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 650; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .2rem .55rem; border-radius: 100px; font-size: .76rem; font-weight: 600;
  background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
}
.badge.green { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.orange { background: var(--primary-soft); color: var(--primary-dark); border-color: transparent; }
.badge.red { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.gray { background: var(--surface-2); color: var(--text-muted); }
.badge.blue { background: #e2eaf5; color: var(--info); border-color: transparent; }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---------- Flash ---------- */
.flashes { margin-bottom: 1.2rem; display: flex; flex-direction: column; gap: .6rem; }
.flash {
  padding: .75rem 1rem; border-radius: var(--radius-sm); font-size: .92rem;
  border: 1px solid transparent; display: flex; align-items: center; gap: .6rem;
}
.flash.success { background: var(--accent-soft); color: #2c5a40; }
.flash.danger  { background: var(--danger-soft); color: #9a332b; }
.flash.warning { background: #fbf0d8; color: #8a6418; }
.flash.info    { background: #e2eaf5; color: #355377; }

/* ---------- Auth pages ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background: radial-gradient(1200px 600px at 80% -10%, #fbe7dd 0%, transparent 60%),
              radial-gradient(900px 500px at -10% 110%, #e2efe7 0%, transparent 55%), var(--bg); }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--shadow); padding: 2.2rem; width: 100%; max-width: 420px; }
.auth-card .brand { display: flex; align-items: center; gap: .6rem; font-weight: 750;
  font-size: 1.35rem; margin-bottom: .3rem; letter-spacing: -0.02em; }
.auth-card .brand .logo { width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark)); display: grid; place-items: center; }
.auth-sub { color: var(--text-muted); margin-bottom: 1.6rem; }
.auth-foot { text-align: center; margin-top: 1.3rem; font-size: .9rem; color: var(--text-muted); }

/* ---------- Misc ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.page-head .sub { color: var(--text-muted); margin: 0; }
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--text-muted); }
.empty .ic { font-size: 2.5rem; display: block; margin-bottom: .5rem; opacity: .6; }
.list-row { display: flex; align-items: center; justify-content: space-between; padding: .7rem 0; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: none; }
.tag-list { display: flex; flex-wrap: wrap; gap: .4rem; }
.divider { height: 1px; background: var(--border); margin: 1.2rem 0; }

/* Meal planner grid */
.week-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .7rem; }
.day-col { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .6rem; min-height: 120px; }
.day-col.today { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.day-col .day-head { font-size: .82rem; font-weight: 650; margin-bottom: .5rem; display: flex; justify-content: space-between; }
.meal-chip { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .35rem .5rem; font-size: .78rem; margin-bottom: .35rem; }
.meal-chip .mt { font-size: .68rem; text-transform: uppercase; color: var(--text-muted); letter-spacing: .03em; }
.meal-chip.cooked { opacity: .65; background: var(--accent-soft); }

@media print {
  .sidebar, .topbar, .btn, form, .page-head .btn-row { display: none !important; }
  .content { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; }
}

.recipe-card { display: flex; flex-direction: column; }
.recipe-card .body { flex: 1; }
.inline-form { display: inline; }

@media (max-width: 900px) {
  .sidebar { position: fixed; left: -260px; z-index: 30; transition: left .2s; }
  .sidebar.open { left: 0; }
  .grid.cols-3, .grid.cols-4, .grid.cols-2 { grid-template-columns: 1fr; }
  .week-grid { grid-template-columns: 1fr; }
  .content { padding: 1.2rem; }
  .topbar { padding: 1rem 1.2rem; }
  .menu-toggle { display: inline-flex !important; }
}
.menu-toggle { display: none; }
