/* XONOX Chat – Optik nach dem Forecast-Design (Apple-Look). Farben nur über CSS-Variablen,
   damit das Widget in anderen Apps deren Farben übernehmen kann (werden inline auf <html> gesetzt). */
:root, :root[data-theme="light"] {
  --bg: #f5f5f7; --surface: #ffffff; --surface-2: #f2f2f7; --border: #e5e5ea; --text: #1d1d1f; --muted: #6e6e73;
  --accent: #0071e3; --accent-contrast: #fff; --danger: #ff3b30; --ok: #34c759; --warn: #ff9f0a;
  --bubble-in: #e9e9eb; --bubble-in-text: #1d1d1f;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 30px rgba(0,0,0,.06);
  --radius: 18px;
  --font: var(--font-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif);
  --fill: color-mix(in srgb, var(--text) 6%, transparent);
  --ease: cubic-bezier(.32,.72,0,1); --spring: cubic-bezier(.34,1.4,.64,1);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000; --surface: #1c1c1e; --surface-2: #2c2c2e; --border: #38383a; --text: #f5f5f7; --muted: #98989d;
    --accent: #0a84ff; --accent-contrast: #fff; --danger: #ff453a; --ok: #30d158; --warn: #ff9f0a;
    --bubble-in: #2c2c2e; --bubble-in-text: #f5f5f7; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #000; --surface: #1c1c1e; --surface-2: #2c2c2e; --border: #38383a; --text: #f5f5f7; --muted: #98989d;
  --accent: #0a84ff; --accent-contrast: #fff; --danger: #ff453a; --ok: #30d158; --warn: #ff9f0a;
  --bubble-in: #2c2c2e; --bubble-in-text: #f5f5f7; --shadow: none;
}
/* Farben aus der einbettenden App: eingehende Blasen aus deren Flächenfarben ableiten */
:root[data-host-theme] { --bubble-in: color-mix(in srgb, var(--text) 9%, var(--surface)); --bubble-in-text: var(--text); }
:root:not(.embed) { color-scheme: light dark; }
:root[data-theme="light"]:not(.embed) { color-scheme: light; }
:root[data-theme="dark"]:not(.embed) { color-scheme: dark; }

* { box-sizing: border-box; }
html, body, #app { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.42 var(--font); letter-spacing: -.01em; -webkit-font-smoothing: antialiased; overflow: hidden; }
.embed body { background: transparent; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 26px; font-weight: 700; letter-spacing: -.03em; }
h2 { font-size: 18px; font-weight: 650; letter-spacing: -.02em; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }
:root { accent-color: var(--accent); }
* { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--text) 25%, transparent) transparent; }

/* ---- Bedienelemente (wie Forecast) ---- */
button, .btn { font: inherit; border: 0; background: var(--fill); color: var(--accent); padding: 8px 16px; border-radius: 980px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-weight: 500; text-decoration: none; transition: background .15s, filter .15s, transform .1s; }
button:hover, .btn:hover { background: color-mix(in srgb, var(--accent) 16%, transparent); }
button:active { transform: scale(.97); }
button.primary { background: var(--accent); color: var(--accent-contrast); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
button.ghost { background: transparent; }
button.ghost:hover { background: var(--fill); }
button.icon { width: 34px; height: 34px; padding: 0; border-radius: 50%; background: transparent; color: var(--accent); flex: none; }
button.icon:hover { background: var(--fill); }
button.icon svg { width: 20px; height: 20px; }
button:disabled { opacity: .4; cursor: default; transform: none; }
button:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 0; box-shadow: 0 0 0 1px var(--border) inset; border-radius: 10px; padding: 9px 12px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: none; box-shadow: 0 0 0 1px var(--accent) inset, 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent); }
input[type=search] { border-radius: 980px; background: var(--fill); box-shadow: none; padding-left: 34px; -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='%238e8e93' stroke-width='1.8' stroke-linecap='round'%3E%3Ccircle cx='7' cy='7' r='4.8'/%3E%3Cpath d='M11 11l3.2 3.2'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 12px center; background-size: 15px; }
input[type=search]:focus { background-color: var(--surface); }
input[type=checkbox] { -webkit-appearance: none; appearance: none; width: 20px; height: 20px; padding: 0; border-radius: 50%; flex: none; cursor: pointer;
  box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--text) 28%, transparent) inset; background: transparent center / 12px no-repeat; }
input[type=checkbox]:checked { background-color: var(--accent); box-shadow: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2.5 6.4l2.4 2.4 4.6-5'/%3E%3C/svg%3E"); }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 500; color: var(--muted); }
label.field > input, label.field > select { color: var(--text); font-size: 15px; }
.seg { display: inline-flex; border-radius: 980px; padding: 3px; gap: 2px; background: color-mix(in srgb, var(--text) 8%, transparent); }
.seg button { padding: 5px 14px; color: var(--text); background: transparent; }
.seg button.on { background: var(--surface); font-weight: 600; box-shadow: 0 1px 1px rgba(0,0,0,.08), 0 3px 8px rgba(0,0,0,.12); }
.error-text { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---- Login ---- */
.login-wrap { height: 100%; display: grid; place-items: center; padding: 16px; overflow: auto; }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; background: var(--surface); padding: 36px 32px; border-radius: 24px;
  box-shadow: 0 0 0 .5px color-mix(in srgb, var(--text) 8%, transparent), 0 12px 32px rgba(0,0,0,.06); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.02em; }
.brand .logo { width: 32px; height: 32px; border-radius: 9px; flex: none; }
.login-card .brand { font-size: 24px; }
.login-card .brand .logo { width: 44px; height: 44px; border-radius: 12px; }

/* ---- Grundlayout: Liste links, Verlauf rechts ---- */
.app { display: grid; grid-template-columns: 330px 1fr; height: 100%; background: var(--bg); }
.embed .app { background: var(--surface); }
.pane-list { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 72%, transparent); -webkit-backdrop-filter: saturate(180%) blur(24px); backdrop-filter: saturate(180%) blur(24px); }
.embed .pane-list { background: color-mix(in srgb, var(--text) 3%, var(--surface)); }
.list-head { display: flex; align-items: center; gap: 4px; padding: 14px 12px 8px 16px; }
.list-head h1 { flex: 1; font-size: 24px; }
.embed .list-head h1 { font-size: 20px; }
.list-search { padding: 4px 12px 10px; }
.list-search input { width: 100%; }
.conv-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.conv { display: flex; gap: 11px; align-items: center; padding: 9px 10px; border-radius: 12px; cursor: pointer; position: relative; transition: background .15s; }
.conv:hover { background: var(--fill); }
.conv.active { background: var(--accent); color: var(--accent-contrast); }
.conv.active .conv-sub, .conv.active .conv-time { color: color-mix(in srgb, var(--accent-contrast) 80%, transparent); }
.conv-main { flex: 1; min-width: 0; }
.conv-top { display: flex; gap: 8px; align-items: baseline; }
.conv-name { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 12.5px; color: var(--muted); flex: none; }
.conv-bottom { display: flex; gap: 8px; align-items: center; }
.conv-sub { flex: 1; font-size: 13.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv.unread .conv-sub { color: var(--text); }
.conv.active.unread .conv-sub { color: var(--accent-contrast); }
.unread-badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: var(--accent-contrast); font-size: 12px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; flex: none; }
.conv.active .unread-badge { background: var(--accent-contrast); color: var(--accent); }
.muted-icon { width: 14px; height: 14px; flex: none; opacity: .6; }
.list-empty { padding: 30px 16px; text-align: center; color: var(--muted); font-size: 14px; }
.list-foot { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); font-size: 13.5px; }
.list-foot .me { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* Avatare */
.avatar { --size: 44px; width: var(--size); height: var(--size); border-radius: 50%; flex: none; display: grid; place-items: center; position: relative;
  color: #fff; font-weight: 600; font-size: calc(var(--size) * .38); letter-spacing: 0; background: linear-gradient(180deg, color-mix(in srgb, var(--av) 75%, #fff), var(--av)); }
.avatar.sm { --size: 28px; } .avatar.xs { --size: 22px; } .avatar.lg { --size: 64px; }
.avatar svg { width: 55%; height: 55%; }
.avatar .dot { position: absolute; right: 0; bottom: 0; width: 28%; height: 28%; min-width: 9px; min-height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 2px var(--surface); }

/* ---- Verlauf ---- */
.pane-chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); position: relative; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); min-height: 60px;
  background: color-mix(in srgb, var(--surface) 80%, transparent); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px); z-index: 2; }
.chat-title { flex: 1; min-width: 0; cursor: default; }
.chat-title.clickable { cursor: pointer; }
.chat-title .name { font-weight: 650; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-title .sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back-btn { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 14px 16px 8px; display: flex; flex-direction: column; overscroll-behavior: contain; }
.messages .spacer { flex: 1; }
.load-more { align-self: center; margin: 4px 0 12px; font-size: 13px; }
.day { align-self: center; font-size: 12px; font-weight: 600; color: var(--muted); margin: 14px 0 8px; }
.sys { align-self: center; font-size: 12.5px; color: var(--muted); margin: 6px 0; text-align: center; max-width: 80%; }
.msg { display: flex; gap: 8px; align-items: flex-end; max-width: 78%; margin-top: 2px; position: relative; }
.msg.first { margin-top: 10px; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg .avatar-slot { width: 28px; flex: none; }
.msg-col { display: flex; flex-direction: column; min-width: 0; align-items: flex-start; }
.msg.mine .msg-col { align-items: flex-end; }
.sender { font-size: 12px; color: var(--muted); margin: 0 12px 2px; font-weight: 500; }
.bubble { padding: 7px 13px; border-radius: 19px; background: var(--bubble-in); color: var(--bubble-in-text); white-space: pre-wrap; overflow-wrap: anywhere; max-width: 100%; }
.msg.mine .bubble { background: var(--accent); color: var(--accent-contrast); }
.msg.mine .bubble a { color: inherit; }
.bubble.deleted { background: transparent !important; color: var(--muted) !important; font-style: italic; box-shadow: 0 0 0 1px var(--border) inset; }
.bubble.flash { animation: flash 1.2s var(--ease); }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 70%, transparent); } }
.meta { font-size: 11.5px; color: var(--muted); margin: 2px 12px 0; }
.msg-actions { position: absolute; top: -4px; display: none; gap: 2px; background: var(--surface); border-radius: 980px; padding: 2px; box-shadow: 0 0 0 .5px var(--border), 0 4px 14px rgba(0,0,0,.12); z-index: 1; }
.msg.mine .msg-actions { right: calc(100% + 4px); }
.msg:not(.mine) .msg-actions { left: calc(100% + 4px); }
.msg:hover .msg-actions, .msg:focus-within .msg-actions { display: flex; }
.msg-actions button { width: 28px; height: 28px; padding: 0; background: transparent; color: var(--muted); }
.msg-actions button:hover { color: var(--accent); background: var(--fill); }
.msg-actions svg { width: 15px; height: 15px; }
.atts { display: flex; flex-direction: column; gap: 4px; margin-bottom: 3px; max-width: 100%; }
.msg.mine .atts { align-items: flex-end; }
.att-img { display: block; border-radius: 16px; overflow: hidden; max-width: min(300px, 100%); background: var(--fill); cursor: zoom-in; }
.att-img img { display: block; max-width: 100%; max-height: 300px; object-fit: contain; }
.att-file { display: flex; align-items: center; gap: 10px; padding: 9px 14px 9px 10px; border-radius: 16px; background: var(--bubble-in); color: var(--bubble-in-text); text-decoration: none; max-width: 320px; }
.msg.mine .att-file { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); color: var(--text); }
.att-file:hover { filter: brightness(.97); }
.att-file .ficon { width: 34px; height: 40px; flex: none; border-radius: 6px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 10px; font-weight: 700; text-transform: uppercase; }
.att-file .fname { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-file .fsize { font-size: 12px; color: var(--muted); }
.att-file > div { min-width: 0; }
.chat-empty { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 24px; }
.chat-empty svg { width: 64px; height: 64px; opacity: .35; margin-bottom: 10px; }

/* Eingabe */
.composer { padding: 8px 12px 12px; border-top: 1px solid color-mix(in srgb, var(--border) 60%, transparent); }
.pending { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.pending .chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 10px; border-radius: 980px; background: var(--fill); font-size: 13px; max-width: 240px; }
.pending .chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pending .chip.err { color: var(--danger); }
.pending .chip .prog { width: 40px; height: 4px; border-radius: 2px; background: var(--border); overflow: hidden; flex: none; }
.pending .chip .prog i { display: block; height: 100%; background: var(--accent); width: 0; }
.pending .chip button { width: 20px; height: 20px; padding: 0; background: transparent; color: var(--muted); }
.compose-row { display: flex; align-items: flex-end; gap: 6px; }
.compose-box { flex: 1; display: flex; align-items: flex-end; border-radius: 20px; box-shadow: 0 0 0 1px var(--border) inset; background: var(--surface); }
.compose-box:focus-within { box-shadow: 0 0 0 1px var(--accent) inset, 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent); }
.compose-box textarea { flex: 1; resize: none; border: 0; box-shadow: none !important; background: transparent; padding: 9px 14px; max-height: 160px; min-height: 38px; line-height: 1.35; }
.send-btn { width: 32px; height: 32px; margin: 3px; padding: 0; border-radius: 50%; background: var(--accent); color: var(--accent-contrast); flex: none; }
.send-btn:hover { background: var(--accent); filter: brightness(1.08); }
.send-btn svg { width: 18px; height: 18px; }
.edit-note { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.drop-hint { position: absolute; inset: 8px; border-radius: 16px; border: 2px dashed var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  display: grid; place-items: center; font-weight: 600; color: var(--accent); z-index: 5; pointer-events: none; }

/* ---- Dialoge ---- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); display: flex; align-items: flex-start;
  justify-content: center; padding: 6vh 12px; z-index: 50; overflow: auto; animation: fade .2s; }
.modal { background: var(--surface); border-radius: 22px; width: min(480px, 100%); box-shadow: 0 30px 80px rgba(0,0,0,.3); display: flex; flex-direction: column; max-height: 88vh; animation: pop .3s var(--spring); }
.modal.wide { width: min(760px, 100%); }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.modal header h2 { flex: 1; }
.modal .body { padding: 16px 20px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.modal footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0 } }
@keyframes pop { from { opacity: 0; transform: scale(.95) translateY(8px) } }
.pick-list { display: flex; flex-direction: column; max-height: 50vh; overflow: auto; margin: 0 -8px; }
.pick { display: flex; align-items: center; gap: 11px; padding: 8px; border-radius: 12px; cursor: pointer; }
.pick:hover { background: var(--fill); }
.pick .who { flex: 1; min-width: 0; }
.pick .who small { display: block; color: var(--muted); font-size: 12.5px; }
.members .pick { cursor: default; }
.section-title { font-size: 12.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-top: 6px; }
table.users { width: 100%; border-collapse: collapse; font-size: 14px; }
table.users th, table.users td { padding: 8px 6px; border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent); text-align: left; }
table.users th { font-weight: 500; font-size: 12.5px; color: var(--muted); }
table.users tr.inactive td { opacity: .5; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1; min-width: 140px; }
.menu { position: fixed; z-index: 60; min-width: 220px; background: color-mix(in srgb, var(--surface) 94%, transparent); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  border-radius: 14px; padding: 6px; box-shadow: 0 0 0 .5px var(--border), 0 12px 40px rgba(0,0,0,.22); animation: pop .2s var(--ease); }
.menu button { width: 100%; justify-content: flex-start; background: transparent; color: var(--text); border-radius: 8px; padding: 8px 12px; font-weight: 400; }
.menu button:hover { background: var(--accent); color: var(--accent-contrast); }
.menu button.danger { color: var(--danger); }
.menu button.danger:hover { background: var(--danger); color: #fff; }
.menu hr { border: 0; height: 1px; background: var(--border); margin: 5px 6px; }
.lightbox { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.85); display: grid; place-items: center; padding: 24px; cursor: zoom-out; animation: fade .2s; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 80; align-items: center; }
.toast { background: color-mix(in srgb, var(--text) 88%, transparent); color: var(--bg); padding: 9px 16px; border-radius: 14px; font-size: 14px; animation: pop .25s var(--spring); }
.toast.error { background: var(--danger); color: #fff; }

/* ---- Schnellantwort (oben mittig) ---- */
.quick-wrap { position: fixed; top: 0; left: 0; right: 0; display: flex; justify-content: center; padding: 10px 12px 24px; z-index: 90; pointer-events: none; }
.embed .quick-wrap { position: static; padding: 10px 28px 40px; }
.quick { pointer-events: auto; width: min(460px, 100%); background: color-mix(in srgb, var(--surface) 92%, transparent); -webkit-backdrop-filter: saturate(180%) blur(24px); backdrop-filter: saturate(180%) blur(24px);
  border-radius: 22px; padding: 12px 12px 12px; box-shadow: 0 0 0 .5px color-mix(in srgb, var(--text) 12%, transparent), 0 10px 30px rgba(0,0,0,.22); animation: drop .35s var(--spring); }
.embed .quick { background: var(--surface); }
@keyframes drop { from { opacity: 0; transform: translateY(-16px) scale(.97) } }
.quick-head { display: flex; align-items: center; gap: 10px; }
.quick-head .who { flex: 1; min-width: 0; cursor: pointer; }
.quick-head .who b { display: block; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quick-head .who small { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quick-body { margin: 8px 2px 10px 50px; font-size: 14.5px; white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; }
.quick-body .more { color: var(--muted); font-size: 12.5px; }
.quick form { display: flex; gap: 6px; align-items: center; }
.quick form input { flex: 1; border-radius: 980px; padding: 8px 14px; }
.quick .sent { text-align: center; color: var(--ok); font-weight: 600; padding: 6px; }

/* ---- Schmal: eine Spalte ---- */
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .app.has-active .pane-list { display: none; }
  .app:not(.has-active) .pane-chat { display: none; }
  .back-btn { display: inline-flex; }
  .msg { max-width: 88%; }
  .msg-actions { display: none !important; }
  .msg.show-actions .msg-actions { display: flex !important; }
  input, textarea, select { font-size: 16px !important; }
}
