/* SwapIngredient - Design System */

/* ===== CSS Variables / Design Tokens ===== */
:root {
  --color-bg: #fafaf9;
  --color-surface: #ffffff;
  --color-border: #e5e7eb;
  --color-text: #111827;
  --color-text-muted: #6b7280;
  --color-accent: #16a34a;
  --color-accent-hover: #15803d;

  --quality-perfect: #22c55e;
  --quality-good: #eab308;
  --quality-acceptable: #f97316;

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;

  --font-body: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

  --shadow-card: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-card-hover: 0 4px 12px rgba(0,0,0,0.10);
  --shadow-focus: 0 0 0 3px rgba(22, 163, 74, 0.25);
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-body);
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
}

a {
  color: var(--color-accent);
  text-decoration: none;
  transition: color 0.15s ease;
}

a:hover {
  color: var(--color-accent-hover);
  text-decoration: underline;
}

/* ===== Layout ===== */
.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* ===== Header ===== */
header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 1.25rem 0;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.logo {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--color-text);
  letter-spacing: -0.02em;
}

.logo span {
  color: var(--color-accent);
}

.tagline {
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

/* ===== Main Content ===== */
main {
  padding: 2rem 0;
}

/* ===== Mode Toggle ===== */
#mode-toggle {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  background: var(--color-surface);
  padding: 0.5rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}

.mode-btn {
  flex: 1;
  padding: 0.75rem 1rem;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 0.9375rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.mode-btn:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.mode-btn.active {
  background: var(--color-accent);
  color: white;
}

.mode-btn:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

/* ===== Search Bar ===== */
#search-wrapper {
  position: relative;
  margin-bottom: 1.5rem;
}

#search-input {
  width: 100%;
  padding: 1rem 1.25rem;
  font-size: 1.25rem;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#search-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: var(--shadow-focus);
}

#search-input::placeholder {
  color: var(--color-text-muted);
}

#clear-btn {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 0.5rem;
  line-height: 1;
}

#clear-btn:hover {
  color: var(--color-text);
}

#clear-btn:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
  border-radius: var(--radius-sm);
}

/* ===== Suggestions Dropdown ===== */
#suggestions-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card-hover);
  margin: 0.25rem 0 0 0;
  padding: 0;
  list-style: none;
  z-index: 1000;
  max-height: 320px;
  overflow-y: auto;
}

#suggestions-list li {
  padding: 0.75rem 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background 0.1s ease;
}

#suggestions-list li:hover,
#suggestions-list li.selected {
  background: var(--color-bg);
}

#suggestions-list li .ingredient-name {
  font-weight: 500;
}

#suggestions-list li .category-badge {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  background: var(--color-bg);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
}

/* ===== Quantity Input Row ===== */
#quantity-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  background: var(--color-surface);
  padding: 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}

#quantity-row label {
  font-weight: 500;
  color: var(--color-text);
}

#quantity-input {
  width: 100px;
  padding: 0.625rem 0.75rem;
  font-size: 1rem;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
}

#quantity-input:focus {
  outline: none;
  border-color: var(--color-accent);
}

#unit-select {
  padding: 0.625rem 0.75rem;
  font-size: 1rem;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
  cursor: pointer;
}

#unit-select:focus {
  outline: none;
  border-color: var(--color-accent);
}

/* ===== Filter Pills ===== */
#category-filters,
#dietary-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.filter-label {
  font-weight: 500;
  color: var(--color-text-muted);
  margin-right: 0.25rem;
}

.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.filter-pill:hover {
  border-color: var(--color-text-muted);
}

.filter-pill input {
  display: none;
}

.filter-pill input:checked + span {
  color: var(--color-accent);
}

.filter-pill:has(input:checked) {
  border-color: var(--color-accent);
  background: rgba(22, 163, 74, 0.05);
}

.filter-pill:focus-within {
  outline: none;
  box-shadow: var(--shadow-focus);
}

.reset-link {
  background: none;
  border: none;
  color: var(--color-accent);
  font-size: 0.875rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  text-decoration: underline;
}

.reset-link:hover {
  color: var(--color-accent-hover);
}

/* ===== Results Header ===== */
#results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding: 0.5rem 0;
}

#results-count {
  font-size: 0.9375rem;
  color: var(--color-text-muted);
  margin: 0;
}

#results-count strong {
  color: var(--color-text);
}

#filter-status {
  color: var(--color-accent);
}

#print-btn {
  background: none;
  border: 1px solid var(--color-border);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  cursor: pointer;
  color: var(--color-text-muted);
  transition: all 0.15s ease;
}

#print-btn:hover {
  border-color: var(--color-text-muted);
  color: var(--color-text);
}

/* ===== Result Cards ===== */
#results-area {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 1rem;
}

@media (max-width: 767px) {
  #results-area {
    grid-template-columns: 1fr;
  }
}

.result-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-card);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.result-card:hover {
  box-shadow: var(--shadow-card-hover);
  transform: translateY(-1px);
}

/* Quality Badge */
.quality-badge {
  display: inline-block;
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.quality-badge.quality-3 {
  background: var(--quality-perfect);
  color: white;
}

.quality-badge.quality-2 {
  background: var(--quality-good);
  color: #1f2937;
}

.quality-badge.quality-1 {
  background: var(--quality-acceptable);
  color: white;
}

/* Card Title */
.substitute-name {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0 0 0.75rem 0;
  color: var(--color-text);
}

/* Calculated Amount */
.calculated-amount {
  background: rgba(22, 163, 74, 0.1);
  padding: 0.625rem 0.875rem;
  border-radius: var(--radius-sm);
  margin-bottom: 0.75rem;
  font-size: 0.9375rem;
}

.calculated-amount strong {
  color: var(--color-accent);
}

/* Ratio Display */
.ratio-display {
  margin-bottom: 0.75rem;
}

.ratio-label {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  margin-right: 0.375rem;
}

.ratio-value {
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  color: var(--color-text);
}

.conversion-note {
  display: block;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  margin-top: 0.25rem;
  font-style: italic;
}

/* How To Section */
.how-to {
  margin: 0.75rem 0;
}

.how-to summary {
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--color-accent);
  font-weight: 500;
  padding: 0.5rem 0;
  list-style: none;
}

.how-to summary::-webkit-details-marker {
  display: none;
}

.how-to summary::after {
  content: ' ▾';
  font-size: 0.75rem;
}

.how-to[open] summary::after {
  content: ' ▴';
}

.ratio-steps {
  margin: 0;
  padding-left: 1.25rem;
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.ratio-steps li {
  margin-bottom: 0.375rem;
}

/* Context Rows */
.context-row {
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
}

.context-label {
  color: var(--color-text-muted);
}

.context-value {
  color: var(--color-text);
}

.avoid-row .context-label {
  color: var(--quality-acceptable);
}

/* Uncertainty Banner */
.uncertainty-banner {
  background: rgba(234, 179, 8, 0.15);
  color: #854d0e;
  padding: 0.625rem 0.875rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  margin: 0.75rem 0;
}

/* Dietary Tags */
.dietary-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin: 0.75rem 0;
}

.tag {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text-muted);
}

/* Card Notes */
.sub-notes {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin: 0.75rem 0;
  font-style: italic;
}

/* Card Actions */
.card-actions {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--color-border);
}

.copy-btn {
  background: transparent;
  border: 1px solid var(--color-border);
  padding: 0.5rem 0.875rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  cursor: pointer;
  color: var(--color-text-muted);
  transition: all 0.15s ease;
}

.copy-btn:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.copy-btn.copied {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: white;
}

/* ===== Empty State & No Results ===== */
#empty-state,
#no-results-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-text-muted);
}

#empty-state p,
#no-results-state p {
  font-size: 1.125rem;
  margin-bottom: 0.5rem;
}

#empty-state .hint {
  font-size: 0.875rem;
}

#failed-query {
  color: var(--color-text);
}

/* ===== Affiliate Section ===== */
#affiliate-tools {
  margin-top: 3rem;
  padding: 2rem;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
}

#affiliate-tools h2 {
  font-size: 1.25rem;
  margin: 0 0 0.5rem 0;
  color: var(--color-text);
}

#affiliate-tools > p {
  color: var(--color-text-muted);
  margin-bottom: 1.5rem;
}

.tool-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.tool-card {
  padding: 1rem;
  background: var(--color-bg);
  border-radius: var(--radius-md);
}

.tool-card h3 {
  font-size: 1rem;
  margin: 0 0 0.5rem 0;
  color: var(--color-text);
}

.tool-card p {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin: 0 0 0.75rem 0;
}

.affiliate-link {
  font-size: 0.875rem;
  font-weight: 500;
}

.affiliate-disclosure {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  text-align: center;
}

/* ===== Footer ===== */
footer {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: 2rem 0;
  margin-top: 2rem;
}

.disclaimer {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  max-width: 700px;
  margin: 0 auto 1.5rem;
  text-align: center;
  line-height: 1.5;
}

.footer-nav {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 1rem;
}

.footer-nav a {
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.copyright {
  text-align: center;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  margin: 0;
}

/* ===== Mode B Specific Styles ===== */
.mode-b-card .substitute-name a {
  color: var(--color-text);
}

.mode-b-card .substitute-name a:hover {
  color: var(--color-accent);
}

/* ===== Mobile Responsive ===== */
@media (max-width: 639px) {
  .header-content {
    flex-direction: column;
    text-align: center;
  }

  #mode-toggle {
    flex-direction: column;
  }

  .mode-btn {
    width: 100%;
  }

  #quantity-row {
    flex-direction: column;
    align-items: stretch;
  }

  #quantity-row label {
    margin-bottom: 0.25rem;
  }

  #category-filters,
  #dietary-filters {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 0.5rem;
    -webkit-overflow-scrolling: touch;
  }

  .filter-pill {
    flex-shrink: 0;
  }
}

/* ===== Print Styles ===== */
@media print {
  header,
  #mode-toggle,
  #search-wrapper,
  #quantity-row,
  #category-filters,
  #dietary-filters,
  #results-header,
  #affiliate-tools,
  footer,
  .card-actions {
    display: none !important;
  }

  body {
    background: white;
    color: black;
  }

  main {
    padding: 0;
  }

  #results-area {
    display: block;
  }

  .result-card {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ddd;
    margin-bottom: 1rem;
    page-break-inside: avoid;
  }

  .disclaimer {
    display: block !important;
    text-align: left;
    margin-top: 2rem;
  }
}

/* ===== Accessibility ===== */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ===== Hidden State ===== */
[hidden] {
  display: none !important;
}
