:root {
  --bg: #07080c;
  --bg-2: #10141b;
  --card: #181e27;
  --text: #f4f6f8;
  --muted: #8b95a1;
  --line: rgba(255, 255, 255, 0.08);
  --accent: #22d39a;
  --accent-in: #22d39a;
  --accent-out: #ffb020;
  --danger: #ff5d6a;
  --blue: #4da3ff;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: "Source Han Sans CN", "Noto Sans CJK SC", "Noto Sans SC", "HarmonyOS Sans SC",
    "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
body { overflow: hidden; }
button, input { font-family: inherit; }
#app { height: 100%; height: 100dvh; position: relative; overflow: hidden; background: var(--bg); }

.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  opacity: 0; pointer-events: none;
  transform: translateX(12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.screen.is-active { opacity: 1; pointer-events: auto; transform: none; }
.screen[hidden] { display: none !important; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  gap: 10px;
  z-index: 3;
  background: linear-gradient(to bottom, rgba(7,8,12,0.96), rgba(7,8,12,0.7) 70%, transparent);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-icon { width: 36px; height: 36px; border-radius: 9px; }
.brand h1, .topbar h1 {
  margin: 0; font-size: 17px; font-weight: 650; letter-spacing: 0.02em;
}
.subtitle { margin: 1px 0 0; font-size: 11px; color: var(--muted); }
.top-actions { display: flex; gap: 6px; }
.top-spacer { width: 40px; }
.icon-btn, .round-btn, .text-btn, .shutter, .chip, .seg, .btn {
  border: 0; cursor: pointer; color: inherit; background: none;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px;
  background: rgba(255,255,255,0.06);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700; letter-spacing: 0.04em; color: var(--text);
}
.icon-btn.back { background: transparent; }
.text-btn { font-size: 14px; color: var(--muted); padding: 8px; }

.viewfinder {
  position: relative;
  flex: 1;
  margin: 0 12px;
  border-radius: 22px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 10px 40px rgba(0,0,0,0.45);
}
#camera, #preview-overlay {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  background: #000;
}
#camera.is-front { transform: scaleX(-1); }
.vf-top {
  position: absolute; top: 12px; left: 12px; right: 12px;
  display: flex; justify-content: flex-start; z-index: 2;
}
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  max-width: 100%;
  padding: 6px 10px; border-radius: 999px;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(10px);
  font-size: 11px; color: #e8edf2;
  border: 1px solid rgba(255,255,255,0.08);
}
.pill .dot {
  width: 7px; height: 7px; border-radius: 50%; background: #ffb020;
  box-shadow: 0 0 0 3px rgba(255,176,32,0.18);
  flex-shrink: 0;
}
.pill.is-ok .dot { background: var(--accent); box-shadow: 0 0 0 3px rgba(34,211,154,0.2); }
.pill.is-bad .dot { background: var(--danger); box-shadow: 0 0 0 3px rgba(255,93,106,0.2); }
#gps-pill-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.camera-error {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px; text-align: center;
  background: rgba(7,8,12,0.88); z-index: 4;
}
.camera-error p { margin: 0; color: var(--muted); line-height: 1.5; font-size: 14px; }

.live-watermark {
  position: absolute; left: 10px; right: 10px; bottom: 10px; z-index: 2;
  pointer-events: none;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(6,10,16,0.15), rgba(6,10,16,0.82) 30%, rgba(6,10,16,0.92));
  border-left: 4px solid var(--accent-in);
  padding: 10px 12px 10px 12px;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.55);
}
.live-watermark.is-out { border-left-color: var(--accent-out); }
.wm-badge {
  display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: 0.06em;
  padding: 2px 7px; border-radius: 6px; margin-bottom: 4px;
  background: var(--accent-in); color: #062318;
}
.live-watermark.is-out .wm-badge { background: var(--accent-out); color: #2a1c00; }
.wm-time { font-size: 26px; font-weight: 700; letter-spacing: 0.04em; line-height: 1.05; font-variant-numeric: tabular-nums; }
.wm-date { font-size: 12px; margin-top: 2px; opacity: 0.95; }
.wm-line { font-size: 11px; margin-top: 3px; color: #e6edf3; line-height: 1.35; }
.wm-line.dim { color: #c5ced6; }

.dock {
  padding: 12px 16px calc(16px + var(--safe-b));
  display: flex; flex-direction: column; gap: 12px;
}
.meta-row { display: flex; gap: 8px; }
.chip {
  display: flex; align-items: center; gap: 5px;
  padding: 8px 12px; border-radius: 12px;
  background: var(--card); border: 1px solid var(--line);
  font-size: 13px; color: var(--text);
  min-height: 42px;
}
.chip-grow { flex: 1; min-width: 0; justify-content: flex-start; }
.chip-k { color: var(--muted); font-size: 11px; flex-shrink: 0; }
.chip-v { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .sep { color: var(--muted); }
.chip.type-in { background: rgba(34,211,154,0.12); border-color: rgba(34,211,154,0.28); color: var(--accent-in); font-weight: 700; }
.chip.type-out { background: rgba(255,176,32,0.12); border-color: rgba(255,176,32,0.28); color: var(--accent-out); font-weight: 700; }

.shutter-row {
  display: flex; align-items: center; justify-content: space-around;
  padding: 4px 8px 0;
}
.round-btn {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--card); border: 1px solid var(--line);
  display: grid; place-items: center; color: var(--text);
}
.shutter {
  width: 76px; height: 76px; border-radius: 50%;
  background: #fff; padding: 6px;
  box-shadow: 0 0 0 4px rgba(255,255,255,0.14), 0 8px 24px rgba(0,0,0,0.35);
}
.shutter-inner {
  display: block; width: 100%; height: 100%; border-radius: 50%;
  background: #fff; border: 3px solid var(--bg);
}
.shutter:active { transform: scale(0.96); }
.shutter:disabled { opacity: 0.45; }
.hint { margin: 0; text-align: center; font-size: 11px; color: var(--muted); }

.backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,0.55);
  z-index: 20;
}
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 21;
  background: #161b22;
  border-radius: 20px 20px 0 0;
  padding: 8px 20px calc(20px + var(--safe-b));
  box-shadow: 0 -12px 40px rgba(0,0,0,0.4);
}
.sheet[hidden], .backdrop[hidden] { display: none !important; }
.sheet-handle {
  width: 40px; height: 4px; border-radius: 4px; background: #3a4450;
  margin: 6px auto 12px;
}
.sheet h2 { margin: 0 0 16px; font-size: 18px; }
.field { margin-bottom: 14px; }
.label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.input {
  width: 100%; height: 48px; border-radius: 12px;
  border: 1px solid var(--line); background: #0e1218; color: var(--text);
  padding: 0 14px; font-size: 16px; outline: none;
}
.input:focus { border-color: var(--accent); }
.field-note { margin: -4px 0 16px; font-size: 12px; color: var(--muted); }
.segmented {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.seg {
  height: 44px; border-radius: 12px;
  background: #0e1218; border: 1px solid var(--line);
  font-size: 15px; font-weight: 650; color: var(--muted);
}
.seg.is-on[data-type="in"] { background: rgba(34,211,154,0.16); border-color: var(--accent-in); color: var(--accent-in); }
.seg.is-on[data-type="out"] { background: rgba(255,176,32,0.16); border-color: var(--accent-out); color: var(--accent-out); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 48px; padding: 0 18px; border-radius: 14px;
  font-size: 15px; font-weight: 650;
}
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: #062318; }
.btn-secondary { background: var(--card); color: var(--text); border: 1px solid var(--line); }
.preview-actions { display: grid; grid-template-columns: 1fr 1.3fr; gap: 10px; }
.preview-wrap {
  flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center;
  padding: 0 12px 8px;
}
#preview-image {
  max-width: 100%; max-height: 100%;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.history-list {
  list-style: none; margin: 0; padding: 0 14px calc(20px + var(--safe-b));
  overflow: auto; flex: 1;
}
.history-item {
  display: grid; grid-template-columns: 84px 1fr auto; gap: 12px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.history-item img {
  width: 84px; height: 84px; object-fit: cover; border-radius: 12px; background: #000;
}
.hist-type { font-weight: 700; font-size: 14px; }
.hist-type.in { color: var(--accent-in); }
.hist-type.out { color: var(--accent-out); }
.hist-meta { font-size: 12px; color: var(--muted); margin-top: 3px; line-height: 1.45; }
.hist-del {
  width: 36px; height: 36px; border-radius: 10px;
  background: rgba(255,93,106,0.1); color: var(--danger);
  display: grid; place-items: center; border: 0; cursor: pointer;
}
.empty { flex: 1; display: grid; place-items: center; padding: 40px 28px; text-align: center; color: var(--muted); }

.toast {
  position: absolute; left: 50%; bottom: calc(28px + var(--safe-b));
  transform: translateX(-50%);
  background: rgba(20,24,32,0.95);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 16px; border-radius: 999px;
  font-size: 13px; z-index: 40;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  white-space: nowrap;
}
.toast[hidden] { display: none !important; }

.vf-top { flex-wrap: wrap; gap: 6px; }
#server-pill.is-ok .dot { background: var(--blue); box-shadow: 0 0 0 3px rgba(77,163,255,0.2); }
.preview-wrap { flex-direction: column; }
.preview-flags { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 10px; min-height: 0; }
.flag {
  font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px;
}
.flag-late, .flag-early, .flag-missing, .flag-geo, .flag-timeskew {
  background: rgba(255,93,106,0.16); color: #ff8b94;
}
.flag-ok { background: rgba(34,211,154,0.16); color: var(--accent-in); }
.flag-pending { background: rgba(255,176,32,0.16); color: var(--accent-out); }
.upload-status { margin: 8px 0 0; text-align: center; font-size: 12px; color: var(--muted); }
.upload-status.is-err { color: var(--danger); }
.upload-status.is-ok { color: var(--accent-in); }

.camera-error[hidden] { display: none !important; }
.camera-error { overflow-y: auto; }
.ce-title { font-size: 17px !important; font-weight: 700; color: var(--text) !important; }
.ce-text { max-width: 320px; }
.ce-help {
  max-width: 330px; text-align: left; font-size: 13px; line-height: 1.6; color: #d7dee5;
  background: rgba(255,255,255,0.06); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
}
.ce-help ol { margin: 4px 0 0; padding-left: 18px; }
.ce-help b { color: var(--accent); }
.camera-error .btn { width: 100%; max-width: 280px; }


/* ---- v1.1: four punch types, location retry, preview actions ---- */
:root { --accent-bin: #4da3ff; --accent-bout: #b084ff; }
.type-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.tbtn {
  height: 40px; border-radius: 12px; padding: 0 4px;
  background: var(--card); border: 1px solid var(--line);
  font-size: 13px; font-weight: 650; color: var(--muted);
}
.tbtn.is-on[data-type="in"] { background: rgba(34,211,154,0.16); border-color: var(--accent-in); color: var(--accent-in); }
.tbtn.is-on[data-type="out"] { background: rgba(255,176,32,0.16); border-color: var(--accent-out); color: var(--accent-out); }
.tbtn.is-on[data-type="break_in"] { background: rgba(77,163,255,0.16); border-color: var(--accent-bin); color: var(--accent-bin); }
.tbtn.is-on[data-type="break_out"] { background: rgba(176,132,255,0.16); border-color: var(--accent-bout); color: var(--accent-bout); }
.segmented { grid-template-columns: 1fr 1fr; }
.seg.is-on[data-type="break_in"] { background: rgba(77,163,255,0.16); border-color: var(--accent-bin); color: var(--accent-bin); }
.seg.is-on[data-type="break_out"] { background: rgba(176,132,255,0.16); border-color: var(--accent-bout); color: var(--accent-bout); }
.live-watermark.t-out { border-left-color: var(--accent-out); }
.live-watermark.t-break_in { border-left-color: var(--accent-bin); }
.live-watermark.t-break_out { border-left-color: var(--accent-bout); }
.live-watermark.t-out .wm-badge { background: var(--accent-out); color: #2a1c00; }
.live-watermark.t-break_in .wm-badge { background: var(--accent-bin); color: #04182f; }
.live-watermark.t-break_out .wm-badge { background: var(--accent-bout); color: #1c0c38; }
.hist-type.break_in { color: var(--accent-bin); }
.hist-type.break_out { color: var(--accent-bout); }
.pill-btn { border: 1px solid rgba(255,93,106,0.5); color: #ffb3b9; background: rgba(255,93,106,0.18); font-weight: 700; }
.pill-btn[hidden] { display: none !important; }
.pill.is-bad { cursor: pointer; }
.btn[hidden] { display: none !important; }
.preview-actions { display: flex; flex-direction: row; gap: 8px; grid-template-columns: none; }
.preview-actions .btn { flex: 1; padding: 0 8px; font-size: 14px; white-space: nowrap; }
.preview-actions #btn-upload, .preview-actions #btn-done { flex: 1.4; }
.preview-actions .btn:disabled { opacity: 0.55; }
.flag-geofence, .flag-locmissing, .flag-overbreak { background: rgba(255,93,106,0.16); color: #ff8b94; }
.flag-warn { background: rgba(255,176,32,0.16); color: var(--accent-out); }
.review-note { margin: 8px 6px 0; font-size: 12.5px; line-height: 1.5; color: var(--muted); text-align: center; }
.review-note.is-warn { color: var(--accent-out); }
/* location pill + retry stay tappable above the camera start/error overlay */
.vf-top { z-index: 6; pointer-events: none; }
.vf-top .pill { pointer-events: auto; }

/* ---- v1.2: store / nearby-shop picker ---- */
.chip .chev { margin-left: auto; color: var(--muted); font-size: 18px; }
.place-body { flex: 1; overflow-y: auto; padding: 4px 14px 12px; -webkit-overflow-scrolling: touch; }
.place-body .type-row { margin-top: 4px; }
.place-map { margin-top: 10px; border-radius: 16px; overflow: hidden; border: 1px solid var(--line); }
.place-map[hidden] { display: none !important; }
#place-map { height: 210px; background: #1a2230; }
.place-head { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; }
.place-head h3 { margin: 0 2px; font-size: 17px; }
.place-body .sub { margin: 2px 2px 8px; font-size: 12.5px; color: var(--muted); }
.place-list { display: flex; flex-direction: column; gap: 7px; }
.place-row {
  display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: 12px; text-align: left;
  background: var(--card); border: 1px solid var(--line); color: var(--text); font-size: 15px; width: 100%;
}
.place-row.sel { border-color: var(--accent); background: rgba(34,211,154,0.10); }
.place-row .radio { width: 20px; height: 20px; border-radius: 50%; border: 2px solid #5b6879; display: grid; place-items: center; flex: none; }
.place-row.sel .radio { border-color: var(--accent); }
.place-row .radio i { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.pr-name { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.pr-name small { color: var(--muted); font-weight: 400; margin-left: 6px; font-size: 12px; }
.pr-name em { font-style: normal; font-size: 11px; font-weight: 700; color: var(--accent); background: rgba(34,211,154,0.14); border-radius: 6px; padding: 1px 6px; margin-left: 6px; }
.pr-d { color: var(--muted); font-size: 13px; flex: none; }
.place-row.sel .pr-d { color: var(--accent); font-weight: 700; }
.place-skel { height: 46px; border-radius: 12px; background: linear-gradient(90deg, var(--card), #212a36, var(--card)); background-size: 200% 100%; animation: skel 1.2s linear infinite; }
@keyframes skel { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.link-btn { margin: 12px auto 4px; display: block; background: none; border: 0; color: var(--blue); font-weight: 700; font-size: 14px; padding: 8px; }
.link-btn[hidden], .place-manual[hidden], .place-retry[hidden] { display: none !important; }
.place-manual { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.place-manual select, .place-manual input { width: 100%; }
.place-manual [hidden] { display: none !important; }
.place-retry { width: 100%; margin-top: 10px; height: 40px; }
.place-actions { display: flex; flex-direction: row; gap: 10px; }
.place-actions .btn { height: 50px; font-size: 16px; }
.place-actions .btn-secondary { flex: 1; }
.place-actions .btn-primary { flex: 2; }
.place-actions .btn:disabled { opacity: 0.45; }
.pin-icon { background: none; border: 0; }
.leaflet-container { font-family: var(--font); background: #1a2230; }
.poi-tip { background: rgba(7,8,12,0.9); color: #fff; border: 1px solid var(--accent); font-weight: 700; font-size: 12px; }
.poi-tip::before { display: none; }
#screen-place .topbar .pill { position: static; }
.place-loc-row {
  display: flex; align-items: center; gap: 8px;
  margin: 4px 0 8px;
}
.place-loc-row .pill { flex: 1; min-width: 0; }
.place-loc-row .place-retry {
  width: auto; min-width: 96px; height: 36px; margin-top: 0;
  padding: 0 12px; flex-shrink: 0;
}

#outlet-dialog {
  width: min(92vw, 440px);
  max-height: 85vh;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  color: var(--text);
  background: var(--bg);
}
#outlet-dialog::backdrop { background: rgba(0,0,0,0.65); }
#outlet-dialog h2 { margin: 0 0 12px; font-size: 18px; }
#outlet-status { margin: 8px 0; }
#outlet-status:empty { margin: 0; }
#outlet-list { margin-top: 8px; }
#outlet-list .pr-name, .wm-line { overflow-wrap: anywhere; }
#outlet-list small { flex: none; color: var(--muted); }
#outlet-dialog .btn { margin-top: 12px; }
.meta-row .chip { min-width: 0; }
#btn-open-form { max-width: 33%; }
.toast { max-width: 94%; white-space: normal; text-align: center; }
