/* =========================================================
   КИПиА Portal — форматированный материал
   ========================================================= */

.content-with-toc {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 250px;
  gap: 28px;
  align-items: start;
}

.article-main {
  min-width: 0;
}

.article-toc {
  position: sticky;
  top: 96px;
  padding: 18px;
  background: #ffffff;
  border: 1px solid #dfe5e8;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.035);
}

.article-toc[hidden] {
  display: none;
}

.toc-title {
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 700;
  color: #37474f;
}

.toc-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.toc-link {
  color: #607d8b;
  text-decoration: none;
  font-size: 13px;
  line-height: 1.35;
}

.toc-link:hover {
  color: #1976d2;
}

.toc-h3 {
  padding-left: 12px;
}

.toc-h4 {
  padding-left: 24px;
}

/* =========================================================
   Вывод HTML-раздела
   ========================================================= */

.document-rich {
  background: #ffffff;
  padding: 34px 38px;
  border: 1px solid #e2e7ea;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.035);
  font-size: 16px;
  line-height: 1.75;
}

.document-rich > :first-child {
  margin-top: 0;
}

.document-rich > :last-child {
  margin-bottom: 0;
}

.document-rich h2,
.document-rich h3,
.document-rich h4 {
  scroll-margin-top: 100px;
  color: #1f2d33;
}

.document-rich h2 {
  margin: 34px 0 16px;
  padding-bottom: 9px;
  border-bottom: 1px solid #e7ecef;
  font-size: 24px;
}

.document-rich h3 {
  margin: 28px 0 12px;
  font-size: 20px;
}

.document-rich h4 {
  margin: 24px 0 10px;
  font-size: 17px;
}

.document-rich p {
  margin: 0 0 16px;
}

.document-rich ul,
.document-rich ol {
  margin: 12px 0 18px;
  padding-left: 28px;
}

.document-rich li {
  margin: 5px 0;
}

.document-rich blockquote {
  margin: 20px 0;
  padding: 12px 18px;
  border-left: 4px solid #90a4ae;
  background: #f6f8f9;
  color: #455a64;
}

.document-rich a {
  color: #1565c0;
}

.document-rich figure {
  margin: 28px auto;
  text-align: center;
}

.document-rich img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid #e0e5e8;
}

.document-rich figcaption {
  margin-top: 8px;
  color: #78909c;
  font-size: 13px;
}

.content-table {
  width: 100%;
  margin: 22px 0;
  border-collapse: collapse;
  overflow: hidden;
}

.content-table th,
.content-table td {
  padding: 10px 12px;
  border: 1px solid #cfd8dc;
  text-align: left;
  vertical-align: top;
}

.content-table th {
  background: #eef3f6;
  font-weight: 700;
}

.callout {
  margin: 22px 0;
  padding: 15px 18px;
  border-radius: 8px;
}

.callout > :last-child {
  margin-bottom: 0;
}

.callout-warning {
  background: #fff8e1;
  border: 1px solid #ffe082;
}

.callout-info {
  background: #e3f2fd;
  border: 1px solid #90caf9;
}

.callout-success {
  background: #e8f5e9;
  border: 1px solid #a5d6a7;
}

/* =========================================================
   Редактор
   ========================================================= */

.content-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.content-title-row h1 {
  margin: 0;
}

.edit-button {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  padding: 9px 14px;
  border: 1px solid #90a4ae;
  border-radius: 7px;
  background: #ffffff;
  color: #455a64;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
}

.edit-button:hover {
  background: #eceff1;
}

.save-success {
  margin-bottom: 20px;
  padding: 13px 16px;
  background: #e8f5e9;
  border: 1px solid #a5d6a7;
  border-radius: 7px;
  color: #2e7d32;
  font-weight: 600;
}

.editor-shell {
  display: flex;
  flex-direction: column;

  height: calc(100vh - 230px);
  min-height: 560px;

  overflow: hidden;

  background: #ffffff;
  border: 1px solid #d6dde1;
  border-radius: 12px;

  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.045);
}

/* =========================================================
   ВЕРХНЕЕ МЕНЮ ПРОГРАММЫ
   ========================================================= */

.editor-menubar {
  flex-shrink: 0;

  display: flex;
  align-items: center;

  min-height: 36px;
  padding: 0 8px;

  background: #ffffff;
  border-bottom: 1px solid #dfe5e8;

  position: relative;
  z-index: 50;
}

.program-menu {
  position: relative;
}

.program-menu-button {
  min-height: 34px;

  padding: 0 11px;

  border: 0;
  border-radius: 4px;

  background: transparent;
  color: #263238;

  font-size: 13px;

  cursor: pointer;
}

.program-menu-button:hover,
.program-menu.open > .program-menu-button {
  background: #e8eef2;
}

.program-menu-dropdown {
  display: none;

  position: absolute;
  top: calc(100% + 1px);
  left: 0;

  min-width: 230px;

  padding: 5px;

  background: #ffffff;

  border: 1px solid #cfd8dc;
  border-radius: 7px;

  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.16);

  z-index: 1000;
}

.program-menu.open > .program-menu-dropdown {
  display: block;
}

.program-menu-dropdown-wide {
  min-width: 290px;
}

.program-menu-dropdown button,
.program-menu-dropdown a {
  width: 100%;
  min-height: 34px;

  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;

  padding: 7px 10px;

  border: 0;
  border-radius: 4px;

  background: transparent;
  color: #263238;

  font-family: inherit;
  font-size: 13px;
  text-align: left;
  text-decoration: none;

  cursor: pointer;
}

.program-menu-dropdown button:hover,
.program-menu-dropdown a:hover {
  background: #e3f2fd;
  color: #0d47a1;
}

.program-menu-dropdown kbd {
  color: #78909c;
  font-family: inherit;
  font-size: 11px;
  font-weight: 400;
}

.program-menu-divider {
  height: 1px;

  margin: 5px 4px;

  background: #e3e8eb;
}

.editor-document-name {
  min-width: 0;

  margin-left: auto;
  padding: 0 12px;

  overflow: hidden;

  color: #78909c;

  font-size: 12px;

  text-overflow: ellipsis;
  white-space: nowrap;
}

/* =========================================================
   ПАНЕЛЬ БЫСТРЫХ КНОПОК
   ========================================================= */

.editor-toolbar {
  flex-shrink: 0;

  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;

  padding: 9px 10px;

  background: #f7f9fa;
  border-bottom: 1px solid #dfe5e8;

  position: relative;
  z-index: 20;
}

.editor-toolbar button,
.editor-toolbar select {
  min-height: 34px;
  padding: 6px 10px;

  border: 1px solid #c7d1d6;
  border-radius: 6px;

  background: #ffffff;
  color: #37474f;

  font-size: 13px;

  cursor: pointer;
}

.editor-toolbar button:hover,
.editor-toolbar select:hover {
  border-color: #90a4ae;
  background: #f1f4f5;
}

.editor-toolbar button:disabled {
  opacity: 0.6;
  cursor: wait;
}

.editor-toolbar button[data-command^="justify"] {
  min-width: 36px;
  font-size: 17px;
  line-height: 1;
}

.toolbar-separator {
  width: 1px;
  height: 25px;

  margin: 0 2px;

  background: #d6dde1;
}

/* =========================================================
   ПРОКРУЧИВАЕТСЯ ТОЛЬКО ТЕКСТ
   ========================================================= */

.rich-editor {
  flex: 1;
  min-height: 0;

  overflow-y: auto;
  overflow-x: hidden;

  padding: 32px 36px;

  outline: none;

  background: #ffffff;

  font-size: 16px;
  line-height: 1.75;
}

.rich-editor:focus {
  box-shadow: inset 0 0 0 2px rgba(25, 118, 210, 0.13);
}

.rich-editor h2 {
  margin: 30px 0 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid #e7ecef;
}

.rich-editor figure {
  margin: 24px auto;
  text-align: center;
}

.rich-editor img {
  max-width: 100%;
  height: auto;
}

.rich-editor figcaption {
  color: #78909c;
  font-size: 13px;
}

/* =========================================================
   НИЖНИЕ КНОПКИ НЕ ДВИГАЮТСЯ
   ========================================================= */

.editor-actions {
  flex-shrink: 0;

  display: flex;
  gap: 12px;
  align-items: center;

  padding: 12px 16px;

  border-top: 1px solid #dfe5e8;

  background: #f7f9fa;
}

/* =========================================================
   ПОЛНОЭКРАННЫЙ РЕЖИМ
   ========================================================= */

body.editor-fullscreen-open {
  overflow: hidden;
}

.editor-shell.editor-fullscreen {
  position: fixed;

  inset: 0;

  width: 100vw;
  height: 100vh;
  min-height: 0;

  z-index: 5000;

  border: 0;
  border-radius: 0;
}

.save-button,
.cancel-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 9px 16px;
  border-radius: 7px;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.save-button {
  border: 0;
  background: #1976d2;
  color: #ffffff;
  cursor: pointer;
}

.save-button:hover {
  background: #1565c0;
}

.cancel-button {
  border: 1px solid #cfd8dc;
  background: #ffffff;
  color: #546e7a;
}

.cancel-button:hover {
  background: #eceff1;
}

@media (max-width: 1050px) {
  .content-with-toc {
    grid-template-columns: 1fr;
  }

  .article-toc {
    position: static;
    order: -1;
  }
}

@media (max-width: 760px) {
  .content-title-row {
    display: block;
  }

  .edit-button {
    margin-top: 14px;
  }

  .rich-editor,
  .document-rich {
    padding: 22px 20px;
  }

  .rich-editor {
    min-height: 460px;
  }
}

@media (max-width: 760px) {
  .editor-shell {
    height: calc(100vh - 170px);
    min-height: 500px;
  }

  .editor-menubar {
    overflow-x: auto;
    overflow-y: visible;
  }

  .editor-document-name {
    display: none;
  }

  .rich-editor {
    padding: 20px;
  }
}

@media print {
  .header,
  .sidebar,
  .breadcrumb,
  .content-title-row,
  .editor-menubar,
  .editor-toolbar,
  .editor-actions {
    display: none !important;
  }

  .layout,
  .content {
    display: block;
    max-width: none;
    padding: 0;
  }

  .editor-shell {
    display: block;
    height: auto;
    min-height: 0;
    overflow: visible;
    border: 0;
    box-shadow: none;
  }

  .rich-editor {
    overflow: visible;
    padding: 0;
  }
}
