:root {
  --bg: #f4f5fb;
  --card: #ffffff;
  --text: #1c1d2b;
  --muted: #6b6f85;
  --line: #e3e5ef;
  --accent: #4f46e5;
  --accent-soft: #eceafe;
  --mine: #4f46e5;
  --mine-text: #ffffff;
  --theirs: #ffffff;
  --danger: #c0392b;
  --note: #fff7e0;
  --radius: 14px;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12131c;
    --card: #1c1e2b;
    --text: #ececf3;
    --muted: #9a9db3;
    --line: #2c2f42;
    --accent: #8b84ff;
    --accent-soft: #2a2858;
    --mine: #5a52e8;
    --theirs: #232638;
    --danger: #ff7b6e;
    --note: #3a3220;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 18px; margin-top: 8px; }
h3 { font-size: 16px; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); margin: 0; }
.empty { color: var(--muted); text-align: center; padding: 32px 16px; }
.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.link { color: var(--accent); }
.quote { white-space: pre-wrap; background: var(--bg); padding: 8px 10px; border-radius: 8px; margin: 8px 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; white-space: nowrap; color: var(--text);
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 6px 10px; font-size: 14px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; }
.icon-btn {
  border: 0; background: none; font-size: 24px; line-height: 1; padding: 4px 8px;
  cursor: pointer; color: var(--accent); min-width: 40px; min-height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
}

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card.narrow { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.card.narrow p { margin: 0; }
.link-card { display: block; color: var(--text); }
.brand { font-size: 22px; color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 4px; }
.label { font-size: 13px; color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.span2 { grid-column: 1 / -1; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }

/* каркас: снизу меню на телефоне, слева — на широком экране */
.layout { min-height: 100vh; }
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px; font-size: 12px; color: var(--muted); position: relative;
}
.nav a.active { color: var(--accent); }
.nav-icon { font-size: 20px; line-height: 1; }
.nav .badge { position: absolute; top: 4px; left: calc(50% + 8px); }
.main { padding: 0 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); max-width: 1100px; margin: 0 auto; }
.top {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  display: flex; align-items: center; gap: 8px; padding: calc(12px + env(safe-area-inset-top)) 0 12px;
}
.top h1 { font-size: 20px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-actions { display: flex; gap: 8px; }

@media (min-width: 900px) {
  .nav {
    top: 0; right: auto; width: 200px; flex-direction: column; justify-content: flex-start;
    border-top: 0; border-right: 1px solid var(--line); padding: 16px 8px; gap: 4px;
  }
  .nav a { flex: none; flex-direction: row; gap: 10px; font-size: 15px; padding: 10px 12px; border-radius: 10px; }
  .nav a.active { background: var(--accent-soft); }
  .nav .badge { position: static; margin-left: auto; }
  .main { margin-left: 200px; padding-bottom: 24px; padding-left: 24px; padding-right: 24px; max-width: none; }
}

.badge {
  background: var(--accent); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 600;
  min-width: 18px; height: 18px; padding: 0 5px; display: inline-flex; align-items: center; justify-content: center;
}
.avatar {
  flex: none; width: 42px; height: 42px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 15px; color: #fff; background: #8a8fa8;
}
.role-owner, .role-admin { background: #4f46e5; }
.role-teacher { background: #0d9488; }
.role-student { background: #e67e22; }
.role-parent { background: #8e44ad; }
.role-family { background: var(--accent-soft); font-size: 20px; }

.tabs { display: flex; gap: 4px; overflow-x: auto; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }

.search { margin-bottom: 12px; }
.group { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 16px 0 6px; }
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list-item {
  display: flex; gap: 12px; align-items: center; padding: 12px 14px; width: 100%;
  border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; color: var(--text); cursor: pointer;
  flex-wrap: wrap;
}
.list-item:last-child { border-bottom: 0; }
a.list-item:hover, button.list-item:hover { background: var(--accent-soft); }
.list .line { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.time { font-size: 12px; color: var(--muted); flex: none; }
.item-actions { display: flex; gap: 6px; flex-wrap: wrap; }
@media (max-width: 600px) { .item-actions { width: 100%; padding-left: 54px; } }

/* чат */
.main.is-chat { padding-bottom: 0; }
.chat { display: flex; flex-direction: column; height: calc(100dvh - 64px - env(safe-area-inset-top) - var(--nav-h) - env(safe-area-inset-bottom)); }
@media (min-width: 900px) { .chat { height: calc(100dvh - 64px); } }
.chat-sub { margin: 0 0 6px; }
.messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 8px 0; }
.msg { max-width: min(80%, 560px); align-self: flex-start; background: var(--theirs); border: 1px solid var(--line); border-radius: 16px 16px 16px 4px; padding: 8px 12px; }
.msg.mine { align-self: flex-end; background: var(--mine); color: var(--mine-text); border-color: var(--mine); border-radius: 16px 16px 4px 16px; }
.msg.mine a { color: #fff; text-decoration: underline; }
.msg-name { font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-time { font-size: 11px; opacity: .65; text-align: right; margin-top: 2px; }
.more { align-self: center; }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 0 12px; }
.composer textarea { resize: none; max-height: 160px; border-radius: 20px; padding: 10px 16px; }
.composer .btn { border-radius: 50%; width: 44px; height: 44px; padding: 0; flex: none; }
.note.warn { background: #fde8e6; color: #8a1f14; }
@media (prefers-color-scheme: dark) { .note.warn { background: #4a2420; color: #ffd6d0; } }
.note { background: var(--note); border-radius: 10px; padding: 8px 12px; font-size: 14px; margin: 4px 0; }

/* список учеников: таблица на широком экране, карточки на телефоне */
.filters { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.filters .search { margin: 0; }
@media (max-width: 700px) { .filters { grid-template-columns: 1fr 1fr; } .filters .search { grid-column: 1 / -1; } }
.students { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.srow {
  display: grid; grid-template-columns: 1.4fr .5fr 1.6fr 1.8fr .8fr 1.1fr; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; color: var(--text); font-size: 14px;
}
a.srow:hover { border-color: var(--accent); }
.shead { background: none; border: 0; padding: 0 14px; color: var(--muted); font-size: 12px; }
@media (max-width: 900px) {
  .shead { display: none; }
  .srow { grid-template-columns: 1fr 1fr; }
  .srow .s-name { grid-column: 1 / -1; }
  .srow [data-label]::before { content: attr(data-label); display: block; font-size: 11px; color: var(--muted); }
}

/* окна и всплывашки */
.modal { border: 0; border-radius: var(--radius); padding: 16px; width: min(520px, calc(100vw - 32px)); background: var(--card); color: var(--text); }
.modal::backdrop { background: rgba(0, 0, 0, .4); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h2 { margin: 0; }
.modal p { margin: 0 0 12px; }
.modal textarea { margin-bottom: 12px; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: #1c1d2b; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  max-width: min(520px, calc(100vw - 32px)); opacity: 0; pointer-events: none; transition: .2s; z-index: 100;
}
#toast.show { opacity: 1; transform: translateX(-50%); }

/* вложения */
.msg-files { display: flex; flex-direction: column; gap: 6px; margin: 2px 0 4px; }
.att-img img { display: block; max-width: 100%; width: auto; height: auto; max-height: 320px; border-radius: 10px; background: var(--line); }
.att-doc {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px;
  background: var(--bg); color: var(--text); border: 1px solid var(--line); min-width: 0;
}
.msg.mine .att-doc { background: rgba(255,255,255,.15); color: #fff; border-color: rgba(255,255,255,.3); text-decoration: none; }
.att-icon { font-size: 22px; }
.att-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-size { font-size: 12px; opacity: .7; flex: none; }
.attach { font-size: 22px; flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 240px; padding: 4px 6px 4px 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px; font-size: 13px;
}
.chip img { width: 24px; height: 24px; object-fit: cover; border-radius: 6px; }
.chip.loading { opacity: .6; }
.chip-x { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 4px; font-size: 14px; }

/* сигнал о задержанных */
.badge.alert { background: #e53935; }
.nav .badge.alert { left: auto; right: 6px; }
@media (min-width: 900px) { .nav .badge.alert { margin-left: auto; } }
.alert-banner { display: block; font-weight: 600; margin-bottom: 12px; }
.alert-card { border-color: #e53935; box-shadow: 0 0 0 1px #e53935 inset; }
.link-card .badge { margin-left: 8px; }

/* меню из шести пунктов на телефоне: подписи в две строки с переносом */
.nav a span:not(.badge):not(.nav-icon) { hyphens: manual; text-align: center; line-height: 1.15; }
@media (max-width: 899px) { .nav a { font-size: 11px; padding: 6px 2px; min-width: 0; } }

.goal { margin-top: 2px; }
.pre { white-space: pre-wrap; }
.logo { width: 100%; height: auto; border-radius: 12px; }
.check-list { max-height: 50vh; overflow-y: auto; display: flex; flex-direction: column; margin-bottom: 12px; }
.check { display: flex; gap: 10px; align-items: center; padding: 8px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.check input { width: 20px; height: 20px; flex: none; }
.chat-group { margin-bottom: 8px; }
.chat-group .group a { color: inherit; }
.material .msg-files { max-width: 420px; }
.chat-group .list-item b.ellipsis { white-space: normal; }
.add-block > summary { list-style: none; display: inline-flex; margin-bottom: 8px; }
.add-block > summary::-webkit-details-marker { display: none; }

/* удаление сообщений */
.msg-time { display: flex; justify-content: flex-end; align-items: center; gap: 6px; }
.msg-more { border: 0; background: none; color: inherit; opacity: .55; cursor: pointer; font-size: 16px; line-height: 1; padding: 0 4px; }
.msg-more:hover { opacity: 1; }
@media (hover: hover) { .msg .msg-more { visibility: hidden; } .msg:hover .msg-more { visibility: visible; } }
.msg.deleted { opacity: .75; border-style: dashed; }
.msg.deleted .msg-body:not(.muted), .msg.deleted .msg-files { text-decoration: line-through; }
.msg.mine.deleted { background: var(--card); color: var(--text); border-color: var(--line); }
.msg-deleted-note { font-size: 12px; color: #c0392b; margin-top: 4px; }
.msg { -webkit-touch-callout: none; }

/* согласие */
.consent-card { max-width: 640px; width: 100%; display: flex; flex-direction: column; gap: 12px; }
.consent-card .brand { font-size: 20px; }
.consent-text { max-height: 50vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; font-size: 14px; background: var(--bg); }
.modal .consent-text { max-height: 65vh; }
.consent-text h3 { font-size: 15px; margin: 12px 0 4px; }
.consent-text p, .consent-text ul { margin: 4px 0; }
.consent-text ul { padding-left: 20px; }
.consent-check { border: 0; align-items: flex-start; font-size: 14px; }

/* библиотека по темам */
.topic h3 { font-size: 17px; }
.topic { display: flex; flex-direction: column; gap: 10px; }
.topic-section { border-top: 1px solid var(--line); padding-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.topic-item { display: flex; flex-direction: column; gap: 4px; }
.topic-item .att-img img { max-height: 220px; }
.topic-item .item-actions { padding-left: 0; }
.item-caption { font-size: 14px; font-weight: 600; }
.upload-row { border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.composer .attach { padding: 4px; min-width: 32px; }
.topic .item-actions { padding-left: 0; width: auto; }
.grade-boxes { display: flex; flex-wrap: wrap; gap: 6px; }
.grade-box { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; background: var(--card); }
.grade-box input { width: 18px; height: 18px; margin: 0; }
.grade-box:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

/* сообщение с темой из библиотеки: белое, без резкого фиолетового */
.msg.topic-msg, .msg.mine.topic-msg { background: #fff; color: #1c1d2b; border: 1px solid var(--line); box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.msg.topic-msg a { color: #2563eb; text-decoration: none; }
.msg.mine.topic-msg .att-doc { background: var(--bg); color: var(--text); border-color: var(--line); }
.msg.topic-msg .msg-time { color: var(--muted); opacity: 1; }
@media (prefers-color-scheme: dark) { .msg.topic-msg, .msg.mine.topic-msg { background: var(--card); color: var(--text); } .msg.topic-msg a { color: #8ab4ff; } }

/* пароль с кнопкой «Показать» */
.pw-wrap { position: relative; display: flex; }
.pw-wrap input { padding-right: 112px; font-size: 17px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: var(--accent-soft); color: var(--accent); border-radius: 8px; padding: 6px 10px; font-size: 13px; cursor: pointer; }
.login-box { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.login-box b { font-size: 17px; word-break: break-all; }

/* Переливающийся фон, как на only-positive.com (20.10.2026) */
body { background: transparent; }
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: linear-gradient(-45deg, #ff9a9e, #fad0c4, #fbc2eb, #a1c4fd, #c2e9fb, #a6c0fe, #8fd3f4, #84fab0, #fee140);
  background-size: 400% 400%;
  animation: op-gradient 15s ease infinite;
}
@keyframes op-gradient { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } }
@media (prefers-reduced-motion: reduce) { body::before { animation: none; } }
@media (prefers-color-scheme: dark) { body::before { filter: brightness(.35) saturate(.8); } }
.top { background: rgba(255,255,255,.55); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.nav { background: rgba(255,255,255,.8); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
@media (prefers-color-scheme: dark) { .top { background: rgba(18,19,28,.6); } .nav { background: rgba(28,30,43,.85); } }
@media (min-width: 900px) { .top { margin: 0 -24px; padding-left: 24px; padding-right: 24px; } }
.empty, .chat-sub, .group, .shead { text-shadow: 0 1px 0 rgba(255,255,255,.5); }
.filters select, .search { background: var(--card); }
