:root {
  --bg: #faf6f0;
  --bg-card: #fffdf9;
  --primary: #d4734a;
  --primary-dark: #b85a35;
  --primary-light: #f4e4d9;
  --text: #3d3229;
  --text-muted: #8a7a6b;
  --border: #e8ddd3;
  --success: #6b9b6e;
  --shadow: 0 2px 12px rgba(61, 50, 41, 0.08);
  --radius: 12px;
  --nav-h: 56px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB',
    'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + 16px);
}

a {
  color: inherit;
  text-decoration: none;
}

header.top-bar {
  background: linear-gradient(135deg, #e8956a 0%, var(--primary) 100%);
  color: #fff;
  padding: 16px 16px 20px;
  position: sticky;
  top: 0;
  z-index: 10;
}

header.top-bar h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

header.top-bar .sub {
  font-size: 0.8rem;
  opacity: 0.9;
  margin-top: 4px;
}

main {
  padding: 16px;
  max-width: 640px;
  margin: 0 auto;
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.card h2 {
  font-size: 1rem;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card h2 .badge {
  font-size: 0.7rem;
  background: var(--primary-light);
  color: var(--primary-dark);
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 500;
}

.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 12px;
}

.form-row label {
  font-size: 0.9rem;
  white-space: nowrap;
}

input[type='number'],
input[type='text'],
select,
textarea {
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  background: #fff;
  color: var(--text);
  width: 100%;
}

input[type='number'] {
  width: 80px;
  text-align: center;
}

.category-config {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.category-row {
  display: grid;
  grid-template-columns: 1fr 72px auto;
  gap: 8px;
  align-items: center;
}

.category-row .type-select {
  min-width: 0;
}

.category-row .count-input {
  width: 100%;
}

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: #fff5f0;
  color: var(--primary);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.btn-outline {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-block {
  width: 100%;
}

.btn-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.meal-result {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}

.meal-result.empty {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 20px 0;
}

.dish-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.dish-item:last-child {
  border-bottom: none;
}

.dish-info {
  flex: 1;
  min-width: 0;
}

.dish-info .cat {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.dish-info .name {
  font-size: 0.95rem;
  font-weight: 500;
}

.meal-actions {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(61, 50, 41, 0.92);
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 100;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

nav.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  background: #fff;
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 20;
}

nav.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.7rem;
  color: var(--text-muted);
  transition: color 0.15s;
}

nav.bottom-nav a.active {
  color: var(--primary);
}

nav.bottom-nav a .icon {
  font-size: 1.2rem;
}

/* 菜库页 */
.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.toolbar select,
.toolbar input {
  flex: 1;
  min-width: 100px;
}

.dish-list-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.dish-list-item .meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.dish-list-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--bg-card);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 20px 16px 32px;
}

.modal h3 {
  margin-bottom: 16px;
  font-size: 1.1rem;
}

.modal .form-field {
  margin-bottom: 12px;
}

.modal .form-field label {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 4px;
  color: var(--text-muted);
}

.modal .season-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.modal .season-checks label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--text);
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

/* 历史页 */
.history-item {
  margin-bottom: 12px;
}

.history-item .date-line {
  font-size: 0.8rem;
  color: var(--text-muted);
   margin-bottom: 6px;
}

.history-item .meal-tag {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 4px;
  margin-right: 6px;
}

.history-dish {
  font-size: 0.9rem;
  padding: 2px 0;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 16px;
  font-size: 0.9rem;
}

@media (min-width: 640px) {
  .modal-overlay {
    align-items: center;
  }

  .modal {
    border-radius: var(--radius);
    max-height: 80vh;
  }
}
