:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c1d21;
  --muted: #7a7f8c;
  --line: #e6e8ec;
  --accent: #5b5bd6;
  --accent-soft: #ececfb;
  --mine: #e7e7fb;
  --danger: #d64545;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* protection: no selection, no callout, no drag */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

img, video { -webkit-user-drag: none; user-drag: none; pointer-events: auto; }
textarea, input { -webkit-user-select: text; user-select: text; font: inherit; }

#app { height: 100%; display: flex; flex-direction: column; }

#watermark {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  background-repeat: repeat;
  opacity: 0.09;
}

.screen { flex: 1; padding: 24px; }
.center { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 12px; }
.center h2 { margin: 0; font-size: 19px; }
.center p { margin: 0; color: var(--muted); max-width: 320px; }

.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

header.top {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px 0;
}
header.top .title { font-weight: 600; font-size: 16px; }
header.top .sub { color: var(--muted); font-size: 13px; }
header.top select {
  margin-top: 4px; border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; background: var(--card);
}

.tabs { display: flex; gap: 4px; margin-top: 8px; }
.tabs button {
  flex: 1; border: 0; background: none; padding: 10px 0; font-size: 15px; color: var(--muted);
  border-bottom: 2px solid transparent; cursor: pointer;
}
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

main { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* materials */
.feed { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.post { background: var(--card); border-radius: var(--radius); padding: 14px; }
.post .date { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.post .date .soon { color: var(--accent); }
.post .text { white-space: pre-wrap; word-wrap: break-word; }
.post img, .post video, .bubble img { max-width: 100%; border-radius: 10px; display: block; margin-top: 8px; }
.post audio, .bubble audio { width: 100%; margin-top: 8px; }
.file-link { display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; color: var(--accent); }
a.ext { color: var(--accent); text-decoration: underline; }

.composer-post { background: var(--card); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.composer-post textarea { border: 1px solid var(--line); border-radius: 10px; padding: 8px; min-height: 80px; resize: vertical; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn {
  border: 0; border-radius: 10px; padding: 9px 14px; background: var(--accent); color: #fff; font-size: 15px; cursor: pointer;
}
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn:disabled { opacity: 0.5; }

/* chat */
.chat { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.messages { flex: 1; overflow-y: auto; padding: 10px 10px 6px; display: flex; flex-direction: column; gap: 4px; }
.loader-top { text-align: center; color: var(--muted); font-size: 12px; padding: 6px; }
.day { align-self: center; color: var(--muted); font-size: 12px; background: var(--card); border-radius: 10px; padding: 2px 10px; margin: 8px 0 4px; }
.msg { display: flex; flex-direction: column; max-width: 86%; align-self: flex-start; }
.msg.mine { align-self: flex-end; }
.bubble { background: var(--card); border-radius: 14px; padding: 7px 10px; position: relative; cursor: pointer; }
.msg.mine .bubble { background: var(--mine); }
.msg .who { font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.msg .who.owner::after { content: " · ведущая"; color: var(--muted); font-weight: 400; }
.msg .body { white-space: pre-wrap; word-wrap: break-word; }
.msg .meta { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.msg.deleted .body { color: var(--muted); font-style: italic; }
.quote { border-left: 3px solid var(--accent); padding: 2px 8px; margin-bottom: 4px; background: rgba(91, 91, 214, 0.06); border-radius: 4px; font-size: 13px; }
.quote b { display: block; color: var(--accent); font-weight: 600; }

.new-pill {
  position: absolute; bottom: 76px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #fff; border-radius: 16px; padding: 6px 14px; font-size: 13px; cursor: pointer;
}

.composer { background: var(--card); border-top: 1px solid var(--line); padding: 8px 8px calc(8px + var(--safe-bottom)); }
.reply-bar { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 0 4px 6px; }
.reply-bar .q { flex: 1; border-left: 3px solid var(--accent); padding-left: 8px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.input-row { display: flex; align-items: flex-end; gap: 6px; }
.input-row textarea {
  flex: 1; border: 1px solid var(--line); border-radius: 18px; padding: 8px 12px; max-height: 120px; resize: none; background: var(--bg);
}
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 0; background: none; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex: none;
}
.icon-btn.send { background: var(--accent); color: #fff; }
.icon-btn svg { width: 20px; height: 20px; }

.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.3); z-index: 40; display: flex; align-items: flex-end; }
.sheet { background: var(--card); width: 100%; border-radius: 16px 16px 0 0; padding: 8px 8px calc(12px + var(--safe-bottom)); }
.sheet button { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; padding: 14px 12px; font-size: 16px; text-align: left; cursor: pointer; }
.sheet button.danger { color: var(--danger); }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: rgba(28, 29, 33, 0.92); color: #fff; padding: 8px 14px; border-radius: 10px; z-index: 60; font-size: 14px; }

/* materials: view toggle, post menu, edit mode */
.seg { display: flex; background: var(--card); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 0; border-radius: 9px; font-size: 14px; color: var(--muted); cursor: pointer; }
.seg button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.post-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.post-head .date { margin-bottom: 6px; }
.post-menu { width: 32px; height: 32px; margin: -6px -6px 0 0; }
.composer-post.editing { outline: 2px solid var(--accent); }
.edit-note { font-size: 13px; color: var(--accent); font-weight: 600; }
.sheet-q { padding: 12px 12px 4px; color: var(--muted); font-size: 14px; }

/* emoji */
.emoji-panel {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
  max-height: 180px; overflow-y: auto; padding: 6px 2px 8px;
}
.emoji-panel[hidden] { display: none; }
.emoji-panel button { border: 0; background: none; font-size: 24px; line-height: 1; padding: 6px 0; border-radius: 8px; cursor: pointer; }
.emoji-panel button:active { background: var(--accent-soft); }

.seg.small button { padding: 6px 0; font-size: 13px; }
.row[hidden], .input-row[hidden], .rec-row[hidden], .icon-btn[hidden] { display: none !important; }

/* voice recording */
.rec-row { display: flex; align-items: center; gap: 8px; }
.rec-info { flex: 1; display: flex; align-items: center; gap: 8px; color: var(--muted); }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.3; } }

.voice-preview { display: flex; align-items: center; gap: 6px; }
.voice-preview[hidden] { display: none !important; }
.voice-preview audio { flex: 1; margin: 0; }
