[hidden] { display: none !important; }

:root {
  --bg: #f3f7f4;
  --bg2: #e9f3ee;
  --card: #ffffff;
  --card-soft: #f4f8f6;
  --text: #1f2a37;
  --muted: #6b7885;           /* AA contrast on white */
  --line: #e2e9e5;
  --primary: #2fa571;
  --primary-dark: #248a5c;
  --accent: #e8851f;
  --danger: #e04848;
  --star: #f5b301;
  --radius: 18px;
  --shadow: 0 6px 20px rgba(31, 42, 55, 0.08);
  --shadow-sm: 0 1px 4px rgba(31, 42, 55, 0.08);
  --header-h: 190px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101614; --bg2: #0c1210; --card: #1a2321; --card-soft: #222d2a;
    --text: #e8efec; --muted: #9aa8a2; --line: #2b3834;
    --primary: #3fb27f; --primary-dark: #2f9667; --accent: #ffa24a;
    --shadow: 0 6px 20px rgba(0, 0, 0, .45); --shadow-sm: 0 1px 4px rgba(0, 0, 0, .4);
  }
  img[data-asset] { filter: brightness(.95); }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; overflow-x: hidden; min-height: 100%;
  color: var(--text);
  font-family: "Inter", "Roboto", system-ui, -apple-system, Arial, sans-serif;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%) fixed;
}
button, input { font-family: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 55%, transparent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ===================== ENTRY ===================== */
#view-entry .main-content {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 24px 18px;
}
.container {
  position: relative; width: 100%; max-width: 400px; padding: 34px 26px 28px;
  background: var(--card); border-radius: 24px; box-shadow: var(--shadow);
  text-align: center; margin-bottom: 22px;
}
.container::before { content: "🛒"; display: block; font-size: 44px; margin-bottom: 6px; }
.label { display: block; font-size: 1.1em; font-weight: 700; margin-bottom: 12px; }
.input-field {
  width: 100%; padding: 14px 16px; border: 2px solid var(--line); border-radius: 14px;
  font-size: 16px; outline: none; background: var(--card-soft); text-align: center;
  transition: border-color .2s, box-shadow .2s;
}
.input-field:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(47, 165, 113, .18); }
.button {
  margin-top: 16px; width: 100%; min-height: 48px; padding: 14px 20px; font-size: 1em; font-weight: 700;
  letter-spacing: .06em; border: none; border-radius: 14px; color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  box-shadow: 0 6px 14px rgba(47, 165, 113, .35); transition: transform .1s;
}
.button:active { transform: scale(.97); }
.shopping-card { display: block; margin: 0 auto; width: 84px; height: auto; padding: 10px; background: #fff; border-radius: 16px; box-shadow: var(--shadow-sm); }
.file-input { margin: 8px 15px; display: block; font-size: 14px; max-width: calc(100% - 30px); }

.corner-btn {
  position: absolute; top: 8px; right: 8px; width: 44px; height: 44px; padding: 0;
  display: grid; place-items: center; background: none; border: none; border-radius: 50%;
}
.corner-btn img { width: 22px; height: auto; opacity: .75; transition: transform .1s, opacity .2s; }
.corner-btn:hover img { opacity: 1; }
.corner-btn:active img { transform: scale(.82); }

/* ===================== LIST: HEADER ===================== */
.top-fixed {
  position: fixed; top: 0; left: 0; width: 100%; z-index: 1000;
  padding: calc(8px + var(--safe-t)) 12px 4px;
  background: linear-gradient(180deg, var(--bg) 82%, transparent);
}
.head-card { max-width: 640px; margin: 0 auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 12px 12px 16px; }
.head-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.head-title { min-width: 0; display: flex; flex-direction: column; }
.head-label { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.head-name { margin: 0; color: var(--accent); font-size: 20px; font-weight: 800; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.head-count { color: var(--muted); font-size: 12.5px; font-weight: 600; margin-top: 1px; min-height: 1em; }
.head-actions { display: flex; gap: 4px; flex-shrink: 0; margin-top: -2px; }
.round-btn {
  width: 44px; height: 44px; display: grid; place-items: center; padding: 0;
  background: none; border: none; border-radius: 50%; transition: background .2s, transform .1s;
}
.round-btn:hover { background: var(--card-soft); }
.round-btn:active { transform: scale(.88); }
.round-btn .material-icons { font-size: 26px; color: var(--muted); }

.add-form { display: flex; flex-direction: column; gap: 8px; padding-right: 4px; }
.add-row { display: flex; gap: 8px; align-items: center; }
.add-form input {
  min-height: 44px; padding: 8px 12px; font-size: 16px;  /* 16px avoids iOS zoom on focus */
  border: 2px solid var(--line); border-radius: 12px; background: var(--card-soft); outline: none;
  transition: border-color .2s, box-shadow .2s, background .2s;
}
.add-form input::placeholder { color: var(--muted); opacity: .8; }
.add-form input:focus { border-color: var(--primary); background: var(--card); box-shadow: 0 0 0 4px rgba(47, 165, 113, .15); }
#itemName { flex: 1; min-width: 0; }
#itemQuantity { width: 72px; flex-shrink: 0; text-align: center; }
#itemNotes { width: 100%; font-size: 15px; }
.add-btn {
  width: 48px; height: 48px; flex-shrink: 0; display: grid; place-items: center; padding: 0; border: none; border-radius: 50%;
  color: #fff; background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  box-shadow: 0 4px 10px rgba(47, 165, 113, .4); transition: transform .1s;
}
.add-btn:active { transform: scale(.88); }
.add-btn.editing { background: linear-gradient(135deg, #f5a623, var(--accent)); box-shadow: 0 4px 10px rgba(232, 133, 31, .4); }
.add-btn .material-icons { font-size: 28px; }
.form-hint { margin: 0; font-size: 12.5px; color: var(--accent); font-weight: 600; }

/* ===================== LIST: BODY ===================== */
.content {
  max-width: 640px; margin: 0 auto;
  padding: calc(var(--header-h) + 2px) 12px calc(86px + var(--safe-b));
}
.content ul { list-style: none; padding: 0; margin: 0; }

.item {
  background: var(--card); border-radius: 12px; margin-bottom: 9px; box-shadow: var(--shadow-sm);
  overflow: hidden; animation: pop .25s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.item-main { display: flex; align-items: center; min-height: 38px; }
.item.is-important { box-shadow: inset 4px 0 0 var(--star), var(--shadow-sm); }

.check {
  flex-shrink: 0; width: 42px; height: 38px; display: grid; place-items: center;
  background: none; border: none; padding: 0;
}
.check .material-icons {
  width: 24px; height: 24px; display: grid; place-items: center; font-size: 16px; color: transparent;
  border: 2px solid #b4c0ba; border-radius: 50%; transition: background .15s, border-color .15s, color .15s, transform .1s;
}
.check:active .material-icons { transform: scale(.85); }
.is-done .check .material-icons { background: var(--primary); border-color: var(--primary); color: #fff; }

.item-body {
  flex: 1; min-width: 0; align-self: stretch; display: flex; flex-direction: column; justify-content: center; gap: 1px;
  background: none; border: none; text-align: left; padding: 2px 10px 2px 0;
}
.item-name { font-size: 15px; font-weight: 600; line-height: 1.25; word-break: break-word; }
.item-meta { font-size: 12.5px; line-height: 1.25; color: var(--muted); font-weight: 500; word-break: break-word; }
.star { color: var(--star); font-size: 18px; margin-right: 10px; }
.is-done .item-name { color: var(--muted); text-decoration: line-through; opacity: .7; }
.is-done .item-meta { opacity: .6; }

.item-actions {
  display: flex; gap: 6px; padding: 0 8px 8px; animation: pop .18s ease;
}
.act {
  flex: 1; min-height: 40px; display: flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 14px; font-weight: 600; border: none; border-radius: 12px;
  background: var(--card-soft); color: var(--text); transition: background .15s, transform .1s;
}
.act:active { transform: scale(.96); }
.act .material-icons { font-size: 20px; color: var(--muted); }
.act-imp .material-icons { color: var(--star); }
.act-del { color: var(--danger); }
.act-del .material-icons { color: var(--danger); }

/* empty / error states */
.state { text-align: center; color: var(--muted); padding: 56px 24px 0; }
.state-emoji { font-size: 56px; line-height: 1; margin-bottom: 10px; }
.state p { margin: 0 0 4px; color: var(--text); font-weight: 700; font-size: 17px; }
.state small { font-size: 14px; }
.retry {
  display: block; margin: 16px auto 0; min-height: 44px; padding: 0 22px; border: none; border-radius: 999px;
  font-weight: 700; color: #fff; background: var(--primary);
}

/* ===================== FOOTER ===================== */
.fixed-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 10px; height: 56px; position: fixed; bottom: calc(10px + var(--safe-b)); left: 12px; right: 12px;
  max-width: 616px; margin: 0 auto; z-index: 999;
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(8px);
  border-radius: 999px; box-shadow: var(--shadow);
}
.footer-left, .footer-right { display: flex; align-items: center; min-width: 0; }
.footer-center { position: absolute; left: 50%; transform: translateX(-50%); display: flex; }
.foot-btn { width: 44px; height: 44px; display: grid; place-items: center; padding: 0; background: none; border: none; border-radius: 50%; transition: transform .15s; }
.foot-btn:active { transform: scale(.86); }
.foot-btn .material-icons { font-size: 26px; color: var(--muted); transition: color .2s; }
.foot-btn:hover .material-icons { color: var(--primary); }
#btn-entry { width: 48px; height: 48px; background: var(--primary); box-shadow: 0 4px 10px rgba(47, 165, 113, .4); }
#btn-entry .material-icons { color: #fff; }
/* "chatting as" bar, at the top of the chat panel (keeps the footer clean) */
.chat-head {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px;
  border-bottom: 1px solid var(--line); font-size: 13px; color: var(--muted); font-weight: 600;
}
.user-tag {
  min-height: 30px; font-size: 13px; font-weight: 700; border: none;
  background: var(--card-soft); color: var(--primary-dark); padding: 4px 12px; border-radius: 999px;
}
.user-tag-input {
  width: 72px; min-height: 30px; border: 2px solid var(--primary); outline: none;
  background: var(--card); border-radius: 999px; padding: 2px 10px; font-size: 16px;
}

/* ===================== SIDEBAR ===================== */
.sidebar {
  position: fixed; top: 0; left: -290px; width: 280px; max-width: 86vw; height: 100%;
  background: var(--card); box-shadow: 4px 0 24px rgba(0, 0, 0, 0.18);
  border-radius: 0 var(--radius) var(--radius) 0; padding-top: var(--safe-t);
  transition: left .3s ease, visibility .3s; visibility: hidden; z-index: 2000;
}
.sidebar.sidebar-open { left: 0; visibility: visible; }
.side-label { margin: 22px 16px 14px; font-weight: 700; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.sidebar ul { padding: 0 12px; margin: 0; list-style: none; }
.side-list {
  margin-bottom: 8px; padding: 0 12px; min-height: 48px; background: var(--card-soft); border-radius: 12px;
  display: flex; align-items: center; cursor: pointer; font-weight: 600;
  transition: background .2s, transform .1s;
}
.side-list:active { transform: scale(.98); }
.side-list span { flex: 1; padding: 12px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-list img { padding: 14px; box-sizing: content-box; }

/* ===================== CHAT ===================== */
.chat-panel {
  position: fixed; bottom: calc(76px + var(--safe-b)); left: 12px; right: 12px; max-width: 616px; margin: 0 auto; height: 0;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
  transition: height .3s ease; z-index: 1500; display: flex; flex-direction: column;
}
.chat-panel.open { height: 260px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 12px; font-size: 14px; display: flex; flex-direction: column; gap: 6px; }
.chat-msg { max-width: 80%; padding: 8px 12px; border-radius: 14px; word-wrap: break-word; display: inline-flex; box-shadow: var(--shadow-sm); }
.msg-me { align-self: flex-end; background: #d8f5e4; color: #14372a; border-bottom-right-radius: 4px; }
.msg-other { align-self: flex-start; background: var(--card-soft); border-bottom-left-radius: 4px; }
#codes-list { margin: 0; padding: 0 12px; list-style: none; font-size: 13px; }
.chat-input-area { display: flex; gap: 8px; padding: 8px; border-top: 1px solid var(--line); }
.chat-input-area input { flex: 1; min-height: 44px; border: 2px solid var(--line); border-radius: 999px; padding: 8px 16px; font-size: 16px; outline: none; background: var(--card-soft); }
.chat-input-area input:focus { border-color: var(--primary); }
.chat-input-area button { min-height: 44px; border: none; background: var(--primary); color: #fff; padding: 0 20px; border-radius: 999px; font-weight: 700; }
.chat-toggle-btn.blink { animation: blinkOrange 1s infinite; }
@keyframes blinkOrange {
  0%   { box-shadow: 0 0 0 0 rgba(255, 159, 67, .75); }
  70%  { box-shadow: 0 0 0 10px rgba(255, 159, 67, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 159, 67, 0); }
}

/* ===================== POPUPS ===================== */
.popup, .simple-popup .pop, .dup-popup .pop {
  background: var(--card); border-radius: 20px; text-align: center; font-weight: 600;
  box-shadow: 0 0 0 100vmax rgba(8, 14, 12, .45), 0 12px 40px rgba(0, 0, 0, .3);   /* dims the page */
}
.simple-popup .pop { box-shadow: 0 12px 40px rgba(0, 0, 0, .3); }
.popup {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  padding: 28px 30px 22px; z-index: 3000; width: min(320px, 90vw);
}
.popup p { margin: 0; font-size: 17px; }
.popup .close-button { position: absolute; top: 4px; right: 4px; width: 44px; height: 44px; background: none; border: none; display: grid; place-items: center; }
.close-icon-image { width: 16px; height: 16px; cursor: pointer; }
.button-container { margin-top: 16px; }
.yes-button { width: 100%; min-height: 46px; background: var(--danger); color: #fff; border: none; padding: 0 18px; border-radius: 12px; font-weight: 700; box-shadow: 0 6px 14px rgba(224, 72, 72, .3); }
.yes-button:active { transform: scale(.97); }

.simple-popup, .dup-popup { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 3000; display: none; }
.simple-popup.show, .dup-popup.show { display: block; animation: pop .2s ease; }
.simple-popup { top: auto; bottom: calc(86px + var(--safe-b)); transform: translateX(-50%); }
.simple-popup .pop { padding: 12px 22px; font-size: 14px; }
.simple-popup .pop p { margin: 0; }
.dup-popup .pop { position: relative; padding: 30px 26px 24px; width: min(340px, 90vw); }
.dup-popup .pop p { margin: 0 0 12px; font-size: 16px; }
.dup-popup .close-icon-image { position: absolute; top: 14px; right: 14px; padding: 8px; box-sizing: content-box; }
.dup-popup input { width: 100%; min-height: 44px; margin-bottom: 10px; padding: 8px 12px; font-size: 16px; border: 2px solid var(--line); border-radius: 12px; outline: none; background: var(--card-soft); }
.dup-popup input:focus { border-color: var(--primary); }
.dup-popup button { width: 100%; min-height: 46px; border: none; border-radius: 12px; background: var(--primary); color: #fff; font-weight: 700; }
