:root {
  --bg: #f3f6fb;
  --panel: #ffffff;
  --line: #d8e1ef;
  --text: #13213a;
  --muted: #5b6d87;
  --primary: #0f5dd9;
  --primary-soft: #e8f0ff;
  --ok-bg: #dff3e6;
  --ok-text: #1a693a;
  --warn-bg: #fff2d7;
  --warn-text: #7a4a00;
  --error-bg: #ffe2e2;
  --error-text: #7a2222;
  --ghost-bg: #eef3ff;
  --ghost-text: #1d3560;
  --table-row-alt: #f8fbff;
}

body.theme-dark {
  --bg: #0e1420;
  --panel: #151f2f;
  --line: #2a3954;
  --text: #dbe6ff;
  --muted: #9db0d1;
  --primary: #6ea8ff;
  --primary-soft: #243654;
  --ok-bg: #173a2a;
  --ok-text: #9de5b8;
  --warn-bg: #4c3b1d;
  --warn-text: #ffd89a;
  --error-bg: #4a2020;
  --error-text: #ffb8b8;
  --ghost-bg: #243654;
  --ghost-text: #dbe6ff;
  --table-row-alt: #1a2639;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Inter", system-ui, -apple-system, Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 500px at 80% -100px, #dfe9ff 0%, var(--bg) 55%);
}

body.theme-dark {
  background: radial-gradient(1200px 500px at 80% -100px, #142947 0%, var(--bg) 55%);
}

a {
  color: var(--primary);
  text-decoration: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--panel) 90%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1220px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.topbar-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  row-gap: 8px;
}

.top-session-user {
  font-size: 13px;
  color: var(--muted);
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-auth-btn {
  padding: 6px 10px;
}

.top-link {
  color: var(--text);
  padding: 6px 10px;
  border-radius: 8px;
}

.top-link:hover {
  background: color-mix(in srgb, var(--primary-soft) 80%, transparent);
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--primary) 70%, #fff 30%);
  outline-offset: 2px;
}

.top-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.lang-toggle {
  display: inline-flex;
  gap: 6px;
}

.lang-btn {
  min-width: 44px;
  padding: 6px 10px;
}

.lang-btn.active {
  background: var(--primary);
  color: #fff;
}

.theme-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}

.theme-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.theme-slider {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 78%, var(--primary-soft) 22%);
  transition: background 0.2s ease;
}

.theme-slider::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s ease;
}

.theme-switch input:checked + .theme-slider::after {
  transform: translateX(20px);
}

.theme-icon {
  font-size: 14px;
  line-height: 1;
}

.layout {
  max-width: 1220px;
  margin: 16px auto;
  padding: 0 16px 20px;
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(16, 46, 92, 0.07);
}

.sidebar {
  padding: 14px;
  align-self: start;
  position: sticky;
  top: 66px;
  max-height: calc(100vh - 84px);
  overflow: auto;
}

.content {
  padding: 16px;
  min-height: 60vh;
}

.section-title {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #425b7f;
  text-transform: uppercase;
}

.field {
  margin-bottom: 10px;
}

.field.compact {
  margin-bottom: 6px;
}

.field.compact:last-child {
  margin-bottom: 0;
}

label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--muted);
}

input,
textarea,
select,
button {
  font: inherit;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: color-mix(in srgb, var(--panel) 96%, #fff 4%);
  padding: 9px 11px;
  color: var(--text);
}

textarea {
  resize: vertical;
  min-height: 76px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.actions .route-link {
  width: auto;
  display: inline-flex;
  align-items: center;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 600;
  background: var(--primary);
  color: #fff;
}

button.secondary {
  background: #2e3f5f;
}

button.ghost {
  background: var(--ghost-bg);
  color: var(--ghost-text);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.status {
  margin-top: 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 10px 12px;
  font-size: 13px;
  white-space: pre-wrap;
}

.status.ok {
  background: var(--ok-bg);
  color: var(--ok-text);
  border-color: #b7e2c7;
}

.status.warn {
  background: var(--warn-bg);
  color: var(--warn-text);
  border-color: #eed7a5;
}

.status.error {
  background: var(--error-bg);
  color: var(--error-text);
  border-color: #f0bcbc;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.route-links {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  align-content: start;
}

.access-box {
  border: 1px solid #dbe5f5;
  border-radius: 10px;
  background: #f8fbff;
  padding: 8px 10px;
  font-size: 13px;
}

.access-box.warn {
  background: var(--warn-bg);
  border-color: #eed7a5;
  color: var(--warn-text);
}

.access-courses {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.route-link {
  display: block;
  border: 1px solid #dbe5f5;
  border-radius: 10px;
  background: #f8fbff;
  padding: 8px 10px;
  color: #20395f;
  font-size: 14px;
}

.route-link:hover {
  border-color: #c6d8f8;
  background: color-mix(in srgb, var(--primary-soft) 74%, var(--panel) 26%);
}

.route-link:focus-visible {
  border-color: color-mix(in srgb, var(--primary) 50%, var(--line) 50%);
}

.route-link.active {
  background: var(--primary-soft);
  border-color: #c6d8f8;
  color: #153d84;
  font-weight: 600;
}

h1,
h2,
h3,
h4 {
  margin: 0 0 8px;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 19px;
}

h3 {
  font-size: 16px;
}

.muted {
  color: var(--muted);
}

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

.pill {
  display: inline-block;
  border-radius: 999px;
  background: var(--primary-soft);
  color: #1f417f;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 600;
}

.grid {
  display: grid;
  gap: 12px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: var(--panel);
}

.section-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-top: 10px;
  background: color-mix(in srgb, var(--panel) 92%, #fff 8%);
}

.course-overview-toolbar {
  margin-bottom: 12px;
}

.course-edit-toolbar {
  border-color: color-mix(in srgb, var(--primary) 45%, var(--line) 55%);
  background: color-mix(in srgb, var(--primary-soft) 78%, var(--panel) 22%);
}

.course-edit-toolbar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.course-edit-toolbar-head h3 {
  margin: 0;
  font-size: 15px;
}

.course-inline-notice {
  margin-top: 8px;
}

.inline-busy-note {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--primary) 40%, var(--line) 60%);
  background: color-mix(in srgb, var(--primary-soft) 78%, var(--panel) 22%);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.inline-section-card {
  border-color: color-mix(in srgb, var(--primary) 32%, var(--line) 68%);
}

.inline-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.inline-head-controls {
  align-items: center;
}

.inline-drag-handle {
  padding: 4px 8px;
  font-size: 12px;
  cursor: grab;
}

.inline-drag-handle:active {
  cursor: grabbing;
}

.inline-section-head h3 {
  margin-bottom: 4px;
}

.inline-editor-block {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: color-mix(in srgb, var(--panel) 95%, #fff 5%);
}

.inline-editor-block > summary {
  list-style: none;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
  padding: 10px 12px;
  color: var(--text);
}

.inline-editor-block > summary::-webkit-details-marker {
  display: none;
}

.inline-editor-block > summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 8px;
  color: var(--muted);
  transition: transform 0.15s ease;
}

.inline-editor-block[open] > summary::before {
  transform: rotate(90deg);
}

.inline-editor-body {
  padding: 0 12px 12px;
}

.inline-content-blocks-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 8px 0;
}

.inline-content-blocks-list {
  display: grid;
  gap: 10px;
}

.inline-content-block {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: color-mix(in srgb, var(--panel) 96%, #fff 4%);
  padding: 10px;
}

.inline-content-block-head {
  display: grid;
  grid-template-columns: auto auto minmax(140px, 180px) minmax(220px, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.inline-content-block-drag {
  cursor: grab;
  padding: 4px 8px;
}

.inline-content-block-drag:active {
  cursor: grabbing;
}

.inline-content-block-body {
  margin-top: 8px;
}

.inline-content-block-dragging {
  opacity: 0.55;
}

.inline-content-block-drop-before {
  box-shadow: inset 0 4px 0 0 color-mix(in srgb, var(--primary) 80%, #fff 20%);
}

.inline-content-block-drop-after {
  box-shadow: inset 0 -4px 0 0 color-mix(in srgb, var(--primary) 80%, #fff 20%);
}

.inline-lessons-list {
  margin-top: 12px;
}

.inline-lessons-list h4 {
  margin: 0 0 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #425b7f;
}

.inline-lesson-card {
  margin-top: 8px;
}

.inline-lesson-summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.inline-lesson-summary::-webkit-details-marker {
  display: none;
}

.inline-lesson-summary-title {
  font-weight: 700;
  color: #16386d;
}

.inline-open-link {
  display: inline-block;
  width: auto;
  padding: 8px 10px;
  border-radius: 10px;
}

.inline-dragging {
  opacity: 0.55;
}

.inline-drop-target {
  outline: 2px dashed color-mix(in srgb, var(--primary) 70%, #fff 30%);
  outline-offset: 2px;
}

.inline-drop-before {
  box-shadow: inset 0 4px 0 0 color-mix(in srgb, var(--primary) 80%, #fff 20%);
}

.inline-drop-after {
  box-shadow: inset 0 -4px 0 0 color-mix(in srgb, var(--primary) 80%, #fff 20%);
}

.inline-drop-append {
  box-shadow: inset 0 -4px 0 0 color-mix(in srgb, var(--primary) 70%, #fff 30%);
}

.inline-type-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.inline-chooser-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.inline-chooser-backdrop[hidden] {
  display: none !important;
}

.inline-chooser-modal {
  width: min(840px, 100%);
  max-height: 90vh;
  overflow: auto;
}

.inline-chooser-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.inline-chooser-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.inline-chooser-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 94%, #fff 6%);
  color: var(--text);
  border-radius: 10px;
  padding: 10px;
}

.inline-chooser-option.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.lesson {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  margin-top: 8px;
  background: var(--panel);
}

.lesson-player {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  gap: 12px;
}

.lesson-player-toc {
  align-self: start;
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 96px);
  overflow: auto;
}

.toc-list {
  display: grid;
  gap: 10px;
}

.toc-section {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.toc-section:first-child {
  border-top: 0;
  padding-top: 0;
}

.toc-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.toc-item {
  display: grid;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: color-mix(in srgb, var(--panel) 92%, #fff 8%);
  padding: 8px 10px;
  color: var(--text);
}

.toc-item small {
  color: var(--muted);
  font-size: 11px;
}

.toc-item.active {
  border-color: color-mix(in srgb, var(--primary) 55%, var(--line) 45%);
  background: color-mix(in srgb, var(--primary-soft) 78%, var(--panel) 22%);
}

.lesson-player-content {
  min-width: 0;
}

.student-content-blocks {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.student-content-block {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: color-mix(in srgb, var(--panel) 95%, #fff 5%);
}

.student-content-block h4 {
  margin: 0 0 8px;
}

.lesson-video-frame {
  width: 100%;
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #000;
}

.lesson-html {
  line-height: 1.55;
  color: var(--text);
}

.lesson-html img,
.lesson-html video,
.lesson-html iframe {
  max-width: 100%;
  height: auto;
}

.lesson-html table {
  width: 100%;
}

.rich-editor-block {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: color-mix(in srgb, var(--panel) 95%, #fff 5%);
}

.rich-editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

.rich-editor-toolbar button {
  padding: 5px 8px;
  font-size: 12px;
}

.rich-editor-surface {
  min-height: 120px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: color-mix(in srgb, var(--panel) 98%, #fff 2%);
  padding: 10px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.rich-editor-surface:empty::before {
  content: "Введите текст...";
  color: var(--muted);
}

.rich-editor-html-input {
  margin-top: 6px;
}

.book-reader {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.book-chapter {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: color-mix(in srgb, var(--panel) 94%, #fff 6%);
}

.book-chapter.subchapter {
  margin-left: 14px;
}

.book-chapter.hidden {
  opacity: 0.65;
}

.book-chapter h4 {
  margin: 0 0 8px;
}

.activity-callout {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: color-mix(in srgb, var(--primary-soft) 72%, var(--panel) 28%);
}

.scorm-frame-card {
  margin-top: 10px;
}

.scorm-frame {
  width: 100%;
  min-height: 680px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.lesson-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.lesson-title a {
  color: #14386f;
  font-weight: 600;
}

.list {
  margin: 6px 0 0;
  padding-left: 18px;
}

pre {
  margin: 8px 0 0;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 88%, #000 12%);
  color: var(--text);
  font-size: 12px;
  padding: 10px;
  overflow: auto;
  max-height: 340px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 760px;
}

th,
td {
  border-bottom: 1px solid #e4ebf8;
  padding: 7px 8px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 700;
  background: color-mix(in srgb, var(--panel) 85%, #fff 15%);
  position: sticky;
  top: 0;
  z-index: 1;
}

tbody tr:nth-child(even) td {
  background: var(--table-row-alt);
}

td input,
td select {
  min-width: 120px;
}

.empty {
  color: var(--muted);
  font-style: italic;
}

@media (max-width: 980px) {
  .topbar-inner {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-right {
    width: 100%;
    justify-content: flex-start;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    max-height: none;
  }

  .grid.two {
    grid-template-columns: 1fr;
  }

  .inline-section-head,
  .inline-lesson-summary,
  .course-edit-toolbar-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .inline-content-block-head {
    grid-template-columns: 1fr;
  }

  .inline-chooser-grid {
    grid-template-columns: 1fr;
  }

  table {
    min-width: 680px;
  }

  .lesson-player {
    grid-template-columns: 1fr;
  }

  .lesson-player-toc {
    position: static;
    max-height: none;
  }
}

@media (max-width: 640px) {
  .content {
    padding: 12px;
  }

  .panel {
    border-radius: 12px;
  }

  h1 {
    font-size: 21px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
