:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #eef3f1;
  --ink: #202520;
  --muted: #66706a;
  --line: #d9ded8;
  --accent: #2f6f63;
  --accent-strong: #1f584e;
  --gold: #bd8b2f;
  --danger: #b64234;
  --shadow: 0 16px 40px rgba(27, 45, 38, 0.12);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

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

button,
.button {
  align-items: center;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: white;
  cursor: pointer;
  display: inline-flex;
  font-weight: 700;
  gap: 0.45rem;
  justify-content: center;
  min-height: 42px;
  padding: 0.68rem 1rem;
  text-decoration: none;
}

button:hover,
.button:hover {
  background: var(--accent-strong);
}

button.secondary,
.button.secondary {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

button.secondary:hover,
.button.secondary:hover {
  background: var(--surface-2);
}

button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--accent-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.app-shell {
  margin: 0 auto;
  max-width: 1120px;
  padding: 28px;
}

.admin-shell {
  max-width: none;
  width: 100%;
}

.topbar {
  align-items: center;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  margin-bottom: 28px;
}

.brand {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topbar nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.hero {
  display: grid;
  gap: 18px;
  margin: 0 auto 28px;
  max-width: 820px;
}

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

h1 {
  font-size: clamp(2rem, 4vw, 3.25rem);
}

h2 {
  font-size: clamp(1.4rem, 3vw, 2rem);
}

p {
  color: var(--muted);
  line-height: 1.6;
  margin: 0;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.survey-card {
  margin: 0 auto;
  max-width: 820px;
}

.login-panel {
  margin: 12vh auto 0;
  max-width: 460px;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

.progress {
  background: var(--surface-2);
  border-radius: 999px;
  height: 10px;
  margin: 8px 0 24px;
  overflow: hidden;
}

.progress span {
  background: var(--gold);
  display: block;
  height: 100%;
  transition: width 180ms ease;
}

.survey-progress {
  margin-bottom: 18px;
}

.progress-meta {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 0.92rem;
  gap: 12px;
  justify-content: space-between;
}

.progress-meta strong {
  color: var(--accent-strong);
}

.page-description {
  margin: 10px 0 22px;
  max-width: 70ch;
}

.field {
  display: grid;
  gap: 0.45rem;
  margin: 0 0 20px;
}

.field label,
.field legend {
  color: var(--ink);
  font-weight: 800;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.required {
  color: var(--danger);
}

input[type="text"],
textarea,
select {
  background: white;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  min-height: 44px;
  padding: 0.7rem 0.8rem;
  width: 100%;
}

textarea {
  min-height: 110px;
  resize: vertical;
}

.compact-textarea {
  min-height: 86px;
}

.choice-list {
  border: 0;
  display: grid;
  gap: 0.65rem;
  margin: 0;
  padding: 0;
}

.choice {
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  display: flex;
  gap: 0.6rem;
  min-height: 44px;
  padding: 0.65rem 0.75rem;
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 700;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: space-between;
  margin-top: 24px;
}

.tabs {
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 20px;
}

.tab {
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  color: var(--muted);
}

.tab.active {
  border-bottom-color: var(--accent);
  color: var(--ink);
}

.admin-grid {
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
}

.builder-layout {
  align-items: start;
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
}

.field-palette {
  display: grid;
  gap: 10px;
  position: sticky;
  top: 20px;
}

.field-type {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  justify-content: flex-start;
  width: 100%;
}

.field-type:hover {
  background: var(--surface-2);
}

.builder-header {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 16px;
}

.survey-settings {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) minmax(140px, 180px);
  margin-bottom: 18px;
}

.form-flow {
  display: grid;
  gap: 18px;
}

.page-block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.page-block.drag-over {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 99, 0.14);
}

.page-summary {
  align-items: center;
  background: #fbfcfb;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 14px 18px;
}

.page-block.collapsed .page-summary {
  border-bottom: 0;
}

.page-body {
  padding: 18px;
}

.page-header {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(160px, 1fr) auto;
  margin-bottom: 14px;
}

.page-fields {
  display: grid;
  gap: 12px;
}

.question-stack {
  display: grid;
  gap: 12px;
  min-height: 56px;
}

.question-card {
  background: #fbfcfb;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  overflow: hidden;
}

.content-card {
  background: #f7faf8;
}

.question-card.dragging {
  opacity: 0.55;
}

.question-card-header {
  align-items: center;
  cursor: move;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  padding: 12px 14px;
}

.question-card-header:hover {
  background: var(--surface-2);
  cursor: move;
}

.question-card.collapsed .question-card-header {
  border-bottom: 0;
}

.question-card h3 {
  font-size: 1rem;
}

.question-title {
  align-items: center;
  display: flex;
  gap: 10px;
  min-width: 0;
}

.question-title h3 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.type-badge {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  flex: 0 0 auto;
  font-size: 0.78rem;
  font-weight: 800;
  padding: 0.2rem 0.5rem;
}

.question-body {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 12px;
  padding: 14px;
}

.question-card.collapsed .question-body {
  display: none;
}

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

.danger-button:hover {
  background: var(--surface-2);
  color: var(--danger);
}

.question-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.icon-button {
  min-height: 34px;
  padding: 0.35rem 0.55rem;
}

.field-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(220px, 1.2fr) minmax(140px, 0.7fr) minmax(120px, 0.45fr);
}

.content-field-grid {
  grid-template-columns: minmax(220px, 1fr) minmax(140px, 220px);
}

.description-editor {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(220px, 1fr) auto;
}

.branch-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(180px, 1fr) minmax(140px, 0.6fr) minmax(180px, 1fr);
}

.inline-check {
  align-items: center;
  display: inline-flex;
  gap: 8px;
  min-height: 44px;
}

.options-editor {
  display: grid;
  gap: 8px;
}

.option-row {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
}

.wysiwyg-editor {
  display: grid;
  gap: 8px;
}

.wysiwyg-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.wysiwyg-surface {
  background: white;
  border: 1px solid var(--line);
  border-radius: 6px;
  line-height: 1.6;
  min-height: 150px;
  padding: 0.8rem;
}

.wysiwyg-surface:focus {
  outline: 2px solid rgba(47, 111, 99, 0.22);
  outline-offset: 2px;
}

.content-block {
  display: grid;
  gap: 10px;
  margin-bottom: 20px;
  padding: 4px 0;
}

.content-block h3,
.rich-content h3,
.rich-content h4 {
  margin: 0;
}

.rich-content {
  color: var(--muted);
  line-height: 1.65;
}

.rich-content p,
.rich-content ul,
.rich-content ol {
  margin: 0 0 0.75rem;
}

.rich-content p:last-child,
.rich-content ul:last-child,
.rich-content ol:last-child {
  margin-bottom: 0;
}

.editor {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  min-height: 560px;
}

.metrics {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.map-panel {
  margin-bottom: 20px;
}

.map-header {
  align-items: center;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  margin-bottom: 16px;
}

.map-total {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 150px;
  padding: 14px;
}

.map-total strong {
  display: block;
  font-size: 2rem;
}

.zip-map {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  height: 430px;
  overflow: hidden;
}

.zip-count-marker {
  align-items: center;
  background: var(--accent);
  border: 3px solid white;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(22, 45, 38, 0.28);
  color: white;
  display: flex;
  font-weight: 900;
  justify-content: center;
}

.zip-count-marker span {
  line-height: 1;
}

.zip-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.zip-breakdown span {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  display: inline-flex;
  gap: 6px;
  padding: 0.36rem 0.65rem;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.metric strong {
  display: block;
  font-size: 2rem;
}

.bar-list {
  display: grid;
  gap: 14px;
}

.bar-row {
  display: grid;
  gap: 7px;
}

.bar-label {
  display: flex;
  gap: 0.75rem;
  justify-content: space-between;
}

.bar-track {
  background: var(--surface-2);
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}

.bar-track span {
  background: var(--accent);
  display: block;
  height: 100%;
}

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

.response-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  padding: 14px;
}

.response-item.active {
  border-color: var(--accent);
}

.response-detail {
  display: grid;
  gap: 14px;
}

.answer {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 4px;
  padding-bottom: 12px;
}

.answer span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
  text-transform: uppercase;
}

.empty {
  background: var(--surface-2);
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 18px;
}

.split-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: flex-end;
}

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

@media (max-width: 780px) {
  .app-shell {
    padding: 18px;
  }

  .topbar,
  .admin-grid,
  .builder-layout,
  .survey-settings,
  .page-header,
  .map-header,
  .field-grid,
  .content-field-grid,
  .branch-grid,
  .description-editor,
  .metrics {
    grid-template-columns: 1fr;
  }

  .field-palette {
    position: static;
  }

  .topbar {
    align-items: flex-start;
    display: grid;
  }

  .actions {
    display: grid;
  }
}
