:root {
  color-scheme: dark;
  --bg: #0b1220;
  --surface: #111827;
  --surface-muted: #1f2937;
  --border: #374151;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger-bg: #2b1517;
  --danger-border: #7f1d1d;
  --success-bg: #14261a;
  --success-border: #166534;
  --warning-bg: #2b240f;
  --warning-border: #ca8a04;
  --info-bg: #142033;
  --info-border: #1d4ed8;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  padding: 32px 16px 48px;
}

.shell {
  width: min(1100px, 100%);
  margin: 0 auto;
}

.hero {
  text-align: left;
  padding: 8px 2px 20px;
}

.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}

h1 {
  margin: 0;
  font-size: clamp(1.75rem, 3vw, 2.2rem);
  line-height: 1.25;
}

.lede {
  max-width: 760px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.5;
}

.panel,
.results-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.panel {
  padding: 16px;
}

.search-form {
  display: grid;
  gap: 18px;
}

.dietary-filters {
  display: grid;
  gap: 12px;
  padding: 14px;
  background: var(--warning-bg);
  border-radius: 8px;
  border: 1px solid var(--warning-border);
}

.cuisine-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  background: #153026;
  border-radius: 8px;
  border: 1px solid #0f766e;
}

.cuisine-section > label:first-child {
  font-weight: 600;
  margin-bottom: 4px;
}

.event-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  background: #2d2415;
  border-radius: 8px;
  border: 1px solid #b45309;
}

.event-section > label:first-child {
  font-weight: 600;
  margin-bottom: 4px;
}

.food-type-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  background: #2a1f2e;
  border-radius: 8px;
  border: 1px solid #9333ea;
}

.food-type-section > label:first-child {
  font-weight: 600;
  margin-bottom: 4px;
}

.dietary-filters label {
  font-weight: 600;
  margin-bottom: 4px;
}

.filter-options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.filter-options label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  cursor: pointer;
}

.filter-options input[type="checkbox"] {
  width: auto;
  border: none;
  padding: 0;
  background: none;
  cursor: pointer;
  accent-color: var(--accent);
}

.allergies-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  background: var(--danger-bg);
  border-radius: 8px;
  border: 1px solid var(--danger-border);
}

.exclude-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  background: var(--info-bg);
  border-radius: 8px;
  border: 1px solid var(--info-border);
}

.complexity-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  background: #1f1633;
  border-radius: 8px;
  border: 1px solid #6d28d9;
}

.complexity-section > label:first-child {
  font-weight: 600;
  margin-bottom: 4px;
}

.complexity-options {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  grid-template-columns: none;
}

.complexity-options label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: auto;
  font-weight: 500;
}

.complexity-options input[type="radio"] {
  width: auto;
  margin: 0;
  cursor: pointer;
}

.secondary-button {
  justify-self: start;
  border-color: var(--border);
  background: var(--surface-muted);
  color: var(--text);
}

.secondary-button:hover {
  background: #273244;
}

.exclude-section > label:first-child {
  font-weight: 600;
  margin-bottom: 4px;
}

.allergies-section > label:first-child {
  font-weight: 600;
  margin-bottom: 4px;
}

.allergies-section input[type="text"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0f172a;
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
  font-size: 0.9rem;
  outline: none;
}

.allergies-section input[type="text"]:focus {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
}

.ingredients-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  background: var(--success-bg);
  border-radius: 8px;
  border: 1px solid var(--success-border);
}

.ingredients-section > label:first-child {
  font-weight: 600;
  margin-bottom: 4px;
}

.ingredient-options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}

.ingredient-options label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  cursor: pointer;
  font-size: 0.95rem;
}

.ingredient-options input[type="checkbox"] {
  width: auto;
  border: none;
  padding: 0;
  background: none;
  cursor: pointer;
  accent-color: var(--accent);
}

.custom-entry-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.icon-button {
  min-width: 40px;
  height: 40px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-size: 1.3rem;
  line-height: 1;
}

.custom-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-chip {
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.85rem;
  cursor: pointer;
}

.tag-chip:hover {
  border-color: var(--accent);
}

.hint {
  margin: -2px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

label {
  display: grid;
  gap: 8px;
  font-weight: 600;
}

input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0f172a;
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
  outline: none;
}

textarea:focus,
input:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  align-items: end;
}

button {
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--accent);
  color: white;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

button:hover {
  background: var(--accent-hover);
}

button:disabled {
  opacity: 0.7;
  cursor: wait;
  transform: none;
}

.results-section {
  margin-top: 20px;
  padding: 16px;
}

.results-chat-layout {
  display: block;
}

.results-pane {
  width: 100%;
}

.chat-pane {
  position: fixed;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  width: 320px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #0f172a;
  padding: 12px;
  display: grid;
  gap: 10px;
  z-index: 100;
  max-height: 80vh;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.chat-header h3 {
  margin: 0;
}

.chat-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.chat-messages {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0b1220;
  min-height: 280px;
  max-height: 420px;
  overflow-y: auto;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.chat-empty {
  color: var(--muted);
  font-size: 0.92rem;
}

.chat-bubble {
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.92rem;
  line-height: 1.4;
  display: grid;
  gap: 4px;
}

.chat-bubble--user {
  background: #1e3a8a;
  border: 1px solid #3b82f6;
}

.chat-bubble--assistant {
  background: #1f2937;
  border: 1px solid #4b5563;
}

.chat-form {
  display: grid;
  gap: 8px;
}

.chat-form textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #111827;
  color: var(--text);
  padding: 10px;
  font: inherit;
  resize: vertical;
}

.chat-actions {
  display: flex;
  gap: 8px;
}

.results-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.results-header h2 {
  margin: 0;
  font-size: 1.4rem;
}

#status {
  margin: 0;
  color: var(--muted);
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  align-items: stretch;
}

.recipe-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: var(--surface-muted);
  gap: 10px;
  position: relative;
}

.recipe-image-wrapper {
  position: relative;
  display: inline-block;
  width: 100%;
}

.recipe-card--selected {
  border-color: #22c55e;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2);
}

.recipe-card-link {
  display: block;
  color: inherit;
  text-decoration: none;
  transition: color 0.15s ease;
}

.recipe-card-link:hover h3 {
  color: #93c5fd;
}

.recipe-card-link:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}

.recipe-image {
  width: 100%;
  aspect-ratio: 282 / 188;
  object-fit: cover;
  display: block;
  border-radius: 8px;
  background: #374151;
}

.recipe-image--placeholder {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.95rem;
}

.recipe-card h3 {
  margin: 0 0 10px;
  font-size: 1.1rem;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 4px;
}

.stars {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #d97706;
}

.stars strong {
  color: var(--text);
}

.stars.muted {
  color: var(--muted);
}

.recipe-card a {
  display: inline-flex;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.recipe-card a:hover {
  text-decoration: underline;
}

.select-recipe-button {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 4px 8px;
  font-size: 0.75rem;
  height: auto;
  min-width: auto;
  background: #14532d;
  border-color: #16a34a;
  border: 1px solid #16a34a;
  border-radius: 4px;
  z-index: 10;
}

.select-recipe-button:hover {
  background: #166534;
}

.empty-state,
.error-state {
  padding: 18px;
  border-radius: 8px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  color: var(--muted);
}

.results-grid > .empty-state,
.results-grid > .error-state {
  grid-column: 1 / -1;
  min-height: 140px;
  display: grid;
  place-items: center;
  text-align: center;
}

.error-state {
  color: #fecaca;
  border-color: #7f1d1d;
}

@media (max-width: 960px) {
  .chat-pane {
    position: static;
    transform: none;
    width: 100%;
    max-height: none;
  }
}

@media (max-width: 760px) {
  .controls {
    grid-template-columns: 1fr;
  }

  .results-grid {
    grid-template-columns: 1fr;
  }

  .results-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
