/*
 * Ugrana styles.
 * Built for older eyes first: large type (everything in rem, so the
 * "Large text" setting scales the whole app), strong contrast, big targets
 * (≥ 48px), and level shown by shape as well as colour.
 */

:root {
  --bg: #f7f3ea;
  --card: #fffdf8;
  --ink: #1f1c16;
  --muted: #6b6356;
  --line: #e4dbc8;
  --brand: #2f5d3a;
  --brand-2: #3e7a4b;
  --brand-ink: #ffffff;
  --accent: #c98a00;

  --full: #2e7d32;
  --half: #a87400;
  --low: #d35400;
  --over: #c0392b;
  --unset: #9a938a;

  --full-bg: #eaf4e9;
  --half-bg: #faf1d9;
  --low-bg: #fde9d8;
  --over-bg: #fbe0dd;

  --radius: 1rem;
  --nav-h: 4.4rem;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --tile-min: 6.4rem;

  font-size: 17px;
}
html.large-text {
  font-size: 20px;
  --tile-min: 7.6rem;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans Kannada", "Noto Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .4rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
p { margin: .4rem 0; }
small { font-size: .8rem; }

.boot { display: grid; place-items: center; min-height: 100vh; font-size: 3rem; }

/* ------------------------------------------------------------ layout */

#app { max-width: 40rem; margin: 0 auto; }
.main { padding: 0 .75rem calc(var(--nav-h) + var(--safe-b) + 5rem); min-height: 100vh; }
.view { padding-top: .5rem; }
.row { display: flex; align-items: center; }
.col { display: flex; flex-direction: column; }
.gap { gap: .6rem; }
.row.gap { margin: .5rem 0; }
.grow { flex: 1 1 auto; min-width: 0; }
.top-gap { margin-top: 1rem !important; }
.center { text-align: center; }
.muted { color: var(--muted); }
.meta { color: var(--muted); font-size: .82rem; }
.lead { font-size: 1.15rem; }
.mono { font-family: ui-monospace, Menlo, monospace; letter-spacing: .1em; text-transform: uppercase; }
.error-txt { color: var(--over); font-weight: 600; min-height: 1.4em; }
.danger-txt { color: var(--over) !important; }
.divider { height: 1px; background: var(--line); margin: 1rem 0; }

.bi { display: inline-flex; flex-direction: column; line-height: 1.25; }
.bi-main { font-weight: 650; }
.bi-sub { font-size: .78em; color: var(--muted); font-weight: 400; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .9rem 1rem;
  margin: .75rem 0;
}
.card.tip { background: #fff8e1; border-color: #f0dca0; }
.card.tip p { margin: .3rem 0 0; }

.section-h {
  display: flex; align-items: center; gap: .3rem;
  margin: 1.2rem .1rem .5rem;
  font-size: 1rem;
}

.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.empty.big { padding-top: 4rem; font-size: 1.2rem; }
.empty-emoji { font-size: 3.5rem; margin-bottom: .5rem; }

/* ------------------------------------------------------------- inputs */

.input {
  width: 100%;
  padding: .75rem .9rem;
  border: 2px solid var(--line);
  border-radius: .8rem;
  background: #fff;
  font-size: 1rem;
  min-height: 3rem;
}
.input:focus { outline: none; border-color: var(--brand-2); }
.input.big { font-size: 1.15rem; min-height: 3.4rem; }
.input + .input { margin-top: .5rem; }
.field-label { display: block; margin: 1rem 0 .35rem; font-size: .95rem; }

.sticky-top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: .6rem 0 .4rem;
  margin: -.5rem 0 0;
}
.input.search { border-radius: 2rem; padding-left: 1.1rem; }

.chips { display: flex; gap: .45rem; padding: .55rem 0 .2rem; }
.chips.scroll { overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; }
.chip {
  flex: 0 0 auto;
  position: relative;
  border: 2px solid var(--line);
  background: var(--card);
  border-radius: 2rem;
  padding: .45rem .9rem;
  min-height: 2.6rem;
  white-space: nowrap;
  font-size: .95rem;
}
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 650; }
.chip-dot {
  position: absolute; top: .15rem; right: .25rem;
  width: .55rem; height: .55rem; border-radius: 50%;
  background: var(--low); border: 2px solid var(--card);
}

.seg { display: flex; gap: .4rem; flex-wrap: wrap; }
.seg-btn, .seg-opt > span {
  display: inline-block;
  border: 2px solid var(--line);
  background: var(--card);
  border-radius: .8rem;
  padding: .6rem .9rem;
  min-height: 3rem;
}
.seg-btn.on, .seg-opt input:checked + span { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 650; }
.seg-opt input { position: absolute; opacity: 0; pointer-events: none; }
.seg-opt { flex: 1; text-align: center; }
.seg-opt > span { width: 100%; }

.toggle { display: flex; align-items: center; gap: .7rem; margin: 1rem 0; }
.toggle input { width: 1.6rem; height: 1.6rem; accent-color: var(--brand); flex: 0 0 auto; }

/* ------------------------------------------------------------ buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 3.2rem;
  padding: .6rem 1.1rem;
  border-radius: .9rem;
  border: 2px solid transparent;
  background: var(--card);
  font-weight: 650;
  text-decoration: none;
  color: var(--ink);
}
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.primary:active { background: var(--brand-2); }
.btn.secondary { background: #fff3cf; border-color: #ecd48a; }
.btn.ghost { border-color: var(--line); }
.btn.link { background: none; color: var(--brand); padding: .4rem .2rem; min-height: 2.6rem; }
.btn.danger { background: var(--over); color: #fff; }
.btn.small { min-height: 2.5rem; padding: .3rem .8rem; font-size: .9rem; }
.btn.wide { display: flex; width: 100%; margin: .5rem 0; }
.btn.big { min-height: 3.6rem; font-size: 1.15rem; }
.btn.huge { min-height: 4.4rem; font-size: 1.4rem; }
.btn.mic { flex: 0 0 3.4rem; min-height: 3.4rem; font-size: 1.4rem; padding: 0; border-color: var(--line); }
.btn.mic.listening { background: var(--over); border-color: var(--over); animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }
.btn:disabled { opacity: .5; }

/* -------------------------------------------------------------- icons */

.icon { display: inline-grid; place-items: center; flex: 0 0 auto; line-height: 1; }
.icon-sm { width: 2.4rem; height: 2.4rem; font-size: 1.6rem; }
.icon-md { width: 3rem; height: 3rem; font-size: 2.1rem; }
.icon-lg { width: 4.6rem; height: 4.6rem; font-size: 3.4rem; }
.icon.photo { object-fit: cover; border-radius: .6rem; background: #fff; }

/* Fuel gauge: three bars, filled from the left. */
.lvbar { display: inline-flex; gap: 3px; align-items: center; }
.lvbar i { width: .9rem; height: .5rem; border-radius: 2px; background: #ddd5c4; display: block; }
.lvbar.lv3 i.on { background: var(--full); }
.lvbar.lv2 i.on { background: var(--half); }
.lvbar.lv1 i.on { background: var(--low); }
.lvbar.lv0 i { background: transparent; border: 1.5px solid var(--over); }
.lvbar.lvx i { background: transparent; border: 1.5px dashed var(--unset); }

/* -------------------------------------------------------------- tiles */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile-min), 1fr));
  gap: .55rem;
}
.tile {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  gap: .2rem;
  padding: .65rem .35rem .55rem;
  min-height: 8.2rem;
  border-radius: var(--radius);
  border: 2px solid var(--line);
  background: var(--card);
  text-align: center;
}
.tile:active { transform: scale(.97); }
.tile-name {
  font-weight: 650; font-size: .98rem; line-height: 1.25;
  overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.tile-sub { font-size: .74rem; color: var(--muted); line-height: 1.2; overflow-wrap: anywhere; }
.tile-level { margin-top: auto; display: flex; flex-direction: column; align-items: center; gap: .15rem; padding-top: .2rem; }
.tile-level-txt { font-size: .74rem; font-weight: 650; }
.tile-cart { position: absolute; top: .3rem; right: .35rem; font-size: .9rem; }

.tile.lv3 { background: var(--full-bg); border-color: #cfe5cd; }
.tile.lv2 { background: var(--half-bg); border-color: #efdca6; }
.tile.lv1 { background: var(--low-bg); border-color: #f4c39e; }
.tile.lv0 { background: var(--over-bg); border-color: #efb1aa; }
.tile.lvx { border-style: dashed; }
.tile.lv3 .tile-level-txt { color: var(--full); }
.tile.lv2 .tile-level-txt { color: var(--half); }
.tile.lv1 .tile-level-txt { color: var(--low); }
.tile.lv0 .tile-level-txt { color: var(--over); }
.tile.lvx .tile-level-txt { color: var(--unset); }
.tile.untracked { opacity: .7; }

/* ------------------------------------------------------------- nudges */

.nudge {
  border-radius: var(--radius);
  padding: .75rem .8rem .8rem;
  margin: .7rem 0;
  border: 2px solid;
}
.nudge-check { background: #fff6e0; border-color: #f0d793; }
.nudge-soon { background: #eef6ff; border-color: #c4dbf3; }
.nudge-h { display: flex; flex-wrap: wrap; align-items: baseline; gap: .2rem .7rem; margin-bottom: .5rem; }
.nudge-sub { font-size: .82rem; color: var(--muted); }
.nudge-row { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .15rem; scrollbar-width: none; }
.nudge-row::-webkit-scrollbar { display: none; }
.mini {
  flex: 0 0 6.2rem;
  display: flex; flex-direction: column; align-items: center; gap: .2rem;
  padding: .5rem .3rem;
  border-radius: .8rem;
  border: 1px solid var(--line);
  background: var(--card);
}
.mini-name { font-size: .85rem; font-weight: 650; line-height: 1.2; text-align: center; overflow-wrap: anywhere; }
.mini-note { font-size: .75rem; color: var(--muted); }

/* ------------------------------------------------------------- sheets */

.sheet-wrap { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(20, 16, 8, .45); opacity: 0; transition: opacity .2s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-width: 40rem; margin: 0 auto;
  max-height: 92vh;
  display: flex; flex-direction: column;
  background: var(--bg);
  border-radius: 1.4rem 1.4rem 0 0;
  transform: translateY(100%);
  transition: transform .22s ease-out;
  box-shadow: 0 -6px 30px rgba(0, 0, 0, .18);
}
.sheet.tall { height: 92vh; }
.sheet-wrap.open .sheet { transform: none; }
.sheet-wrap.open .sheet-backdrop { opacity: 1; }
.sheet-grip { width: 3rem; height: .3rem; border-radius: 1rem; background: #cfc5b0; margin: .6rem auto .2rem; flex: 0 0 auto; }
.sheet-body { overflow-y: auto; padding: .4rem 1.1rem calc(1.4rem + var(--safe-b)); flex: 1 1 auto; overscroll-behavior: contain; }

.item-head { display: flex; gap: .9rem; align-items: center; margin-bottom: .5rem; }
.item-head h2 { margin: 0; font-size: 1.45rem; }
.item-head-txt { min-width: 0; }
.sheet-q { margin: 1rem 0 .6rem; }

.level-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.level-btn {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .3rem;
  min-height: 6rem;
  border-radius: 1rem;
  border: 3px solid transparent;
  padding: .6rem .4rem;
}
.level-btn .lvbar i { width: 1.4rem; height: .7rem; }
.level-main { font-size: 1.25rem; font-weight: 750; }
.level-sub { font-size: .82rem; opacity: .85; }
.level-btn.lv3 { background: var(--full-bg); color: var(--full); }
.level-btn.lv2 { background: var(--half-bg); color: var(--half); }
.level-btn.lv1 { background: var(--low-bg); color: var(--low); }
.level-btn.lv0 { background: var(--over-bg); color: var(--over); }
.level-btn.current { border-color: currentColor; }
.level-btn:active { transform: scale(.97); }
.level-tick {
  position: absolute; top: .35rem; right: .5rem;
  font-weight: 800; font-size: 1.1rem;
}

.on-list { background: #fff3cf; border: 2px solid #ecd48a; border-radius: 1rem; padding: .7rem .8rem .2rem; }
.on-list-txt { font-weight: 650; }

.ask { padding: .6rem 0; }
.ask-q { font-size: 1.2rem; font-weight: 650; margin: .5rem 0 1rem; }

.add-sheet .input { flex: 1; }
.add-results { margin-top: .6rem; }
.add-row {
  display: flex; align-items: center; gap: .7rem;
  width: 100%;
  padding: .55rem .6rem;
  min-height: 3.6rem;
  margin: .35rem 0;
  border-radius: .9rem;
  border: 2px solid var(--line);
  background: var(--card);
  text-align: left;
}
.add-row-txt { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.add-row-act {
  flex: 0 0 2.6rem; height: 2.6rem; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--brand); color: #fff; font-size: 1.5rem; font-weight: 700;
}
.add-row.is-on { opacity: .65; }
.add-row.is-on .add-row-act { background: var(--full); font-size: 1.2rem; }
.add-row.new { border-style: dashed; }
.tag { font-size: .75rem; color: var(--muted); }

/* --------------------------------------------------------------- list */

.list-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .4rem 0; flex-wrap: wrap; }
.view-title { display: flex; align-items: center; gap: .6rem; margin: 0; }
.count {
  display: inline-grid; place-items: center;
  min-width: 2rem; height: 2rem; padding: 0 .5rem;
  border-radius: 1rem;
  background: var(--brand); color: #fff;
  font-size: .95rem; font-weight: 700;
}
.count.small { min-width: 1.7rem; height: 1.7rem; font-size: .85rem; background: var(--muted); }

.shop { margin: 1rem 0; }
.shop-h {
  display: flex; align-items: center; gap: .6rem;
  padding: .3rem .2rem .5rem;
  border-bottom: 2px solid var(--line);
  margin-bottom: .3rem;
}
.shop-emoji { font-size: 1.6rem; }

.lrow { display: flex; align-items: stretch; gap: .2rem; border-bottom: 1px solid var(--line); }
.lrow.pending { opacity: .6; }
.check {
  flex: 0 0 3.6rem;
  display: grid; place-items: center;
  background: none; border: none; padding: 0;
}
.check::before {
  content: '';
  width: 2.2rem; height: 2.2rem;
  border-radius: 50%;
  border: 3px solid var(--brand);
  background: #fff;
  transition: background .15s;
}
.check.ticked::before { background: var(--brand); box-shadow: inset 0 0 0 4px #fff; }
.lrow-main {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: .6rem;
  padding: .6rem .2rem;
  min-height: 4rem;
  background: none; border: none; text-align: left;
}
.lrow-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.lrow-txt .bi-main { font-size: 1.05rem; }
.lrow-meta { font-size: .75rem; color: var(--muted); margin-top: .1rem; }
.qty {
  flex: 0 0 auto;
  background: #fff3cf; border: 1px solid #ecd48a;
  border-radius: .6rem; padding: .2rem .55rem;
  font-weight: 650; font-size: .9rem;
}

/* ------------------------------------------------------ bottom chrome */

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  max-width: 40rem; margin: 0 auto;
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--card);
  border-top: 1px solid var(--line);
  box-shadow: 0 -2px 12px rgba(0, 0, 0, .05);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .1rem;
  background: none; border: none;
  color: var(--muted);
  font-size: .9rem;
}
.tab.on { color: var(--brand); font-weight: 750; }
.tab.on .tab-icon { background: #e3efe4; }
.tab-icon { position: relative; font-size: 1.5rem; line-height: 1; padding: .25rem 1rem; border-radius: 1rem; }
.badge {
  position: absolute; top: -.3rem; right: .1rem;
  min-width: 1.4rem; height: 1.4rem; padding: 0 .3rem;
  border-radius: .7rem;
  background: var(--over); color: #fff;
  font-size: .78rem; font-weight: 750;
  display: grid; place-items: center;
}

.fab {
  position: fixed; z-index: 21;
  right: max(1rem, calc(50vw - 20rem + 1rem));
  bottom: calc(var(--nav-h) + var(--safe-b) + .9rem);
  display: flex; align-items: center; gap: .4rem;
  padding: 0 1.4rem 0 1.1rem;
  height: 3.6rem;
  border-radius: 1.8rem;
  border: none;
  background: var(--accent); color: #fff;
  font-size: 1.15rem; font-weight: 750;
  box-shadow: 0 6px 18px rgba(150, 100, 0, .35);
}
.fab-plus { font-size: 2rem; line-height: 1; margin-top: -.15rem; }
.fab[hidden] { display: none; }

.banner {
  position: sticky; top: 0; z-index: 30;
  padding: .55rem .9rem;
  text-align: center;
  font-weight: 650; font-size: .9rem;
}
.banner.offline { background: #5b5446; color: #fff; }
.banner.update { background: var(--brand); color: #fff; }
.banner button { background: none; border: none; color: inherit; font-weight: 700; width: 100%; }

.toast {
  position: fixed; z-index: 60;
  left: .75rem; right: .75rem;
  bottom: calc(var(--nav-h) + var(--safe-b) + 5.2rem);
  max-width: 38rem; margin: 0 auto;
  display: flex; align-items: center; gap: .6rem;
  padding: .75rem .8rem .75rem 1rem;
  border-radius: 1rem;
  background: #26231d; color: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  transform: translateY(1rem); opacity: 0;
  transition: transform .2s, opacity .2s;
}
.toast.show { transform: none; opacity: 1; }
.toast.error { background: var(--over); }
.toast-msg { flex: 1; font-weight: 600; }
.toast-undo {
  flex: 0 0 auto;
  min-height: 2.8rem; padding: 0 1rem;
  border-radius: .8rem; border: 2px solid #fff;
  background: transparent; color: #fff; font-weight: 750;
}

/* -------------------------------------------------------------- more */

.person { padding: .7rem 0; border-bottom: 1px solid var(--line); }
.person-h { display: flex; align-items: center; gap: .7rem; }
.avatar {
  flex: 0 0 2.8rem; height: 2.8rem; border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; font-weight: 750; font-size: 1.2rem;
}
.devices { margin: .5rem 0 0 3.5rem; }
.device { display: flex; align-items: center; gap: .5rem; font-size: .85rem; color: var(--muted); }
.admin-links .btn { justify-content: flex-start; }

.connect { text-align: center; }
.qr { background: #fff; padding: 1rem; border-radius: 1rem; margin: 1rem auto; width: min(18rem, 80vw); border: 1px solid var(--line); }
.qr svg { width: 100%; height: auto; display: block; }
.qr.loading { height: 16rem; display: grid; place-items: center; }
.link-box { font-family: ui-monospace, monospace; font-size: .8rem; word-break: break-all; background: #fff; border: 1px dashed var(--line); padding: .5rem; border-radius: .6rem; }

.activity { margin-bottom: 1rem; }
.act { display: flex; align-items: center; gap: .6rem; padding: .55rem .2rem; border-bottom: 1px solid var(--line); font-size: .92rem; }
.act.undone { opacity: .5; text-decoration: line-through; }

.photo-field { display: flex; align-items: center; gap: 1rem; margin: .5rem 0; }
.editor h2 { margin-top: .3rem; }

/* -------------------------------------------------------------- gate */

.gate {
  min-height: 100vh;
  display: flex; flex-direction: column; justify-content: center; gap: .6rem;
  padding: 2rem 1.4rem;
  text-align: center;
}
.gate form { text-align: left; margin-top: 1rem; }
.gate-logo { font-size: 4rem; }
.gate h1 { font-size: 1.7rem; }
.gate h1 .bi { align-items: center; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* While a sheet is open, show messages at the top so they don't cover it. */
body.has-sheet .toast {
  bottom: auto;
  top: calc(env(safe-area-inset-top, 0px) + .75rem);
  transform: translateY(-1rem);
}
body.has-sheet .toast.show { transform: none; }

/* Owner is looking at another household. */
.banner.viewing { background: #8a4fa3; color: #fff; }
.household.showing { background: #eef6ee; border-radius: .8rem; padding-left: .5rem; padding-right: .5rem; }

/* Food type picker: three tall options with an emoji on top. */
.diet-seg .seg-opt > span { padding: .55rem .3rem; line-height: 1.25; height: 100%; }
.diet-emoji { font-size: 1.6rem; }
.admin-links .bi { align-items: flex-start; text-align: left; }
