/**
 * X Control - Rich Text Editor Styles
 * Professional WYSIWYG editor with fullscreen, dropdowns, source view
 */

/* ─── Wrapper ─────────────────────────────────────── */
.re-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-md);
}

.re-wrap--fullscreen {
  position: fixed !important;
  inset: 0;
  z-index: 9999;
  border-radius: 0;
  background: var(--color-surface-1);
  display: flex;
  flex-direction: column;
}

body.re-noscroll {
  overflow: hidden !important;
}

/* ─── Fullscreen Title ────────────────────────────── */
.re-fullscreen-title {
  padding: 12px 18px;
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--color-text-primary);
  background: var(--color-surface-2);
  border-bottom: 1px solid var(--color-border);
  display: none;
}

/* ─── Toolbar ─────────────────────────────────────── */
.re-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 8px;
  background: var(--color-surface-3);
  border: 1px solid var(--color-border);
  border-bottom: none;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  flex-wrap: wrap;
}

.re-wrap--fullscreen .re-toolbar {
  border-radius: 0;
  padding: 8px 12px;
  border-left: none;
  border-right: none;
  flex-wrap: nowrap;
}

.re-toolbar__right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 2px;
}

/* ─── Buttons ─────────────────────────────────────── */
.re-btn {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 15px;
  transition: all 0.15s;
  padding: 0;
  flex-shrink: 0;
}

.re-btn:hover {
  background: var(--color-surface-4);
  color: var(--color-text-primary);
}

.re-btn:active {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.re-btn.is-active {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.re-btn--wide {
  width: auto;
  padding: 0 8px;
  gap: 4px;
}

.re-btn__label {
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  max-width: 70px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.re-btn--source,
.re-btn--fullscreen {
  font-size: 16px;
}

.re-btn.is-loading {
  opacity: 0.5;
  pointer-events: none;
  animation: re-pulse 1s infinite;
}

@keyframes re-pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* ─── Separator ───────────────────────────────────── */
.re-sep {
  width: 1px;
  height: 20px;
  background: var(--color-border);
  margin: 0 4px;
  flex-shrink: 0;
}

/* ─── Dropdown ────────────────────────────────────── */
.re-dropdown {
  position: relative;
}

.re-dropdown__menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  min-width: 150px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  padding: 4px;
  max-height: 280px;
  overflow-y: auto;
}

.re-dropdown.is-open .re-dropdown__menu {
  display: block;
}

.re-dropdown__item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 6px 10px;
  border: none;
  background: transparent;
  color: var(--color-text-primary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  transition: background 0.1s;
}

.re-dropdown__item:hover {
  background: var(--color-surface-4);
}

/* ─── Color Picker ────────────────────────────────── */
.re-dropdown__menu--colors {
  min-width: auto;
  padding: 8px;
  display: none;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.re-dropdown.is-open .re-dropdown__menu--colors {
  display: grid;
}

.re-color-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border);
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 3px;
  transition: transform 0.1s, border-color 0.1s;
}

.re-color-btn:hover {
  transform: scale(1.15);
  border-color: var(--color-text-secondary);
}

.re-color-btn span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 2px;
}

.re-color-indicator {
  width: 12px;
  height: 3px;
  border-radius: 1px;
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
}

.re-btn:has(.re-color-indicator) {
  position: relative;
}

/* ─── Editor Body ─────────────────────────────────── */
.re-body {
  border: 1px solid var(--color-border);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  padding: 12px 14px;
  background: var(--color-surface-1);
  color: var(--color-text-primary);
  font-family: var(--font-primary);
  font-size: var(--text-md);
  line-height: 1.7;
  outline: none;
  overflow-y: auto;
  max-height: 300px;
  transition: border-color 0.15s;
}

.re-body:focus {
  border-color: var(--color-primary);
}

.re-wrap--fullscreen .re-body {
  flex: 1;
  max-height: none;
  border-radius: 0;
  border-left: none;
  border-right: none;
  padding: 20px 24px;
  font-size: var(--text-base);
}

/* Placeholder */
.re-body:empty::before {
  content: attr(data-placeholder);
  color: var(--color-text-muted);
  pointer-events: none;
}

/* ─── Body Content Styles ─────────────────────────── */
.re-body h2 {
  font-size: 20px;
  font-weight: var(--font-semibold);
  color: var(--color-text-primary);
  margin: 14px 0 8px;
}

.re-body h3 {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--color-text-primary);
  margin: 12px 0 6px;
}

.re-body h4 {
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  color: var(--color-text-primary);
  margin: 10px 0 4px;
}

.re-body h2:first-child,
.re-body h3:first-child,
.re-body h4:first-child {
  margin-top: 0;
}

.re-body p {
  margin: 0 0 8px;
}

.re-body blockquote {
  margin: 8px 0;
  padding: 8px 14px;
  border-left: 3px solid var(--color-primary);
  background: var(--color-surface-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--color-text-secondary);
  font-style: italic;
}

.re-body ul,
.re-body ol {
  margin: 4px 0 8px;
  padding-left: 22px;
}

.re-body li {
  margin-bottom: 2px;
}

.re-body a {
  color: var(--color-primary);
  text-decoration: underline;
}

.re-body strong,
.re-body b {
  font-weight: var(--font-semibold);
  color: var(--color-text-primary);
}

.re-body hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 12px 0;
}

.re-body img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 8px 0;
  cursor: default;
}

/* ─── Source Textarea ─────────────────────────────── */
.re-source {
  border: 1px solid var(--color-border);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  padding: 12px 14px;
  background: var(--color-surface-2);
  color: var(--color-primary);
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.6;
  outline: none;
  resize: vertical;
  width: 100%;
  box-sizing: border-box;
  tab-size: 2;
}

.re-source:focus {
  border-color: var(--color-primary);
}

.re-wrap--fullscreen .re-source {
  flex: 1;
  max-height: none;
  border-radius: 0;
  border-left: none;
  border-right: none;
  resize: none;
  padding: 20px 24px;
  font-size: 13px;
}

/* ─── Status Bar ──────────────────────────────────── */
.re-statusbar {
  display: flex;
  align-items: center;
  padding: 3px 10px;
  background: var(--color-surface-3);
  border: 1px solid var(--color-border);
  border-top: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  min-height: 22px;
}

.re-wrap--fullscreen .re-statusbar {
  border-radius: 0;
  border-left: none;
  border-right: none;
  border-bottom: none;
}

.re-statusbar__path {
  font-size: 11px;
  color: var(--color-text-muted);
  font-family: 'Consolas', 'Monaco', monospace;
}
