/* CartYard — "Don't Make Me Think" UI.
   Dark-clean, mobile-first, min 48px touch targets, system fonts. */
:root {
  --bg: #0f1419;
  --bg2: #161d24;
  --card: #1c2530;
  --line: #2a3642;
  --text: #e8eef4;
  --muted: #8fa1b3;
  --accent: #2f9e6e;
  --accent2: #3b82f6;
  --danger: #e5484d;
  --warn: #f5a524;
  --purple: #a855f7;
  --teal: #2dd4bf;
  --orange: #f97316;
  --radius: 12px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
  overflow: hidden;
  display: flex; flex-direction: column;
}
/* #view is the app's scroll container — the document itself never scrolls,
   so iOS can't rubber-band the page and fixed/sticky bars stay put. */
main {
  flex: 1 1 auto; min-height: 0; width: 100%;
  max-width: 720px; margin: 0 auto;
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: calc(14px + env(safe-area-inset-top)) 14px 110px;
}
.hidden { display: none !important; }
/* Locked while the bottom sheet is open: the content behind must not scroll
   or iOS chains the sheet's scroll into it and the sheet sticks/glitches. */
html.locked, html.locked body { overflow: hidden; }
html.locked main { overflow: hidden; }

/* ---------- top bar ---------- */
#topbar {
  position: sticky; top: 0; z-index: 50;
  transform: translateZ(0);
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px; background: var(--bg2);
  border-bottom: 1px solid var(--line);
}
.storebtn {
  flex: 1; display: flex; align-items: center; gap: 6px;
  background: none; border: 0; color: var(--text);
  font-size: 18px; font-weight: 700; padding: 12px 4px;
  min-height: 48px; text-align: left; cursor: pointer;
}
.storebtn .chev { color: var(--muted); font-size: 22px; line-height: 1; }
.storebtn.locked .chev { display: none; }
.storebtn.locked { cursor: default; }
.linkbtn {
  background: none; border: 0; color: var(--muted);
  font-size: 14px; padding: 12px 8px; min-height: 48px; cursor: pointer;
}

/* ---------- layout ---------- */
h1 { font-size: 24px; margin: 6px 0 16px; }
h2 { font-size: 18px; margin: 20px 0 10px; }
.center { text-align: center; color: var(--muted); padding: 32px 16px; }
.error { color: var(--danger); font-size: 14px; margin: 10px 0; min-height: 20px; }

/* ---------- login ---------- */
.login-wrap { max-width: 400px; margin: 10vh auto 0; padding: 0 20px; }
.login-logo { font-size: 30px; font-weight: 800; text-align: center; margin-bottom: 6px; }
.login-sub { text-align: center; color: var(--muted); margin-bottom: 24px; font-size: 15px; }
.login-dealer { text-align: center; font-size: 19px; font-weight: 700; margin: -2px 0 14px; }

/* ---------- forms ---------- */
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 4px; }
input, select, textarea {
  width: 100%; background: var(--bg2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 0 14px; font-size: 16px; min-height: 52px; margin: 0;
  font-family: inherit;
}
textarea { padding: 12px 14px; min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
}
.btn {
  display: block; width: 100%; background: var(--accent); color: #fff;
  border: 0; border-radius: 10px; min-height: 54px;
  font-size: 17px; font-weight: 700; cursor: pointer; margin-top: 18px;
}
.btn:active { opacity: .85; }
.btn.danger { background: var(--danger); }
.btn.danger.armed { background: #7a1f22; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn:disabled { opacity: .5; }
.filebtn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px dashed var(--line); border-radius: 10px; color: var(--text);
  min-height: 56px; font-size: 15px; font-weight: 600; cursor: pointer;
  margin: 4px 0 2px;
}
.photoprev { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.photoprev img {
  width: 72px; height: 54px; object-fit: cover;
  border-radius: 8px; border: 1px solid var(--line);
}

/* ---------- transfer picker ---------- */
.storerow { color: var(--muted); font-size: 14px; margin: 4px 0 10px; }
.storerow b { color: var(--text); }
.transferpick { display: grid; gap: 10px; margin-top: 10px; }
.storepick {
  display: block; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 0 16px; min-height: 56px;
  font-size: 16px; font-weight: 600; cursor: pointer;
}
.storepick:active { border-color: var(--accent); }
.storepick.armed { border-color: var(--danger); border-width: 2px; background: #2a1518; color: #f87171; }
#addphotos { margin: 10px 0 4px; }

/* ---------- store picker ---------- */
.storecards { display: grid; gap: 14px; }
.storecard {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px;
  min-height: 64px; width: 100%; color: var(--text);
  font-size: 18px; font-weight: 700; cursor: pointer; text-align: left;
}
.storecard:active { border-color: var(--accent); }
.storecard .count { font-size: 15px; font-weight: 600; color: var(--accent); white-space: nowrap; }
.storecard .count small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }

/* ---------- brand chips ---------- */
.chips {
  display: flex; gap: 10px; overflow-x: auto; padding: 4px 2px 12px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chipbtn {
  flex: 0 0 auto; min-height: 48px; padding: 0 18px;
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  border-radius: 999px; font-size: 15px; font-weight: 600; cursor: pointer;
  white-space: nowrap;
}
.chipbtn small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.chipbtn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chipbtn.on small { color: rgba(255,255,255,.8); }

/* ---------- cart cards (Airtable-style rows) ---------- */
.cartcard {
  display: block; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px;
  color: var(--text); cursor: pointer;
}
.cartcard:active { border-color: var(--accent); }
.cartcard .nm { font-size: 17px; font-weight: 700; margin-bottom: 10px; }
.cartcard .row3 { display: flex; align-items: center; gap: 12px; }
.cartcard .thumb {
  flex: 0 0 64px; width: 64px; height: 48px; border-radius: 8px;
  overflow: hidden; background: var(--bg2); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
}
.cartcard .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cartcard .thumb.empty::after { content: "—"; color: var(--muted); font-size: 18px; }
.stpill {
  display: inline-block; padding: 7px 16px; border-radius: 999px;
  font-size: 13px; font-weight: 700; letter-spacing: .4px; white-space: nowrap;
  text-transform: uppercase; color: var(--dot);
  background: color-mix(in srgb, var(--dot) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--dot) 45%, transparent);
}
.cartcard .dt { margin-left: auto; color: var(--muted); font-size: 13px; white-space: nowrap; }

/* ---------- subtle banner ---------- */
.banner {
  display: block; width: 100%; text-align: left;
  background: rgba(245,165,36,.08); border: 1px solid rgba(245,165,36,.35);
  color: var(--warn); border-radius: 10px; padding: 12px 14px;
  font-size: 14px; margin-bottom: 12px; cursor: pointer; min-height: 48px;
}
.banner.on { background: rgba(245,165,36,.18); }

/* ---------- bottom sheet ---------- */
.photostrip {
  display: flex; gap: 8px; overflow-x: auto; margin: 12px 0 4px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.photostrip::-webkit-scrollbar { display: none; }
.photostrip img {
  flex: 0 0 auto; width: 112px; height: 84px; object-fit: cover;
  border-radius: 10px; border: 1px solid var(--line); cursor: zoom-in;
  background: var(--bg2);
}
.lightbox {
  position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,.92);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
#sheet-root .scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 100;
  animation: fadein .18s ease-out;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 101;
  max-height: 94dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  transform: translateZ(0);
  background: var(--bg2); border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0; padding: 10px 18px calc(20px + env(safe-area-inset-bottom));
  animation: slideup .22s ease-out;
}
@keyframes slideup { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@media (min-width: 720px) {
  .sheet {
    left: 50%; right: auto; bottom: auto; top: 8vh;
    transform: translateX(-50%) translateZ(0); width: 560px; max-width: calc(100vw - 40px);
    border: 1px solid var(--line); border-radius: 18px;
    max-height: 84vh; animation: fadein .18s ease-out;
  }
}
.grabber { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 6px auto 12px; }
.sheet h2 { margin: 4px 40px 4px 0; font-size: 22px; }
.sheet .sub { color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.kv { display: grid; grid-template-columns: 108px 1fr; gap: 8px 12px; font-size: 15px; margin: 12px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.sheetclose {
  position: absolute; top: 12px; right: 12px;
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--card); border: 1px solid var(--line);
  color: var(--text); font-size: 20px; cursor: pointer;
}
.statusgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 8px 0 4px; }
.statusbtn {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 0 14px; min-height: 56px;
  font-size: 15px; font-weight: 600; cursor: pointer;
}
.statusbtn.cur { border-color: var(--accent); border-width: 2px; }
.statusbtn .dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; }
.statusbtn.armed { border-color: var(--danger); border-width: 2px; background: #2a1518; }
.statusbtn.armed .lbl { color: #f87171; }
.nudge {
  background: rgba(245,165,36,.08); border: 1px solid rgba(245,165,36,.35);
  border-radius: 10px; padding: 14px; margin: 14px 0;
}
.nudge p { margin: 0 0 10px; font-size: 14px; color: var(--warn); }
.nudgerow { display: flex; gap: 10px; }
.nudgerow input { flex: 1; }
.nudgerow .btn { width: auto; margin-top: 0; padding: 0 20px; min-height: 52px; font-size: 15px; }
.notesrow { display: flex; gap: 10px; align-items: flex-start; }
.notesrow textarea { flex: 1; }
.notesrow .btn { width: auto; margin-top: 0; padding: 0 20px; min-height: 52px; font-size: 15px; }
.notesro { color: var(--text); font-size: 15px; margin: 4px 0 8px; white-space: pre-wrap; }

/* ---------- bottom tab bar ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  transform: translateZ(0);
  display: flex; background: var(--bg2); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabbar .tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: 0; color: var(--muted);
  font-size: 11px; padding: 10px 0 8px; min-height: 62px; cursor: pointer;
  font-family: inherit;
}
#tabbar .tab .ico { font-size: 22px; line-height: 1.2; }
#tabbar .tab.on { color: var(--accent); }

/* ---------- install nudge ---------- */
#installnudge {
  position: fixed; left: 12px; right: 12px; z-index: 90;
  bottom: calc(84px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--accent); color: var(--text);
  border-radius: 14px; padding: 12px 12px 12px 14px; font-size: 14px;
  box-shadow: 0 8px 28px rgba(0,0,0,.5);
  animation: fadein .25s ease-out;
}
#installnudge .inmsg { flex: 1; }
#installnudge .inmsg b { color: var(--accent); }
#indismiss {
  flex: 0 0 auto; width: 36px; height: 36px; border-radius: 50%;
  background: var(--bg2); border: 1px solid var(--line); color: var(--muted);
  font-size: 15px; cursor: pointer;
}
@media (min-width: 720px) {
  #tabbar { left: 50%; transform: translateX(-50%) translateZ(0); max-width: 720px;
    border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}

/* ---------- activity / admin ---------- */
.logitem { padding: 13px 2px; border-bottom: 1px solid var(--line); font-size: 15px; }
.logitem .who { font-weight: 700; }
.logitem .when { color: var(--muted); font-size: 13px; margin-top: 3px; }
.usercard {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
}
.usercard .nm { font-weight: 700; font-size: 16px; }
.usercard .em { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.userrow { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pwrow { display: flex; gap: 10px; margin-top: 10px; }
.pwrow input { flex: 1; }
.pwrow .btn { width: auto; margin-top: 0; padding: 0 18px; min-height: 52px; font-size: 14px; }
/* compact team rows */
.usercard.slim { padding: 12px 14px; margin-bottom: 8px; }
.urow1 { display: flex; align-items: center; gap: 10px; }
.urow1 .uid { flex: 1; min-width: 0; }
.urow1 .nm { font-size: 15px; }
.urow1 .em { margin: 0; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.urow1 .savebtn { width: auto; flex: 0 0 auto; margin: 0; padding: 0 18px; min-height: 44px; font-size: 14px; }
.urow2 { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.urow2 select { flex: 1; min-width: 0; min-height: 44px; font-size: 14px; }
.pwlink { flex: 0 0 auto; min-height: 0; padding: 10px 6px; font-size: 13px; }
.usercard.slim .pwrow { margin-top: 8px; }
.usercard.slim .pwrow input { min-height: 44px; }
.usercard.slim .pwrow .btn { min-height: 44px; }

/* ---------- toast ---------- */
#toast-root {
  position: fixed; bottom: calc(84px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%); z-index: 200; width: max-content; max-width: 90vw;
}
.toast {
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  padding: 12px 22px; border-radius: 999px; margin-top: 8px;
  font-size: 15px; font-weight: 600; text-align: center;
  animation: fadein .18s ease-out;
}
.showmore {
  display: block; width: 100%; background: var(--card); border: 1px solid var(--line);
  color: var(--text); border-radius: 10px; min-height: 52px;
  font-size: 15px; font-weight: 600; cursor: pointer; margin: 6px 0 12px;
}
