:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --line: #2a2f3a;
  --text: #eef0f4;
  --muted: #9aa1ae;
  --accent: #7c5cff;
  --accent-2: #00c8aa;
  --danger: #ff5c7a;
  --warn: #ffb547;
  --radius: 18px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent-2); }

/* ---------- Login ---------- */
.login {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
}
.login form { width: min(360px, 100%); display: grid; gap: 14px; text-align: center; }
.login img { width: 88px; height: 88px; margin: 0 auto 8px; border-radius: 24px; }
.login h1 { margin: 0 0 8px; font-size: 28px; }

input[type=password], input[type=text], textarea {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 90px; }

.btn {
  border: 0; border-radius: 12px; padding: 11px 16px; background: var(--panel-2);
  border: 1px solid var(--line); cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.good { background: var(--accent-2); border-color: var(--accent-2); color: #002a24; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.small { padding: 7px 11px; font-size: 14px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.error { color: var(--danger); min-height: 1.4em; }

/* ---------- Layout ---------- */
.shell { height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  padding: calc(10px + var(--safe-t)) 16px 10px; display: flex; align-items: center; gap: 10px;
  background: linear-gradient(var(--bg) 60%, transparent); pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.topbar .logo { font-weight: 700; font-size: 18px; }
.topbar .chip { margin-left: auto; font-size: 12px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); padding: 4px 10px; border-radius: 99px; }
.topbar .env { font-size: 11px; background: var(--warn); color: #000; padding: 2px 8px; border-radius: 99px; font-weight: 700; }

.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: flex; justify-content: space-around; align-items: center;
  background: rgba(15,17,21,.92); backdrop-filter: blur(12px); border-top: 1px solid var(--line);
}
.nav button { background: none; border: 0; padding: 8px 18px; color: var(--muted); font-size: 13px; display: grid; justify-items: center; gap: 2px; cursor: pointer; }
.nav button .i { font-size: 22px; line-height: 1; }
.nav button.active { color: var(--text); }
.nav .plus { width: 54px; height: 54px; border-radius: 18px; background: var(--accent); color: #fff; font-size: 30px; padding: 0; place-content: center; box-shadow: 0 6px 20px rgba(124,92,255,.4); }

/* ---------- Feed ---------- */
.feed {
  height: 100dvh; overflow-y: scroll; scroll-snap-type: y mandatory;
  scrollbar-width: none;
}
.feed::-webkit-scrollbar { display: none; }
.slide {
  height: 100dvh; scroll-snap-align: start; scroll-snap-stop: always;
  padding: calc(56px + var(--safe-t)) 14px calc(var(--nav-h) + var(--safe-b) + 14px);
  display: flex;
}
.card {
  flex: 1; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; display: flex; flex-direction: column; gap: 12px; overflow: hidden;
  transition: transform .3s ease, opacity .3s ease;
}
.card.leaving { transform: translateX(-110%) rotate(-4deg); opacity: 0; }
.card.leaving.right { transform: translateX(110%) rotate(4deg); }
.card .meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.badge { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); }
.badge.hot { background: var(--danger); border-color: var(--danger); color: #fff; }
.badge.warm { background: var(--warn); border-color: var(--warn); color: #000; }
.card h2 { margin: 0; font-size: 22px; line-height: 1.25; }
.card .scroll { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.card .body { color: #d6d9e0; white-space: pre-wrap; }
.assess { background: rgba(124,92,255,.12); border: 1px solid rgba(124,92,255,.35); border-radius: 12px; padding: 10px 12px; font-size: 15px; }
.assess b { color: #b7a6ff; }
.draft textarea { min-height: 160px; font-size: 15px; }
.draft .hint { color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 8px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions .grow { flex: 1; }
.card.big { justify-content: center; text-align: center; }
.card.big h2 { font-size: 30px; }
.card.big .emoji { font-size: 64px; }
.card.big .actions { justify-content: center; }
.end { justify-content: center; align-items: center; text-align: center; color: var(--muted); }

.spinner { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Sheet (Erfassen, Details) ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: min(720px, 100%); max-height: 92dvh; overflow-y: auto; background: var(--panel);
  border-radius: 22px 22px 0 0; border: 1px solid var(--line); padding: 18px 16px calc(18px + var(--safe-b));
  display: grid; gap: 12px; animation: up .2s ease;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet h3 { margin: 0; }
.sheet .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.files-preview { display: flex; gap: 8px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.mailbody { white-space: pre-wrap; background: var(--panel-2); border-radius: 12px; padding: 12px; font-size: 14px; max-height: 50dvh; overflow-y: auto; }

/* ---------- Desk ---------- */
.desk { padding: calc(56px + var(--safe-t)) 14px calc(var(--nav-h) + var(--safe-b) + 14px); height: 100dvh; overflow-y: auto; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.tabs button { flex: none; }
.tabs .on { background: var(--accent); border-color: var(--accent); color: #fff; }
.desk-grid { display: grid; gap: 14px; }
@media (min-width: 900px) {
  .desk-grid { grid-template-columns: minmax(320px, 1fr) 1.4fr; align-items: start; }
  .desk-detail { position: sticky; top: 70px; }
}
.list { display: grid; gap: 8px; }
.row-item { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; cursor: pointer; display: grid; gap: 4px; }
.row-item:hover, .row-item.sel { border-color: var(--accent); }
.row-item .t { font-weight: 600; }
.row-item .s { color: var(--muted); font-size: 13px; }
.desk-detail .card { min-height: 300px; }
.stats { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.memory { display: flex; gap: 8px; align-items: flex-start; }
.memory .c { flex: 1; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); transform: translateX(-50%) translateY(20px);
  background: #fff; color: #000; padding: 10px 16px; border-radius: 12px; font-weight: 600; z-index: 60;
  opacity: 0; pointer-events: none; transition: all .25s ease; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Runde 2: Kinder-Karten, Rückfrage, Entwurf, Editor ---------- */
.kids { display: grid; gap: 6px; }
.kid {
  display: flex; align-items: center; gap: 8px; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 8px 10px; font-size: 15px;
}
.kid > span { flex: 1; min-width: 0; }
.kid small { color: var(--muted); }
.kid-done span { text-decoration: line-through; color: var(--muted); }
.ask { background: rgba(255,181,71,.10); border: 1px solid rgba(255,181,71,.35); border-radius: 12px; padding: 10px 12px; display: grid; gap: 8px; font-size: 15px; }
.ask .row { display: flex; gap: 8px; }
.ask input { padding: 8px 10px; }
.draft-preview {
  background: var(--panel-2); border: 1px dashed var(--line); border-radius: 12px; padding: 12px;
  white-space: pre-wrap; font-size: 15px; cursor: text; max-height: 40dvh; overflow: hidden; position: relative;
}
.draft-label { color: var(--accent); font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.hint-small { color: var(--muted); font-size: 13px; margin: 0; }

body.noscroll { overflow: hidden; }
.editor {
  position: fixed; left: 0; right: 0; top: 0; z-index: 80; background: var(--bg);
  display: flex; flex-direction: column; padding: 0 0 var(--safe-b);
}
.editor-bar {
  display: flex; align-items: center; gap: 8px; padding: calc(8px + var(--safe-t)) 10px 8px;
  border-bottom: 1px solid var(--line); flex: none;
}
.editor-title { flex: 1; text-align: center; color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-text {
  flex: 1; min-height: 0; border: 0; border-radius: 0; background: var(--bg); resize: none;
  padding: 14px 16px; font-size: 17px; line-height: 1.5;
}
.editor-text:focus { border: 0; }
.editor-tools { flex: none; display: grid; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.editor-tools .row { display: flex; gap: 8px; }
.editor-tools input { padding: 9px 11px; }
.editor.kbd .editor-tools, .editor.typing .editor-tools { display: none; }   /* beim Tippen nur Text */
.card .scroll > * { flex-shrink: 0; }                  /* Inhalte nicht zusammenquetschen, lieber scrollen */
.draft-preview { max-height: none; }
.editor.busy::after {
  content: 'Schreibe neu …'; position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(15,17,21,.75); font-weight: 600;
}
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--panel-2); border-radius: 99px; padding: 6px 12px; font-size: 14px; cursor: pointer; }
.chip:active { background: var(--accent); }
.sheet > .btn { width: 100%; }
.kid.kept { border-color: var(--accent-2); }
.kid.kept span { color: var(--accent-2); }

/* ---------- Hilf-mir-Chat ---------- */
.chat-log { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 92%; padding: 10px 13px; border-radius: 16px; white-space: pre-wrap; font-size: 15.5px; line-height: 1.45; word-break: break-word; }
.msg.assistant { background: var(--panel); border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.user { background: var(--accent); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg a { color: var(--accent-2); }
.chat-input { flex: none; display: flex; gap: 8px; padding: 8px 10px calc(8px + var(--safe-b)); border-top: 1px solid var(--line); align-items: flex-end; }
.chat-input textarea { min-height: 42px; max-height: 120px; resize: none; padding: 10px 12px; }
.msg.note { align-self: center; background: rgba(0,200,170,.12); border: 1px solid rgba(0,200,170,.4); color: var(--accent-2); font-size: 14px; padding: 6px 12px; }
.chat-sugg { flex-wrap: wrap; overflow: visible; }

/* ---------- Antwort-Feld, Links ---------- */
.answer-tap { background: var(--panel-2); border: 1px dashed var(--accent); border-radius: 12px; padding: 14px; color: var(--muted); cursor: text; text-align: left; }
.answer-tap.small { padding: 9px 12px; font-size: 14px; }
.answer-q { flex: none; padding: 14px 16px 4px; font-size: 18px; font-weight: 600; line-height: 1.35; }
.editor.answer .editor-text { padding-top: 8px; }
.links { display: flex; gap: 8px; flex-wrap: wrap; }
.card .body a, .card .assess a { color: var(--accent-2); word-break: break-all; }
.badge.new { background: var(--accent-2); border-color: var(--accent-2); color: #002a24; }
.topbar .chip { cursor: pointer; }
.btn.folder { width: 100%; justify-content: flex-start; margin-bottom: 6px; }
#fl { max-height: 50dvh; overflow-y: auto; }

/* ================= Desktop (ab 1000 px): Arbeitsplatz ================= */
kbd { font: 600 11px/1 system-ui, sans-serif; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 2px 5px; margin-left: 4px; color: var(--muted); background: var(--panel-2); }
.desktop kbd { display: inline-block; }
body:not(.desktop) .btn kbd { display: none; }

.dshell { display: grid; grid-template-columns: 220px minmax(0, 1fr); height: 100dvh; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 16px 12px; gap: 12px; min-height: 0; }
.side-head { display: flex; align-items: center; gap: 8px; padding: 0 6px; }
.side-head .logo { font-weight: 700; font-size: 20px; }
.side-head .env { font-size: 11px; background: var(--warn); color: #000; padding: 2px 8px; border-radius: 99px; font-weight: 700; }
.side-plus { width: 100%; }
.side-nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; min-height: 0; }
.side-nav button { display: flex; align-items: center; gap: 10px; background: none; border: 0; border-radius: 10px; padding: 8px 10px; color: var(--muted); cursor: pointer; text-align: left; font-size: 15px; }
.side-nav button .i { width: 22px; text-align: center; }
.side-nav button:hover { background: var(--panel-2); color: var(--text); }
.side-nav button.on { background: rgba(124,92,255,.18); color: var(--text); font-weight: 600; }
.side-sep { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 14px 10px 4px; }
.side-foot { font-size: 12px; color: var(--muted); display: grid; gap: 4px; border-top: 1px solid var(--line); padding-top: 10px; }
.side-foot details { margin-top: 4px; }
.side-foot summary { cursor: pointer; }
.side-foot details > div { margin-top: 3px; }
.side-foot .btn { justify-self: start; margin-top: 4px; }

.dmain { min-width: 0; height: 100dvh; overflow: hidden; }
.desktop #toast { bottom: 24px; }

/* Feed am PC: schmale Spalte in der Mitte */
.desktop .feed { height: 100dvh; }
.desktop .slide { height: 100dvh; padding: 28px 24px; justify-content: center; }
.desktop .slide { align-items: center; }
.desktop .slide > .card { max-width: 620px; width: 100%; flex: none; max-height: 100%; min-height: 360px; }

/* Bottom-Sheets am PC als Dialog in der Mitte, Vollbild-Overlays als breite Spalte */
.desktop .sheet-bg { align-items: center; }
.desktop .sheet { border-radius: 22px; width: min(560px, 92vw); }
.desktop .editor { left: 50%; right: auto; width: min(760px, 100vw); transform: translateX(-50%); border-left: 1px solid var(--line); border-right: 1px solid var(--line); box-shadow: 0 0 0 100vmax rgba(0,0,0,.55); }

/* Arbeitsfläche: Liste | Karte + Entwurf + Original | Chat */
.dws { display: grid; grid-template-columns: 340px minmax(0, 1fr) 380px; height: 100dvh; }
.dws.wide { grid-template-columns: minmax(0, 960px); justify-content: center; }
.dws > section { min-height: 0; overflow-y: auto; padding: 18px 16px; }
.dlist { border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.dws.wide .dlist { border: 0; padding: 24px 28px; }
.dhead { display: flex; align-items: baseline; gap: 10px; }
.dhead h2 { margin: 0; font-size: 22px; }
.dlist .list { gap: 6px; }
.dlist .keys { margin-top: auto; padding-top: 12px; }
.group-h { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 10px 2px 2px; display: flex; justify-content: space-between; }
.row-item.compact { padding: 9px 12px; gap: 2px; border-radius: 12px; }
.row-item.compact .t { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-item.compact .s { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-item.sel { background: rgba(124,92,255,.12); }
.newdot { color: var(--accent-2); }
.today-box { background: var(--panel); border: 1px solid var(--accent); border-radius: 14px; padding: 12px 14px; display: grid; gap: 4px; }
.today-box .t { font-weight: 700; }
.today-box .s { font-size: 14px; }

.dwork { display: flex; flex-direction: column; gap: 14px; padding: 22px 26px !important; }
.dwork .card { flex: none; overflow: visible; padding: 22px; }
.dwork .card h2 { font-size: 24px; }
.dwork .card .scroll { overflow: visible; flex: none; }
.empty-work { color: var(--muted); display: grid; place-items: center; height: 60%; font-size: 18px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: grid; gap: 10px; position: relative; }
.panel-h { font-weight: 600; display: flex; gap: 8px; align-items: baseline; }
.panel .row { display: flex; gap: 8px; align-items: center; }
.panel .row input { flex: 1; padding: 9px 11px; }
.panel .grow { flex: 1; }
.panel .mailbody { max-height: none; font-size: 14.5px; line-height: 1.5; }
.panel .files { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-start; }
.panel .files img { max-width: 100%; max-height: 520px; border-radius: 10px; border: 1px solid var(--line); display: block; }
.draft-ta { min-height: 240px; font-size: 15.5px; line-height: 1.55; resize: vertical; }
.panel.busy::after { content: 'Schreibe …'; position: absolute; inset: 0; display: grid; place-items: center; background: rgba(15,17,21,.75); border-radius: var(--radius); font-weight: 600; }

.dchat { border-left: 1px solid var(--line); display: flex; flex-direction: column; padding: 0 !important; overflow: hidden !important; background: var(--panel); }
.dchat-h { padding: 14px 16px; border-bottom: 1px solid var(--line); font-weight: 600; flex: none; }
.chat-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.dchat .chat-input { padding-bottom: 12px; }
.dchat .msg { font-size: 14.5px; max-width: 100%; }

/* Schmalere Bildschirme (1000–1350 px): Chat unter die Arbeitsfläche */
@media (max-width: 1350px) {
  .dws { grid-template-columns: 300px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) 38dvh; }
  .dws .dlist { grid-row: 1 / span 2; }
  .dws .dchat { grid-column: 2; border-left: 0; border-top: 1px solid var(--line); }
}
