/* СВОИ — тема в стиле Claude: тёплый крем, терракота, спокойная типографика. */
:root {
  --bg: #eeece3;
  --sidebar: #f3f1e9;
  --surface: #fbfaf6;
  --elevated: #ffffff;
  --accent: #d97757;
  --accent-strong: #c15f3c;
  --accent-soft: rgba(217, 119, 87, .12);
  --text: #26241f;
  --muted: #83807a;
  --border: #e4e0d6;
  --border-soft: #ece9df;
  --bubble-out: #d97757;
  --bubble-out-text: #fffaf6;
  --bubble-in: #ffffff;
  --danger: #b64f3a;
  --online: #7a9a62;
  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;
  --shadow: 0 1px 2px rgba(38, 36, 31, .05), 0 8px 24px rgba(38, 36, 31, .06);
  --font: ui-sans-serif, -apple-system, "SF Pro Text", "Inter", system-ui, "Segoe UI", Roboto, sans-serif;
  --serif: "Tiempos", "Iowan Old Style", "Palatino", Georgia, serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg); color: var(--text);
  overflow: hidden; -webkit-font-smoothing: antialiased;
}
#app { height: 100%; display: flex; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; }

/* SVG-иконки вместо эмодзи */
.ic { width: 22px; height: 22px; display: inline-block; vertical-align: middle; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.ic.sm { width: 18px; height: 18px; }

/* ---------- Экран входа ---------- */
.auth {
  margin: auto; width: min(420px, 92vw);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 24px; padding: 34px 30px; box-shadow: var(--shadow);
}
.auth .brand { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-bottom: 6px; }
.auth .brand img { width: 68px; height: 68px; border-radius: 18px; }
.auth h1 { margin: 0; font-family: var(--serif); font-size: 30px; letter-spacing: 5px; font-weight: 500; text-align: center; }
.auth .sub { text-align: center; color: var(--muted); margin: 4px 0 24px; font-size: 14px; }
.auth label { display: block; font-size: 12.5px; color: var(--muted); margin: 16px 0 6px; font-weight: 500; }
.auth input {
  width: 100%; padding: 13px 15px; border-radius: var(--r-md); border: 1px solid var(--border);
  background: var(--elevated); color: var(--text); font-size: 15px; outline: none; transition: border-color .15s;
}
.auth input:focus { border-color: var(--accent); }
.btn {
  width: 100%; padding: 14px; border-radius: var(--r-md); margin-top: 22px;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 600; transition: background .15s, transform .05s;
}
.btn:hover { background: var(--accent-strong); }
.btn:active { transform: scale(.99); }
.btn.ghost { background: transparent; color: var(--accent); margin-top: 8px; }
.btn.danger { background: var(--danger); }
.err { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 16px; text-align: center; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 12px; line-height: 1.55; }
.tabs { display: flex; gap: 6px; margin-bottom: 6px; background: var(--bg); padding: 4px; border-radius: var(--r-md); }
.tabs button { flex: 1; padding: 9px; border-radius: var(--r-sm); color: var(--muted); font-size: 14px; font-weight: 500; }
.tabs button.on { background: var(--elevated); color: var(--text); box-shadow: 0 1px 3px rgba(38,36,31,.08); }

/* ---------- Макет ---------- */
.layout { display: flex; width: 100%; height: 100%; }
.sidebar { width: 348px; min-width: 348px; background: var(--sidebar); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.side-head { padding: calc(14px + env(safe-area-inset-top)) 16px 14px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--border); }
.side-head .me { flex: 1; overflow: hidden; }
.side-head .me .name { font-weight: 600; font-size: 15px; }
.side-head .me .uname { color: var(--muted); font-size: 12.5px; }
.iconbtn { background: transparent; color: var(--text); width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; transition: background .15s; }
.iconbtn:hover { background: var(--accent-soft); }
.iconbtn:active { background: var(--accent-soft); }
.iconbtn.primary { background: var(--accent); color: #fff; }
.iconbtn.primary:hover { background: var(--accent-strong); }

.stories-strip { display: flex; gap: 14px; padding: 14px 16px; overflow-x: auto; border-bottom: 1px solid var(--border); }
.stories-strip::-webkit-scrollbar { display: none; }
.story-av { flex: 0 0 auto; text-align: center; width: 62px; }
.story-av .ring { width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; font-size: 16px; font-weight: 600; margin: 0 auto 5px;
  background: var(--elevated); color: var(--accent); border: 2px solid var(--accent); }
.story-av.add .ring { border-style: dashed; border-color: var(--muted); color: var(--muted); }
.story-av .ring.has { border: 2.5px solid var(--accent); position: relative; }
.story-av .ring.has span { font-size: 16px; }
.story-add-btn { position: absolute; right: -3px; bottom: -3px; width: 20px; height: 20px; padding: 0; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; border: 2px solid var(--bg); z-index: 2; box-shadow: 0 1px 3px rgba(0,0,0,.18); }
.story-add-btn .ic { width: 12px; height: 12px; stroke-width: 2.6; }
.story-av .lbl { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.folders { display: flex; gap: 7px; padding: 10px 16px; overflow-x: auto; border-bottom: 1px solid var(--border); }
.folders::-webkit-scrollbar { display: none; }
.folders button { flex: 0 0 auto; padding: 7px 14px; border-radius: 20px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 500; border: 1px solid transparent; }
.folders button.on { background: var(--accent-soft); color: var(--accent-strong); }

.chatlist { flex: 1; overflow-y: auto; }
.chat-item { display: flex; gap: 13px; padding: 12px 16px; cursor: pointer; align-items: center; transition: background .12s; }
.chat-item:hover { background: rgba(38,36,31,.03); }
.chat-item.on { background: var(--accent-soft); }
.avatar { width: 50px; height: 50px; border-radius: 50%; background: linear-gradient(150deg, #e6a68c, var(--accent)); color: #fff; display: grid; place-items: center; font-size: 17px; font-weight: 600; flex: 0 0 auto; position: relative; }
.avatar .av-img, .ring .av-img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.avatar .dot { position: absolute; right: 1px; bottom: 1px; width: 12px; height: 12px; border-radius: 50%; background: var(--muted); border: 2.5px solid var(--sidebar); z-index: 1; }
.avatar .dot.on { background: var(--online); }
.chat-item .info { flex: 1; overflow: hidden; }
.chat-item .info .top { display: flex; justify-content: space-between; align-items: baseline; }
.chat-item .info .nm { font-weight: 600; font-size: 15px; }
.chat-item .info .tm { color: var(--muted); font-size: 11.5px; }
.chat-item .info .pv { color: var(--muted); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }

/* ---------- Чат ---------- */
.main { flex: 1; display: flex; flex-direction: column; background: var(--bg); }
.main.empty { display: grid; place-items: center; color: var(--muted); text-align: center; }
.main.empty .brand-lg { width: 72px; height: 72px; border-radius: 20px; margin: 0 auto 16px; opacity: .9; }
.chat-head { padding: calc(12px + env(safe-area-inset-top)) 18px 12px; display: flex; align-items: center; gap: 13px; background: var(--surface); border-bottom: 1px solid var(--border); }
.chat-head .info { flex: 1; }
.chat-head .info .nm { font-weight: 600; }
.chat-head .info .st { font-size: 12px; color: var(--muted); margin-top: 1px; }
.chat-head .info .st.on { color: var(--online); }

.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 3px; }
.msg { max-width: 72%; padding: 9px 13px; border-radius: 18px; font-size: 14.5px; line-height: 1.4; position: relative; word-wrap: break-word; box-shadow: 0 1px 1px rgba(38,36,31,.04); }
.msg.in { background: var(--bubble-in); border: 1px solid var(--border-soft); align-self: flex-start; border-bottom-left-radius: 6px; }
.msg.out { background: var(--bubble-out); color: var(--bubble-out-text); align-self: flex-end; border-bottom-right-radius: 6px; }
.msg .time { font-size: 10px; margin-left: 8px; float: right; margin-top: 5px; display: inline-flex; align-items: center; gap: 2px; }
.msg.in .time { color: var(--muted); }
.msg.out .time { color: rgba(255, 250, 246, .7); }
.msg .tick { display: inline-flex; margin-left: 1px; }
.msg .tick .ic { width: 15px; height: 15px; stroke-width: 2.2; }
.msg.out .tick .ic { color: rgba(255, 250, 246, .8); }
.msg.out .tick.read .ic { color: #9ecbff; opacity: 1; }
.msg .tick.read { opacity: 1; }
/* непрочитанные */
.pv-row { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.pv-row .pv { flex: 1; margin-top: 0; }
.unread { flex: 0 0 auto; background: var(--accent); color: #fff; font-size: 12px; font-weight: 600; min-width: 20px; height: 20px; border-radius: 10px; padding: 0 6px; display: grid; place-items: center; }
.msg img, .msg video { max-width: 100%; border-radius: 12px; display: block; }
.msg.sticker { background: transparent !important; border: none !important; box-shadow: none !important; font-size: 60px; padding: 0; }
.msg .fname { font-size: 12.5px; opacity: .8; }
.day-sep { align-self: center; background: rgba(38,36,31,.06); color: var(--muted); font-size: 11.5px; padding: 4px 12px; border-radius: 12px; margin: 10px 0; }
.typing { align-self: flex-start; color: var(--muted); font-size: 12.5px; padding: 2px 8px 8px; }

/* ---------- Ввод ---------- */
.composer { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--border); display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; max-height: 120px; padding: 12px 16px; border-radius: 22px; border: 1px solid var(--border); background: var(--elevated); color: var(--text); font-size: 15px; outline: none; transition: border-color .15s; }
.composer textarea:focus { border-color: var(--accent); }
.composer .iconbtn { flex: 0 0 auto; }

/* меню отложенной отправки (по удержанию) */
.send-menu { position: absolute; bottom: 74px; right: 16px; background: var(--elevated); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow); overflow: hidden; z-index: 45; min-width: 210px; }
.send-menu button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 13px 16px; font-size: 14px; }
.send-menu button:hover { background: var(--accent-soft); }
.send-menu button + button { border-top: 1px solid var(--border-soft); }

/* ---------- Нижняя навигация и вкладки ---------- */
.shell { height: 100%; width: 100%; flex: 1; display: flex; flex-direction: column; }
.tab-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.tabbar { display: flex; border-top: 1px solid var(--border); background: var(--surface); padding-bottom: env(safe-area-inset-bottom); }
.tabbar button { flex: 1; padding: 8px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--muted); font-size: 11px; font-weight: 500; }
.tabbar button .ic { width: 24px; height: 24px; }
.tabbar button.on { color: var(--accent); }
.tab-head { padding: calc(14px + env(safe-area-inset-top)) 16px 12px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); background: var(--surface); }
.wordmark { margin: 0; font-family: var(--serif); font-size: 22px; letter-spacing: 3px; font-weight: 500; }
.search-bar { display: flex; align-items: center; gap: 8px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.search-bar .ic { color: var(--muted); flex: 0 0 auto; }
.search-bar input { flex: 1; border: 1px solid var(--border); background: var(--elevated); border-radius: 12px; padding: 10px 14px; font-size: 15px; color: var(--text); outline: none; }
.search-bar input:focus { border-color: var(--accent); }
.scroll { flex: 1; overflow-y: auto; }
.section-lbl { font-size: 11px; color: var(--muted); font-weight: 600; letter-spacing: .6px; padding: 16px 18px 6px; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
.list-row .grow { flex: 1; overflow: hidden; }
.list-row .nm { font-weight: 600; font-size: 15px; }
.list-row .iconbtn { width: 40px; height: 40px; flex: 0 0 auto; }
.list-row .call-a { color: var(--online); }
.list-row .call-v { color: var(--accent); }
.avatar.sm { width: 46px; height: 46px; font-size: 15px; }
.avatar.lg { width: 66px; height: 66px; font-size: 24px; }
.avatar.muted { background: linear-gradient(150deg, #cfcabb, #a49f90); }
.list-row.picked { background: var(--accent-soft); }
.list-row .check { flex: 0 0 auto; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border); }
.list-row.picked .check { background: var(--accent); border-color: var(--accent); box-shadow: inset 0 0 0 3px var(--surface); }
.avatar.group { background: linear-gradient(150deg, #cfa088, var(--accent)); }
.avatar.group .ic { width: 24px; height: 24px; color: #fff; }
.avatar.sm.group .ic, .chat-item .avatar.group .ic { width: 24px; height: 24px; }
.sender-name { font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.btn-pill { background: var(--accent); color: #fff; padding: 8px 15px; border-radius: 18px; font-size: 13px; font-weight: 600; }
.btn-pill.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.set-row { display: flex; align-items: center; gap: 13px; padding: 15px 16px; border-bottom: 1px solid var(--border-soft); cursor: pointer; font-size: 15px; }
.set-row .ic { color: var(--muted); flex: 0 0 auto; }
.set-row:active { background: rgba(38,36,31,.03); }
.profile-card { display: flex; align-items: center; gap: 15px; padding: 20px 16px; }

/* полноэкранный чат поверх вкладок */
.chat-screen { position: fixed; inset: 0; z-index: 30; background: var(--bg); display: flex; flex-direction: column; }
.reply-bar { display: flex; align-items: center; gap: 10px; padding: 9px 14px; background: var(--surface); border-top: 1px solid var(--border); }
.reply-bar .rb-icon { color: var(--accent); display: flex; }
.reply-bar .rb-body { flex: 1; overflow: hidden; }
.reply-bar .rb-name { font-size: 12.5px; font-weight: 600; color: var(--accent); }
.reply-bar .rb-text { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* цитата ответа внутри пузыря */
.msg-quote { border-left: 2px solid var(--accent); padding: 2px 8px; margin-bottom: 5px; font-size: 13px; background: rgba(217,119,87,.08); border-radius: 4px; }
.msg.out .msg-quote { border-color: rgba(255,255,255,.75); background: rgba(255,255,255,.14); }
.msg-quote .q-name { font-weight: 600; font-size: 12px; }
.msg-quote .q-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 210px; opacity: .85; }

/* ---------- Модалки ---------- */
.overlay { position: fixed; inset: 0; background: rgba(38,36,31,.4); backdrop-filter: blur(2px); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 22px; padding: 24px; width: min(440px, 94vw); max-height: 86vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal h2 { margin: 0 0 16px; font-size: 19px; font-weight: 600; }
.modal .row { display: flex; align-items: center; gap: 13px; padding: 12px; border-radius: var(--r-md); }
.modal .row:hover { background: rgba(38,36,31,.03); }
.modal .row .ic { color: var(--muted); flex: 0 0 auto; }
.close-x { float: right; color: var(--muted); width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; margin: -6px -6px 0 0; }
.close-x:hover { background: rgba(38,36,31,.05); }
.invite-code { font-family: ui-monospace, "SF Mono", monospace; font-size: 20px; letter-spacing: 3px; background: var(--bg); padding: 13px; border-radius: var(--r-md); text-align: center; margin: 10px 0; user-select: all; color: var(--accent-strong); font-weight: 600; }
.small { font-size: 12.5px; color: var(--muted); }

/* эмодзи / стикеры (контент, не UI) */
.emoji-panel { position: absolute; bottom: 74px; right: 16px; width: min(340px, 90vw); max-height: 260px; overflow-y: auto; background: var(--elevated); border: 1px solid var(--border); border-radius: var(--r-md); padding: 10px; display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; z-index: 40; box-shadow: var(--shadow); }
.emoji-panel button { font-size: 23px; padding: 4px; border-radius: 8px; }
.emoji-panel button:hover { background: var(--accent-soft); }
.emoji-panel .cat { grid-column: 1/-1; font-size: 11px; color: var(--muted); padding: 7px 2px 2px; font-weight: 500; }

/* сторис-просмотр */
.story-view { position: fixed; inset: 0; background: #1a1815; z-index: 60; display: grid; place-items: center; }
.story-view img, .story-view video { max-width: 100vw; max-height: 90vh; }
.story-view .bar { position: absolute; top: env(safe-area-inset-top); left: 0; right: 0; display: flex; gap: 4px; padding: 12px; }
.story-view .bar .seg { flex: 1; height: 3px; background: rgba(255,255,255,.3); border-radius: 2px; overflow: hidden; }
.story-view .who { position: absolute; top: calc(26px + env(safe-area-inset-top)); left: 18px; font-weight: 600; color: #fff; }
.story-view .x { position: absolute; top: calc(22px + env(safe-area-inset-top)); right: 20px; color: #fff; z-index: 2; width: 34px; height: 34px; display: grid; place-items: center; }

/* редактор истории */
.story-editor { position: fixed; inset: 0; background: #000; z-index: 65; display: flex; flex-direction: column; }
.se-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; }
.se-tools { display: flex; gap: 6px; }
.se-stagewrap { flex: 1; display: grid; place-items: center; overflow: hidden; }
.se-stage { position: relative; overflow: hidden; border-radius: 14px; background: #000; touch-action: none; }
.se-stage #se-img { position: absolute; left: 50%; top: 50%; transform-origin: center; will-change: transform; }
.se-layers { position: absolute; inset: 0; pointer-events: none; }
.se-text { position: absolute; left: 50%; top: 50%; transform-origin: center; color: #fff; font-weight: 700; max-width: 80%; text-align: center; text-shadow: 0 2px 8px rgba(0,0,0,.5); white-space: pre-wrap; padding: 2px 8px; pointer-events: auto; user-select: none; }
.se-text.sel { outline: 1.5px dashed rgba(255,255,255,.75); border-radius: 8px; }
.se-colors { display: flex; gap: 12px; justify-content: center; padding: 12px; }
.se-color { width: 30px; height: 30px; border-radius: 50%; border: 2px solid rgba(255,255,255,.65); }
.se-hint { text-align: center; color: rgba(255,255,255,.55); font-size: 12px; padding: 8px 16px calc(14px + env(safe-area-inset-bottom)); }

/* звонок */
.call { position: fixed; inset: 0; z-index: 70; display: flex; flex-direction: column;
  background: radial-gradient(120% 90% at 50% 0%, #3a2e26 0%, #221c17 55%, #17130f 100%); }
.call video.remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.call video.local { position: absolute; top: calc(18px + env(safe-area-inset-top)); right: 16px; width: 108px; aspect-ratio: 3/4; object-fit: cover; border-radius: 16px; border: 1.5px solid rgba(255,255,255,.3); box-shadow: 0 8px 24px rgba(0,0,0,.4); z-index: 2; background: #000; }
.call audio { display: none; }
.call .call-info { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; z-index: 1; padding-top: env(safe-area-inset-top); }
.call .call-info .avatar.xl { width: 116px; height: 116px; font-size: 40px; margin-bottom: 14px; box-shadow: 0 0 0 10px rgba(217,119,87,.14), 0 0 0 22px rgba(217,119,87,.06); }
.call .call-name { color: #fdfaf5; font-size: 27px; font-weight: 600; font-family: var(--serif); letter-spacing: .5px; }
.call .call-status { color: rgba(253,250,245,.55); font-size: 15px; font-variant-numeric: tabular-nums; }
.call.has-video.connected .call-info { visibility: hidden; }  /* при видеосвязи инфо уступает место видео (место сохраняем, чтобы кнопки не прыгали) */
.call .controls { display: flex; justify-content: center; gap: 26px; padding: 26px 26px calc(34px + env(safe-area-inset-bottom)); z-index: 2; margin-top: auto; }
.call .controls button { width: 64px; height: 64px; border-radius: 50%; color: #fff; background: rgba(255,255,255,.12); backdrop-filter: blur(10px); display: grid; place-items: center; transition: background .15s, transform .05s; }
.call .controls button:active { transform: scale(.95); }
.call .controls .end { background: var(--danger); }
.call .controls .accept { background: var(--online); }

/* входящий звонок */
.ringing { position: fixed; top: calc(22px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: 14px 18px; z-index: 80; display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow); }
.ringing button { border-radius: var(--r-sm); padding: 10px 15px; color: #fff; font-weight: 600; }

.badge-e2e { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--online); }

/* тост */
#toast { position: fixed; bottom: calc(24px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 11px 20px; border-radius: 22px; z-index: 100; font-size: 14px; box-shadow: var(--shadow); transition: opacity .2s; }

/* мобильная адаптация */
.back-btn { display: none; }
@media (max-width: 720px) {
  .sidebar { width: 100%; min-width: 0; }
  .main { position: absolute; inset: 0; z-index: 10; }
  .layout.show-chat .sidebar { display: none; }
  .layout:not(.show-chat) .main { display: none; }
  .back-btn { display: grid; }
}
