/* Field Survey PWA — mobile-first, thao tác bằng ngón tay ngoài hiện trường */
:root {
  --bg: #eef6f3;
  --bg-accent: #d9efe8;
  --surface: #ffffff;
  --ink: #12241f;
  --muted: #4d675f;
  --line: #d5e5df;
  --primary: #0f6e62;
  --primary-dark: #0b544b;
  --primary-soft: #e3f5f1;
  --accent: #d97706;
  --danger: #b42318;
  --success: #157347;
  --info: #0b6e99;
  --shadow: 0 10px 30px rgba(16, 52, 44, 0.08);
  --radius: 18px;
  --nav-h: 68px;
  --header-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
}

body {
  padding-top: var(--safe-t);
}

a {
  color: var(--primary);
  text-decoration: none;
}

h1, h2, h3 {
  line-height: 1.2;
  margin: 0 0 0.4rem;
}

p {
  margin: 0 0 0.75rem;
  color: var(--muted);
}

img {
  max-width: 100%;
}

#app {
  min-height: 100vh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--header-h);
  padding: 10px 16px;
  background: #0c3d36;
  color: #fff;
}

.app-header a {
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mode-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  background: #d9efe8;
  color: #0b544b;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.mode-pill.is-app {
  background: #fde68a;
  color: #78350f;
}

.header-settings {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff !important;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.network-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #d8ffe9;
  font-size: 13px;
  font-weight: 600;
}

.network-pill .dot,
.network-pill.is-offline .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.2);
}

.network-pill.is-offline {
  color: #ffe4e6;
  background: rgba(180, 35, 24, 0.28);
}

.network-pill.is-offline .dot {
  background: #fb7185;
  box-shadow: 0 0 0 4px rgba(251, 113, 133, 0.18);
}

#offline-banner {
  margin: 0;
  padding: 10px 16px;
  background: #fff4e5;
  color: #9a3412;
  font-size: 14px;
}

#view {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + var(--safe-b) + 20px);
}

.page-header {
  margin-bottom: 16px;
}

.hero {
  padding: 8px 2px 18px;
}

.hero h1 {
  font-size: 2rem;
}

.brand-kicker,
.card-kicker {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.ghost-link {
  color: var(--muted);
  font-size: 14px;
}

.stack {
  display: grid;
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.survey-card h3,
.list-row h3 {
  margin-bottom: 6px;
}

.card-meta {
  display: flex;
  gap: 12px;
  margin: 10px 0 14px;
  color: var(--muted);
  font-size: 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 12px 16px;
  border: 0;
  border-radius: 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
}

.btn-secondary {
  background: #f59e0b;
  color: #1c1405;
}

.btn-ghost {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.btn-block {
  width: 100%;
}

.btn-lg {
  min-height: 56px;
  font-size: 1.05rem;
}

.callout {
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  background: #fff7ed;
  color: #9a3412;
}

.sync-mini,
.install-card {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.back-link {
  display: inline-block;
  margin-bottom: 10px;
  color: var(--muted);
}

.question-preview {
  list-style: none;
  padding: 0;
  margin: 0 0 16px;
}

.question-preview li {
  display: flex;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.q-index {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-dark);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  flex: none;
}

.field {
  margin-bottom: 16px;
}

.field-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 700;
}

.req {
  color: var(--danger);
}

.control {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1.5px solid #c7dad4;
  border-radius: 14px;
  background: #f8fbfa;
  color: var(--ink);
  font: inherit;
}

.control:focus {
  outline: 3px solid rgba(15, 110, 98, 0.2);
  border-color: var(--primary);
}

textarea.control {
  min-height: 110px;
  resize: vertical;
}

.choice-list,
.yesno {
  display: grid;
  gap: 8px;
}

.choice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 10px 12px;
  border: 1.5px solid #c7dad4;
  border-radius: 14px;
  background: #f8fbfa;
}

.choice-lg {
  justify-content: center;
  font-weight: 700;
}

.choice:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.rating {
  display: flex;
  gap: 8px;
}

.star {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 56px;
  border: 1.5px solid #c7dad4;
  border-radius: 14px;
  background: #f8fbfa;
  cursor: pointer;
}

.star input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.star span {
  color: #cbd5d1;
  font-size: 1.4rem;
}

.star:has(input:checked),
.star:has(input:checked) ~ .star {
  /* keep selected star highlighted individually */
}

.star:has(input:checked) {
  border-color: var(--accent);
  background: #fff7ed;
}

.star:has(input:checked) span {
  color: var(--accent);
}

.star em {
  font-size: 11px;
  color: var(--muted);
  font-style: normal;
}

.field-error,
.form-alert {
  margin-top: 8px;
  color: var(--danger);
  font-size: 14px;
  font-weight: 600;
}

.form-alert {
  padding: 10px 12px;
  border-radius: 12px;
  background: #fef2f2;
}

.field.has-error .control,
.field.has-error .choice,
.field.has-error .star {
  border-color: #f3b4ae;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-success { background: #dcfce7; color: var(--success); }
.badge-warn { background: #fef3c7; color: #92400e; }
.badge-info { background: #e0f2fe; color: var(--info); }
.badge-danger { background: #fee2e2; color: var(--danger); }
.badge-muted { background: #e5e7eb; color: #374151; }

.list-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  color: inherit;
}

.list-row p,
.list-row small {
  margin: 0;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}

.stat strong {
  display: block;
  font-size: 1.6rem;
}

.stat small {
  color: var(--muted);
}

.success-card {
  text-align: center;
}

.success-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 12px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #dcfce7;
  color: var(--success);
  font-size: 1.8rem;
}

.kv {
  display: grid;
  gap: 10px;
  text-align: left;
  margin: 16px 0;
}

.kv div {
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.kv dt {
  color: var(--muted);
  font-size: 12px;
}

.kv dd {
  margin: 2px 0 0;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
  word-break: break-all;
}

.muted {
  color: var(--muted);
}

.state-block {
  text-align: center;
  padding: 32px 12px;
}

.state-icon {
  font-size: 2rem;
}

.state-error h3 {
  color: var(--danger);
}

.spinner {
  width: 28px;
  height: 28px;
  margin: 0 auto 10px;
  border: 3px solid #cde5df;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: #fff;
  border-top: 1px solid var(--line);
}

.bottom-nav a {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: #678078;
  font-size: 11px;
  font-weight: 700;
}

.bottom-nav a.is-active {
  color: var(--primary);
}

.nav-badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 22px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #f59e0b;
  color: #1c1405;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}

#toast-root {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--nav-h) + var(--safe-b) + 12px);
  z-index: 50;
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 14px;
  border-radius: 14px;
  background: #12332d;
  color: #fff;
  opacity: 0;
  transform: translateY(8px);
  transition: 0.2s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: none;
}

.toast-success { background: #14532d; }
.toast-warn { background: #9a3412; }
.toast-danger { background: #7f1d1d; }

#splash {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #0c3d36, #0f6e62);
  color: #fff;
  text-align: center;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}

#splash.is-hidden {
  opacity: 0;
  visibility: hidden;
}

.splash-mark {
  width: 84px;
  height: 84px;
  margin: 0 auto 12px;
  display: grid;
  place-items: center;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.12);
  font-size: 2rem;
}

#splash p {
  color: #d1fae5;
}
