:root {
  color-scheme: light;
  --navy: #0b3a75;
  --navy-2: #062b5e;
  --blue: #1668dc;
  --green: #149954;
  --green-bg: #e9f8f0;
  --orange: #ed6a18;
  --orange-bg: #fff3e9;
  --red: #d83b3b;
  --red-bg: #fff0f0;
  --ink: #132238;
  --muted: #68788d;
  --line: #dce3ec;
  --surface: #ffffff;
  --canvas: #f3f6fa;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--canvas);
  color: var(--ink);
}

button,
input,
textarea,
select { font: inherit; }

button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  min-height: 100vh;
  max-width: 520px;
  margin: 0 auto;
  background: var(--canvas);
  padding-bottom: calc(86px + var(--safe-bottom));
}

.login-page {
  min-height: 100vh;
  display: grid;
  align-content: center;
  padding: 28px 22px;
  background:
    radial-gradient(circle at 12% 9%, rgba(36, 118, 215, .14), transparent 35%),
    linear-gradient(155deg, #f8fbff 0%, #eef3f9 100%);
}

.login-brand {
  width: 74px;
  height: 74px;
  border-radius: 23px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--navy);
  box-shadow: 0 14px 28px rgba(11, 58, 117, .22);
  margin-bottom: 22px;
}

.login-brand svg { width: 42px; height: 42px; }
.login-page h1 { font-size: 31px; margin: 0 0 8px; }
.login-page > p { margin: 0 0 28px; color: var(--muted); line-height: 1.7; }

.login-card,
.card {
  background: var(--surface);
  border: 1px solid rgba(210, 220, 233, .82);
  border-radius: 18px;
  box-shadow: 0 8px 24px rgba(22, 44, 75, .07);
}

.login-card { padding: 20px; }
.field { display: grid; gap: 8px; margin-bottom: 16px; }
.field label { font-weight: 700; font-size: 14px; color: #314158; }
.field input,
.field textarea,
.field select {
  width: 100%;
  min-height: 52px;
  border: 1px solid #cbd5e2;
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
  background: #fff;
  color: var(--ink);
}

.field textarea { min-height: 92px; resize: vertical; }
.field input:focus,
.field textarea:focus,
.field select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(22, 104, 220, .12); }

.login-hint {
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  color: white;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 18px 14px;
  background: linear-gradient(135deg, var(--navy-2), var(--navy));
  box-shadow: 0 3px 14px rgba(9, 41, 83, .22);
}

.topbar-line {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.topbar h1 { margin: 0; font-size: 21px; letter-spacing: .02em; }
.topbar .subtitle { margin-top: 4px; color: rgba(255,255,255,.72); font-size: 13px; }

.icon-btn {
  border: 0;
  background: transparent;
  color: inherit;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.icon-btn:active { background: rgba(255,255,255,.12); }
.icon-btn svg { width: 24px; height: 24px; }

.sync-pill {
  border: 0;
  border-radius: 999px;
  min-height: 32px;
  padding: 6px 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(31, 181, 98, .95);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.sync-pill.demo { background: #d07a13; }
.sync-pill.offline { background: #788699; }
.sync-pill svg { width: 14px; height: 14px; }

.page { padding: 16px; }
.summary-card { padding: 18px; margin-bottom: 16px; }
.summary-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.summary-title { font-size: 14px; color: var(--muted); }
.summary-main { margin-top: 5px; font-size: 26px; font-weight: 900; }
.date-chip { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; color: var(--navy); font-weight: 800; background: #f7faff; }

.progress-track { height: 8px; border-radius: 99px; background: #e8edf4; overflow: hidden; margin-top: 16px; }
.progress-track span { display: block; height: 100%; background: var(--green); border-radius: inherit; }
.progress-label { display: flex; justify-content: space-between; margin-top: 8px; color: var(--muted); font-size: 12px; }

.section-title { margin: 22px 2px 11px; display: flex; align-items: baseline; justify-content: space-between; }
.section-title h2 { margin: 0; font-size: 17px; }
.section-title span { color: var(--muted); font-size: 13px; }

.stall-list { display: grid; gap: 12px; }
.stall-card {
  width: 100%;
  border: 1px solid rgba(207, 218, 231, .9);
  border-radius: 17px;
  background: white;
  padding: 16px;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  align-items: center;
  gap: 13px;
  text-align: left;
  color: inherit;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(24, 48, 79, .06);
}

.stall-card:active { transform: scale(.992); background: #fafdff; }
.stall-icon { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 15px; background: #edf4ff; color: var(--blue); }
.stall-icon svg { width: 31px; height: 31px; }
.stall-code { font-size: 20px; font-weight: 900; }
.stall-meta { margin-top: 5px; color: var(--muted); font-size: 13px; }
.stall-side { text-align: right; display: grid; justify-items: end; gap: 8px; }
.chevron { color: #7c8a9d; width: 20px; height: 20px; }

.status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  color: var(--orange);
  background: var(--orange-bg);
}

.status.green { color: var(--green); background: var(--green-bg); }
.status.gray { color: #68778a; background: #eef1f5; }
.status.red { color: var(--red); background: var(--red-bg); }

.detail-hero { padding: 18px; margin-bottom: 14px; }
.detail-code { font-size: 34px; font-weight: 950; line-height: 1; }
.detail-row { display: flex; justify-content: space-between; gap: 14px; margin-top: 13px; color: var(--muted); }
.detail-row strong { color: var(--ink); }

.photo-box {
  position: relative;
  overflow: hidden;
  min-height: 160px;
  border: 2px dashed #82a9dd;
  border-radius: 16px;
  background: #f7fbff;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--navy);
  cursor: pointer;
}

.photo-box input { position: absolute; opacity: 0; inset: 0; width: 100%; cursor: pointer; }
.photo-box svg { width: 48px; height: 48px; margin-bottom: 7px; }
.photo-box span { display: block; font-weight: 900; }
.photo-preview { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; padding: 8px; }
.photo-preview img { width: 100%; aspect-ratio: 1; border-radius: 11px; object-fit: cover; }

.form-card { padding: 16px; margin-top: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.primary-btn,
.secondary-btn,
.danger-btn {
  width: 100%;
  min-height: 56px;
  border-radius: 14px;
  font-weight: 900;
  border: 0;
  cursor: pointer;
  padding: 12px 18px;
}

.primary-btn { color: white; background: var(--green); box-shadow: 0 8px 18px rgba(20, 153, 84, .18); }
.primary-btn.blue { background: var(--blue); box-shadow: 0 8px 18px rgba(22, 104, 220, .18); }
.secondary-btn { color: var(--orange); background: #fff; border: 1.5px solid var(--orange); }
.danger-btn { color: white; background: var(--red); }
.primary-btn:disabled,
.secondary-btn:disabled,
.danger-btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.action-stack { display: grid; gap: 10px; margin-top: 16px; }

.sync-note { display: flex; justify-content: center; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; margin: 15px 0 2px; }
.sync-note svg { width: 17px; height: 17px; color: var(--green); }

.item-list { display: grid; gap: 10px; }
.item-card {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 32px;
  gap: 12px;
  align-items: center;
  padding: 11px;
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 15px;
}

.item-card.selectable { cursor: pointer; }
.item-card.selected { border-color: var(--red); background: var(--red-bg); }
.product-image { width: 72px; height: 72px; border-radius: 11px; object-fit: cover; background: #e8edf3; }
.item-title { font-size: 14px; font-weight: 800; line-height: 1.4; }
.item-meta { margin-top: 6px; color: var(--muted); font-size: 13px; }
.check-circle { width: 27px; height: 27px; border-radius: 50%; display: grid; place-items: center; color: white; background: var(--green); }
.check-circle.empty { color: #95a2b3; background: white; border: 2px solid #b6c1cf; }
.check-circle.alert { background: var(--red); }
.check-circle svg { width: 17px; height: 17px; }

.inspection-actions {
  position: sticky;
  bottom: calc(74px + var(--safe-bottom));
  padding: 12px 0 5px;
  background: linear-gradient(to bottom, rgba(243,246,250,0), var(--canvas) 20%);
  z-index: 10;
}

.exception-choice { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.exception-choice label { display: block; }
.exception-choice input { position: absolute; opacity: 0; pointer-events: none; }
.exception-choice span { min-height: 45px; display: grid; place-items: center; border: 1px solid #d4dce7; border-radius: 11px; background: white; color: #405069; font-weight: 800; font-size: 13px; }
.exception-choice input:checked + span { border-color: var(--red); color: var(--red); background: var(--red-bg); }

.bottom-nav {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(520px, 100%);
  height: calc(72px + var(--safe-bottom));
  padding: 7px 18px var(--safe-bottom);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(255,255,255,.97);
  border-top: 1px solid var(--line);
  box-shadow: 0 -8px 24px rgba(23, 43, 69, .07);
}

.nav-item { border: 0; background: transparent; color: #6f7e92; display: grid; justify-items: center; gap: 3px; font-size: 11px; padding: 4px 0; cursor: pointer; }
.nav-item.active { color: var(--blue); font-weight: 900; }
.nav-item svg { width: 23px; height: 23px; }

.empty-state { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty-state svg { width: 64px; height: 64px; color: #9ba9ba; margin-bottom: 12px; }
.empty-state strong { display: block; color: var(--ink); font-size: 18px; margin-bottom: 7px; }

.settings-list { display: grid; gap: 12px; }
.settings-row { padding: 16px; display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.settings-row strong { display: block; }
.settings-row small { display: block; color: var(--muted); margin-top: 4px; }
.link-btn { border: 0; background: transparent; color: var(--blue); font-weight: 800; cursor: pointer; }

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: calc(92px + var(--safe-bottom));
  transform: translate(-50%, 24px);
  max-width: min(400px, calc(100% - 32px));
  border-radius: 12px;
  padding: 12px 16px;
  background: rgba(20, 32, 49, .94);
  color: white;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: rgba(174, 35, 35, .96); }
.toast.success { background: rgba(9, 117, 64, .96); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(7, 21, 40, .48);
  display: grid;
  align-items: end;
}

.modal-sheet {
  width: min(520px, 100%);
  margin: 0 auto;
  max-height: 90vh;
  overflow: auto;
  padding: 20px 18px calc(22px + var(--safe-bottom));
  border-radius: 24px 24px 0 0;
  background: white;
  box-shadow: 0 -12px 30px rgba(0,0,0,.18);
}

.modal-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-title h2 { margin: 0; font-size: 20px; }
.warning-box { border-radius: 12px; padding: 12px; margin: 12px 0; background: var(--orange-bg); color: #8a480e; font-size: 13px; line-height: 1.5; }

@media (min-width: 700px) {
  body { padding: 24px 0; }
  .app-shell { min-height: calc(100vh - 48px); border-radius: 28px; overflow: clip; box-shadow: 0 18px 60px rgba(22, 43, 69, .15); }
  .topbar { position: relative; }
  .bottom-nav { bottom: 24px; border-radius: 0 0 28px 28px; }
  .login-page { min-height: calc(100vh - 48px); }
}

@media (max-width: 370px) {
  .page { padding: 12px; }
  .stall-card { padding: 13px; grid-template-columns: 46px minmax(0, 1fr) auto; gap: 10px; }
  .stall-icon { width: 46px; height: 46px; }
  .form-grid { grid-template-columns: 1fr; }
  .product-image { width: 64px; height: 64px; }
  .item-card { grid-template-columns: 64px minmax(0, 1fr) 29px; }
}
