:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-strong: #f9fbfd;
  --text: #17202f;
  --muted: #647084;
  --line: #d9e1ea;
  --primary: #0f766e;
  --primary-strong: #0b5f59;
  --primary-soft: #e3f4f1;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --shadow: 0 16px 38px rgba(25, 39, 62, 0.08);
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.45;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.3);
  outline-offset: 2px;
}

.app-shell {
  width: min(100%, 820px);
  margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) 12px calc(22px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: -10px -12px 10px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: rgba(246, 248, 251, 0.94);
  border-bottom: 1px solid rgba(217, 225, 234, 0.86);
  backdrop-filter: blur(14px);
}

.topbar-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.18;
}

h2 {
  font-size: 17px;
  line-height: 1.25;
}

h3 {
  font-size: 15px;
  line-height: 1.3;
}

main {
  display: grid;
  gap: 10px;
}

.panel,
.camera-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}


.section-head,
.camera-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-head {
  margin-bottom: 10px;
}

.status-pill {
  flex: 0 0 auto;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0 10px;
  color: var(--primary-strong);
  background: var(--primary-soft);
  font-size: 12px;
  font-weight: 700;
}

.field-block {
  display: grid;
  gap: 8px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.field-block:first-of-type {
  border-top: 0;
  padding-top: 0;
}

label,
legend {
  color: #2d3a4d;
  font-size: 13px;
  font-weight: 700;
}

.inline-control,
.location-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: stretch;
}

.readonly-value {
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--muted);
  font-weight: 700;
  word-break: break-all;
}

.readonly-value.has-value {
  color: var(--text);
  background: #eefaf7;
  border-color: #a7d8d0;
}

.coordinate-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.coordinate-grid > div {
  min-height: 54px;
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.coordinate-grid span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.coordinate-grid strong {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.primary-action,
.secondary-action,
.ghost-action,
.clear-action,
.add-action,
.icon-button {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 800;
}

.primary-action {
  flex: 0 0 auto;
  min-width: 104px;
  padding: 0 12px;
  color: #fff;
  background: var(--primary);
  box-shadow: 0 10px 18px rgba(15, 118, 110, 0.18);
}

.primary-action:active,
.secondary-action:active,
.clear-action:active,
.add-action:active {
  transform: translateY(1px);
}

.secondary-action {
  min-width: 82px;
  padding: 0 12px;
  color: #fff;
  background: #1d4ed8;
}

.ghost-action {
  padding: 0 12px;
  color: var(--primary-strong);
  background: var(--primary-soft);
}

.clear-action {
  min-width: 78px;
  padding: 0 12px;
  color: var(--danger);
  background: var(--danger-soft);
}

.ghost-action:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.helper-text {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.camera-list {
  display: grid;
  gap: 10px;
}

.camera-card {
  padding: 12px;
  box-shadow: none;
}

.camera-card-head {
  margin-bottom: 10px;
}

.icon-button {
  width: 44px;
  padding: 0;
  color: var(--muted);
  background: #eef2f7;
}

.icon-button.danger {
  color: var(--danger);
  background: var(--danger-soft);
}

.camera-card:first-child .remove-camera {
  visibility: hidden;
}

.form-grid {
  display: grid;
  gap: 10px;
}

.input-field {
  position: relative;
  display: grid;
  gap: 6px;
}

.input-field input {
  width: 100%;
  min-height: 44px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--text);
}

.input-field input::placeholder {
  color: #8a96a8;
}

.suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 5;
  max-height: 278px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 18px 30px rgba(24, 35, 56, 0.15);
}

.suggestions button {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-bottom: 1px solid #edf1f5;
  padding: 9px 12px;
  color: var(--text);
  background: #fff;
  text-align: left;
}

.suggestions button:last-child {
  border-bottom: 0;
}

.suggestions button:active {
  background: var(--primary-soft);
}

.type-field {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0 0;
  padding: 0;
  border: 0;
}

.type-field legend {
  grid-column: 1 / -1;
  margin-bottom: 4px;
}

.type-field label {
  min-width: 0;
}

.type-field input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.type-field span {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: #314055;
  background: var(--surface-strong);
  font-size: 14px;
  font-weight: 800;
}

.type-field label:has(input[value="替换"]:checked) span {
  border-color: #0f766e;
  color: #0b5f59;
  background: #dff7ef;
}

.type-field label:has(input[value="新增"]:checked) span {
  border-color: #1d4ed8;
  color: #1e40af;
  background: #e3edff;
}

.type-field label:has(input[value="老设备"]:checked) span {
  border-color: #b45309;
  color: #92400e;
  background: #fff1d6;
}

.add-action {
  width: 100%;
  margin-top: 10px;
  color: #fff;
  background: var(--primary);
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: end center;
  padding: 14px;
  background: rgba(12, 20, 32, 0.55);
}

.sheet[hidden] {
  display: none !important;
}

.sheet-panel {
  width: min(100%, 760px);
  max-height: calc(100dvh - 28px);
  overflow: auto;
  padding: 14px;
  border-radius: 12px 12px var(--radius) var(--radius);
  background: var(--surface);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.28);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.video-wrap {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  background: #0b1020;
  aspect-ratio: 4 / 3;
}

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.scan-frame {
  position: absolute;
  inset: 28% 12%;
  border: 2px solid #fff;
  border-radius: var(--radius);
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.28);
}

.scan-status {
  min-height: 24px;
  margin: 12px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.toast {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 80;
  display: none;
  max-width: 520px;
  margin: 0 auto;
  padding: 12px 14px;
  border-radius: var(--radius);
  color: #fff;
  background: #17202f;
  box-shadow: 0 16px 34px rgba(23, 32, 47, 0.22);
  font-weight: 800;
}

.toast.show {
  display: block;
}

@media (min-width: 720px) {
  .app-shell {
    padding-top: calc(14px + env(safe-area-inset-top));
  }

  .topbar {
    margin: -14px -12px 12px;
  }

  .panel {
    padding: 14px;
  }

  .form-grid {
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .primary-action,
  .secondary-action,
  .clear-action,
  .add-action,
  .toast {
    transition: transform 160ms ease, opacity 160ms ease;
  }
}
