* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --green: #2e7d32; --green-dark: #1b5e20; --bg: #f5f7f4;
  --user: #2e7d32; --assistant: #fff; --border: #d8e0d6;
}
body { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: #1c241b; height: 100vh; }
.hidden { display: none !important; }
.muted { color: #8a968a; font-size: .9rem; margin: .5rem 0; }

#auth-view { display: flex; align-items: center; justify-content: center; height: 100vh; }
.card { background: #fff; padding: 2.5rem; border-radius: 16px; box-shadow: 0 8px 30px rgba(0,0,0,.08); width: 340px; max-width: 90vw; text-align: center; }
.card h1 { font-size: 2rem; margin-bottom: .25rem; }
.tagline { color: #6b776a; margin-bottom: 1.5rem; font-size: .9rem; }
.card input { width: 100%; padding: .75rem; margin-bottom: .75rem; border: 1px solid var(--border); border-radius: 8px; font-size: 1rem; }
.card button { width: 100%; padding: .75rem; border: none; border-radius: 8px; font-size: 1rem; cursor: pointer; margin-bottom: .5rem; }
#btn-login { background: var(--green); color: #fff; }
.secondary { background: #eef2ec; color: var(--green-dark); }
.error { color: #c62828; font-size: .85rem; min-height: 1.2em; }

#app-view { display: flex; height: 100vh; }
aside { width: 270px; background: #fff; border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 1rem; }
.nav { display: grid; grid-template-columns: 1fr 1fr; gap: .35rem; margin-bottom: 1rem; }
.nav-btn { padding: .5rem .4rem; border: none; background: #eef2ec; border-radius: 8px; cursor: pointer; font-size: .85rem; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-btn.active { background: var(--green); color: #fff; }
.side-panel { flex: 1; overflow-y: auto; }
.new-chat { width: 100%; border: none; border-radius: 8px; padding: .7rem; cursor: pointer; font-size: .95rem; background: var(--green); color: #fff; margin-bottom: 1rem; }
.new-chat:hover { background: var(--green-dark); }
#session-list, #project-list { list-style: none; }
#session-list li, #project-list li { padding: .6rem .7rem; border-radius: 8px; cursor: pointer; font-size: .9rem; color: #44503f; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#session-list li:hover, #project-list li:hover { background: #eef2ec; }
#session-list li.active, #project-list li.active { background: #e0ebdd; font-weight: 600; }
.badge { font-size: .7rem; background: #cfe3ca; color: var(--green-dark); border-radius: 6px; padding: .1rem .4rem; margin-left: .3rem; }
.logout { background: none; border: 1px solid var(--border); border-radius: 8px; padding: .6rem; cursor: pointer; color: #6b776a; margin-top: .6rem; }
.quota { font-size: .78rem; color: #6b776a; border-top: 1px solid var(--border); padding-top: .6rem; margin-top: .6rem; display: flex; flex-direction: column; gap: .2rem; }
.quota strong { text-transform: capitalize; color: var(--green-dark); }

main { flex: 1; display: flex; flex-direction: column; }
#main-chats { flex: 1; display: flex; flex-direction: column; }
.chat-header { display: flex; justify-content: space-between; align-items: center; padding: .8rem 1.5rem; border-bottom: 1px solid var(--border); background: #fff; min-height: 3rem; font-weight: 600; }
.chat-actions button { border: 1px solid var(--border); background: #fff; border-radius: 8px; padding: .35rem .6rem; cursor: pointer; font-size: .8rem; margin-left: .4rem; }
#messages { flex: 1; overflow-y: auto; padding: 1.5rem; display: flex; flex-direction: column; gap: .8rem; }
.msg { max-width: 70%; padding: .7rem 1rem; border-radius: 14px; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--user); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--assistant); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
/* Nachrichtentext: Markdown (Assistent) vs. Klartext (Nutzer) */
.msg-body { white-space: normal; }
.msg.user .msg-body { white-space: pre-wrap; }
.msg-body > :first-child { margin-top: 0; }
.msg-body > :last-child { margin-bottom: 0; }
.msg-body h3, .msg-body h4, .msg-body h5, .msg-body h6 { margin: .7rem 0 .35rem; font-size: 1.03rem; line-height: 1.3; }
.msg-body p { margin: .45rem 0; }
.msg-body ul, .msg-body ol { margin: .45rem 0; padding-left: 1.35rem; }
.msg-body li { margin: .15rem 0; }
.msg-body code { background: rgba(0,0,0,.07); padding: .1rem .3rem; border-radius: 4px; font-size: .9em; }
.msg.user .msg-body code { background: rgba(255,255,255,.2); }
.msg-body pre { background: #1c241b; color: #e8f0e6; padding: .7rem .9rem; border-radius: 8px; overflow-x: auto; margin: .5rem 0; }
.msg-body pre code { background: none; padding: 0; }
.msg-body a { color: var(--green-dark); }
.msg.user .msg-body a { color: #fff; }
.msg-body hr { border: none; border-top: 1px solid var(--border); margin: .6rem 0; }
.msg-toolbar { display: flex; gap: .4rem; margin-top: .5rem; }
.msg-tool-btn { background: transparent; border: 1px solid var(--border); border-radius: 6px; padding: .2rem .55rem; font-size: .74rem; color: #6b776a; cursor: pointer; }
.msg-tool-btn:hover { background: #eef2ec; }
.msg.user .msg-tool-btn { border-color: rgba(255,255,255,.4); color: rgba(255,255,255,.9); }
.msg.user .msg-tool-btn:hover { background: rgba(255,255,255,.15); }
.msg-sources { display: flex; flex-direction: column; gap: .3rem; margin-top: .5rem; padding: .55rem .7rem; background: rgba(0,0,0,.04); border-radius: 8px; }
.msg-sources a { font-size: .8rem; color: var(--green-dark); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg.user .msg-sources { background: rgba(255,255,255,.12); }
.msg.user .msg-sources a { color: #fff; }

/* Projekt-Detail: Instruktionen + Dokumente */
.project-instructions { width: 100%; max-width: 640px; padding: .6rem .7rem; border: 1px solid var(--border); border-radius: 8px; font-size: .9rem; box-sizing: border-box; resize: vertical; margin-bottom: .5rem; }
#project-docs { list-style: none; padding: 0; margin: .3rem 0 1.2rem; max-width: 640px; }
#project-docs li { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .5rem .2rem; border-bottom: 1px solid var(--border); font-size: .9rem; color: #44503f; }
#project-docs li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#chat-form { display: flex; flex-direction: column; gap: .55rem; padding: 1rem 1.5rem; border-top: 1px solid var(--border); background: #fff; }
.chat-toolbar { display: flex; gap: .4rem; flex-wrap: wrap; }
.toggle-chip { padding: .35rem .75rem; border: 1px solid var(--border); border-radius: 999px; background: #fff; color: #44503f; cursor: pointer; font-size: .82rem; user-select: none; transition: background .15s, color .15s, border-color .15s; }
.toggle-chip:hover { border-color: var(--green); }
.toggle-chip.active { background: var(--green); color: #fff; border-color: var(--green); }
.prompt-select { padding: .35rem .5rem; border: 1px solid var(--border); border-radius: 999px; background: #fff; color: #44503f; font-size: .82rem; cursor: pointer; max-width: 170px; }
.chat-input-row { display: flex; gap: .5rem; align-items: flex-end; }
#chat-form input, #chat-form textarea { flex: 1; padding: .75rem 1rem; border: 1px solid var(--border); border-radius: 10px; font-size: 1rem; }
#chat-form textarea { resize: vertical; min-height: 5rem; max-height: 280px; overflow-y: auto; line-height: 1.4; font-family: inherit; }
#chat-form button[type="submit"] { padding: .75rem 1.5rem; border: none; border-radius: 10px; cursor: pointer; background: var(--green); color: #fff; }
#chat-form input:disabled, #chat-form textarea:disabled, #chat-form button:disabled, .toggle-chip:disabled { opacity: .55; cursor: not-allowed; }
.input-hint { font-size: .78rem; color: #6b776a; padding: .1rem .3rem; }
.input-hint.over { color: #c62828; font-weight: 600; }
#downloads-bar { display: flex; flex-wrap: wrap; gap: .4rem; padding: .5rem 1.5rem 0; }
.dl-chip { display: inline-flex; align-items: center; gap: .5rem; background: #eef6ec; border: 1px solid var(--green); border-radius: 8px; padding: .4rem .7rem; font-size: .82rem; color: var(--green-dark); font-weight: 600; }
.dl-name { cursor: pointer; }
.dl-name:hover { text-decoration: underline; }
.dl-del { border: none; background: none; color: #6b776a; cursor: pointer; font-size: .9rem; line-height: 1; padding: 0; }
.dl-del:hover { color: #c62828; }
.add-btn { padding: .35rem .75rem; border: 1px solid var(--green); border-radius: 999px; background: #eef6ec; color: var(--green-dark); cursor: pointer; font-size: .82rem; font-weight: 600; }
.add-btn:hover { background: #e0ebdd; }
#attachment-bar { display: flex; flex-wrap: wrap; gap: .4rem; }
.attach-chip { display: inline-flex; align-items: center; gap: .4rem; background: #eef2ec; border: 1px solid var(--border); border-radius: 8px; padding: .3rem .55rem; font-size: .8rem; color: #44503f; max-width: 260px; }
.attach-chip .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attach-chip.uploading { opacity: .7; font-style: italic; }
.attach-chip.error { background: #fdecea; border-color: #f5c6c2; color: #c62828; }
.attach-chip button { border: none; background: none; cursor: pointer; color: #8a968a; font-size: 1rem; line-height: 1; padding: 0; }
.attach-chip button:hover { color: #c62828; }
/* Bild-Anhang als Thumbnail */
.attach-chip.image { padding: 0; position: relative; width: 52px; height: 52px; border-radius: 8px; overflow: hidden; background: #1c241b; }
.attach-chip.image .attach-thumb { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; display: block; }
.attach-chip.image .name { display: none; }
.attach-chip.image button { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; background: rgba(0,0,0,.55); color: #fff; border-radius: 50%; font-size: .7rem; display: flex; align-items: center; justify-content: center; }
.attach-chip.image button:hover { background: #c62828; color: #fff; }
.attach-chip.image.uploading { opacity: .8; }
.attach-chip.image.uploading::after { content: ""; position: absolute; inset: 0; margin: auto; width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.6); border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
/* Anhang-Vorschau INNERHALB einer Nachricht im Verlauf */
.msg-attachments { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.attach-chip.msg-att { max-width: 220px; }
.msg.user .attach-chip.msg-att:not(.image) { background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.35); color: #fff; }
/* Lightbox (Bild gross) */
#lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.82); display: flex; align-items: center; justify-content: center; cursor: zoom-out; padding: 2rem; }
#lightbox img { max-width: 95%; max-height: 95vh; border-radius: 8px; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
/* Drag&Drop-Overlay */
#main-chats { position: relative; }
#drop-overlay { position: absolute; inset: 0; z-index: 15; background: rgba(46,125,50,.12); border: 3px dashed var(--green); display: flex; align-items: center; justify-content: center; font-size: 1.1rem; color: var(--green-dark); font-weight: 600; pointer-events: none; }
.msg.research-bubble { max-width: 92%; }
.msg.research-bubble.loading { color: #37474f; font-style: italic; animation: research-pulse 1.4s ease-in-out infinite; }
@keyframes research-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }
/* Während einer laufenden Tiefensuche ist die Navigation gesperrt (Ergebnis erscheint inline). */
#app-view.researching .nav, #app-view.researching .side-panel { pointer-events: none; opacity: .55; }
.empty { color: #9aa697; text-align: center; margin-top: 2rem; }
.incognito-btn { background: #455a64 !important; }
.incognito-btn:hover { background: #37474f !important; }
#incognito-banner { background: #37474f; color: #fff; padding: .55rem 1.5rem; font-size: .85rem; text-align: center; }
#reminder-banner { background: #fff4d6; border-bottom: 1px solid #e6d28a; }
.reminder-item { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .55rem 1.5rem; font-size: .9rem; color: #6b5800; }
.reminder-item + .reminder-item { border-top: 1px solid #efe2b0; }
.reminder-item button { border: none; background: var(--green); color: #fff; border-radius: 6px; padding: .3rem .8rem; cursor: pointer; font-size: .8rem; }
.usage-grid { display: flex; flex-wrap: wrap; gap: .8rem; margin-bottom: 1rem; }
.stat { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: .8rem 1.2rem; min-width: 110px; text-align: center; }
.stat-num { display: block; font-size: 1.6rem; font-weight: 700; color: var(--green-dark); }
.stat-lbl { font-size: .8rem; color: #6b776a; }
.plan-row { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: .6rem .9rem; margin-bottom: .5rem; }
.plan-row strong { text-transform: capitalize; min-width: 70px; }
.plan-row label { font-size: .85rem; color: #44503f; display: flex; flex-direction: column; }
.plan-row input { width: 90px; padding: .3rem; border: 1px solid var(--border); border-radius: 6px; }
.plan-row button { background: var(--green); color: #fff; border: none; border-radius: 6px; padding: .4rem .8rem; cursor: pointer; }
#admin-users select { padding: .3rem; border: 1px solid var(--border); border-radius: 6px; }

/* --- Ein-/ausklappbares Menü (Desktop + Mobile) --- */
#menu-toggle {
  display: flex; position: fixed; top: 1rem; left: 1rem; z-index: 30;
  width: 2.4rem; height: 2.4rem; align-items: center; justify-content: center;
  border: none; border-radius: 8px; background: var(--green); color: #fff;
  font-size: 1.25rem; cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
#backdrop { display: none; }
.nav { margin-top: 2.9rem; }            /* Platz für den linksbündigen Toggle oben */
.chat-header { padding-left: 3.4rem; }  /* Platz für den Toggle */
.panel-page { padding-top: 3.4rem; }

/* Desktop: Sidebar im Layout, einklappbar (Breite 0) */
aside { transition: width .2s ease, padding .2s ease; overflow: hidden; }
#app-view.collapsed aside {
  width: 0 !important; min-width: 0; padding-left: 0; padding-right: 0; border: none;
}

/* Mobile: Sidebar als Overlay-Drawer */
@media (max-width: 768px) {
  aside {
    position: fixed; top: 0; left: 0; bottom: 0; width: 82%; max-width: 300px;
    z-index: 25; box-shadow: 2px 0 14px rgba(0,0,0,.25);
    transition: transform .25s ease; transform: translateX(0);
  }
  #app-view.collapsed aside {
    width: 82% !important; max-width: 300px; padding: 1rem; transform: translateX(-100%);
  }
  #app-view:not(.collapsed) #backdrop {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20;
  }
  main { width: 100%; }
  #messages { padding: 1rem; }
  .msg { max-width: 88%; }
  .plan-row { gap: .5rem; }
}

.panel-page { padding: 2rem; overflow-y: auto; }
.panel-page h2 { margin-bottom: 1rem; }
.panel-page h3 { margin: 1.2rem 0 .6rem; font-size: 1rem; }
.panel-page ul { list-style: none; }
.panel-page li { padding: .5rem .7rem; border: 1px solid var(--border); border-radius: 8px; margin-bottom: .4rem; background: #fff; display: flex; justify-content: space-between; align-items: center; font-size: .9rem; }
.panel-page button.small { padding: .5rem .9rem; border: none; border-radius: 8px; background: var(--green); color: #fff; cursor: pointer; margin-right: .5rem; margin-top: .5rem; font-size: .85rem; }
.panel-page button.danger { background: #c62828; }
.panel-page button#btn-create-org, .panel-page button#btn-invite { background: var(--green); color: #fff; border: none; border-radius: 8px; padding: .6rem 1rem; cursor: pointer; }
.row-action { border: 1px solid var(--border); background: #fff; border-radius: 6px; padding: .2rem .5rem; cursor: pointer; font-size: .8rem; }
.setting-label { display: block; font-size: .85rem; font-weight: 600; color: #44503f; margin: 1rem 0 .3rem; }
.setting-input, .setting-area { width: 100%; max-width: 640px; padding: .6rem .8rem; border: 1px solid var(--border); border-radius: 8px; font-size: .95rem; font-family: inherit; }
.setting-area { resize: vertical; line-height: 1.4; }
.setting-input:disabled, .setting-area:disabled { opacity: .6; cursor: not-allowed; }
#org-settings { border-top: 1px solid var(--border); margin-top: 1.5rem; padding-top: .5rem; }

/* Einwilligungs-Dialog (DSGVO) */
#consent-modal { position: fixed; inset: 0; z-index: 60; background: rgba(28,36,27,.55); display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.consent-card { background: #fff; border-radius: 16px; padding: 2rem; max-width: 440px; width: 100%; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.consent-card h2 { margin-bottom: .6rem; font-size: 1.3rem; }
.consent-check { display: flex; gap: .5rem; align-items: flex-start; margin: .8rem 0; font-size: .92rem; color: #44503f; }
.consent-check input { margin-top: .2rem; }
#btn-consent-accept { width: 100%; padding: .8rem; border: none; border-radius: 8px; background: var(--green); color: #fff; font-size: 1rem; cursor: pointer; margin-top: .6rem; }
#btn-consent-accept:hover { background: var(--green-dark); }

/* Zustimmung in der Registrierungsansicht */
.auth-consent { display: flex; gap: .5rem; align-items: flex-start; text-align: left; font-size: .85rem; color: #44503f; margin: .2rem 0 .5rem; }
.auth-consent input { margin-top: .2rem; flex: 0 0 auto; }
/* Text + Links als EIN fließendes Element neben der Checkbox (sonst zerreißt Flex jedes Wort). */
.auth-consent span, .consent-check span { min-width: 0; line-height: 1.45; }
.auth-consent-note { text-align: left; font-size: .76rem; color: #6b776a; margin: 0 0 1rem; line-height: 1.4; }

/* --- Generischer Dialog + Toast (ersetzt Browser-prompt/alert/confirm) --- */
#ui-dialog { position: fixed; inset: 0; z-index: 70; background: rgba(28,36,27,.55); display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.ui-dialog-card { background: #fff; border-radius: 16px; padding: 1.6rem 1.5rem; max-width: 420px; width: 100%; box-shadow: 0 12px 40px rgba(0,0,0,.28); }
.ui-dialog-card h3 { margin: 0 0 .8rem; font-size: 1.15rem; color: var(--green-dark); }
.ui-dialog-card .ui-msg { margin: 0 0 .4rem; color: #44503f; font-size: .95rem; line-height: 1.45; }
.ui-field-label { margin: 0 0 .35rem; font-size: .85rem; color: #6b776a; }
.ui-check { display: flex; gap: .5rem; align-items: center; margin-top: .8rem; font-size: .9rem; color: #44503f; cursor: pointer; }
.ui-input { width: 100%; padding: .6rem .7rem; border: 1px solid var(--border); border-radius: 8px; font-size: .95rem; box-sizing: border-box; background: #fff; color: #1c241b; }
.ui-dialog-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.2rem; }
.ui-dialog-actions button { padding: .55rem 1.1rem; border: none; border-radius: 8px; cursor: pointer; font-size: .9rem; }
#ui-dialog-ok { background: var(--green); color: #fff; }
#ui-dialog-ok:hover { background: var(--green-dark); }
#ui-dialog-cancel { background: #eef2ec; color: #44503f; }
#ui-toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%) translateY(1rem); z-index: 80; background: #1c241b; color: #fff; padding: .7rem 1.2rem; border-radius: 10px; font-size: .9rem; box-shadow: 0 6px 20px rgba(0,0,0,.3); opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none; max-width: 90%; }
#ui-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --- Chat-Suche --- */
.chat-search { width: 100%; padding: .5rem .7rem; margin: .2rem 0 .5rem; border: 1px solid var(--border); border-radius: 8px; font-size: .85rem; box-sizing: border-box; }
#search-results { list-style: none; padding: 0; margin: 0; }
#search-results li { padding: .55rem .7rem; border-radius: 8px; cursor: pointer; }
#search-results li:hover { background: #eef2ec; }
.search-snippet { display: block; font-size: .76rem; color: #8a968a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: .15rem; }
.search-empty { color: #9aa697; font-size: .85rem; padding: .5rem .2rem; }

/* Gefährliche Aktion (z. B. Chat löschen) */
button.danger:hover { color: #c62828; }
