/* ============================================================
   Sift — Minimalist Recipe Manager PWA
   Local-first, offline-capable, zero clutter
   ============================================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --orange-50: #fff7ed;
  --orange-100: #ffedd5;
  --orange-200: #fed7aa;
  --orange-300: #fdba74;
  --orange-400: #fb923c;
  --orange-500: #f97316;
  --orange-600: #ea580c;
  --orange-700: #c2410c;
  --orange-800: #9a3412;
  
  --stone-50: #fafaf9;
  --stone-100: #f5f5f4;
  --stone-200: #e7e5e4;
  --stone-300: #d6d3d1;
  --stone-400: #a8a29e;
  --stone-500: #78716c;
  --stone-600: #57534e;
  --stone-700: #44403c;
  --stone-800: #292524;
  --stone-900: #1c1917;
  
  --red-500: #ef4444;
  --red-600: #dc2626;
  --red-100: #fee2e2;
  
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.05);
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --header-h: 56px;
  --nav-h: 64px;
  --max-w: 720px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--stone-50);
  color: var(--stone-800);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  display: flex;
  flex-direction: column;
  max-width: var(--max-w);
  margin: 0 auto;
  padding-top: var(--header-h);
  padding-bottom: var(--nav-h);
  min-height: 100vh;
  min-height: 100dvh;
}

/* --- Typography --- */
h1 { font-size: 1.35rem; font-weight: 700; color: var(--stone-900); }
h2 { font-size: 1.1rem; font-weight: 600; color: var(--stone-800); }
h3 { font-size: 1rem; font-weight: 600; color: var(--stone-700); }
p { color: var(--stone-600); }
a { color: var(--orange-600); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Header --- */
#app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--header-h);
  background: rgba(255, 255, 255, 0.85);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--stone-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  max-width: var(--max-w);
  margin: 0 auto;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

#app-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--orange-500);
  letter-spacing: -0.02em;
}

/* --- Bottom Navigation --- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--nav-h);
  background: rgba(255, 255, 255, 0.92);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--stone-200);
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding-bottom: env(safe-area-inset-bottom, 0);
  max-width: var(--max-w);
  margin: 0 auto;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--stone-400);
  font-size: 0.7rem;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
}

.nav-item.active {
  color: var(--orange-500);
}

.nav-item svg {
  transition: transform 0.15s;
}

.nav-item:active svg {
  transform: scale(0.9);
}

/* --- Buttons --- */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--stone-600);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover, .icon-btn:focus-visible {
  background: var(--orange-100);
  color: var(--orange-600);
}

.icon-btn:active {
  background: var(--orange-200);
  transform: scale(0.92);
}

.btn-primary, .btn-secondary, .btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--orange-500);
  color: white;
  box-shadow: var(--shadow-md);
}

.btn-primary:hover, .btn-primary:focus-visible {
  background: var(--orange-600);
  box-shadow: var(--shadow-lg);
}

.btn-primary:active {
  transform: scale(0.97);
}

.btn-secondary {
  background: var(--stone-100);
  color: var(--stone-700);
  border: 1px solid var(--stone-200);
}

.btn-secondary:hover, .btn-secondary:focus-visible {
  background: var(--stone-200);
}

.btn-danger {
  background: var(--red-100);
  color: var(--red-600);
  border: 1px solid transparent;
}

.btn-danger:hover, .btn-danger:focus-visible {
  background: var(--red-500);
  color: white;
}

.upload-btn {
  cursor: pointer;
  text-align: center;
}

/* --- Search Bar --- */
.search-bar {
  position: fixed;
  top: var(--header-h);
  left: 0;
  right: 0;
  z-index: 99;
  background: white;
  border-bottom: 1px solid var(--stone-200);
  padding: 8px 16px;
  display: flex;
  gap: 8px;
  align-items: center;
  max-width: var(--max-w);
  margin: 0 auto;
}

.search-bar input {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid var(--stone-200);
  border-radius: var(--radius-md);
  font-size: 1rem;
  background: var(--stone-50);
  color: var(--stone-800);
  outline: none;
  transition: border-color 0.15s;
}

.search-bar input:focus {
  border-color: var(--orange-400);
  background: white;
}

/* --- Main Content --- */
#app-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.view {
  display: none;
  padding: 16px;
  animation: fadeIn 0.2s ease;
}

.view.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Recipe Grid (Home) --- */
.recipe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  padding-bottom: 8px;
}

.recipe-card {
  background: white;
  border: 1px solid var(--stone-200);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.15s;
  position: relative;
}

.recipe-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--orange-200);
}

.recipe-card:active {
  transform: scale(0.97);
}

.recipe-card-body {
  padding: 14px;
}

.recipe-card-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--stone-800);
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.recipe-card-meta {
  font-size: 0.8rem;
  color: var(--stone-400);
  display: flex;
  gap: 8px;
  align-items: center;
}

.recipe-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.recipe-tag {
  display: inline-block;
  padding: 2px 8px;
  background: var(--orange-100);
  color: var(--orange-700);
  font-size: 0.7rem;
  font-weight: 500;
  border-radius: 100px;
}

.recipe-card-fav {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.9);
  border-radius: 50%;
  border: none;
  cursor: pointer;
  color: var(--stone-300);
  transition: color 0.15s, transform 0.15s;
}

.recipe-card-fav.is-fav {
  color: var(--red-500);
}

.recipe-card-fav:active {
  transform: scale(1.2);
}

/* --- Empty State --- */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.empty-state svg {
  margin-bottom: 8px;
}

.empty-state h2 {
  font-size: 1.2rem;
  color: var(--stone-700);
}

.empty-state p {
  color: var(--stone-400);
  max-width: 260px;
}

.empty-state .btn-primary,
.empty-state .btn-secondary {
  margin-top: 4px;
}

/* --- Recipe Detail --- */
.recipe-detail {
  background: white;
  border-radius: var(--radius-lg);
  border: 1px solid var(--stone-200);
  overflow: hidden;
}

.recipe-detail-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--stone-100);
}

.recipe-detail-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--stone-900);
  margin-bottom: 8px;
  line-height: 1.3;
}

.recipe-detail-times {
  display: flex;
  gap: 16px;
  font-size: 0.85rem;
  color: var(--stone-500);
}

.recipe-detail-times span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.recipe-detail-actions {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--stone-100);
}

.recipe-detail-actions .icon-btn {
  width: 36px;
  height: 36px;
}

.recipe-detail-section {
  padding: 16px 20px;
}

.recipe-detail-section + .recipe-detail-section {
  border-top: 1px solid var(--stone-100);
}

.recipe-detail-section h3 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--stone-400);
  margin-bottom: 10px;
}

.ingredients-list {
  list-style: none;
  padding: 0;
}

.ingredients-list li {
  padding: 5px 0;
  color: var(--stone-700);
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.ingredients-list li::before {
  content: "•";
  color: var(--orange-400);
  font-weight: bold;
}

/* --- Servings Controls --- */
.servings-control {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: var(--stone-100);
  border-radius: var(--radius-lg);
  border: 1px solid var(--stone-200);
}

.servings-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--stone-300);
  background: white;
  color: var(--stone-700);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  line-height: 1;
  padding: 0;
}

.servings-btn:hover {
  border-color: var(--orange-400);
  color: var(--orange-600);
  background: var(--orange-50);
}

.servings-btn:active {
  transform: scale(0.92);
}

.servings-display {
  flex: 1;
  text-align: center;
  font-size: 1rem;
  font-weight: 600;
  color: var(--stone-800);
}

.servings-label {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--stone-500);
}

.servings-reset {
  background: none;
  border: none;
  color: var(--stone-400);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: all 0.15s;
  line-height: 1;
}

.servings-reset:hover {
  color: var(--orange-500);
  background: var(--orange-50);
}

.servings-scaled {
  border-color: var(--orange-300);
  background: var(--orange-50);
}

.servings-scaled .servings-display {
  color: var(--orange-700);
}

.servings-scaled .servings-label {
  color: var(--orange-500);
}

.instructions-list {
  list-style: none;
  padding: 0;
  counter-reset: step;
}

.instructions-list li {
  counter-increment: step;
  padding: 8px 0 8px 36px;
  position: relative;
  color: var(--stone-700);
  line-height: 1.6;
}

.instructions-list li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 8px;
  width: 24px;
  height: 24px;
  background: var(--orange-100);
  color: var(--orange-700);
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.recipe-detail-source {
  color: var(--stone-400);
  font-size: 0.85rem;
  word-break: break-all;
}

.recipe-detail-notes {
  color: var(--stone-600);
  white-space: pre-wrap;
  font-style: italic;
}

/* --- Form --- */
.recipe-form {
  background: white;
  border-radius: var(--radius-lg);
  border: 1px solid var(--stone-200);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--stone-700);
}

.form-group input,
.form-group textarea {
  padding: 10px 12px;
  border: 2px solid var(--stone-200);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--stone-50);
  color: var(--stone-800);
  outline: none;
  transition: border-color 0.15s;
  resize: vertical;
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--orange-400);
  background: white;
}

.form-group input::placeholder,
.form-group textarea::placeholder {
  color: var(--stone-300);
}

.form-hint {
  font-size: 0.8rem;
  color: var(--stone-400);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-actions {
  display: flex;
  gap: 10px;
  padding-top: 8px;
}

.form-actions .btn-primary,
.form-actions .btn-secondary {
  flex: 1;
}

/* --- Import View --- */
.import-view {
  max-width: 600px;
}

.import-view h2 {
  margin-bottom: 8px;
}

.import-desc {
  color: var(--stone-500);
  margin-bottom: 20px;
  line-height: 1.5;
}

.import-status {
  margin-top: 16px;
  padding: 12px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

.import-status.loading {
  background: var(--orange-100);
  color: var(--orange-700);
}

.import-status.error {
  background: var(--red-100);
  color: var(--red-600);
}

.import-status.success {
  background: #f0fdf4;
  color: #166534;
}

.import-result {
  margin-top: 20px;
  padding: 16px;
  background: white;
  border: 1px solid var(--stone-200);
  border-radius: var(--radius-md);
}

.import-result h3 {
  margin-bottom: 12px;
}

.import-preview-recipe {
  margin-bottom: 12px;
}

.import-preview-recipe h4 {
  font-size: 1.1rem;
  margin-bottom: 8px;
  color: var(--stone-800);
}

.import-preview-recipe .preview-field {
  margin-bottom: 8px;
}

.import-preview-recipe .preview-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--stone-400);
  margin-bottom: 2px;
}

.import-preview-recipe .preview-value {
  color: var(--stone-700);
  white-space: pre-wrap;
  font-size: 0.9rem;
}

.import-note {
  margin-top: 20px;
  padding: 12px;
  background: var(--stone-100);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--stone-500);
}

/* --- Settings View --- */
.settings-view {
  max-width: 500px;
}

.settings-view h2 {
  margin-bottom: 6px;
}

.settings-desc {
  color: var(--stone-500);
  margin-bottom: 24px;
}

.settings-section {
  background: white;
  border: 1px solid var(--stone-200);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
}

.settings-section h3 {
  margin-bottom: 12px;
  font-size: 0.9rem;
  color: var(--stone-500);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.settings-section .btn-secondary,
.settings-section .btn-danger {
  display: block;
  width: 100%;
  margin-bottom: 8px;
}

.settings-section .btn-danger:last-child {
  margin-bottom: 0;
}

/* --- Toast Notifications --- */
.toast-container {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  max-width: 90vw;
}

.toast {
  padding: 12px 20px;
  background: var(--stone-800);
  color: white;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.5s forwards;
  pointer-events: auto;
}

.toast.success {
  background: #166534;
}

.toast.error {
  background: var(--red-600);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(16px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(-8px) scale(0.95); }
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--stone-300);
  border-radius: 100px;
}

/* --- Responsive --- */
@media (min-width: 600px) {
  .recipe-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
  }
  
  .recipe-detail {
    border-radius: var(--radius-xl);
  }
  
  .recipe-form {
    padding: 28px;
  }
}

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

/* --- Print Styles --- */
@media print {
  #app-header, .bottom-nav, .search-bar, .recipe-detail-actions {
    display: none !important;
  }
  body {
    padding: 0;
    max-width: 100%;
  }
  .recipe-detail {
    border: none;
    box-shadow: none;
  }
  .recipe-detail-section {
    page-break-inside: avoid;
  }
}

/* ============================================================
   Monetization — Affiliate Card, Cross-Promotion, Support
   ============================================================ */

/* --- Affiliate Card --- */
.affiliate-card {
  background: white;
}

.affiliate-desc {
  font-size: 0.85rem;
  color: var(--stone-500);
  margin-bottom: 12px;
  line-height: 1.4;
}

.affiliate-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.affiliate-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  background: var(--stone-50);
  border: 1px solid var(--stone-200);
  border-radius: var(--radius-md);
  text-decoration: none !important;
  transition: all 0.15s;
}

.affiliate-item:hover {
  border-color: var(--orange-300);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.affiliate-img {
  width: 100%;
  aspect-ratio: 1;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  border-radius: var(--radius-sm);
  background-color: white;
}

.affiliate-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.affiliate-name {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--stone-700);
  line-height: 1.3;
}

.affiliate-price {
  font-size: 0.65rem;
  color: var(--stone-400);
  line-height: 1.3;
}

.affiliate-disclosure {
  font-size: 0.7rem;
  color: var(--stone-400);
  text-align: center;
  margin-top: 4px;
  font-style: italic;
}

/* --- Cross-Promotion (SousChef Pro) --- */
.cross-promo {
  background: linear-gradient(135deg, #fff7ed, #ffedd5);
  border-color: var(--orange-200);
}

.cross-promo h3 {
  text-transform: none;
  letter-spacing: normal;
  color: var(--orange-700);
  font-size: 1rem;
}

.cross-promo p {
  font-size: 0.9rem;
  color: var(--stone-600);
  margin-bottom: 12px;
  line-height: 1.5;
}

.btn-promo {
  display: inline-block;
  padding: 10px 20px;
  background: var(--orange-500);
  color: white !important;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none !important;
  transition: background 0.15s;
}

.btn-promo:hover {
  background: var(--orange-600);
  text-decoration: none;
}

/* --- Support Section (Ko-fi) --- */
.support-section {
  text-align: center;
  background: var(--stone-50);
  border: 1px dashed var(--stone-300);
}

.support-text {
  font-size: 0.85rem;
  color: var(--stone-500);
  margin-bottom: 12px;
  line-height: 1.5;
}

.kofi-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--orange-500);
  color: white !important;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none !important;
  transition: background 0.15s;
}

.kofi-link:hover {
  background: var(--orange-600);
  text-decoration: none;
}

/* --- Affiliate Grid Responsive --- */
@media (max-width: 400px) {
  .affiliate-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
