/* ─── BUTTONS ─── */
.btn-primary {
  padding: 8px 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none; border-radius: 8px; color: var(--on-accent);
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: opacity 0.2s, transform 0.1s; white-space: nowrap;
}
.btn-primary:hover { opacity: 0.88; }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

.btn-secondary {
  padding: 7px 14px; background: none; border: 1px solid var(--accent);
  border-radius: 8px; color: var(--accent-text); font-family: inherit;
  font-size: 13px; font-weight: 600; cursor: pointer; transition: all 0.2s; white-space: nowrap;
}
.btn-secondary:hover { background: rgba(var(--accent-rgb), 0.1); }
.btn-secondary:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-ghost {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  color: var(--text2); font-size: 13px; padding: 7px 13px; cursor: pointer;
  transition: all 0.2s; font-family: inherit; white-space: nowrap;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent-text); }
.btn-ghost:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-danger {
  background: none; border: 1px solid rgba(var(--red-rgb), 0.4); border-radius: 8px;
  color: var(--red); font-size: 13px; padding: 7px 13px; cursor: pointer;
  transition: all 0.2s; font-family: inherit; white-space: nowrap;
}
.btn-danger:hover { background: rgba(var(--red-rgb), 0.1); }

.btn-xs { padding: 4px 9px; font-size: 12px; }

/* ─── BADGES ─── */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 20px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-exam  { background: var(--badge-exam-bg);  color: var(--badge-exam-text);  border: 1px solid var(--badge-exam-border); }
.badge-level { background: var(--badge-level-bg); color: var(--badge-level-text); border: 1px solid var(--badge-level-border); }
.badge-role  { background: var(--badge-role-bg);  color: var(--badge-role-text);  border: 1px solid var(--badge-role-border); }
.badge-muted { background: var(--surface2); color: var(--text2); border: 1px solid var(--border); }
.badge-bad   { background: var(--danger-solid); color: var(--on-solid); border: 1px solid var(--danger-solid); cursor: help; }

/* ─── INPUTS ─── */
.input, .select, textarea.input {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 13px; color: var(--text);
  font-family: inherit; font-size: 13px; outline: none; transition: border-color 0.2s;
}
.input:focus, .select:focus, textarea.input:focus { border-color: var(--accent); }
textarea.input { resize: vertical; min-height: 64px; }
.select { cursor: pointer; appearance: none;
  background-image: var(--select-arrow);
  background-repeat: no-repeat; background-position: right 11px center; padding-right: 30px; }
.select option { background: var(--surface-raised); }
.select.am-list { height: auto; background-image: none; padding-right: 13px; }
.select.am-list option { padding: 6px 9px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--text2); margin-bottom: 6px; font-weight: 500; }

/* ─── FILTER BAR ─── */
.filter-bar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.filter-input-wrap { position: relative; flex: 1; min-width: 180px; }
.filter-input-wrap input {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 14px 9px 36px; color: var(--text);
  font-family: inherit; font-size: 13px; outline: none; transition: border-color 0.2s;
}
.filter-input-wrap input:focus { border-color: var(--accent); }
.filter-input-wrap::before { content: '🔍'; position: absolute; left: 11px; top: 50%; transform: translateY(-50%); font-size: 13px; pointer-events: none; }
.filter-count { font-size: 12px; color: var(--text3); white-space: nowrap; }
/* кнопку сворачивания фильтров добавляет ui.js, видна она только на телефоне */
.filter-toggle { display: none; align-items: center; gap: 6px; padding: 9px 12px; border-radius: 10px; }
.filter-toggle-n {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; display: none;
  align-items: center; justify-content: center; font-size: 11px; font-weight: 700;
  background: var(--accent); color: var(--on-accent);
}
.filter-toggle-n:not(:empty) { display: inline-flex; }
.btn-reset {
  background: none; border: 1px solid var(--border); border-radius: 10px;
  color: var(--text3); padding: 9px 14px; font-family: inherit; font-size: 13px;
  cursor: pointer; transition: all 0.2s; white-space: nowrap;
}
.btn-reset:hover { border-color: var(--red); color: var(--red); }

/* ─── TABLE ─── */
.data-table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; overflow-x: auto; box-shadow: var(--card-shadow); }
table.dtable { width: 100%; border-collapse: collapse; }
table.dtable thead tr { border-bottom: 1px solid var(--border); }
table.dtable th {
  padding: 12px 16px; text-align: left; font-size: 11px; font-weight: 600;
  color: var(--text3); text-transform: uppercase; letter-spacing: 0.6px; white-space: nowrap;
}
table.dtable th.sortable { cursor: pointer; user-select: none; transition: color 0.15s; }
table.dtable th.sortable:hover { color: var(--text2); }
table.dtable th.sortable.active { color: var(--accent-text); }
.sort-icon { margin-left: 4px; opacity: 0.35; font-size: 10px; }
th.sortable.active .sort-icon { opacity: 1; }
table.dtable tbody tr { border-bottom: 1px solid var(--border); transition: background 0.15s; }
table.dtable tbody tr:last-child { border-bottom: none; }
table.dtable tbody tr:hover { background: var(--surface2); }
table.dtable td { padding: 11px 16px; font-size: 14px; vertical-align: middle; }
.td-bold { font-weight: 600; }
.td-muted { color: var(--text2); }
.td-empty { color: var(--text3); font-style: italic; font-size: 12px; }
.td-link { color: var(--accent-text); cursor: pointer; }
.td-link:hover { text-decoration: underline; }

.action-cell { display: flex; gap: 8px; align-items: center; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }

/* ─── MODAL ─── */
#modal-root { position: fixed; inset: 0; z-index: 100; display: none; }
#modal-root.open { display: block; }
.modal-overlay { position: absolute; inset: 0; background: var(--overlay); backdrop-filter: blur(2px); }
.modal {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 560px; max-width: calc(100vw - 32px); max-height: calc(100vh - 60px);
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 24px 60px var(--shadow-strong);
}
.modal.wide { width: 880px; }
.modal.xwide { width: 1180px; }
.modal-head { display: flex; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 16px; font-weight: 700; }
.modal-close { margin-left: auto; background: none; border: none; color: var(--text3); font-size: 22px; cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ─── DIALOG LAYER (поверх модалок) ─── */
#dialog-root { position: fixed; inset: 0; z-index: 130; display: none; }
#dialog-root.open { display: block; }
.dlg-text { font-size: 14px; line-height: 1.65; color: var(--text); }
.dlg-list { margin: 12px 0 0; padding-left: 20px; font-size: 13px; line-height: 1.9; color: var(--text2); }
.dlg-list b { color: var(--text); }
.timer-hint { margin-top: 14px; font-size: 12px; color: var(--text3); text-align: center; }
.profile-sep { margin: 20px 0 14px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 14px; font-weight: 700; color: var(--text); }
.bulk-textarea { width: 100%; min-height: 150px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; line-height: 1.5; resize: vertical; }

/* ─── TOAST ─── */
#toast-root { position: fixed; bottom: 22px; right: 22px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 16px; font-size: 13px; color: var(--text); min-width: 220px; max-width: 360px;
  box-shadow: 0 8px 24px var(--shadow-medium); animation: toastIn 0.2s ease;
}
.toast.success { border-color: rgba(var(--green-rgb), 0.4); }
.toast.error { border-color: rgba(var(--red-rgb), 0.4); color: var(--toast-error-text); }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } }

/* ─── CHIPS / MULTISELECT ─── */
.chips { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--chip-bg); border: 1px solid var(--chip-border);
  color: var(--chip-text); border-radius: 14px; padding: 2px 4px 2px 9px; font-size: 12px;
}
.chip button { background: none; border: none; color: inherit; cursor: pointer; font-size: 13px; line-height: 1; opacity: 0.7; }
.chip button:hover { opacity: 1; }
/* персональный тег: основа цвета и оттенки текста приходят из students.js, для светлой темы см. theme.css */
.chip.tag-chip {
  background: rgba(var(--tag-rgb), .14); border-color: rgba(var(--tag-rgb), .48); color: var(--tag-text-dark);
}

.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 50;
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: 10px;
  padding: 6px; min-width: 180px; max-height: 240px; overflow-y: auto;
  box-shadow: 0 10px 30px var(--shadow-medium); display: none;
}
.dropdown-menu.open { display: block; }
.dropdown-opt { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: 7px; cursor: pointer; font-size: 13px; }
.dropdown-opt:hover { background: var(--menu-hover); }
.dropdown-opt input { accent-color: var(--accent); }


/* номер строки и ссылка на ученика в Umschool */
table.dtable th.th-num, table.dtable td.td-num { width: 46px; text-align: right; color: var(--text3); }
.id-link { color: var(--accent-text); text-decoration: none; }
.id-link:hover { text-decoration: underline; }

/* список тегов: лежит на body, поэтому его не обрезает прокручиваемая обёртка таблицы */
.tag-menu {
  position: fixed; z-index: 90; min-width: 200px; max-height: 320px; overflow-y: auto; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 32px var(--shadow-strong); display: flex; flex-direction: column; gap: 2px;
}
.tag-menu label {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px;
  border-radius: 7px; font-size: 13px; cursor: pointer;
}
.tag-menu label:hover { background: var(--surface2); }
.tag-menu .empty { padding: 8px; color: var(--text3); font-size: 12px; }
.tag-color-dot {
  width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto;
  box-shadow: 0 0 0 1px var(--tag-dot-ring);
}

/* управление персональными тегами куратора */
.tag-manager-create {
  display: grid; grid-template-columns: minmax(0, 1fr) 42px auto;
  gap: 10px; align-items: center;
}
.tag-manager-list { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.tag-manager-row {
  display: grid; grid-template-columns: 42px minmax(0, 1fr) auto auto auto;
  gap: 8px; align-items: center; padding: 9px;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 10px;
}
.tag-color-input {
  width: 42px; height: 38px; padding: 3px; display: flex; align-items: center;
  border: 1px solid var(--border); border-radius: 9px; background: var(--surface); cursor: pointer;
}
.tag-color-input input[type="color"] {
  width: 100%; height: 100%; padding: 0; border: 0; background: none; cursor: pointer;
}
.tag-color-input input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.tag-color-input input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 6px; }
.tag-color-input input[type="color"]::-moz-color-swatch { border: 0; border-radius: 6px; }
.tag-manager-empty { padding: 24px 0; }

@media (max-width: 720px) {
  .tag-manager-row { grid-template-columns: 42px minmax(0, 1fr) auto; }
  .tag-manager-row .badge { justify-self: center; }
  .tag-manager-row [data-save] { grid-column: 2; }
  .tag-manager-row [data-delete] { grid-column: 3; }
}

/* ─── ТЕЛЕФОН ─── */
@media (max-width: 640px) {
  /* текст полей от 16px: на меньшем iOS увеличивает страницу при фокусе */
  input:not([type="checkbox"]):not([type="radio"]):not([type="color"]), select, textarea { font-size: 16px !important; }

  .btn-xs { padding: 7px 12px; font-size: 13px; }
  .action-cell { flex-wrap: wrap; }
  .toolbar { gap: 8px; }

  /* фильтры: на виду поиск и кнопка, остальные поля раскрываются по ней */
  .filter-bar { gap: 8px; }
  /* основа ширины оставляет в строке место только кнопке «Фильтры», списки уходят ниже */
  .filter-input-wrap { flex: 1 1 calc(100% - 150px); min-width: 0; }
  .filter-toggle { display: inline-flex; }
  .filter-bar[data-filters="open"] .filter-toggle { border-color: var(--accent); color: var(--accent-text); }
  .filter-bar > .select { flex: 1 1 calc(50% - 4px); min-width: 0; }
  .filter-bar[data-filters="closed"] > .select,
  .filter-bar[data-filters="closed"] > .btn-reset { display: none; }
  .filter-count { flex-basis: 100%; }

  /* таблицы - карточками: первая ячейка заголовком, у остальных подпись из шапки (ставит ui.js) */
  .data-table-wrap { border-radius: 12px; }
  table.dtable, table.dtable tbody { display: block; }
  table.dtable thead { display: block; border-bottom: 1px solid var(--border); }
  table.dtable thead:not(:has(th.sortable)) { display: none; }
  /* из шапки остаётся только сортировка */
  table.dtable thead tr {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 10px 12px; border: 0;
  }
  table.dtable thead tr::before { content: 'Сортировка'; font-size: 12px; color: var(--text3); margin-right: 2px; }
  table.dtable thead th { display: none; }
  table.dtable thead th.sortable {
    display: inline-flex; align-items: center; padding: 6px 11px;
    border: 1px solid var(--border); border-radius: 15px;
    font-size: 12px; text-transform: none; letter-spacing: 0;
  }
  table.dtable thead th.sortable.active { border-color: var(--accent); background: rgba(var(--accent-rgb), .1); }
  table.dtable tbody tr { display: block; padding: 12px 14px; }
  table.dtable tbody tr:hover { background: none; }
  table.dtable tbody td {
    display: block; position: relative; padding: 4px 0 4px 112px; min-height: 24px;
    font-size: 13px; overflow-wrap: anywhere;
  }
  table.dtable tbody td::before {
    content: attr(data-label); position: absolute; left: 0; top: 6px; width: 104px;
    font-size: 12px; color: var(--text3); line-height: 1.3;
  }
  table.dtable tbody td:first-child, table.dtable tbody td[data-label=""] { padding-left: 0; }
  table.dtable tbody td:first-child::before, table.dtable tbody td[data-label=""]::before { display: none; }
  table.dtable tbody td:first-child { font-size: 15px; padding-bottom: 6px; }
  table.dtable tbody td[data-label=""] { padding-top: 8px; }

  /* модалки - листом снизу экрана */
  .modal, .modal.wide, .modal.xwide {
    top: auto; bottom: 0; left: 0; transform: none;
    width: 100%; max-width: 100%; max-height: calc(100dvh - 40px);
    border-radius: 16px 16px 0 0; border-bottom: 0; animation: sheetIn .2s ease;
  }
  .modal-head { padding: 12px 8px 12px 16px; }
  .modal-head h3 { min-width: 0; overflow-wrap: anywhere; }
  .modal-close { width: 40px; height: 40px; flex-shrink: 0; font-size: 26px; }
  .modal-body { padding: 16px; }
  .modal-foot { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
  .modal-foot > button { flex: 1; }

  #toast-root { top: 64px; bottom: auto; left: 12px; right: 12px; }
  .toast { min-width: 0; max-width: none; animation-name: toastDown; }

  .tag-menu label { padding: 10px 8px; }
  .dropdown-opt { padding: 10px; }
}
@keyframes sheetIn { from { transform: translateY(24px); opacity: 0; } }
@keyframes toastDown { from { opacity: 0; transform: translateY(-8px); } }
@media (prefers-reduced-motion: reduce) {
  .modal { animation: none; }
}

/* вход в Telegram по QR-коду */
.admin-tabs.tg-tabs { margin-bottom: 14px; }
.tg-qr {
  width: 216px; height: 216px; margin: 4px auto 8px; background: var(--qr-bg); border-radius: 12px;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.tg-qr svg { width: 100%; height: 100%; display: block; }
.tg-qr-stale { color: var(--qr-text); font-size: 14px; line-height: 1.4; padding: 0 18px; text-align: center; }
.tg-qr-note { text-align: center; font-size: 12px; color: var(--text2); margin-bottom: 10px; min-height: 16px; }
