/* ==========================================================================
   Message Builder v3 Styles
   Prefix: mb-
   Depends on: core.css (custom properties), tools.css (preview & color-preset)
   ========================================================================== */


/* ---------- Layout ---------- */

.mb-layout {
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 1.5rem;
}

.mb-form-col {
  max-width: none;
}

.mb-preview-col {
  /* right column */
}

.mb-preview-sticky {
  position: sticky;
  top: calc(var(--header-h, 80px) + 2rem);
  max-height: calc(100vh - var(--header-h, 80px) - 3rem);
  overflow-y: auto;
}


/* ---------- Sections ---------- */

.mb-section {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.mb-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.mb-section-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
}


/* ---------- Counters ---------- */

.mb-counter {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.mb-counter-warn {
  color: var(--accent-amber);
}

.mb-counter-over {
  color: var(--stat-1);
}

.mb-field-counter {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}


/* ---------- Formatting toolbar ---------- */

.mb-fmt-toolbar {
  display: flex;
  gap: 0.2rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.mb-fmt-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  color: var(--text-muted);
  padding: 0.3rem 0.4rem;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mb-fmt-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.mb-fmt-btn svg {
  width: 14px;
  height: 14px;
}


/* ---------- Textarea ---------- */

.mb-textarea {
  background: #1a1d24;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-main);
  padding: 0.75rem;
  font-size: 0.88rem;
  font-family: inherit;
  resize: none;
  width: 100%;
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.2s;
  min-height: 80px;
  overflow-y: auto;
}

.mb-textarea:focus {
  border-color: rgba(88, 101, 242, 0.4);
}


/* ---------- Add button ---------- */

.mb-add-btn {
  background: rgba(88, 101, 242, 0.1);
  border: 1px solid rgba(88, 101, 242, 0.2);
  border-radius: 6px;
  color: #5865F2;
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.15s;
  white-space: nowrap;
}

.mb-add-btn:hover {
  background: rgba(88, 101, 242, 0.18);
}

.mb-add-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.mb-add-sm {
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
}


/* ---------- Embed card ---------- */

.mb-embed-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  margin-bottom: 0.75rem;
  overflow: hidden;
  transition: border-color 0.2s;
}

.mb-embed-active {
  border-color: rgba(88, 101, 242, 0.25);
}

.mb-embed-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.75rem;
  cursor: pointer;
  transition: background 0.15s;
}

.mb-embed-header:hover {
  background: rgba(255, 255, 255, 0.02);
}

.mb-embed-header-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.mb-embed-color-swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  flex-shrink: 0;
}

.mb-embed-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

.mb-embed-header-right {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.mb-embed-collapse,
.mb-embed-remove,
.mb-embed-icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.mb-embed-collapse:hover,
.mb-embed-icon-btn:hover {
  background: rgba(255, 255, 255, 0.05);
}

.mb-embed-icon-btn:hover {
  color: #fff;
}

.mb-embed-remove:hover {
  color: var(--stat-1);
}

.mb-embed-icon-btn[style*="red"],
.mb-embed-icon-btn[style*="ed4245"] {
  color: rgba(237, 66, 69, 0.6);
}

.mb-embed-icon-btn[style*="red"]:hover,
.mb-embed-icon-btn[style*="ed4245"]:hover {
  color: var(--danger);
  background: rgba(255, 80, 80, 0.08);
}

.mb-embed-body {
  padding: 0.75rem 0.75rem 0.75rem;
}


/* ---------- Embed grid & fields ---------- */

.mb-embed-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.mb-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.mb-field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.mb-field-full {
  grid-column: 1 / -1;
}

.mb-input {
  background: #1a1d24;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-main);
  padding: 0.55rem 0.7rem;
  font-size: 0.85rem;
  font-family: inherit;
  width: 100%;
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.2s;
}

.mb-input:focus {
  border-color: rgba(88, 101, 242, 0.4);
}

.mb-input::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}


/* ---------- Color row & presets ---------- */

.mb-color-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

/* Custom color picker (replaces native input) */
.mb-color-picker-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #1a1d24;
  cursor: pointer;
  position: relative;
  transition: border-color 0.15s;
}

.mb-color-picker-wrap:hover { border-color: rgba(255,255,255,0.15); }

.mb-color-indicator {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 2px solid rgba(255,255,255,0.15);
  flex-shrink: 0;
  transition: border-color 0.15s;
}

.mb-color-picker-wrap:hover .mb-color-indicator { border-color: rgba(255,255,255,0.3); }

.mb-color-hex {
  font-size: 12px;
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.mb-color-input-hidden {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: none;
  padding: 0;
}

/* Color presets */
.mb-color-presets {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

.mb-color-presets .color-preset {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
  flex-shrink: 0;
}

.mb-color-presets .color-preset:hover {
  border-color: rgba(255, 255, 255, 0.4);
  transform: scale(1.15);
}

.mb-color-presets .color-preset.active {
  border-color: #fff;
  transform: scale(1.15);
}


/* ---------- Toggle checkbox (checkmark style) ---------- */

.mb-toggle-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.mb-toggle-label input[type="checkbox"] {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: all 0.15s;
}

.mb-toggle-label input[type="checkbox"]:checked {
  background: #5865F2;
}

.mb-toggle-label input[type="checkbox"]::after {
  content: '';
  position: absolute;
  top: 1.5px;
  left: 1.5px;
  width: 11px;
  height: 11px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='11' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E") center/contain no-repeat;
  border-radius: 2px;
}

/* Inline toggle */
.mb-inline-toggle {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  cursor: pointer;
}

.mb-inline-toggle input {
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: all 0.15s;
}

.mb-inline-toggle input:checked { background: #5865F2; }

.mb-inline-toggle input::after {
  content: '';
  position: absolute;
  top: 1px;
  left: 1px;
  width: 8px;
  height: 8px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E") center/contain no-repeat;
}


/* ---------- Timestamp 3-state toggle button ---------- */

.mb-ts-toggle {
  background: #1a1d24;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px;
  color: var(--text-muted);
  padding: 0.45rem 0.85rem;
  font-size: 0.8rem;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.mb-ts-toggle:hover { background: rgba(255,255,255,0.06); }

.mb-ts-toggle.active {
  background: rgba(88,101,242,0.12);
  border-color: rgba(88,101,242,0.3);
  color: #5865F2;
}

.mb-ts-toggle .mb-ts-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.15s;
}

.mb-ts-toggle.active .mb-ts-dot { background: #5865F2; }




/* ---------- Mini formatting toolbar for embed fields ---------- */

.mb-mini-toolbar {
  display: flex;
  gap: 0.15rem;
  margin-bottom: 0.35rem;
}

.mb-mini-toolbar .mb-fmt-btn {
  padding: 0.2rem 0.35rem;
}

.mb-mini-toolbar .mb-fmt-btn svg {
  width: 12px;
  height: 12px;
}


/* ---------- Image row (thumbnail + image same line) ---------- */

.mb-image-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}


/* ---------- Subsection ---------- */

.mb-subsection {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.mb-subsection-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.mb-subsection-head span {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}


/* ---------- Field card redesign ---------- */

.mb-field-card {
  background: #1a1d24;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  margin-bottom: 0.6rem;
  transition: border-color 0.15s;
}

.mb-field-card:hover { border-color: rgba(255,255,255,0.12); }

.mb-field-card-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.mb-field-card-num {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  background: rgba(255,255,255,0.06);
  border-radius: 4px;
  padding: 0.15rem 0.45rem;
  flex-shrink: 0;
}

.mb-field-card-head .mb-inline-toggle {
  margin-left: auto;
}


/* ---------- Field row (legacy fallback) ---------- */

.mb-field-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 0.5rem;
  align-items: end;
  margin-bottom: 0.5rem;
}


/* ---------- Remove small ---------- */

.mb-remove-sm {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.3rem;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}

.mb-remove-sm:hover {
  color: var(--danger);
  background: rgba(255, 80, 80, 0.08);
}


/* ---------- Empty message ---------- */

.mb-empty-msg {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 1.5rem 0.75rem;
  border: 1px dashed rgba(255, 255, 255, 0.08);
  border-radius: 8px;
}


/* ---------- Component card (action rows / buttons) ---------- */

.mb-comp-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 0.75rem;
  overflow: hidden;
}

.mb-comp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.75rem;
  cursor: pointer;
  transition: background 0.15s;
}

.mb-comp-header:hover {
  background: rgba(255, 255, 255, 0.02);
}

.mb-comp-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.mb-comp-header-right {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.mb-comp-body {
  padding: 0 0.75rem 0.75rem;
}


/* ---------- Button card (link only) ---------- */

.mb-btn-card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
}

.mb-btn-link-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.mb-btn-link-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #4E5058;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.mb-btn-link-icon svg {
  width: 16px;
  height: 16px;
  color: #fff;
}

.mb-btn-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}


/* ---------- Format toggle buttons ---------- */

.mb-format-btns {
  display: flex;
  gap: 0.2rem;
}

.mb-format-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  color: var(--text-muted);
  padding: 0.25rem 0.55rem;
  font-size: 0.72rem;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  font-weight: 600;
}

.mb-format-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.mb-format-btn.active {
  background: rgba(88, 101, 242, 0.12);
  border-color: rgba(88, 101, 242, 0.25);
  color: #5865F2;
}


/* ---------- JSON hint ---------- */

.mb-json-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  opacity: 0.7;
}


/* ---------- JSON output & View Full ---------- */

.embed-json-area {
  background: #030305;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px;
  padding: 0.75rem;
  color: var(--accent-cyan);
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.8rem;
  line-height: 1.55;
  width: 100%;
  box-sizing: border-box;
  resize: none;
  outline: none;
}

.mb-view-full-btn {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  color: var(--text-muted);
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  transition: all 0.15s;
  display: none;
  margin-top: 0.4rem;
}

.mb-view-full-btn:hover { background: rgba(255,255,255,0.08); color: var(--text-main); }
.mb-view-full-btn.visible { display: inline-block; }

.mb-fullview-textarea {
  width: 100%;
  min-height: 60vh;
  background: #030305;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px;
  padding: 1rem;
  color: var(--text-main);
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.82rem;
  line-height: 1.55;
  resize: none;
  outline: none;
  box-sizing: border-box;
}


/* ---------- Action bar ---------- */

.mb-action-bar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.mb-action-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: var(--text-main);
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
  font-weight: 600;
  font-family: inherit;
}

.mb-action-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.mb-action-primary {
  background: rgba(88, 101, 242, 0.12);
  border-color: rgba(88, 101, 242, 0.25);
  color: #5865F2;
}

.mb-action-primary:hover {
  background: rgba(88, 101, 242, 0.2);
}


/* ---------- Modal (webhook send / view full) ---------- */

.mb-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
}

.mb-modal-visible {
  opacity: 1;
}

.mb-modal {
  background: var(--panel-dark);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  width: 100%;
  max-width: 440px;
  margin: 1rem;
  transform: scale(0.95) translateY(10px);
  transition: transform 0.2s;
}

.mb-modal.mb-modal-lg {
  max-width: 720px;
}

.mb-modal-visible .mb-modal {
  transform: scale(1) translateY(0);
}

.mb-modal-header {
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.mb-modal-body {
  padding: 1rem 1.25rem;
}

.mb-modal-body label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.35rem;
}

.mb-modal-body input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-main);
  padding: 0.55rem 0.7rem;
  font-size: 0.85rem;
  font-family: inherit;
  width: 100%;
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.2s;
}

.mb-modal-body input:focus {
  border-color: rgba(88, 101, 242, 0.4);
}

.mb-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.mb-modal-cancel {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: var(--text-main);
  padding: 0.45rem 1rem;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
}

.mb-modal-ok {
  background: #5865F2;
  border: 1px solid #5865F2;
  border-radius: 8px;
  color: #fff;
  padding: 0.45rem 1rem;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: inherit;
}


/* ---------- Discord preview rounded embeds ---------- */

.discord-embed {
  border-radius: 4px;
}


/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .mb-layout {
    grid-template-columns: 1fr;
  }

  .mb-preview-sticky {
    position: static;
  }
}

@media (max-width: 640px) {
  .mb-embed-grid {
    grid-template-columns: 1fr;
  }

  .mb-field-row {
    grid-template-columns: 1fr;
  }

  .mb-btn-fields {
    grid-template-columns: 1fr;
  }

  .mb-image-row {
    grid-template-columns: 1fr;
  }
}
