/* Kitchen Inventory App - Core Styles */
:root {
  --primary: #4f46e5;
  --primary-light: #a5f3fc;
  --secondary: #10b981;
  --danger: #ef4444;
  --muted: #6b7280;
  --bg-light: #f8fafc;
  --card-bg: #ffffff;
}

html {
  box-sizing: border-box;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

*, *::before, *::after { box-sizing: inherit; }

body {
  margin: 0; padding: 0;
  background: var(--bg-light);
  color: #1e293b;
}

/* Base */
a { text-decoration: none; color: inherit; }
img { max-width: 100%; display: block; }
button { cursor: pointer; }

/* Layout */
.wrap { max-width: 1200px; margin: 0 auto; padding: 2rem; }
header { margin-bottom: 2rem; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 1rem 0; border-bottom: 1px solid #e2e8f0; }
.brand { display: flex; align-items: center; gap: 0.5rem; }
.brand img { width: 32px; height: 32px; border-radius: 4px; }
.spacer { flex: 1; }

nav.nav a { margin-left: 0.75rem; }
nav.nav img { width: 14px; height: 14px; margin-right: 0.3rem; }

nav.nav a[aria-current="page"] { font-weight: 600; }

main { min-height: 600px; }
footer { margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid #e2e8f0; color: var(--muted); font-size: 0.875rem; }
footer .foot-links a + span { margin: 0 0.5rem; }

/* Forms */
.form { max-width: 600px; margin: 0 auto; }
.form .field { margin-bottom: 1rem; }
.form .field label { display: block; margin-bottom: 0.25rem; font-weight: 500; }
.form .field input, .form .field select, .form .field textarea { width: 100%; padding: 0.5rem; border: 1px solid #cbd5e1; border-radius: 4px; font-size: 1rem; }
.form .field-group { margin-bottom: 1rem; }
.form .field-group h3 { margin: 0 0 0.5rem 0; font-size: 0.875rem; color: var(--muted); font-weight: 600; }
.form .field-row { display: flex; gap: 1rem; }
.form .field-row .field { flex: 1; }
.form .field-row .field:first-child { flex: 0 0 45%; }
.form .field input[type="number"] { width: auto; }
.form .form-actions { display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 1.5rem; }
.form .btn { display: inline-block; padding: 0.5rem 1rem; border-radius: 4px; font-size: 0.875rem; font-weight: 600; }
.form .btn-primary { background: var(--primary); color: white; border: none; }
.form .btn-primary:hover { background: #3730a3; }
.form .btn-secondary { background: #e2e8f0; color: #1e293b; border: none; }
.form .btn-secondary:hover { background: #cbd5e1; }
.form .btn-danger { background: var(--danger); color: white; border: none; }
.form .btn-ghost { background: transparent; border: 1px solid var(--muted); color: var(--muted); padding: 0.5rem 1rem; }
.form .btn-ghost:hover { background: #f1f5f9; }

/* Tables */
table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
th, td { padding: 0.75rem; text-align: left; border-bottom: 1px solid #e2e8f0; }
th { font-weight: 600; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; }
tr { background: var(--card-bg); }
tr:hover { background: #f1f5f9; }

/* Data Table */
.data-table td:first-child { font-weight: 500; }
.kcal { color: var(--primary); font-family: monospace; }
.prot, .fat, .carbs { color: var(--muted); font-size: 0.875rem; }

/* Recipe Grid */
.recipe-grid { display: grid; grid-template-column: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; margin-top: 1rem; }
.recipe-card { background: var(--card-bg); border-radius: 6px; padding: 1rem; text-align: left; }
.recipe-card h3 { margin: 0 0 0.5rem 0; }
.recipe-card .badge { display: inline-block; padding: 0.25rem 0.5rem; background: var(--primary-light); color: var(--primary); border-radius: 4px; font-size: 0.75rem; margin-right: 0.5rem; }
.recipe-meta { color: var(--muted); font-size: 0.875rem; margin-top: 0.25rem; }

/* Recipe Card - View */
.recipe-table .total-row { font-weight: 600; background: #f8fafc; }
.recipe-table .per-serving-row { background: #f8fafc; font-weight: 600; }
.macro-breakdown { margin: 1rem 0; padding: 0.75rem; background: var(--primary-light); border-radius: 4px; }
.macro-breakdown p { margin: 0; display: flex; justify-content: space-between; }
.macro-breakdown p span { color: var(--muted); }

/* Filters */
.filter-bar { margin-bottom: 1rem; display: flex; gap: 1rem; flex-wrap: wrap; }
.filter-form { display: flex; gap: 0.5rem; align-items: center; }
.filter-form input { flex: 1; padding: 0.5rem 0.75rem; border: 1px solid #cbd5e1; border-radius: 4px; font-size: 0.875rem; }
.filter-form select { padding: 0.5rem; border: 1px solid #cbd5e1; border-radius: 4px; min-width: 150px; }

/* Hero */
.hero { text-align: center; padding: 3rem 1rem; }
.hero-links { margin-top: 1.5rem; display: flex; gap: 1rem; justify-content: center; }
.hero h1 { font-size: 2.5rem; margin-bottom: 0.5rem; }
.tagline { color: var(--muted); font-size: 1.25rem; margin-bottom: 2rem; }

/* Features */
.features { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1.5rem; margin-top: 2rem; }
.feature { padding: 1.5rem; background: var(--card-bg); border-radius: 8px; text-align: center; transition: transform 0.2s; }
.feature:hover { transform: translateY(-2px); }
.feature img { width: 48px; height: 48px; margin: 0 auto 1rem; }
.feature h3 { margin: 0 0 0.5rem 0; }
.feature p { color: var(--muted); font-size: 0.875rem; }

/* Page Header */
.page-header { text-align: center; margin-bottom: 2rem; }
.page-header h1 { font-size: 2rem; margin-bottom: 0.5rem; }

/* Admin */
.admin-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.admin-stats .stat { text-align: center; padding: 1rem; background: var(--card-bg); border-radius: 6px; }
.admin-stats .stat .stat-num { font-size: 2rem; font-weight: 700; color: var(--primary); display: block; }
.admin-stats .stat .stat-label { color: var(--muted); font-size: 0.875rem; margin-top: 0.25rem; }
.admin-actions { margin-top: 1rem; }
.action-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-top: 1rem; }
.action-grid .btn { width: 100%; }

/* Errors */
.errors { background: #fef2f2; border: 1px solid #fecaca; padding: 0.75rem 1rem; border-radius: 4px; margin-bottom: 1rem; }
.errors ul { margin: 0; padding-left: 1.5rem; }

/* Serving Selector */
.serving-selector { margin: 1rem 0; padding: 0.75rem; background: var(--primary-light); border-radius: 4px; }
.serving-selector form { display: flex; gap: 0.5rem; align-items: center; }
.serving-selector input { padding: 0.25rem 0.5rem; font-size: 0.875rem; }

/* Modal / Add Row JS */
#ingredients-table { width: 100%; }
#ingredient-rows tr { border-bottom: 1px solid #e2e8f0; }
#ingredient-rows td:last-child { text-align: right; }

/* Responsive */
@media (max-width: 640px) {
  .topbar { flex-direction: column; gap: 1rem; }
  nav.nav { order: 3; width: 100%; justify-content: center; }
  .form .field-row .field:first-child { flex: 1; }
  .form .field-row .field:last-child { flex: 1; }
  .recipe-grid { grid-template-columns: 1fr; }
  .features { grid-template-columns: 1fr; }
  .action-grid .btn, .admin-stats .stat { flex: 1; }
}