/* Added — mobile-first, high-contrast grocery app */

:root {
  --green: #0d7a3f;
  --green-dark: #085c2e;
  --green-light: #e6f4ec;
  --ink: #111417;
  --ink-soft: #4a5158;
  --bg: #f5f6f7;
  --card: #ffffff;
  --line: #d9dde1;
  --danger: #c0262c;
  --radius: 12px;
  --nav-height: 64px;
  --header-height: 56px;
  --tap: 48px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 17px;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* ---------- Views ---------- */

.view { height: 100dvh; }

.app-view {
  display: flex;
  flex-direction: column;
}

.app-header {
  height: var(--header-height);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  background: var(--green);
  color: #fff;
}

.app-header h2 { font-size: 1.25rem; font-weight: 700; }

.header-badge {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.85rem;
  font-weight: 700;
}

/* Independently scrolling main area */
.scroll-area {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px calc(var(--nav-height) + 24px);
}

/* ---------- Auth ---------- */

.auth-view {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  overflow-y: auto;
  background: linear-gradient(160deg, var(--green) 0%, var(--green-dark) 100%);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: 16px;
  padding: 28px 22px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
}

.logo {
  font-size: 2rem;
  font-weight: 800;
  color: var(--green);
  text-align: center;
}

.tagline {
  text-align: center;
  color: var(--ink-soft);
  margin: 6px 0 20px;
  font-size: 0.95rem;
}

.auth-tabs {
  display: flex;
  border: 2px solid var(--green);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 20px;
}

.auth-tab {
  flex: 1;
  min-height: var(--tap);
  border: none;
  background: var(--card);
  color: var(--green);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.auth-tab.active { background: var(--green); color: #fff; }

.field { display: block; margin-bottom: 14px; }

.field span {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  min-height: var(--tap);
  padding: 0 14px;
  font-size: 1.05rem;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}

.field input:focus {
  outline: none;
  border-color: var(--green);
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink-soft);
  margin: 18px 0;
  font-size: 0.85rem;
}

.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

/* ---------- Buttons ---------- */

.btn {
  min-height: var(--tap);
  padding: 0 18px;
  border: none;
  border-radius: 10px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.05s ease;
}

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

.btn.primary { background: var(--green); color: #fff; width: 100%; }
.btn.secondary { background: var(--green-light); color: var(--green-dark); width: 100%; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost {
  background: transparent;
  color: var(--ink-soft);
  width: 100%;
  margin-top: 10px;
}
.btn.wide { width: 100%; margin-top: 14px; }

.error {
  color: var(--danger);
  font-weight: 600;
  font-size: 0.9rem;
  margin: 4px 0 12px;
}

/* ---------- Add row (Planning) ---------- */

.add-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: 4px 0 8px;
}

.add-row input {
  flex: 1;
  min-height: var(--tap);
  padding: 0 14px;
  font-size: 1.05rem;
  border: 2px solid var(--line);
  border-radius: 10px;
}

.add-row input:focus { outline: none; border-color: var(--green); }

.add-btn {
  flex: 0 0 var(--tap);
  width: var(--tap);
  font-size: 1.6rem;
  line-height: 1;
  padding: 0;
}

/* ---------- Grouped lists ---------- */

.category-group { margin-bottom: 18px; }

.category-title {
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--green-dark);
  padding: 4px 6px;
  margin-bottom: 6px;
}

.item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--tap);
  width: 100%;
  padding: 6px 12px;
  margin-bottom: 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 1.05rem;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
}

.item-row .check {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  border: 2.5px solid var(--ink-soft);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 800;
  color: transparent;
  background: #fff;
}

.item-row.checked .check {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.item-row .item-name { flex: 1; font-weight: 600; }

.item-row.checked .item-name {
  text-decoration: line-through;
  opacity: 0.45;
}

.item-row.checked { opacity: 0.75; }

.item-row .checked-by {
  font-size: 0.75rem;
  color: var(--ink-soft);
}

.item-row .remove-btn {
  flex: 0 0 var(--tap);
  min-height: var(--tap);
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 1.3rem;
  cursor: pointer;
}

/* ---------- Shopping ---------- */

.sync-dot {
  margin-left: auto;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #7ef0a8;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.empty-state {
  text-align: center;
  color: var(--ink-soft);
  padding: 60px 20px;
  line-height: 1.5;
}

.empty-state p:first-child { font-size: 3rem; margin-bottom: 10px; }

/* ---------- History ---------- */

.trip-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}

.trip-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.trip-date { font-weight: 800; }

.trip-count { color: var(--ink-soft); font-size: 0.85rem; }

.trip-items {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.trip-chip {
  background: var(--green-light);
  color: var(--green-dark);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.85rem;
  font-weight: 600;
}

/* ---------- Settings ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.card h3 { margin-bottom: 12px; color: var(--green-dark); }

.kv {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 36px;
  font-size: 0.95rem;
}

.kv span { color: var(--ink-soft); }

.invite-code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 1.3rem;
  letter-spacing: 0.15em;
  color: var(--green);
}

.hint { font-size: 0.8rem; color: var(--ink-soft); margin: 4px 0 10px; }

/* ---------- Toast & dialog ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + 18px);
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.95rem;
  z-index: 60;
  max-width: 90vw;
  text-align: center;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 70;
  padding: 20px;
}

.dialog {
  background: var(--card);
  border-radius: 16px;
  padding: 22px;
  width: 100%;
  max-width: 360px;
  font-size: 1.05rem;
  line-height: 1.4;
}

.dialog-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.dialog-actions .btn { flex: 1; }

/* ---------- Bottom nav ---------- */

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--nav-height);
  display: flex;
  background: var(--card);
  border-top: 2px solid var(--line);
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-btn {
  flex: 1;
  min-height: var(--tap);
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink-soft);
  cursor: pointer;
}

.nav-btn .nav-icon { font-size: 1.35rem; }

.nav-btn.active { color: var(--green); background: var(--green-light); }

/* ---------- Larger screens ---------- */

@media (min-width: 700px) {
  .scroll-area, .app-header { padding-left: max(16px, calc(50vw - 330px)); padding-right: max(16px, calc(50vw - 330px)); }
}
