:root {
  color-scheme: light dark;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #1a2230;
  --muted: #64748b;
  --primary: #3b5bdb;
  --primary-hover: #364fc7;
  --primary-soft: #eef1fd;
  --banner: #3b5bdb;
  --danger: #d6336c;
  --danger-soft: #fdeef3;
  --ok: #2b8a3e;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 6px 20px rgba(16, 24, 40, .06);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --surface: #1a2029;
    --surface-2: #151b23;
    --border: #2b3542;
    --text: #e6eaf0;
    --muted: #93a1b3;
    --primary: #6b8afd;
    --primary-hover: #7d99ff;
    --primary-soft: #1e2740;
    --banner: #202a44;
    --danger: #f06595;
    --danger-soft: #2a1a22;
    --ok: #69db7c;
    --shadow: 0 1px 3px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.app-header {
  position: sticky; top: 0; z-index: 10;
  background: var(--banner);
  color: #fff;
}
.app-header-inner {
  max-width: 900px; margin: 0 auto;
  padding: .8rem 1.25rem;
  display: flex; align-items: center; gap: 1rem;
}
.app-header .brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; letter-spacing: -.01em; }
.app-header .brand small { color: rgba(255,255,255,.82); font-weight: 500; margin-left: .5rem; font-size: .78rem; }
.header-nav { margin-left: auto; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; }
.hbtn {
  background: rgba(255,255,255,.14); color: #fff;
  border: 1px solid rgba(255,255,255,.7); border-radius: 7px;
  padding: .35rem .8rem; font: inherit; font-size: .85rem; font-weight: 600;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .12s, color .12s;
}
.hbtn:hover { background: #fff; color: var(--banner); }
main { max-width: 900px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }

/* ---------- Briefkopf / Logo ---------- */
.letterhead { display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap; }
.logo-chip { flex: 0 0 auto; background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: .5rem .7rem; display: flex; align-items: center; box-shadow: var(--shadow); }
.logo-chip img { display: block; height: 54px; width: auto; max-width: 150px; }
.logo-chip.sm { padding: .3rem .45rem; }
.logo-chip.sm img { height: 34px; max-width: 90px; }
.logo-chip.placeholder { color: var(--muted); font-size: 1.35rem; min-width: 46px; justify-content: center; }
.letterhead .lh-info { flex: 1 1 auto; min-width: 0; }
.lh-name { font-size: 1.2rem; font-weight: 700; letter-spacing: -.01em; }
.lh-sub { color: var(--muted); font-size: .86rem; margin-top: .2rem; white-space: pre-line; }
.letterhead .btn { margin-left: auto; }
.logo-preview { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: .84rem; margin: 0 0 .6rem; }

/* ---------- Institution auswählen ---------- */
.choose-list { display: flex; flex-direction: column; gap: .55rem; margin-top: .4rem; }
.choose-item {
  display: flex; align-items: center; gap: .9rem; width: 100%; text-align: left;
  padding: .7rem .8rem; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); font: inherit; color: var(--text); cursor: pointer;
  transition: border-color .12s, background .12s;
}
.choose-item:hover { border-color: var(--primary); background: var(--primary-soft); }
.ci-info { flex: 1 1 auto; min-width: 0; }
.ci-name { font-weight: 600; }
.ci-sub { color: var(--muted); font-size: .84rem; margin-top: .1rem; }
.ci-arrow { color: var(--muted); font-size: 1.4rem; flex: 0 0 auto; line-height: 1; }

/* ---------- Klickbare Institutions-Karte ---------- */
.inst-open { display: flex; align-items: center; gap: 1rem; flex: 1 1 auto; min-width: 0; text-decoration: none; color: inherit; cursor: pointer; border-radius: 8px; }
.inst-open .ci-arrow { margin-left: auto; }
.inst-open:hover .inv-title { color: var(--primary); }
.inst-open:hover .ci-arrow { color: var(--primary); }
.overview-sub { margin: 1.5rem 0 .8rem; font-size: 1rem; letter-spacing: -.01em; }
.inst-hero { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 1.6rem 1.4rem; }
.inst-hero-name { font-size: 1.3rem; font-weight: 700; letter-spacing: -.01em; margin-bottom: 1.1rem; }

/* ---------- Dezente Icon-Buttons ---------- */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0;
  border: none; background: none; color: var(--muted);
  cursor: pointer; border-radius: 8px; text-decoration: none;
  transition: background .12s, color .12s;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------- Mitglieder ---------- */
.member-line { display: grid; grid-template-columns: 1fr 1fr 1.4fr 1fr auto; gap: .5rem; align-items: center; margin-bottom: .5rem; }
.member-head { display: grid; grid-template-columns: 1fr 1fr 1.4fr 1fr auto; gap: .5rem; font-size: .72rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-bottom: .45rem; padding: 0 .1rem; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  font: inherit; font-weight: 600; cursor: pointer;
  padding: .5rem .9rem; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: .3rem .6rem; font-size: .85rem; border-radius: 7px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.25rem 1.4rem; margin-bottom: 1.1rem;
}
.card > h2, .card > h3 { margin: 0 0 .9rem; font-size: 1rem; letter-spacing: -.01em; }
.section-title { display: flex; align-items: center; gap: .6rem; margin: 1.6rem 0 .8rem; }
.section-title h1 { font-size: 1.4rem; margin: 0; letter-spacing: -.02em; }

/* ---------- Forms ---------- */
label { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: .3rem; }
input[type=text], input[type=email], input[type=datetime-local], input[type=password], textarea {
  width: 100%; font: inherit; color: var(--text);
  padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); transition: border-color .12s, box-shadow .12s;
}
input:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
textarea { resize: vertical; min-height: 80px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.field { margin-bottom: 1rem; }
.field:last-child { margin-bottom: 0; }

/* ---------- Repeatable rows ---------- */
.row-line { display: grid; grid-template-columns: 1.2fr 1.4fr 1fr auto; gap: .55rem; align-items: center; margin-bottom: .55rem; }
.decision-line { display: grid; grid-template-columns: 1fr auto; gap: .6rem; align-items: center; margin-bottom: .5rem; }
.add-link { color: var(--primary); background: none; border: none; font: inherit; font-weight: 600; cursor: pointer; padding: .3rem 0; display: inline-flex; align-items: center; gap: .35rem; }
.add-link:hover { text-decoration: underline; }
.icon-x { border: none; background: none; cursor: pointer; color: var(--muted); font-size: 1.15rem; line-height: 1; padding: .25rem .45rem; border-radius: 6px; }
.icon-x:hover { color: var(--danger); background: var(--danger-soft); }

/* ---------- TOP-Block ---------- */
.top-block { border: 1px solid var(--border); border-radius: 10px; padding: 1rem; margin-bottom: .9rem; background: var(--surface-2); }
.top-block .top-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .7rem; }
.top-badge { flex-shrink: 0; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--primary); background: var(--primary-soft); padding: .2rem .5rem; border-radius: 6px; }
.docs { margin-top: .6rem; }
.doc-item { display: flex; align-items: center; gap: .5rem; font-size: .88rem; padding: .35rem .5rem; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); margin-bottom: .35rem; }
.doc-item .doc-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-item .doc-size { color: var(--muted); font-size: .78rem; }

/* ---------- TOP als Fieldset + Drop-Zone ---------- */
.top-fieldset {
  min-inline-size: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  padding: .4rem 1.15rem 1.15rem;
  margin: 0 0 1rem;
}
.top-fieldset > legend {
  font-weight: 700;
  color: var(--primary);
  font-size: .9rem;
  padding: 0 .5rem;
}
.top-title-row { display: flex; align-items: center; gap: .6rem; }
.top-fieldset .docs { margin-top: .7rem; }
.dropzone {
  margin-top: .7rem;
  border: 2px dashed color-mix(in srgb, var(--primary) 42%, transparent);
  border-radius: 9px;
  background: var(--primary-soft);
  padding: 1.1rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--primary); outline: none; }
.dropzone.dragover { border-style: solid; border-color: var(--primary); background: color-mix(in srgb, var(--primary) 16%, transparent); }
.dz-icon { font-size: 1.5rem; line-height: 1; color: var(--primary); }
.dz-text { margin-top: .3rem; font-size: .9rem; }
.dz-text strong { color: var(--primary); }
.dz-link { color: var(--primary); text-decoration: underline; }
.dz-formats { font-size: .75rem; color: var(--muted); margin-top: .4rem; }

/* ---------- Abschnitt als Rahmen mit Legende (Eckdaten, Teilnehmer) ---------- */
fieldset.section-fs {
  min-inline-size: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .6rem 1.4rem 1.4rem;
  margin: 0 0 1.1rem;
}
fieldset.section-fs > legend { font-weight: 700; color: var(--primary); font-size: .95rem; padding: 0 .5rem; }
.member-names { font-size: .92rem; color: var(--text); line-height: 1.6; }

/* ---------- Stepper (Sitzungs-Assistent) ---------- */
.stepper { display: flex; gap: .5rem; margin: 0 0 1.1rem; flex-wrap: nowrap; overflow-x: auto; }
.step {
  flex: 1 1 0; min-width: 0;
  display: flex; align-items: center; gap: .5rem;
  padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); color: var(--muted);
  font: inherit; font-size: .85rem; cursor: pointer; text-align: left;
  transition: border-color .12s, background .12s, color .12s;
}
.step:hover:not(.disabled):not(.current) { border-color: var(--primary); }
.step.current { border-color: var(--primary); background: var(--primary-soft); color: var(--text); font-weight: 600; }
.step.done { color: var(--text); }
.step.disabled { cursor: default; }
.step-num {
  flex: 0 0 auto; width: 22px; height: 22px; border-radius: 50%;
  border: 1.5px solid var(--border); display: inline-flex; align-items: center; justify-content: center;
  font-size: .78rem; font-weight: 700;
}
.step.current .step-num { background: var(--primary); color: #fff; border-color: var(--primary); }
.step.done .step-num { background: var(--ok); color: #fff; border-color: var(--ok); }
.step-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 620px) {
  .step-label { display: none; }
  .step { flex: 1; justify-content: center; }
}

/* Read-only Protokoll (Verabschiedung) */
.ro-text { white-space: pre-wrap; color: var(--text); font-size: .92rem; padding: .2rem 0; }
.dec-list { margin: .3rem 0 0; padding-left: 1.2rem; }
.dec-list li { margin: .15rem 0; }

/* ---------- Liste ---------- */
.inv-list { display: flex; flex-direction: column; gap: .8rem; }
.inv-card { display: flex; align-items: center; gap: 1rem; cursor: default; }
.inv-card .inv-main { flex: 1; min-width: 0; }
.inv-card .inv-title { font-weight: 700; font-size: 1.02rem; }
.inv-card .inv-meta { color: var(--muted); font-size: .86rem; margin-top: .15rem; }
.inv-card .inv-actions { display: flex; gap: .4rem; flex-shrink: 0; }
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: .12rem .5rem; border-radius: 20px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.badge.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.empty { text-align: center; color: var(--muted); padding: 3rem 1rem; }
.empty h3 { color: var(--text); margin: .5rem 0; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.login-card { width: 100%; max-width: 380px; text-align: center; }
.login-card h1 { font-size: 1.5rem; margin: 0 0 .3rem; }
.login-card p.sub { color: var(--muted); margin: 0 0 1.4rem; font-size: .9rem; }
.login-card .field { text-align: left; }
.err { color: var(--danger); font-size: .85rem; margin-top: .6rem; min-height: 1.1em; }

/* ---------- Protokoll ---------- */
.proto-head { color: var(--muted); font-size: .9rem; }
.proto-head strong { color: var(--text); }
.proto-participants { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.pill { font-size: .82rem; padding: .18rem .6rem; border-radius: 20px; background: var(--surface-2); border: 1px solid var(--border); }
.decisions-box { margin-top: .9rem; padding-top: .9rem; border-top: 1px dashed var(--border); }
.decisions-box > .dec-title { font-size: .82rem; font-weight: 700; color: var(--muted); margin-bottom: .55rem; text-transform: uppercase; letter-spacing: .03em; }

/* ---------- Toast ---------- */
#toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .65rem 1.1rem; border-radius: 9px; font-size: .9rem; font-weight: 600; box-shadow: var(--shadow); opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

@media (max-width: 620px) {
  .grid-2 { grid-template-columns: 1fr; }
  .row-line { grid-template-columns: 1fr 1fr; }
  .member-line { grid-template-columns: 1fr 1fr; }
  .member-head { display: none; }
  .inv-card { flex-direction: column; align-items: stretch; }
  .inv-card .inv-actions { justify-content: flex-end; }
  .app-header-inner { flex-wrap: wrap; }
}

/* ---------- Print (Protokoll) ---------- */
@media print {
  .app-header, .no-print, .btn, .add-link, .icon-x { display: none !important; }
  body { background: #fff; color: #000; }
  main { max-width: none; padding: 0; }
  .card { box-shadow: none; border: none; padding: 0 0 1rem; margin: 0 0 1rem; break-inside: avoid; }
  .top-block { background: #fff; border: 1px solid #ccc; break-inside: avoid; }
  textarea { border: none; background: #fff; resize: none; padding: 0; min-height: 0; }
}
