:root {
  --bg: #f8f8f8;
  --surface: #fff;
  --text: #171717;
  --text-secondary: #5c5c5c;
  --text-muted: #999;
  --border: #e8e8e8;
  --border-focus: #171717;
  --accent: #171717;
  --accent-hover: #333;
  --danger: #d32f2f;
  --danger-hover: #b71c1c;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 1px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.10);
  --max-width: 640px;
  --safe-bottom: env(safe-area-inset-bottom, 16px);
  --transition: 0.15s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-bottom);
  -webkit-tap-highlight-color: transparent;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.app-header {
  background: var(--accent);
  color: #fff;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 0 rgba(255,255,255,0.08) inset, 0 2px 8px rgba(0,0,0,0.12);
}
.app-header h1 {
  font-size: 1rem; font-weight: 600; letter-spacing: -0.02em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex-shrink: 1;
}
.header-actions { display: flex; gap: 2px; flex-shrink: 0; }

.app-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 20px;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: auto;
  letter-spacing: 0.02em;
}

#main-content {
  flex: 1;
  max-width: var(--max-width);
  width: 100%;
  margin: 0 auto;
  padding: 20px 16px 32px;
}

.page { display: none; animation: fadeIn 0.2s ease; }
.page.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.page-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}
.page-header h2 { flex: 1; font-size: 1.15rem; font-weight: 600; letter-spacing: -0.02em; }

.records-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.records-toolbar .search-wrap {
  flex: 1; min-width: 140px; position: relative;
}
.records-toolbar .search-wrap input {
  width: 100%; padding: 8px 12px 8px 32px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 0.85rem; font-family: inherit; background: var(--surface);
}
.records-toolbar .search-wrap input:focus { outline: none; border-color: var(--border-focus); }
.records-toolbar .search-wrap .search-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  font-size: 0.85rem; color: var(--text-muted); pointer-events: none;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
  overflow: hidden;
  transition: opacity 0.2s, filter 0.2s;
  box-shadow: var(--shadow-sm);
}
.card.disabled { opacity: 0.35; pointer-events: none; filter: grayscale(0.4); }

.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  background: #fafafa;
  border-bottom: 1px solid var(--border);
}
.card-header h2 { font-size: 0.95rem; font-weight: 600; letter-spacing: -0.01em; }
.card-body { padding: 20px; }

.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 24px;
  border: 1.5px solid transparent;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
  font-family: inherit;
  letter-spacing: -0.01em;
  position: relative;
  overflow: hidden;
  min-height: 48px;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.3; cursor: not-allowed; pointer-events: none; transform: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent-hover); }
.btn-outline { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-outline:active { background: #f5f5f5; border-color: #ccc; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:active { background: var(--danger-hover); }
.btn-link {
  background: none; border: none; color: var(--text-secondary);
  font-size: 0.85rem; font-weight: 500; cursor: pointer; text-decoration: underline;
  padding: 4px 8px; min-height: auto;
}
.btn-link:disabled { color: var(--text-muted); cursor: not-allowed; }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 8px 16px; font-size: 0.82rem; min-height: 40px; }
.btn-lg { padding: 16px 28px; font-size: 1rem; min-height: 56px; }
.btn-header {
  background: transparent; border: none; color: rgba(255,255,255,0.8);
  font-size: 0.8rem; padding: 5px 8px; font-weight: 500; min-height: auto;
  cursor: pointer; font-family: inherit; letter-spacing: 0.01em;
  border-radius: var(--radius); transition: all var(--transition); white-space: nowrap;
}
.btn-header:hover { color: #fff; background: rgba(255,255,255,0.1); }
.btn-header:active { background: rgba(255,255,255,0.18); }

.input-lg {
  width: 100%;
  padding: 13px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  margin-bottom: 10px;
  transition: border-color var(--transition), box-shadow var(--transition);
  background: var(--surface);
  font-family: inherit;
  color: var(--text);
  min-height: 48px;
}
.input-lg:focus { outline: none; border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(0,0,0,0.06); }
.input-lg:disabled { background: #f5f5f5; color: var(--text-muted); }
.input-lg::placeholder { color: var(--text-muted); }
.input-sm {
  padding: 10px 12px; border: 1.5px solid var(--border); border-radius: var(--radius);
  font-size: 0.9rem; width: calc(50% - 5px); font-family: inherit;
  min-height: 44px;
}
.input-sm:focus { outline: none; border-color: var(--border-focus); }
textarea.input-lg { resize: vertical; min-height: 80px; }

.field-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 16px 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.field-label:first-child { margin-top: 0; }
.field-label .required-mark { color: var(--danger); margin-left: 2px; font-weight: 700; }

.field-wrap { margin-bottom: 4px; }

.select-wrapper { display: flex; gap: 8px; align-items: center; }
.select-wrapper select { flex: 1; margin-bottom: 0; }

.gps-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.gps-status { font-size: 0.82rem; color: var(--text-secondary); }
.gps-status.success { color: var(--text); font-weight: 500; }
.gps-status.error { color: var(--danger); }
.gps-result {
  font-size: 0.9rem; color: var(--text); margin-bottom: 8px;
  padding: 10px 14px; background: #fafafa; border-radius: var(--radius);
  font-family: "SF Mono", "Menlo", "Consolas", monospace; letter-spacing: -0.01em;
}
.gps-accuracy-warn { color: var(--danger); font-size: 0.78rem; margin-left: 10px; }
.gps-manual { margin-bottom: 6px; }
.gps-manual .input-sm { margin: 4px; }

.photo-area { margin-top: 4px; }
.photo-preview { margin-top: 10px; text-align: center; }
.photo-preview img {
  max-width: 100%; max-height: 300px; border-radius: var(--radius);
  border: 1px solid var(--border); object-fit: cover; cursor: pointer;
  transition: transform var(--transition);
}
.photo-preview img:hover { transform: scale(1.01); }
.photo-preview .btn { margin-top: 8px; }

.hint { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }

.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #fff; padding: 12px 24px;
  border-radius: var(--radius-lg); font-size: 0.9rem; font-weight: 500;
  z-index: 999; box-shadow: var(--shadow-lg);
  transition: opacity 0.2s, transform 0.2s;
  max-width: 90vw; text-align: center; pointer-events: none;
}
.toast.success { background: #171717; }
.toast.error { background: #c0392b; }
.toast.warning { background: #555; }

.records-list { display: flex; flex-direction: column; gap: 10px; }
.empty-state { text-align: center; color: var(--text-muted); padding: 60px 16px; font-size: 0.9rem; }

.record-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
  box-shadow: var(--shadow-sm); transition: box-shadow var(--transition);
}
.record-item:hover { box-shadow: var(--shadow); }

.record-item .record-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; background: #fafafa; border-bottom: 1px solid var(--border);
}
.record-item .record-id { font-weight: 700; font-size: 0.95rem; color: var(--text); }
.record-item .record-body { padding: 14px 18px; font-size: 0.85rem; line-height: 1.7; color: var(--text-secondary); }
.record-item .record-body img {
  max-width: 100%; max-height: 200px; border-radius: var(--radius);
  margin-top: 8px; cursor: pointer; transition: opacity var(--transition);
}
.record-item .record-body img:hover { opacity: 0.85; }
.record-item .record-actions { padding: 8px 18px 14px; display: flex; gap: 8px; flex-wrap: wrap; }

.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,0.92); z-index: 300;
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.15s ease;
}
.lightbox img { max-width: 95vw; max-height: 95vh; border-radius: 4px; object-fit: contain; }
.lightbox .lightbox-close {
  position: absolute; top: 16px; right: 20px;
  color: #fff; font-size: 2rem; cursor: pointer;
  background: none; border: none; width: 48px; height: 48px;
  display: flex; align-items: center; justify-content: center;
  opacity: 0.8; transition: opacity var(--transition);
}
.lightbox .lightbox-close:hover { opacity: 1; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 200;
  animation: fadeIn 0.15s ease;
}
.modal-card {
  background: var(--surface); border-radius: var(--radius-lg);
  padding: 24px; width: 90%; max-width: 380px; box-shadow: var(--shadow-lg);
}
.modal-card h3 { margin-bottom: 14px; font-size: 1rem; font-weight: 600; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; justify-content: flex-end; }

.template-actions { display: flex; gap: 10px; margin-top: 16px; }

.template-field-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px; background: #fafafa;
}
.template-field-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.template-field-row label { font-size: 0.75rem; color: var(--text-muted); font-weight: 600; min-width: 36px; text-transform: uppercase; letter-spacing: 0.04em; }
.template-field-row input,
.template-field-row select {
  font-size: 0.82rem; padding: 6px 10px; border: 1px solid var(--border);
  border-radius: var(--radius); font-family: inherit; background: var(--surface);
}
.template-field-row input:focus,
.template-field-row select:focus { outline: none; border-color: var(--border-focus); }
.template-field-row input[type="text"] { flex: 1; min-width: 80px; }
.template-field-row select { min-width: 90px; }
.template-field-card .field-options-textarea {
  width: 100%; font-size: 0.82rem; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-family: inherit; resize: vertical; min-height: 56px; background: var(--surface);
}
.template-field-card .field-options-textarea:focus { outline: none; border-color: var(--border-focus); }
.template-field-card .btn-remove-field {
  font-size: 0.75rem; padding: 4px 10px; color: var(--danger);
  background: none; border: 1px solid var(--danger); border-radius: var(--radius);
  cursor: pointer; font-weight: 600;
}
.template-field-card .btn-remove-field:active { background: var(--danger); color: #fff; }
.toggle-wrap { display: flex; align-items: center; gap: 5px; font-size: 0.78rem; color: var(--text-secondary); }
.toggle-wrap input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent); }

.hidden { display: none !important; }

@media (min-width: 768px) {
  #main-content { padding: 36px 20px 40px; }
  .app-header { padding: 16px 28px; }
  .app-header h1 { font-size: 1.2rem; }
  .card-body { padding: 24px 28px; }
  .card-header { padding: 18px 28px; }
  .input-lg { font-size: 1rem; padding: 14px 18px; }
  .photo-preview img { max-height: 400px; }
  .record-item .record-body {
    display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
  }
  .record-item .record-body img { grid-column: 2; grid-row: 1 / 4; max-height: 220px; }
}

@media print {
  .app-header, .app-footer, .btn, .header-actions, .records-toolbar, .record-actions { display: none; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
}
