/* Home-OS · Modul 5 · Familien-Chat
   Baut auf themes.css (Farben je Theme) und app.css (Knöpfe, Karten, Dialoge) auf.
   Klickflächen mindestens 44 × 44 px, Fokus immer sichtbar, Bewegung nur ohne „reduzierte Bewegung“. */

.hide-sm { }
@media (max-width: 640px) { .hide-sm { display: none !important; } }
.small { font-size: 15px; }
.warn-text { color: var(--color-sun-700); }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.label { font-weight: 700; }

/* ---- Grundgerüst: links Liste, rechts Unterhaltung. Am Handy immer nur eins von beiden. */
.app { padding-bottom: 24px; }
.chat-shell { display: grid; grid-template-columns: minmax(280px, 360px) 1fr; gap: 16px; height: calc(100dvh - 120px); min-height: 480px; }
.chat-side, .chat-main {
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-panel);
  box-shadow: var(--shadow-soft); min-height: 0; overflow: hidden; display: flex; flex-direction: column;
}
.chat-side { overflow-y: auto; padding: 12px; gap: 10px; }
@media (max-width: 819px) {
  .app { padding: 10px 8px 10px; }
  .topbar { margin-bottom: 10px; }
  .chat-shell { grid-template-columns: 1fr; height: calc(100dvh - 90px); }
  body.main-open .chat-side { display: none; }
  body:not(.main-open) .chat-main { display: none; }
}
@media (min-width: 820px) { .back-btn { display: none !important; } }
.conn-badge svg { width: 18px; height: 18px; }

/* ---- Reiter und Listen */
.side-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.side-tab {
  flex: 1; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--color-border); background: var(--color-soft); color: var(--color-text);
  border-radius: 999px; font: inherit; font-weight: 700; padding: 6px 12px; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.side-tab svg { width: 20px; height: 20px; }
.side-tab.is-active { background: var(--color-primary); color: var(--color-on-primary); border-color: transparent; }
.side-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 6px 4px 0; }
.side-head .h2 { margin: 0; }
.count {
  min-width: 24px; height: 24px; padding: 0 7px; border-radius: 999px; display: inline-grid; place-items: center;
  background: var(--color-primary); color: var(--color-on-primary); font-size: 14px; font-weight: 800; line-height: 1;
}
.side-tab.is-active .count { background: var(--color-surface); color: var(--color-text); }
.count.is-alert { background: var(--color-danger); color: var(--color-on-danger); }

.push-hint { display: flex; gap: 10px; padding: 12px 14px; background: var(--color-info-bg); border-radius: var(--radius-control); border: 1px solid var(--color-border); }
.push-hint > svg { width: 24px; height: 24px; flex: none; color: var(--color-link); }
.push-hint p { margin: 2px 0 0; font-size: 15px; }

.chat-list, .member-list, .pick-list, .report-list, .rule-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.chat-item, .member, .pick {
  display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: var(--radius-control);
  color: var(--color-text); text-decoration: none; min-height: 64px; width: 100%; text-align: left;
  background: transparent; border: 2px solid transparent; font: inherit; cursor: pointer;
}
.member, .pick.is-static { cursor: default; }
.chat-item:hover, .pick:not(:disabled):not(.is-static):hover { background: var(--color-soft); }
.chat-item.is-active { background: var(--color-secondary); border-color: var(--color-secondary-border); }
.pick:disabled { opacity: .55; cursor: not-allowed; }
.ci-text { display: grid; gap: 2px; min-width: 0; flex: 1; }
.ci-top, .ci-bottom { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ci-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.ci-time { font-size: 14px; flex: none; }
.ci-preview, .ci-typing, .ci-call { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; font-size: 15px; }
.ci-typing { color: var(--color-meadow-600); font-style: italic; }
.ci-call { color: var(--color-success); font-weight: 700; display: inline-flex; align-items: center; gap: 4px; }
.ci-call svg, .ci-muted svg { width: 16px; height: 16px; }
.ci-muted { color: var(--color-text-muted); display: inline-flex; }
.has-unread .ci-title, .has-unread .ci-preview { font-weight: 800; color: var(--color-text); }
.member-actions { display: flex; gap: 0; flex: none; }
.member .ci-text > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (min-width: 820px) and (max-width: 1100px) { .member-actions .icon-btn:nth-child(3) { display: none; } }

.chat-ava { position: relative; width: 48px; height: 48px; flex: none; display: inline-grid; place-items: center; border-radius: 50%; }
.chat-ava > svg { width: 100%; height: 100%; }
.chat-ava.is-big { width: 52px; height: 52px; }
.chat-ava.is-sm { width: 32px; height: 32px; }
.chat-ava-icon > svg { width: 26px; height: 26px; }
.online-dot { position: absolute; right: 0; bottom: 0; width: 14px; height: 14px; border-radius: 50%; background: var(--color-success); border: 3px solid var(--color-surface); }

.icon-btn {
  width: 44px; height: 44px; display: inline-grid; place-items: center; border-radius: 50%; flex: none;
  background: transparent; border: 0; color: var(--color-text); cursor: pointer; text-decoration: none;
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:hover:not(:disabled) { background: var(--color-soft); }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }
.icon-btn:focus-visible, .side-tab:focus-visible, .chat-item:focus-visible, .pick:focus-visible, .msg-more:focus-visible, .emoji:focus-visible, .bubble-img:focus-visible {
  outline: 3px solid var(--color-focus); outline-offset: 2px;
}

/* ---- Unterhaltung */
.main-empty { margin: auto; text-align: center; padding: 24px; display: grid; justify-items: center; gap: 8px; }
.hero-icon { width: 84px; height: 84px; border-radius: 28px; display: grid; place-items: center; }
.hero-icon svg { width: 46px; height: 46px; }
.conv { display: flex; flex-direction: column; height: 100%; min-height: 0; position: relative; }
.conv-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--color-border); background: var(--color-glass); }
.conv-title { flex: 1; min-width: 0; }
.conv-title .h2 { margin: 0; font-size: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-title p { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 480px) { .conv-head > .chat-ava { display: none; } .conv-head { gap: 6px; padding: 8px; } .conv-actions { gap: 4px; } }
.conv-title .is-online { color: var(--color-success); }
.conv-actions { display: flex; gap: 6px; align-items: center; }
.conv-banner:empty { display: none; }
.conv-banner { padding: 8px 12px 0; display: grid; gap: 8px; }
.call-banner { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: var(--radius-control); background: var(--color-success-bg); color: var(--color-success); font-weight: 700; flex-wrap: wrap; }
.call-banner > svg { width: 22px; height: 22px; }
.call-banner span { flex: 1; }

.msgs-scroll { flex: 1; overflow-y: auto; padding: 12px 12px 6px; overscroll-behavior: contain; }
.msgs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.msgs:focus-visible { outline: 3px solid var(--color-focus); outline-offset: -3px; }
.msgs-more, .msgs-empty, .msgs-loading { text-align: center; padding: 10px; }
.day-sep { text-align: center; margin: 12px 0 6px; }
.day-sep span { display: inline-block; padding: 4px 12px; border-radius: 999px; background: var(--color-soft); font-size: 14px; font-weight: 700; color: var(--color-text-muted); }
.msg-system { text-align: center; font-size: 14px; color: var(--color-text-muted); margin: 6px 0; }
.msg-call { display: flex; align-items: center; gap: 10px; align-self: center; margin: 8px 0; padding: 8px 14px; border-radius: var(--radius-control); background: var(--color-soft); flex-wrap: wrap; justify-content: center; max-width: 100%; }
.msg-call > svg { width: 22px; height: 22px; color: var(--color-success); }
.msg-call.is-missed > svg, .msg-call.is-missed strong { color: var(--color-danger); }

.msg { display: flex; gap: 8px; align-items: flex-end; max-width: min(78%, 640px); }
.msg.first { margin-top: 8px; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg-ava { width: 34px; height: 34px; flex: none; }
.msg-ava svg { width: 34px; height: 34px; }
.msg-body { display: grid; gap: 2px; min-width: 0; }
.msg.mine .msg-body { justify-items: end; }
.msg-sender { font-size: 14px; font-weight: 800; color: var(--color-meadow-600); padding-left: 12px; }
.bubble {
  padding: 9px 14px; border-radius: 20px 20px 20px 6px; background: var(--color-soft); color: var(--color-text);
  border: 1px solid var(--color-border); overflow-wrap: anywhere; max-width: 100%;
}
.msg.mine .bubble { background: var(--color-secondary); border-color: var(--color-secondary-border); border-radius: 20px 20px 6px 20px; }
.bubble p { margin: 0; white-space: pre-wrap; }
.bubble a { color: var(--color-link); font-weight: 700; }
.bubble-text.is-emoji { font-size: 40px; line-height: 1.2; }
.bubble:has(.is-emoji) { background: transparent; border-color: transparent; padding: 0 4px; }
.bubble-deleted { color: var(--color-text-muted); font-style: italic; display: inline-flex; align-items: center; gap: 6px; }
.bubble-deleted svg { width: 16px; height: 16px; }
.bubble-image { padding: 4px; }
.bubble-img { display: block; padding: 0; border: 0; background: none; cursor: zoom-in; border-radius: 16px; overflow: hidden; }
.bubble-img img { display: block; max-width: min(320px, 64vw); max-height: 360px; width: auto; height: auto; object-fit: cover; border-radius: 16px; }
.voice { display: flex; align-items: center; gap: 8px; }
.voice > svg { width: 22px; height: 22px; flex: none; color: var(--color-meadow-600); }
.voice audio { height: 40px; max-width: min(260px, 52vw); }
.msg-foot { display: flex; align-items: center; gap: 4px; padding: 0 6px; }
.msg-meta { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--color-text-muted); }
.tick { display: inline-flex; }
.tick svg { width: 16px; height: 16px; }
.tick.is-read { color: var(--color-link); }
.retry { color: var(--color-danger); background: none; border: 0; font: inherit; font-size: 14px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; min-height: 32px; text-decoration: underline; }
.retry svg { width: 16px; height: 16px; }
.msg-more { width: 32px; height: 32px; border-radius: 50%; border: 0; background: transparent; color: var(--color-text-muted); cursor: pointer; display: inline-grid; place-items: center; opacity: .55; }
.msg-more svg { width: 18px; height: 18px; }
.msg:hover .msg-more, .msg-more:focus-visible { opacity: 1; }
@media (pointer: coarse) { .msg-more { width: 40px; height: 40px; opacity: .8; } }

.new-msgs { position: absolute; left: 50%; transform: translateX(-50%); bottom: 96px; z-index: 3; }
.typing-line { min-height: 22px; margin: 0; padding: 0 18px; font-size: 14px; font-style: italic; color: var(--color-meadow-600); }

/* ---- Schreibfeld */
.composer { position: relative; display: flex; align-items: flex-end; gap: 4px; padding: 8px 10px 10px; border-top: 1px solid var(--color-border); background: var(--color-glass); }
.composer.is-disabled { opacity: .6; }
.composer-input {
  flex: 1; min-height: 48px; max-height: 160px; resize: none; padding: 11px 14px; border-radius: 24px;
  border: 2px solid var(--color-input-border); background: var(--color-input-bg); color: var(--color-text); font: inherit; line-height: 1.4;
}
.composer-input:focus-visible { outline: 3px solid var(--color-focus); outline-offset: 1px; border-color: var(--color-link); }
.composer-send { min-height: 48px; border-radius: 24px; padding: 8px 16px; }
.emoji-pop {
  position: absolute; bottom: calc(100% + 6px); left: 8px; z-index: 20; display: grid; grid-template-columns: repeat(8, 40px); gap: 2px;
  padding: 8px; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-control); box-shadow: var(--shadow-lift);
}
@media (max-width: 400px) { .emoji-pop { grid-template-columns: repeat(6, 40px); } }
.emoji { width: 40px; height: 40px; font-size: 24px; border: 0; background: none; border-radius: 10px; cursor: pointer; }
.emoji:hover { background: var(--color-soft); }
.rec-bar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--color-border); background: var(--color-danger-bg); flex-wrap: wrap; }
.rec-bar > span:nth-child(2) { font-weight: 700; color: var(--color-danger); }
.rec-time { font-variant-numeric: tabular-nums; flex: 1; }
.rec-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--color-danger); }
@media (prefers-reduced-motion: no-preference) { .rec-dot { animation: pulse 1.2s ease-in-out infinite; } }
@keyframes pulse { 50% { opacity: .3; } }

/* ---- Menüs und Dialoge */
.pop-menu {
  position: fixed; z-index: 60; min-width: 220px; padding: 6px; display: grid; gap: 2px;
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-control); box-shadow: var(--shadow-lift);
}
.pop-item { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 8px 12px; border: 0; border-radius: 10px; background: none; color: var(--color-text); font: inherit; text-align: left; cursor: pointer; }
.pop-item svg { width: 20px; height: 20px; }
.pop-item:hover, .pop-item:focus-visible { background: var(--color-soft); outline: none; }
.pop-item:focus-visible { box-shadow: inset 0 0 0 3px var(--color-focus); }
.pop-item.is-danger { color: var(--color-danger); }
.dlg-sub { font-size: 17px; margin: 20px 0 8px; }
.check-list { border: 0; padding: 0; margin: 0; display: grid; gap: 6px; }
.check-list legend { margin-bottom: 8px; }
.check-row { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check-row input { width: 22px; height: 22px; accent-color: var(--color-primary); flex: none; }
.check-row label { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.grp-form { margin-top: 8px; border-top: 1px solid var(--color-border); padding-top: 4px; display: grid; gap: 12px; }
.lightbox { max-width: min(96vw, 1200px); background: var(--color-surface); }
.lightbox-inner { padding: 12px; }
.lightbox-inner img { display: block; max-width: 100%; max-height: 78vh; margin: 0 auto 12px; border-radius: 12px; }

/* ---- Verwalten */
.admin { overflow-y: auto; padding: 16px; display: grid; gap: 24px; align-content: start; }
.admin-sec { display: grid; gap: 10px; }
.report { padding: 14px; border-radius: var(--radius-control); border: 1px solid var(--color-pending-border); background: var(--color-pending-bg); display: grid; gap: 8px; }
.report.is-done { background: var(--color-soft); border-color: var(--color-border); opacity: .8; }
.report-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.report p { margin: 0; }
.report-quote { margin: 0; padding: 10px 14px; border-left: 4px solid var(--color-danger); background: var(--color-surface); border-radius: 8px; white-space: pre-wrap; overflow-wrap: anywhere; }
.report-img { max-width: 240px; max-height: 240px; border-radius: 10px; }
.kid-box { padding: 14px; border: 1px solid var(--color-border); border-radius: var(--radius-control); background: var(--color-soft); }
.kid-name { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; }
.rule { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 6px 0; }
.rule-name { flex: 1; min-width: 120px; font-weight: 700; }
.rule .badge svg { width: 16px; height: 16px; }

/* ---- Anruf (Vollbild) */
body.in-call { overflow: hidden; }
.call-layer {
  position: fixed; inset: 0; z-index: 80; display: flex; flex-direction: column; gap: 12px; padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom)); background: #10221b; color: #fff;
}
.call-top { text-align: center; }
.call-title { margin: 0; font-family: var(--font-display); font-size: 24px; color: #fff; }
.call-status { margin: 4px 0 0; color: #cfe3da; }
.call-grid { flex: 1; min-height: 0; display: grid; gap: 10px; grid-template-columns: 1fr; grid-auto-rows: 1fr; }
.call-grid[data-count="2"] { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.call-grid[data-count="3"], .call-grid[data-count="4"] { grid-template-columns: repeat(2, 1fr); }
.call-grid[data-count="5"], .call-grid[data-count="6"] { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
@media (max-width: 640px) { .call-grid[data-count="2"] { grid-template-columns: 1fr; } }
.call-tile { position: relative; border-radius: 20px; overflow: hidden; background: #1d3a2f; display: grid; place-items: center; min-height: 120px; }
.call-tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; }
.call-tile.has-video video { opacity: 1; }
.call-tile.has-video .tile-ava { visibility: hidden; }
.tile-ava { width: 112px; height: 112px; }
.tile-ava svg { width: 100%; height: 100%; }
.call-tile.is-waiting { gap: 12px; align-content: center; }
.call-tile.is-waiting .tile-name { position: static; }
@media (prefers-reduced-motion: no-preference) { .call-tile.is-waiting .tile-ava { animation: pulse 1.6s ease-in-out infinite; } }
.tile-foot { position: absolute; left: 10px; bottom: 10px; display: flex; align-items: center; gap: 6px; }
.tile-name, .tile-badge:not(:empty) { background: rgba(0, 0, 0, .55); color: #fff; padding: 4px 10px; border-radius: 999px; font-weight: 700; font-size: 15px; display: inline-flex; align-items: center; gap: 4px; }
.tile-badge svg { width: 16px; height: 16px; }
.call-self { position: absolute; right: 20px; top: 84px; width: min(28vw, 180px); aspect-ratio: 3 / 4; object-fit: cover; border-radius: 16px; border: 2px solid rgba(255, 255, 255, .6); background: #000; z-index: 2; }
@media (min-width: 820px) { .call-self { aspect-ratio: 4 / 3; width: 220px; } }
.call-self.mirror { transform: scaleX(-1); }
.call-controls { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; }
.round-btn { display: grid; justify-items: center; gap: 6px; background: none; border: 0; color: #fff; font: inherit; font-size: 14px; font-weight: 700; cursor: pointer; min-width: 64px; }
.round { width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, .16); transition: transform .12s; }
.round svg { width: 28px; height: 28px; }
.round-btn:hover .round { transform: scale(1.06); }
.round-btn:focus-visible { outline: none; }
.round-btn:focus-visible .round { outline: 3px solid #fff; outline-offset: 3px; }
.round-btn.is-off .round { background: #fff; color: #10221b; }
.round-btn.is-danger .round { background: #d64545; }
.round-btn.is-go .round { background: #2f9e5b; }
.sound-btn { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 5; }

.ring-layer { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 16px; background: rgba(16, 34, 27, .78); }
.ring-card { width: 100%; max-width: 420px; text-align: center; padding: 32px 24px; border-radius: var(--radius-panel); background: var(--color-surface); box-shadow: var(--shadow-lift); }
.ring-card .h1 { margin: 12px 0 4px; }
.ring-ava { width: 120px; height: 120px; margin: 0 auto; }
.ring-ava svg { width: 100%; height: 100%; }
@media (prefers-reduced-motion: no-preference) { .ring-ava { animation: pulse 1.2s ease-in-out infinite; } }
.ring-actions { display: flex; justify-content: center; gap: 22px; margin-top: 24px; }
.ring-actions .round-btn { color: var(--color-text); }
.ring-actions .is-soft .round { background: var(--color-soft); color: var(--color-text); }
@media (prefers-reduced-motion: reduce) { .round { transition: none; } }
.call-layer[hidden], .ring-layer[hidden], .conn-badge[hidden], .new-msgs[hidden], .composer[hidden] { display: none !important; }
