/* =============================================================
   SoundWave · 自研富文本编辑器样式（表格 / 演示模式）
   -------------------------------------------------------------
   · 颜色一律走 CSS 变量，随宿主深浅色模式切换，**不写死颜色**
   · 变量都带回退值：本文件单独引入也能用
   · 无外部字体 / 图标 / CDN
   ============================================================= */

/* ---------- 变量 ---------- */
:root {
  --rt-line: var(--line, #E6E9EF);
  --rt-line-2: var(--line-2, #EEF2F7);
  --rt-line-strong: var(--line-strong, #CBD5E1);
  --rt-surface: var(--surface, #FFFFFF);
  --rt-surface-2: var(--surface-2, #FCFCFD);
  --rt-sunken: var(--sunken, #F1F5F9);
  --rt-ink: var(--ink, #0F172A);
  --rt-ink-2: var(--ink-2, #334155);
  --rt-muted: var(--muted, #64748B);
  --rt-muted-2: var(--muted-2, #94A3B8);
  --rt-brand: var(--brand, #1B4DF5);
  --rt-brand-hover: var(--brand-hover, #1539D1);
  --rt-brand-soft: var(--brand-soft, #EEF4FF);
  --rt-brand-ring: var(--brand-ring, rgba(27, 77, 245, .18));
  --rt-accent: var(--accent, #F97316);
  --rt-accent-soft: var(--accent-soft, #FFF4ED);
  --rt-danger: var(--danger, #DC2626);
  --rt-sh-1: var(--sh-1, 0 1px 1px rgba(15, 23, 42, .03), 0 1px 2px rgba(15, 23, 42, .05));
  --rt-sh-2: var(--sh-2, 0 1px 2px rgba(15, 23, 42, .04), 0 4px 10px rgba(15, 23, 42, .06));
  --rt-sh-pop: var(--sh-pop, 0 4px 8px rgba(15, 23, 42, .05), 0 24px 56px rgba(15, 23, 42, .14));
  --rt-r-xs: var(--r-xs, 6px);
  --rt-r-sm: var(--r-sm, 8px);
  --rt-r: var(--r, 10px);
  --rt-mono: var(--mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
  --rt-font: var(--font, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif);
  /* 编辑区正文 */
  --rt-slide-bg: var(--surface, #FFFFFF);
  --rt-slide-ink: var(--ink, #0F172A);
}

/* 深色模式：跟随系统，可被 [data-theme] 覆盖 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --rt-line: var(--line, #1F2A3D);
    --rt-line-2: var(--line-2, #182031);
    --rt-line-strong: var(--line-strong, #2C3A52);
    --rt-surface: var(--surface, #111827);
    --rt-surface-2: var(--surface-2, #0F1626);
    --rt-sunken: var(--sunken, #161F31);
    --rt-ink: var(--ink, #F1F5F9);
    --rt-ink-2: var(--ink-2, #CBD5E1);
    --rt-muted: var(--muted, #8FA0B8);
    --rt-muted-2: var(--muted-2, #64748B);
    --rt-brand: var(--brand, #5C8CFF);
    --rt-brand-hover: var(--brand-hover, #93B4FF);
    --rt-brand-soft: var(--brand-soft, rgba(27, 77, 245, .14));
    --rt-brand-ring: var(--brand-ring, rgba(92, 140, 255, .30));
    --rt-accent: var(--accent, #FF8A3D);
    --rt-accent-soft: var(--accent-soft, rgba(249, 115, 22, .14));
    --rt-danger: var(--danger, #F87171);
    --rt-sh-1: var(--sh-1, 0 1px 2px rgba(0, 0, 0, .30));
    --rt-sh-2: var(--sh-2, 0 4px 14px rgba(0, 0, 0, .38));
    --rt-sh-pop: var(--sh-pop, 0 28px 72px rgba(0, 0, 0, .62));
    --rt-slide-bg: var(--surface, #111827);
    --rt-slide-ink: var(--ink, #F1F5F9);
  }
}

:root[data-theme="dark"] {
  --rt-line: var(--line, #1F2A3D);
  --rt-line-2: var(--line-2, #182031);
  --rt-line-strong: var(--line-strong, #2C3A52);
  --rt-surface: var(--surface, #111827);
  --rt-surface-2: var(--surface-2, #0F1626);
  --rt-sunken: var(--sunken, #161F31);
  --rt-ink: var(--ink, #F1F5F9);
  --rt-ink-2: var(--ink-2, #CBD5E1);
  --rt-muted: var(--muted, #8FA0B8);
  --rt-muted-2: var(--muted-2, #64748B);
  --rt-brand: var(--brand, #5C8CFF);
  --rt-brand-hover: var(--brand-hover, #93B4FF);
  --rt-brand-soft: var(--brand-soft, rgba(27, 77, 245, .14));
  --rt-brand-ring: var(--brand-ring, rgba(92, 140, 255, .30));
  --rt-accent: var(--accent, #FF8A3D);
  --rt-accent-soft: var(--accent-soft, rgba(249, 115, 22, .14));
  --rt-danger: var(--danger, #F87171);
  --rt-sh-1: var(--sh-1, 0 1px 2px rgba(0, 0, 0, .30));
  --rt-sh-2: var(--sh-2, 0 4px 14px rgba(0, 0, 0, .38));
  --rt-sh-pop: var(--sh-pop, 0 28px 72px rgba(0, 0, 0, .62));
  --rt-slide-bg: var(--surface, #111827);
  --rt-slide-ink: var(--ink, #F1F5F9);
}

/* ---------- 容器 ---------- */
.rtRoot {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--rt-line);
  border-radius: var(--rt-r);
  background: var(--rt-surface);
  color: var(--rt-ink);
  font-family: var(--rt-font);
  font-size: 13.5px;
  line-height: 1.65;
}

.rtHost {
  display: block;
}

/* ---------- 工具栏 ---------- */
.rtToolbar,
.rtTableBar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 8px;
  background: var(--rt-surface-2);
  border-bottom: 1px solid var(--rt-line);
}

.rtTableBar {
  position: static;
  background: var(--rt-brand-soft);
  border-bottom: 1px solid var(--rt-line);
}

.rtBarLabel {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--rt-brand);
  padding: 0 6px 0 2px;
  white-space: nowrap;
}

.rtGroup {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 0 6px;
  border-right: 1px solid var(--rt-line);
}

.rtGroup:last-child {
  border-right: 0;
}

.rtBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--rt-r-xs);
  background: transparent;
  color: var(--rt-ink-2);
  cursor: pointer;
  transition: background .16s ease, color .16s ease, border-color .16s ease;
}

.rtBtn svg {
  width: 15px;
  height: 15px;
}

.rtBtn:hover {
  background: var(--rt-sunken);
  color: var(--rt-ink);
}

.rtBtn:focus-visible {
  outline: 0;
  border-color: var(--rt-brand);
  box-shadow: 0 0 0 3px var(--rt-brand-ring);
}

.rtBtn.on {
  background: var(--rt-brand-soft);
  color: var(--rt-brand);
}

.rtBtn.rtPrimary {
  width: auto;
  padding: 0 12px;
  background: var(--rt-brand);
  color: var(--rt-surface);
  font-size: 12.5px;
  font-weight: 550;
}

.rtBtn.rtPrimary:hover {
  background: var(--rt-brand-hover);
  color: var(--rt-surface);
}

.rtSel {
  height: 28px;
  max-width: 92px;
  padding: 0 6px;
  border: 1px solid var(--rt-line);
  border-radius: var(--rt-r-xs);
  background: var(--rt-surface);
  color: var(--rt-ink-2);
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
}

.rtSel:focus-visible {
  outline: 0;
  border-color: var(--rt-brand);
  box-shadow: 0 0 0 3px var(--rt-brand-ring);
}

.rtColorBtn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--rt-r-xs);
  cursor: pointer;
  color: var(--rt-ink-2);
}

.rtColorBtn:hover {
  background: var(--rt-sunken);
  color: var(--rt-ink);
}

.rtColorBtn input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: 0;
  padding: 0;
}

/* 插入表格的小面板 */
.rtPop {
  position: absolute;
  top: 44px;
  right: 12px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 190px;
  padding: 12px;
  border: 1px solid var(--rt-line);
  border-radius: var(--rt-r);
  background: var(--rt-surface);
  box-shadow: var(--rt-sh-pop);
  font-size: 12.5px;
}

.rtPop[hidden] {
  display: none;
}

.rtPop label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--rt-ink-2);
}

.rtPop input[type="number"] {
  width: 64px;
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--rt-line);
  border-radius: var(--rt-r-xs);
  background: var(--rt-surface);
  color: var(--rt-ink);
  font-family: inherit;
  font-size: 12.5px;
}

.rtPopCheck {
  justify-content: flex-start !important;
  gap: 6px !important;
}

.rtPopFoot {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  padding-top: 2px;
}

/* ---------- 正文区 ---------- */
.rtContent {
  flex: 1;
  min-height: 180px;
  max-height: 62vh;
  overflow: auto;
  padding: 14px 16px;
  outline: 0;
  color: var(--rt-ink);
}

.rtContent:focus {
  box-shadow: inset 0 0 0 2px var(--rt-brand-ring);
}

.rtContent:empty::before {
  content: attr(data-placeholder);
  color: var(--rt-muted-2);
  pointer-events: none;
}

.rtContent p {
  margin: 0 0 10px;
}

.rtContent h1,
.rtContent h2,
.rtContent h3 {
  margin: 16px 0 8px;
  line-height: 1.35;
  font-weight: 650;
  color: var(--rt-ink);
}

.rtContent h1 { font-size: 21px; }
.rtContent h2 { font-size: 18px; }
.rtContent h3 { font-size: 16px; }

.rtContent ul,
.rtContent ol {
  margin: 0 0 10px;
  padding-left: 24px;
}

.rtContent blockquote {
  margin: 0 0 10px;
  padding: 6px 12px;
  border-left: 3px solid var(--rt-brand);
  background: var(--rt-surface-2);
  color: var(--rt-ink-2);
}

.rtContent pre {
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: var(--rt-r-sm);
  background: var(--rt-sunken);
  font-family: var(--rt-mono);
  font-size: 12.5px;
  overflow: auto;
}

.rtContent code,
.rtContent .rtInlineCode {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--rt-sunken);
  color: var(--rt-accent);
  font-family: var(--rt-mono);
  font-size: .92em;
}

.rtContent a {
  color: var(--rt-brand);
  text-decoration: underline;
}

.rtContent img {
  max-width: 100%;
  border-radius: var(--rt-r-sm);
}

.rtContent hr {
  border: 0;
  border-top: 1px solid var(--rt-line);
  margin: 14px 0;
}

/* 分页符：编辑态显示为虚线，演示切页的锚点 */
.rtContent hr.sw-page-break,
.rtContent hr[class*="page-break"] {
  border-top: 2px dashed var(--rt-brand);
  position: relative;
}

.rtContent hr.sw-page-break::after {
  content: "⤓";
  position: absolute;
  top: -9px;
  left: 8px;
  padding: 0 6px;
  border-radius: var(--rt-r-xs);
  background: var(--rt-brand-soft);
  color: var(--rt-brand);
  font-size: 11px;
  line-height: 16px;
}

/* ---------- 表格 ---------- */
.rtContent table {
  width: 100%;
  margin: 0 0 12px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 13px;
}

.rtContent table th,
.rtContent table td {
  padding: 7px 10px;
  border: 1px solid var(--rt-line);
  text-align: left;
  vertical-align: top;
  word-break: break-word;
}

.rtContent table th {
  background: var(--rt-sunken);
  color: var(--rt-ink);
  font-weight: 600;
}

.rtContent table tbody tr:nth-child(even) td {
  background: var(--rt-surface-2);
}

.rtContent table th.rtCellSel,
.rtContent table td.rtCellSel {
  outline: 2px solid var(--rt-brand);
  outline-offset: -2px;
  background: var(--rt-brand-soft);
}

/* 单元格右边缘可拖拽调列宽 */
.rtContent table td,
.rtContent table th {
  position: relative;
}

.rtContent table td:hover,
.rtContent table th:hover {
  box-shadow: inset -3px 0 0 -1px var(--rt-brand-ring);
}

/* ---------- 状态栏 ---------- */
.rtStatus {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 12px;
  border-top: 1px solid var(--rt-line);
  background: var(--rt-surface-2);
  color: var(--rt-muted);
  font-size: 11.5px;
}

.rtStatus .rtCount {
  font-variant-numeric: tabular-nums;
}

/* ---------- 演示模式 ---------- */
body.rtPresenting {
  overflow: hidden;
}

.rtPresent {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  background: var(--rt-surface-2);
  color: var(--rt-ink);
  font-family: var(--rt-font);
}

.rtPresentBar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--rt-line);
  background: var(--rt-surface);
  box-shadow: var(--rt-sh-1);
}

.rtPresentTitle {
  font-size: 13px;
  font-weight: 600;
}

.rtPresentPage {
  font-size: 12px;
  color: var(--rt-muted);
  font-variant-numeric: tabular-nums;
}

.rtPresentSpacer {
  flex: 1;
}

.rtPresentMain {
  flex: 1;
  display: flex;
  min-height: 0;
}

.rtThumbs {
  width: 190px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  overflow: auto;
  border-right: 1px solid var(--rt-line);
  background: var(--rt-surface);
}

.rtThumb {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 1px solid var(--rt-line);
  border-radius: var(--rt-r-sm);
  background: var(--rt-surface-2);
  color: inherit;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  transition: border-color .16s ease, box-shadow .16s ease;
}

.rtThumb:hover {
  border-color: var(--rt-line-strong);
}

.rtThumb.on {
  border-color: var(--rt-brand);
  box-shadow: 0 0 0 2px var(--rt-brand-ring);
}

.rtThumbNo {
  position: absolute;
  top: 3px;
  left: 6px;
  z-index: 2;
  font-size: 10px;
  color: var(--rt-muted);
}

.rtThumbTitle {
  display: block;
  padding: 4px 8px 0 22px;
  font-size: 11px;
  color: var(--rt-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rtThumbBody {
  display: block;
  height: 88px;
  overflow: hidden;
  padding: 14px 8px 0;
  background: var(--rt-slide-bg);
  color: var(--rt-slide-ink);
  font-size: 7px;
  line-height: 1.5;
  text-align: left;
}

.rtThumbBody > * {
  transform: scale(.55);
  transform-origin: top left;
  width: 182%;
}

.rtStage {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  overflow: auto;
}

.rtSlide {
  width: min(960px, 100%);
  min-height: 540px;
  padding: 40px 48px;
  border-radius: var(--rt-r-lg, 14px);
  background: var(--rt-slide-bg);
  color: var(--rt-slide-ink);
  box-shadow: var(--rt-sh-pop);
  overflow: auto;
}

.rtSlide h1 { font-size: 30px; margin: 0 0 12px; }
.rtSlide h2 { font-size: 23px; margin: 0 0 10px; }
.rtSlide h3 { font-size: 19px; margin: 0 0 8px; }
.rtSlide p { margin: 0 0 12px; }
.rtSlide table { width: 100%; border-collapse: collapse; margin: 0 0 14px; }
.rtSlide th, .rtSlide td { border: 1px solid var(--rt-line); padding: 6px 9px; text-align: left; font-size: 13px; }
.rtSlide th { background: var(--rt-sunken); }
.rtSlide pre { padding: 10px 12px; border-radius: var(--rt-r-sm); background: var(--rt-sunken); font-family: var(--rt-mono); font-size: 12.5px; overflow: auto; }
.rtSlide blockquote { margin: 0 0 12px; padding: 6px 12px; border-left: 3px solid var(--rt-brand); background: var(--rt-surface-2); }
.rtSlide img { max-width: 100%; }
.rtSlide hr.sw-page-break { display: none; }

.rtNotesBox {
  flex: none;
  max-height: 24vh;
  display: flex;
  gap: 12px;
  padding: 10px 16px;
  border-top: 1px solid var(--rt-line);
  background: var(--rt-surface);
  overflow: auto;
}

.rtNotesTitle {
  flex: none;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--rt-muted);
  padding-top: 2px;
}

.rtNotesText {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  color: var(--rt-ink-2);
  white-space: pre-wrap;
}

.rtNotesText:empty::before {
  content: "—";
  color: var(--rt-muted-2);
}

/* ---------- 窄屏 ---------- */
@media (max-width: 720px) {
  .rtThumbs { width: 128px; }
  .rtThumbBody { height: 62px; }
  .rtSlide { padding: 24px 20px; min-height: 320px; }
  .rtContent { max-height: 48vh; }
}
