:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --primary: #1d4ed8;
  --primary-dark: #1e3a8a;
  --primary-soft: #eff6ff;
  --primary-ring: rgba(37, 99, 235, 0.22);

  --success: #059669;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 6px 24px -4px rgba(15, 23, 42, 0.07), 0 2px 6px -1px rgba(15, 23, 42, 0.04);
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* Top Navigation Bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}

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

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text-secondary);
}

.sync-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}

.sync-pill.connected {
  background: var(--success-soft);
  border-color: #a7f3d0;
  color: #065f46;
}

.sync-pill.connected .dot {
  background: var(--success);
}

.nav-tabs {
  display: inline-flex;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
}

.nav-tab {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.84rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.nav-tab:hover {
  color: var(--text);
}

.nav-tab.active {
  background: var(--surface);
  color: var(--primary-dark);
  box-shadow: var(--shadow-sm);
}

.badge-count {
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
}

/* Progress Bar Strip */
.progress-track {
  height: 3px;
  width: 100%;
  background: #e2e8f0;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary-dark), #3b82f6);
  transition: width 0.25s ease;
}

/* Main Container */
.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 28px 20px 64px;
}

.view {
  display: none;
}

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

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

/* Hero Banner */
.hero-card {
  background: linear-gradient(135deg, #172554 0%, #1e40af 65%, #2563eb 100%);
  color: #ffffff;
  border-radius: var(--radius-lg);
  padding: 32px 32px 28px;
  margin-bottom: 22px;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}

.hero-card::after {
  content: "";
  position: absolute;
  top: -60px;
  right: -60px;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.14), transparent 70%);
  pointer-events: none;
}

.hero-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: rgba(255, 255, 255, 0.14);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 12px;
}

.hero-card h1 {
  margin: 0 0 8px;
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.hero-card p {
  margin: 0;
  color: rgba(255, 255, 255, 0.88);
  font-size: 0.96rem;
  max-width: 640px;
}

.hero-meta {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.82);
}

.hero-meta span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* Question Cards */
.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 26px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.question-card:focus-within {
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.question-card.has-error {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}

.q-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
}

.q-number {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 800;
  font-size: 0.82rem;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.q-title {
  margin: 0;
  font-size: 1.03rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.4;
}

.q-required {
  color: var(--danger);
  margin-left: 3px;
}

.q-hint {
  margin: 4px 0 0;
  font-size: 0.84rem;
  color: var(--text-muted);
}

/* Choice Options Grid */
.options-list {
  display: grid;
  gap: 10px;
}

.options-grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.options-grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.option-item {
  position: relative;
}

.option-item input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.option-label {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 15px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  cursor: pointer;
  font-size: 0.94rem;
  font-weight: 500;
  color: var(--text);
  transition: all 0.15s ease;
  user-select: none;
}

.option-label:hover {
  border-color: #93c5fd;
  background: #f8fbff;
}

.option-radio {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.option-radio::after {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ffffff;
  transform: scale(0);
  transition: transform 0.15s ease;
}

.option-item input[type="radio"]:checked + .option-label {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 600;
}

.option-item input[type="radio"]:checked + .option-label .option-radio {
  border-color: var(--primary);
  background: var(--primary);
}

.option-item input[type="radio"]:checked + .option-label .option-radio::after {
  transform: scale(1);
}

.option-item input[type="radio"]:focus-visible + .option-label {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Pill Style for Yes / Partially / No */
.options-grid-3 .option-label {
  justify-content: center;
  text-align: center;
  padding: 13px 12px;
}

/* Textarea */
.textarea-wrap {
  position: relative;
}

.survey-textarea {
  width: 100%;
  min-height: 120px;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--surface);
  resize: vertical;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.survey-textarea:hover {
  border-color: #93c5fd;
}

.survey-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.textarea-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.error-msg {
  display: none;
  margin-top: 10px;
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--danger);
}

.question-card.has-error .error-msg {
  display: block;
}

/* Form Footer & Buttons */
.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 22px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 11px 20px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: #ffffff;
  box-shadow: 0 2px 10px rgba(29, 78, 216, 0.25);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.btn-success {
  background: var(--success);
  color: #ffffff;
}

.btn-success:hover:not(:disabled) {
  background: #047857;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text-secondary);
  border-color: var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-muted);
  color: var(--text);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
  border-color: #fecaca;
}

.btn-danger-ghost:hover:not(:disabled) {
  background: var(--danger-soft);
}

.btn-sm {
  font-size: 0.82rem;
  padding: 7px 12px;
  border-radius: 8px;
}

/* Success Screen */
.success-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 28px;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.success-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--success-soft);
  color: var(--success);
  display: grid;
  place-items: center;
  margin: 0 auto 16px;
  font-size: 1.8rem;
}

.success-card h2 {
  margin: 0 0 8px;
  font-size: 1.45rem;
}

.success-card p {
  margin: 0 auto 20px;
  max-width: 480px;
  color: var(--text-secondary);
}

.sync-note {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 600;
  margin-bottom: 24px;
}

.sync-note.ok {
  background: var(--success-soft);
  color: #065f46;
}

.sync-note.local {
  background: var(--warning-soft);
  color: #92400e;
}

.success-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Dashboard View */
.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.dashboard-header h2 {
  margin: 0 0 4px;
  font-size: 1.4rem;
}

.dashboard-header p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.export-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}

.kpi-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.1;
}

.kpi-sub {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Panel Cards */
.panel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}

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

.panel-header h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

/* Cloud Sync Form */
.sync-grid {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 12px;
  align-items: end;
}

.field-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.field-input,
.field-select {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  font-family: inherit;
  font-size: 0.88rem;
  color: var(--text);
  background: var(--surface);
}

.field-input:focus,
.field-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.sync-actions {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.sync-help {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* Charts Breakdown */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.chart-box {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  background: var(--surface-muted);
}

.chart-box.full-span {
  grid-column: 1 / -1;
}

.chart-title {
  font-size: 0.88rem;
  font-weight: 700;
  margin: 0 0 12px;
  color: var(--text);
}

.bar-row {
  margin-bottom: 9px;
}

.bar-row:last-child {
  margin-bottom: 0;
}

.bar-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  margin-bottom: 4px;
  gap: 8px;
}

.bar-label {
  color: var(--text-secondary);
  font-weight: 500;
}

.bar-stat {
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
}

.bar-track {
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--primary);
  transition: width 0.3s ease;
}

.bar-fill.yes { background: var(--success); }
.bar-fill.partially { background: var(--warning); }
.bar-fill.no { background: var(--danger); }

/* Responses Table */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
  min-width: 720px;
}

thead th {
  background: var(--surface-muted);
  color: var(--text-secondary);
  font-weight: 700;
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  color: var(--text);
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: #f8fafc;
}

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.tag-yes { background: var(--success-soft); color: #065f46; }
.tag-partially { background: var(--warning-soft); color: #92400e; }
.tag-no { background: var(--danger-soft); color: #991b1b; }

.empty-state {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-muted);
  font-size: 0.92rem;
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 60;
  background: #0f172a;
  color: #ffffff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.25);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: all 0.22s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.hidden {
  display: none !important;
}

@media (max-width: 680px) {
  .topbar-inner {
    flex-wrap: wrap;
  }

  .hero-card {
    padding: 24px 20px;
  }

  .hero-card h1 {
    font-size: 1.35rem;
  }

  .question-card {
    padding: 20px 18px;
  }

  .options-grid-2,
  .options-grid-3,
  .kpi-grid,
  .charts-grid,
  .sync-grid {
    grid-template-columns: 1fr;
  }

  .options-grid-3 .option-label {
    justify-content: flex-start;
    text-align: left;
  }
}
