:root {
  --bg: #ffffff; --panel: #f3f3f7; --line: #dcdce3; --text: #1c1c1f; --muted: #6e6e78;
  --accent: #3b6cf6; --accent-text: #ffffff; --bubble: #e7e7ee; --danger: #d92c2c; --online: #2fb457;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1c1c1f; --panel: #26262b; --line: #3a3a42; --text: #f2f2f5; --muted: #9a9aa6; --bubble: #35353d; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.4 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
h1, h2 { margin: 0; font-size: 20px; }
p { margin: 0; }
button, input, .button { font: inherit; color: inherit; }
button, .button {
  border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 6px 12px; cursor: pointer;
}
button:hover, .button:hover { filter: brightness(0.96); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { color: var(--danger); }
button.small { padding: 3px 9px; font-size: 13px; }
input:not([type=checkbox]) {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.error { color: var(--danger); text-align: center; }
.hint { color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); }
.row { display: flex; gap: 8px; justify-content: center; align-items: center; }

/* Sign in */
#auth { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card { display: flex; flex-direction: column; gap: 12px; width: min(320px, 100%); align-items: stretch; text-align: center; }
.logo { width: 96px; height: 96px; align-self: center; }
.tabs { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tabs button { flex: 1; border: 0; border-radius: 0; background: transparent; }
.tabs button.active { background: var(--accent); color: var(--accent-text); }

/* Layout */
#app { height: 100%; display: flex; }
#sidebar { width: 280px; flex: none; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); }
#search { margin: 10px; width: auto; }
#lists { flex: 1; overflow-y: auto; padding: 0 6px 10px; }
#sidebar footer { display: flex; gap: 8px; align-items: center; padding: 10px; border-top: 1px solid var(--line); }
#me { flex: 1; min-width: 0; border: 0; background: transparent; padding: 0; text-align: left; }
#chat { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* Sidebar lists */
.section { display: flex; align-items: center; justify-content: space-between; padding: 12px 8px 4px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; }
.section button { padding: 0 8px; font-size: 16px; line-height: 1.3; }
.item { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; width: 100%; border: 0; background: transparent; text-align: left; }
button.item:hover { background: var(--line); filter: none; }
.item.selected, button.item.selected:hover { background: var(--accent); color: var(--accent-text); }
.item.selected .muted, .item.selected .status { color: inherit; opacity: 0.85; }
.item .grow { flex: 1; min-width: 0; }
.item .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { font-size: 12px; color: var(--muted); }
.status.online { color: var(--online); }
.unread { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); flex: none; }
.item.selected .unread { background: var(--accent-text); }
.request { flex-direction: column; align-items: stretch; gap: 6px; }
.request .who { display: flex; align-items: center; gap: 10px; }
.empty-note { padding: 24px 12px; text-align: center; color: var(--muted); }

.avatar { position: relative; flex: none; width: 32px; height: 32px; }
.avatar img, .avatar .initial { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.avatar .initial { display: grid; place-items: center; background: color-mix(in srgb, var(--accent) 25%, transparent); font-weight: 600; }
.avatar .dot { position: absolute; right: -2px; bottom: -2px; width: 11px; height: 11px; border-radius: 50%; background: #9a9aa6; border: 2px solid var(--panel); }
.avatar .dot.online { background: var(--online); }
.avatar.large { width: 96px; height: 96px; font-size: 40px; }
#profile-avatar { align-self: center; }
.group-icon { width: 32px; text-align: center; flex: none; }

/* Conversation */
.placeholder { margin: auto; text-align: center; color: var(--muted); padding: 20px; }
.placeholder .big { font-size: 48px; }
.placeholder h2 { color: var(--text); margin-bottom: 4px; }
#conversation { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#conversation header { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
#chat-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
#chat-title .name { font-weight: 600; }
#back { display: none; font-size: 22px; line-height: 1; padding: 2px 10px; }
#messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.message { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; max-width: 78%; }
.message.mine { align-self: flex-end; align-items: flex-end; }
.message .sender, .message .time { font-size: 11px; color: var(--muted); }
.message .line { display: flex; align-items: center; gap: 6px; }
.message.mine .line { flex-direction: row-reverse; }
.bubble { padding: 7px 12px; border-radius: 14px; background: var(--bubble); white-space: pre-wrap; overflow-wrap: anywhere; }
.message.mine .bubble { background: var(--accent); color: var(--accent-text); }
.message img.photo, .message video { max-width: min(280px, 100%); max-height: 280px; border-radius: 14px; display: block; }
.react { border: 0; background: transparent; padding: 2px 4px; opacity: 0.45; }
.react:hover { opacity: 1; }
.picker { display: flex; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 16px; background: var(--bg); }
.picker button { border: 0; background: transparent; padding: 2px 5px; font-size: 18px; }
.reactions { display: flex; gap: 4px; flex-wrap: wrap; }
.reactions button { border: 0; padding: 1px 8px; border-radius: 12px; background: var(--bubble); font-size: 14px; }
.reactions button.mine { background: color-mix(in srgb, var(--accent) 35%, transparent); }
#composer { display: flex; gap: 8px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line); }
.icon-button { cursor: pointer; font-size: 20px; padding: 0 2px; }
#chat-error { padding: 0 14px 8px; }

/* Dialogs */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 22px; background: var(--bg); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.field { display: flex; flex-direction: column; gap: 4px; text-align: left; font-size: 13px; color: var(--muted); }
.checklist { max-height: 220px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: 4px; text-align: left; }
.checklist label { display: flex; align-items: center; gap: 10px; padding: 5px 6px; cursor: pointer; }

/* Phones: one pane at a time */
@media (max-width: 700px) {
  #sidebar { width: 100%; border-right: 0; }
  #chat { display: none; }
  #app.chat-open #sidebar { display: none; }
  #app.chat-open #chat { display: flex; }
  #back { display: block; }
  .message { max-width: 88%; }
}

/* Calls */
#call-audio, #call-video { padding: 4px 9px; }
.overlay { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, 0.55); }
.overlay > .card, .call-panel { background: var(--bg); border: 1px solid var(--line); border-radius: 16px; padding: 22px; }
#ringing-who { align-self: center; }
button.accept { background: var(--online); border-color: var(--online); }
button.leave { background: var(--danger); border-color: var(--danger); }
.call-panel { width: min(960px, 100%); max-height: 100%; display: flex; flex-direction: column; gap: 12px; overflow: auto; text-align: center; }
#tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; }
.tile { position: relative; aspect-ratio: 4 / 3; background: #000; border-radius: 12px; overflow: hidden; display: grid; place-items: center; }
.tile.spotlight { grid-column: 1 / -1; aspect-ratio: 16 / 9; }
.tile video { width: 100%; height: 100%; object-fit: contain; }
.tile video.mirrored { transform: scaleX(-1); }
.tile .avatar { position: absolute; }
.tile .label { position: absolute; left: 8px; bottom: 8px; padding: 2px 8px; border-radius: 10px; background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 12px; }
.controls { flex-wrap: wrap; }
.controls button.on { background: var(--bubble); }

/* Inside the iText app, only the call screens show, filling the app's call area. */
.embedded body { background: transparent; }
.embedded .overlay { background: var(--bg); }
