/* ============================================================
   tag-editor.css — the homebrew tag editor: its surface, its chips, the / and @ menu
   ============================================================ */

/* ─── THE EDITOR ─────────────────────────────────────────── */
.tag-editor { position: relative; display: flex; flex-direction: column; gap: 3px; }

/* Looks like the textarea it replaces (base.css). `pre-wrap` shows the "\n"s
   the editor writes for Enter. */
.te-surface {
  position: relative;
  padding: 4px 8px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--field);
  border: 1px solid var(--border2);
  border-radius: 3px;
  box-shadow: inset 0 1px 2px var(--emboss-lo);
  outline: none;
  cursor: text;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.te-surface:focus-within {
  border-color: var(--accent);
  box-shadow: inset 0 1px 2px var(--emboss-lo), 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent);
}
.te-surface.te-empty::before {
  content: attr(data-placeholder);
  position: absolute;
  left: 8px;
  top: 4px;
  color: var(--text-dim);
  pointer-events: none;
}

.te-source { width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

.te-source-toggle {
  align-self: flex-end;
  padding: 0 2px;
  font-size: 10px;
  color: var(--text-dim);
}
.te-source-toggle:hover { color: var(--accent); }

/* ─── CHIPS ──────────────────────────────────────────────── */
/* A homebrew field is a `.field`, whose label rule (modals.css) styles every
   span in it; the chips' spans undo that, and the rules below that set those
   properties again carry `.tag-editor` to outrank this. */
.tag-editor span {
  font-size: inherit;
  font-weight: inherit;
  color: inherit;
  text-transform: none;
  letter-spacing: normal;
}

/* One atomic box in the prose; its fields wrap inside it when it runs long. */
.tag-editor .te-chip {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 3px;
  max-width: 100%;
  margin: 1px 1px;
  padding: 1px 3px 1px 5px;
  vertical-align: middle;
  line-height: 1.3;
  white-space: normal;
  font-size: 11.5px;
  background: var(--panel);
  border: 1px solid color-mix(in srgb, var(--accent-soft) 60%, transparent);
  border-radius: 4px;
  cursor: default;
  user-select: none;
}
.te-chip .te-chip { margin: 0; background: color-mix(in srgb, var(--accent-soft) 10%, var(--panel)); }

.tag-editor .te-chip-label {
  font-weight: 700;
  color: var(--accent);
  font-variant: small-caps;
  letter-spacing: 0.03em;
  cursor: help;
}

/* Selected by a first Backspace; a second one deletes it. */
.te-top.te-selected { box-shadow: 0 0 0 2px var(--accent); }

.te-has-problems { border-style: dashed; border-color: var(--danger); }

.tag-editor .te-ref { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.te-ref[data-ref-kind="spell"] .te-ref-name { font-style: italic; }
.tag-editor .te-ref.missing { color: var(--text-dim); border-style: dashed; }
.te-ref.missing .te-ref-name { text-decoration: line-through; }

.tag-editor .te-invalid {
  color: var(--text-dim);
  font-family: ui-monospace, Consolas, monospace;
  border-color: var(--danger);
  border-style: dashed;
}

/* ─── FIELDS ─────────────────────────────────────────────── */
.te-chip input.te-num,
.te-chip select.te-select {
  padding: 0 3px;
  font-size: 11.5px;
  line-height: 1.4;
  box-shadow: none;
}
.te-chip input.te-num { width: 6.5ch; text-align: center; }
.te-chip select.te-select { width: auto; max-width: 14em; }

/* An empty required field: dashed until filled. */
.te-chip .te-missing { border-style: dashed; border-color: var(--danger); }
.te-slot.te-missing, .te-list.te-missing { border: 1px dashed var(--danger); border-radius: 3px; }

.te-slot, .te-list { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 3px; }

.te-add,
.te-remove {
  padding: 0 4px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--text-dim);
  border-radius: 3px;
}
.te-add { border: 1px dashed var(--border2); }
.te-add:hover, .te-add:focus-visible { color: var(--accent); border-color: var(--accent); }
.te-remove { font-size: 9px; padding: 0 2px; }
.te-remove:hover, .te-remove:focus-visible { color: var(--danger); }
.te-add:focus-visible, .te-remove:focus-visible { outline: 1px solid var(--accent); }

/* ─── THE MENU ───────────────────────────────────────────── */
/* src/js/tag-menu.js: one popup for every editor, fixed to the viewport. */
.tag-menu {
  position: fixed;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  width: 300px;
  max-height: 300px;
  background: var(--panel);
  border: 1px solid var(--border2);
  border-radius: 4px;
  box-shadow: var(--shadow-deep);
  overflow: hidden;
}
.tag-menu-search { margin: 6px; font-size: 12px; }
.tag-menu-list { overflow-y: auto; padding-bottom: 4px; }

.tag-menu-group {
  padding: 6px 10px 2px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.tag-menu-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 6px;
  padding: 3px 10px;
  font-size: 12.5px;
  cursor: pointer;
}
.tag-menu-row.active { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.tag-menu-name { color: var(--text); font-weight: 600; }
.tag-menu-name mark { background: none; color: var(--accent); text-decoration: underline; }
.tag-menu-detail { flex-basis: 100%; font-size: 11px; color: var(--text-dim); }
.tag-menu-badge {
  padding: 0 4px;
  font-size: 9px;
  font-weight: 700;
  color: var(--on-accent);
  background: var(--accent-soft);
  border-radius: 3px;
}
.tag-menu-empty { padding: 8px 10px; font-size: 12px; font-style: italic; color: var(--text-dim); }

/* ─── A JUMPED-TO CHIP ───────────────────────────────────── */
/* The preview's problems list scrolls to a chip and flashes it. */
.te-flash { animation: te-flash 0.4s ease-in-out 3 alternate; }
@keyframes te-flash {
  to { box-shadow: 0 0 0 3px var(--danger); }
}
@media (prefers-reduced-motion: reduce) {
  .te-flash { animation: none; box-shadow: 0 0 0 3px var(--danger); }
}
