/* Grocery Tracker — mobile-first, store-friendly UI */

:root {
  --bg: #f4f7f5;
  --surface: #ffffff;
  --text: #1a2420;
  --muted: #5c6b64;
  --border: #dce5df;
  --primary: #1a7a4c;
  --primary-dark: #145f3b;
  --primary-soft: #e6f5ed;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --warning: #b7791f;
  --shadow: 0 8px 24px rgba(26, 36, 32, 0.08);
  --radius: 14px;
  --radius-sm: 10px;
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(1200px 400px at 10% -10%, #d8f3e4 0%, transparent 50%),
    radial-gradient(800px 300px at 100% 0%, #e8f0ff 0%, transparent 40%),
    var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1, h2, h3 {
  margin: 0;
  line-height: 1.2;
  font-weight: 700;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 800;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.brand:hover {
  text-decoration: none;
  color: var(--primary);
}

.topnav {
  display: flex;
  gap: 12px;
  margin-left: auto;
}

.topnav a {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.92rem;
  text-decoration: none;
  padding: 6px 8px;
  border-radius: 8px;
}

.topnav a.active,
.topnav a:hover {
  color: var(--primary);
  background: var(--primary-soft);
}

.topnav a.muted {
  color: var(--muted);
  font-weight: 500;
}

.user-chip {
  display: none;
  font-size: 0.85rem;
  color: var(--muted);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (min-width: 640px) {
  .user-chip {
    display: block;
  }
}

/* Layout */
.container {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 20px 16px calc(40px + var(--safe-bottom));
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.page-head h1 {
  font-size: 1.7rem;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 999px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, box-shadow 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 14px rgba(26, 122, 76, 0.28);
}

.btn-primary:hover {
  background: var(--primary-dark);
  text-decoration: none;
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: #fff;
  color: var(--text);
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.9rem;
}

.btn-block {
  width: 100%;
}

.icon-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.35rem;
  line-height: 1;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
}

.icon-btn:hover,
.icon-btn.danger:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

/* Forms */
.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
  font: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26, 122, 76, 0.15);
}

textarea {
  resize: vertical;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

/* Alerts */
.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-weight: 600;
  font-size: 0.95rem;
}

.alert-error {
  background: var(--danger-soft);
  color: var(--danger);
}

.alert-success {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

/* Auth */
.auth-page .container {
  display: flex;
  align-items: center;
  min-height: 100vh;
  padding-top: 24px;
  padding-bottom: 24px;
}

.auth-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  padding: 28px 22px;
}

.auth-hero {
  text-align: center;
  margin-bottom: 22px;
}

.auth-emoji {
  font-size: 2.4rem;
  display: block;
  margin-bottom: 8px;
}

.auth-hero h1 {
  font-size: 1.6rem;
  margin-bottom: 6px;
}

.auth-hero p {
  margin: 0;
  color: var(--muted);
}

.auth-footer {
  text-align: center;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-bottom: 18px;
  padding-bottom: 2px;
}

.tabs a {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.9rem;
  text-decoration: none;
  border: 1px solid transparent;
}

.tabs a.active {
  background: var(--primary-soft);
  color: var(--primary-dark);
  border-color: #b7e0c8;
}

.tabs a:hover {
  background: #eef3f0;
  text-decoration: none;
}

/* List cards */
.list-cards {
  display: grid;
  gap: 12px;
}

.list-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 2px 8px rgba(26, 36, 32, 0.04);
  text-decoration: none;
  color: inherit;
  transition: transform 0.1s ease, box-shadow 0.15s ease;
}

.list-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
  text-decoration: none;
}

.list-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.list-card h2 {
  font-size: 1.15rem;
}

.badge {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 8px;
  border-radius: 999px;
  flex-shrink: 0;
}

.badge-active {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.badge-completed {
  background: #eef2ff;
  color: #4338ca;
}

.badge-archived {
  background: #f1f1f1;
  color: #666;
}

.meta {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.meta.muted {
  margin-top: 10px;
  margin-bottom: 0;
  font-size: 0.82rem;
}

.progress-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.progress-row.big {
  margin-top: 12px;
}

.progress {
  flex: 1;
  height: 8px;
  background: #e8eee9;
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #22a06b, #1a7a4c);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.progress-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
  min-width: 3.5rem;
  text-align: right;
}

/* Empty */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.empty-emoji {
  font-size: 2.5rem;
  margin-bottom: 8px;
}

.empty-state h2 {
  margin-bottom: 6px;
}

.empty-state p {
  color: var(--muted);
  margin: 0 0 18px;
}

.empty-inline {
  color: var(--muted);
  padding: 16px;
  text-align: center;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
}

/* List page */
.list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.back-link {
  font-weight: 700;
  color: var(--muted);
  text-decoration: none;
}

.back-link:hover {
  color: var(--primary);
}

.list-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  position: relative;
}

.list-hero {
  margin-bottom: 18px;
}

.list-hero h1 {
  font-size: 1.65rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 2px 8px rgba(26, 36, 32, 0.04);
}

.add-panel {
  margin-bottom: 22px;
  position: sticky;
  top: 56px;
  z-index: 30;
}

.add-row {
  display: flex;
  gap: 8px;
}

.add-row input[type="text"] {
  flex: 1;
  font-size: 1.05rem;
  padding: 14px 14px;
}

.add-row .btn {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  font-size: 1.5rem;
  padding: 0;
  flex-shrink: 0;
}

.add-extras {
  display: grid;
  grid-template-columns: 80px 1fr 1.4fr;
  gap: 8px;
  margin-top: 10px;
}

.add-extras input,
.add-extras select {
  padding: 10px 12px;
  font-size: 0.92rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
  align-items: center;
}

.chips-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  margin-right: 2px;
}

.chip {
  border: 1px solid var(--border);
  background: #f8fbf9;
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.chip:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
}

/* Items */
.section-title {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title .count {
  background: #e8eee9;
  color: var(--text);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.8rem;
  letter-spacing: 0;
  text-transform: none;
}

.cat-group {
  margin-bottom: 14px;
}

.cat-heading {
  font-size: 0.88rem;
  color: var(--muted);
  margin: 0 0 6px 4px;
  font-weight: 700;
}

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.item-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 8px 8px 6px;
  transition: background 0.15s, opacity 0.15s, transform 0.12s;
  min-height: 56px; /* fat finger friendly */
}

.item-row.is-checked {
  opacity: 0.62;
  background: #f7faf8;
}

.item-row.is-checked .item-name {
  text-decoration: line-through;
  color: var(--muted);
}

.item-row.just-toggled {
  transform: scale(0.98);
  background: var(--primary-soft);
}

.check-btn {
  border: none;
  background: transparent;
  padding: 4px;
  cursor: pointer;
  flex-shrink: 0;
}

.check-circle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  color: #fff;
  font-weight: 800;
  font-size: 0.95rem;
  background: transparent;
  transition: background 0.12s, border-color 0.12s;
}

.item-row.is-checked .check-circle {
  background: var(--primary);
  border-color: var(--primary);
}

.item-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.item-name {
  font-weight: 700;
  font-size: 1.02rem;
  word-break: break-word;
}

.item-meta {
  font-size: 0.85rem;
  color: var(--muted);
}

.item-qty {
  font-weight: 600;
}

.checked-section {
  margin-top: 28px;
  opacity: 0.95;
}

/* Menu */
.menu {
  position: relative;
}

.menu-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  min-width: 190px;
  padding: 6px;
  z-index: 50;
}

.menu-dropdown form {
  margin: 0;
}

.menu-dropdown button {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 10px 12px;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.menu-dropdown button:hover {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.menu-dropdown button.danger {
  color: var(--danger);
}

.menu-dropdown button.danger:hover {
  background: var(--danger-soft);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 26, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal {
  background: #fff;
  width: min(440px, 100%);
  border-radius: 18px 18px 14px 14px;
  padding: 20px;
  box-shadow: var(--shadow);
  max-height: 90vh;
  overflow: auto;
}

.modal h2 {
  margin-bottom: 14px;
  font-size: 1.2rem;
}

@media (min-width: 560px) {
  .modal-backdrop {
    align-items: center;
  }
  .modal {
    border-radius: 18px;
  }
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--safe-bottom));
  transform: translateX(-50%);
  background: #1a2420;
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
  z-index: 200;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}
