/* ==========================================================
   Shopmigo — design tokens
   Palette grounded in a fresh grocery/market feel:
   deep greens (produce, trust) + warm mango (price tags, CTAs)
   ========================================================== */
:root {
  --color-primary: #1F4D3D;
  --color-primary-light: #2F6B54;
  --color-primary-dark: #143529;
  --color-accent: #E8A33D;
  --color-accent-dark: #C9861F;
  --color-bg: #F1F4EE;
  --color-surface: #FFFFFF;
  --color-text: #20241F;
  --color-text-muted: #6E7268;
  --color-border: #E1E6DB;
  --color-danger: #C1443D;
  --color-danger-bg: #FBEAE8;
  --color-success: #3F8F5F;
  --color-success-bg: #E8F3EB;
  --shell-max-width: 480px;
  --nav-height: 64px;
  --topbar-height: 56px;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --font-display: 'Outfit', sans-serif;
  --font-body: 'Inter', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-primary-dark);
  color: var(--color-text);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

h1, h2, h3, h4, .display {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}

/* ---------- App shell (phone-like frame) ---------- */
.app-shell {
  max-width: var(--shell-max-width);
  margin: 0 auto;
  min-height: 100vh;
  background: var(--color-bg);
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (min-width: 560px) {
  html, body { background: var(--color-primary-dark); }
  .app-shell {
    min-height: 100vh;
    max-height: 100vh;
    margin-top: 0;
    box-shadow: 0 30px 60px rgba(0,0,0,0.35);
  }
}

/* ---------- Top bar ---------- */
.topbar {
  height: var(--topbar-height);
  min-height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h1 {
  font-size: 18px;
  color: var(--color-primary-dark);
}
.topbar .topbar-action {
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar-icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--color-primary);
  cursor: pointer;
}
.topbar-icon-btn:active { background: var(--color-bg); }
.topbar-back {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--color-primary);
  font-weight: 600;
  font-size: 15px;
}

/* ---------- Main content area ---------- */
.app-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px calc(var(--nav-height) + 24px);
  -webkit-overflow-scrolling: touch;
}
.app-content.no-nav-pad {
  padding-bottom: 24px;
}

/* ---------- Bottom nav bar ---------- */
.bottom-nav {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: stretch;
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--color-text-muted);
  font-size: 11px;
  font-weight: 500;
  position: relative;
}
.nav-item svg { width: 22px; height: 22px; }
.nav-item.active { color: var(--color-primary); }
.nav-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  width: 28px;
  height: 3px;
  border-radius: 0 0 4px 4px;
  background: var(--color-primary);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-md);
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-body);
  transition: transform 0.08s ease, opacity 0.15s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-light); }
.btn-accent { background: var(--color-accent); color: #3A2A05; }
.btn-outline { background: transparent; color: var(--color-primary); border: 1.5px solid var(--color-primary); }
.btn-danger { background: var(--color-danger-bg); color: var(--color-danger); }
.btn-ghost { background: transparent; color: var(--color-text-muted); }
.btn-sm { padding: 8px 12px; font-size: 13px; border-radius: var(--radius-sm); }
.btn-block { width: 100%; }
.btn-icon {
  width: 40px; height: 40px; padding: 0; border-radius: 50%;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.fab {
  position: fixed;
  right: calc((100vw - min(100vw, var(--shell-max-width))) / 2 + 20px);
  bottom: calc(var(--nav-height) + 20px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-accent);
  color: #3A2A05;
  border: none;
  box-shadow: 0 8px 20px rgba(232,163,61,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 25;
}
.fab:active { transform: scale(0.94); }
.fab svg { width: 26px; height: 26px; }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 6px;
}
.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field input[type="number"],
.field input[type="search"],
.field select,
.field textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--color-border);
  background: var(--color-surface);
  font-size: 15px;
  font-family: var(--font-body);
  color: var(--color-text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}
.field-hint { font-size: 12px; color: var(--color-text-muted); margin-top: 4px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

/* ---------- Cards ---------- */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--color-border);
}
.auth-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  margin-top: 12vh;
}
.auth-logo {
  width: 56px; height: 56px;
  display: block;
  margin: 0 auto 16px;
  border-radius: 16px;
}
.auth-logo svg { width: 28px; height: 28px; }

/* ---------- List summary cards (dashboard) ---------- */
.list-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 10px;
}
.list-card-icon {
  width: 44px; height: 44px;
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-primary);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.list-card-icon svg { width: 22px; height: 22px; }
.list-card-body { flex: 1; min-width: 0; }
.list-card-body h3 { font-size: 15px; }
.list-card-meta { font-size: 12.5px; color: var(--color-text-muted); margin-top: 2px; }
.list-card-chevron { color: var(--color-text-muted); }
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--color-bg);
  color: var(--color-primary);
}
.badge-shared { background: #EFE7F7; color: #6B4FA0; }

/* ---------- Section headers ---------- */
.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 20px 0 10px;
}
.section-title:first-child { margin-top: 4px; }

/* ---------- Shopping list items ---------- */
.item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 8px;
}
.item-check {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid var(--color-border);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: transparent;
  background: var(--color-surface);
}
.item-check svg { width: 15px; height: 15px; }
.item-row.purchased .item-check {
  background: var(--color-success);
  border-color: var(--color-success);
  color: #fff;
}
.item-row.purchased .item-name { text-decoration: line-through; color: var(--color-text-muted); }
.item-body { flex: 1; min-width: 0; }
.item-name { font-size: 15px; font-weight: 600; }
.item-meta { font-size: 12.5px; color: var(--color-text-muted); margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; }
.item-price { font-family: var(--font-display); font-weight: 600; color: var(--color-accent-dark); }
.item-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 32px; height: 32px;
  border: none; background: transparent; border-radius: 50%;
  color: var(--color-text-muted);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:active { background: var(--color-bg); }
.icon-btn.danger { color: var(--color-danger); }

/* ---------- Empty states ---------- */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--color-text-muted);
}
.empty-state svg { width: 56px; height: 56px; margin-bottom: 12px; opacity: 0.5; }
.empty-state h3 { color: var(--color-text); margin-bottom: 6px; font-size: 16px; }
.empty-state p { font-size: 13.5px; margin: 0; }

/* ---------- Flash / toast messages ---------- */
.flash {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 14px;
  font-weight: 500;
}
.flash-success { background: var(--color-success-bg); color: var(--color-success); }
.flash-error { background: var(--color-danger-bg); color: var(--color-danger); }
.flash-info { background: var(--color-bg); color: var(--color-primary-dark); }

.toast-container {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  width: calc(100% - 32px);
  max-width: calc(var(--shell-max-width) - 32px);
}
.toast {
  background: var(--color-primary-dark);
  color: #fff;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  margin-bottom: 8px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.25);
  animation: toast-in 0.2s ease;
}
.toast.error { background: var(--color-danger); }
.toast.success { background: var(--color-success); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Friend rows ---------- */
.friend-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--color-border);
}
.friend-row:last-child { border-bottom: none; }
.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-family: var(--font-display);
  flex-shrink: 0;
  font-size: 15px;
}
.friend-info { flex: 1; min-width: 0; }
.friend-info strong { font-size: 14.5px; display: block; }
.friend-info span { font-size: 12px; color: var(--color-text-muted); }

.uid-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-primary);
  color: #fff;
  padding: 16px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}
.uid-display .uid-code {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.06em;
}
.uid-display .uid-label { font-size: 11.5px; opacity: 0.75; text-transform: uppercase; letter-spacing: 0.05em; }

/* ---------- Modal / bottom sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(20,26,20,0.5);
  z-index: 90;
  display: none;
}
.sheet-backdrop.open { display: block; }
.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--shell-max-width);
  background: var(--color-surface);
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(24px + env(safe-area-inset-bottom, 0));
  z-index: 91;
  display: none;
  max-height: 85vh;
  overflow-y: auto;
}
.sheet.open { display: block; animation: sheet-up 0.2s ease; }
@keyframes sheet-up {
  from { transform: translate(-50%, 40px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}
.sheet-handle {
  width: 36px; height: 4px;
  background: var(--color-border);
  border-radius: 4px;
  margin: 0 auto 16px;
}
.sheet h3 { font-size: 17px; margin-bottom: 16px; }

/* ---------- Tables (admin) ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  overflow: hidden;
}
table.data-table th, table.data-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
table.data-table th {
  background: var(--color-bg);
  color: var(--color-text-muted);
  font-weight: 700;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
table.data-table tr:last-child td { border-bottom: none; }
.status-pill {
  display: inline-flex;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
}
.status-pending { background: #FCEFD9; color: var(--color-accent-dark); }
.status-active { background: var(--color-success-bg); color: var(--color-success); }
.status-inactive { background: var(--color-danger-bg); color: var(--color-danger); }
.role-admin { background: #E4E9FA; color: #3A55B0; }
.role-user { background: var(--color-bg); color: var(--color-text-muted); }

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px;
}
.stat-card .stat-value { font-family: var(--font-display); font-size: 24px; font-weight: 700; color: var(--color-primary-dark); }
.stat-card .stat-label { font-size: 12px; color: var(--color-text-muted); margin-top: 2px; }

.tab-row {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  background: var(--color-bg);
  padding: 4px;
  border-radius: var(--radius-md);
}
.tab-row a {
  flex: 1;
  text-align: center;
  padding: 9px 4px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 10px;
  color: var(--color-text-muted);
}
.tab-row a.active { background: var(--color-surface); color: var(--color-primary); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }

.divider { height: 1px; background: var(--color-border); margin: 16px 0; }

.request-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
}
.request-row .friend-info { flex: 1; }

.link-muted { color: var(--color-text-muted); font-size: 13px; }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; }
