@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Playfair+Display:ital,wght@0,500;0,600;1,400&display=swap');

:root {
  --cream: #f8f0e6;
  --paper: #fffaf4;
  --card-bg: #ffffff;
  --brown: #35291f;
  --text-secondary: #5c4d3f;
  --muted: #827568;
  --rose: #bb7e6e;
  --rose-hover: #a56959;
  --rose-light: #f3e2d9;
  --border: #e9ded1;
  --border-strong: #d8c7b4;
  --accent-green: #2e7d52;
  --accent-green-bg: #e6f4ec;
  --accent-warn: #b45309;
  --accent-warn-bg: #fef3c7;
  --accent-danger: #b91c1c;
  --accent-danger-bg: #fee2e2;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 12px 35px rgba(80, 54, 36, 0.08);
  --shadow-sm: 0 4px 14px rgba(80, 54, 36, 0.06);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(ellipse at 80% 8%, #edd6b9 0%, transparent 45%),
    radial-gradient(ellipse at 8% 32%, #f2e3d2 0%, transparent 45%),
    var(--cream);
  color: var(--brown);
  min-height: 100vh;
  line-height: 1.5;
  padding-bottom: 3rem;
}

.hidden {
  display: none !important;
}

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.25rem 1rem;
}

/* Header (analog zu Recipe) */
.app-header {
  max-width: 1180px;
  margin: 18px auto 0;
  padding: 0.85rem 1.35rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  border-radius: 50px;
  background: rgba(255, 250, 244, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.85);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 10px;
  z-index: 50;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  font-size: 1.75rem;
}

.header-brand h1 {
  font-family: "Playfair Display", Georgia, serif;
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--brown);
  line-height: 1.15;
}

.brand-subtitle {
  font-size: 0.78rem;
  color: var(--muted);
}

.header-user {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.user-badge {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--cream);
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}

/* Cards */
.card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem;
  margin-bottom: 1.15rem;
  box-shadow: var(--shadow);
}

/* Auth View */
.auth-container {
  max-width: 460px;
  margin-top: 2.5rem;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  background: var(--cream);
  padding: 0.3rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0.65rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 999px;
  transition: all 0.2s;
  min-height: 44px;
}

.tab-btn.active {
  color: #ffffff;
  background: var(--rose);
  box-shadow: var(--shadow-sm);
}

/* Forms & Inputs */
.form-group {
  margin-bottom: 1rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.9rem;
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

input,
select,
textarea {
  width: 100%;
  padding: 0.7rem 0.9rem;
  background: var(--card-bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--brown);
  font-size: 0.96rem;
  font-family: inherit;
  min-height: 44px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--rose);
  box-shadow: 0 0 0 3px rgba(187, 126, 110, 0.2);
}

.form-hint {
  font-size: 0.85rem;
  color: var(--text-secondary);
  background: var(--rose-light);
  border-left: 3px solid var(--rose);
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.65rem 1.15rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.92rem;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.18s ease;
  min-height: 44px;
  touch-action: manipulation;
}

.btn-primary {
  background: var(--rose);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(187, 126, 110, 0.28);
}

.btn-primary:hover {
  background: var(--rose-hover);
}

.btn-secondary {
  background: #e9d8c8;
  color: var(--brown);
  border-color: var(--border-strong);
}

.btn-secondary:hover {
  background: #dec7b2;
}

.btn-outline {
  background: var(--card-bg);
  border-color: var(--border-strong);
  color: var(--brown);
}

.btn-outline:hover {
  background: var(--cream);
}

.btn-danger {
  background: var(--accent-danger-bg);
  color: var(--accent-danger);
  border-color: #fecaca;
}

.btn-danger:hover {
  background: #fecaca;
}

.btn-sm {
  padding: 0.42rem 0.85rem;
  font-size: 0.82rem;
  min-height: 38px;
}

.btn-block {
  width: 100%;
}

/* Navigation & Pills */
.main-nav {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding: 0.4rem;
  margin-bottom: 1.15rem;
  background: rgba(255, 250, 244, 0.85);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  -webkit-overflow-scrolling: touch;
}

.nav-tab {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 44px;
  transition: all 0.2s;
}

.nav-tab:hover {
  background: #f1e6dc;
}

.nav-tab.active {
  background: var(--rose);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

.nav-count-pill {
  background: rgba(53, 41, 31, 0.14);
  color: inherit;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.76rem;
}

.nav-tab.active .nav-count-pill {
  background: rgba(255, 255, 255, 0.26);
  color: #ffffff;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  box-shadow: var(--shadow-sm);
}

.stat-warning {
  border-color: #f59e0b;
  background: #fffbeb;
}

.stat-danger {
  border-color: #f87171;
  background: #fef2f2;
}

.stat-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stat-value {
  font-family: "Playfair Display", Georgia, serif;
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--brown);
}

/* Filter Pills */
.search-row,
.manual-barcode-row {
  display: flex;
  gap: 0.65rem;
  margin-bottom: 0.85rem;
}

.filter-pills,
.quick-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.55rem;
}

.pill {
  background: var(--card-bg);
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  padding: 0.42rem 0.9rem;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 38px;
  transition: all 0.15s;
}

.pill:hover {
  background: #f3e8de;
}

.pill.active {
  background: var(--rose);
  border-color: var(--rose);
  color: #ffffff;
}

/* Inventory Grid & Item Cards */
.inventory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 1rem;
}

.item-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.8rem;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.item-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.item-card.status-expiring_soon {
  border-left: 5px solid #d97706;
  background: #fffdf7;
}

.item-card.status-expired {
  border-left: 5px solid #dc2626;
  background: #fffafa;
}

.item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.65rem;
}

.item-header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.item-thumb {
  width: 54px;
  height: 54px;
  object-fit: contain;
  border-radius: 12px;
  background: var(--paper);
  border: 1px solid var(--border);
  padding: 3px;
  flex-shrink: 0;
}

.item-title {
  font-weight: 700;
  font-size: 1.02rem;
  color: var(--brown);
  word-break: break-word;
}

.item-brand {
  font-size: 0.8rem;
  color: var(--muted);
}

.badge {
  font-size: 0.74rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-ok {
  background: var(--accent-green-bg);
  color: var(--accent-green);
}

.badge-neutral {
  background: #f1e6dc;
  color: var(--text-secondary);
}

.badge-warn {
  background: var(--accent-warn-bg);
  color: var(--accent-warn);
}

.badge-danger {
  background: var(--accent-danger-bg);
  color: var(--accent-danger);
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.83rem;
  color: var(--text-secondary);
}

.item-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
}

.stepper-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.stepper-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 1.2rem;
}

/* Item Form Image Preview */
.item-form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.item-image-preview-wrap {
  width: 72px;
  height: 72px;
  border-radius: 14px;
  border: 1px solid var(--border-strong);
  background: var(--card-bg);
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}

.item-image-preview-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 10px;
}

/* Scanner Viewport */
.scanner-viewport-wrapper {
  position: relative;
  width: 100%;
  max-width: 520px;
  height: 270px;
  margin: 1rem auto;
  background: #231b15;
  border-radius: var(--radius);
  overflow: hidden;
  border: 2px solid var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.scanner-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.scanner-reticle {
  width: 72%;
  height: 52%;
  border: 2px dashed rgba(255, 250, 244, 0.9);
  border-radius: 14px;
  box-shadow: 0 0 0 9999px rgba(25, 18, 12, 0.38);
}

.scanner-controls {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-bottom: 1rem;
}

/* Connected Recipes Grid */
.connected-recipes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.9rem;
  margin-top: 1rem;
}

.recipe-mini-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.75rem;
  box-shadow: var(--shadow-sm);
}

.recipe-mini-top {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.recipe-mini-thumb {
  width: 58px;
  height: 58px;
  border-radius: 12px;
  object-fit: cover;
  background: var(--cream);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.recipe-mini-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.recipe-mini-info {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.recipe-mini-title {
  font-size: 0.96rem;
  color: var(--brown);
}

.recipe-mini-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.recipe-mini-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

/* Synced Shopping List */
.shopping-sync-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 1rem;
}

.shopping-sync-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.75rem 1rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.shopping-sync-row.is-checked {
  opacity: 0.65;
  background: var(--cream);
}

.shopping-sync-row.is-checked .shopping-sync-text {
  text-decoration: line-through;
}

.shopping-sync-label {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  cursor: pointer;
  margin: 0;
  flex: 1;
}

.shopping-sync-label input[type="checkbox"] {
  width: 22px;
  height: 22px;
  min-height: 22px;
  accent-color: var(--rose);
  cursor: pointer;
}

.shopping-sync-text {
  font-size: 0.96rem;
  font-weight: 600;
  color: var(--brown);
}

/* Alerts, Toast & Recipe Result */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.9rem;
  border: 1px solid var(--border-strong);
  background: var(--card-bg);
}

.toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: calc(100vw - 2.5rem);
}

.toast {
  background: var(--brown);
  color: var(--paper);
  padding: 0.8rem 1.15rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  font-weight: 500;
}

.text-muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}

.inline-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 1rem;
}

.recipe-result {
  margin-top: 1.25rem;
  padding: 1rem;
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
}

/* Mobile Optimization */
@media (max-width: 768px) {
  .app-header {
    margin: 10px 10px 0;
    padding: 0.75rem 1rem;
    border-radius: 24px;
    flex-wrap: wrap;
  }

  .header-brand h1 {
    font-size: 1.15rem;
  }

  .container {
    padding: 0.9rem 0.75rem;
  }

  .card {
    padding: 1rem;
    border-radius: 16px;
  }

  .search-row,
  .manual-barcode-row {
    flex-direction: column;
  }

  .search-row .btn,
  .manual-barcode-row .btn,
  .form-actions .btn {
    width: 100%;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .inventory-grid,
  .connected-recipes-grid {
    grid-template-columns: 1fr;
  }

  .scanner-viewport-wrapper {
    height: 230px;
  }

  .shopping-sync-row {
    flex-direction: column;
    align-items: stretch;
  }

  .shopping-sync-row .stepper-group {
    justify-content: flex-end;
  }
}

@media (max-width: 480px) {
  .header-user {
    width: 100%;
    justify-content: space-between;
  }

  .nav-tab {
    padding: 0.55rem 0.85rem;
    font-size: 0.84rem;
  }

  .item-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .item-actions .stepper-group {
    justify-content: space-between;
  }
}
