/* =====================================================================
   rte.css — редактор описания книги (панель-иконки из rte.js)
   и стили типографики описания на сайте (.book-summary).
   ===================================================================== */

/* ---------- каркас редактора ---------- */
.rte-wrap {
  border: 1px solid var(--line-2);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  max-width: 880px;
  overflow: visible;
}
.rte-bar {
  position: sticky;
  top: 78px;
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  padding: 8px;
  border-bottom: 1px solid var(--line-2);
  border-radius: 12px 12px 0 0;
  background: var(--surface);
  box-shadow: 0 8px 20px -14px rgb(40 25 10 / .45);
}
.rte-bar .g {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 0 7px;
  border-right: 1px solid var(--line);
}
.rte-bar .g:last-of-type { border-right: 0; margin-left: auto; }
.rte-bar button,
.rte-bar select {
  min-height: 34px;
  min-width: 34px;
  padding: 0 7px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  font: 600 12.5px/1 var(--sans);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  user-select: none;
  -webkit-user-select: none;
}
.rte-bar button:hover,
.rte-bar select:hover { background: var(--surface-2); border-color: var(--line-2); }
.rte-bar button.on {
  background: var(--accent);
  color: var(--accent-ink, #fff);
  border-color: var(--accent);
}
.rte-bar button.danger:hover { background: var(--err-bg); color: var(--err-ink); }
.rte-bar select {
  max-width: 165px;
  padding: 0 6px;
  border-color: var(--line-2);
  background: var(--surface);
}
.rte-bar select:hover { border-color: var(--accent); }
.rte-bar button b, .rte-bar button i, .rte-bar button u, .rte-bar button s { font-size: 14.5px; }
.rte-bar .hl-ico { background: var(--warn-bg); color: var(--warn-ink); border-radius: 4px; padding: 1px 5px; font-weight: 700; }

/* вторая строка: панель картинки / таблицы */
.rte-figbar {
  flex: 1 0 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  padding: 8px;
  border-top: 1px dashed var(--line-2);
  background: var(--surface-2);
  border-radius: 8px;
  font: 13px/1 var(--sans);
}
.rte-figbar[hidden] { display: none; }
.rte-figbar > span { color: var(--muted); font-weight: 600; margin: 0 4px 0 2px; }
.rte-figbar button {
  min-height: 30px;
  min-width: 0;
  padding: 0 9px;
  border: 1px solid var(--line-2);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  font: 600 12.5px/1 var(--sans);
  cursor: pointer;
}
.rte-figbar button:hover { border-color: var(--accent); color: var(--accent); }
.rte-figbar button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink, #fff); }
.rte-figbar button.danger { color: var(--err-ink); }
.rte-figbar button.danger:hover { background: var(--err-bg); border-color: var(--err-ink); }

/* ---------- поле редактора ---------- */
.rte {
  min-height: 340px;
  max-height: 75vh;
  overflow-y: auto;
  padding: 26px clamp(16px, 4vw, 40px);
  font: 17.5px/1.7 var(--serif);
  color: var(--ink);
  outline: none;
  caret-color: var(--accent);
  text-align: left;
  cursor: text;
}
.rte:focus { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent); }
.rte:empty::before { content: attr(data-placeholder); color: var(--muted); pointer-events: none; }
.rte.drag { outline: 3px dashed var(--accent); outline-offset: -6px; }
.rte-raw {
  display: none;
  width: 100%;
  min-height: 340px;
  border: 0;
  border-top: 1px dashed var(--line-2);
  padding: 16px;
  font: 13.5px/1.6 ui-monospace, SFMono-Regular, Consolas, monospace;
  background: var(--surface-2);
  color: var(--ink);
  resize: vertical;
}
.rte-raw[hidden] { display: none; }
.rte-status {
  padding: 8px 14px;
  border-top: 1px solid var(--line);
  border-radius: 0 0 12px 12px;
  background: var(--surface-2);
  color: var(--muted);
  font: 12.5px/1.4 var(--sans);
  font-variant-numeric: tabular-nums;
}

/* выбранная картинка и загрузка */
.rte figure { cursor: pointer; }
.rte figure.rte-sel { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
.rte-uploading figcaption { color: var(--muted); font: 13px/1.4 var(--sans); }

/* ---------- всплывающие окошки ---------- */
.rte-pop {
  position: absolute;
  z-index: 300;
  min-width: 230px;
  max-width: min(430px, calc(100vw - 16px));
  padding: 14px;
  border: 1px solid var(--line-2);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  font: 14px/1.5 var(--sans);
  color: var(--ink);
}
.rte-pop b { display: block; margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.rte-pop label { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; }
.rte-pop input[type="text"], .rte-pop input[type="number"] {
  flex: 1;
  min-width: 0;
  height: 34px;
  padding: 0 9px;
  border: 1px solid var(--line-2);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}
.rte-pop button {
  display: block;
  width: 100%;
  margin: 0 0 5px;
  padding: 8px 10px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.rte-pop button:hover { border-color: var(--accent); color: var(--accent); }
.rte-pop .row { display: flex; gap: 8px; }
.rte-pop .row button { flex: 1; text-align: center; }
.rte-pop p.muted { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.rte-pop .chars { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.rte-pop .chars button { display: flex; align-items: center; justify-content: center; min-width: 0; margin: 0; padding: 7px 0; font-size: 17px; font-family: var(--serif); text-align: center; }
.rte-pop .lh-menu button { text-align: left; }
.rte-pop .c-red span { color: #8E2A24; } .rte-pop .c-blue span { color: #27466F; }
.rte-pop .c-green span { color: #2E5E4E; } .rte-pop .c-gold span { color: #8a6a12; } .rte-pop .c-gray span { color: #5E554B; }

/* ---------- предпросмотр и полноэкранный режим ---------- */
dialog.rte-preview {
  width: min(880px, calc(100vw - 32px));
  max-height: min(84vh, 900px);
  border: 1px solid var(--line-2);
  border-radius: 14px;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}
dialog.rte-preview::backdrop { background: rgb(20 14 8 / .5); }
.rte-preview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 14px 14px 0 0;
  font: 14px/1.3 var(--sans);
}
.rte-preview-body { padding: 20px clamp(16px, 4vw, 32px); overflow: auto; max-height: calc(min(84vh, 900px) - 60px); }
.rte-wrap.rte-full {
  position: fixed;
  z-index: 1000;
  inset: 14px;
  max-width: none;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  border-radius: 14px;
}
.rte-wrap.rte-full .rte { flex: 1; max-height: none; min-height: 0; }
.rte-wrap.rte-full .rte-bar { position: static; border-radius: 14px 14px 0 0; }
body.rte-noscroll { overflow: hidden; }

/* =====================================================================
   Типографика описания — единая для редактора (.rte) и сайта (.book-summary)
   ===================================================================== */
.rte p, .book-summary p { margin: 0 0 .9em; text-align: inherit; }
.rte h2, .book-summary h2 { font: 700 1.5em/1.25 var(--serif); margin: 1.1em 0 .4em; }
.rte h3, .book-summary h3 { font: 700 1.28em/1.3 var(--serif); margin: 1em 0 .35em; }
.rte h4, .book-summary h4 { font: 700 1.12em/1.3 var(--serif); margin: .9em 0 .3em; }
.rte blockquote, .book-summary blockquote {
  margin: 14px 0;
  padding: 10px 16px;
  border-left: 4px solid var(--accent);
  color: var(--ink-2);
  background: var(--surface-2);
  border-radius: 0 8px 8px 0;
}
.rte ul, .rte ol, .book-summary ul, .book-summary ol { margin: 0 0 .9em; padding-left: 28px; }
.rte hr, .book-summary hr { border: 0; border-top: 2px solid var(--line-2); margin: 22px 0; }
.rte a, .book-summary a { color: var(--link); text-decoration: underline; text-underline-offset: 2px; }
.rte img, .book-summary img { max-width: 100%; height: auto; border-radius: 8px; }
.rte table, .book-summary table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: .95em; }
.rte th, .rte td, .book-summary th, .book-summary td {
  padding: 7px 10px;
  border: 1px solid var(--line-2);
  text-align: left;
  vertical-align: top;
}
.rte th, .book-summary th { background: var(--surface-2); font-weight: 700; }
.rte table.tbl, .book-summary table.tbl { width: auto; min-width: 40%; }
.rte sup, .book-summary sup { line-height: 0; }
.rte sup.fn, .book-summary sup.fn { color: var(--accent); font-weight: 700; cursor: help; }

/* выравнивание абзацев */
.rte .al-left, .book-summary .al-left { text-align: left; }
.rte .al-center, .book-summary .al-center { text-align: center; }
.rte .al-right, .book-summary .al-right { text-align: right; }
.rte .al-justify, .book-summary .al-justify {
  text-align: justify;
  hyphens: auto;
  -webkit-hyphens: auto;
}

/* стили абзацев */
.rte .lead, .book-summary .lead { font-size: 1.08em; color: var(--ink-2); }
.rte .epigraph, .book-summary .epigraph {
  margin: 14px 8% 14px auto;
  max-width: 70%;
  font-style: italic;
  color: var(--muted);
  text-align: right;
}
.rte .poem, .book-summary .poem {
  margin: 16px 0;
  padding: 14px 20px;
  border-left: 3px solid var(--line-2);
  background: var(--surface-2);
  font-family: var(--serif);
  font-size: 1.04em;
  line-height: 1.65;
  border-radius: 0 8px 8px 0;
  text-align: left;
}
.rte .poem.stanza, .book-summary .poem.stanza { margin-bottom: 4px; }
.rte .sign, .book-summary .sign { text-align: right; font-style: italic; color: var(--muted); margin-top: -6px; }
.rte .footnote, .book-summary .footnote { font-size: .85em; color: var(--muted); border-top: 1px solid var(--line); padding-top: 6px; }
.rte .dropcap::first-letter, .book-summary .dropcap::first-letter {
  float: left;
  font: 700 3.1em/0.85 var(--serif);
  padding: 4px 8px 0 0;
  color: var(--accent);
}

/* строки-инструменты */
.rte .spaced, .book-summary .spaced { letter-spacing: .14em; }
.rte .caps, .book-summary .caps { font-variant: small-caps; }
.rte .hl, .book-summary .hl { background: var(--warn-bg); color: var(--warn-ink); padding: 0 2px; border-radius: 3px; }

/* цвета и размеры */
.rte .c-red, .book-summary .c-red { color: #8E2A24; }
.rte .c-blue, .book-summary .c-blue { color: #27466F; }
.rte .c-green, .book-summary .c-green { color: #2E5E4E; }
.rte .c-gold, .book-summary .c-gold { color: #8a6a12; }
.rte .c-gray, .book-summary .c-gray { color: #5E554B; }
.rte .fs-sm, .book-summary .fs-sm { font-size: .85em; }
.rte .fs-lg, .book-summary .fs-lg { font-size: 1.18em; }
.rte .fs-xl, .book-summary .fs-xl { font-size: 1.35em; }
.rte .lh-100, .book-summary .lh-100 { line-height: 1.0; }
.rte .lh-120, .book-summary .lh-120 { line-height: 1.2; }
.rte .lh-140, .book-summary .lh-140 { line-height: 1.4; }
.rte .lh-160, .book-summary .lh-160 { line-height: 1.6; }
.rte .lh-180, .book-summary .lh-180 { line-height: 1.8; }
.rte .lh-200, .book-summary .lh-200 { line-height: 2.0; }

/* картинки-иллюстрации */
.rte figure.fig, .book-summary figure.fig { margin: 16px 0; text-align: center; }
.rte figure.fig-left, .book-summary figure.fig-left { float: left; margin: 6px 20px 12px 0; }
.rte figure.fig-right, .book-summary figure.fig-right { float: right; margin: 6px 0 12px 20px; }
.rte figure.w25, .book-summary figure.w25 { width: 25%; }
.rte figure.w33, .book-summary figure.w33 { width: 33%; }
.rte figure.w50, .book-summary figure.w50 { width: 50%; }
.rte figure.w75, .book-summary figure.w75 { width: 75%; }
.rte figure.w100, .book-summary figure.w100 { width: 100%; }
.rte figure figcaption, .book-summary figure figcaption {
  font: 12.5px/1.5 var(--sans);
  color: var(--muted);
  padding: 6px 4px 0;
  text-align: center;
}
.book-summary::after { content: ""; display: block; clear: both; }

/* ---------- мобильная версия ---------- */
@media (max-width: 700px) {
  .rte-bar { position: static; }
  .rte-bar .g { padding: 0 4px; border-right: 0; }
  .rte-bar .g:last-of-type { margin-left: 0; }
  .rte { min-height: 260px; padding: 16px; font-size: 16px; }
  .rte-pop .chars { grid-template-columns: repeat(6, 1fr); }
  .rte figure.fig-left, .book-summary figure.fig-left,
  .rte figure.fig-right, .book-summary figure.fig-right { float: none; margin: 14px auto; }
}
@media print {
  .rte-bar, .rte-status { display: none; }
}
