/* ============================================================
   CipChat — дизайн-система CipOS (cipos.ru)
   Токены взяты 1:1 с главной страницы cipos.ru
   ============================================================ */
:root {
  --bg: #0A0D14;
  --panel: #0E121B;
  --card: #121722;
  --card2: #161C29;
  --line: rgba(255, 255, 255, .08);
  --line2: rgba(255, 255, 255, .16);
  --text: #EAEFF7;
  --muted: #9BA5B6;
  --dim: #6E7889;
  --neon: #A240F5;
  --neon2: #C77DFF;
  --neon-dim: rgba(162, 64, 245, .13);
  --cyan: #4FD1E8;
  --cyan-dim: rgba(79, 209, 232, .12);
  --green: #4ADE80;
  --violet: #A78BFA;
  --blue: #60A5FA;
  --coral: #FB7185;
  --slate: #94A3B8;
  --red: #F87171;
  --fd: 'Unbounded', sans-serif;
  --fb: 'Manrope', sans-serif;
  --rad: 0px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  background-image:
    linear-gradient(rgba(255, 255, 255, .024) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .024) 1px, transparent 1px);
  background-size: 42px 42px;
  color: var(--text);
  font-family: var(--fb);
  font-size: 15px;
  line-height: 1.45;
  overflow: hidden;
}

button { font-family: var(--fb); }
input, textarea { font-family: var(--fb); color: var(--text); }
a { color: var(--blue); text-decoration: none; }
::selection { background: rgba(162, 64, 245, .4); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .12); }
::-webkit-scrollbar-thumb:hover { background: rgba(162, 64, 245, .45); }

/* ---------------- splash ---------------- */
.splash {
  position: fixed; inset: 0; z-index: 400;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; background: var(--bg);
  background-image:
    linear-gradient(rgba(255, 255, 255, .024) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .024) 1px, transparent 1px);
  background-size: 42px 42px;
  transition: opacity .35s;
}
.splash.hide { opacity: 0; pointer-events: none; }
.splash-mark { width: 92px; height: 92px; border: 1px solid var(--line); background: linear-gradient(180deg, var(--card2), var(--card)); }
.splash-name { font-family: var(--fd); font-weight: 800; font-size: 26px; letter-spacing: .02em; }
.splash-name em { font-style: normal; background: linear-gradient(100deg, var(--neon2), var(--neon)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.splash-note { color: var(--dim); font-size: 12px; letter-spacing: .14em; text-transform: uppercase; }
.splash-bar { width: 180px; height: 2px; background: var(--line); overflow: hidden; margin-top: 8px; }
.splash-bar i { display: block; width: 40%; height: 100%; background: linear-gradient(90deg, transparent, var(--neon), transparent); animation: slide 1.1s infinite; }
@keyframes slide { from { transform: translateX(-120%); } to { transform: translateX(340%); } }

/* ---------------- общие компоненты ---------------- */
.eyebrow {
  display: inline-flex; align-items: center; gap: 10px;
  font-size: 11px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--neon2); font-weight: 700;
}
.eyebrow::before {
  content: ""; width: 26px; height: 2px;
  background: linear-gradient(90deg, var(--neon), rgba(162, 64, 245, .18));
  box-shadow: 0 0 9px var(--neon), 0 0 22px rgba(162, 64, 245, .55);
}

.btn {
  border: 1px solid var(--line2); background: rgba(255, 255, 255, .035);
  color: var(--text); cursor: pointer; padding: 10px 16px; font-size: 14px;
  font-weight: 700; transition: all .18s; user-select: none;
}
.btn:hover { border-color: rgba(162, 64, 245, .55); background: var(--neon-dim); }
.btn:disabled { opacity: .45; cursor: default; }

.btn-p {
  background: linear-gradient(135deg, #C77DFF, #8A2BE2);
  color: #FFFFFF; border: none;
  box-shadow: 0 6px 26px rgba(162, 64, 245, .3);
}
.btn-p:hover { background: linear-gradient(135deg, #D48EFF, #9B35F0); box-shadow: 0 8px 30px rgba(162, 64, 245, .4); transform: translateY(-1px); }

.btn-ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn-danger { color: var(--coral); border-color: rgba(251, 113, 133, .35); }
.btn-danger:hover { border-color: var(--coral); background: rgba(251, 113, 133, .1); }

.f-in {
  width: 100%; background: linear-gradient(180deg, rgba(255, 255, 255, .035), rgba(255, 255, 255, .014));
  border: 1px solid var(--line); color: var(--text);
  padding: 13px 14px; font-size: 15px; outline: none; transition: border-color .18s;
}
.f-in:focus { border-color: rgba(162, 64, 245, .65); box-shadow: 0 0 0 3px var(--neon-dim); }
.f-in::placeholder { color: var(--dim); }
.label { display: block; font-size: 12px; color: var(--muted); margin: 14px 0 6px; letter-spacing: .04em; }

.card {
  background: linear-gradient(180deg, var(--card2), var(--card));
  border: 1px solid var(--line);
}

/* ---------------- авторизация ---------------- */
.auth-wrap {
  height: 100%; display: flex; align-items: center; justify-content: center;
  padding: 20px; overflow-y: auto;
}
.auth-card {
  width: 100%; max-width: 420px; padding: 34px 30px 30px;
  background: linear-gradient(160deg, rgba(162, 64, 245, .13), rgba(22, 28, 41, .9) 42%, rgba(14, 18, 27, .96));
  border: 1px solid rgba(162, 64, 245, .35);
  box-shadow: 0 26px 70px rgba(0, 0, 0, .42);
}
.auth-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.auth-logo svg { width: 44px; height: 40px; }
.brand-name { font-family: var(--fd); font-weight: 800; font-size: 24px; letter-spacing: .01em; }
.brand-name em { font-style: normal; background: linear-gradient(100deg, var(--neon2), var(--neon)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.auth-sub { color: var(--muted); font-size: 14px; margin: 4px 0 8px; }
.auth-err {
  margin-top: 12px; padding: 10px 12px; font-size: 13.5px; color: var(--coral);
  border: 1px solid rgba(251, 113, 133, .3); background: rgba(251, 113, 133, .07);
}
.auth-err:empty { display: none; }
.auth-actions { margin-top: 18px; }
.btn-block { width: 100%; padding: 13px; font-size: 15px; }
.auth-foot { margin-top: 18px; font-size: 12px; color: var(--dim); text-align: center; }
.dev-code {
  margin-top: 14px; padding: 12px 14px;
  background: var(--neon-dim); border: 1px solid rgba(162, 64, 245, .4);
}
.dev-code b { font-family: var(--fd); font-size: 20px; letter-spacing: .22em; color: var(--neon2); }
.dev-code span { display: block; font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.code-hint { color: var(--muted); font-size: 13.5px; }
.code-hint b { color: var(--text); }
.change-phone { margin-top: 16px; }

/* ---------------- каркас приложения ---------------- */
.app { height: 100%; display: none; }
.app.on { display: grid; grid-template-columns: 344px 1fr; }

.conn-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 320;
  background: linear-gradient(90deg, rgba(162, 64, 245, .28), rgba(79, 209, 232, .18));
  border-bottom: 1px solid rgba(162, 64, 245, .45);
  color: var(--text); font-size: 13px; text-align: center; padding: 7px;
  display: none;
}
.conn-banner.on { display: block; }

/* ---------------- сайдбар ---------------- */
.sidebar {
  display: flex; flex-direction: column; min-width: 0;
  border-right: 1px solid var(--line); background: linear-gradient(180deg, var(--panel), var(--bg));
}
.sb-head { padding: 14px 14px 10px; border-bottom: 1px solid var(--line); }
.sb-logo { display: flex; align-items: center; gap: 10px; }
.sb-logo svg { width: 34px; height: 31px; flex: none; }
.sb-logo .brand-name { font-size: 19px; }
.sb-logo .spacer { flex: 1; }
.iconbtn {
  width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line2); background: rgba(255, 255, 255, .035);
  color: var(--text); cursor: pointer; font-size: 17px; transition: all .18s; flex: none;
}
.iconbtn:hover { border-color: rgba(162, 64, 245, .55); background: var(--neon-dim); color: var(--neon2); }
.sb-search { margin-top: 12px; position: relative; }
.sb-search .f-in { padding: 10px 12px 10px 36px; font-size: 14px; }
.sb-search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); opacity: .5; }

.chatlist { flex: 1; overflow-y: auto; padding: 6px 0; }
.cl-item {
  display: flex; gap: 12px; align-items: center; padding: 11px 14px;
  cursor: pointer; border-left: 2px solid transparent; transition: background .15s;
}
.cl-item:hover { background: rgba(255, 255, 255, .03); }
.cl-item.on { background: linear-gradient(90deg, rgba(162, 64, 245, .12), rgba(162, 64, 245, .03)); border-left-color: var(--neon); }
.cl-main { flex: 1; min-width: 0; }
.cl-row1 { display: flex; align-items: center; gap: 8px; }
.cl-name { font-weight: 700; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cl-time { margin-left: auto; font-size: 11.5px; color: var(--dim); flex: none; }
.cl-row2 { display: flex; align-items: center; gap: 8px; margin-top: 3px; }
.cl-preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cl-item .cl-preview.unsent { color: var(--coral); }
.cl-badge {
  flex: none; min-width: 20px; height: 20px; padding: 0 6px;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #C77DFF, #8A2BE2);
  color: #fff; font-size: 11.5px; font-weight: 800;
}
.cl-badge.off { display: none; }
.cl-empty { padding: 40px 24px; text-align: center; color: var(--muted); }
.cl-empty .btn { margin-top: 16px; }

.sb-foot { padding: 10px 14px; border-top: 1px solid var(--line); font-size: 11px; color: var(--dim); display: flex; align-items: center; gap: 8px; }
.push-banner {
  margin: 8px 10px 4px; padding: 10px 12px; cursor: pointer;
  background: var(--cyan-dim); border: 1px solid rgba(79, 209, 232, .35);
  font-size: 12.5px; color: var(--text); display: none;
}
.push-banner.on { display: block; }
.push-banner b { color: var(--cyan); }

/* ---------------- аватары ---------------- */
.avatar {
  position: relative; flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 46px; height: 46px; font-family: var(--fd); font-weight: 700; font-size: 16px;
  color: #fff; border: 1px solid var(--line); overflow: hidden; user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 36px; height: 36px; font-size: 13px; }
.avatar.lg { width: 84px; height: 84px; font-size: 30px; }
.av-g0 { background: linear-gradient(135deg, #8A2BE2, #A240F5); }
.av-g1 { background: linear-gradient(135deg, #3B9EC9, #4FD1E8); }
.av-g2 { background: linear-gradient(135deg, #22C55E, #4ADE80); }
.av-g3 { background: linear-gradient(135deg, #3B82F6, #60A5FA); }
.av-g4 { background: linear-gradient(135deg, #E11D48, #FB7185); }
.av-g5 { background: linear-gradient(135deg, #7C3AED, #A78BFA); }
.presence {
  position: absolute; right: -3px; bottom: -3px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--dim); border: 2px solid var(--panel); display: none;
}
.presence.on { display: block; background: var(--green); box-shadow: 0 0 8px rgba(74, 222, 128, .6); }

/* ---------------- панель чата ---------------- */
.chatpane { display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.chatpane-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--dim); padding: 24px; text-align: center; }
.chatpane-empty .big { font-family: var(--fd); font-weight: 700; font-size: 20px; color: var(--muted); }

.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  border-bottom: 1px solid var(--line); background: linear-gradient(180deg, var(--panel), rgba(14, 18, 27, .92));
  min-height: 62px;
}
.chat-head .backbtn { display: none; }
.ch-main { flex: 1; min-width: 0; cursor: pointer; }
.ch-title { font-family: var(--fd); font-weight: 600; font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-sub .typing { color: var(--cyan); }

.msgs { flex: 1; overflow-y: auto; padding: 18px 18px 8px; scroll-behavior: auto; }
.day-sep { display: flex; align-items: center; gap: 14px; margin: 18px 0 10px; color: var(--dim); font-size: 11.5px; letter-spacing: .1em; text-transform: uppercase; }
.day-sep::before, .day-sep::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.unread-sep { display: flex; align-items: center; gap: 14px; margin: 12px 0; color: var(--neon2); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; }
.unread-sep::before, .unread-sep::after { content: ""; flex: 1; height: 1px; background: rgba(162, 64, 245, .4); }

.msg { display: flex; margin: 3px 0; }
.msg.own { justify-content: flex-end; }
.msg .body { max-width: min(72%, 560px); min-width: 60px; }
.msg .meta { display: flex; gap: 8px; align-items: flex-end; justify-content: flex-end; margin-top: 3px; font-size: 10.5px; color: var(--dim); }
.bubble {
  padding: 9px 12px; border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--card2), var(--card));
  white-space: pre-wrap; word-break: break-word; font-size: 14.5px;
}
.msg.own .bubble {
  background: linear-gradient(135deg, rgba(162, 64, 245, .88), rgba(138, 43, 226, .82));
  border-color: rgba(162, 64, 245, .5);
}
.msg .sender-line { font-size: 12px; font-weight: 700; color: var(--neon2); margin-bottom: 3px; }
.quote { border-left: 2px solid var(--neon); background: rgba(162, 64, 245, .08); padding: 6px 9px; margin-bottom: 6px; font-size: 12.5px; color: var(--muted); }
.quote .qn { color: var(--neon2); font-weight: 700; }
.bubble img.pic { display: block; max-width: 100%; max-height: 320px; border: 1px solid var(--line); cursor: zoom-in; margin: 2px 0; }
.bubble .status { display: inline-block; }
.tick { font-size: 12px; color: rgba(255, 255, 255, .55); }
.tick.read { color: var(--cyan); }
.file-card { display: flex; gap: 10px; align-items: center; padding: 8px 10px; background: rgba(0, 0, 0, .25); border: 1px solid var(--line); cursor: pointer; }
.file-card .fic { width: 34px; height: 34px; flex: none; display: flex; align-items: center; justify-content: center; background: var(--cyan-dim); color: var(--cyan); font-size: 15px; }
.file-card .fn { font-size: 13.5px; font-weight: 700; word-break: break-all; }
.file-card .fs { font-size: 11.5px; color: var(--dim); }
.pending { opacity: .55; }
.pending .spinner { display: inline-block; width: 11px; height: 11px; border: 2px solid rgba(255, 255, 255, .3); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.msgs-empty { padding: 60px 20px; text-align: center; color: var(--dim); }
.msgs-more { text-align: center; padding: 6px; }
.msgs-more button { font-size: 12px; }

/* ---------------- composer ---------------- */
.composer { border-top: 1px solid var(--line); background: linear-gradient(180deg, var(--panel), var(--bg)); padding: 10px 14px 12px; }
.reply-bar {
  display: flex; align-items: center; gap: 10px; margin-bottom: 8px; padding: 8px 10px;
  background: var(--neon-dim); border: 1px solid rgba(162, 64, 245, .35); font-size: 13px;
}
.reply-bar .rb-quote { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar .rb-quote .qn { color: var(--neon2); font-weight: 700; }
.reply-bar .iconbtn { width: 26px; height: 26px; font-size: 13px; }
.comp-row { display: flex; align-items: flex-end; gap: 10px; }
.comp-row .f-in {
  flex: 1; resize: none; max-height: 132px; min-height: 42px;
  padding: 11px 13px; line-height: 1.4; background: linear-gradient(180deg, rgba(255, 255, 255, .035), rgba(255, 255, 255, .014));
}
.sendbtn {
  flex: none; width: 44px; height: 44px; border: none; cursor: pointer;
  background: linear-gradient(135deg, #C77DFF, #8A2BE2);
  color: #fff; font-size: 18px; box-shadow: 0 6px 26px rgba(162, 64, 245, .3);
  display: inline-flex; align-items: center; justify-content: center; transition: transform .15s;
}
.sendbtn:hover { transform: translateY(-1px); }
.sendbtn:disabled { opacity: .4; cursor: default; transform: none; }

/* ---------------- модальные окна ---------------- */
.overlay {
  position: fixed; inset: 0; z-index: 340; background: rgba(5, 7, 11, .72);
  display: none; align-items: center; justify-content: center; padding: 18px;
  backdrop-filter: blur(2px);
}
.overlay.on { display: flex; }
.modal {
  width: 100%; max-width: 440px; max-height: calc(100vh - 60px); overflow-y: auto;
  padding: 24px; background: linear-gradient(180deg, var(--card2), var(--card));
  border: 1px solid var(--line2); box-shadow: 0 26px 70px rgba(0, 0, 0, .5);
}
.modal h3 { font-family: var(--fd); font-weight: 600; font-size: 17px; margin: 0 0 4px; }
.modal .modal-x { float: right; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions .btn { flex: 1; }

.contact-item { display: flex; align-items: center; gap: 12px; padding: 9px 8px; cursor: pointer; border-left: 2px solid transparent; }
.contact-item:hover { background: rgba(255, 255, 255, .04); border-left-color: var(--neon); }
.contact-item .c-name { font-weight: 700; font-size: 14px; }
.contact-item .c-phone { font-size: 12px; color: var(--muted); }
.contact-item.sel { background: var(--neon-dim); border-left-color: var(--neon); }
.contact-list { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 6px; min-height: 40px; max-height: 300px; overflow-y: auto; }

.profile-top { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 6px; }
.profile-top .avatar { cursor: pointer; }
.profile-top .hint { font-size: 11px; color: var(--dim); }
.row-line { display: flex; align-items: center; justify-content: space-between; padding: 12px 4px; border-bottom: 1px solid var(--line); font-size: 14px; }

.member-row { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.member-row .m-name { font-size: 14px; font-weight: 700; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member-row .m-role { font-size: 11px; color: var(--cyan); letter-spacing: .08em; text-transform: uppercase; }

.invite-box { margin-top: 12px; padding: 14px; background: var(--cyan-dim); border: 1px solid rgba(79, 209, 232, .35); }
.invite-box .txt { font-size: 13.5px; color: var(--text); word-break: break-all; margin: 6px 0 10px; }

/* ---------------- lightbox / toast ---------------- */
.lightbox { position: fixed; inset: 0; z-index: 360; background: rgba(4, 6, 10, .92); display: none; align-items: center; justify-content: center; cursor: zoom-out; }
.lightbox.on { display: flex; }
.lightbox img { max-width: 94vw; max-height: 92vh; border: 1px solid var(--line2); }

.toast-zone { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 380; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: linear-gradient(180deg, var(--card2), var(--card));
  border: 1px solid rgba(162, 64, 245, .5); color: var(--text);
  padding: 10px 18px; font-size: 13.5px; box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
  animation: pop .25s;
}
@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------------- мобильная версия ---------------- */
@media (max-width: 760px) {
  .app.on { display: block; }
  .sidebar { height: 100%; }
  .chatpane { position: fixed; inset: 0; z-index: 200; transform: translateX(100%); transition: transform .22s ease; background: var(--bg); }
  body.chat-open .chatpane { transform: none; }
  .chat-head .backbtn { display: inline-flex; }
  .msg .body { max-width: 84%; }
}
