:root {
  --bg: #f5f6f8;
  --card: #fff;
  --text: #1d2330;
  --muted: #6b7280;
  --border: #dde1e7;
  --accent: #2f6fed;
  --accent-hover: #1f5ad0;
  --danger: #c62828;
  --success-bg: #e7f6ec;
  --success: #1e7b3c;
  --error-bg: #fdecec;
  --warn-bg: #fff6e0;
  --warn: #7a5200;
  --warn-border: #f0d9a0;
  --radius: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --card: #1d2128;
    --text: #e6e8eb;
    --muted: #9aa1ad;
    --border: #323843;
    --accent: #5b8def;
    --accent-hover: #7aa3f3;
    --danger: #ef6b6b;
    --success-bg: #173222;
    --success: #7fd69b;
    --error-bg: #3a1c1c;
    --warn-bg: #33290f;
    --warn: #f0c96a;
    --warn-border: #5a4718;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: 0 0 .5rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .75rem; }
.card h2 { margin-top: 0; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-block: 24px 64px; }
main.narrow { max-width: 640px; }

.topbar { background: var(--card); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; min-height: 52px; }
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.login-brand { text-align: center; font-weight: 700; font-size: 1.3rem; margin: 24px 0 16px; }
.topbar nav { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.topbar nav a { color: var(--text); text-decoration: none; }
.topbar nav a:hover { color: var(--accent); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.center { text-align: center; }
.muted { color: var(--muted); font-weight: normal; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.inline { display: inline; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .nowrap { display: flex; gap: 8px; flex-wrap: wrap; }

.stack { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: normal; }

input, textarea, select {
  font: inherit;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  width: 100%;
}
input[type="checkbox"], input[type="radio"] { width: auto; margin: 0; accent-color: var(--accent); }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
textarea { resize: vertical; }

button, .button {
  font: inherit;
  display: inline-block;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  line-height: 1.3;
}
button:hover, .button:hover { border-color: var(--accent); }
button:disabled { opacity: .4; cursor: default; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover, .button.primary:hover { background: var(--accent-hover); }
button.danger { color: var(--danger); }
button.danger:hover { border-color: var(--danger); }
.small { padding: 4px 10px; font-size: .9em; }
button.linklike { border: 0; background: none; padding: 0; color: var(--text); }
button.linklike:hover { color: var(--accent); }

.alert { padding: 10px 14px; border-radius: 6px; margin: 0 0 16px; }
.alert.error { background: var(--error-bg); color: var(--danger); }
.alert.success { background: var(--success-bg); color: var(--success); }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .85em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.nowrap .button { margin-left: 4px; }
table.responses td.answer { min-width: 140px; max-width: 360px; white-space: pre-wrap; overflow-wrap: anywhere; }

.badge { font-size: .8em; padding: 2px 8px; border-radius: 99px; }
.badge.open { background: var(--success-bg); color: var(--success); }
.badge.closed { background: var(--border); color: var(--muted); }

.share { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.share input { flex: 1; min-width: 0; }

.field-card { display: flex; flex-direction: column; gap: 12px; }
.field-card-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.field-card-head select { width: auto; }
.field-num { font-weight: 700; color: var(--muted); margin-right: 4px; }
.spacer { flex: 1; }

.add-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.save-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(transparent, var(--bg) 30%);
  margin-bottom: 24px;
}

.danger-zone summary { cursor: pointer; color: var(--danger); }

td.actions { white-space: nowrap; }
details.reset { display: inline-block; vertical-align: top; text-align: left; }
details.reset summary { list-style: none; }
details.reset summary::-webkit-details-marker { display: none; }
.reset-form { display: flex; gap: 6px; margin-top: 6px; }
.reset-form input[type="password"] { width: 200px; padding: 4px 8px; }

.notice { padding: 12px 14px; border-radius: 6px; background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn-border); margin: 0 0 16px; }
.notice strong { display: block; }

.pager { display: flex; justify-content: center; align-items: center; gap: 12px; margin-bottom: 16px; }
input.short { max-width: 10em; }

.badge.failed { background: var(--error-bg); color: var(--danger); }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 560px) { dl.facts { grid-template-columns: 1fr; } dl.facts dd { margin-bottom: 8px; } }
.restore-form { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; max-width: 360px; white-space: normal; }
.restore-form p { margin: 0; font-size: .9em; }
pre.log { margin: 0; overflow-x: auto; font-size: .85em; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
code { font-size: .9em; }

.site-footer { border-top: 1px solid var(--border); padding-block: 16px; font-size: .9em; color: var(--muted); }
.site-footer .wrap { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--accent); }

/* Header image: full card width on the public form, smaller preview in the editor */
.card.has-header { padding-top: 0; overflow: hidden; }
.form-header { display: block; width: calc(100% + 40px); max-width: none; margin: 0 -20px 20px; max-height: 280px; object-fit: cover; }
.header-image-box { display: flex; flex-direction: column; gap: 10px; }
.header-image-box img { display: block; width: 100%; max-height: 180px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
.header-image-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.header-image-actions input[type="file"] { width: auto; max-width: 100%; }

/* Public form */
.description { white-space: pre-wrap; color: var(--muted); }
fieldset.field { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
fieldset.field legend, fieldset.field .legend { font-weight: 600; padding: 0; margin-bottom: 2px; }
.help { margin: 0; color: var(--muted); font-size: .9em; }
.req { color: var(--danger); }
.has-error input, .has-error textarea, .has-error select { border-color: var(--danger); }
.field-error { margin: 0; color: var(--danger); font-size: .9em; }
.public-form { gap: 22px; }
.public-form > button { align-self: flex-start; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
