:root {
  --bg: #eef2f7;
  --bg-2: #e4ebf5;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #dbe3ee;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --yellow: #d97706;
  --yellow-soft: #fffbeb;
  --green: #16a34a;
  --green-soft: #f0fdf4;
  --shadow: 0 10px 30px rgba(15, 23, 42, .06);
  --radius: 18px;
  --safe-bottom: calc(86px + env(safe-area-inset-bottom));
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  background:
    radial-gradient(900px 400px at 20% -10%, rgba(37, 99, 235, .10), transparent 60%),
    radial-gradient(700px 400px at 100% 0%, rgba(22, 163, 74, .07), transparent 55%),
    linear-gradient(180deg, var(--bg), var(--bg-2));
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }

.hidden { display: none !important; }

.app {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 0 14px var(--safe-bottom);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 -14px 14px;
  padding: 14px 16px 10px;
  background: rgba(238, 242, 247, .9);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(219, 227, 238, .7);
}

.eyebrow {
  font-size: 9px;
  letter-spacing: .16em;
  color: var(--primary);
  font-weight: 700;
}

.topbar h1 {
  margin: 3px 0 0;
  font-size: 19px;
  letter-spacing: .01em;
}

.net-badge {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--green);
  background: var(--green-soft);
  border: 1px solid rgba(22, 163, 74, .22);
  padding: 5px 9px;
  border-radius: 999px;
  font-weight: 600;
}

.net-badge.offline {
  color: var(--red);
  background: var(--red-soft);
  border-color: rgba(220, 38, 38, .22);
}

.view { display: block; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.card-kicker {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.gps-status {
  margin-top: 4px;
  font-size: 14px;
  font-weight: 600;
}

.gps-status.error { color: var(--red); }
.gps-status.warn { color: var(--yellow); }
.gps-status.ok { color: var(--green); }

.coords {
  margin-top: 14px;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: clamp(20px, 5.8vw, 28px);
  font-weight: 700;
  letter-spacing: .01em;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

.loc-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.loc-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.pill.gps { background: #eff6ff; color: var(--primary); }
.pill.manual { background: var(--yellow-soft); color: var(--yellow); }

.manual-loc {
  margin-top: 12px;
  border-top: 1px dashed var(--line);
  padding-top: 10px;
}

.manual-loc summary {
  cursor: pointer;
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
}

.manual-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 0;
}

.manual-grid label:last-child { grid-column: 1 / -1; }

.manual-grid label,
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.manual-grid input,
.manual-grid select,
.field input,
.field select,
.field textarea,
.search {
  width: 100%;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 13px;
  font-size: 16px;
  color: var(--text);
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

.field textarea { resize: vertical; min-height: 62px; }

.manual-grid input:focus,
.manual-grid select:focus,
.field input:focus,
.field select:focus,
.field textarea:focus,
.search:focus {
  background: #fff;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .13);
}

.hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

.form-card { display: flex; flex-direction: column; gap: 17px; }

.label {
  font-size: 12px;
  font-weight: 600;
  color: #475569;
}

.label em {
  font-style: normal;
  color: #94a3b8;
  font-weight: 400;
}

.chips {
  display: grid;
  gap: 8px;
}

.movement-chips { grid-template-columns: repeat(4, 1fr); }

.chip {
  position: relative;
  border: 1.5px solid var(--line);
  background: #f8fafc;
  border-radius: 13px;
  color: #334155;
  transition: .15s ease;
  -webkit-tap-highlight-color: transparent;
}

.chip:active { transform: scale(.97); }

.chip.on {
  border-color: var(--primary);
  background: #eff6ff;
  color: var(--primary-dark);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.chip.on::after {
  content: "✓";
  position: absolute;
  top: 5px;
  right: 7px;
  font-size: 10px;
  font-weight: 800;
  color: var(--primary);
}

.move {
  height: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.move b { font-size: 20px; line-height: 1; font-weight: 700; }
.move span { font-size: 11px; }

.color-chips { grid-template-columns: repeat(3, 1fr); }

.color-chips .chip {
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
}

.color-chips .chip i {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: #cbd5e1;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .55);
}

.color-chips .chip.red i { background: var(--red); box-shadow: 0 0 10px rgba(220, 38, 38, .45); }
.color-chips .chip.yellow i { background: var(--yellow); box-shadow: 0 0 10px rgba(217, 119, 6, .4); }
.color-chips .chip.green i { background: var(--green); box-shadow: 0 0 10px rgba(22, 163, 74, .4); }
.color-chips .chip.flash i { background: repeating-linear-gradient(45deg, var(--yellow) 0 3px, #fff7d6 3px 6px); }
.color-chips .chip.off i { background: #475569; box-shadow: none; }

.color-chips .chip.red.on { background: var(--red-soft); border-color: var(--red); color: var(--red); box-shadow: 0 0 0 3px rgba(220, 38, 38, .12); }
.color-chips .chip.yellow.on { background: var(--yellow-soft); border-color: var(--yellow); color: var(--yellow); box-shadow: 0 0 0 3px rgba(217, 119, 6, .12); }
.color-chips .chip.green.on { background: var(--green-soft); border-color: var(--green); color: var(--green); box-shadow: 0 0 0 3px rgba(22, 163, 74, .12); }
.color-chips .chip.flash.on { background: var(--yellow-soft); border-color: var(--yellow); color: var(--yellow); box-shadow: 0 0 0 3px rgba(217, 119, 6, .12); }
.color-chips .chip.off.on { background: #f1f5f9; border-color: #64748b; color: #475569; box-shadow: 0 0 0 3px rgba(71, 85, 105, .1); }

.color-chips .chip.red.on::after,
.color-chips .chip.yellow.on::after,
.color-chips .chip.green.on::after,
.color-chips .chip.flash.on::after,
.color-chips .chip.off.on::after { color: currentColor; }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.big-number {
  text-align: center !important;
  font-size: 30px !important;
  font-weight: 800 !important;
  font-variant-numeric: tabular-nums;
  padding: 6px 8px !important;
  height: 56px;
}

.big-number::-webkit-outer-spin-button,
.big-number::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

.stepper {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.stepper button {
  height: 38px;
  border: 1px solid var(--line);
  background: #f8fafc;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  color: #475569;
  -webkit-tap-highlight-color: transparent;
}

.stepper button:active { background: #e2e8f0; }

.quick-row {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.quick-row button {
  flex: 1 1 auto;
  min-width: 36px;
  height: 30px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  font-size: 11px;
  color: var(--muted);
}

.quick-row button:active { background: #f1f5f9; }

.completeness {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 11px 12px;
}

.completeness-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
}

.completeness-head b { color: var(--text); font-variant-numeric: tabular-nums; }

.bar {
  height: 7px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
  margin: 8px 0 7px;
}

.bar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), #60a5fa);
  transition: width .2s ease;
}

.completeness.complete .bar i { background: linear-gradient(90deg, var(--green), #4ade80); }
.completeness p { margin: 0; color: var(--muted); font-size: 10.5px; line-height: 1.5; }

.form-actions {
  display: grid;
  grid-template-columns: 1fr 1.7fr;
  gap: 9px;
}

.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 700;
  background: #f1f5f9;
  color: #475569;
  -webkit-tap-highlight-color: transparent;
  transition: .15s ease;
}

.btn:active { transform: scale(.98); }

.btn.primary {
  background: linear-gradient(180deg, #3b82f6, var(--primary));
  border-color: var(--primary-dark);
  color: #fff;
  box-shadow: 0 6px 16px rgba(37, 99, 235, .22);
}

.btn.primary:active { background: var(--primary-dark); }

.btn.ghost {
  background: #fff;
  border-color: var(--line);
  color: #475569;
}

.btn.tiny {
  padding: 7px 10px;
  font-size: 11.5px;
  border-radius: 9px;
}

.btn.big { padding: 14px 16px; font-size: 16px; }

.save-hint {
  margin: -7px 0 0;
  color: var(--muted);
  font-size: 10.5px;
  text-align: center;
}

.nearby-teaser { padding-bottom: 13px; }

.nearby-mini {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nearby-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #f8fafc;
  padding: 9px 10px;
  font-size: 12px;
}

.nearby-item b { font-weight: 600; }
.nearby-item span { color: var(--muted); font-variant-numeric: tabular-nums; }

.records-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  margin: 4px 2px 12px;
}

.records-head h2 { margin: 3px 0 0; font-size: 20px; }

.filters {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-bottom: 10px;
}

.filter-chips { grid-template-columns: repeat(3, 1fr); }

.filter-chips .chip {
  height: 40px;
  font-size: 12px;
  font-weight: 600;
}

.filter-chips .chip.on::after { content: none; }

.search {
  height: 44px;
  background: #fff;
}

.records-summary {
  color: var(--muted);
  font-size: 11px;
  padding: 0 2px 9px;
  min-height: 18px;
}

.record-list { display: flex; flex-direction: column; gap: 10px; }

.record-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 13px 14px;
}

.record-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.record-site {
  font-size: 15.5px;
  font-weight: 700;
  line-height: 1.35;
  word-break: break-word;
}

.record-sub {
  color: var(--muted);
  font-size: 10.5px;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}

.badge {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.complete { background: var(--green-soft); color: var(--green); border: 1px solid rgba(22, 163, 74, .2); }
.badge.incomplete { background: var(--yellow-soft); color: var(--yellow); border: 1px solid rgba(217, 119, 6, .2); }
.badge.verified { background: #eff6ff; color: var(--primary); border: 1px solid rgba(37, 99, 235, .18); }

.record-values {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.value {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 8px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid var(--line);
  font-size: 11.5px;
  font-weight: 600;
}

.value .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #cbd5e1;
}

.dot.red { background: var(--red); }
.dot.yellow { background: var(--yellow); }
.dot.green { background: var(--green); }
.dot.flash { background: repeating-linear-gradient(45deg, var(--yellow) 0 2px, #fff 2px 4px); }
.dot.off { background: #64748b; }

.record-note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
  word-break: break-word;
}

.record-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 11px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}

.adj {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
}

.adj span {
  font-size: 10px;
  color: var(--muted);
  padding: 0 4px;
  white-space: nowrap;
}

.adj button {
  width: 38px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: #fff;
  color: #334155;
  font-size: 14px;
  font-weight: 800;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .06);
}

.adj button:active { background: #e2e8f0; }

.action {
  height: 40px;
  padding: 0 11px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: #475569;
  font-size: 11.5px;
  font-weight: 600;
}

.action.primary {
  background: #eff6ff;
  border-color: rgba(37, 99, 235, .25);
  color: var(--primary-dark);
}

.action:active { background: #f1f5f9; }

.empty {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 42px 20px;
  background: rgba(255, 255, 255, .6);
  border: 1px dashed var(--line);
  border-radius: 16px;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100%, 760px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 9px 14px calc(9px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(16px);
  z-index: 30;
}

.nav-item {
  position: relative;
  height: 52px;
  border: 0;
  border-radius: 13px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.nav-item span { font-size: 17px; font-weight: 400; }

.nav-item.on {
  color: var(--primary);
  background: #eff6ff;
}

.nav-count {
  position: absolute;
  top: 5px;
  right: calc(50% - 35px);
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 9px;
  font-style: normal;
  line-height: 17px;
  text-align: center;
}

.gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.gate-card {
  width: min(100%, 380px);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, .12);
  padding: 26px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.gate-icon { font-size: 28px; }

.gate-card h1 { margin: 0; font-size: 22px; }
.gate-card p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.gate-card code { background: #f1f5f9; padding: 1px 4px; border-radius: 4px; }

.gate-card input {
  width: 100%;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px 14px;
  font-size: 16px;
  outline: none;
}

.gate-card input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .13); }

.error {
  color: var(--red) !important;
  min-height: 16px;
  font-size: 11px !important;
}

.dialog {
  width: min(94vw, 560px);
  max-height: 88vh;
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: var(--card);
  color: var(--text);
  box-shadow: 0 30px 80px rgba(15, 23, 42, .3);
  overflow: hidden;
}

.dialog::backdrop { background: rgba(15, 23, 42, .48); backdrop-filter: blur(3px); }

.dialog-body {
  display: flex;
  flex-direction: column;
  gap: 13px;
  padding: 18px;
  max-height: 88vh;
  overflow-y: auto;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.dialog-head h2 { margin: 0; font-size: 18px; }

.icon-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: #f1f5f9;
  color: #475569;
  font-size: 20px;
  line-height: 1;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 9px;
  margin-top: 3px;
}

.edit-location {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  color: var(--muted);
  font-size: 11px;
  font-family: "Cascadia Code", Consolas, monospace;
  line-height: 1.55;
  word-break: break-all;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 11.5px;
  line-height: 1.5;
}

.history-item b { font-weight: 700; }
.history-item time { display: block; color: var(--muted); font-size: 10px; margin-top: 2px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom));
  transform: translate(-50%, 14px);
  max-width: min(90vw, 420px);
  background: rgba(15, 23, 42, .94);
  color: #fff;
  padding: 10px 15px;
  border-radius: 11px;
  font-size: 12px;
  line-height: 1.45;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
  z-index: 60;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 680px) {
  .app { padding-left: 20px; padding-right: 20px; }
  .topbar { margin-left: -20px; margin-right: -20px; padding-left: 22px; padding-right: 22px; }
  .card { padding: 19px; }
  .movement-chips { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .color-chips { grid-template-columns: repeat(5, 1fr); }
}

@media (max-width: 370px) {
  .two-col { grid-template-columns: 1fr; }
  .color-chips { grid-template-columns: repeat(2, 1fr); }
  .movement-chips { grid-template-columns: repeat(2, 1fr); }
}
