/* Мессенджер — дополняет app.css (цвета берутся оттуда) */
.badge {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--m2); color: #fff; font: 700 .72rem/1 var(--sans); margin-left: 6px; vertical-align: 1px;
}
.tabbar a { position: relative; }
.tabbar a .badge { position: absolute; top: 0; left: 50%; margin-left: 6px; }
.toast.msg {
  display: grid; gap: 2px; text-decoration: none; background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-left: 4px solid var(--navy); font-weight: 400;
}
.toast.msg b { color: var(--navy-d); }

body[data-page=chats] .app { max-width: 1180px; padding-bottom: 20px; }
.chat-layout {
  display: grid; grid-template-columns: 330px minmax(0, 1fr); height: calc(100vh - 108px); min-height: 420px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden;
}
.chat-side { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.chat-side-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 16px 12px; border-bottom: 1px solid var(--line); }
.chat-side-head h1 { font-size: 1.35rem; margin: 0; }
.pad { padding: 16px; }
.chat-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.chat-item {
  display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 10px; align-items: center;
  padding: 9px 10px; border-radius: 12px; text-decoration: none; color: inherit;
}
.chat-item:hover { background: var(--paper-2); }
.chat-item.active { background: var(--sky-l); }
.ci-main { display: grid; gap: 2px; min-width: 0; }
.ci-top, .ci-bottom { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; min-width: 0; }
.ci-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-time { color: var(--muted); font-size: .78rem; flex: none; }
.ci-last { color: var(--muted); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font: 700 .95rem var(--sans); color: #fff; background: var(--sky);
}
.avatar.teacher { background: var(--gold); }
.avatar.admin { background: var(--navy); }
.avatar.cls { background: var(--paper-2); font-size: 1.3rem; }

.chat-empty { display: grid; place-items: center; text-align: center; color: var(--muted); }
.chat-empty p { margin: 6px 0 14px; }
.big-icon { font-size: 3rem; }

.conv { display: flex; flex-direction: column; min-height: 0; min-width: 0; position: relative; }
.conv.drop::after {
  content: "Отпустите, чтобы отправить файл"; position: absolute; inset: 8px; border: 3px dashed var(--navy);
  border-radius: var(--r); display: grid; place-items: center; font-weight: 700; color: var(--navy);
  background: color-mix(in srgb, var(--card) 85%, transparent);
}
.conv-head { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.conv-head .avatar { width: 40px; height: 40px; }
.conv-title { display: grid; flex: 1; min-width: 0; }
.conv-title b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-title .muted { font-size: .85rem; }
.back-btn { display: none; text-decoration: none; font-size: 1.3rem; padding: 4px 8px; border-radius: 8px; }
.msgs { flex: 1; overflow-y: auto; padding: 14px 18px; display: flex; flex-direction: column; gap: 4px; background: var(--paper); }
.more-btn { align-self: center; margin-bottom: 8px; }
.msgs-empty { margin: auto; color: var(--muted); }
.day-sep { text-align: center; margin: 10px 0 6px; }
.day-sep span { background: var(--paper-2); color: var(--muted); font-size: .78rem; font-weight: 600; padding: 3px 12px; border-radius: 999px; }

.msg { display: flex; align-items: flex-start; gap: 4px; max-width: min(78%, 620px); }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.bubble {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px 16px 16px 4px;
  padding: 7px 12px 6px; display: grid; gap: 3px; min-width: 70px; box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
}
.msg.mine .bubble { background: var(--navy); color: #fff; border-color: transparent; border-radius: 16px 16px 4px 16px; }
.m-text { white-space: pre-wrap; word-break: break-word; }
.msg.mine .m-text a { color: inherit; }
.m-author { font-weight: 700; font-size: .84rem; color: var(--sky); }
.m-author.teacher { color: var(--m3); }
.m-author.admin { color: var(--navy); }
.m-role {
  font-weight: 600; font-size: .7rem; background: color-mix(in srgb, var(--gold) 22%, transparent);
  color: var(--m3); padding: 1px 6px; border-radius: 999px; margin-left: 6px;
}
.m-meta { justify-self: end; font-size: .72rem; opacity: .7; white-space: nowrap; }
.m-ticks { margin-left: 4px; letter-spacing: -2px; }
.m-ticks.read { color: var(--gold); }
.msg.deleted .bubble { background: transparent; color: var(--muted); border: 1px dashed var(--line); }
.m-deleted { font-style: italic; font-size: .9rem; }
.m-img img { display: block; max-width: min(280px, 100%); max-height: 320px; border-radius: 10px; object-fit: cover; }
.m-file { display: flex; gap: 10px; align-items: center; text-decoration: none; color: inherit; padding: 4px 0; }
.m-file > span:last-child { display: grid; }
.m-file b { word-break: break-word; }
.msg.mine .m-file .muted { color: inherit; opacity: .75; }
.m-file-icon { font-size: 1.6rem; }
.m-more {
  background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1.1rem; line-height: 1;
  width: 28px; height: 28px; border-radius: 50%; opacity: 0; margin-top: 4px;
}
.msg:hover .m-more, .m-more:focus-visible { opacity: 1; }
.m-more:hover { background: var(--paper-2); }
@media (pointer: coarse) { .m-more { opacity: .55; } }
.m-menu {
  position: absolute; z-index: 45; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 5px; display: grid; min-width: 160px;
}
.m-menu button { text-align: left; background: none; border: 0; font: inherit; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--ink); }
.m-menu button:hover, .m-menu button:focus-visible { background: var(--paper-2); }
.m-menu button.danger { color: var(--danger); }

.composer { border-top: 1px solid var(--line); padding: 10px 12px; background: var(--card); }
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.composer-input { min-height: 44px; max-height: 160px; resize: none; border-radius: 22px; padding: 11px 16px; line-height: 1.35; }
.attach-btn, .send-btn {
  flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer; font-size: 1.15rem;
  display: grid; place-items: center;
}
.attach-btn { background: var(--paper-2); }
.send-btn { background: var(--navy); color: #fff; }
.send-btn:hover { background: var(--navy-d); }
.edit-bar { display: flex; justify-content: space-between; align-items: center; font-size: .88rem; font-weight: 600; color: var(--navy); padding: 0 8px 8px; }
.composer-closed { border-top: 1px solid var(--line); padding: 14px; text-align: center; color: var(--muted); background: var(--paper-2); font-size: .92rem; }

.contacts-group { font: 600 .8rem var(--sans); text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 14px 0 6px; }
.contacts .people { display: grid; gap: 2px; }
.contact {
  display: flex; align-items: center; gap: 12px; width: 100%; background: none; border: 0; padding: 8px;
  border-radius: 12px; cursor: pointer; font: inherit; color: var(--ink); text-align: left;
}
.contact:hover, .contact:focus-visible { background: var(--paper-2); }
.contact .avatar { width: 38px; height: 38px; font-size: .85rem; }
.small-link { font-size: .95rem; text-decoration: none; margin-left: 6px; padding: 0 4px; }
.write-teacher { margin: -4px 0 16px; }

@media (prefers-color-scheme: dark) {
  .badge, .avatar:not(.cls), .send-btn { color: #10131c; }
  .msg.mine .bubble { background: #2c3a7a; color: #eef1ff; }
}

@media (max-width: 720px) {
  body[data-page=chats] .app { padding: 0 0 calc(70px + env(safe-area-inset-bottom)); }
  .chat-layout {
    grid-template-columns: 1fr; border-radius: 0; border: 0; box-shadow: none;
    height: calc(100vh - 56px - 70px - env(safe-area-inset-bottom));
  }
  .chat-layout.has-open .chat-side { display: none; }
  .chat-layout:not(.has-open) .chat-empty { display: none; }
  .chat-side { border-right: 0; }
  .back-btn { display: block; }
  .msg { max-width: 88%; }
  .msgs { padding: 12px; }
}
