/* Grocery Decoder — "a calm daytime shopping companion".
   Deliberately light-committed: predictable in a bright store, native on iOS.
   Type is the platform's own stack (SF / SF Arabic) — renders the Arabic
   beautifully with no web-font loading. */

:root {
  --accent: #2e7d32;
  --accent-strong: #1b5e20;
  --accent-tint: #e7f1e8;
  --bg: #f4f6f1;          /* warm, faintly green off-white */
  --card: #ffffff;
  --ink: #1b211c;         /* near-black, green bias */
  --muted: #667065;       /* sage grey */
  --faint: #97a096;
  --line: #e4e8df;
  --line-strong: #cfd6c9;
  --danger: #b3261e;
  --radius: 16px;
  --radius-sm: 11px;
  --shadow: 0 1px 2px rgba(27, 40, 28, .05), 0 4px 14px rgba(27, 40, 28, .05);
  --tap: 48px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "Noto Sans", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { color-scheme: light; }

body {
  margin: 0;
  padding: 1rem 1rem 4rem;
  max-width: 560px;
  margin-inline: auto;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---- header ---- */
header {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .35rem .1rem 1rem;
}
header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -.02em;
}

/* ---- buttons ---- */
button {
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  border: 0;
  border-radius: 999px;
  padding: .78rem 1.15rem;
  min-height: var(--tap);
  color: #fff;
  background: var(--accent);
  transition: filter .15s ease, transform .06s ease, background .15s ease;
}
button:hover { filter: brightness(1.05); }
button:active { transform: scale(.975); }
button:disabled { opacity: .45; cursor: default; filter: none; transform: none; }
button.secondary {
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
button.secondary:hover { background: #fbfcfa; filter: none; }

.row { display: flex; gap: .6rem; margin: .5rem 0; }
.row button { flex: 1; }

/* ---- inputs ---- */
textarea,
.add-row input,
.item .edit-ar,
.item .edit-cat,
input#pin-input {
  font: inherit;
  width: 100%;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: .8rem .9rem;
}
textarea {
  min-height: 8.5rem;
  font-size: 1.05rem;
  resize: vertical;
  box-shadow: var(--shadow);
}
textarea::placeholder,
.add-row input::placeholder { color: var(--faint); }
:focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 1px;
}
textarea:focus,
.add-row input:focus,
.edit-ar:focus,
.edit-cat:focus,
#pin-input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-tint); }

/* ---- PIN gate ---- */
#pin-view {
  max-width: 320px;
  margin: 3.5rem auto 0;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.75rem 1.5rem;
}
#pin-view p { color: var(--muted); margin: 0 0 .9rem; font-weight: 600; }
input#pin-input {
  text-align: center;
  font-size: 1.5rem;
  letter-spacing: .35em;
  padding-inline: .5rem;
  max-width: 11rem;
  margin: 0 auto .8rem;
}
#pin-save { width: 100%; }
#pin-error { margin: .75rem 0 0; }

/* ---- decode / list toolbars ---- */
.list-date {
  margin: .35rem .15rem .85rem;
  color: var(--muted);
  font-size: .9rem;
  font-weight: 650;
}
.list-date:empty { display: none; }

#to-list-btn { width: 100%; margin-top: .5rem; }

.add-row { display: flex; gap: .55rem; margin: .3rem 0 1rem; }
.add-row input { flex: 1; font-size: 1.05rem; }
.add-row button { flex: 0 0 auto; }

/* ---- checklist ---- */
#checklist, #history-list { list-style: none; padding: 0; margin: 0; }

.cat-header {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin: 1.15rem .1rem .5rem;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--accent);
}
.cat-header::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.item {
  display: flex;
  align-items: center;
  gap: .8rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: .8rem .85rem;
  margin-bottom: .5rem;
}
.item.checked { background: #f7faf6; border-color: var(--line); }
.item.checked .labels { opacity: .55; }
.item.checked .ar,
.item.checked .en-name { text-decoration: line-through; }

/* custom checkbox */
.item > input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  margin: 0;
  border: 2px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  display: grid;
  place-content: center;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.item > input[type="checkbox"]::before {
  content: "";
  width: 15px;
  height: 15px;
  transform: scale(0);
  transition: transform .12s ease;
  background: #fff;
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}
.item > input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.item > input[type="checkbox"]:checked::before { transform: scale(1); }

.labels { flex: 1; min-width: 0; }
.ar { font-size: 1.3rem; font-weight: 700; line-height: 1.25; }
.en {
  margin-top: .12rem;
  color: var(--muted);
  font-size: .92rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .35rem;
}
.src { color: var(--faint); }
.note {
  background: var(--accent-tint);
  color: var(--accent-strong);
  font-weight: 700;
  font-size: .76rem;
  padding: .08rem .45rem;
  border-radius: 6px;
  white-space: nowrap;
}

.item .edit {
  flex: 0 0 auto;
  min-height: auto;
  padding: .4rem .55rem;
  font-size: 1.15rem;
  background: transparent;
  color: var(--faint);
  border-radius: 9px;
  box-shadow: none;
}
.item .edit:hover { background: var(--accent-tint); color: var(--accent); filter: none; }

/* ---- inline edit ---- */
.item.editing { flex-wrap: wrap; align-items: stretch; }
.item.editing .labels { flex: 1 1 100%; }
.item .edit-ar { font-size: 1.2rem; margin: .1rem 0; }
.item .edit-cat { margin: .35rem 0 .1rem; font-size: 1rem; }
.item .edit-hint { color: var(--faint); font-size: .78rem; margin: .15rem 0; }
.item .save, .item .cancel { flex: 0 0 auto; min-height: 42px; padding: .5rem 1.1rem; margin-top: .5rem; }

/* ---- history rows are simple cards ---- */
#history-list .item { cursor: pointer; }
#history-list .ar { font-size: 1.05rem; font-weight: 650; }

/* ---- spinner ---- */
#spinner {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(244, 246, 241, .8);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  font-weight: 700;
  color: var(--accent-strong);
}

.error { color: var(--danger); font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
