:root {
  --bg: #eef2f6;
  --card: #ffffff;
  --ink: #101828;
  --muted: #667085;
  --line: #d5dbe3;
  --accent: #0b5ed7;
  --accent-dark: #0a4cb0;
  --accent-soft: #e8f0fe;
  --ok: #0f7a4d;
  --ok-soft: #e6f6ee;
  --warn: #b54708;
  --warn-soft: #fff3e6;
  --danger: #b42318;
  --danger-soft: #fdeceb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 6px 18px rgba(16, 24, 40, .05);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -.01em;
  flex: 1;
  min-width: 0;
}
.brand span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-mark {
  display: block;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  flex-shrink: 0;
}
.iconbtn svg { display: block; }
.topbar-right { display: flex; align-items: center; gap: 6px; }

.iconbtn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  font-size: 18px;
  line-height: 1;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.iconbtn:active { background: #eef2f6; }
.iconbtn.danger { color: var(--danger); font-size: 15px; }

.net-badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--ok-soft);
  color: var(--ok);
  white-space: nowrap;
}
.net-badge.offline { background: var(--warn-soft); color: var(--warn); }

/* ---------- layout ---------- */
.view {
  max-width: 760px;
  margin: 0 auto;
  padding: 14px 14px calc(96px + env(safe-area-inset-bottom));
}
.view.no-nav { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

.page-head { margin: 4px 2px 14px; }
.page-head h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.page-head .sub { color: var(--muted); font-size: 13.5px; margin-top: 3px; }
.eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent);
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}
.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.card-head h2 {
  flex: 1;
  margin: 0;
  font-size: 15.5px;
  display: flex;
  align-items: center;
  gap: 9px;
  letter-spacing: -.01em;
}
.secnum {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: 7px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
}

/* ---------- forms ---------- */
.field { display: block; margin-bottom: 12px; }
.field > span {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: #344054;
  margin-bottom: 5px;
}
.req { color: var(--danger); }
input[type="text"], input[type="password"], input[type="number"], input[type="search"], textarea, select {
  width: 100%;
  min-height: 46px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  outline: none;
  appearance: none;
}
textarea { min-height: 72px; resize: vertical; }
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 36px;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11, 94, 215, .14);
}
input:disabled, textarea:disabled, select:disabled {
  background: #f8fafc;
  color: #475467;
  -webkit-text-fill-color: #475467;
  opacity: 1;
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row .field { margin-bottom: 0; }

/* ---------- buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  font-weight: 650;
  min-height: 46px;
  padding: 10px 16px;
  border-radius: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-dark); }
.btn.ghost { background: #fff; }
.btn.danger { color: var(--danger); border-color: #f4c7c3; background: var(--danger-soft); }
.btn.small { min-height: 38px; padding: 7px 12px; font-size: 13.5px; border-radius: 9px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; }

.actions { display: grid; gap: 9px; }
.actions .btn { width: 100%; }
.add-grid { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- pills & hints ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .02em;
  white-space: nowrap;
}
.pill.draft { background: #eef2f6; color: #475467; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.error { background: var(--danger-soft); color: var(--danger); }
.pill.sync { background: var(--accent-soft); color: var(--accent-dark); }

.sync-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 9px 12px;
  border-radius: 10px;
  margin-bottom: 12px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--muted);
}
.sync-hint.ok { background: var(--ok-soft); border-color: #bfe7d2; color: var(--ok); }
.sync-hint.warn { background: var(--warn-soft); border-color: #f5d6b5; color: var(--warn); }
.sync-hint.error { background: var(--danger-soft); border-color: #f4c7c3; color: var(--danger); }
.sync-hint.info { background: var(--accent-soft); border-color: #c6d9fb; color: var(--accent-dark); }

.small { font-size: 12.5px; color: var(--muted); }
.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.link { color: var(--accent); text-decoration: none; }
.link:active { text-decoration: underline; }

/* ---------- list ---------- */
.search-wrap { margin-bottom: 12px; }
.search-wrap input { background: #fff; }

.survey-card {
  width: 100%;
  text-align: left;
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 13px 14px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.survey-card:active { background: #f8fafc; }
.survey-main { flex: 1; min-width: 0; }
.survey-title {
  font-weight: 700;
  font-size: 15.5px;
  letter-spacing: -.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.survey-meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.survey-side { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; flex-shrink: 0; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 18px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .6);
}
.empty strong { display: block; color: var(--ink); margin-bottom: 4px; font-size: 16px; }
.empty .btn { margin-top: 14px; }

.list-toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.list-toolbar .btn { flex: 1; }

/* ---------- GPS ---------- */
.gps-box {
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #f8fafc;
  padding: 11px 12px;
  margin-bottom: 12px;
}
.gps-row { display: flex; align-items: center; gap: 10px; }
.gps-row > div:first-child { flex: 1; min-width: 0; }
.gps-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.coord { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.manual { margin-top: 10px; }
.manual summary { font-size: 12.5px; color: var(--accent); cursor: pointer; }
.manual .row { margin-top: 8px; }

/* ---------- photos ---------- */
.photo-block { margin-top: 4px; }
.photo-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 12.5px;
  font-weight: 600;
  color: #344054;
  margin-bottom: 7px;
}
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.photo {
  position: relative;
  margin: 0;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  background: #e4e9ef;
  border: 1px solid var(--line);
}
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 999px;
  background: rgba(16, 24, 40, .72);
  color: #fff;
  font-size: 17px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.photo-add {
  aspect-ratio: 1 / 1;
  border: 1.5px dashed #b6c0cc;
  border-radius: 10px;
  background: #fbfcfd;
  color: #475467;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 20px;
  cursor: pointer;
}
.photo-add span { font-size: 11.5px; font-weight: 600; }
.photo-add svg { width: 24px; height: 24px; }
.photo-add:active { background: #eef2f6; }

/* ---------- bottom nav ---------- */
.bottombar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  gap: 6px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.navbtn {
  flex: 1;
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 11px;
  min-height: 46px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 650;
  color: #344054;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
}
.navbtn.primary { background: var(--accent); color: #fff; }
.navbtn:active { background: #eef2f6; }
.navbtn.primary:active { background: var(--accent-dark); }
.badge {
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--warn);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ---------- login ---------- */
.login-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(1200px 500px at 50% -10%, #dbe9ff 0%, transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 10px 36px rgba(16, 24, 40, .10);
  padding: 22px;
}
.login-logo {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  background: var(--accent);
  overflow: hidden;
  margin-bottom: 14px;
}
.login-logo img { display: block; width: 100%; height: 100%; object-fit: cover; }
.login-card h1 { margin: 0 0 3px; font-size: 21px; letter-spacing: -.02em; }
.login-card .sub { color: var(--muted); font-size: 13.5px; margin-bottom: 18px; }
.login-note {
  font-size: 12.5px;
  color: var(--muted);
  padding: 9px 11px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 9px;
  margin-top: 12px;
}
.login-error { color: var(--danger); font-size: 13px; margin: 10px 0 0; }

/* ---------- toast / overlay ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(92vw, 460px);
  padding: 11px 15px;
  border-radius: 11px;
  background: #101828;
  color: #fff;
  font-size: 13.5px;
  font-weight: 550;
  box-shadow: 0 10px 30px rgba(16, 24, 40, .28);
  text-align: center;
}
.toast.ok { background: var(--ok); }
.toast.warn { background: var(--warn); }
.toast.error { background: var(--danger); }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(16, 24, 40, .55);
  backdrop-filter: blur(2px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}
.spinner {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 3px solid rgba(255, 255, 255, .3);
  border-top-color: #fff;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.notice {
  font-size: 12.5px;
  color: var(--warn);
  background: var(--warn-soft);
  border: 1px solid #f5d6b5;
  border-radius: 9px;
  padding: 8px 10px;
  margin-bottom: 12px;
}

@media (min-width: 700px) {
  .photo-grid { grid-template-columns: repeat(4, 1fr); }
  .actions { grid-template-columns: 1fr 1fr; }
}
