:root {
  --bg: #f4f6f3;
  --card: #ffffff;
  --text: #1a231a;
  --muted: #6f7a6c;
  --muted-light: #98a094;
  --accent: #2f7a3d;
  --accent-dark: #235c2e;
  --accent-light: #e8f4ea;
  --accent-soft: #f0f8f1;
  --border: #e4e8e1;
  --border-strong: #d4dad0;
  --danger: #c0392b;
  --danger-light: #fbeae8;
  --shadow-sm: 0 1px 2px rgba(20, 30, 20, 0.05);
  --shadow-md: 0 2px 8px rgba(20, 30, 20, 0.07);
  --shadow-lg: 0 8px 24px rgba(20, 30, 20, 0.12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

* { box-sizing: border-box; }

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--accent-dark);
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tabs {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tab {
  border: 1px solid var(--border-strong);
  background: var(--card);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 7px;
  transition: all 0.15s ease;
}

.tab:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  box-shadow: var(--shadow-sm);
}

.tab.active:hover {
  background: var(--accent-dark);
  color: white;
}

.badge {
  background: var(--danger);
  color: white;
  border-radius: 10px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: 0.72rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tab.active .badge {
  background: white;
  color: var(--accent-dark);
}

.lang-btn {
  margin-left: 4px;
  border-color: var(--accent);
  color: var(--accent-dark);
  font-weight: 700;
}

/* Layout */
.layout {
  max-width: 1140px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

.view {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.view[hidden] {
  display: none;
}

/* Sidebar */
.sidebar {
  width: 234px;
  flex-shrink: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 82px;
}

.sidebar-title {
  padding: 14px 16px;
  font-weight: 700;
  font-size: 0.88rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--accent-soft);
}

.category-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  max-height: 75vh;
  overflow-y: auto;
}

.category-list li {
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1.04rem;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  transition: background 0.12s ease;
}

.category-list li:hover {
  background: var(--accent-soft);
}

.category-list li.active {
  background: var(--accent);
  color: white;
  font-weight: 600;
}

.category-list .cat-count {
  color: var(--muted-light);
  font-size: 0.86rem;
  font-weight: 600;
}

.category-list li.active .cat-count {
  color: rgba(255, 255, 255, 0.85);
}

/* Content */
.content {
  flex: 1;
  min-width: 0;
}

.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.content-header h2 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

#catalog-search {
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  min-width: 220px;
  background: var(--card);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#catalog-search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 14px;
}

.product-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 12px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}

.product-actions {
  display: flex;
  gap: 6px;
  width: 100%;
}

.product-actions .product-add {
  flex: 1 1 auto;
}

.product-delete {
  flex: 0 0 auto;
  width: 36px;
  border: 1.5px solid var(--danger);
  background: var(--card);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.product-delete:hover {
  background: var(--danger);
  color: white;
}

.product-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.product-icon {
  font-size: 2.1rem;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  border-radius: 50%;
}

.product-name {
  font-size: 1.02rem;
  font-weight: 600;
  min-height: 2.3em;
  color: var(--text);
}

.product-add {
  width: 100%;
  border: 1.5px solid var(--accent);
  background: var(--card);
  color: var(--accent-dark);
  border-radius: var(--radius-sm);
  padding: 9px 8px;
  font-size: 0.94rem;
  cursor: pointer;
  font-weight: 700;
  transition: all 0.15s ease;
}

.product-add:hover {
  background: var(--accent-light);
}

.product-add.added {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.product-add.added:hover {
  background: var(--accent-dark);
}

/* Qty box: groups Packs/Size inputs and unit dropdown into one cohesive control */
.qty-box {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
}

.product-qty-row {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 8px;
}

.qty-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted-light);
  margin-bottom: 3px;
  text-align: left;
}

.qty-group,
.qty-group-sm {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-width: 0;
}

.qty-group-sm .qty-label {
  font-size: 0.68rem;
  margin-bottom: 2px;
}

/* All qty/unit inputs share one consistent look */
.qty-box input[type="number"],
.qty-box select,
.item-qty input[type="number"],
.item-qty select {
  width: 100%;
  min-width: 0;
  padding: 7px 7px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: 0.94rem;
  background: var(--card);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.qty-box input[type="number"]:focus,
.qty-box select:focus,
.item-qty input[type="number"]:focus,
.item-qty select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.qty-box select {
  font-weight: 600;
  cursor: pointer;
}

.product-qty-sep,
.item-qty-sep {
  padding-bottom: 7px;
  color: var(--muted-light);
  font-size: 0.78rem;
  font-weight: 700;
}

.item-qty {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-top: 8px;
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
}

.item-qty select {
  flex: 0 0 64px;
}

/* Quantity stepper: trash/minus, value, plus — matches cart-style widgets */
.stepper {
  display: flex;
  align-items: stretch;
  background: var(--accent);
  border-radius: 8px;
  overflow: hidden;
  flex: 0 0 auto;
  box-shadow: var(--shadow-sm);
}

.stepper-btn {
  border: none;
  background: transparent;
  color: white;
  width: 30px;
  height: 30px;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease;
}

.stepper-btn:hover {
  background: rgba(0, 0, 0, 0.12);
}

.stepper-minus-danger {
  font-size: 0.85rem;
}

.stepper-value {
  background: var(--card);
  color: var(--text);
  min-width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.88rem;
}

.section-heading {
  grid-column: 1 / -1;
  font-weight: 800;
  font-size: 1.02rem;
  margin: 14px 0 2px;
  color: var(--accent-dark);
  display: flex;
  align-items: center;
  gap: 6px;
}

.section-heading:first-child {
  margin-top: 0;
}

/* My List view */
.list-panel {
  flex: 1;
  max-width: 600px;
  margin: 0 auto;
}

.add-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  background: var(--card);
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.add-form input[type="text"] {
  flex: 1 1 140px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 1.05rem;
  background: var(--card);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.add-form input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.add-form button {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: white;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease;
}

.add-form button:hover { background: var(--accent-dark); }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding: 0 2px;
  font-size: 0.95rem;
  color: var(--muted);
}

.count {
  font-weight: 600;
}

.link-btn {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 4px;
  transition: opacity 0.15s ease;
}

.link-btn:hover { opacity: 0.75; }

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s ease, background 0.15s ease;
}

.item:hover {
  box-shadow: var(--shadow-md);
}

.item.checked {
  background: var(--accent-soft);
  border-color: var(--accent-light);
}

.item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  flex-shrink: 0;
  cursor: pointer;
  margin-top: 2px;
}

.item-text {
  flex: 1;
  min-width: 0;
}

.item-name {
  font-size: 1.15rem;
  font-weight: 600;
  word-break: break-word;
}

.item.checked .item-name {
  text-decoration: line-through;
  color: var(--muted);
  font-weight: 500;
}

.item-category {
  font-size: 0.86rem;
  color: var(--muted-light);
  margin-top: 2px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.item-delete {
  background: none;
  border: none;
  color: var(--muted-light);
  font-size: 1.05rem;
  cursor: pointer;
  padding: 4px 8px;
  flex-shrink: 0;
  border-radius: 6px;
  transition: all 0.15s ease;
}

.item-delete:hover {
  color: var(--danger);
  background: var(--danger-light);
}

.empty {
  text-align: center;
  color: var(--muted);
  margin-top: 48px;
  font-size: 0.95rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent-dark);
  color: white;
  padding: 10px 10px 10px 20px;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
}

.toast[hidden] {
  display: none;
}

.toast-undo {
  border: none;
  background: white;
  color: var(--accent-dark);
  font-weight: 700;
  font-size: 0.82rem;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s ease;
}

.toast-undo:hover {
  opacity: 0.85;
}

/* Responsive */
@media (max-width: 720px) {
  .topbar {
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .layout {
    padding: 16px 14px 48px;
  }
  .view {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    position: static;
  }
  .category-list {
    max-height: none;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px;
  }
  .category-list li {
    flex: 0 0 auto;
  }
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
  }
}
