:root {
  --purple: #673ab7;
  --purple-dark: #5b30a6;
  --purple-soft: #ede7f6;
  --bg: #f0ebf8;
  --card: #ffffff;
  --border: #dadce0;
  --text: #202124;
  --muted: #5f6368;
  --blue: #4285f4;
  --red: #d93025;
  --green: #188038;
  --green-soft: #e6f4ea;
  --red-soft: #fce8e6;
  --font: "Google Sans", "Roboto", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--purple); }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.hidden { display: none !important; }
svg.i { width: 20px; height: 20px; fill: currentColor; flex: none; }

/* ---------- Top bar ---------- */
.topbar {
  background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; padding: 0 20px; height: 64px;
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 20px; text-decoration: none; color: var(--text); }
.brand svg { width: 32px; height: 32px; fill: var(--purple); }
.topbar .grow { flex: 1; }
.topbar .title-input {
  border: 0; border-bottom: 1px solid transparent; font-size: 18px; min-width: 0; width: min(380px, 40vw);
  padding: 4px 6px; background: transparent; border-radius: 4px;
}
.topbar .title-input:hover { border-bottom-color: var(--border); }
.topbar .title-input:focus { outline: none; border-bottom: 2px solid var(--purple); }
.doc-title { font-size: 18px; max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.save-state { color: var(--muted); font-size: 13px; white-space: nowrap; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--purple); color: #fff;
  display: grid; place-items: center; font-weight: 500; text-transform: uppercase; border: 0; cursor: pointer;
}
.menu { position: absolute; right: 0; top: 44px; z-index: 30; background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 4px 16px rgba(60,64,67,.25); padding: 8px 0; min-width: 220px; }
.menu .who { padding: 8px 16px 12px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu .who small { display: block; color: var(--muted); }
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 10px 16px; cursor: pointer; }
.menu button:hover { background: #f1f3f4; }

/* ---------- Tabs ---------- */
.tabs { background: #fff; border-bottom: 1px solid var(--border); display: flex; justify-content: center; gap: 8px; position: sticky; top: 64px; z-index: 19; }
.tab {
  display: inline-block; text-decoration: none; background: none; border: 0; padding: 14px 20px; cursor: pointer; color: var(--muted); font-weight: 500;
  border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); background: #f8f9fa; }
.tab.active { color: var(--purple); border-bottom-color: var(--purple); }
.tab .count { background: var(--purple-soft); color: var(--purple); border-radius: 10px; padding: 0 8px; margin-left: 6px; font-size: 12px; }

/* ---------- Layout ---------- */
.page { max-width: 770px; margin: 0 auto; padding: 16px 12px 80px; }
.wide { max-width: 1080px; margin: 0 auto; padding: 24px 16px 80px; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 24px; margin-bottom: 12px; position: relative;
}
.card.accent { border-top: 10px solid var(--purple); border-top-left-radius: 8px; border-top-right-radius: 8px; }
.card.editable { transition: box-shadow .15s; }
.card.editable::before {
  content: ""; position: absolute; left: -1px; top: -1px; bottom: -1px; width: 6px; border-radius: 8px 0 0 8px;
  background: var(--blue); opacity: 0; transition: opacity .15s;
}
.card.editable:focus-within { box-shadow: 0 1px 6px rgba(32,33,36,.28); }
.card.editable:focus-within::before { opacity: 1; }
.card h2 { font-size: 18px; font-weight: 500; margin: 0 0 4px; }
.card .sub { color: var(--muted); margin: 0 0 16px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid transparent; border-radius: 4px;
  padding: 9px 22px; cursor: pointer; font-weight: 500; background: transparent; color: var(--purple); text-decoration: none;
}
.btn:hover { background: var(--purple-soft); }
.btn.primary { background: var(--purple); color: #fff; }
.btn.primary:hover { background: var(--purple-dark); box-shadow: 0 1px 3px rgba(60,64,67,.4); }
.btn.outline { border-color: var(--border); }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: var(--red-soft); }
.btn.small { padding: 5px 12px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; pointer-events: none; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: none; cursor: pointer; color: var(--muted);
  display: inline-grid; place-items: center; flex: none;
}
.icon-btn:hover { background: #f1f3f4; color: var(--text); }
.icon-btn[disabled] { opacity: .3; pointer-events: none; }

/* ---------- Formularfelder ---------- */
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 13px; }
.input, .textarea, .select {
  width: 100%; border: 1px solid var(--border); border-radius: 4px; padding: 10px 12px; background: #fff;
}
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--purple); box-shadow: 0 0 0 1px var(--purple); }
.textarea { resize: vertical; min-height: 80px; }
.underline {
  width: 100%; border: 0; border-bottom: 1px solid var(--border); padding: 8px 2px; background: transparent; border-radius: 0;
}
.underline:hover { border-bottom-color: var(--muted); }
.underline:focus { outline: none; border-bottom: 2px solid var(--purple); padding-bottom: 7px; }
textarea.underline { resize: none; overflow: hidden; }
.error { color: var(--red); background: var(--red-soft); padding: 10px 14px; border-radius: 4px; margin-bottom: 16px; }
.hint { color: var(--muted); font-size: 13px; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card h1 { font-size: 24px; font-weight: 400; margin: 8px 0 4px; }
.auth-card .brand { margin-bottom: 8px; }
.auth-card .switch { margin-top: 20px; color: var(--muted); }
.auth-card .btn.primary { width: 100%; justify-content: center; padding: 11px; }

/* ---------- Dashboard ---------- */
.dash-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.dash-head h1 { font-size: 22px; font-weight: 400; margin: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.survey-card { padding: 0; margin: 0; overflow: hidden; display: flex; flex-direction: column; cursor: pointer; }
.survey-card:hover { border-color: var(--purple); }
.survey-card .thumb { height: 8px; background: var(--purple); }
.survey-card.closed .thumb { background: #9aa0a6; }
.survey-card .body { padding: 16px; flex: 1; }
.survey-card h3 { margin: 0 0 8px; font-size: 16px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.survey-card .meta { color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 6px 12px; }
.survey-card .foot { border-top: 1px solid var(--border); padding: 4px 8px; display: flex; justify-content: flex-end; gap: 2px; }
.chip { display: inline-block; border-radius: 12px; padding: 1px 10px; font-size: 12px; background: var(--purple-soft); color: var(--purple); }
.chip.closed { background: #f1f3f4; color: var(--muted); }
.chip.green { background: var(--green-soft); color: var(--green); }
.chip.red { background: var(--red-soft); color: var(--red); }
.empty { text-align: center; padding: 56px 16px; color: var(--muted); }
.empty h2 { color: var(--text); font-weight: 400; }

/* ---------- Editor ---------- */
.title-card input.big { font-size: 32px; line-height: 1.25; }
.title-card .desc { margin-top: 8px; }
.q-head { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 16px; }
.q-head .q-title { flex: 1; background: #f8f9fa; font-size: 16px; padding: 14px 12px 12px; border-bottom: 1px solid var(--muted); }
.q-head .q-title:focus { background: #f1f3f4; }
.q-head .select { width: 220px; padding: 14px 12px; }
.ghost { color: #80868b; border-bottom: 1px dotted #9aa0a6; padding: 6px 2px; width: 55%; }
.ghost.long { width: 90%; }
.opt { display: flex; align-items: center; gap: 8px; }
.opt .mark { width: 18px; height: 18px; border: 2px solid #80868b; flex: none; margin: 0 11px; }
.opt .mark.radio { border-radius: 50%; }
.opt .mark.checkbox { border-radius: 3px; }
.opt .mark.num { border: 0; width: auto; min-width: 18px; color: var(--muted); }
.opt input.underline { border-bottom-color: transparent; flex: 1; min-width: 0; }
.opt:hover input.underline { border-bottom-color: var(--border); }
.opt input.underline:focus { border-bottom-color: var(--purple); }
.add-opt { color: #80868b; background: none; border: 0; padding: 8px 12px 8px 40px; cursor: pointer; }
.add-opt:hover { color: var(--text); }
.scale-prev { display: flex; gap: 24px; color: var(--muted); }
.scale-prev div { text-align: center; }
.scale-prev i { display: block; width: 20px; height: 20px; border: 2px solid #80868b; border-radius: 50%; margin: 4px auto 0; }
.q-foot { display: flex; align-items: center; justify-content: flex-end; gap: 4px; border-top: 1px solid var(--border); margin-top: 20px; padding-top: 12px; flex-wrap: wrap; }
.q-foot .sep { width: 1px; height: 28px; background: var(--border); margin: 0 12px; }
.switch-row { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch-row input { position: absolute; opacity: 0; }
.switch { width: 36px; height: 14px; background: #bdc1c6; border-radius: 7px; position: relative; transition: background .15s; flex: none; }
.switch::after {
  content: ""; position: absolute; top: -3px; left: -2px; width: 20px; height: 20px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.4); transition: transform .15s, background .15s;
}
.switch-row input:checked + .switch { background: #b39ddb; }
.switch-row input:checked + .switch::after { background: var(--purple); transform: translateX(18px); }
.switch-row input:focus-visible + .switch { outline: 2px solid var(--blue); outline-offset: 4px; }
.add-q { display: flex; justify-content: center; margin: 16px 0; }
.fab {
  display: inline-flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--border); border-radius: 24px;
  padding: 10px 22px 10px 16px; cursor: pointer; font-weight: 500; box-shadow: 0 1px 3px rgba(60,64,67,.3);
}
.fab:hover { background: var(--purple-soft); }
.fab svg { fill: var(--purple); }

/* ---------- Ergebnisse ---------- */
.stats { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.stats .big { font-size: 28px; font-weight: 400; }
.stats .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.bar-row { display: grid; grid-template-columns: minmax(80px, 220px) 1fr 80px; gap: 12px; align-items: center; margin: 8px 0; }
.bar-row .label { overflow-wrap: anywhere; }
.bar-track { background: #f1f3f4; border-radius: 4px; height: 24px; overflow: hidden; }
.bar-fill { background: var(--purple); height: 100%; border-radius: 4px; min-width: 2px; transition: width .4s; }
.bar-row .val { color: var(--muted); font-size: 13px; text-align: right; }
.text-list { max-height: 320px; overflow: auto; border: 1px solid var(--border); border-radius: 4px; }
.text-list div { padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: pre-wrap; overflow-wrap: anywhere; }
.text-list div:last-child { border-bottom: 0; }
.q-meta { color: var(--muted); font-size: 13px; margin-bottom: 12px; }

/* ---------- Teilen ---------- */
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode {
  border: 2px solid var(--border); border-radius: 8px; padding: 16px; cursor: pointer; background: #fff; text-align: left;
}
.mode:hover { border-color: #b39ddb; }
.mode.active { border-color: var(--purple); background: var(--purple-soft); }
.mode b { display: block; margin-bottom: 4px; font-weight: 500; }
.mode span { color: var(--muted); font-size: 13px; }
.copy-row { display: flex; gap: 8px; }
.copy-row .input { flex: 1; background: #f8f9fa; }
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; color: var(--muted); font-weight: 500; font-size: 13px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.tbl td { padding: 6px 10px; border-bottom: 1px solid #f1f3f4; vertical-align: middle; }
.tbl .code { font-family: Consolas, "SF Mono", monospace; letter-spacing: 1px; }
.tbl .acts { text-align: right; white-space: nowrap; }
.progress { height: 8px; background: #f1f3f4; border-radius: 4px; overflow: hidden; margin: 8px 0 4px; }
.progress div { height: 100%; background: var(--green); }
.notice { background: var(--purple-soft); border-radius: 4px; padding: 10px 14px; margin: 12px 0; font-size: 14px; }
.notice.warn { background: #fef7e0; }

/* ---------- Öffentliches Formular ---------- */
.pub .card { padding: 22px 24px; }
.pub .q-title { font-size: 16px; margin: 0 0 16px; overflow-wrap: anywhere; }
.pub .req { color: var(--red); margin-left: 4px; }
.pub .card.invalid { border-color: var(--red); }
.pub .card .err { color: var(--red); font-size: 13px; margin-top: 10px; display: none; }
.pub .card.invalid .err { display: block; }
.pub h1 { font-size: 32px; font-weight: 400; margin: 0 0 12px; line-height: 1.25; overflow-wrap: anywhere; }
.pub .desc { white-space: pre-wrap; margin: 0 0 12px; }
.pub .req-note { color: var(--red); font-size: 14px; border-top: 1px solid var(--border); padding-top: 12px; margin-top: 12px; }
.choice { display: flex; align-items: center; gap: 14px; padding: 8px 0; cursor: pointer; overflow-wrap: anywhere; }
.choice input { width: 18px; height: 18px; accent-color: var(--purple); flex: none; margin: 0; }
.scale-pick { display: flex; gap: 8px; flex-wrap: wrap; }
.scale-pick label { display: flex; flex-direction: column; align-items: center; gap: 8px; cursor: pointer; width: 56px; padding: 8px 0; border-radius: 8px; }
.scale-pick label:hover { background: #f1f3f4; }
.scale-pick input { width: 20px; height: 20px; accent-color: var(--purple); margin: 0; }
.pub .actions { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; gap: 12px; }
.code-input { font-family: Consolas, "SF Mono", monospace; font-size: 22px; letter-spacing: 3px; text-transform: uppercase; max-width: 280px; }
.done { text-align: center; padding: 32px 16px; }
.done .tick { width: 56px; height: 56px; border-radius: 50%; background: var(--green-soft); color: var(--green); display: grid; place-items: center; margin: 0 auto 16px; }
.done .tick svg { width: 32px; height: 32px; }
.footer-note { text-align: center; color: var(--muted); font-size: 12px; margin-top: 24px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 80px); background: #323232; color: #fff;
  padding: 12px 20px; border-radius: 4px; opacity: 0; transition: transform .2s, opacity .2s; z-index: 100; max-width: 90vw;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

.loading { text-align: center; padding: 64px; color: var(--muted); }

@media (max-width: 640px) {
  .q-head { flex-direction: column; gap: 8px; }
  .q-head .select { width: 100%; }
  .mode-grid { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 1fr 70px; }
  .bar-row .bar-track { grid-column: 1 / -1; order: 3; }
  .topbar { padding: 0 10px; gap: 8px; }
  .doc-title, .save-state { display: none; }
  .card { padding: 18px 16px; }
  .title-card input.big, .pub h1 { font-size: 26px; }
  .tab { padding: 12px 14px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
