/* ============================================================
   Variables & Reset
   ============================================================ */
:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --primary: #4a2080;
  --primary-hover: #3a1868;
  --primary-light: #f0ebf8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --text: #1a1a2e;
  --muted: #6b7280;
  --border: #e2e8f0;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
}

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

/* Ensure the hidden attribute always wins, even over display rules like .btn */
[hidden] { display: none !important; }

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 16px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================================
   Site Header (admin pages)
   ============================================================ */
.site-header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: .75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.header-brand { display: flex; align-items: center; flex-shrink: 0; }
.header-brand:hover { opacity: .85; text-decoration: none; }
.site-logo { height: 38px; max-width: 160px; width: auto; object-fit: contain; display: block; }

.header-nav { display: flex; align-items: center; gap: 1.5rem; }
.header-nav a { color: var(--muted); font-size: .9rem; font-weight: 500; }
.header-nav a:hover { color: var(--primary); text-decoration: none; }

/* ============================================================
   Layout
   ============================================================ */
.container { max-width: 960px; margin: 0 auto; padding: 2rem 1.5rem; }

.form-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.form-header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: center;
}
.form-header-logo { height: 36px; max-width: 150px; width: auto; object-fit: contain; display: block; }

.form-body {
  flex: 1;
  padding: 2rem 1rem 3rem;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

.center-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background: var(--bg);
}

.login-wrapper {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.login-logo-wrap { text-align: center; }
.login-logo { height: 48px; max-width: 200px; width: auto; object-fit: contain; display: inline-block; }

/* ============================================================
   Cards
   ============================================================ */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  border: 1px solid var(--border);
}

.login-card {
  width: 100%;
  padding: 2rem;
}
.login-card form { display: flex; flex-direction: column; gap: .75rem; }

/* ============================================================
   Page headers
   ============================================================ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: .75rem;
}
.page-header h1 { font-size: 1.5rem; font-weight: 700; }

.back-link { font-size: .875rem; color: var(--muted); margin-bottom: 1rem; display: block; }
.back-link:hover { color: var(--text); }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  padding: .5rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  line-height: 1.4;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #f8fafc; text-decoration: none; }

.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }

.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); color: #fff; }

.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: #f1f5f9; color: var(--text); }

.btn-sm { padding: .3rem .65rem; font-size: .8rem; }
.btn-delete-x { color: #dc2626 !important; padding: .3rem .5rem; font-weight: 700; }
.btn-delete-x:hover { background: #fee2e2; border-color: #dc2626; color: #dc2626 !important; }
.btn-icon { background: none; border: none; cursor: pointer; color: var(--muted); padding: .25rem .4rem; border-radius: 4px; font-size: .9rem; }
.btn-icon:hover { background: #fee2e2; color: var(--danger); }

.w-full { width: 100%; justify-content: center; }

/* ============================================================
   Forms
   ============================================================ */
label {
  display: block;
  font-size: .875rem;
  font-weight: 500;
  margin-bottom: .3rem;
  color: var(--text);
}

input[type="text"],
input[type="password"],
input[type="date"],
textarea,
select {
  width: 100%;
  padding: .55rem .75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .95rem;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color .15s;
  -webkit-appearance: none;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(74,32,128,.15);
}

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

.form-group { display: flex; flex-direction: column; gap: .3rem; margin-bottom: 1rem; }
.form-row { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; }
.form-row > * { flex: 1; min-width: 0; }

.inline-form { display: flex; gap: .5rem; align-items: center; }
.inline-form input { flex: 1; }

.input-sm { padding: .4rem .6rem; font-size: .875rem; }
.input-full { width: 100%; }

/* ============================================================
   Dashboard event list
   ============================================================ */
.events-list { display: flex; flex-direction: column; gap: .75rem; }

.event-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.event-card.closed { opacity: .65; }
.event-info h2 { font-size: 1.05rem; font-weight: 600; }
.event-info h2 a { color: var(--text); }
.event-info h2 a:hover { color: var(--primary); text-decoration: none; }
.event-actions { display: flex; gap: .5rem; flex-shrink: 0; }

.empty-state { text-align: center; padding: 3rem; color: var(--muted); }

/* ============================================================
   Badges
   ============================================================ */
.badge {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .02em;
}
.badge-open { background: #dcfce7; color: #15803d; }
.badge-closed { background: #fee2e2; color: #b91c1c; }
.badge-type-text { background: var(--primary-light); color: var(--primary); }
.badge-type-single { background: #fef3c7; color: #92400e; }
.badge-type-multi { background: #fce7f3; color: #9d174d; }

/* ============================================================
   Event edit — question builder
   ============================================================ */
.section { margin-top: 2rem; }
.section-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 1rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.questions-list { display: flex; flex-direction: column; gap: .75rem; }

.question-card {
  background: #f8f7fc;
  border: 1px solid #ddd8ec;
  border-radius: var(--radius);
  padding: 1rem;
}
.question-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .75rem;
  flex-wrap: wrap;
}
.question-header .badge { flex-shrink: 0; }
.question-header input { flex: 1; min-width: 160px; }
.question-header .btn-icon { flex-shrink: 0; }

.choices-section { margin-top: .75rem; }
.choices-label { font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: .5rem; }
.choices-list { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .5rem; }

.choice-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .4rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .25rem .4rem .25rem .6rem;
  font-size: .9rem;
}

.choice-edit-input {
  flex: 1;
  min-width: 0;
  border: 1px solid transparent;
  background: transparent;
  font-size: .9rem;
  padding: .25rem .4rem;
  border-radius: 4px;
  width: auto;
}
.choice-edit-input:hover { border-color: var(--border); background: #f8f7fc; }
.choice-edit-input:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(74,32,128,.12);
  outline: none;
}

/* Brief confirmation flash after an inline edit saves */
.just-saved {
  animation: savedFlash 1s ease;
}
@keyframes savedFlash {
  0%   { background: #dcfce7; border-color: #16a34a; }
  100% { background: transparent; border-color: var(--border); }
}

.allow-comment-label {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .82rem;
  color: var(--muted);
  cursor: pointer;
  margin-top: .75rem;
  user-select: none;
}
.allow-comment-label input[type="checkbox"] {
  width: 15px;
  height: 15px;
  min-width: 15px;
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
}
.allow-comment-label:hover { color: var(--text); }

.add-question-form {
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: .75rem;
}
.add-question-form .form-row { margin-bottom: .75rem; }

.link-box {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}
.link-url {
  font-family: monospace;
  font-size: .85rem;
  color: #15803d;
  word-break: break-all;
  flex: 1;
}
.copy-btn { flex-shrink: 0; }

.apply-template-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.apply-template-form select { flex: 1; min-width: 160px; }

/* ============================================================
   Results page
   ============================================================ */
.result-meta { color: var(--muted); font-size: .9rem; margin-bottom: 2rem; }
.result-section { margin-bottom: 2.5rem; }
.result-question-title { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; }

.text-answers { list-style: none; display: flex; flex-direction: column; gap: .5rem; }
.text-answer-item {
  background: #f8f7fc;
  border: 1px solid #ddd8ec;
  border-radius: 6px;
  padding: .6rem .9rem;
  font-size: .95rem;
}
.no-answers { color: var(--muted); font-style: italic; font-size: .9rem; }
.chart-wrapper { position: relative; max-width: 560px; }

.result-comments { margin-top: 1.25rem; }
.result-comments-title { font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .5rem; }

.comment-field { margin-top: 1rem; }
.comment-field-label { font-size: .875rem; font-weight: 500; color: var(--muted); margin-bottom: .4rem; display: block; }

/* ============================================================
   Public form (mobile-first)
   ============================================================ */
.form-event-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: .4rem;
  line-height: 1.3;
  color: var(--primary);
}
.form-event-desc { color: var(--muted); margin-bottom: 2rem; font-size: .95rem; }

.form-question { margin-bottom: 2rem; }
.form-question-text {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: .9rem;
  line-height: 1.4;
}

.choice-label {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem 1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: .5rem;
  font-size: 1rem;
  background: #fff;
  transition: border-color .15s, background .15s;
  -webkit-tap-highlight-color: transparent;
}
.choice-label:hover { border-color: var(--primary); background: var(--primary-light); }
.choice-label input[type="radio"],
.choice-label input[type="checkbox"] {
  width: 20px;
  height: 20px;
  min-width: 20px;
  margin: 0;
  padding: 0;
  cursor: pointer;
  accent-color: var(--primary);
}
.choice-label:has(input:checked) { border-color: var(--primary); background: var(--primary-light); }

.form-textarea {
  width: 100%;
  min-height: 120px;
  padding: .75rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
  -webkit-appearance: none;
}
.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(74,32,128,.15);
}

.form-submit {
  width: 100%;
  padding: 1rem;
  font-size: 1.05rem;
  border-radius: 8px;
  margin-top: 1rem;
  font-weight: 600;
}

/* Thank-you page */
.thankyou-card { text-align: center; padding: 2.5rem 2rem; }
.thankyou-card .checkmark {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #dcfce7;
  color: #15803d;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.25rem;
}
.thankyou-card h1 { font-size: 1.4rem; margin-bottom: .5rem; color: var(--primary); }
.thankyou-card p { color: var(--muted); }

/* ============================================================
   Utility
   ============================================================ */
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: .9rem; }
.success-msg { color: var(--success); font-size: .9rem; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
hr { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator { opacity: 1; }

/* ============================================================
   Sections (admin builder)
   ============================================================ */
.ungrouped-block { margin-bottom: 1.5rem; }
.ungrouped-label {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: .5rem;
}
.section-card {
  background: #fff;
  border: 2px solid #ddd8ec;
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.section-card-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}
.section-icon { color: var(--primary); font-size: 1rem; flex-shrink: 0; }
.section-title-input {
  flex: 1;
  min-width: 140px;
  font-weight: 600;
  font-size: .95rem;
  border: 1px solid transparent;
  background: transparent;
  padding: .3rem .5rem;
  border-radius: 4px;
  width: auto;
}
.section-title-input:hover { border-color: var(--border); background: #f8f7fc; }
.section-title-input:focus { border-color: var(--primary); background: #fff;
  box-shadow: 0 0 0 3px rgba(74,32,128,.12); outline: none; }
.section-actions { display: flex; align-items: center; gap: .4rem; flex-shrink: 0; margin-left: auto; }
.trigger-badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  background: #fef3c7;
  color: #92400e;
  border-radius: 999px;
  padding: .2rem .65rem;
  font-size: .75rem;
  font-weight: 600;
}
.trigger-setup-form {
  background: #f8f7fc;
  border: 1px solid #ddd8ec;
  border-radius: 8px;
  padding: .75rem;
  margin-top: .75rem;
}
.trigger-choices {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  padding: .2rem 0;
}
.trigger-choice-option {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .85rem;
  cursor: pointer;
}
.trigger-choice-option input { margin: 0; }
.add-section-form {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
}

/* Results section grouping */
.result-section-header {
  font-size: .9rem;
  font-weight: 700;
  color: var(--primary);
  margin: 1.5rem 0 .5rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  padding-bottom: .4rem;
  border-bottom: 2px solid #ddd8ec;
}

/* ============================================================
   Scale question (1–10)
   ============================================================ */
.scale-buttons {
  display: flex;
  gap: .4rem;
  flex-wrap: wrap;
  margin-bottom: .4rem;
}
.scale-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.scale-label input[type="radio"] { display: none; }
.scale-label span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  background: #fff;
  transition: border-color .12s, background .12s, color .12s;
  cursor: pointer;
}
.scale-label:hover span { border-color: var(--primary); background: var(--primary-light); }
.scale-label input:checked + span { background: var(--primary); border-color: var(--primary); color: #fff; }
.scale-hints {
  display: flex;
  justify-content: space-between;
  font-size: .75rem;
  color: var(--muted);
  margin-top: .25rem;
}
.badge-type-scale { background: #ecfdf5; color: #065f46; }
.scale-result-avg { font-size: 1.1rem; font-weight: 500; }
.scale-result-avg strong { color: var(--primary); font-size: 1.4rem; }

/* ============================================================
   Form sections (public)
   ============================================================ */
.form-section { margin-top: .5rem; }
.form-section-header {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 1rem;
  padding-bottom: .5rem;
  border-bottom: 2px solid #ddd8ec;
}

/* ============================================================
   Wizard (multi-step public form)
   ============================================================ */
.wizard-progress { margin-bottom: 1.75rem; }
.wizard-progress-bar {
  height: 6px;
  background: #ece9f5;
  border-radius: 999px;
  overflow: hidden;
}
.wizard-progress-fill {
  height: 100%;
  width: 0;
  background: var(--primary);
  border-radius: 999px;
  transition: width .3s ease;
}
.wizard-step-label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
  margin-top: .5rem;
}
.wizard-page[hidden] { display: none; }

.wizard-nav {
  display: flex;
  gap: .75rem;
  align-items: center;
  margin-top: 2rem;
}
.wizard-nav #btn-next,
.wizard-nav #btn-submit { margin-left: auto; }
.wizard-nav .btn { padding: .7rem 1.4rem; font-size: 1rem; }
