.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: #2c3e50;
  color: #fff;
}
.app-header h1 { margin: 0; font-size: 18px; font-weight: 600; }
.header-actions { display: flex; gap: 8px; }

.btn {
  padding: 6px 12px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: #3498db;
  color: #fff;
  cursor: pointer;
  font-size: 13px;
}
.btn:hover { background: #2980b9; }
.btn-secondary { background: #7f8c8d; }
.btn-secondary:hover { background: #6b7a7b; }
.btn-danger { background: #e74c3c; }
.btn-danger:hover { background: #c0392b; }
.btn-sm { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 16px;
  background: #ecf0f1;
  border-bottom: 1px solid #d0d7de;
}
.tab {
  padding: 6px 12px;
  border: 1px solid #bdc3c7;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
}
.tab.active { background: #3498db; color: #fff; border-color: #2980b9; }

.main { padding: 16px; }

/* ---------- Шаблон сетки ---------- */
.panel {
  background: #fff;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  padding: 14px;
  margin-bottom: 16px;
}
.panel h2 { margin: 0 0 10px; font-size: 15px; }
.panel .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.panel .hint { color: #7f8c8d; font-size: 12px; }

.template-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.template-table th, .template-table td {
  border: 1px solid #d0d7de;
  padding: 4px 6px;
  text-align: left;
}
.template-table th { background: #f0f3f6; font-weight: 600; font-size: 12px; }
.template-table input, .template-table select {
  width: 100%;
  padding: 4px;
  border: 1px solid #ccc;
  border-radius: 3px;
  font: inherit;
}

/* ---------- 7 колонок дней ---------- */
.days-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(180px, 1fr));
  gap: 10px;
  overflow-x: auto;
}
.day-col {
  border: 1px solid #d0d7de;
  border-radius: 6px;
  background: #fff;
  display: flex;
  flex-direction: column;
  min-height: 200px;
}
.day-col.drop-target { outline: 2px dashed #3498db; outline-offset: 2px; }
.day-col.dragging { opacity: .45; }

.day-header {
  display: flex;
  flex-wrap: wrap;              /* разрешаем перенос на вторую строку */
  align-items: center;
  justify-content: space-between;
  gap: 6px;                     /* отступ между названием и кнопками */
  padding: 8px 10px;
  background: #f0f3f6;
  border-bottom: 1px solid #d0d7de;
  font-weight: 600;
  font-size: 13px;
  cursor: grab;
  user-select: none;
}
.day-header:active { cursor: grabbing; }

.day-header > span:first-child {
  /* название дня */
  flex: 0 0 auto;
  white-space: nowrap;
}

.day-header .day-actions {
  display: flex;
  flex-wrap: wrap;              /* кнопки тоже могут переноситься */
  gap: 4px;
  justify-content: flex-end;
  flex: 1 1 auto;               /* занимают оставшееся место */
  min-width: 0;
}

.day-body { padding: 6px 8px; flex: 1; }
.slot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 5px 8px;
  margin-bottom: 5px;
  border-radius: 4px;
  border: 1px solid #e1e4e8;
  background: #fafbfc;
  font-size: 12px;
}
.slot.slot-lesson  { border-left: 3px solid #3498db; }
.slot.slot-break   { border-left: 3px solid #f1c40f; background: #fffbe6; }
.slot.slot-lunch   { border-left: 3px solid #e67e22; background: #fff3e0; }
.slot .slot-num { font-weight: 600; }
.slot .slot-time { color: #555; }
.slot .slot-type {
  font-size: 10px;
  text-transform: uppercase;
  color: #7f8c8d;
  letter-spacing: .5px;
}
.day-empty { color: #aaa; font-size: 12px; padding: 8px 0; text-align: center; }

/* ---------- Заглушка ---------- */
.placeholder {
  background: #fff;
  border: 1px dashed #bdc3c7;
  border-radius: 6px;
  padding: 40px;
  text-align: center;
  color: #7f8c8d;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #2c3e50;
  color: #fff;
  padding: 10px 16px;
  border-radius: 4px;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .2s, transform .2s;
  z-index: 1000;
  font-size: 13px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #c0392b; }
/* ---- Режим редактирования структуры дня ---- */
.day-edit { padding: 6px 8px; }
.day-edit .edit-row {
  display: grid;
  grid-template-columns: 38px 1fr 70px 70px 26px;
  gap: 4px;
  align-items: center;
  margin-bottom: 4px;
}
.day-edit .edit-row input,
.day-edit .edit-row select {
  padding: 3px;
  border: 1px solid #ccc;
  border-radius: 3px;
  font: inherit;
  font-size: 12px;
  min-width: 0;
}
.day-edit .edit-row .btn { padding: 1px 6px; font-size: 12px; }
.day-edit .edit-footer {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.day-targets { display: flex; flex-wrap: wrap; gap: 10px; }
.day-targets .chk { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; }
/* ---------- Раздел «Аудитории» ---------- */
.rooms-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
  align-items: start;
}
.rooms-list-panel { min-width: 0; }
.rooms-detail-panel { min-width: 0; }

.room-item {
  padding: 8px 10px;
  border: 1px solid #e1e4e8;
  border-radius: 4px;
  margin-bottom: 6px;
  cursor: pointer;
  background: #fff;
}
.room-item:hover { background: #fafbfc; }
.room-item.active { border-color: #3498db; background: #eef6fd; }
.room-name { font-weight: 600; font-size: 13px; }
.room-desc  { font-size: 12px; color: #7f8c8d; margin-top: 2px; }

/* ---------- Занятость ---------- */
.busy-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(120px, 1fr));
  gap: 6px;
  overflow-x: auto;
  margin-top: 8px;
}
.busy-col {
  border: 1px solid #e1e4e8;
  border-radius: 4px;
  padding: 6px;
  background: #fafbfc;
  min-width: 0;
}
.busy-col-title { font-weight: 600; font-size: 12px; margin-bottom: 4px; text-align: center; }
.busy-slot {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 5px;
  margin-bottom: 3px;
  border-radius: 3px;
  border: 1px solid #e1e4e8;
  background: #fff;
  font-size: 11px;
  cursor: pointer;
  user-select: none;
}
.busy-slot.busy { background: #fdecea; border-color: #e74c3c; color: #c0392b; }
.busy-slot.type-break { border-left: 3px solid #f1c40f; }
.busy-slot.type-lunch { border-left: 3px solid #e67e22; }
.busy-slot .busy-num { font-weight: 600; }
.busy-slot input { margin: 0; }

/* ---------- Белые списки ---------- */
.whitelist-block { margin-bottom: 12px; }
.whitelist-title { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.whitelist-block input[type="text"] {
  padding: 4px 6px; border: 1px solid #ccc; border-radius: 3px;
  font: inherit; font-size: 12px; flex: 1;
}
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px 2px 8px;
  background: #eef6fd;
  border: 1px solid #b6d7f3;
  border-radius: 12px;
  font-size: 12px;
}
.tag-remove {
  border: none; background: transparent; cursor: pointer;
  font-size: 14px; line-height: 1; color: #3498db;
}
.tag-remove:hover { color: #c0392b; }

/* ---------- Модалка ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000;
}
.modal {
  background: #fff;
  border-radius: 6px;
  padding: 16px 18px;
  min-width: 360px;
  max-width: 520px;
  box-shadow: 0 8px 30px rgba(0,0,0,.2);
}
.form-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.form-row label { font-size: 12px; color: #555; }
.form-row input, .form-row textarea {
  padding: 6px 8px; border: 1px solid #ccc; border-radius: 4px; font: inherit; font-size: 13px;
}
.whitelist-block select {
  padding: 4px 6px;
  border: 1px solid #ccc;
  border-radius: 3px;
  font: inherit;
  font-size: 12px;
  max-width: 320px;
  flex: 1;
}
.modal input[type="number"] {
  padding: 4px 6px;
  border: 1px solid #ccc;
  border-radius: 3px;
  font: inherit;
  width: 100%;
}
.stream-groups-list {
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 2px;
}
.stream-group-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px;
  border-radius: 3px;
  font-size: 13px;
  cursor: pointer;
}
.stream-group-row:hover { background: #f5f9ff; }
.stream-group-row input { margin: 0; }
/* ---------- Сетка расписания ---------- */
.schedule-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(180px, 1fr));
  gap: 8px;
  overflow-x: auto;
}
.schedule-day {
  border: 1px solid #d0d7de;
  border-radius: 6px;
  background: #fff;
}
.schedule-day-title {
  padding: 6px 8px;
  background: #f0f3f6;
  border-bottom: 1px solid #d0d7de;
  font-weight: 600;
  font-size: 12px;
  text-align: center;
}
.schedule-day-body { padding: 6px; }

.lesson-card {
  padding: 6px 8px;
  border-radius: 4px;
  border-left: 3px solid #3498db;
  background: #eef6fd;
  margin-bottom: 5px;
  font-size: 12px;
  cursor: grab;
}
.lesson-card:active { cursor: grabbing; }
.lesson-time { color: #555; font-size: 11px; }
.lesson-subj { font-weight: 600; color: #1d4d75; margin: 2px 0; }
.lesson-meta { color: #555; font-size: 11px; }

.lesson-empty {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 4px;
  border: 1px dashed #cfd8e3;
  border-radius: 4px;
  margin-bottom: 5px;
  background: #fbfcfe;
}
.lesson-empty .lesson-empty-info { font-size: 11px; color: #99a; }

/* Modal form controls (повтор для расписания) */
.modal select, .modal input[type="number"], .modal input[type="text"] {
  padding: 5px 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font: inherit;
  font-size: 13px;
  width: 100%;
}
/* Drag&drop карточек занятий */
.lesson-card {
  position: relative;
  transition: box-shadow .15s, transform .15s;
}
.lesson-card.dragging { opacity: .5; }
.lesson-card:hover { box-shadow: 0 2px 8px rgba(52,152,219,.25); }

.lesson-actions {
  position: absolute;
  top: 3px;
  right: 3px;
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity .15s;
}
.lesson-card:hover .lesson-actions { opacity: 1; }
.btn-icon {
  border: none;
  background: rgba(255,255,255,.9);
  border-radius: 3px;
  padding: 1px 5px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1.2;
  color: #555;
}
.btn-icon:hover { background: #fff; color: #c0392b; }

/* Подсветка зоны дропа */
[data-drop-slot].drop-target {
  outline: 2px dashed #3498db;
  outline-offset: 2px;
  background: #eef6fd;
}

.guide { max-width: 920px; margin: 0 auto; padding: 20px; }
.guide h1 { margin-top: 0; }
.guide h2 {
  margin-top: 32px;
  padding-bottom: 6px;
  border-bottom: 2px solid #3498db;
  color: #2c3e50;
}
.guide h3 { margin-top: 20px; color: #34495e; }
.guide p, .guide li { line-height: 1.65; }
.guide code, .guide kbd {
  background: #f0f3f6;
  border: 1px solid #d0d7de;
  border-radius: 3px;
  padding: 1px 5px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12.5px;
}
.guide .note {
  background: #fffbe6;
  border-left: 4px solid #f1c40f;
  padding: 10px 14px;
  border-radius: 4px;
  margin: 12px 0;
}
.guide .tip {
  background: #eef6fd;
  border-left: 4px solid #3498db;
  padding: 10px 14px;
  border-radius: 4px;
  margin: 12px 0;
}
.guide .toc {
  background: #f7f9fb;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  padding: 12px 18px;
}
.guide .toc ol { margin: 6px 0 0; padding-left: 22px; }
.guide .toc a { color: #2c3e50; text-decoration: none; }
.guide .toc a:hover { color: #3498db; text-decoration: underline; }
.guide table { border-collapse: collapse; width: 100%; margin: 10px 0; }
.guide th, .guide td {
  border: 1px solid #d0d7de;
  padding: 6px 10px;
  text-align: left;
  vertical-align: top;
}
.guide th { background: #f0f3f6; font-weight: 600; }
.guide ol.steps { padding-left: 22px; }
.guide ol.steps > li { margin-bottom: 8px; }
.guide .back {
  display: inline-block;
  margin-top: 24px;
  color: #3498db;
  text-decoration: none;
  font-weight: 600;
}
.guide .back:hover { text-decoration: underline; }