﻿

.editor {
  --ed-btn: var(--text-dim);
  --ed-btn-hover-bg: var(--surface-2);
  --ed-btn-hover-color: var(--ink);
  --ed-on-bg: var(--surface-2);
  --ed-on-color: var(--ink);
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);

  transition: border-color .15s, box-shadow .15s;
}

.editor > :first-child { border-top-left-radius: calc(var(--r-lg) - 1px); border-top-right-radius: calc(var(--r-lg) - 1px); }
.editor > :last-child:not([hidden]):not(.ed-pop):not(.ed-imgbar) { border-bottom-left-radius: calc(var(--r-lg) - 1px); border-bottom-right-radius: calc(var(--r-lg) - 1px); }
.editor:focus-within { border-color: var(--ink); box-shadow: 0 0 0 3px var(--accent-dim); }
.editor.is-err { border-color: var(--red) !important; box-shadow: 0 0 0 3px var(--accent-dim) !important; }

.editor__toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--line);
}
.editor__group { display: flex; align-items: center; gap: 2px; }
.editor__sep { width: 1px; height: 20px; background: var(--line-2); margin: 0 6px; flex: none; }

.editor__btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ed-btn);
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
  line-height: 1;
  overflow: hidden;
  transition: background .12s, color .12s, transform .06s;
  -webkit-tap-highlight-color: transparent;
}
.editor__btn svg { width: 16px; height: 16px; flex: none; display: block; pointer-events: none; }
.editor__btn:hover { background: var(--ed-btn-hover-bg); color: var(--ed-btn-hover-color); }
.editor__btn:active { transform: translateY(1px); }
.editor__btn.is-on { background: var(--ed-on-bg); color: var(--ed-on-color); }
.editor__btn:disabled { opacity: .35; cursor: default; pointer-events: none; }

.ed-tip {
  position: absolute;
  z-index: 75;
  background: var(--ink);
  color: var(--bg);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  font-family: var(--font);
  white-space: nowrap;
  padding: 5px 9px;
  border-radius: 6px;
  box-shadow: var(--shadow-2);
  pointer-events: none;
  opacity: 0;
  transition: opacity .12s ease;
}
.ed-tip.is-on { opacity: 1; }
.ed-tip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: var(--ink);
}
.ed-tip.is-below::after { top: auto; bottom: 100%; border-top-color: transparent; border-bottom-color: var(--ink); }

.editor__sel {
  appearance: none;
  height: 32px;
  padding: 0 26px 0 10px;
  border: 1px solid var(--line-2);
  border-radius: 7px;
  background: var(--surface);
  background-image: var(--sel-arrow);
  background-repeat: no-repeat;
  background-position: right 10px center;
  color: var(--ink);
  font-family: var(--font);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.editor__sel:hover { border-color: var(--line-2); }
.editor__sel:focus { outline: none; border-color: var(--ink); }

.editor__tabs { display: flex; align-items: center; gap: 2px; margin-left: auto; background: var(--surface-2); border-radius: 8px; padding: 2px; }
.editor__tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.editor__tab.is-on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .25); }
.editor__tab svg { width: 14px; height: 14px; flex: none; display: block; pointer-events: none; }

.editor__canvas { display: flex; flex-direction: column; }
.editor__write, .editor__read { width: 100%; }

.editor .ql-editor {
  min-height: 240px;
  padding: 16px 18px;
  font-family: var(--font);
  font-size: 15.5px;
  line-height: 1.7;
  color: var(--ink-2);
  cursor: text;
  overflow-wrap: anywhere;
}
.editor .ql-editor:focus { outline: none; }
.editor .ql-editor.ql-blank::before {
  color: var(--text-3);
  font-style: normal;
  font-family: var(--font);
}
.editor .ql-editor > * { margin: 0 0 10px; }
.editor .ql-editor > *:last-child { margin-bottom: 0; }
.editor .ql-editor h1 { font-size: 27px; color: var(--ink); font-weight: 700; letter-spacing: -0.015em; }
.editor .ql-editor h2 { font-size: 22px; color: var(--ink); font-weight: 700; letter-spacing: -0.015em; }
.editor .ql-editor h3 { font-size: 18px; color: var(--ink); font-weight: 700; }
.editor .ql-editor strong { color: var(--ink); }
.editor .ql-editor a { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.editor .ql-editor blockquote { border-left: 3px solid var(--line-2); padding-left: 16px; color: var(--text-dim); }
.editor .ql-editor code { font-family: var(--mono); background: var(--surface-2); border-radius: 6px; padding: 2px 6px; font-size: .9em; }
.editor .ql-editor pre { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px 14px; overflow-x: auto; font-family: var(--mono); font-size: .92em; line-height: 1.6; }
.editor .ql-editor pre code { background: none; padding: 0; font-size: inherit; }
.editor .ql-editor ul, .editor .ql-editor ol { padding-left: 22px; }
.editor .ql-editor .ql-align-center { text-align: center; }
.editor .ql-editor .ql-align-right { text-align: right; }
.editor .ql-editor .ql-align-justify { text-align: justify; }
.editor .ql-editor img { max-width: 100%; height: auto; border-radius: var(--r-sm); }
.editor .ql-editor hr { border: 0; border-top: 1px solid var(--line-2); margin: 18px 0; }
.editor .ql-editor s { color: var(--text-3); }

.editor__preview {
  min-height: 240px;
  padding: 16px 18px;
  font-size: 15.5px;
  line-height: 1.7;
  color: var(--ink-2);
  max-width: none;
}
.editor__preview.is-loading { opacity: .55; }

.editor__meta {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: var(--bg-alt);
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--text-dim);
  font-family: var(--font);
}
.editor__meta .editor__msg { color: var(--ink); font-weight: 600; }
.editor__meta .editor__msg.is-err { color: var(--red); }
.editor__count { margin-left: auto; font-variant-numeric: tabular-nums; }
.editor__count.is-over { color: var(--red); font-weight: 600; }
.editor__saved { opacity: 0; transition: opacity .3s; }
.editor__saved.is-visible { opacity: 1; }

.editor__draft {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 9px 14px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
  color: var(--text-dim);
}
.editor__draft b { color: var(--ink); font-weight: 600; }
.editor__draft .btn { margin-left: auto; }

.ed-pop {
  position: absolute;
  z-index: 65;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px;
  min-width: 250px;
}
.ed-pop__title { font-size: 13px; font-weight: 600; color: var(--ink); margin-bottom: 10px; display: block; }
.ed-pop .field { gap: 5px; margin-bottom: 10px; }
.ed-pop label { font-size: 12.5px; font-weight: 600; color: var(--text-dim); }
.ed-pop .input { font-size: 14px; padding: 9px 12px; }
.ed-pop__row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.ed-pop__row .btn { padding: 8px 14px; font-size: 13.5px; }
.ed-pop__check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text-dim); cursor: pointer; margin: 2px 0 8px; }
.ed-pop__check input { margin: 0; }

.ed-pop__menu { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; }
.ed-pop__menu .editor__btn { width: 100%; padding: 0 8px; gap: 8px; justify-content: flex-start; font-size: 13px; }
.ed-pop__menu .editor__btn.is-wide { grid-column: span 2; }
.ed-pop__menu .editor__btn svg { flex: none; }

.ed-imgbar {
  position: absolute;
  z-index: 66;
  display: flex;
  align-items: center;
  gap: 3px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-2);
  padding: 4px;
}
.ed-imgbar .editor__btn { width: auto; padding: 0 9px; font-size: 12.5px; font-weight: 600; height: 28px; gap: 5px; }

.editor__write.is-uploading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--dz-bg);
  z-index: 40;
}
.ed-uploading-note {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 41;
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  padding: 8px 14px;
  border-radius: var(--r-sm);
  box-shadow: var(--shadow);
}

body.has-editor-full { overflow: hidden; }
.editor.is-full {
  position: fixed;
  inset: 0;
  z-index: 200;
  border-radius: 0;
  border: 0;
}
.editor.is-full > :first-child, .editor.is-full > :last-child { border-radius: 0; }
.editor.is-full .editor__toolbar { position: sticky; top: 0; z-index: 30; border-radius: 0; }
.editor.is-full .editor__canvas { flex: 1; overflow-y: auto; min-height: 0; }
.editor.is-full .editor .ql-editor { min-height: 60vh; }
.editor.is-full .editor__meta { border-radius: 0; }

@media (max-width: 640px) {
  .editor__toolbar { padding: 6px; gap: 3px; }
  .editor__btn { width: 34px; height: 34px; }
  .editor__sep { margin: 0 4px; }
  .editor__tabs { margin-left: 0; }
  .editor__toolbar { row-gap: 6px; }
  .editor .ql-editor { min-height: 200px; font-size: 16px; }
  .ed-pop { left: 8px !important; right: 8px; min-width: 0; }
}

@media (max-width: 900px) {
  .usermenu__pop, .notifmenu__pop {
    position: absolute;
    right: 0;
    left: auto;
    top: calc(100% + 10px);
    box-shadow: var(--shadow);
    max-width: calc(100vw - 32px);
  }
}
@media (prefers-reduced-motion: reduce) {
  .editor * { transition-duration: .01ms !important; }
}

.ed-dropline {
  position: absolute; z-index: 65; width: 2px; height: 20px; border-radius: 2px;
  background: var(--accent, #ef4444); box-shadow: 0 0 8px rgba(239,68,68,.8);
  pointer-events: none; display: none;
}

.ed-imgsel {
  position: absolute; z-index: 64; pointer-events: none;
  border: 2px solid var(--accent, #ef4444); border-radius: 4px; box-sizing: border-box;
}
.ed-imgsel[hidden] { display: none; }
.ed-imgsel__h {
  position: absolute; width: 11px; height: 11px; box-sizing: border-box;
  background: var(--surface, #fff); border: 2px solid var(--accent, #ef4444);
  border-radius: 3px; pointer-events: auto; cursor: nwse-resize;
}
.ed-imgsel__h--nw { left: -7px; top: -7px; cursor: nwse-resize; }
.ed-imgsel__h--n  { left: 50%; margin-left: -6px; top: -7px; cursor: ns-resize; }
.ed-imgsel__h--ne { right: -7px; top: -7px; cursor: nesw-resize; }
.ed-imgsel__h--e  { right: -7px; top: 50%; margin-top: -6px; cursor: ew-resize; }
.ed-imgsel__h--se { right: -7px; bottom: -7px; cursor: nwse-resize; }
.ed-imgsel__h--s  { left: 50%; margin-left: -6px; bottom: -7px; cursor: ns-resize; }
.ed-imgsel__h--sw { left: -7px; bottom: -7px; cursor: nesw-resize; }
.ed-imgsel__h--w  { left: -7px; top: 50%; margin-top: -6px; cursor: ew-resize; }

/* ============ prose (markdown rendering) ============ */
.prose {
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--text-dim);
  word-break: break-word;
}
.prose p { margin: 0 0 10px; }
.prose p:last-child { margin-bottom: 0; }
.prose h1, .prose h2, .prose h3, .prose h4, .prose h5, .prose h6 {
  font-weight: 700;
  color: var(--ink);
  margin: 16px 0 8px;
  line-height: 1.3;
}
.prose h1 { font-size: 20px; }
.prose h2 { font-size: 17px; }
.prose h3 { font-size: 15px; }
.prose h4, .prose h5, .prose h6 { font-size: 13.5px; }
.prose ul, .prose ol { margin: 0 0 10px; padding-left: 22px; }
.prose li { margin: 3px 0; }
.prose blockquote {
  margin: 0 0 10px;
  padding: 8px 14px;
  border-left: 3px solid var(--accent);
  background: var(--accent-dim);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  color: var(--text-dim);
}
.prose blockquote p { margin: 0; }
.prose code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-xs);
  padding: 1px 6px;
  color: var(--accent);
}
.prose pre {
  margin: 0 0 10px;
  padding: 12px 14px;
  background: var(--bg-alt);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow-x: auto;
}
.prose pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--ink);
  font-size: 12.5px;
}
.prose a { color: var(--accent); font-weight: 600; }
.prose a:hover { text-decoration: underline; text-underline-offset: 3px; }
.prose img { max-width: 100%; height: auto; border-radius: var(--r-sm); margin: 4px 0; }
.prose hr { border: none; border-top: 1px solid var(--line-2); margin: 14px 0; }
.prose strong { color: var(--ink); }
