/* ===== DESIGN TOKENS ===== */
:root {
  --green-dark:  #1E4D38;
  --green-mid:   #2D6A4F;
  --green-light: #52B788;
  --green-pale:  #D8F3DC;
  --green-xpale: #F0FAF2;
  --white:       #FFFFFF;
  --bg:          #F4F7F5;
  --card:        #FFFFFF;
  --border:      #E2EAE5;
  --text-dark:   #1A2E22;
  --text-mid:    #4A6558;
  --text-light:  #8AA898;
  --danger:      #DC2626;
  --danger-pale: #FEE2E2;
  --checked-bg:  #F8FAF8;
  --shadow:      0 2px 8px rgba(0,0,0,.08);
  --shadow-lg:   0 8px 24px rgba(0,0,0,.12);
  --radius:      14px;
  --radius-sm:   8px;
  --bar-h:       64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text-dark);
  min-height: 100dvh;
  overscroll-behavior: none;
}
button { cursor: pointer; font-family: inherit; border: none; background: none; }
input  { font-family: inherit; }
a      { color: inherit; text-decoration: none; }

/* ===== LAYOUT ===== */
.screen {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
}

/* ===== APP BAR ===== */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--green-mid);
  color: var(--white);
  padding: 0 16px;
  height: var(--bar-h);
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  padding-top: env(safe-area-inset-top, 0px);
}
.app-bar .bar-title {
  flex: 1;
  font-size: 1.15rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-bar .bar-sub {
  font-size: .75rem;
  opacity: .75;
  font-weight: 400;
}
.icon-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--white);
  flex-shrink: 0;
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active { background: rgba(255,255,255,.2); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ===== CONTENT ===== */
.content {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
  overflow-y: auto;
}

/* ===== AUTH SCREEN ===== */
.auth-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px 20px;
  background: linear-gradient(160deg, var(--green-pale) 0%, var(--bg) 50%);
}
.auth-logo {
  margin-bottom: 32px;
  text-align: center;
}
.auth-logo .logo-icon {
  width: 72px;
  height: 72px;
  background: var(--green-mid);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  box-shadow: var(--shadow-lg);
}
.auth-logo .logo-icon svg { width: 40px; height: 40px; stroke: white; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.auth-logo h1 { font-size: 1.6rem; font-weight: 800; color: var(--green-dark); }
.auth-logo p  { font-size: .9rem; color: var(--text-mid); margin-top: 4px; }

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: var(--shadow-lg);
}
.auth-tabs {
  display: flex;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 24px;
}
.auth-tab {
  flex: 1;
  padding: 10px;
  border-radius: calc(var(--radius-sm) - 2px);
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-mid);
  text-align: center;
  transition: all .2s;
}
.auth-tab.active {
  background: var(--white);
  color: var(--green-dark);
  box-shadow: 0 1px 4px rgba(0,0,0,.1);
}

/* ===== FORMS ===== */
.field {
  margin-bottom: 16px;
}
.field label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-mid);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.field input {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  color: var(--text-dark);
  background: var(--white);
  transition: border-color .2s;
  -webkit-appearance: none;
}
.field input:focus {
  outline: none;
  border-color: var(--green-light);
  box-shadow: 0 0 0 3px rgba(82,183,136,.15);
}
.field input::placeholder { color: var(--text-light); }

.field-error {
  font-size: .8rem;
  color: var(--danger);
  margin-top: 6px;
}

/* ===== BUTTONS ===== */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 15px 20px;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 700;
  transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary {
  background: var(--green-mid);
  color: var(--white);
}
.btn-primary:active { background: var(--green-dark); transform: scale(.98); }
.btn-primary:disabled { opacity: .6; }
.btn-danger  { background: var(--danger); color: var(--white); }
.btn-danger:active { background: #B91C1C; }
.btn-ghost   { background: transparent; color: var(--text-mid); border: 1.5px solid var(--border); }
.btn-ghost:active { background: var(--bg); }

/* ===== LISTS SCREEN ===== */
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.list-header h2 { font-size: 1.1rem; font-weight: 700; color: var(--text-dark); }
.list-header .count { font-size: .8rem; color: var(--text-light); font-weight: 400; }

.fab {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  right: 20px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--green-mid);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(45,106,79,.4);
  z-index: 50;
  -webkit-tap-highlight-color: transparent;
  transition: transform .15s, box-shadow .15s;
}
.fab:active { transform: scale(.92); box-shadow: 0 2px 8px rgba(45,106,79,.4); }
.fab svg { width: 28px; height: 28px; stroke: white; fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }

/* ===== LIST CARDS ===== */
.list-cards { display: flex; flex-direction: column; gap: 10px; }

.list-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 16px 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform .15s, box-shadow .15s;
  border-left: 4px solid var(--green-light);
}
.list-card:active { transform: scale(.98); box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.list-card.shared { border-left-color: #F59E0B; }

.card-info { flex: 1; min-width: 0; }
.card-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-meta { font-size: .8rem; color: var(--text-light); margin-top: 3px; }
.card-meta strong { color: var(--green-mid); }

.card-badge {
  background: var(--green-pale);
  color: var(--green-dark);
  font-size: .85rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  flex-shrink: 0;
}
.card-badge.zero { background: var(--bg); color: var(--text-light); }

.card-del {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--text-light);
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.card-del:active { background: var(--danger-pale); color: var(--danger); }
.card-del svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ===== EMPTY STATE ===== */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 20px;
  color: var(--text-light);
  text-align: center;
}
.empty svg { width: 64px; height: 64px; stroke: var(--border); fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.empty p { font-size: .95rem; }

/* ===== LIST DETAIL ===== */
.items-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  padding-bottom: calc(80px + var(--safe-bottom));
}

.section-label {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-light);
  padding: 12px 4px 6px;
}

/* ===== ITEM ROW ===== */
.item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 12px 10px 12px 14px;
  margin-bottom: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  transition: opacity .2s;
}
.item-row.checked {
  background: var(--checked-bg);
  opacity: .7;
}

.item-check {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  transition: all .2s;
  -webkit-tap-highlight-color: transparent;
}
.item-check:active { transform: scale(.88); }
.item-check.checked {
  background: var(--green-light);
  border-color: var(--green-light);
}
.item-check svg { width: 16px; height: 16px; stroke: white; fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; display: none; }
.item-check.checked svg { display: block; }

.item-body { flex: 1; min-width: 0; }
.item-name {
  font-size: .98rem;
  font-weight: 500;
  color: var(--text-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-row.checked .item-name {
  text-decoration: line-through;
  color: var(--text-light);
}
.item-qty {
  font-size: .78rem;
  color: var(--text-light);
  margin-top: 2px;
}
.item-qty span {
  background: var(--green-pale);
  color: var(--green-dark);
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 600;
}

.item-del {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--text-light);
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.item-del:active { background: var(--danger-pale); color: var(--danger); }
.item-del svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ===== CLEAR CHECKED BAR ===== */
.clear-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 16px 2px;
}
.clear-btn {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-light);
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--white);
  -webkit-tap-highlight-color: transparent;
}
.clear-btn:active { background: var(--danger-pale); color: var(--danger); border-color: transparent; }

/* ===== ADD ITEM BAR ===== */
.add-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: var(--white);
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  padding-bottom: calc(10px + var(--safe-bottom));
  z-index: 100;
  box-shadow: 0 -4px 16px rgba(0,0,0,.06);
}

.suggestions-box {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
  display: none;
}
.suggestions-box.visible { display: block; }
.suggestion-item {
  padding: 12px 16px;
  font-size: .95rem;
  color: var(--text-dark);
  cursor: pointer;
  border-bottom: 1px solid var(--bg);
  -webkit-tap-highlight-color: transparent;
}
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:active { background: var(--green-pale); }

.add-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.add-row .name-wrap { flex: 1; position: relative; }
.add-row input {
  width: 100%;
  padding: 13px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  color: var(--text-dark);
  background: var(--bg);
  -webkit-appearance: none;
}
.add-row input:focus {
  outline: none;
  border-color: var(--green-light);
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(82,183,136,.15);
}
.add-row input::placeholder { color: var(--text-light); }
.qty-input { width: 76px !important; flex-shrink: 0; }
.add-submit {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--green-mid);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s, transform .15s;
}
.add-submit:active { background: var(--green-dark); transform: scale(.9); }
.add-submit svg { width: 22px; height: 22px; stroke: white; fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }

/* ===== MODALS ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: var(--safe-bottom);
  animation: fadeIn .2s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--white);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px 20px calc(20px + var(--safe-bottom));
  width: 100%;
  max-width: 480px;
  animation: slideUp .25s ease-out;
  max-height: 90dvh;
  overflow-y: auto;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: -8px auto 20px;
}
.modal h2 { font-size: 1.1rem; font-weight: 800; margin-bottom: 20px; }

.member-list { margin: 12px 0 20px; }
.member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--bg);
}
.member-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--green-pale);
  color: var(--green-dark);
  font-weight: 700;
  font-size: .9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.member-name { flex: 1; font-size: .95rem; }
.member-badge { font-size: .72rem; color: var(--text-light); background: var(--bg); padding: 2px 8px; border-radius: 10px; }

.modal-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }

/* ===== FREQUENT SUGGESTIONS ===== */
.freq-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 20px;
}
.freq-chip {
  padding: 8px 14px;
  background: var(--green-pale);
  color: var(--green-dark);
  border-radius: 20px;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid transparent;
  -webkit-tap-highlight-color: transparent;
  transition: all .15s;
}
.freq-chip.selected {
  background: var(--green-mid);
  color: var(--white);
}
.freq-chip:active { transform: scale(.94); }

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-dark);
  color: var(--white);
  padding: 12px 20px;
  border-radius: 24px;
  font-size: .9rem;
  font-weight: 500;
  z-index: 300;
  max-width: calc(100% - 40px);
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: toastIn .25s ease-out;
}
.toast.hidden { display: none; }
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* ===== SPINNER ===== */
.spinner-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--green-light);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== SYNC INDICATOR ===== */
.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green-light);
  opacity: 0;
  transition: opacity .3s;
}
.sync-dot.active {
  opacity: 1;
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: .4; } 50% { opacity: 1; } }

/* ===== DESKTOP ===== */
@media (min-width: 480px) {
  .modal-overlay { align-items: center; padding: 20px; }
  .modal { border-radius: var(--radius); max-height: 85dvh; }
  .add-bar { border-radius: var(--radius) var(--radius) 0 0; }
}
