/* ============================================================
   Kitchen Talks — Mobile-first, elder-friendly stylesheet
   ============================================================ */

/* ── CSS Variables ──────────────────────────────────────────── */
:root {
  --clr-primary:       #27AE60;
  --clr-primary-dark:  #1E8449;
  --clr-primary-light: #D5F5E3;
  --clr-bg:            #F0F4F0;
  --clr-surface:       #FFFFFF;
  --clr-border:        #DADADA;
  --clr-text:          #1A1A1A;
  --clr-text-muted:    #5A5A5A;
  --clr-bubble-out:    #D5F5E3;
  --clr-bubble-in:     #FFFFFF;
  --clr-danger:        #C0392B;
  --clr-online:        #2ECC71;

  --font-base:   17px;
  --font-sm:     14px;
  --font-lg:     20px;
  --font-xl:     26px;

  --radius-sm:   8px;
  --radius-md:   14px;
  --radius-lg:   20px;

  --shadow-sm:   0 1px 4px rgba(0,0,0,.10);
  --shadow-md:   0 3px 12px rgba(0,0,0,.13);

  --touch:       52px;   /* minimum touch-target height */
  --bar-h:       60px;   /* top-bar height */
  --input-bar-h: 66px;   /* bottom input bar */
}

/* ── Reset / Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: var(--font-base);
  color: var(--clr-text);
  background: var(--clr-bg);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button { cursor: pointer; border: none; background: none; font: inherit; }
input  { font: inherit; }
a      { color: inherit; }
img    { max-width: 100%; display: block; border-radius: var(--radius-sm); }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.hidden, [hidden] { display: none !important; }

/* ── App layout ─────────────────────────────────────────────── */
#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  /* Prevent virtual keyboard from pushing layout on mobile. 100% is the
     fallback for browsers without dvh support; 100dvh (kept up to date by
     JS via --app-height on iOS, where dvh alone can lag/jump) must win when
     supported, so it's declared last. */
  height: 100%;
  height: 100dvh;
  height: var(--app-height, 100dvh);
}

.screen {
  display: flex;
  flex-direction: column;
  flex: 1;          /* fill remaining space above the install banner */
  overflow: hidden;
  min-height: 0;    /* allow shrinking in flex context */
}

/* ── Top bar ────────────────────────────────────────────────── */
.top-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--bar-h);
  padding: 0 12px;
  background: var(--clr-primary);
  color: #fff;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.top-bar.telegram {
  background: #229ED9;
}

.top-bar-title {
  font-size: var(--font-lg);
  font-weight: 700;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-bar-actions { display: flex; gap: 4px; }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--touch);
  height: var(--touch);
  border-radius: 50%;
  font-size: 22px;
  color: #fff;
  transition: background .15s;
}
.icon-btn:hover, .icon-btn:active { background: rgba(255,255,255,.2); }
.top-bar .icon-btn { color: #fff; }

/* ── Status row ─────────────────────────────────────────────── */
.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: var(--clr-surface);
  border-bottom: 1px solid var(--clr-border);
  flex-shrink: 0;
}

.version-badge {
  font-size: 10px;
  color: var(--clr-text-muted);
  opacity: 0.7;
  margin-left: auto;
}

.status-badge {
  font-size: var(--font-sm);
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
}
.status-badge.connected    { background: var(--clr-primary-light); color: var(--clr-primary-dark); }
.status-badge.disconnected { background: #FDECEA; color: var(--clr-danger); }
.status-badge.telegram-online { background: rgba(34, 158, 217, 0.12); color: #0E678A; }
.status-badge.telegram-offline { background: #F2F4F5; color: #4B5563; }
.status-badge.telegram-reconnecting { background: #FFF3E0; color: #E65100; }
#telegram-status {
  cursor: pointer;
  user-select: none;
  position: relative;
  transition: opacity 0.2s ease;
}
#telegram-status:hover {
  opacity: 0.85;
}
/* Animated ring around the badge while contacts/chats are syncing */
#telegram-status.syncing {
  position: relative;
}

#telegram-status.syncing::after {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: inherit;
  border: 2px solid #229ED9;
  opacity: .5;
  pointer-events: none;
  animation: kt-border-breathe 2s ease-in-out infinite;
}

@keyframes kt-border-breathe {
  0%,100% {
    opacity: .3;
  }
  50% {
    opacity: 1;
  }
}



.knock-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--font-sm);
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  background: #FFF3E0;
  color: #E65100;
  border: 1.5px solid #FFB74D;
  cursor: pointer;
  animation: knock-pulse 1.5s ease-in-out infinite;
}
.knock-badge.hidden { display: none; }
@keyframes knock-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

/* ── Section labels ─────────────────────────────────────────── */
.section-label {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--clr-text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 10px 14px 4px;
  flex-shrink: 0;
}

/* ── Online users list ──────────────────────────────────────── */
.online-list {
  display: flex;
  gap: 10px;
  padding: 8px 14px 6px;
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
}
.online-list::-webkit-scrollbar { display: none; }

.user-pill {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  min-width: 62px;
  width: 100%;
  font-size: var(--font-sm);
  color: var(--clr-text);
  padding: 6px 4px;
  border-radius: var(--radius-md);
  transition: background .15s;
}
.user-pill:active { background: var(--clr-primary-light); }
.user-pill .avatar {
  width: 46px; height: 46px;
  font-size: 20px; font-weight: 700;
  color: #fff;
}
.user-pill.offline {
  opacity: 0.6;
}
.user-pill.offline .avatar {
  background: #999;
  margin: 4px;
}

.last-seen-badge {
  font-size: 11px;
  color: var(--clr-text-muted);
  background: rgba(0,0,0,0.06);
  padding: 1px 6px;
  border-radius: 8px;
  margin-left: auto;
  white-space: nowrap;
}

.telegram-contact.telegram-unavailable,
.telegram-contact.telegram-unavailable .avatar,
.telegram-contact.telegram-unavailable .telegram-contact-status,
.telegram-contact.telegram-unavailable .telegram-contact-badge {
  opacity: 0.6;
  filter: grayscale(1);
  color: #7d7d7d;
}

/* ── Avatar circle ──────────────────────────────────────────── */
.avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px; height: 46px;
  border-radius: 50%;
  background: var(--clr-primary);
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.avatar.telegram-avatar {
  background: #229ED9;
  color: #fff;
  box-shadow: inset 0 0 0 2px rgba(34, 158, 217, 0.18);
}

/* ── Chat list ──────────────────────────────────────────────── */
.chat-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--clr-surface);
  border-bottom: 1px solid var(--clr-border);
  cursor: pointer;
  min-height: var(--touch);
  transition: background .1s, border-color .15s, box-shadow .15s;
}
.chat-item.kt { border-left: 4px solid #27AE60; }
.chat-item.telegram { border-left: 4px solid #229ED9; }
.chat-item.telegram .chat-name { color: #229ED9; }
.chat-item.kt .chat-name { color: #27AE60; }
.chat-item:active { background: var(--clr-primary-light); }

.chat-item-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chat-name    { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-preview { font-size: var(--font-sm); color: var(--clr-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-time    { font-size: 12px; color: var(--clr-text-muted); white-space: nowrap; }
.chat-transport-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
  width: fit-content;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(34, 158, 217, 0.12);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

/* Chat unread badge */
.chat-unread-badge {
  background: var(--clr-primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  flex-shrink: 0;
}

/* Chat delete button */
.chat-delete-btn {
  background: none;
  border: none;
  color: var(--clr-text-muted);
  font-size: 16px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.3;
  transition: opacity .2s, background .15s;
  flex-shrink: 0;
}
.chat-item:hover .chat-delete-btn,
.chat-item:active .chat-delete-btn { opacity: 1; }
.chat-delete-btn:hover { background: rgba(0,0,0,.08); color: var(--clr-danger); }

/* Favorite (star) toggle — chat list */
.chat-favorite-btn {
  background: none;
  border: none;
  color: var(--clr-text-muted);
  font-size: 18px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity .2s, background .15s, color .15s;
  flex-shrink: 0;
}
.chat-favorite-btn:hover { background: rgba(0,0,0,.08); opacity: 1; }
.chat-item.favorite .chat-favorite-btn { color: #f5a623; opacity: 1; }
.chat-item.favorite { background: rgba(245, 166, 35, 0.06); }

/* Mute toggle — chat list */
.chat-mute-btn {
  background: none;
  border: none;
  font-size: 15px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.35;
  transition: opacity .2s, background .15s;
  flex-shrink: 0;
}
.chat-mute-btn:hover { background: rgba(0,0,0,.08); opacity: 1; }
.chat-item.muted .chat-mute-btn { opacity: 1; }
.chat-item.muted .chat-name { color: var(--clr-text-muted); }
.chat-item.muted .chat-unread-badge { background: var(--clr-text-muted); }

/* Favorite (star) toggle — contact pills (Kitchen Talk + Telegram) */
.star-btn {
  display: block;
  font-size: 15px;
  line-height: 1;
  color: var(--clr-text-muted);
  opacity: 0.5;
  cursor: pointer;
  padding: 2px;
}
.star-btn:hover { opacity: 1; }
.user-pill.favorite .star-btn { color: #f5a623; opacity: 1; }

/* Back button with unread badge */
.back-btn {
  position: relative;
}
.unread-badge {
  position: absolute;
  top: 2px;
  right: 0;
  background: var(--clr-danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}
.unread-badge.hidden { display: none; }

.empty-hint {
  padding: 20px 14px;
  color: var(--clr-text-muted);
  font-size: var(--font-sm);
  text-align: center;
}

/* ── Chat header info ───────────────────────────────────────── */
.chat-header-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.chat-peer-name   { font-size: var(--font-lg); font-weight: 700; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-peer-status { font-size: var(--font-sm); color: rgba(255,255,255,.85); }

/* ── Messages container ─────────────────────────────────────── */
#screen-chat { position: relative; }

.messages-container {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px 10px 6px;
  background: var(--clr-bg);
}

/* Floating "jump to oldest unread message" button — arrow flips to point
   toward wherever that message currently sits relative to the viewport. */
.scroll-unread-btn {
  position: absolute;
  right: 16px;
  bottom: calc(var(--input-bar-h) + 14px);
  min-width: 40px;
  padding: 0 8px;
  height: 40px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
  background: var(--clr-primary);
  box-shadow: var(--shadow-sm);
  z-index: 5;
  transition: opacity .15s, transform .15s;
}
.scroll-unread-btn:active { transform: scale(0.92); }
.scroll-unread-btn.hidden { display: none; }

.scroll-bottom-btn {
  position: absolute;
  right: 16px;
  bottom: calc(var(--input-bar-h) + 14px);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--clr-primary-dark);
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  box-shadow: var(--shadow-sm);
  z-index: 4;
  transition: opacity .15s, transform .15s;
}
/* Sit to the left of the unread button when both are visible */
.scroll-unread-btn:not(.hidden) ~ .scroll-bottom-btn,
.scroll-bottom-btn:has(~ .scroll-unread-btn:not(.hidden)) { right: 64px; }
.scroll-bottom-btn:active { transform: scale(0.92); }
.scroll-bottom-btn.hidden { display: none; }

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Date separators */
.date-separator {
  text-align: center;
  font-size: 12px;
  color: var(--clr-text-muted);
  padding: 8px 0 4px;
  position: sticky;
  top: 0;
  z-index: 1;
}
.date-separator::before,
.date-separator::after {
  content: '';
  display: inline-block;
  width: 30px;
  height: 1px;
  background: var(--clr-border);
  vertical-align: middle;
  margin: 0 8px;
}

/* ── Message bubbles ────────────────────────────────────────── */
.message {
  display: flex;
  flex-direction: column;
  max-width: 78%;
  gap: 2px;
}
.message.mine   { align-self: flex-end;  align-items: flex-end; }
.message.theirs { align-self: flex-start; align-items: flex-start; }

/* Call history entries */
.message.call-history {
  align-self: center;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  max-width: 90%;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-md);
  padding: 8px 14px;
}
.call-history-icon { font-size: 20px; }
.call-history-info { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.call-history-title { font-size: var(--font-sm); font-weight: 600; color: var(--clr-text); }
.call-history-details { font-size: 12px; color: var(--clr-text-muted); }
.call-history-time { font-size: 11px; color: var(--clr-text-muted); white-space: nowrap; }
.btn-calendar { margin-top: 6px; font-size: 12px; padding: 4px 10px; background: var(--clr-primary); color: #fff; border: none; border-radius: var(--radius-sm); cursor: pointer; }
.btn-calendar:active { opacity: 0.8; }

.msg-from {
  font-size: 12px;
  font-weight: 600;
  color: var(--clr-primary-dark);
  padding: 0 4px;
}

.msg-text, .msg-photo {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: var(--font-base);
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: var(--shadow-sm);
}
.message.mine   .msg-text { background: var(--clr-bubble-out); border-bottom-right-radius: 4px; }
.message.theirs .msg-text { background: var(--clr-bubble-in);  border-bottom-left-radius: 4px; }
.message.telegram .msg-text,
.message.telegram .msg-photo,
.message.telegram .msg-gallery {
  background: #eaf6ff;
  border: 1px solid rgba(34, 158, 217, 0.2);
  box-shadow: 0 1px 0 rgba(34, 158, 217, 0.14);
}
.message.telegram.mine .msg-text,
.message.telegram.mine .msg-photo,
.message.telegram.mine .msg-gallery { background: #dff0ff; }

.msg-photo {
  padding: 4px;
  max-width: 260px;
  border-radius: var(--radius-md);
  background: var(--clr-surface);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}

.msg-video {
  display: block;
  max-width: 260px;
  max-height: 320px;
  border-radius: var(--radius-md);
  background: #000;
  box-shadow: var(--shadow-sm);
}
.msg-video-wrap { position: relative; display: inline-block; max-width: 100%; }
.msg-media-expand {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.msg-media-expand:active { background: rgba(0,0,0,.75); }

.msg-voice {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-lg);
  background: var(--clr-bubble-in);
  box-shadow: var(--shadow-sm);
}
.message.mine .msg-voice { background: var(--clr-bubble-out); }
.message.telegram .msg-voice { background: #eaf6ff; border: 1px solid rgba(34, 158, 217, 0.2); }
.msg-voice audio { max-width: 220px; height: 34px; }
.msg-voice-duration { font-size: 12px; color: var(--clr-text-muted); white-space: nowrap; }

/* Photo gallery (multi-photo messages) */
.msg-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 4px;
  max-width: 280px;
  padding: 4px;
  border-radius: var(--radius-md);
  background: var(--clr-surface);
  box-shadow: var(--shadow-sm);
}
.msg-gallery img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.msg-gallery-count {
  font-size: 11px;
  color: var(--clr-text-muted);
  text-align: center;
  padding: 2px 0;
}

.msg-gallery-more {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
}

/* Undownloaded/unsupported Telegram media (video, document, voice note) */
.msg-document {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  background: var(--clr-bubble-in);
  box-shadow: var(--shadow-sm);
  max-width: 260px;
}
.message.mine .msg-document { background: var(--clr-bubble-out); }
.message.telegram .msg-document { background: #eaf6ff; border: 1px solid rgba(34, 158, 217, 0.2); }
.message.telegram.mine .msg-document { background: #dff0ff; }
.msg-document-icon { font-size: 22px; }
a.msg-document { text-decoration: none; color: inherit; }
.msg-document-info { display: flex; flex-direction: column; min-width: 0; }
.msg-document-name { font-size: var(--font-sm); font-weight: 600; color: var(--clr-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-document-size { font-size: 11px; color: var(--clr-text-muted); }

/* Photo upload progress */
.photo-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 10px;
  background: var(--clr-surface);
  border-bottom: 1px solid var(--clr-border);
}
.photo-progress.hidden { display: none; }
.photo-progress-text {
  font-size: 12px;
  color: var(--clr-text-muted);
  white-space: nowrap;
}
.photo-progress-bar {
  flex: 1;
  height: 4px;
  background: var(--clr-border);
  border-radius: 2px;
  overflow: hidden;
}
.photo-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--clr-primary);
  border-radius: 2px;
  transition: width 0.2s ease;
}

.msg-time {
  font-size: 11px;
  color: var(--clr-text-muted);
  padding: 0 4px;
}

/* Message footer (time + status) */
.msg-footer {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: flex-end;
}

/* Delivery/read status marks */
.msg-status {
  font-size: 12px;
  color: var(--clr-text-muted);
  margin-left: 2px;
}
.msg-status.delivered { color: var(--clr-text-muted); }
.msg-status.read { color: var(--clr-primary); }
.msg-status.undelivered { color: var(--clr-danger); font-weight: 700; }

/* Own message the server could not deliver: Resend / Delete */
.message.undelivered .msg-text,
.message.undelivered .msg-photo,
.message.undelivered .msg-gallery,
.message.undelivered .msg-document,
.message.undelivered .msg-voice,
.message.undelivered .msg-video { outline: 2px solid rgba(192, 57, 43, .45); outline-offset: 1px; }
.msg-undelivered {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  font-size: 12px;
}
.msg-undelivered-label { color: var(--clr-danger); font-weight: 600; }
.msg-undelivered-btn {
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--clr-border);
  background: var(--clr-surface);
  color: var(--clr-primary-dark);
  font-size: 12px;
  font-weight: 600;
}
.msg-undelivered-btn.danger { color: var(--clr-danger); }
.msg-undelivered-btn:active { opacity: .7; }

/* Placeholders for messages still being delivered to us */
.incoming-list { margin-top: 6px; }
.incoming-bubble {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 200px;
  max-width: 260px;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 4px;
  background: var(--clr-bubble-in);
  border: 1px dashed var(--clr-border);
  box-shadow: var(--shadow-sm);
}
.incoming-placeholder.failed .incoming-bubble { border-color: rgba(192, 57, 43, .5); }
.incoming-icon { font-size: 22px; }
.incoming-info { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.incoming-label { font-size: var(--font-sm); color: var(--clr-text-muted); }
.incoming-placeholder.failed .incoming-label { color: var(--clr-danger); }
.incoming-size { font-size: 11px; color: var(--clr-text-muted); }
.incoming-size:empty { display: none; }
.incoming-progress {
  position: relative;
  height: 4px;
  background: var(--clr-border);
  border-radius: 2px;
  overflow: hidden;
}
.incoming-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--clr-primary);
  border-radius: 2px;
  transition: width .2s ease;
}
.incoming-progress.indeterminate .incoming-progress-fill {
  position: absolute;
  width: 35%;
  animation: incoming-indeterminate 1.2s ease-in-out infinite;
}
@keyframes incoming-indeterminate {
  from { left: -35%; }
  to   { left: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .incoming-progress.indeterminate .incoming-progress-fill { animation: none; left: 0; width: 100%; opacity: .4; }
}
.incoming-dismiss {
  align-self: flex-start;
  font-size: 20px;
  line-height: 1;
  color: var(--clr-text-muted);
  padding: 0 2px;
}

/* Reply quote inside a message */
.msg-reply-quote {
  padding: 4px 8px;
  margin-bottom: 4px;
  border-left: 3px solid var(--clr-primary);
  background: rgba(0,0,0,.04);
  border-radius: 4px;
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.msg-reply-name { font-weight: 600; color: var(--clr-primary-dark); }
.msg-reply-text { color: var(--clr-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Reply button on messages */
.msg-reply-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: none;
  border: none;
  font-size: 14px;
  color: var(--clr-text-muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity .15s;
}
.message { position: relative; user-select: none; -webkit-user-select: none; }
.message:hover .msg-reply-btn,
.message:active .msg-reply-btn { opacity: 1; }

/* Message reactions display */
.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.msg-reaction-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 14px;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: 12px;
  padding: 2px 6px;
  cursor: pointer;
}
.msg-reaction-badge.mine {
  border-color: var(--clr-primary);
  background: var(--clr-primary-light);
}
.msg-reaction-count {
  font-size: 11px;
  color: var(--clr-text-muted);
}

/* Message context menu (long-press overlay) */
.msg-context-menu {
  position: fixed;
  z-index: 8001;
  background: var(--clr-surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
  padding: 8px;
  min-width: 200px;
  animation: ctx-pop .15s ease;
}
.msg-context-menu.hidden { display: none; }
@keyframes ctx-pop {
  from { opacity: 0; transform: scale(.9); }
  to   { opacity: 1; transform: scale(1); }
}
.msg-context-reactions {
  display: flex;
  justify-content: space-around;
  padding: 6px 4px 10px;
  border-bottom: 1px solid var(--clr-border);
}
.msg-react-btn {
  font-size: 24px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
  transition: transform .1s, background .1s;
}
.msg-react-btn:active {
  transform: scale(1.3);
  background: var(--clr-primary-light);
}
.msg-context-actions {
  display: flex;
  flex-direction: column;
  padding-top: 4px;
}
.msg-context-action {
  background: none;
  border: none;
  text-align: left;
  font-size: 15px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--clr-text);
}
.msg-context-action:active {
  background: var(--clr-primary-light);
}
.msg-context-backdrop {
  position: fixed;
  inset: 0;
  z-index: 7999;
  background: rgba(0,0,0,.15);
}

/* Message details (event log) floating view */
.msg-details {
  position: fixed;
  inset: 0;
  z-index: 8002;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0,0,0,.15);
}
.msg-details-card {
  width: min(380px, 100%);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  background: var(--clr-surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
  animation: ctx-pop .15s ease;
}
.msg-details-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 6px 6px 16px;
  border-bottom: 1px solid var(--clr-border);
}
.msg-details-header h3 { font-size: var(--font-base); }
.msg-details-header .icon-btn { color: var(--clr-text-muted); width: 40px; height: 40px; font-size: 18px; }
.msg-details-list {
  list-style: none;
  overflow-y: auto;
  padding: 8px 16px 12px;
  font-size: var(--font-sm);
}
.msg-details-list li {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--clr-border);
}
.msg-details-list li:last-child { border-bottom: none; }
.msg-details-time { font-variant-numeric: tabular-nums; color: var(--clr-text-muted); }
.msg-details-label { font-weight: 600; }
.msg-details-user { color: var(--clr-text-muted); }

/* Links in messages */
.msg-text a {
  color: var(--clr-primary);
  text-decoration: underline;
  word-break: break-all;
}

/* ── Input bar ──────────────────────────────────────────────── */
.input-bar {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px;
  background: var(--clr-surface);
  border-top: 1px solid var(--clr-border);
  flex-shrink: 0;
  flex-wrap: wrap;
  /* Safe area for iPhone X+ home indicator */
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}

.chat-loading {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 64px;
  height: 28px;
  border-radius: 8px;
  background: rgba(35, 43, 48, .7);
  box-shadow: var(--shadow-sm);
  pointer-events: none;
  z-index: 2;
}
.chat-loading span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
  animation: chat-loading-pulse 1.2s ease-in-out infinite;
}
.chat-loading span:nth-child(2) { animation-delay: .15s; }
.chat-loading span:nth-child(3) { animation-delay: .3s; }
@keyframes chat-loading-pulse {
  0%, 80%, 100% { opacity: .35; transform: scale(.8); }
  40% { opacity: 1; transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .chat-loading span { animation: none; }
}

/* Reply preview */
.reply-preview {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--clr-primary-light);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--clr-primary);
  margin-bottom: 4px;
}
.reply-preview.hidden { display: none; }
.reply-preview-content { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.reply-preview-name { font-weight: 600; font-size: 0.8rem; color: var(--clr-primary-dark); }
.reply-preview-text { font-size: 0.8rem; color: var(--clr-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-preview-close { background: none; border: none; font-size: 18px; color: var(--clr-text-muted); cursor: pointer; padding: 0 4px; }

.msg-input {
  flex: 1;
  min-height: var(--touch);
  max-height: 120px;
  padding: 10px 14px;
  border: 2px solid var(--clr-border);
  border-radius: var(--radius-lg);
  outline: none;
  font-size: var(--font-base);
  background: var(--clr-bg);
  transition: border-color .15s;
  resize: none;
  overflow-y: auto;
  line-height: 1.4;
  font-family: inherit;
  min-width: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  -webkit-user-select: text;
  user-select: text;
}
.msg-input:focus { border-color: var(--clr-primary); }
.msg-input[contenteditable]:empty::before {
  content: attr(data-placeholder);
  color: var(--clr-text-muted);
  pointer-events: none;
}

.btn-send {
  width: var(--touch);
  height: var(--touch);
  border-radius: 50%;
  background: var(--clr-primary);
  color: #fff;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  transition: background .15s, transform .1s;
}
.btn-send:active { background: var(--clr-primary-dark); transform: scale(.93); }

.attach-btn {
  color: var(--clr-text-muted);
  flex-shrink: 0;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: background .15s, color .15s, transform .1s;
}
.attach-btn svg { display: block; transform: rotate(45deg); }
.attach-btn:hover { background: var(--clr-primary-light); color: var(--clr-primary); }
.attach-btn:active { transform: scale(.92); }
.attach-btn:active,
.attach-btn[aria-expanded="true"] { color: var(--clr-primary); background: var(--clr-primary-light); }
.attach-btn:disabled { opacity: .45; }

.attach-menu {
  position: absolute;
  left: 10px;
  bottom: calc(100% + 6px);
  z-index: 40;
  min-width: 220px;
  max-width: calc(100% - 20px);
  padding: 6px;
  display: flex;
  flex-direction: column;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
  animation: ctx-pop .15s ease;
}
.attach-menu.hidden { display: none; }
.attach-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--touch);
  padding: 10px 12px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  text-align: left;
  font-size: 15px;
  font-family: inherit;
  color: var(--clr-text);
  cursor: pointer;
}
.attach-menu-item:active { background: var(--clr-primary-light); }
.attach-menu-icon { font-size: 20px; }

/* Generic show/hide toggle for input-bar controls swapped out while recording voice */
.input-bar > .hidden { display: none !important; }

.voice-btn { font-size: 22px; color: var(--clr-text-muted); }
.voice-btn:active, .voice-btn.recording { color: var(--clr-danger); }

.voice-record-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  padding: 8px 12px;
  border: 2px solid var(--clr-border);
  border-radius: var(--radius-lg);
  background: var(--clr-bg);
}
.voice-record-bar.hidden { display: none; }
.voice-record-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--clr-danger);
  animation: voice-record-blink 1s ease-in-out infinite;
}
@keyframes voice-record-blink { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
.voice-record-timer { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--clr-text); }
.voice-record-hint { flex: 1; font-size: var(--font-sm); color: var(--clr-text-muted); }

/* ── Setup / center card ────────────────────────────────────── */
.screen#screen-setup {
  background: var(--clr-primary);
  justify-content: center;
  align-items: center;
  padding: 20px;
  overflow-y: auto;
}

.center-card {
  background: var(--clr-surface);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.app-logo   { font-size: 54px; text-align: center; }
.app-title  { font-size: var(--font-xl); font-weight: 800; text-align: center; color: var(--clr-primary); }
.app-subtitle { text-align: center; color: var(--clr-text-muted); margin-top: -8px; }

/* ── Forms ──────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 600; font-size: var(--font-sm); color: var(--clr-text-muted); }
.field input {
  height: var(--touch);
  padding: 10px 14px;
  border: 2px solid var(--clr-border);
  border-radius: var(--radius-md);
  font-size: var(--font-base);
  outline: none;
  transition: border-color .15s;
}
.field input:focus { border-color: var(--clr-primary); }

.hint {
  font-size: var(--font-sm);
  color: var(--clr-text-muted);
  text-align: center;
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch);
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-size: var(--font-base);
  font-weight: 600;
  transition: background .15s, transform .1s, opacity .15s;
  white-space: nowrap;
}
.btn:active { transform: scale(.96); }

.btn-primary   { background: var(--clr-primary);   color: #fff; }
.btn-primary:hover { background: var(--clr-primary-dark); }

.btn-secondary { background: var(--clr-primary-light); color: var(--clr-primary-dark); }
.btn-ghost     { background: transparent; color: var(--clr-text-muted); }
.btn-danger    { background: var(--clr-danger); color: #fff; }
.btn-success   { background: #27ae60; color: #fff; opacity: 0.8; }

.btn-full { width: 100%; }
.btn-sm   { min-height: 40px; padding: 8px 16px; font-size: var(--font-sm); }
.btn-lg   { min-height: 56px; padding: 14px 24px; font-size: 18px; font-weight: 700; }

/* ── Setup details (manual join) ─────────────────────────────── */
.setup-details summary {
  cursor: pointer;
  color: var(--clr-text-muted);
  font-size: var(--font-sm);
  padding: 8px 0;
}
.setup-details[open] summary {
  color: var(--clr-text);
}

/* ── Install prompt full (for invite visitors) ───────────────── */
.install-prompt-full {
  text-align: center;
  padding: 20px;
  margin: 16px 0;
  background: var(--clr-primary-light);
  border-radius: var(--radius-lg);
}
.install-prompt-full.hidden { display: none; }
.install-prompt-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.install-prompt-icon {
  font-size: 48px;
}
.install-prompt-full h3 {
  margin: 0;
  font-size: 18px;
}
.install-prompt-full p {
  margin: 0;
  font-size: var(--font-sm);
  color: var(--clr-text-muted);
}

/* ── Modals ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: flex-end;  /* sheet from bottom on mobile */
  justify-content: center;
  z-index: 300;  /* above install banner (200) */
  padding: 0 0 env(safe-area-inset-bottom, 0);
}

.modal-card {
  background: var(--clr-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 24px 20px 32px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow-md);
}
.modal-card h2 { font-size: var(--font-lg); }
.modal-hint    { font-size: var(--font-sm); color: var(--clr-text-muted); }

/* Admin panel (room owner / co-owners) */
#modal-admin { z-index: 310; }
.admin-card { max-width: 860px; height: 92vh; max-height: 92vh; overflow: hidden; gap: 10px; padding-bottom: 12px; }
.admin-header { display: flex; align-items: center; gap: 10px; }
.admin-header h2 { flex: 1; }
.admin-close { font-size: 28px; line-height: 1; color: var(--clr-text-muted); padding: 0 6px; }
#modal-admin.loading #btn-admin-refresh { opacity: .5; pointer-events: none; }
.admin-tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--clr-border); }
.admin-tab {
  padding: 8px 12px;
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--clr-text-muted);
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
.admin-tab.active { color: var(--clr-primary-dark); border-bottom-color: var(--clr-primary); }
.admin-tab-count:not(:empty) {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--clr-danger);
  color: #fff;
  font-size: 11px;
  text-align: center;
}
.admin-error { color: var(--clr-danger); font-size: var(--font-sm); }
.admin-body { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding-right: 2px; }
.admin-section { display: flex; flex-direction: column; gap: 8px; }
.admin-section-title { font-size: var(--font-base); }
.admin-subtitle { font-size: var(--font-sm); margin-top: 4px; }
.admin-kv { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: 4px 12px; font-size: var(--font-sm); }
.admin-kv dt { color: var(--clr-text-muted); }
.admin-kv dd { word-break: break-word; }
.admin-table-wrap { overflow-x: auto; }
.admin-merge-form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.admin-merge-form label { display: grid; gap: 6px; min-width: 0; font-size: var(--font-sm); }
.admin-merge-form select { width: 100%; min-width: 0; min-height: 44px; padding: 8px; border: 1px solid var(--clr-border); border-radius: 6px; background: var(--clr-bg); color: var(--clr-text); font: inherit; }
.admin-merge-form button { justify-self: start; }
.admin-table { width: 100%; border-collapse: collapse; font-size: var(--font-sm); }
.admin-table th, .admin-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--clr-border); white-space: nowrap; }
.admin-table th { color: var(--clr-text-muted); font-weight: 600; }
.admin-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-md);
  background: var(--clr-surface);
}
.admin-item.warn { border-color: rgba(192, 57, 43, .45); }
.admin-item-head { display: flex; align-items: center; gap: 10px; }
.admin-item-icon { font-size: 22px; }
.admin-item-title { display: flex; flex-direction: column; min-width: 0; }
.admin-item-title strong { font-size: var(--font-sm); overflow: hidden; text-overflow: ellipsis; }
.admin-item-sub { font-size: 12px; color: var(--clr-text-muted); }
.admin-badges, .admin-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.admin-actions .btn-sm { min-height: 34px; padding: 4px 10px; }
.admin-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--clr-bg);
  border: 1px solid var(--clr-border);
  color: var(--clr-text);
}
.admin-badge.ok { background: var(--clr-primary-light); border-color: var(--clr-primary); }
.admin-badge.warn { background: #fdecea; border-color: var(--clr-danger); color: var(--clr-danger); }
.admin-badge.muted { color: var(--clr-text-muted); }
.admin-item-details { display: flex; flex-direction: column; gap: 6px; padding-top: 6px; border-top: 1px dashed var(--clr-border); }
.admin-events { list-style: none; font-size: 12px; color: var(--clr-text-muted); display: flex; flex-direction: column; gap: 2px; }
.admin-inspect { font-size: var(--font-sm); }
.admin-empty { color: var(--clr-text-muted); font-size: var(--font-sm); }
.admin-usage { display: flex; align-items: center; gap: 10px; font-size: 12px; }
.admin-usage-bar { flex: 1; height: 8px; border-radius: 4px; background: var(--clr-border); overflow: hidden; }
.admin-usage-fill { height: 100%; background: var(--clr-primary); }
.admin-usage-fill.high { background: var(--clr-danger); }
.admin-usage-title { font-size: 12px; color: var(--clr-text-muted); }
@media (min-width: 720px) {
  #modal-admin { align-items: center; }
  .admin-card { border-radius: var(--radius-lg); height: 86vh; }
}

/* About modal */
.about-card { text-align: center; align-items: center; }
.about-icon { margin-bottom: 4px; }
.about-icon img { border-radius: var(--radius-md); }
.about-version { font-size: var(--font-sm); color: var(--clr-text-muted); margin: 0; }
.about-desc { font-size: var(--font-base); color: var(--clr-text-muted); max-width: 300px; }
.about-features { display: flex; gap: 12px; font-size: var(--font-sm); color: var(--clr-text-muted); }

/* Disabled button style */
.btn-disabled { opacity: 0.5; cursor: not-allowed; }

.modal-actions { display: flex; flex-direction: column; gap: 10px; }

.invite-link-box  { display: flex; flex-direction: column; gap: 8px; }
.invite-link-input {
  height: var(--touch);
  padding: 10px 14px;
  border: 2px solid var(--clr-border);
  border-radius: var(--radius-md);
  font-size: var(--font-sm);
  background: var(--clr-bg);
  color: var(--clr-text);
  width: 100%;
}
.invite-link-actions { display: flex; gap: 8px; }
.invite-link-actions .btn { flex: 1; }

/* ── Settings ───────────────────────────────────────────────── */
.settings-row  { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; }
.settings-label { font-weight: 600; color: var(--clr-text-muted); }
.settings-value { font-size: var(--font-lg); font-weight: 700; }

.lang-select {
  padding: 6px 10px;
  border: 2px solid var(--clr-border);
  border-radius: var(--radius-md);
  font-size: var(--font-base);
  background: var(--clr-bg);
  color: var(--clr-text);
}

.room-id-value {
  font-family: monospace;
  font-size: var(--font-base);
  letter-spacing: .1em;
  color: var(--clr-primary-dark);
  background: var(--clr-primary-light);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}

.invite-prefilled {
  opacity: 0.5;
  pointer-events: none;
}

/* ── Room discovery & Knock UI ─────────────────────────────── */

.rooms-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 16px 0;
}

.room-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--clr-surface);
  border: 2px solid var(--clr-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: left;
  transition: border-color .15s, box-shadow .15s;
}
.room-item:hover, .room-item:focus {
  border-color: var(--clr-primary);
  box-shadow: var(--shadow-sm);
}

.room-icon {
  font-size: 28px;
}

.room-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.room-item-name {
  font-size: var(--font-base);
  font-weight: 600;
  color: var(--clr-text);
}

.room-item-type {
  font-size: var(--font-sm);
  color: var(--clr-text-muted);
}

.screen-title {
  font-size: var(--font-xl);
  font-weight: 700;
  margin-bottom: 4px;
}

.screen-hint {
  font-size: var(--font-base);
  color: var(--clr-text-muted);
  margin-bottom: 16px;
}

/* PIN input */
.pin-input {
  width: 100%;
  text-align: center;
  font-size: 28px;
  letter-spacing: 12px;
  padding: 12px;
  border: 2px solid var(--clr-border);
  border-radius: var(--radius-md);
  background: var(--clr-surface);
}
.pin-input:focus {
  border-color: var(--clr-primary);
  outline: none;
}

/* Door grid (replaces doorbell grid) */
.door-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 12px 0;
}

.door-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 0.75;
  border: 3px solid var(--clr-border);
  border-radius: var(--radius-md);
  background: var(--clr-surface);
  cursor: pointer;
  transition: border-color .15s, transform .1s, box-shadow .15s;
  padding: 4px;
}
.door-btn:hover {
  border-color: var(--clr-primary);
  transform: scale(1.05);
}
.door-btn.selected {
  border-color: var(--clr-primary);
  box-shadow: 0 0 0 3px var(--clr-primary-light);
  transform: scale(1.08);
}
.door-btn svg {
  width: 100%;
  height: 100%;
}

/* Knock error & cooldown */
.knock-error {
  color: var(--clr-danger);
  font-size: var(--font-sm);
  font-weight: 600;
  text-align: center;
  margin: 8px 0;
}

.knock-cooldown {
  color: var(--clr-text-muted);
  font-size: var(--font-sm);
  text-align: center;
  margin: 4px 0;
}

/* Knock waiting */
.knock-spinner {
  width: 40px;
  height: 40px;
  margin: 16px auto;
  border: 4px solid var(--clr-border);
  border-top-color: var(--clr-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.knock-wait-status {
  text-align: center;
  font-size: var(--font-base);
  color: var(--clr-text-muted);
  margin: 8px 0;
}

.knock-waiting-anim {
  animation: knock-pulse 1.5s ease-in-out infinite;
}
@keyframes knock-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1) rotate(-5deg); }
}

/* Knock notification for owner */
.knock-notify-text {
  font-size: var(--font-lg);
  text-align: center;
  margin: 12px 0;
}

/* Challenge hint */
.challenge-hint {
  font-size: var(--font-base);
  color: var(--clr-text-muted);
  text-align: center;
  margin-bottom: 12px;
}

/* Settings details (room admin) */
.settings-details {
  margin: 12px 0;
  padding: 12px;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-md);
}
.settings-details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--clr-primary-dark);
}

/* Members list */
.members-list {
  margin-top: 8px;
}
.member-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--clr-border);
}
.member-row:last-child {
  border-bottom: none;
}
.member-info {
  font-size: 0.9rem;
}
.member-kick {
  font-size: 0.75rem;
  padding: 3px 8px;
}

/* Co-owner management */
.co-owner-section {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--clr-border);
}
.co-owner-title {
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 6px;
  color: var(--clr-primary-dark);
}
.co-owner-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}
.co-owner-name {
  font-size: 0.85rem;
}

/* Doorbell preview (for room owner) */
.doorbell-preview-container {
  margin-top: 10px;
  display: flex;
  justify-content: center;
}

.doorbell-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px;
  border: 2px solid var(--clr-primary);
  border-radius: var(--radius-md);
  background: var(--clr-primary-light);
}
.doorbell-preview svg {
  width: 64px;
  height: 64px;
}
.doorbell-preview-label {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--clr-primary-dark);
}

.cleanup-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}
.cleanup-input {
  width: 50px;
  padding: 6px 8px;
  border: 2px solid var(--clr-border);
  border-radius: var(--radius-md);
  font-size: var(--font-base);
  text-align: center;
  background: var(--clr-bg);
}

/* ── Install banner ─────────────────────────────────────────── */
.install-banner {
  /* Normal flow inside #app flex column — no overlap issues */
  background: var(--clr-primary);
  color: #fff;
  padding: 10px 14px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  box-shadow: 0 -2px 8px rgba(0,0,0,.15);
}
.install-text { flex: 1; font-size: var(--font-sm); font-weight: 600; }

/* ── Update banner ─────────────────────────────────────────── */
.update-banner {
  background: #ff9800;
  color: #fff;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  box-shadow: 0 -2px 8px rgba(0,0,0,.15);
}
.update-banner.hidden { display: none; }
.update-text { flex: 1; font-size: var(--font-sm); font-weight: 600; }

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 4px; height: 4px; }
::-webkit-scrollbar-thumb { background: var(--clr-border); border-radius: 4px; }

/* ── Responsive: wider screens ──────────────────────────────── */
@media (min-width: 600px) {
  .modal-overlay { align-items: center; }
  .modal-card    { border-radius: var(--radius-lg); max-height: 80vh; overflow-y: auto; }

  .online-list { padding: 8px 20px; }
  .chat-item   { padding: 14px 20px; }
  .messages-container { padding: 14px 16px; }
  .input-bar   { padding: 10px 16px; }
  .top-bar     { padding: 0 16px; }
}

@media (min-width: 768px) {
  :root { --font-base: 18px; }
  .center-card { padding: 40px 32px; }
}

/* ── Lightbox (fullscreen image viewer) ─────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,.92);
  display: flex;
  flex-direction: column;
  overscroll-behavior: contain;
}
.lightbox.hidden { display: none; }

.lightbox-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 6px) 8px 6px 14px;
  color: #fff;
  flex-shrink: 0;
  z-index: 10;
}
.lightbox-title {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: .85;
}
.lightbox-tool {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: none;
  color: #fff;
  cursor: pointer;
}
.lightbox-tool:hover, .lightbox-tool:active { background: rgba(255,255,255,.15); }
.lightbox-close { font-size: 34px; line-height: 1; }

.lightbox-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
}
.lightbox-stage[data-kind="text"] { touch-action: pan-y; }
.lightbox-slide {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px calc(env(safe-area-inset-bottom, 0px) + 8px);
}

.lightbox-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  transform-origin: center center;
  will-change: transform;
}
.lightbox-video { max-width: 100%; max-height: 100%; background: #000; }
.lightbox-doc {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 4px;
  background: #fff;
}
.lightbox-text {
  width: 100%;
  max-width: 900px;
  height: 100%;
  margin: 0;
  padding: 14px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: #1e1e1e;
  color: #e6e6e6;
  border-radius: 6px;
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  user-select: text;
}
.lightbox-file-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 320px;
  padding: 28px 24px;
  border-radius: 16px;
  background: rgba(255,255,255,.08);
  color: #fff;
  text-align: center;
}
.lightbox-file-icon { font-size: 56px; }
.lightbox-file-name { font-weight: 600; word-break: break-word; }
.lightbox-file-size { font-size: 13px; opacity: .7; }
.lightbox-file-card audio { width: 260px; max-width: 100%; }

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 40px;
  color: #fff;
  background: rgba(0,0,0,.4);
  border: none;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
}
.lightbox-nav:active { background: rgba(0,0,0,.6); }
.lightbox-prev-btn { left: 10px; }
.lightbox-next-btn { right: 10px; }
.lightbox-nav.hidden { display: none; }

.lightbox-counter {
  color: #fff;
  font-size: 13px;
  background: rgba(255,255,255,.15);
  padding: 3px 10px;
  border-radius: 12px;
  flex-shrink: 0;
}

/* Edge-swipe back from a chat: chat slides over the (temporarily shown) chat list */
body.chat-swipe-back #screen-chat {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: var(--clr-bg);
  box-shadow: -8px 0 24px rgba(0,0,0,.25);
  will-change: transform;
}

/* ── Voice Call UI ───────────────────────────────────────────────────────────── */

.call-btn {
  font-size: 1.2rem;
  padding: 4px 8px;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Active call overlay */
.call-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.call-overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  color: #fff;
}

.call-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: rgba(255,255,255,.1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  animation: call-pulse 2s infinite;
}

@keyframes call-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(39, 174, 96, .4); }
  50% { box-shadow: 0 0 0 20px rgba(39, 174, 96, 0); }
}

.call-peer-name {
  font-size: 1.4rem;
  font-weight: 600;
  margin: 0;
}

.call-status {
  font-size: 0.9rem;
  opacity: .7;
  margin: 0;
}

.call-timer {
  font-size: 1.8rem;
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  margin: 8px 0 24px;
}

.call-actions {
  display: flex;
  gap: 32px;
  align-items: center;
}

.call-action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,.1);
  border: none;
  border-radius: 50%;
  width: 60px;
  height: 60px;
  justify-content: center;
  cursor: pointer;
  transition: background .2s;
}

.call-action-btn:hover {
  background: rgba(255,255,255,.2);
}

.call-action-btn .call-action-icon {
  font-size: 1.4rem;
}

.call-action-btn .call-action-label {
  font-size: .65rem;
  color: #ccc;
  display: none;
}

.call-end-btn {
  background: #e74c3c;
  width: 70px;
  height: 70px;
}

.call-end-btn:hover {
  background: #c0392b;
}

.call-action-btn.muted {
  background: rgba(231, 76, 60, .3);
}

.call-action-btn.active {
  background: rgba(46, 204, 113, .3);
}

/* Proximity sensor: dim screen when phone near head */
body.proximity-near .call-overlay-content {
  opacity: 0.01;
  transition: opacity 0.3s;
}

body.proximity-near .call-overlay {
  background: #000;
}

/* Call participants (group) */
.call-participants {
  margin-top: 20px;
  text-align: center;
}

.call-participants-label {
  font-size: .8rem;
  opacity: .6;
  margin-bottom: 8px;
}

.call-participants-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.call-participant-pill {
  background: rgba(255,255,255,.15);
  padding: 4px 12px;
  border-radius: 12px;
  font-size: .8rem;
}

/* Incoming call modal */
.incoming-call-card {
  text-align: center;
  animation: incoming-ring .5s ease-in-out infinite alternate;
}

@keyframes incoming-ring {
  from { transform: scale(1); }
  to { transform: scale(1.02); }
}

.incoming-call-icon {
  font-size: 3rem;
  animation: incoming-ring-icon 1s ease-in-out infinite;
  margin-bottom: 8px;
}

@keyframes incoming-ring-icon {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-10deg); }
  75% { transform: rotate(10deg); }
}

.incoming-call-from {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 4px 0 16px;
}

.incoming-call-actions {
  display: flex;
  justify-content: center;
  gap: 40px;
}

.btn-round {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

/* Schedule call modal */
.schedule-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 1rem;
  box-sizing: border-box;
}

.call-request-text {
  font-weight: 500;
  margin-bottom: 4px;
}

.call-request-time {
  font-size: 1.2rem;
  font-weight: 600;
  color: #27AE60;
  margin: 8px 0;
}

.call-request-note {
  font-style: italic;
  opacity: .7;
  margin-bottom: 12px;
}

/* Call button states */
.call-btn.disabled {
  opacity: .4;
  pointer-events: none;
}

.call-btn.in-call {
  color: #27AE60;
  animation: call-pulse-btn 1.5s infinite;
}

@keyframes call-pulse-btn {
  0%, 100% { opacity: 1; }
  50% { opacity: .5; }
}

.telegram-status {
  margin: 10px 0 6px;
  font-weight: 600;
}

#telegram-settings-section .modal-hint {
  margin: 0 0 12px;
}

#telegram-settings-section .btn + .btn {
  margin-left: 8px;
}

#telegram-settings-section .inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

#telegram-auth-form { margin-top: 12px; }
#telegram-auth-form input { width: 100%; box-sizing: border-box; margin: 4px 0 8px; }

.telegram-contact-section {
  border-bottom: 1px solid var(--border-color, #e5e5e5);
  margin-bottom: 10px;
  padding-bottom: 10px;
}
.telegram-contact-section h2 {
  color: #229ED9;
  font-size: var(--font-sm);
  margin: 4px 0 8px;
}
.telegram-contact-avatar-container {
  flex: 0 0 auto;
}
.telegram-contact-info-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.telegram-contact-actions-container {
  flex: 0 0 auto;
  justify-content: flex-end;
  gap: 8px;
}
.telegram-contact { border-left: 4px solid #229ED9; }
.telegram-avatar { background: #229ED9; color: #fff; }
.telegram-contact-badge { color: #229ED9; font-size: .75rem; margin-left: auto; }
.chat-item .avatar.telegram-avatar { background: #229ED9; }
.chat-item.telegram .chat-name { color: #229ED9; }
.chat-item.kt .chat-name { color: #27AE60; }
.chat-item.telegram .avatar { background: #229ED9; }

/* Channel chats visual hints */
.chat-item.channel { border-left: 4px solid #E67E22; }
.chat-item.channel .chat-name { color: #E67E22; }
.chat-item.channel .avatar { background: #E67E22; }
.chat-transport-badge.channel-badge {
  background: rgba(230, 126, 34, 0.12);
  color: #E67E22;
}

/* Comments button on message bubbles */
.msg-comments-btn {
  align-self: flex-start;
  margin-top: 4px;
  padding: 4px 10px;
  border-radius: 12px;
  background: rgba(34, 158, 217, 0.12);
  color: #229ED9;
  border: 1px solid rgba(34, 158, 217, 0.25);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.msg-comments-btn:hover {
  background: rgba(34, 158, 217, 0.22);
}

/* Discussion thread modal */
.discussion-modal-card {
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}
.discussion-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--clr-border);
}
.discussion-messages-container {
  flex: 1;
  min-height: 200px;
  max-height: 50vh;
  overflow-y: auto;
  margin: 10px 0;
}
.discussion-input-bar {
  padding: 8px 0 0;
  border-top: 1px solid var(--clr-border);
}
.comment-item {
  margin-bottom: 8px;
}

.directory-tabs { display: flex; gap: 6px; padding: 10px 0 8px; }
.directory-tab { flex: 1; border: 0; border-radius: 999px; padding: 9px 6px; background: var(--clr-primary-light); color: var(--clr-text-muted); font-weight: 700; }
.directory-tab.active { background: var(--clr-primary); color: #fff; }
.directory-search { display: flex; gap: 8px; align-items: center; background: var(--clr-surface-alt, #f2f4f5); border-radius: var(--radius-md); padding: 9px 12px; margin-bottom: 10px; }
.directory-search input { flex: 1; border: 0; background: transparent; font: inherit; min-width: 0; outline: 0; }
.directory-panel[hidden] { display: none; }

/* The directory is the only scroll container on the main screen. Keeping it
   explicit avoids nested flex children swallowing long Telegram contact lists. */
#screen-chats .directory-panel {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
#screen-chats .directory-panel[data-directory-panel="chats"] > .chat-list {
  min-height: 100%;
}
#telegram-contact-list { overflow: visible; }
#screen-chats .directory-panel[data-directory-panel="contacts"] .online-list {
  flex-wrap: wrap;
  overflow-x: visible;
}

/* Pull to refresh indicator */
.pull-to-refresh {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  margin: 0 0 8px 0;
  background: var(--clr-surface-alt, #f2f4f5);
  border-radius: var(--radius-md);
  color: var(--clr-primary-dark, #0e678a);
  font-size: 0.85rem;
  font-weight: 600;
  transition: max-height 0.2s ease, opacity 0.2s ease;
  overflow: hidden;
  user-select: none;
}
.pull-to-refresh.hidden {
  display: none !important;
}
.pull-icon {
  display: inline-block;
  font-size: 1.1rem;
  transition: transform 0.2s ease;
}
.pull-icon.spinning {
  animation: kt-spin 0.9s linear infinite;
}

/* Telegram toggle row in modal */
.telegram-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  margin: 16px 0;
  background: var(--clr-surface-alt, #f2f4f5);
  border-radius: var(--radius-md);
}

/* Toggle switch styling */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #ccc;
  transition: 0.3s;
  border-radius: 26px;
}
.toggle-slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.toggle-switch input:checked + .toggle-slider {
  background-color: #229ED9;
}
.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(22px);
}
