/* ===========================================================================
   Urban Food Systems — field app
   Loaded after ufs.css. Phone-first: one thumb, 44px targets, bottom nav,
   and an offline state that is always visible rather than guessed at.
   =========================================================================== */

:root {
  --app-header-h: 58px;
  --app-nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

body.app {
  background: var(--surface);
  padding-bottom: calc(var(--app-nav-h) + var(--safe-b));
  overscroll-behavior-y: contain;
  -webkit-tap-highlight-color: transparent;
}

/* ---------------------------------------------------------------------------
   Header
   --------------------------------------------------------------------------- */
.app-header {
  position: sticky; top: 0; z-index: 40;
  height: var(--app-header-h);
  display: flex; align-items: center; gap: .7rem;
  padding: 0 1rem;
  background: linear-gradient(135deg, var(--navcdp-green-deep), var(--navcdp-green-abyss));
  color: #fff;
  box-shadow: 0 2px 12px rgba(17, 67, 28, .22);
}
.app-header .mark {
  width: 32px; height: 32px; flex: 0 0 auto;
  background: #fff; border-radius: 9px; padding: 3px;
  display: grid; place-items: center;
}
.app-header .mark img { width: 100%; height: 100%; object-fit: contain; }
.app-header .ttl { font-size: .98rem; font-weight: 800; line-height: 1.1; }
.app-header .sub { font-size: .7rem; color: rgba(255, 255, 255, .72); }
.app-header .hbtn {
  width: 38px; height: 38px; flex: 0 0 auto;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, .14);
  border: 0; border-radius: 10px; color: #fff; cursor: pointer;
}
.app-header .hbtn:active { background: rgba(255, 255, 255, .26); }

/* Back header, used on sub-pages */
.app-header.is-sub { background: var(--card); color: var(--ink); box-shadow: var(--sh-xs);
  border-bottom: 1px solid var(--line); }
.app-header.is-sub .hbtn { background: var(--surface-2); color: var(--ink); }
.app-header.is-sub .sub { color: var(--muted); }

/* ---------------------------------------------------------------------------
   Connection + sync status
   --------------------------------------------------------------------------- */
.sync-chip {
  display: flex; align-items: center; gap: .45rem;
  padding: .45rem .8rem;
  margin: .75rem 1rem 0;
  border-radius: var(--r-pill);
  background: var(--tint-green); color: var(--primary-deep);
  font-size: .78rem; font-weight: 700;
}
.sync-chip .ico { width: 15px; height: 15px; flex: 0 0 auto; }
.sync-chip.is-offline { background: var(--tint-gold); color: var(--navcdp-gold-deep); }
.sync-chip.is-pending { background: var(--tint-teal); color: var(--ufs-teal); }
.sync-chip.is-error   { background: var(--tint-red); color: var(--ufs-red-dp); }
.sync-chip button {
  margin-left: auto; padding: .15rem .55rem;
  border: 0; border-radius: var(--r-pill);
  background: rgba(0, 0, 0, .08); color: inherit;
  font: inherit; font-size: .72rem; font-weight: 800; cursor: pointer;
}

.offline-banner {
  position: fixed; left: 0; right: 0;
  bottom: calc(var(--app-nav-h) + var(--safe-b));
  z-index: 45;
  padding: .55rem 1rem;
  background: var(--navcdp-gold); color: var(--navcdp-brown-deep);
  font-size: .8rem; font-weight: 800; text-align: center;
  transform: translateY(100%);
  transition: transform .22s var(--ease);
}
.offline-banner.is-on { transform: none; }

/* ---------------------------------------------------------------------------
   Content
   --------------------------------------------------------------------------- */
.app-main { padding: 1rem; max-width: 640px; margin: 0 auto; }

.app-greeting { margin-bottom: 1rem; }
.app-greeting h1 { font-size: 1.32rem; margin-bottom: .15rem; }
.app-greeting p { font-size: .85rem; color: var(--muted); margin: 0; }

/* Two-up quick stats */
.app-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: .65rem; margin-bottom: 1rem; }
.app-stat {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); padding: .85rem .9rem;
}
.app-stat .n {
  font-size: 1.5rem; font-weight: 800; letter-spacing: -.03em; line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.app-stat .l { font-size: .73rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em; margin-top: .15rem; }
.app-stat.is-gold .n { color: var(--navcdp-gold-deep); }
.app-stat.is-teal .n { color: var(--ufs-teal); }

/* Big action tiles */
.app-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: .65rem; margin-bottom: 1.2rem; }
.app-action {
  display: flex; flex-direction: column; gap: .5rem;
  padding: 1rem .9rem;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-lg);
  color: var(--ink); text-align: left;
  min-height: 108px;
  transition: transform .12s var(--ease), box-shadow .12s var(--ease);
}
.app-action:active { transform: scale(.975); }
.app-action .ic {
  width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center;
  background: var(--tint-green); color: var(--primary-deep);
}
.app-action.is-gold .ic { background: var(--tint-gold); color: var(--navcdp-gold-deep); }
.app-action.is-teal .ic { background: var(--tint-teal); color: var(--ufs-teal); }
.app-action.is-brown .ic { background: var(--tint-brown); color: var(--navcdp-brown); }
.app-action .ic svg { width: 20px; height: 20px; }
.app-action .t { display: block; font-size: .92rem; font-weight: 800; line-height: 1.2; }
.app-action .s { display: block; font-size: .74rem; color: var(--muted); line-height: 1.35; }
.app-action.is-primary {
  grid-column: 1 / -1;
  flex-direction: row; align-items: center; gap: .85rem;
  background: linear-gradient(135deg, var(--navcdp-green), var(--navcdp-green-deep));
  border-color: transparent; color: #fff; min-height: 0;
}
.app-action.is-primary .ic { background: rgba(255, 255, 255, .2); color: #fff; }
.app-action.is-primary .s { color: rgba(255, 255, 255, .82); margin-top: .1rem; }
/* The trailing chevron is decoration, not an icon tile. */
.app-action.is-primary > svg { width: 20px; height: 20px; flex: 0 0 auto; opacity: .9; }

/* ---------------------------------------------------------------------------
   List rows
   --------------------------------------------------------------------------- */
.app-section-title {
  display: flex; align-items: center; justify-content: space-between;
  font-size: .74rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); margin: 1.4rem 0 .6rem;
}
.app-section-title a { font-size: .74rem; font-weight: 700; letter-spacing: 0; text-transform: none; }

.app-list { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.app-row {
  display: flex; align-items: center; gap: .75rem;
  padding: .8rem .9rem;
  border-bottom: 1px solid var(--line-soft);
  color: var(--ink);
  min-height: 60px;
}
.app-row:last-child { border-bottom: 0; }
.app-row:active { background: var(--surface); }
.app-row .grow { min-width: 0; }
.app-row .nm {
  font-size: .9rem; font-weight: 700; line-height: 1.25;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.app-row .sb { font-size: .76rem; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-row .chev { color: var(--muted-soft); flex: 0 0 auto; }

/* Outbox state dot */
.dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.dot.is-queued { background: var(--navcdp-gold); }
.dot.is-sending { background: var(--ufs-teal); animation: pulse 1.1s ease-in-out infinite; }
.dot.is-synced { background: var(--navcdp-green); }
.dot.is-error  { background: var(--ufs-red); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------------------------------------------------------------------------
   Multi-step form
   --------------------------------------------------------------------------- */
.step-head { padding: .9rem 1rem .4rem; background: var(--card); border-bottom: 1px solid var(--line); }
.step-bar { display: flex; gap: .3rem; margin-bottom: .55rem; }
.step-bar span {
  flex: 1; height: 4px; border-radius: 2px; background: var(--line);
  transition: background .25s var(--ease);
}
.step-bar span.is-done { background: var(--primary); }
.step-bar span.is-on { background: var(--navcdp-gold); }
.step-meta { display: flex; align-items: baseline; justify-content: space-between; }
.step-meta .t { font-size: 1rem; font-weight: 800; }
.step-meta .c { font-size: .74rem; font-weight: 700; color: var(--muted); }

.step-panel { padding: 1rem; max-width: 640px; margin: 0 auto; }
.step-panel .field { margin-bottom: 1.1rem; }
.step-panel .label { font-size: .86rem; margin-bottom: .4rem; }
.step-panel .input,
.step-panel .select,
.step-panel .textarea { min-height: 50px; font-size: 1rem; border-radius: 12px; }
.step-panel .check { min-height: 54px; align-items: center; border-radius: 12px; }
.step-intro { font-size: .85rem; color: var(--muted); margin-bottom: 1.2rem; }

.step-foot {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex; gap: .6rem;
  padding: .75rem 1rem calc(.75rem + var(--safe-b));
  background: var(--card);
  border-top: 1px solid var(--line);
  box-shadow: 0 -4px 20px rgba(17, 67, 28, .07);
}
.step-foot .btn { flex: 1; min-height: 50px; font-size: .95rem; border-radius: 12px; }
.step-foot .btn-back { flex: 0 0 56px; }
body.has-step-foot { padding-bottom: 86px; }

/* Review list on the final step */
.review-list { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.review-row {
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
  padding: .65rem .9rem; border-bottom: 1px solid var(--line-soft); font-size: .86rem;
}
.review-row:last-child { border-bottom: 0; }
.review-row .k { color: var(--muted); flex: 0 0 auto; }
.review-row .v { font-weight: 700; text-align: right; word-break: break-word; }
.review-group {
  padding: .5rem .9rem; background: var(--surface);
  font-size: .7rem; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; color: var(--muted);
}

/* ---------------------------------------------------------------------------
   Bottom navigation
   --------------------------------------------------------------------------- */
.app-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  height: calc(var(--app-nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: color-mix(in srgb, var(--card) 94%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--line);
}
.app-nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .18rem;
  color: var(--muted); font-size: .68rem; font-weight: 700;
  position: relative;
}
.app-nav a .ico { width: 21px; height: 21px; }
.app-nav a.is-on { color: var(--primary-deep); }
.app-nav a.is-on::before {
  content: ""; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 26px; height: 3px; border-radius: 0 0 3px 3px; background: var(--primary);
}
.app-nav a .pip {
  position: absolute; top: 8px; right: 50%; margin-right: -18px;
  min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: var(--r-pill);
  background: var(--navcdp-gold); color: var(--navcdp-brown-deep);
  font-size: .62rem; font-weight: 800;
  display: grid; place-items: center;
}

/* ---------------------------------------------------------------------------
   Scanner / code entry
   --------------------------------------------------------------------------- */
.code-entry {
  display: flex; gap: .4rem; justify-content: center;
  font-family: var(--mono); font-size: 1.3rem; font-weight: 800;
  letter-spacing: .08em; text-align: center;
}
.code-input {
  width: 100%; text-align: center; text-transform: uppercase;
  font-family: var(--mono); font-size: 1.15rem; font-weight: 800; letter-spacing: .06em;
  min-height: 60px; border-radius: 14px;
}

.scan-frame {
  position: relative;
  aspect-ratio: 1; max-width: 260px; margin: 0 auto 1.2rem;
  border-radius: 20px;
  background: var(--surface-2);
  display: grid; place-items: center;
  overflow: hidden;
}
.scan-frame::before,
.scan-frame::after {
  content: ""; position: absolute; width: 46px; height: 46px;
  border: 3px solid var(--primary);
}
.scan-frame::before { top: 16px; left: 16px; border-right: 0; border-bottom: 0; border-radius: 12px 0 0 0; }
.scan-frame::after { bottom: 16px; right: 16px; border-left: 0; border-top: 0; border-radius: 0 0 12px 0; }
.scan-frame video { width: 100%; height: 100%; object-fit: cover; }

/* ---------------------------------------------------------------------------
   Install prompt
   --------------------------------------------------------------------------- */
.install-card {
  display: flex; gap: .75rem; align-items: center;
  margin: 0 1rem 1rem;
  padding: .85rem 1rem;
  background: var(--tint-green);
  border: 1px solid var(--tint-green2);
  border-radius: var(--r-lg);
}
.install-card .t { font-size: .86rem; font-weight: 800; }
.install-card .s { font-size: .75rem; color: var(--muted); }

/* ---------------------------------------------------------------------------
   Auth (field app)
   --------------------------------------------------------------------------- */
.app-auth {
  min-height: 100vh;
  display: flex; flex-direction: column; justify-content: center;
  padding: 2rem 1.3rem;
  background:
    radial-gradient(700px 360px at 50% 0%, rgba(60, 168, 72, .2), transparent 62%),
    var(--surface);
}
.app-auth-box { width: 100%; max-width: 400px; margin: 0 auto; }
.app-auth-logo { width: 76px; margin: 0 auto 1.4rem; display: block; }
.app-auth h1 { font-size: 1.5rem; text-align: center; margin-bottom: .3rem; }
.app-auth .lead { text-align: center; color: var(--muted); font-size: .88rem; margin-bottom: 1.8rem; }
.app-auth .input { min-height: 52px; font-size: 1rem; border-radius: 12px; }
.app-auth .btn { min-height: 52px; font-size: 1rem; border-radius: 12px; }

@media (min-width: 720px) {
  .app-nav { max-width: 640px; left: 50%; transform: translateX(-50%); border-radius: 18px 18px 0 0;
    border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .offline-banner { max-width: 640px; left: 50%; transform: translateX(-50%) translateY(100%); }
  .offline-banner.is-on { transform: translateX(-50%); }
  .step-foot { max-width: 640px; left: 50%; transform: translateX(-50%);
    border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
