/* v4.23.1 – Gemeinsame Chat-Basis für Portal, Orga und Admin
   Eine zentrale Optik für alle Chat-Varianten. Alte Spezialregeln werden hier bewusst übersteuert. */
:root{
  --kgbs-chat-bg:#f7f7f9;
  --kgbs-chat-green:#dcf8c6;
  --kgbs-chat-white:#ffffff;
  --kgbs-chat-shadow:0 2px 8px rgba(0,0,0,.10);
  --kgbs-chat-border:#dddfe8;
  --kgbs-chat-red:#b3261e;
  --kgbs-chat-max:760px;
  --kgbs-chat-admin-height:calc(100dvh - 205px);
  --kgbs-chat-orga-height:calc(100dvh - 205px);
}

/* ---------- Admin: Chat-Seite ohne extra Titelkarte ---------- */
body.admin-chat-screen .admin-topbar{display:none!important;}
body.admin-chat-screen .admin-main-area{padding-top:14px!important;padding-bottom:10px!important;overflow:hidden!important;}
body.admin-chat-screen #adminContent{height:var(--kgbs-chat-admin-height)!important;min-height:420px!important;overflow:hidden!important;}
body.admin-chat-screen .admin-communication-grid{height:100%!important;min-height:0!important;display:grid!important;grid-template-columns:minmax(280px,390px) minmax(0,1fr)!important;gap:16px!important;align-items:stretch!important;overflow:hidden!important;}
body.admin-chat-screen .admin-chat-sidebar,
body.admin-chat-screen .admin-chat-panel{height:100%!important;min-height:0!important;overflow:hidden!important;display:flex!important;flex-direction:column!important;}
body.admin-chat-screen .admin-chat-panel{display:grid!important;grid-template-rows:auto minmax(0,1fr) auto!important;gap:0!important;}
body.admin-chat-screen .admin-chat-status-row{flex:0 0 auto!important;margin:0 0 10px!important;}
body.admin-chat-screen .admin-chat-messages{height:auto!important;min-height:0!important;max-height:none!important;flex:1 1 auto!important;overflow:auto!important;}
body.admin-chat-screen .admin-chat-side-title{margin:0 0 12px!important;font-size:24px!important;line-height:1.1!important;}
body.admin-chat-screen .admin-chat-list{flex:1 1 auto!important;min-height:0!important;max-height:none!important;overflow:auto!important;display:grid!important;align-content:start!important;gap:10px!important;padding:0 4px 2px 0!important;}
body.admin-chat-screen .admin-chat-item{max-height:96px!important;min-height:0!important;overflow:hidden!important;padding:12px 13px!important;display:grid!important;gap:4px!important;align-content:start!important;}
body.admin-chat-screen .admin-chat-item strong,
body.admin-chat-screen .admin-chat-item span{white-space:nowrap!important;overflow:hidden!important;text-overflow:ellipsis!important;}
body.admin-chat-screen .admin-chat-item em{display:-webkit-box!important;-webkit-line-clamp:2!important;-webkit-box-orient:vertical!important;overflow:hidden!important;line-height:1.25!important;max-height:2.5em!important;}

/* ---------- Orga: Chat-Seitenhöhe sauber an Browserhöhe binden ---------- */
body.orga-chat-screen .orga-dashboard-head{display:none!important;}
body.orga-chat-screen .orga-shell{height:100dvh!important;max-height:100dvh!important;overflow:hidden!important;display:flex!important;flex-direction:column!important;padding:8px 0!important;}
body.orga-chat-screen .orga-root-card{flex:1 1 auto!important;min-height:0!important;overflow:hidden!important;display:flex!important;flex-direction:column!important;}
body.orga-chat-screen .orga-app-layout{flex:1 1 auto!important;min-height:0!important;overflow:hidden!important;display:grid!important;grid-template-rows:auto minmax(0,1fr)!important;gap:10px!important;margin-top:10px!important;}
body.orga-chat-screen .orga-workspace,
body.orga-chat-screen #orgaMainContent{flex:1 1 auto!important;min-height:0!important;overflow:hidden!important;display:flex!important;flex-direction:column!important;}
body.orga-chat-screen .orga-chat-unified,
body.orga-chat-screen .orga-groupchat-grid{height:var(--kgbs-chat-orga-height)!important;min-height:420px!important;overflow:hidden!important;display:grid!important;grid-template-columns:minmax(280px,390px) minmax(0,1fr)!important;gap:16px!important;align-items:stretch!important;}
body.orga-chat-screen .orga-chat-sidebar,
body.orga-chat-screen .orga-chat-detail-card{height:100%!important;min-height:0!important;overflow:hidden!important;display:flex!important;flex-direction:column!important;}
body.orga-chat-screen .orga-chat-side-title{margin:0 0 12px!important;font-size:24px!important;line-height:1.1!important;}
body.orga-chat-screen .orga-chat-sidebar .orga-groupchat-list{flex:1 1 auto!important;min-height:0!important;max-height:none!important;overflow:auto!important;display:grid!important;align-content:start!important;gap:10px!important;padding:0 4px 2px 0!important;margin:0!important;}
body.orga-chat-screen .orga-groupchat-item{max-height:96px!important;min-height:0!important;overflow:hidden!important;padding:12px 13px!important;display:grid!important;gap:4px!important;align-content:start!important;}
body.orga-chat-screen .orga-groupchat-item strong,
body.orga-chat-screen .orga-groupchat-item span{white-space:nowrap!important;overflow:hidden!important;text-overflow:ellipsis!important;}
body.orga-chat-screen .orga-groupchat-item em{display:-webkit-box!important;-webkit-line-clamp:2!important;-webkit-box-orient:vertical!important;overflow:hidden!important;line-height:1.25!important;max-height:2.5em!important;}
body.orga-chat-screen .orga-groupchat-head{flex:0 0 auto!important;margin:0 0 10px!important;}
body.orga-chat-screen .orga-groupchat-panel,
body.orga-chat-screen .orga-chat-card{flex:1 1 auto!important;min-height:0!important;height:100%!important;overflow:hidden!important;display:grid!important;grid-template-rows:minmax(0,1fr) auto!important;background:var(--kgbs-chat-bg)!important;border:1px solid var(--kgbs-chat-border)!important;border-radius:22px!important;}

/* ---------- Gemeinsamer Nachrichtenbereich ---------- */
.admin-chat-messages,
.orga-groupchat-messages,
.orga-chat-list,
.portal-chat-box{
  background:var(--kgbs-chat-bg)!important;
  border:1px solid var(--kgbs-chat-border)!important;
  border-radius:22px 22px 0 0!important;
  border-bottom:0!important;
  padding:10px 12px!important;
  display:flex!important;
  flex-direction:column!important;
  gap:3px!important;
  overflow:auto!important;
  min-height:0!important;
  position:relative!important;
}
.portal-chat-panel{overflow:hidden!important;border-radius:22px!important;display:grid!important;grid-template-rows:minmax(0,1fr) auto!important;background:var(--kgbs-chat-bg)!important;border:1px solid var(--kgbs-chat-border)!important;}
.portal-chat-panel .portal-chat-box{border:0!important;border-radius:22px 22px 0 0!important;}

/* Datum ist eine echte Zeile – nie sticky, nie overlay */
.admin-chat-date,
.orga-groupchat-date,
.orga-chat-date,
.portal-chat-date{
  position:static!important;
  inset:auto!important;
  transform:none!important;
  z-index:1!important;
  display:flex!important;
  justify-content:center!important;
  align-items:center!important;
  width:100%!important;
  flex:0 0 auto!important;
  clear:none!important;
  float:none!important;
  text-align:center!important;
  margin:7px 0 8px!important;
  padding:0!important;
  pointer-events:none!important;
}
.admin-chat-date span,
.orga-groupchat-date span,
.orga-chat-date span,
.portal-chat-date span{
  position:static!important;
  display:inline-flex!important;
  align-items:center!important;
  justify-content:center!important;
  background:rgba(255,255,255,.94)!important;
  border:1px solid var(--kgbs-chat-border)!important;
  border-radius:999px!important;
  padding:4px 10px!important;
  font-size:11px!important;
  line-height:1.1!important;
  font-weight:900!important;
  color:#5f6170!important;
  box-shadow:0 3px 10px rgba(0,0,0,.06)!important;
}

/* Chat-Zeilen */
.admin-chat-row,
.orga-groupchat-row,
.orga-chat-row,
.portal-chat-row{
  width:100%!important;
  min-width:0!important;
  display:flex!important;
  align-items:flex-start!important;
  gap:7px!important;
  margin:1px 0!important;
  float:none!important;
  clear:none!important;
}
.admin-chat-row.admin,
.orga-groupchat-row.admin,
.orga-chat-row.own,
.orga-chat-row.me,
.orga-chat-row.regie,
.portal-chat-row.customer{justify-content:flex-end!important;}
.admin-chat-row.customer,
.orga-groupchat-row.customer,
.orga-chat-row.other,
.orga-chat-row.admin,
.portal-chat-row.admin{justify-content:flex-start!important;}

.chat-avatar{width:31px!important;height:31px!important;min-width:31px!important;border-radius:999px!important;display:inline-flex!important;align-items:center!important;justify-content:center!important;overflow:hidden!important;background:var(--kgbs-chat-red)!important;color:#fff!important;font-size:13px!important;font-weight:950!important;box-shadow:0 2px 8px rgba(0,0,0,.12)!important;margin-top:4px!important;}
.chat-avatar img{width:100%!important;height:100%!important;object-fit:cover!important;display:block!important;}
.chat-avatar.spacer{visibility:hidden!important;background:transparent!important;box-shadow:none!important;}

/* Chatblasen */
.admin-chat-bubble,
.orga-groupchat-bubble,
.orga-chat-bubble,
.portal-bubble{
  position:relative!important;
  width:auto!important;
  min-width:0!important;
  max-width:min(72%,var(--kgbs-chat-max))!important;
  padding:7px 10px 6px!important;
  border:0!important;
  border-radius:12px!important;
  box-shadow:var(--kgbs-chat-shadow)!important;
  line-height:1.38!important;
  float:none!important;
  clear:none!important;
  overflow:visible!important;
}
.admin-chat-bubble.admin,
.orga-groupchat-bubble.admin,
.orga-chat-bubble.own,
.portal-bubble.customer{background:var(--kgbs-chat-green)!important;margin-left:0!important;}
.admin-chat-bubble.customer,
.orga-groupchat-bubble.customer,
.orga-chat-bubble.other,
.portal-bubble.admin{background:var(--kgbs-chat-white)!important;margin-right:0!important;}
.admin-chat-bubble .body,
.orga-groupchat-bubble .body,
.orga-chat-bubble .body,
.portal-bubble .body{display:inline!important;white-space:pre-wrap!important;overflow-wrap:anywhere!important;line-height:1.38!important;}
.admin-chat-bubble .meta,
.orga-groupchat-bubble .meta,
.orga-chat-meta,
.portal-bubble .meta{font-size:12px!important;font-weight:900!important;color:#626273!important;margin:0 0 3px!important;line-height:1.15!important;}
.admin-chat-bubble .bubble-foot,
.orga-groupchat-bubble .bubble-foot,
.orga-chat-bubble .bubble-foot,
.portal-bubble .bubble-foot{display:inline-flex!important;align-items:flex-end!important;justify-content:flex-end!important;gap:5px!important;margin-left:10px!important;vertical-align:baseline!important;transform:translateY(3px)!important;font-size:10.5px!important;line-height:1!important;font-weight:850!important;white-space:nowrap!important;color:#58606e!important;}
.admin-chat-bubble.admin .bubble-foot,
.orga-groupchat-bubble.admin .bubble-foot,
.orga-chat-bubble.own .bubble-foot,
.portal-bubble.customer .bubble-foot{color:#53654a!important;}
.receipt.ticks{display:inline-flex!important;position:relative!important;width:14px!important;height:11px!important;margin-left:1px!important;vertical-align:-1px!important;color:#87909a!important;font-size:12px!important;line-height:1!important;font-weight:950!important;}
.receipt.ticks.read{color:#1d9bf0!important;}
.receipt.ticks .tick{position:absolute!important;top:0!important;line-height:1!important;}
.receipt.ticks .tick-one{left:0!important;}
.receipt.ticks .tick-two{left:5px!important;}

/* Schweif ohne Rand: optisch Teil der Blase */
.admin-chat-bubble.first::after,
.orga-groupchat-bubble.first::after,
.orga-chat-bubble.first::after,
.portal-bubble.first::after{content:""!important;position:absolute!important;top:0!important;width:13px!important;height:13px!important;background:inherit!important;box-shadow:none!important;}
.admin-chat-bubble.admin.first::after,
.orga-groupchat-bubble.admin.first::after,
.orga-chat-bubble.own.first::after,
.portal-bubble.customer.first::after{right:-6px!important;clip-path:polygon(0 0,100% 0,0 100%)!important;}
.admin-chat-bubble.customer.first::after,
.orga-groupchat-bubble.customer.first::after,
.orga-chat-bubble.other.first::after,
.portal-bubble.admin.first::after{left:-6px!important;clip-path:polygon(0 0,100% 0,100% 100%)!important;}

/* Eingabezeile überall gleich */
.admin-wa-compose,
.orga-wa-compose,
.orga-groupchat-compose,
.portal-wa-compose{position:static!important;display:flex!important;align-items:flex-end!important;gap:8px!important;background:#fff!important;border:0!important;border-top:1px solid var(--kgbs-chat-border)!important;border-radius:0 0 22px 22px!important;padding:8px!important;box-shadow:none!important;min-height:58px!important;}
.admin-wa-compose textarea,
.orga-wa-compose textarea,
.orga-groupchat-compose textarea,
.portal-wa-compose textarea{flex:1 1 auto!important;min-height:40px!important;max-height:120px!important;padding:9px 11px!important;border:0!important;outline:0!important;resize:none!important;background:transparent!important;margin:0!important;line-height:1.35!important;font:inherit!important;}
.admin-wa-send,
.orga-wa-send,
.portal-wa-send{width:42px!important;height:42px!important;min-width:42px!important;border:0!important;border-radius:999px!important;background:var(--kgbs-chat-red)!important;color:#fff!important;font-size:21px!important;font-weight:950!important;display:none!important;align-items:center!important;justify-content:center!important;cursor:pointer!important;}
.admin-wa-send.active,
.orga-wa-send.active,
.portal-wa-send.active{display:flex!important;}

/* Portal Desktop / Mobile: Chatfenster bewusst kompakter */
.portal-chat-box{height:clamp(240px,42dvh,470px)!important;max-height:470px!important;}
@media(max-width:900px){
  body.admin-chat-screen{overflow:auto!important;}
  body.admin-chat-screen .admin-main-area{overflow:visible!important;}
  body.admin-chat-screen #adminContent{height:auto!important;min-height:0!important;overflow:visible!important;}
  body.admin-chat-screen .admin-communication-grid{height:auto!important;display:grid!important;grid-template-columns:1fr!important;gap:12px!important;overflow:visible!important;}
  body.admin-chat-screen .admin-chat-sidebar{max-height:220px!important;}
  body.admin-chat-screen .admin-chat-list{max-height:150px!important;}
  body.admin-chat-screen .admin-chat-panel{height:auto!important;min-height:0!important;}
  body.admin-chat-screen .admin-chat-messages{height:44dvh!important;max-height:44dvh!important;min-height:240px!important;}

  body.orga-chat-screen{overflow:auto!important;}
  body.orga-chat-screen .orga-shell,
  body.orga-chat-screen .orga-root-card,
  body.orga-chat-screen .orga-app-layout,
  body.orga-chat-screen .orga-workspace,
  body.orga-chat-screen #orgaMainContent{height:auto!important;max-height:none!important;overflow:visible!important;}
  body.orga-chat-screen .orga-chat-unified,
  body.orga-chat-screen .orga-groupchat-grid{height:auto!important;min-height:0!important;display:grid!important;grid-template-columns:1fr!important;gap:12px!important;overflow:visible!important;}
  body.orga-chat-screen .orga-chat-sidebar{max-height:220px!important;}
  body.orga-chat-screen .orga-chat-sidebar .orga-groupchat-list{max-height:150px!important;}
  body.orga-chat-screen .orga-chat-detail-card{height:auto!important;min-height:0!important;}
  body.orga-chat-screen .orga-groupchat-panel,
  body.orga-chat-screen .orga-chat-card{height:44dvh!important;max-height:44dvh!important;min-height:240px!important;}

  .portal-chat-box{height:34dvh!important;max-height:34dvh!important;min-height:190px!important;}
  .portal-chat-panel{max-height:none!important;}
  .admin-chat-bubble,
  .orga-groupchat-bubble,
  .orga-chat-bubble,
  .portal-bubble{max-width:86%!important;}
}
@media(max-width:520px){
  .portal-chat-box{height:30dvh!important;max-height:30dvh!important;min-height:170px!important;}
  .admin-chat-bubble,
  .orga-groupchat-bubble,
  .orga-chat-bubble,
  .portal-bubble{max-width:88%!important;font-size:14px!important;}
  .chat-avatar{width:28px!important;height:28px!important;min-width:28px!important;}
}
