:root {
  --bg:        #F5F3EF;
  --surface:   #FFFFFF;
  --border:    #E4E0D8;
  --text:      #1C1B18;
  --muted:     #7A7670;
  --hint:      #B0ACA4;
  --accent:    #2A6640;
  --accent-lt: #E6F2EB;
  --accent-dk: #1A4228;
  --danger:    #C03030;
  --warn-bg:   #FEF5DF;
  --warn-tx:   #7A5200;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
}


/* ── Login ── */

#login-screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 32px 24px max(32px, env(safe-area-inset-bottom));
}

.login-icon  { font-size: 56px; margin-bottom: 16px; }
.login-title { font-size: 28px; font-weight: 700; letter-spacing: -.5px; margin-bottom: 6px; }
.login-sub   { font-size: 16px; color: var(--muted); margin-bottom: 36px; text-align: center; }
.login-box   { width: 100%; max-width: 360px; }
.login-lbl   { font-size: 14px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }

.login-input {
  width: 100%;
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  font-size: 17px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  outline: none;
  -webkit-appearance: none;
}
.login-input:focus { border-color: var(--accent); }
.login-input::placeholder { color: var(--hint); }

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

.pwd-toggle {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 12px;
  width: 52px; height: 52px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; cursor: pointer; color: var(--muted);
  flex-shrink: 0;
}

.login-error {
  margin-top: 10px;
  font-size: 14px;
  color: var(--danger);
  text-align: center;
  min-height: 20px;
}

.login-btn {
  margin-top: 16px;
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 20px;
  font-size: 19px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
.login-btn:active   { opacity: .85; }
.login-btn:disabled { opacity: .5; }


/* ── App shell ── */

#app { display: none; }

#offline-bar {
  display: none;
  background: var(--danger);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
}
#offline-bar.show { display: block; }


/* ── Header ── */

#hdr {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px 0;
  padding-top: max(14px, env(safe-area-inset-top));
}

.hdr-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.app-title  { font-size: 24px; font-weight: 700; letter-spacing: -.5px; }
.hdr-right  { display: flex; align-items: center; gap: 10px; }

.sync-pill {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--muted);
}

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--hint); flex-shrink: 0; }
.dot.live { background: #2E8B4E; animation: blink 2.5s infinite; }
.dot.err  { background: var(--danger); }

@keyframes blink { 0%,100%{ opacity:1 } 50%{ opacity:.3 } }

.logout-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
}


/* ── Store tabs ── */

.tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 12px; }
.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex-shrink: 0;
  border: 1.5px solid var(--border);
  background: transparent;
  border-radius: 22px;
  padding: 9px 18px;
  font-size: 15px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
}
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }


/* ── Scroll area ── */

#scroll {
  position: fixed;
  top: var(--hdr-h, 120px);
  left: 0; right: 0; bottom: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#content { padding: 16px 14px 120px; max-width: 540px; margin: 0 auto; }


/* ── Stats bar ── */

.stats-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
}

.stats-txt   { font-size: 15px; color: var(--muted); }
.stats-txt b { color: var(--text); }

.clear-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
}
.clear-btn:active { background: #FAEAEA; color: var(--danger); border-color: var(--danger); }


/* ── Items ── */

.section-lbl {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--hint);
  margin: 20px 0 8px 4px;
}

.items-list { display: flex; flex-direction: column; gap: 6px; }

.item-wrap {
  position: relative;
  overflow: hidden;
  border-radius: 10px;
}

.del-bg {
  position: absolute; right: 0; top: 0; bottom: 0; width: 80px;
  background: var(--danger);
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px;
  pointer-events: none;
}

.item {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 14px;
  display: flex; align-items: center; gap: 14px;
  transition: transform .2s ease, opacity .2s;
  touch-action: pan-y;
  user-select: none;
}
.item.swiping { transition: none; }
.item.bought  { opacity: .45; background: var(--bg); }

.chk {
  width: 48px; height: 48px;
  border-radius: 50%;
  border: 2.5px solid var(--border);
  background: transparent;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  cursor: pointer;
  font-family: inherit;
}
.chk:active { transform: scale(.88); }
.item.bought .chk { background: var(--accent); border-color: var(--accent); color: #fff; }

.item-body { flex: 1; min-width: 0; }

.item-name { font-size: 19px; font-weight: 500; }
.item.bought .item-name { text-decoration: line-through; color: var(--muted); }

.item-tags { display: flex; gap: 5px; margin-top: 5px; flex-wrap: wrap; align-items: center; }

.tag       { font-size: 13px; padding: 3px 9px; border-radius: 5px; font-weight: 500; }
.tag-store { background: var(--accent-lt); color: var(--accent-dk); }
.tag-cat   { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }

.cat-pick {
  background: var(--warn-bg);
  color: var(--warn-tx);
  border: none;
  border-radius: 5px;
  padding: 3px 9px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.item-qty { font-size: 16px; color: var(--muted); font-weight: 600; flex-shrink: 0; }


/* ── Empty state ── */

.empty      { text-align: center; padding: 50px 24px; color: var(--hint); }
.empty-icon { font-size: 54px; margin-bottom: 12px; }
.empty-text { font-size: 18px; }
.empty-sub  { font-size: 15px; margin-top: 6px; }

.loading { text-align: center; padding: 40px; color: var(--hint); font-size: 17px; }


/* ── FAB ── */

#fab {
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom));
  right: 20px;
  width: 64px; height: 64px;
  background: var(--accent);
  color: #fff;
  font-size: 34px; line-height: 1;
  border: none; border-radius: 50%;
  box-shadow: 0 4px 18px rgba(42,102,64,.45);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  z-index: 90;
}
#fab:active { transform: scale(.91); }


/* ── Bottom sheet ── */

#sheet-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 150;
  align-items: flex-end;
}
#sheet-overlay.open { display: flex; }

#sheet {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 0 16px max(20px, env(safe-area-inset-bottom));
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
}
#sheet-overlay.open #sheet { transform: translateY(0); }

.sheet-handle {
  width: 40px; height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 12px auto 18px;
}

.sheet-title { font-size: 21px; font-weight: 700; margin-bottom: 18px; }

.field-label { font-size: 14px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.field-group { margin-bottom: 16px; }

#cat-hint { color: var(--accent); font-size: 12px; font-weight: 600; }

input[type=text] {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 15px 16px;
  font-size: 17px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  outline: none;
  -webkit-appearance: none;
}
input[type=text]:focus { border-color: var(--accent); }
input[type=text]::placeholder { color: var(--hint); }

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 4px; }
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0;
  border: 1.5px solid var(--border);
  background: transparent;
  border-radius: 22px;
  padding: 10px 18px;
  font-size: 15px;
  font-family: inherit;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.chip.sel { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.sheet-btn {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 18px;
  font-size: 18px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  margin-top: 4px;
}
.sheet-btn:active   { opacity: .85; }
.sheet-btn:disabled { opacity: .5; }
