/* ==========================================================================
   Админ-портал школ
   ========================================================================== */

.sp-wrap {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sp-loading,
.sp-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 200px;
  padding: 32px;
  text-align: center;
  color: var(--c-muted);
}
.sp-empty i { font-size: 2rem; color: var(--c-brand); }
.sp-empty h3 { margin: 4px 0 0; font-size: 1.05rem; color: var(--c-text); }
.sp-empty p { margin: 0; }

.sp-card {
  border: 1px solid var(--c-border);
  border-radius: 16px;
  background: var(--c-surface);
  padding: 16px 18px;
}
.sp-card__head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--c-border);
}
.sp-card__head i { color: var(--c-brand); }
.sp-card__head b { font-size: .95rem; color: var(--c-text); }
.sp-card__head small { margin-left: auto; font-size: .72rem; color: var(--c-muted); }

.sp-form { display: flex; flex-direction: column; gap: 13px; }
.sp-field { display: flex; flex-direction: column; gap: 6px; }
.sp-field span { font-size: .82rem; font-weight: 600; color: var(--c-text-2); }
.sp-field small { display: block; font-size: .7rem; font-weight: 400; color: var(--c-muted); }
.sp-field textarea {
  resize: vertical;
  min-height: 90px;
  padding: 10px 12px;
  border: 1px solid var(--c-border);
  border-radius: 10px;
  background: var(--c-surface);
  color: var(--c-text);
  font: inherit;
  font-size: .86rem;
  line-height: 1.5;
}

.sp-upload {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 14px;
}
.sp-input {
  padding: 9px 12px;
  border: 1px solid var(--c-border);
  border-radius: 10px;
  background: var(--c-surface);
  color: var(--c-text);
  font: inherit;
  font-size: .84rem;
}
#spFileTitle { flex: 1 1 260px; }

.sp-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  font: inherit;
  font-size: .84rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.sp-btn:disabled { opacity: .55; cursor: not-allowed; }
.sp-btn--primary { background: var(--c-brand); color: #fff; }
.sp-btn--primary:hover { background: var(--c-brand-2); }
.sp-btn--danger { background: transparent; color: var(--c-danger); border-color: rgba(220, 38, 38, .35); }
.sp-btn--danger:hover { background: rgba(220, 38, 38, .08); }

.sp-actions { display: flex; justify-content: flex-end; }

.sp-files { display: flex; flex-direction: column; gap: 8px; }
.sp-file {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--c-border);
  border-radius: 12px;
  background: var(--c-surface-2);
}
.sp-file > i { color: var(--c-brand); font-size: 1rem; }
.sp-file__body { flex: 1; min-width: 0; }
.sp-file__body b { display: block; font-size: .85rem; color: var(--c-text); }
.sp-file__body small { display: block; margin-top: 2px; font-size: .72rem; color: var(--c-muted); }
.sp-muted { color: var(--c-muted); font-size: .82rem; }

@media (max-width: 700px) {
  .sp-upload { flex-direction: column; align-items: stretch; }
}

/* ------------------------------------------------------- кабинет школ (админ) */
.sp-stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.sp-stat {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  border: 1px solid var(--c-border); border-radius: 13px; background: var(--c-surface);
}
.sp-stat i { font-size: 1rem; color: var(--c-brand); }
.sp-stat b { display: block; font-size: 1.2rem; color: var(--c-text); line-height: 1.1; }
.sp-stat span { display: block; font-size: .68rem; color: var(--c-muted); }
.sp-stat--danger b { color: var(--c-danger); }

.sp-table-wrap { border: 1px solid var(--c-border); border-radius: 12px; overflow: auto; }
.sp-table { width: 100%; border-collapse: collapse; font-size: .8rem; }
.sp-table th {
  background: var(--c-surface-2); color: var(--c-muted); font-size: .66rem; text-transform: uppercase;
  letter-spacing: .05em; padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--c-border); white-space: nowrap;
}
.sp-table td { padding: 9px 10px; border-bottom: 1px solid var(--c-border); color: var(--c-text-2); vertical-align: top; }
.sp-table tr:last-child td { border-bottom: none; }
.sp-table td b { display: block; color: var(--c-text); font-size: .8rem; }
.sp-table td small { display: block; margin-top: 1px; font-size: .68rem; color: var(--c-muted); }
.sp-table code { font-size: .72rem; background: var(--c-surface-2); padding: 2px 5px; border-radius: 5px; }
.sp-empty-cell { text-align: center; color: var(--c-muted); padding: 20px !important; }

.sp-badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; font-size: .66rem; font-weight: 700; background: var(--c-brand-soft); color: var(--c-brand); }
.sp-badge--danger { background: var(--c-danger); color: #fff; }

.sp-chat-preview { display: flex; flex-direction: column; gap: 6px; }
.sp-thread {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px;
  border: 1px solid var(--c-border); border-radius: 10px; background: var(--c-surface-2);
  text-align: left; cursor: pointer; font: inherit;
}
.sp-thread:hover { background: var(--c-brand-soft); }
.sp-thread__icon { display: grid; place-items: center; width: 32px; height: 32px; flex: 0 0 32px; border-radius: 9px; background: var(--c-surface); color: var(--c-brand); }
.sp-thread__body { flex: 1; min-width: 0; }
.sp-thread__body b { display: block; font-size: .8rem; color: var(--c-text); }
.sp-thread__body small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .7rem; color: var(--c-muted); }

/* ---------------------------------------------------------- чат школ (админ) */
.sch-wrap { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 14px; height: calc(100vh - 150px); min-height: 480px; }
.sch-list { display: flex; flex-direction: column; border: 1px solid var(--c-border); border-radius: 14px; background: var(--c-surface); overflow: hidden; }
.sch-list__head { display: flex; align-items: center; gap: 8px; padding: 11px 12px; border-bottom: 1px solid var(--c-border); }
.sch-list__head i { color: var(--c-brand); }
.sch-list__head b { flex: 1; font-size: .86rem; color: var(--c-text); }
.sch-list__body { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 5px; }
.sch-thread {
  display: flex; align-items: center; gap: 9px; width: 100%; padding: 8px;
  border: 1px solid transparent; border-radius: 10px; background: transparent;
  text-align: left; cursor: pointer; font: inherit;
}
.sch-thread:hover { background: var(--c-surface-2); }
.sch-thread.is-active { background: var(--c-brand-soft); border-color: rgba(37, 99, 235, .25); }
.sch-thread__avatar { display: grid; place-items: center; width: 34px; height: 34px; flex: 0 0 34px; border-radius: 50%; background: var(--c-brand-soft); color: var(--c-brand); font-weight: 800; font-size: .8rem; }
.sch-thread__body { flex: 1; min-width: 0; }
.sch-thread__body b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .78rem; color: var(--c-text); }
.sch-thread__body small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .68rem; color: var(--c-muted); }
.sch-thread__meta { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; flex: 0 0 auto; }
.sch-thread__meta small { font-size: .6rem; color: var(--c-muted); }
.sch-chat { display: flex; flex-direction: column; border: 1px solid var(--c-border); border-radius: 14px; background: var(--c-surface); overflow: hidden; }
.sch-chat__head { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--c-border); }
.sch-chat__head > div { flex: 1; min-width: 0; }
.sch-chat__head b { display: block; font-size: .9rem; color: var(--c-text); }
.sch-chat__head small { display: block; margin-top: 1px; font-size: .7rem; color: var(--c-muted); }
.sch-chat__messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; background: var(--c-surface-2); }
.sch-chat__empty { margin: auto; text-align: center; color: var(--c-muted); }
.sch-chat__empty i { font-size: 1.6rem; color: var(--c-brand); }
.sch-msg { display: flex; flex-direction: column; max-width: 72%; }
.sch-msg--admin { align-self: flex-end; align-items: flex-end; }
.sch-msg--school { align-self: flex-start; align-items: flex-start; }
.sch-msg__bubble { padding: 9px 12px; border-radius: 12px; font-size: .84rem; line-height: 1.45; overflow-wrap: anywhere; }
.sch-msg--admin .sch-msg__bubble { background: var(--c-brand); color: #fff; border-bottom-right-radius: 4px; }
.sch-msg--school .sch-msg__bubble { background: var(--c-surface); border: 1px solid var(--c-border); color: var(--c-text); border-bottom-left-radius: 4px; }
.sch-msg__meta { margin-top: 3px; font-size: .6rem; color: var(--c-muted); }
.sch-chat__form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--c-border); }
.sch-chat__form textarea { flex: 1; resize: none; padding: 9px 11px; border: 1px solid var(--c-border); border-radius: 10px; background: var(--c-surface); color: var(--c-text); font: inherit; font-size: .84rem; }

@media (max-width: 900px) {
  .sp-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sch-wrap { grid-template-columns: 1fr; height: auto; }
  .sch-list { max-height: 240px; }
  .sch-chat { min-height: 420px; }
}

.nav-badge {
  margin-left: auto;
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: .6rem;
  font-weight: 700;
  line-height: 1;
}
.nav-badge[hidden] { display: none !important; }

/* ---------------------------------------------------- rich-редактор настроек */
.sp-field--rich { gap: 5px; }
.sp-rich-toolbar { display: flex; gap: 6px; align-items: center; }
.sp-rich-toolbar button {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 30px; height: 28px; padding: 0 8px;
  border: 1px solid var(--c-border); border-radius: 7px;
  background: var(--c-surface); color: var(--c-text-2);
  font: inherit; font-size: .76rem; cursor: pointer;
}
.sp-rich-toolbar button:hover { background: var(--c-surface-2); color: var(--c-text); }
.sp-rich-toolbar button b { font-size: .9rem; }
.sp-rich {
  min-height: 110px;
  max-height: 280px;
  overflow-y: auto;
  padding: 10px 12px;
  border: 1px solid var(--c-border);
  border-radius: 10px;
  background: var(--c-surface);
  color: var(--c-text);
  font-size: .86rem;
  line-height: 1.55;
  outline: none;
}
.sp-rich:focus { border-color: var(--c-brand); box-shadow: 0 0 0 3px var(--c-brand-soft); }
.sp-rich:empty::before { content: attr(data-placeholder); color: var(--c-muted); pointer-events: none; }
.sp-rich p { margin: 0 0 6px; }
.sp-rich p:last-child { margin-bottom: 0; }
/* Чат школ — уже и по центру страницы */
.sch-wrap {
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  grid-template-columns: 300px minmax(0, 1fr);
}
@media (max-width: 900px) {
  .sch-wrap { grid-template-columns: 1fr; max-width: 100%; }
  .sc-chat { max-width: 100%; }
}

/* ===================================================== Кабинет школ (редизайн) */
.sp-admin { max-width: 1280px; margin: 0 auto; }
.sp-hero {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 18px 20px;
  border: 1px solid var(--c-border); border-radius: 16px;
  background: linear-gradient(120deg, var(--c-brand-soft), var(--c-surface) 70%);
}
.sp-hero__text { min-width: 0; }
.sp-eyebrow {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: .68rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--c-brand);
}
.sp-eyebrow i { font-size: .7rem; }
.sp-hero h2 { margin: 4px 0 2px; font-size: 1.35rem; color: var(--c-text); }
.sp-hero p { margin: 0; font-size: .8rem; color: var(--c-muted); }
.sp-hero__actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.sp-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.sp-tab {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 14px; border: 1px solid var(--c-border); border-radius: 999px;
  background: var(--c-surface); color: var(--c-text-2); font: inherit; font-size: .8rem; font-weight: 600;
  cursor: pointer; transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.sp-tab:hover { background: var(--c-surface-2); }
.sp-tab.is-active { background: var(--c-brand); color: #fff; border-color: var(--c-brand); }

.sp-overview-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.sp-action-card { display: flex; flex-direction: column; gap: 10px; }
.sp-card__icon {
  display: grid; place-items: center; width: 38px; height: 38px;
  border-radius: 10px; background: var(--c-brand-soft); color: var(--c-brand); font-size: .95rem;
}
.sp-card__body { flex: 1; min-width: 0; }
.sp-card__body h3 { margin: 0; font-size: .9rem; color: var(--c-text); }
.sp-card__body p { margin: 3px 0 0; font-size: .74rem; line-height: 1.4; color: var(--c-muted); }
.sp-preview-line {
  margin-top: 6px; padding: 6px 8px; border-radius: 7px;
  background: var(--c-surface-2); color: var(--c-text-2); font-size: .7rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.sp-overview-columns { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 12px; }
.sp-thread-list { display: flex; flex-direction: column; gap: 6px; }
.sp-mini-schools { display: flex; flex-direction: column; gap: 5px; }
.sp-mini-school { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 9px; border-radius: 8px; background: var(--c-surface-2); }
.sp-mini-school b { font-size: .76rem; color: var(--c-text); font-weight: 600; }
.sp-mini-school small { font-size: .66rem; color: var(--c-muted); }

.sp-settings { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(300px, .8fr); gap: 13px; align-items: start; }
.sp-settings__main { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.sp-settings__grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.sp-settings__grid .sp-card:last-child { grid-column: 1 / -1; }
.sp-settings__side { display: flex; flex-direction: column; gap: 12px; position: sticky; top: 12px; }
.sp-settings__save { display: flex; flex-direction: column; gap: 8px; }
.sp-school-preview { border: 1px solid var(--c-border); border-radius: 12px; overflow: hidden; background: var(--c-surface-2); }
.sp-school-preview__label { padding: 7px 11px; font-size: .64rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--c-muted); background: var(--c-surface); border-bottom: 1px solid var(--c-border); }
.sp-school-preview__info { padding: 11px; background: rgba(37, 99, 235, .06); font-size: .78rem; line-height: 1.5; color: var(--c-text); min-height: 70px; }
.sp-school-preview__info p { margin: 0 0 5px; }
.sp-school-preview__text { padding: 11px; font-size: .76rem; line-height: 1.5; color: var(--c-text-2); max-height: 180px; overflow-y: auto; }
.sp-school-preview__text p { margin: 0 0 5px; }

.sp-schools-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.sp-search { display: flex; align-items: center; gap: 7px; flex: 1 1 280px; padding: 0 11px; border: 1px solid var(--c-border); border-radius: 10px; background: var(--c-surface); }
.sp-search i { color: var(--c-muted); font-size: .8rem; }
.sp-search input { flex: 1; min-width: 0; padding: 9px 0; border: none; background: transparent; color: var(--c-text); font: inherit; font-size: .82rem; outline: none; }
.sp-files-groups { display: flex; flex-direction: column; gap: 12px; }

.sp-btn--sm { padding: 6px 10px; font-size: .74rem; }
.sp-history-modal { max-width: 660px; }
.sp-history-list { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow-y: auto; padding: 2px; }
.sp-history-item { display: flex; gap: 10px; padding: 9px 10px; border: 1px solid var(--c-border); border-radius: 10px; background: var(--c-surface-2); }
.sp-history-item__dot { width: 8px; height: 8px; margin-top: 5px; border-radius: 50%; background: var(--c-brand); flex: 0 0 8px; }
.sp-history-item__dot--delete { background: var(--c-danger); }
.sp-history-item__dot--create { background: var(--c-success); }
.sp-history-item__body { flex: 1; min-width: 0; }
.sp-history-item__top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sp-history-item__top b { font-size: .76rem; color: var(--c-text); }
.sp-history-item__top span { font-size: .64rem; color: var(--c-muted); }
.sp-history-item p { margin: 3px 0; font-size: .78rem; line-height: 1.4; color: var(--c-text-2); }
.sp-history-item small { font-size: .64rem; color: var(--c-muted); }

@media (max-width: 1150px) {
  .sp-overview-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sp-settings { grid-template-columns: 1fr; }
  .sp-settings__side { position: static; }
}
@media (max-width: 800px) {
  .sp-overview-grid, .sp-settings__grid { grid-template-columns: 1fr; }
  .sp-overview-columns { grid-template-columns: 1fr; }
  .sp-settings__grid .sp-card:last-child { grid-column: auto; }
  .sp-hero { align-items: stretch; flex-direction: column; }
}

/* ------------------------------------------- таблица школ: действия и формы */
.sp-row-actions { display: flex; align-items: center; gap: 4px; }
.sp-icon-btn {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px;
  border: 1px solid var(--c-border); border-radius: 8px;
  background: var(--c-surface); color: var(--c-text-2);
  cursor: pointer; font-size: .72rem;
}
.sp-icon-btn:hover { background: var(--c-surface-2); color: var(--c-text); }

.sp-school-edit-modal { max-width: 760px; }
.sp-school-edit { display: flex; flex-direction: column; gap: 12px; }
.sp-edit-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.sp-field--wide { grid-column: 1 / -1; }
.sp-field input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--c-border);
  border-radius: 10px;
  background: var(--c-surface);
  color: var(--c-text);
  font: inherit;
  font-size: .84rem;
}
.sp-field input:focus { outline: none; border-color: var(--c-brand); box-shadow: 0 0 0 3px var(--c-brand-soft); }
.sp-field em { color: var(--c-danger); font-style: normal; }
.sp-form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.sp-alert { padding: 9px 12px; border-radius: 9px; background: rgba(220, 38, 38, .09); color: var(--c-danger); font-size: .8rem; }

.sp-list-group { margin-bottom: 12px; border: 1px solid var(--c-border); border-radius: 11px; overflow: hidden; }
.sp-list-group__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 11px; background: var(--c-surface-2); border-bottom: 1px solid var(--c-border); }
.sp-list-group__head b { font-size: .78rem; color: var(--c-text); }
.sp-list-group__head small { font-size: .68rem; color: var(--c-muted); }
.sp-file--link { text-decoration: none; color: inherit; border-radius: 0; border: none; border-bottom: 1px solid var(--c-border); background: var(--c-surface); }
.sp-file--link:last-child { border-bottom: none; }
.sp-file--link:hover { background: var(--c-brand-soft); }

@media (max-width: 700px) {
  .sp-edit-grid { grid-template-columns: 1fr; }
}

/* Админ-панель: подсказки к шаблонам и файлы школы */
.sp-textarea { min-height: 58px; resize: vertical; font-family: inherit; }
.sp-file__hint { display: block; margin-top: 3px; color: var(--c-muted); font-size: .68rem; line-height: 1.35; }
.sp-files-title { margin: 14px 4px 8px; font-size: .86rem; color: var(--c-text); display: flex; align-items: center; gap: 7px; }
.sp-hint-modal { max-width: 560px; }
.sp-hint-modal .sp-form-actions { margin-top: 12px; display: flex; justify-content: flex-end; gap: 8px; }
.sp-upload .sp-textarea { flex: 1 1 100%; width: 100%; }
