:root {
  --bg: #f6f3ec;
  --surface: #fffdf8;
  --surface-2: #efeae0;
  --ink: #13293d;
  --muted: #5f6f7c;
  --line: #e2dccf;
  --accent: #1f7a70;
  --accent-ink: #ffffff;
  --coral: #d8613f;
  --warn-bg: #fdf0e8;
  --hint-bg: #e8f3f1;
  --hi-bg: #13293d;
  --hi-ink: #f6f3ec;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(19, 41, 61, .06), 0 6px 24px rgba(19, 41, 61, .06);
  --serif: ui-serif, "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --chat-w: 400px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1821; --surface: #12222e; --surface-2: #182c3a; --ink: #e5edf2; --muted: #8fa3b1; --line: #223747;
    --accent: #3fb3a3; --accent-ink: #06201c; --coral: #f08a6c; --warn-bg: #2d1f19; --hint-bg: #10302c;
    --hi-bg: #e5edf2; --hi-ink: #0c1821;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.55 var(--sans); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { font-family: var(--serif); line-height: 1.2; font-weight: 600; letter-spacing: -.01em; }
a { color: var(--accent); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; border-radius: 10px; padding: .5em 1em; background: var(--surface-2); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.ghost, label.ghost { background: transparent; border: 1px solid var(--line); padding: .35em .8em; border-radius: 10px; }
button.ghost:hover, label.ghost:hover { background: var(--surface-2); }
.small { font-size: .85rem; }
.muted { color: var(--muted); }
.error { color: var(--coral); }
input, textarea { width: 100%; padding: .6em .75em; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
input:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
label { display: block; font-size: .9rem; color: var(--muted); }
label input { margin-top: .3em; color: var(--ink); }
.stack { display: grid; gap: 14px; }

.boot, .logo { font-size: 2.6rem; text-align: center; }
.boot { padding-top: 30vh; opacity: .4; }
.center-card { max-width: 380px; margin: 12vh auto; padding: 32px 28px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.center-card h1 { text-align: center; margin: .2em 0 .8em; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) var(--chat-w); min-height: 100vh; }
.page-col { padding: 0 clamp(16px, 4vw, 56px) 80px; }
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; padding: 40px 0 20px; border-bottom: 1px solid var(--line); margin-bottom: 28px; flex-wrap: wrap; }
.top h1 { margin: 0; font-size: clamp(1.8rem, 4vw, 2.8rem); }
.top p { margin: .3em 0 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.blocks { display: grid; gap: 22px; max-width: 920px; }

.block { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px 26px; scroll-margin-top: 20px; }
.block > h2 { margin: 0 0 .7em; font-size: 1.4rem; }
.block.tone-hinweis, .block:has(.tone-hinweis) { background: var(--hint-bg); }
.block:has(.tone-warnung) { background: var(--warn-bg); border-left: 4px solid var(--coral); }
.block:has(.tone-highlight) { background: var(--hi-bg); color: var(--hi-ink); }
.block:has(.tone-highlight) .muted { color: inherit; opacity: .7; }
.group-title { font-size: 1.05rem; margin: 1.2em 0 .5em; display: flex; gap: .6em; align-items: baseline; }
.group-title:first-child { margin-top: 0; }

.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty h2 { color: var(--ink); }
.empty p { max-width: 520px; margin: 0 auto 24px; }
.suggestions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.chip-btn { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; }

.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose h3, .prose h4, .prose h5 { margin: 1.1em 0 .4em; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose blockquote { margin: .6em 0; padding-left: 1em; border-left: 3px solid var(--line); color: var(--muted); }
.prose code { background: var(--surface-2); padding: .1em .35em; border-radius: 5px; font-size: .9em; }
.prose hr { border: 0; border-top: 1px solid var(--line); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: .5em 0; }
.chip { display: inline-flex; align-items: center; gap: .3em; background: var(--surface-2); border-radius: 999px; padding: .15em .7em; font-size: .85rem; text-decoration: none; color: var(--ink); }
.chip button { background: none; padding: 0 .2em; }

/* ---------- Module ---------- */
.crew-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.crew-card { display: flex; gap: 14px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; }
.crew-card h3 { margin: 0; font-size: 1.1rem; }
.avatar { flex: none; width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: var(--hint-bg); color: var(--accent); }
.avatar.role-kapitän, .avatar.role-skipper { background: var(--hi-bg); color: var(--hi-ink); }

.doc-list, .todo-list, .history { list-style: none; padding: 0; margin: 0; }
.doc-list li { border-top: 1px solid var(--line); }
.doc-list li:first-child { border-top: 0; }
.doc-list summary { cursor: pointer; padding: .6em 0; display: flex; justify-content: space-between; gap: 1em; flex-wrap: wrap; list-style: none; }
.doc-list summary::-webkit-details-marker { display: none; }
.doc-title::before { content: "▸ "; color: var(--muted); }
details[open] > summary .doc-title::before { content: "▾ "; }
.doc-list details > :not(summary) { margin: 0 0 .8em 1.1em; }

.todo { padding: .45em 0; border-top: 1px solid var(--line); }
.todo:first-child { border-top: 0; }
.todo label { display: flex; gap: .6em; align-items: flex-start; color: var(--ink); font-size: 1rem; cursor: pointer; }
.todo input { width: auto; margin-top: .35em; accent-color: var(--accent); }
.todo.done span { text-decoration: line-through; color: var(--muted); }
.todo-meta { display: flex; gap: 1em; margin-left: 1.7em; }
.todo .prose { margin-left: 1.7em; }
.done-list summary { cursor: pointer; margin-top: .5em; }

/* ---------- Chat ---------- */
.chat { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; background: var(--surface); border-left: 1px solid var(--line); }
.chat.drop { outline: 3px dashed var(--accent); outline-offset: -8px; }
.chat-head { display: flex; align-items: baseline; gap: .6em; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.chat-head #chat-close { margin-left: auto; display: none; }
.chat-log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: 88%; padding: .6em .9em; border-radius: 14px; background: var(--surface-2); overflow-wrap: anywhere; }
.bubble p { margin: .3em 0; }
.msg.user .bubble { background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.user .bubble a { color: inherit; }
.msg.user .chip { background: rgba(255, 255, 255, .2); color: inherit; }
.msg.assistant .bubble { border-bottom-left-radius: 4px; }
.action { font-size: .82rem; color: var(--muted); padding-left: .6em; }
.action.failed { color: var(--coral); }
.typing .bubble { display: flex; gap: 4px; padding: .8em 1em; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing span { animation: none; opacity: .6; } }

.composer { border-top: 1px solid var(--line); padding: 12px; display: grid; gap: 8px; }
.composer textarea { resize: none; max-height: 240px; }
.composer-row { display: flex; align-items: center; gap: 8px; }
.composer-row .hint { flex: 1; }
.attach { cursor: pointer; font-size: 1.1rem; padding: .25em .6em !important; }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; }
.attachments:empty { display: none; }
.chat-fab { display: none; }

/* ---------- Dialog ---------- */
dialog { border: 0; border-radius: var(--radius); background: var(--surface); color: var(--ink); box-shadow: var(--shadow); width: min(640px, calc(100vw - 32px)); max-height: 85vh; padding: 24px; }
dialog::backdrop { background: rgba(12, 24, 33, .45); }
dialog h2 { margin-top: 0; }
.dialog-close { float: right; }
.history li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: .6em 0; border-top: 1px solid var(--line); }
.history li.undone > div > span { text-decoration: line-through; color: var(--muted); }
#invite-form { margin-top: 20px; }
.copy { display: flex; gap: 8px; }

/* ---------- Mobil ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .top { padding-top: 24px; }
  .block { padding: 18px 16px; }
  .chat { position: fixed; inset: 0; height: auto; z-index: 20; transform: translateY(100%); transition: transform .25s ease; border-left: 0; }
  .chat-open .chat { transform: none; }
  .chat-head #chat-close { display: inline-block; }
  .composer .hint { visibility: hidden; }
  .chat-fab { display: grid; place-items: center; position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); width: 58px; height: 58px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 1.5rem; box-shadow: var(--shadow); z-index: 10; }
  .chat-open .chat-fab { display: none; }
}

/* ---------- Phase 2: Segel-Module ---------- */
.warn { color: #b7791f; }
@media (prefers-color-scheme: dark) { .warn { color: #f6c35b; } }
.badge { font-size: .75rem; font-weight: 600; padding: .15em .6em; border-radius: 999px; background: var(--surface-2); white-space: nowrap; }
.badge-gebucht, .badge-bezahlt { background: var(--accent); color: var(--accent-ink); }
.badge-optioniert, .badge-angebot { background: var(--hint-bg); color: var(--accent); }
.badge-storniert, .badge-abgelehnt { text-decoration: line-through; color: var(--muted); }

/* Steckbrief */
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.fact { padding: 12px 14px; border-radius: 12px; background: var(--surface-2); }
.fact.open { background: transparent; border: 1px dashed var(--line); }
.fact-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.fact-value { font-family: var(--serif); font-size: 1.2rem; font-weight: 600; margin-top: .15em; }
.fact.open .fact-value { color: var(--muted); }
.fact-detail { font-size: .82rem; color: var(--muted); }
.block:has(.facts) { background: transparent; box-shadow: none; padding: 0; }
.block:has(.facts) > h2 { display: none; }

/* Karte */
.map { height: clamp(280px, 50vh, 460px); border-radius: 12px; overflow: hidden; background: var(--surface-2); position: relative; z-index: 0; }
.map-empty { padding: 2em; text-align: center; }
.pin { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font: 700 13px/1 var(--sans); box-shadow: 0 1px 4px rgba(0,0,0,.35); border: 2px solid #fff; }
.pin-route { background: #13293d; color: #fff; }
.pin-route.pin-besucht { background: #1f7a70; }
.pin-route.pin-idee, .pin-route.pin-geplant { background: #13293d; }
.pin-idea { background: #fff; color: #d8613f; border-color: #d8613f; font-size: 14px; }
.leaflet-popup-content { font: 14px/1.45 var(--sans); }
.leaflet-container a { color: #1f7a70; }
.route-legs { margin-top: 14px; }
.legs { list-style: none; padding: 0; margin: 0 0 .5em; counter-reset: none; }
.legs li { display: grid; grid-template-columns: 4.5em 1fr auto; gap: 2px 10px; padding: .35em 0; border-top: 1px solid var(--line); }
.legs li:first-child { border-top: 0; }
.leg-day { font-weight: 600; font-size: .85rem; color: var(--accent); }
.leg-meta { grid-column: 2 / -1; }

/* Buchungen */
.booking-list { display: grid; gap: 12px; }
.booking { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.booking.status-storniert, .booking.status-abgelehnt { opacity: .55; }
.booking.status-idee, .booking.status-angefragt { border-style: dashed; }
.booking-head { display: flex; gap: 10px; align-items: flex-start; }
.booking-icon { font-size: 1.3rem; line-height: 1.2; }
.booking-title { flex: 1; }
.booking-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 8px; }
.booking details { margin-top: 6px; }

/* Bordkasse */
.kasse { display: grid; grid-template-columns: minmax(200px, 1fr) 2fr; gap: 28px; }
.balances, .transfers, .expense-list { list-style: none; padding: 0; margin: 0; }
.balances li, .expense-list li { display: flex; justify-content: space-between; gap: 12px; padding: .35em 0; border-top: 1px solid var(--line); }
.balances li:first-child, .expense-list li:first-child { border-top: 0; }
.balances .pos { color: var(--accent); font-weight: 600; }
.balances .neg { color: var(--coral); font-weight: 600; }
.transfers li { padding: .2em 0; }
.amount { white-space: nowrap; font-variant-numeric: tabular-nums; }
@media (max-width: 700px) { .kasse { grid-template-columns: 1fr; } }

/* Zeitplan */
.countdown { font-family: var(--serif); font-size: 1.15rem; margin: 0 0 1em; }
.countdown strong { color: var(--coral); font-size: 1.5em; }
.timeline { list-style: none; padding: 0; margin: 0; }
.tl-item { display: grid; grid-template-columns: 7.5em 26px 1fr; gap: 10px; padding: .45em 0; position: relative; }
.tl-date { font-size: .88rem; display: flex; flex-direction: column; }
.tl-dot { width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: .8rem; position: relative; z-index: 1; }
.tl-item:not(:last-child)::after { content: ""; position: absolute; left: calc(7.5em + 10px + 12px); top: 2.2em; bottom: -.45em; width: 2px; background: var(--line); }
.tl-next .tl-dot { background: var(--coral); color: #fff; }
.tl-next .tl-body > div:first-child { font-weight: 600; }
.tl-tentative { opacity: .7; }
.kind-route .tl-dot, .kind-segeltag .tl-dot { background: var(--hint-bg); color: var(--accent); }
.kind-zahlung .tl-dot, .kind-frist .tl-dot { background: var(--warn-bg); }

/* Bausteine-Dialog */
.module-list { list-style: none; padding: 0; margin: 0; }
.module-list li { display: grid; grid-template-columns: 2em 1fr auto; gap: 12px; align-items: center; padding: .7em 0; border-top: 1px solid var(--line); }
.module-icon { font-size: 1.3rem; text-align: center; color: var(--accent); }
.module-list a { white-space: nowrap; }

/* ---------- Korrespondenz ---------- */
.notices { display: flex; flex-wrap: wrap; gap: 8px; max-width: 920px; }
.notices:has(:not([hidden])) { margin-bottom: 18px; }
.notice { background: var(--warn-bg); border: 1px solid var(--line); border-radius: 999px; padding: .35em 1em; font-size: .9rem; }
.notice[hidden] { display: none; }
.mail-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; margin-bottom: 12px; }
.mail-actions { margin-left: auto; display: flex; gap: 8px; }
.threads { display: grid; gap: 8px; }
.thread { border: 1px solid var(--line); border-radius: 12px; }
.thread > summary { cursor: pointer; padding: 10px 14px; display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; list-style: none; }
.thread > summary::-webkit-details-marker { display: none; }
.thread-subject { font-weight: 600; }
.thread > summary .muted { grid-column: 1; }
.thread > summary .badge { grid-row: 1 / span 2; grid-column: 2; align-self: center; }
.thread.status-spam, .thread.status-erledigt { opacity: .7; }
.thread-body { padding: 0 14px 12px; display: grid; gap: 10px; }
.mail { border-top: 1px solid var(--line); padding-top: 10px; }
.mail-out { padding-left: 14px; border-left: 3px solid var(--accent); border-top: 0; }
.mail-body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .93rem; margin: 6px 0; }
.mail-body.long { max-height: 14em; overflow: hidden; mask-image: linear-gradient(#000 70%, transparent); }
.mail-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.draft { display: grid; gap: 8px; background: var(--hint-bg); border-radius: 10px; padding: 12px; border: 0; }
.draft textarea { font: inherit; resize: vertical; }
.compose-slot:empty { display: none; }
.compose-slot { margin-bottom: 12px; }
