/*
 * Rich in-game editor overlay for the Underspire webclient.
 *
 * Driven by the editor OOB protocol (editor_open/editor_save/editor_cancel;
 * see web/static/webclient/js/editor.js and evennia/utils/eveditor.py). Themed
 * entirely with the terminal's CSS variables so it inherits the active theme.
 */

#ed-overlay {
  position: fixed;
  inset: 0;
  z-index: 4000; /* above HUD, panels, chat; below nothing that matters */
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(3px);
  font-family: inherit;
}
#ed-overlay.open {
  display: flex;
}

#ed-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(1200px, 92vw);
  height: min(860px, 88vh);
  background: var(--bg-surface, #08080c);
  border: 1px solid var(--border-subtle, rgba(139, 26, 26, 0.4));
  border-radius: 6px;
  box-shadow: 0 0 0 1px var(--accent-glow, rgba(200, 200, 208, 0.15)),
    0 24px 80px rgba(0, 0, 0, 0.7);
  overflow: hidden;
}

/* header ---------------------------------------------------------------- */
#ed-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-raised, #0e0e14);
  border-bottom: 1px solid var(--border-subtle, rgba(139, 26, 26, 0.3));
}
#ed-title {
  color: var(--text-primary, #c8c8d0);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#ed-mode {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent-ember, #c43030);
  border: 1px solid var(--border-subtle, rgba(139, 26, 26, 0.4));
  border-radius: 3px;
  padding: 2px 7px;
}
#ed-head .ed-x {
  background: none;
  border: none;
  color: var(--text-muted, #9090a0);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
#ed-head .ed-x:hover {
  color: var(--accent-ember, #c43030);
}

/* body: editor + preview ------------------------------------------------ */
#ed-body {
  flex: 1;
  display: flex;
  min-height: 0;
}
#ed-editwrap,
#ed-preview {
  flex: 1;
  min-width: 0;
  overflow: auto;
}
#ed-editwrap {
  display: flex;
  background: var(--bg-deep, #020204);
  border-right: 1px solid var(--border-subtle, rgba(139, 26, 26, 0.25));
}
#ed-overlay.no-preview #ed-preview {
  display: none;
}
#ed-overlay.no-preview #ed-editwrap {
  border-right: none;
}

/* plain-textarea baseline (works with zero external deps) */
#ed-gutter {
  padding: 12px 8px 12px 12px;
  text-align: right;
  color: var(--text-ghost, #2a2a35);
  background: var(--bg-surface, #08080c);
  user-select: none;
  font-variant-numeric: tabular-nums;
  white-space: pre;
}
#ed-textarea {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  padding: 12px 14px;
  background: transparent;
  color: var(--text-primary, #c8c8d0);
  caret-color: var(--accent-ember, #c43030);
  tab-size: 4;
  white-space: pre;
  overflow-wrap: normal;
}
#ed-editwrap,
#ed-textarea,
#ed-gutter,
#ed-preview {
  font-family: inherit;
  font-size: 14px;
  line-height: 1.55;
}

/* CodeMirror, once progressively enhanced, fills the edit area */
#ed-editwrap .cm-editor {
  height: 100%;
  width: 100%;
}
#ed-editwrap .cm-scroller {
  font-family: inherit;
}

#ed-preview {
  padding: 12px 16px;
  color: var(--text-primary, #c8c8d0);
  background: var(--bg-surface, #08080c);
  white-space: pre-wrap;
  word-break: break-word;
}
#ed-preview .ed-preview-empty {
  color: var(--text-dim, #606070);
  font-style: italic;
}

/* footer toolbar -------------------------------------------------------- */
#ed-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  background: var(--bg-raised, #0e0e14);
  border-top: 1px solid var(--border-subtle, rgba(139, 26, 26, 0.3));
}
#ed-counts {
  color: var(--text-dim, #606070);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
}
#ed-status {
  color: var(--accent-ember, #c43030);
  font-size: 11px;
  min-width: 90px;
  opacity: 0;
  transition: opacity 0.2s;
}
#ed-status.show {
  opacity: 1;
}
#ed-foot .ed-spacer {
  flex: 1;
}
#ed-foot button {
  background: var(--bg-surface, #08080c);
  color: var(--text-muted, #9090a0);
  border: 1px solid var(--border-subtle, rgba(139, 26, 26, 0.4));
  border-radius: 4px;
  padding: 6px 13px;
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
#ed-foot button:hover {
  color: var(--text-primary, #c8c8d0);
  border-color: var(--accent-ember, #c43030);
}
#ed-foot button.ed-primary {
  color: var(--text-primary, #c8c8d0);
  border-color: var(--accent-blood, #8b1a1a);
  background: linear-gradient(
    180deg,
    var(--bg-raised, #0e0e14),
    var(--bg-surface, #08080c)
  );
}
#ed-foot button.ed-primary:hover {
  border-color: var(--accent-ember, #c43030);
  box-shadow: 0 0 12px var(--accent-glow, rgba(200, 200, 208, 0.15));
}
#ed-hint {
  color: var(--text-ghost, #2a2a35);
  font-size: 10px;
  letter-spacing: 0.04em;
}

/* snippets menu --------------------------------------------------------- */
#ed-snip-wrap {
  position: relative;
}
#ed-snip-menu[hidden] {
  display: none;
}
#ed-snip-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  min-width: 170px;
  display: flex;
  flex-direction: column;
  background: var(--bg-raised, #0e0e14);
  border: 1px solid var(--border-subtle, rgba(139, 26, 26, 0.4));
  border-radius: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  z-index: 5;
}
#ed-snip-menu button {
  text-align: left;
  border: none;
  border-radius: 0;
  border-bottom: 1px solid var(--border-subtle, rgba(139, 26, 26, 0.15));
  background: none;
  padding: 8px 12px;
}
#ed-snip-menu button:last-child {
  border-bottom: none;
}

/* diff-before-save ------------------------------------------------------ */
#ed-diff {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface, #08080c);
}
#ed-diff[hidden] {
  display: none;
}
#ed-diff-head {
  padding: 12px 16px;
  color: var(--text-primary, #c8c8d0);
  font-weight: 600;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border-subtle, rgba(139, 26, 26, 0.3));
  background: var(--bg-raised, #0e0e14);
}
#ed-diff-body {
  flex: 1;
  overflow: auto;
  padding: 8px 0;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
}
.ed-d-row {
  padding: 0 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.ed-d-sign {
  display: inline-block;
  width: 1.4em;
  color: var(--text-ghost, #2a2a35);
  user-select: none;
}
.ed-d-ctx {
  color: var(--text-dim, #606070);
}
.ed-d-add {
  color: #6ac46a;
  background: rgba(60, 160, 60, 0.08);
}
.ed-d-del {
  color: var(--accent-ember, #c43030);
  background: rgba(196, 48, 48, 0.08);
}
#ed-diff-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--border-subtle, rgba(139, 26, 26, 0.3));
  background: var(--bg-raised, #0e0e14);
}
#ed-diff-summary {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
#ed-diff-foot button {
  background: var(--bg-surface, #08080c);
  color: var(--text-muted, #9090a0);
  border: 1px solid var(--border-subtle, rgba(139, 26, 26, 0.4));
  border-radius: 4px;
  padding: 6px 13px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}
#ed-diff-foot button.ed-primary {
  color: var(--text-primary, #c8c8d0);
  border-color: var(--accent-blood, #8b1a1a);
}
#ed-diff-foot button:hover {
  border-color: var(--accent-ember, #c43030);
  color: var(--text-primary, #c8c8d0);
}

@media (max-width: 720px) {
  #ed-body {
    flex-direction: column;
  }
  #ed-editwrap {
    border-right: none;
    border-bottom: 1px solid var(--border-subtle, rgba(139, 26, 26, 0.25));
  }
  #ed-hint {
    display: none;
  }
}
