:root {
  --color-primary: #2D6A4F;
  --color-primary-light: #52B788;
  --color-primary-dark: #1B4332;
  --color-secondary: #E76F51;
  --color-secondary-light: #F4A261;
  --color-success: #40916C;
  --color-error: #D62828;
  --color-warning: #F4A261;
  --color-neutral: #6B7280;
  --color-bg: #F8F4EF;
  --color-surface: #FFFFFF;
  --color-text: #1B4332;
  --color-text-muted: rgba(27, 67, 50, 0.6);
  --color-border: rgba(27, 67, 50, 0.15);
  --color-on-primary: #FFFFFF;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] {
  --color-primary: #52B788;
  --color-primary-light: #74C69D;
  --color-primary-dark: #2D6A4F;
  --color-bg: #121212;
  --color-surface: #1C1C1E;
  --color-text: #F8F4EF;
  --color-text-muted: rgba(248, 244, 239, 0.6);
  --color-border: rgba(248, 244, 239, 0.15);
  --color-on-primary: #1B4332;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
}

#app { min-height: 100vh; display: flex; flex-direction: column; }

a { color: inherit; }

.topbar {
  background: var(--color-primary);
  color: var(--color-on-primary);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 { font-size: 18px; margin: 0; flex: 1; font-weight: 600; }

.topbar button.icon-btn {
  background: none;
  border: none;
  color: var(--color-on-primary);
  font-size: 20px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
  line-height: 1;
}
.topbar button.icon-btn:hover { background: rgba(255,255,255,0.15); }

.topbar input[type="text"] {
  flex: 1;
  background: rgba(255,255,255,0.15);
  border: none;
  border-radius: 6px;
  padding: 8px 12px;
  color: var(--color-on-primary);
  font-size: 15px;
}
.topbar input[type="text"]::placeholder { color: rgba(255,255,255,0.7); }

.hamburger-btn {
  background: none;
  border: none;
  color: var(--color-on-primary);
  font-size: 22px;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 6px;
  line-height: 1;
}
.hamburger-btn:hover { background: rgba(255,255,255,0.15); }

.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.drawer-overlay.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  max-width: 82vw;
  background: var(--color-surface);
  z-index: 51;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  box-shadow: 2px 0 16px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
}
.drawer.open { transform: translateX(0); }

.drawer-header {
  padding: 4px 20px 18px;
  font-size: 20px;
  font-weight: 700;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 8px;
}

.drawer-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 20px;
  cursor: pointer;
  font-size: 15px;
  color: var(--color-text);
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}
.drawer-item:hover { background: var(--color-bg); }
.drawer-item.active {
  background: rgba(45, 106, 79, 0.12);
  color: var(--color-primary);
  font-weight: 600;
}
[data-theme="dark"] .drawer-item.active { background: rgba(82, 183, 136, 0.18); }

.nav {
  display: flex;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  overflow-x: auto;
}
.nav a {
  padding: 12px 16px;
  text-decoration: none;
  color: var(--color-text-muted);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.nav a.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }

.content {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

.card {
  background: var(--color-surface);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
}
.card.static { cursor: default; }
.card-row { display: flex; align-items: center; gap: 10px; }
.card-title { font-size: 16px; font-weight: 600; margin: 0; }
.card-sub { font-size: 13px; color: var(--color-text-muted); margin: 4px 0 0; }
.card-spacer { flex: 1; }

.badge {
  display: inline-block;
  background: rgba(64,145,108,0.15);
  color: var(--color-success);
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
}

.progress {
  height: 6px;
  border-radius: 3px;
  background: var(--color-border);
  overflow: hidden;
  margin-top: 8px;
}
.progress > div { height: 100%; background: var(--color-primary); }

button {
  font-family: inherit;
  cursor: pointer;
}

.btn {
  background: var(--color-primary);
  color: var(--color-on-primary);
  border: none;
  border-radius: 8px;
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 600;
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.secondary {
  background: transparent;
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
}
.btn.danger { background: var(--color-error); }
.btn.block { width: 100%; }
.btn.small { padding: 6px 12px; font-size: 13px; }

.icon-action {
  background: none;
  border: none;
  font-size: 18px;
  padding: 6px;
  color: var(--color-text-muted);
  border-radius: 6px;
}
.icon-action:hover { background: var(--color-border); }
.icon-action.danger { color: var(--color-error); }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; margin-bottom: 5px; color: var(--color-text-muted); }
.field input[type="text"],
.field input[type="password"],
.field input[type="email"],
.field input[type="number"],
.field input[type="url"],
.field select,
.field textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 15px;
  font-family: inherit;
}
.field textarea { min-height: 120px; resize: vertical; }
.field-error { color: var(--color-error); font-size: 12px; margin-top: 4px; }

.row { display: flex; gap: 10px; }
.row > .field { flex: 1; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: 20px;
  padding: 7px 14px;
  font-size: 13px;
}
.chip.selected { background: var(--color-primary); color: var(--color-on-primary); border-color: var(--color-primary); }

.empty-state, .loading-state, .error-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--color-text-muted);
}
.empty-state .emoji, .error-state .emoji { font-size: 40px; display: block; margin-bottom: 12px; }
.empty-state h3, .error-state h3 { margin: 0 0 6px; color: var(--color-text); }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: var(--color-surface);
  border-radius: 14px;
  padding: 22px;
  max-width: 440px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h2 { margin-top: 0; font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-on-primary);
  border: none;
  font-size: 26px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.25);
  z-index: 5;
}

.auth-shell {
  max-width: 380px;
  margin: 40px auto;
  padding: 0 20px;
}
.auth-shell .logo { text-align: center; font-size: 40px; margin-bottom: 6px; }
.auth-shell h1 { text-align: center; font-size: 22px; margin: 0 0 4px; }
.auth-shell p.sub { text-align: center; color: var(--color-text-muted); margin: 0 0 24px; }
.auth-shell .switch { text-align: center; margin-top: 16px; font-size: 14px; color: var(--color-text-muted); }
.auth-shell .switch a { color: var(--color-primary); font-weight: 600; text-decoration: none; }

.auth-divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 13px;
  margin: 18px 0;
}
.auth-divider::before, .auth-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--color-border);
}
.auth-divider span { padding: 0 10px; }

.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-primary-dark, #1B4332);
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 200;
  box-shadow: var(--shadow);
}

.ingredient-row { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 10px; }
.ingredient-row .field { margin-bottom: 0; }

.recipe-thumb {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--color-border);
}

.recipe-hero {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 12px;
  margin-bottom: 10px;
  background: var(--color-border);
}

.image-picker { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.image-picker .preview,
.image-picker .placeholder {
  width: 72px;
  height: 72px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--color-border);
  flex-shrink: 0;
}
.image-picker .placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
}
.image-picker .image-picker-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }

.step-row { display: flex; gap: 6px; align-items: flex-start; margin-bottom: 10px; }
.step-row .step-number {
  width: 24px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}
.step-row .field { flex: 1; margin-bottom: 0; }
.step-row .field textarea { min-height: 46px; }
.step-row .step-actions { display: flex; flex-shrink: 0; }
.step-row .step-actions .icon-action { font-size: 14px; padding: 6px 4px; }
.step-row .step-actions .icon-action:disabled { opacity: 0.3; }

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-primary);
  margin: 20px 0 8px;
}

.checkbox-row { display: flex; align-items: center; gap: 10px; }
.checkbox-row input { width: 18px; height: 18px; }

.strikethrough { text-decoration: line-through; opacity: 0.5; }

.chat-shell { display: flex; flex-direction: column; height: calc(100vh - 118px); }
.chat-messages { flex: 1; overflow-y: auto; padding: 4px 0; display: flex; flex-direction: column; gap: 10px; }
.chat-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
}
.chat-bubble.user {
  align-self: flex-end;
  background: var(--color-primary);
  color: var(--color-on-primary);
  border-bottom-right-radius: 4px;
}
.chat-bubble.assistant {
  align-self: flex-start;
  background: var(--color-surface);
  box-shadow: var(--shadow);
  border-bottom-left-radius: 4px;
}
.chat-input-row { display: flex; gap: 8px; padding: 10px 0; }
.chat-input-row input { flex: 1; }

.ingredient-list-item { padding: 10px 4px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--color-border); }
.ingredient-list-item.in-pantry { background: rgba(64,145,108,0.06); }

@media (max-width: 480px) {
  .content { padding: 12px; }
}
