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

:root {
  /* Brand palette — derived from the main colour #2A7C13 */
  --primary: #2A7C13;
  --primary-dark: #1E5A0D;
  --primary-light: #BEDCB2;
  --primary-50: #EDF6E9;
  --orange: #fb8c00;
  --red: #e53935;
  --green: #4C9A2A;       /* 'in stock' status — a lighter shade of the primary */
  --bg: #F2F5F0;
  --card: #ffffff;
  --text: #1a1a1a;
  --text-muted: #757575;
  --border: #e0e0e0;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 4px 20px rgba(0,0,0,.12);
  --topbar-h: 56px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea {
  font-family: inherit; font-size: 16px;
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  outline: none; transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
label { display: block; margin-bottom: 12px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
label input, label select, label textarea { margin-top: 4px; font-weight: 400; color: var(--text); }

/* ===== Top App Bar ===== */
#app-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--topbar-h);
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px; box-shadow: var(--shadow);
}
.bar-left, .bar-right { display: flex; align-items: center; gap: 4px; }
.app-logo {
  width: 32px; height: 32px; border-radius: 50%;
  background: #e8f5e9; padding: 2px; flex: 0 0 auto;
}
.loading-logo { width: 96px; height: 96px; }
#page-title { font-size: 18px; font-weight: 600; margin-left: 4px; white-space: nowrap; }
.icon-btn {
  color: #fff; font-size: 22px; width: 40px; height: 40px;
  border-radius: 50%; transition: background .15s;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: rgba(255,255,255,.15); }

/* ===== Sync badge ===== */
#sync-badge {
  background: var(--orange); color: #fff;
  border-radius: 10px; padding: 2px 8px; font-size: 12px; font-weight: 700;
}

/* ===== Search Bar ===== */
#search-bar {
  position: fixed; top: var(--topbar-h); left: 0; right: 0; z-index: 90;
  background: #fff; padding: 8px 12px; display: flex; gap: 8px; box-shadow: var(--shadow);
  flex-wrap: wrap;
}
#search-bar input { flex: 1 1 150px; min-width: 120px; }
#search-bar select { width: auto; min-width: 90px; flex: 0 0 auto; }

/* ===== Sidebar ===== */
#sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 200;
  width: 280px; max-width: 85vw;
  background: #fff; box-shadow: var(--shadow-lg);
  transform: translateX(0); transition: transform .25s ease;
  padding-top: var(--topbar-h); overflow-y: auto;
}
#sidebar.closed { transform: translateX(-100%); }
#sidebar nav { padding: 8px 0; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px; font-size: 15px; font-weight: 500; color: var(--text);
  transition: background .12s;
}
.nav-item.active { background: var(--primary-50); color: var(--primary); font-weight: 600; border-left: 3px solid var(--primary); }
.nav-item:hover { background: var(--bg); }
#sidebar hr { border: none; border-top: 1px solid var(--border); margin: 8px 0; }
.badge {
  background: var(--red); color: #fff; border-radius: 10px;
  padding: 1px 7px; font-size: 12px; font-weight: 700; margin-left: auto;
}
#sidebar-overlay {
  position: fixed; inset: 0; z-index: 150; background: rgba(0,0,0,.3);
}

/* ===== Main ===== */
#main { padding-top: var(--topbar-h); min-height: 100vh; }
.view { display: none; padding: 12px 12px 90px; }
.view.active { display: block; }

/* ===== Product Grid ===== */
.product-grid {
  display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
@media (max-width: 400px) { .product-grid { grid-template-columns: 1fr; } }

/* Compact card. Colour follows stock status via --st (accent) and --st-bg (tint). */
.product-card {
  --st: var(--green); --st-bg: var(--card); --st-chip: #e8f5e9;
  background: var(--st-bg); border-radius: var(--radius); padding: 10px 12px 10px 14px;
  border-left: 5px solid var(--st);
  box-shadow: var(--shadow); transition: box-shadow .15s, transform .1s;
  cursor: pointer; position: relative;
  display: flex; flex-direction: column; gap: 4px;
}
.product-card:hover { box-shadow: var(--shadow-lg); }
.product-card:active { transform: scale(.985); }
.product-card.status-low      { --st: #e91e63; --st-bg: #fff5f8; --st-chip: #fce4ec; }
.product-card.status-expiring { --st: var(--orange); --st-bg: #fffaf2; --st-chip: #fff3e0; }
.product-card.status-expired  { --st: var(--red); --st-bg: #fff5f5; --st-chip: #ffebee; }
.product-card.status-out      { --st: #9e9e9e; --st-bg: #f7f7f7; --st-chip: #eeeeee; }
.product-card.status-out .name { color: var(--text-muted); }

.pc-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.product-card .name {
  font-size: 15px; font-weight: 700; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.product-card .qty { flex: 0 0 auto; white-space: nowrap; }
.product-card .qty .num { font-size: 18px; font-weight: 800; color: var(--st); }
.product-card.status-ok .qty .num { color: var(--primary); }
.product-card .qty .unit { font-size: 12px; color: var(--text-muted); }
.product-card .meta {
  font-size: 12px; color: var(--text-muted); display: flex; gap: 4px;
  overflow: hidden; white-space: nowrap;
}
.product-card .meta span:first-child { color: var(--primary); font-weight: 600; }

.pc-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 2px; }
.status-chip {
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 6px;
  background: var(--st-chip); color: var(--st); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.product-card.status-ok .status-chip { color: #2e7d32; }

/* Use / Restock / Wishlist — compact round buttons */
.card-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.card-actions .act {
  width: 34px; height: 30px; border-radius: 9px;
  font-size: 18px; font-weight: 800; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); background: #fff;
}
.card-actions .act-use { color: #e65100; border-color: #ffcc80; background: #fff3e0; }
.card-actions .act-use:hover { background: #ffe0b2; }
.card-actions .act-use:disabled { opacity: .4; cursor: not-allowed; }
.card-actions .act-restock { color: var(--primary); border-color: var(--primary-light); background: var(--primary-50); }
.card-actions .act-restock:hover { background: var(--primary-light); }
.card-actions .act-wish { color: #f9a825; border-color: #ffe082; background: #fffde7; font-size: 17px; }
.card-actions .act-wish:hover { background: #fff8e1; }
.card-actions .act-wish.on { background: #ffecb3; }

/* Shared purple owner chip (wishlist uses it too) */
.owner-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: #ede7f6; color: #5e35b1; border-radius: 20px;
  padding: 2px 10px; font-size: 12px; font-weight: 600;
}

/* Active filter summary above the inventory grid */
.active-filters {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
  margin: 0 2px 10px; font-size: 13px; color: var(--text-muted);
}
.filter-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--primary-50); color: var(--primary); font-weight: 600;
  border-radius: 20px; padding: 3px 4px 3px 10px;
}
.filter-pill button {
  width: 20px; height: 20px; border-radius: 50%; color: var(--primary);
  font-size: 15px; line-height: 1; display: flex; align-items: center; justify-content: center;
}
.filter-pill button:hover { background: var(--primary-light); }

/* Logo in the app bar doubles as the Home button */
.logo-btn { display: flex; align-items: center; gap: 8px; color: #fff; border-radius: 20px; padding: 2px 8px 2px 2px; }
.logo-btn:hover { background: rgba(255,255,255,.15); }

/* ===== Empty State ===== */
.empty-state {
  text-align: center; padding: 60px 20px; color: var(--text-muted);
}
.empty-state p { margin-bottom: 16px; font-size: 16px; }

/* ===== Buttons ===== */
.btn {
  display: inline-block; padding: 10px 20px; border-radius: 8px;
  font-size: 14px; font-weight: 600; background: #f5f5f5; color: var(--text);
  border: 1px solid var(--border); transition: all .15s;
  text-align: center;
}
.btn:hover { background: #eee; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn.danger:hover { background: #c62828; }

/* ===== FAB ===== */
.fab {
  position: fixed; bottom: 20px; right: 20px; z-index: 80;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 28px;
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
  display: flex; align-items: center; justify-content: center;
  transition: transform .1s, background .15s;
}
.fab:active { transform: scale(.9); }
.fab:hover { background: var(--primary-dark); }

/* ===== Modal ===== */
#modal-overlay, #loc-modal-overlay, #stock-modal-overlay, #wish-modal-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,.4); display: flex;
  align-items: flex-end; justify-content: center;
  animation: fadeIn .15s ease;
}
@media (min-width: 600px) {
  #modal-overlay, #loc-modal-overlay, #stock-modal-overlay, #wish-modal-overlay { align-items: center; }
}
.modal {
  background: #fff; border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg); animation: slideUp .2s ease;
}
@media (min-width: 600px) { .modal { border-radius: var(--radius); } }
.modal-sm { max-width: 400px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: #fff; z-index: 1;
}
.modal-header h2 { font-size: 18px; font-weight: 600; }
.modal-header .icon-btn { color: var(--text-muted); }
.modal-header .icon-btn:hover { background: var(--bg); }
.modal-body { padding: 20px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-footer {
  display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px;
}
.modal-footer .btn { flex: 0 0 auto; }

/* ===== Stock actions, history ===== */
.hint { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.stock-actions { display: flex; gap: 8px; margin-bottom: 16px; }
.stock-actions .btn { flex: 1; }
.btn.use { background: #fff3e0; color: #e65100; border-color: #ffcc80; }
.btn.use:hover { background: #ffe0b2; }
.stock-product { margin-bottom: 14px; }
.field { margin-bottom: 12px; }
.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
.amount-row { display: flex; gap: 8px; align-items: stretch; }
.amount-row input { text-align: center; font-size: 18px; font-weight: 600; }
.amount-row .btn.step { flex: 0 0 48px; padding: 0; font-size: 20px; }
#s-all { margin: -6px 0 10px; padding-left: 0; color: var(--primary); }

.section-title { font-size: 15px; font-weight: 700; margin: 20px 0 8px; padding-top: 16px; border-top: 1px solid var(--border); }
.history-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px;
}
.history-item:last-child { border-bottom: none; }
.history-item[data-id] { cursor: pointer; }
.history-icon { flex: 0 0 24px; text-align: center; }
.history-main { flex: 1; min-width: 0; }
.history-meta { font-size: 12px; color: var(--text-muted); }
.history-change { flex: 0 0 auto; font-weight: 700; font-size: 13px; color: var(--text-muted); white-space: nowrap; }
.history-change.pos { color: var(--green); }
.history-change.neg { color: #e65100; }
.history-empty { padding: 16px 0; text-align: center; color: var(--text-muted); font-size: 14px; }

/* ===== Home / Dashboard ===== */
#view-home { max-width: 720px; margin: 0 auto; }
.dash-head { display: flex; align-items: center; justify-content: space-between; margin: 8px 4px 16px; }
.dash-greet { font-size: 30px; font-weight: 800; letter-spacing: -.5px; line-height: 1.15; }
.dash-avatar {
  width: 52px; height: 52px; border-radius: 50%; flex: 0 0 auto;
  background: #fff; color: var(--text); box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center;
}
.dash-avatar:hover { box-shadow: var(--shadow-lg); }

.dash-row, .dash-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.dash-tile {
  min-height: 132px; border-radius: 22px; padding: 16px;
  display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start;
  text-align: left; color: var(--text); transition: transform .1s, box-shadow .15s;
}
.dash-tile:active, .dash-chip-card:active, .dash-loc:active, .dash-banner:active { transform: scale(.98); }
.tile-expense { background: #E4EFDF; }
.tile-outline { background: #fff; border: 1.5px solid var(--border); }
.tile-icon { display: flex; }
.expense-icon {
  width: 46px; height: 46px; border-radius: 50% 50% 50% 12px;
  background: var(--primary); align-items: center; justify-content: center;
}
.tile-bottom { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.tile-bottom strong { font-size: 17px; font-weight: 800; }
.tile-pill { background: #fff; border-radius: 8px; padding: 1px 8px; font-weight: 700; font-size: 15px; color: #555; }
.tile-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.dash-search {
  display: flex; align-items: center; gap: 12px;
  background: #fff; border: 1.5px solid var(--border); border-radius: 22px;
  padding: 14px 16px; margin-bottom: 12px;
}
.dash-search input { border: none; padding: 6px 0; font-size: 18px; background: transparent; }
.dash-search input::placeholder { color: #9e9e9e; }
.dash-search-icon { flex: 0 0 auto; display: flex; }
.dash-search-clear {
  flex: 0 0 28px; height: 28px; border-radius: 50%;
  background: #222; color: #fff; font-size: 18px; line-height: 1;
}

.dash-chip-card {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px;
  background: #fff; border: 1.5px solid var(--border); border-radius: 22px;
  text-align: left; color: var(--text); min-height: 76px;
}
.chip-illu {
  flex: 0 0 44px; height: 44px; border-radius: 50%;
  background: var(--primary-50); display: flex; align-items: center; justify-content: center; font-size: 22px;
}
#dash-expiring .chip-illu { background: #fff3e0; }
.chip-text { display: flex; flex-direction: column; min-width: 0; }
.chip-text strong { font-size: 17px; font-weight: 700; }
.chip-text span { font-size: 13px; color: var(--text-muted); }
.chip-text span.hot { color: var(--red); font-weight: 700; }

.dash-locations {
  display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory;
  background: #fff; border: 1.5px solid var(--border); border-radius: 22px;
  padding: 12px; margin-bottom: 12px; scrollbar-width: none;
}
.dash-locations::-webkit-scrollbar { display: none; }
.dash-loc {
  flex: 0 0 auto; scroll-snap-align: start; min-width: 92px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 12px; border-radius: 16px; background: var(--bg); color: var(--text);
}
.dash-loc .loc-emoji { font-size: 28px; line-height: 1.1; }
.dash-loc .loc-label { font-size: 14px; font-weight: 700; white-space: nowrap; }
.dash-loc .loc-n { font-size: 11px; color: var(--text-muted); }

.dash-banner {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: linear-gradient(135deg, #e8f5e9 0%, #fff8e1 60%, #ede7f6 100%);
  border-radius: 22px; padding: 18px 12px 18px 20px; margin-bottom: 18px;
  text-align: left; color: var(--text); overflow: hidden; min-height: 150px;
}
.banner-text { display: flex; flex-direction: column; gap: 6px; }
.banner-text strong { font-size: 20px; font-weight: 800; line-height: 1.2; }
.banner-text span { font-size: 13px; color: #555; }
.banner-art { width: 52%; max-width: 240px; flex: 0 0 auto; }

/* Quick add buttons */
.dash-quick { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.quick-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 10px; border-radius: 18px; font-size: 15px; font-weight: 700;
}
.quick-product { background: var(--primary); color: #fff; box-shadow: 0 2px 6px rgba(42,124,19,.3); }
.quick-product:hover { background: var(--primary-dark); }
.quick-wish { background: #fff8e1; color: #8d6e00; border: 1.5px solid #ffe082; }
.quick-wish:hover { background: #ffecb3; }
.quick-plus { font-size: 20px; line-height: 1; }
.quick-btn:active { transform: scale(.98); }

/* Favorites strip */
.dash-favs {
  background: linear-gradient(135deg, #e8f5e9 0%, #fff8e1 60%, #ede7f6 100%);
  border-radius: 22px; padding: 14px 12px 12px; margin-bottom: 18px;
}
.dash-favs .dash-section-title { margin: 0 4px 10px; }
.fav-hint { font-size: 12px; font-weight: 500; color: var(--text-muted); }
.fav-strip {
  display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory;
  padding-bottom: 2px; scrollbar-width: none;
}
.fav-strip::-webkit-scrollbar { display: none; }
.fav-tile {
  --st: var(--primary);
  flex: 0 0 128px; scroll-snap-align: start; cursor: pointer;
  background: #fff; border-radius: 18px; padding: 10px 10px 8px;
  box-shadow: var(--shadow); border-top: 4px solid var(--st);
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px;
}
.fav-tile.status-low { --st: #e91e63; }
.fav-tile.status-expiring { --st: var(--orange); }
.fav-tile.status-expired { --st: var(--red); }
.fav-tile.status-out { --st: #9e9e9e; }
.fav-emoji { font-size: 34px; line-height: 1.15; }
.fav-name {
  font-size: 13px; font-weight: 700; width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fav-qty { font-size: 12px; color: var(--text-muted); }
.fav-qty strong { color: var(--st); font-size: 15px; }
.fav-stat { font-size: 10px; color: var(--text-muted); }
.fav-actions { display: flex; gap: 6px; margin-top: 6px; }
.fav-actions .act {
  width: 40px; height: 30px; border-radius: 9px; font-size: 18px; font-weight: 800;
  display: flex; align-items: center; justify-content: center; border: 1px solid var(--border);
}
.fav-actions .act-use { color: #e65100; border-color: #ffcc80; background: #fff3e0; }
.fav-actions .act-use:disabled { opacity: .4; cursor: not-allowed; }
.fav-actions .act-restock { color: var(--primary); border-color: var(--primary-light); background: var(--primary-50); }

/* Price + "for…" basis */
.price-row { display: flex; gap: 8px; }
.price-row input { flex: 1 1 45%; min-width: 0; }
.price-row select { flex: 1 1 55%; min-width: 0; }
.price-hint { display: block; min-height: 16px; margin-top: 4px; font-size: 12px; color: var(--primary-dark); font-weight: 600; }

/* Restock: new batch expiry date */
.expiry-row { display: flex; gap: 8px; }
.expiry-row input { flex: 1; min-width: 0; }
.expiry-row .btn { flex: 0 0 44px; padding: 0; font-size: 18px; }
.expiry-hint { display: block; margin-top: 4px; font-size: 12px; color: var(--text-muted); }
.expiry-hint.warn { color: #e65100; font-weight: 600; }

/* Category dropdowns: group headers */
select optgroup { font-weight: 700; color: var(--text-muted); }

.dash-section-title { display: flex; justify-content: space-between; align-items: center; margin: 0 4px 8px; font-size: 18px; font-weight: 800; }
.dash-section-title .link-btn { color: var(--primary); text-decoration: none; }

/* ===== Bottom tab bar ===== */
#tabbar {
  position: fixed; left: 12px; right: 12px; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 90;
  max-width: 560px; margin: 0 auto;
  display: flex; justify-content: space-around;
  background: rgba(255,255,255,.92); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border); border-radius: 28px; box-shadow: var(--shadow-lg);
  padding: 6px;
}
.tab-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 2px; border-radius: 22px; color: #333; font-size: 12px; font-weight: 600;
}
.tab-item svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.tab-item.active { color: var(--primary); background: var(--primary-50); }
.tab-item.active svg { fill: currentColor; fill-opacity: .15; }
/* Leave room for the tab bar */
.view { padding-bottom: 120px; }
.fab { bottom: calc(92px + env(safe-area-inset-bottom)); }
body #toast { bottom: calc(150px + env(safe-area-inset-bottom)); } /* beats the later #toast rule */

/* ===== Wishlist ===== */
.badge-primary { background: var(--primary); }
.modal-footer.wrap { flex-wrap: wrap; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; background: var(--card); padding: 4px; border-radius: 10px; box-shadow: var(--shadow); }
.tab { flex: 1; padding: 8px 12px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--text-muted); }
.tab.active { background: var(--primary); color: #fff; }
.wish-summary { font-size: 13px; color: var(--text-muted); margin: 0 4px 8px; }
.wish-item {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--card); border-radius: var(--radius); padding: 12px 14px;
  margin-bottom: 8px; box-shadow: var(--shadow); cursor: pointer;
}
.wish-item:hover { box-shadow: var(--shadow-lg); }
/* Explicit "✓ Bought" / "↩ Undo" button on each wish */
.wish-action {
  flex: 0 0 auto; align-self: center;
  padding: 8px 12px; border-radius: 10px; font-size: 13px; font-weight: 700; white-space: nowrap;
}
.wish-buy { background: var(--primary); color: #fff; box-shadow: 0 1px 3px rgba(42,124,19,.35); }
.wish-buy:hover { background: var(--primary-dark); }
.wish-undo { background: #f5f5f5; color: var(--text-muted); border: 1px solid var(--border); }
.wish-undo:hover { background: #eee; color: var(--text); }
/* Bought but not yet in the inventory → amber edge; fully done → green edge */
.wish-item.bought { border-left: 5px solid #ffb300; }
.wish-item.bought.stocked { border-left-color: var(--green); background: #f6faf6; }
.wish-actions { display: flex; flex-direction: column; gap: 6px; align-self: center; flex: 0 0 auto; }
.wish-stock { background: #fff3e0; color: #e65100; border: 1px solid #ffcc80; }
.wish-stock:hover { background: #ffe0b2; }
.wish-chips .bought-chip { background: #e8f5e9; color: #2e7d32; }
.wish-chips .stocked-chip { background: #2e7d32; color: #fff; }
.wish-chips .unstocked-chip { background: #fff3e0; color: #e65100; }
.wish-chips .stock-chip { background: #f5f5f5; color: var(--text-muted); font-weight: 500; }
.warn-text { color: #e65100; }

/* Status section inside the wish dialog */
.wish-status-box {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 12px; margin-bottom: 14px; border-radius: 10px;
  background: var(--primary-50); border: 1px solid var(--primary-light);
}
.wish-status-box.is-bought { background: #e8f5e9; border-color: #a5d6a7; }
.wish-status-text { flex: 1 1 100%; font-size: 13px; font-weight: 600; color: var(--primary-dark); white-space: pre-line; line-height: 1.6; }
.wish-status-box .btn:disabled { opacity: .7; cursor: default; background: #e8f5e9; color: #2e7d32; border-color: #a5d6a7; }
.wish-status-box .btn { flex: 1 1 auto; padding: 9px 12px; }
.from-wish {
  background: #fffde7; border: 1px solid #ffe082; color: #8d6e00;
  border-radius: 8px; padding: 8px 10px; font-weight: 600;
}
.wish-main { flex: 1; min-width: 0; }
.wish-name { font-weight: 600; font-size: 15px; }
.wish-qty { font-weight: 400; color: var(--text-muted); font-size: 13px; margin-left: 4px; }
.wish-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.wish-chips span { border-radius: 20px; padding: 1px 9px; font-size: 12px; font-weight: 600; }
.wish-chips .owner-chip { background: #ede7f6; color: #5e35b1; }
.prio-high { background: #ffebee; color: var(--red); }
.prio-low { background: #f5f5f5; color: var(--text-muted); }
.stock-chip { background: var(--primary-50); color: var(--primary); }
.new-chip { background: #fff8e1; color: #f57f17; }
.wish-meta { font-size: 12px; color: var(--text-muted); margin-top: 4px; word-break: break-word; }
.wish-link { color: var(--primary); font-weight: 600; margin-left: 6px; }

/* ===== Alerts View ===== */
.alert-section { margin-bottom: 20px; }
.alert-section h3 {
  font-size: 15px; font-weight: 700; margin-bottom: 8px;
  display: flex; align-items: center; gap: 6px;
}
.alert-item {
  background: var(--card); border-radius: 10px; padding: 12px 14px;
  margin-bottom: 8px; box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  cursor: pointer;
}
.alert-item .left { flex: 1; }
.alert-item .name { font-weight: 600; font-size: 15px; }
.alert-item .detail { font-size: 12px; color: var(--text-muted); }
.alert-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.dot-red { background: var(--red); }
.dot-orange { background: var(--orange); }
.dot-pink { background: #e91e63; }
.dot-grey { background: #9e9e9e; }
.out-text { color: #616161; }

.summary-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px,1fr)); gap: 10px; margin-bottom: 20px; }
.summary-card { background: var(--card); border-radius: 10px; padding: 14px; text-align: center; box-shadow: var(--shadow); }
.summary-card .num { font-size: 28px; font-weight: 700; color: var(--primary); }
.summary-card .label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ===== Locations View ===== */
.location-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(180px,1fr)); }
.location-card {
  background: var(--card); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow); text-align: center; cursor: pointer;
  transition: box-shadow .15s, transform .1s; position: relative;
}
.location-card:hover { box-shadow: var(--shadow-lg); }
.location-card:active { transform: scale(.97); }
.location-card .loc-icon { font-size: 38px; margin-bottom: 8px; }
.location-card .loc-name { font-weight: 600; font-size: 15px; }
.location-card .loc-count { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.location-card .loc-edit {
  position: absolute; top: 8px; right: 8px;
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 16px;
}
.location-card .loc-edit:hover { background: var(--bg); color: var(--primary); }

/* ===== Stats View ===== */
.stat-row {
  display: flex; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px;
}
.stat-row:last-child { border: none; }
.stat-row .val { font-weight: 700; color: var(--primary); }

/* ===== Settings View ===== */
.card {
  background: var(--card); border-radius: var(--radius); padding: 18px;
  margin-bottom: 14px; box-shadow: var(--shadow);
}
.card h2 { font-size: 16px; margin-bottom: 14px; }
.card .btn { margin-top: 8px; margin-right: 8px; }

/* ===== Toast ===== */
#toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  z-index: 400; background: #333; color: #fff;
  padding: 10px 24px; border-radius: 24px; font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-lg); animation: toastIn .2s ease;
  max-width: 90vw;
}

/* ===== Connection Error Banner ===== */
#conn-banner {
  position: fixed; top: var(--topbar-h); left: 0; right: 0; z-index: 95;
  background: #fff3e0; color: #e65100;
  padding: 10px 14px; font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  border-bottom: 1px solid #ffb74d; box-shadow: var(--shadow);
}
#conn-banner-msg {
  font-weight: 400; opacity: .85; flex: 1 1 auto; min-width: 0;
  word-break: break-all;
}
#conn-banner-url {
  font-weight: 400; opacity: .7; flex: 1 1 100%;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 12px; word-break: break-all;
  border-top: 1px dashed rgba(230, 81, 0, 0.3); padding-top: 4px; margin-top: 2px;
}
.link-btn {
  background: none; border: none; color: #e65100;
  text-decoration: underline; font-weight: 600; cursor: pointer;
  padding: 4px 6px; font-size: 13px;
}
.link-btn:hover { background: rgba(230, 81, 0, 0.1); border-radius: 4px; }

/* ===== Refresh button ===== */
#refresh-btn svg { animation: none; }
#refresh-btn.spinning svg { animation: spin 0.8s linear infinite; }

/* ===== Loading Overlay ===== */
#loading-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(255, 255, 255, 0.85);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  animation: fadeIn .15s ease;
}
#loading-overlay p { font-size: 14px; font-weight: 600; color: var(--text-muted); }
.loading-spinner {
  width: 40px; height: 40px;
  border: 4px solid var(--primary-light);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ===== Utility ===== */
.d-none { display: none !important; }

/* ===== Animations ===== */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 20px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* ===== Responsive tweaks ===== */
@media (max-width: 360px) {
  .form-row { grid-template-columns: 1fr; }
  #page-title { font-size: 16px; }
}